AW: Datenaustausch mit Mathcad
12.03.2014 09:57:22
bst
Hi,
übergib die Daten als Matrizen in Form von Textdateien.
Hier - mit SciLab - funktioniert so etwas.
HTH, Bernd
--
VBA-Code:
Option Explicit
Sub CallScilab()
Const strProgName = "D:\programme\scilab-5.4.1\bin\scilex.exe -nwmi"
Const strOutName = "e:\daten\scilab\smooth.input"
Const strInpName = "e:\daten\scilab\smooth.output"
Const strScriptName = "e:\daten\scilab\smooth.sce"
Dim ar As Variant, br As Variant
ar = Range("A1").CurrentRegion.Value
If UBound(ar) 2 Then Exit Sub
WriteMatrix strOutName, ar
ShellAndWait strProgName & " -f " & strScriptName
br = ReadMatrix(strInpName)
Range("D1").Resize(UBound(br, 1), UBound(br, 2)).Value = br
End Sub
' schreibt eine Matrix in eine Textdatei
Public Sub WriteMatrix(ByVal strFileName As String, ByVal ar As Variant)
Const strFS As String = " "
Dim intHandle As Integer, strLine As String
Dim i As Long, j As Integer
intHandle = FreeFile
Open strFileName For Output As #intHandle
For i = LBound(ar) To UBound(ar)
strLine = ""
For j = LBound(ar, 2) To UBound(ar, 2) - 1
strLine = strLine & ar(i, j) & strFS
Next
strLine = strLine & ar(i, j)
Print #intHandle, strLine
Next
Close #intHandle
End Sub
' liest eine Matrix aus einer Textdatei
Public Function ReadMatrix(ByVal strFileName As String) As Variant
Const strFS As String = " "
Dim intHandle As Integer
Dim arLines As Variant, arLine As Variant, arData As Variant
Dim i As Long, j As Integer, intColumns As Integer
intHandle = FreeFile
Open strFileName For Input As #intHandle
arLines = Split(Input(LOF(intHandle), #intHandle), vbNewLine)
arLine = Split(WorksheetFunction.Trim(arLines(0)), strFS)
intColumns = UBound(arLine) + 1
ReDim arData(1 To UBound(arLines), 1 To intColumns)
For i = 1 To UBound(arLines)
arLine = Split(WorksheetFunction.Trim(arLines(i)), strFS)
For j = 0 To Application.Min(intColumns - 1, UBound(arLine))
arData(i, j + 1) = Val(arLine(j))
Next
Next
Close #intHandle
ReadMatrix = arData
End Function
' startet ein externes Program und wartet auf dessen Ende
Public Sub ShellAndWait(ByVal strCommandLine As String, Optional ByVal WindowState As Integer = _
1)
Dim WshShell As Object
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run strCommandLine, WindowState, 1 ' 1 = bWaitOnReturn
Set WshShell = Nothing
End Sub
SciLab-Script:
// Glätten der Eingangsdaten via Smooth
ar=read("e:\daten\scilab\smooth.input",-1,2);
y=smooth(ar',0.1);
write("e:\daten\scilab\smooth.output", y');
quit