Contents - Index


Calling EES from other Programs

 

The Professional EES license can be called from other programs such as MATLAB in several different ways.  One way to do this is with dynamic data exchange (DDE).   However, there is a simpler way using the /Solve parameter on the command line, as described here with an example involving MATLAB.

 

First, we will write a small EES program that calculates the specific enthalpy, specific entropy  and sound speed of a real fluid given the fluid name, temperature (K) and pressure (kPa).  The inputs will be read from a text file which is named FromMatLab.dat using the $Import directive.  EES will then write a text file containing the specific enthalpy, specific entropy and sound speed using the $EXPORT directive.  A listing of the EES program is as follows:

 

_____________________________________________________________________________________

 

$UnitSystem SI K kPa kJ 

$Import 'FromMatLab.dat' F$ T P

 

h=enthalpy(F$,T=T,P=P)

s=entropy(F$,T=T,P=P)

c=soundspeed(F$,T=T,P=P)

 

$Export 'ToMatLab.dat' h s c

_____________________________________________________________________________________

 

 

To test this program, create a file named FromMatLab.dat that contains the following line of text.

 

ammonia 300 100

 

Place the FromMatLab.dat file in the same directory as the EES file listed above (or if you wish, provide complete path names in the $Import and $Export directives.

 

Run EES to ensure that it is working.  It should write file 'ToMatLab.dat' with the following line of text.

 

1.55070337E+03 6.62171933E+00 4.34400679E+02

 

 

The plan is to have MATLAB write file 'FromMatLab.dat' and then open and run EES.  EES will write file  'ToMatLab.dat'  which can be opened in MATLAB.  These functions are accomplished in the following MATLAB script, which has been named me.m.

 

_____________________________________________________________________________________

 

%This script will call EES to provide the specific enthalpy, specific

%entropy and sound speed for three different fluids at T=300 K and P=100

%kPa.

 

propinfo={'nitrogen' 300 100; 'carbondioxide' 300 100; 'ammonia' 300 100};

[nrows,ncol]=size(propinfo);;

EESInput='c:\temp\fromMatlab.dat'; %change path as needed"

EESOutput='c:\temp\toMatlab.dat'%change path as needed

for row=1:nrows

  fid=fopen(EESInput,'w');  %open file for writing

  fprintf(fid,'%s %d %d\r\n',propinfo{row,:}); %write fluid, T, P

  fclose(fid); %close file

  system ('c:\ees32\ees.exe c:\temp\tofromMatlab.ees /solve'); %call EES and solve

  hsc=dlmread(EESOutput); %open the file written by EES

  propinfo(row,:) %fluid, temperature and pressure

  hsc %write out specific enthalpy, specific entropy, and sound speed

  h=hsc(1); %specific enthalpy

  s=hsc(2); %specific entropy

  c=hsc(3); %soundspeed 

end

_____________________________________________________________________________________

 

Note that MATLAB calls EES with its system command.  The system command is provided with one string argument that includes the path name of the EES application (your path may be different), the EES file that is to be opened, and the /solve parameter.  EES will start in a hidden state, open the specified file and run it and then close after writing a file with the $Export command.

 

To test the script, enter me in the MATLAB command window.  A listing of the output produced by MATLAB, shown below, indicates that the property information has been passed from EES to MATLAB.

 

_____________________________________________________________________________________

 

>> me

 

ans = 

 

    'nitrogen'    [300]    [100]

 

 

hsc =

 

  311.1973    6.8457  353.1596

 

 

ans = 

 

    'carbondioxide'    [300]    [100]

 

 

hsc =

 

    0.6496    0.0056  269.3906

 

 

ans = 

 

    'ammonia'    [300]    [100]

 

 

hsc =

 

  1.0e+003 *

 

    1.5507    0.0066    0.4344

_____________________________________________________________________________________