Page tree
Skip to end of metadata
Go to start of metadata

Any script as a Code Module exactly named "Equations.bas" can have functions that can be called from output equations in the AWRDE. This way you can create your own custom functions.

These custom functions will create a data file from the result of simulation data. Currently there are two versions of this, one that writes two columns and the other one that writes three columns in the data file. You also must specify the name of the data file to be loaded.

Here is an example of how to run the script. These three lines in output equations will create a data file of S(1,1) of AT31011_1v_1mA and AT31011_1v_1mA measurments and will create a new data file called "test" and put it there. Note that the third line is calling "mkdata2" function loaded in the Equation.bas script.

        Function mkdata2(data1() As Double, data2() As Double,dname As String) As Double
            'this function will be used to be able to set an x-axis for data calculated in the output equations
        
                'first check to see if data file is there
                Debug.Clear
                Dim dfiles As String
                x = Project.DataFiles.Count
                For i = 1 To x
                        If (dname = Project.DataFiles(i).Name) Then
                                Project.DataFiles.Remove(i)
                        End If
                Next i
            len1 = UBound(data1)
            len2 = UBound(data2)
            If (len2 <> len1) Then
                        MsgBox("vectors not the same length")
                        Debug.Print "vectors not the same length"
                        mkdata2 = -1
                        Exit Function
            End If
            tmpname$="__awr$$$.txt"
            Open  tmpname$ For Output As #1
            For i = 0 To len1
                        Print #1,data1(i);" ";data2(i)
            Next i
            Close #1
                Dim df As DataFile
            Set df = Project.DataFiles.Add(dname,tmpname$,True,mwDFT_TXT)
                mkdata2 = 1
        
        End Function
        Function mkdata3(data1() As Double, data2() As Double,data3() As Double,dname As String) As Double
            'this function will be used to be able to set an x-axis for data calculated in the output equations
        
                'first check to see if data file is there
                Debug.Clear
                Dim dfiles As String
                x = Project.DataFiles.Count
                For i = 1 To x
                        If (dname = Project.DataFiles(i).Name) Then
                                Project.DataFiles.Remove(i)
                        End If
                Next i
            len1 = UBound(data1)
            len2 = UBound(data2)
            len3 = UBound(data3)
            If (len2 <> len1) Then
                        MsgBox("vectors not the same length")
                        Debug.Print "vectors not the same length"
                        mkdata3 = -1
                        Exit Function
            End If
            If (Len3 <> len1) Then
                        MsgBox("vectors not the same length")
                        Debug.Print "vectors not the same length"
                        mkdata3 = -1
                        Exit Function
            End If
            tmpname$="__awr$$$.txt"
            Open  tmpname$ For Output As #1
            For i = 0 To len1
                        Print #1,data1(i);" ";data2(i);" ";data3(i)
            Next i
            Close #1
                Dim df As DataFile
            Set df = Project.DataFiles.Add(dname,tmpname$,True,mwDFT_TXT)
                mkdata3= 1
        End Function