Contents - Index


CallMacro

 

The CallMacro is similar in format and function to the Call statement used to access an Internal Procedure or External Procedure.  The difference is that the CallMacro statement will run a macro that exists in the Macro Window.  Although the macro file that is called can use any of the available macro commands, CallMacro is intended to only use the commands that call and return values from other programs, such as MATLAB.  

 

The format of the CallMacro statement is

 

CallMacro MacroName(Input1, Input2, ... : Output1, Output2...)

 

MacroName is the name on the tab of a set of macro commands in the Macro Window.

 

The inputs and outputs are separated by a colon (:) as in internal and external Procedures.  Note that the CallMacro statement may only be used in the main program and the inputs and outputs are variables in the main program.  Note that the input and output variables are not transferred to and from the macro in the usual manner.  The values of the inputs are assumed to be known at the start of the macro call.  The output values MUST be set within the macro.  The real purpose for providing the list of inputs and outputs is to allow EES to properly block the equations so that it can call the macro at the appropriate point in the calculations.

 

Example:

 

Two macros are called.  The macros, labeled matlabmacro1.emf and matlabmacro2.emf are listed below

 

matlabmacro1.emf

MATLAB.Open

MATLAB.SetVariable(N, N)

MATLAB.Execute(ar=randn(5))

NewLookup Lookup Rows=5 Cols=5

Lookup=MATLAB.GetTable(ar)

 

matlabmacro2.emf

MATLAB.Open     

MATLAB.SetVariable(A,A[1..N,1..N])

MATLAB.SetVariable(b,b[1..N])

MATLAB.Execute(X=A\b)

x[1..N]=MATLAB.GetVariable(X)

MATLAB.Execute(Ab=A*b)

Ab[1..3]=MATLAB.GetVariable(Ab)

 

The following EES program calls these two macros

 

$Include C:\temp\matlabmacro1.emf

$Include C:\temp\matlabmacro2.emf

 

N=3

CallMacro matlabmacro1(N:a)

 

A[1,1..N] = [2, 3, 1]

A[2,1..N] = [8, 5, 1]

A[3,1..N] = [7, 1, 2]

 

CallMacro matlabmacro2(N, A[1..3,1..3],B[1..N]:x[1..3],Ab[1..3])

 

b[1]+b[2]+b[3]=8

b[1]+b[2]=3

b[1]+b[3]=6

 

Solution:

A Lookup table containing the matrix ar is created.  The x and Ab arrays are determined by the macros and shown in the Arrays window.