Description
Initialization: Write "intro02_driver.m". The Matlab program "intro02_driver.m" is executed. It writes the GAMS program "makedata.gms" from Matlab. Then it executes "makedata.gms" and displays the resulting GDX file foo1.gdx . Furthermore, it writes the result into a indexed GDX file foo2.gdx and displays the content. Intended use: interactive Matlab session Contributor: Toni Lastusilta
Category : GAMS Data Utilities library
Main file : gdxmrw_intro02_init.gms includes : gdxmrw_intro02_init.gms
$Title Introduction to calling GAMS from Matlab
$ontext
Initialization: Write "intro02_driver.m".
The Matlab program "intro02_driver.m" is executed. It writes the GAMS program
"makedata.gms" from Matlab. Then it executes "makedata.gms" and displays the
resulting GDX file foo1.gdx . Furthermore, it writes the result into a
indexed GDX file foo2.gdx and displays the content.
Intended use: interactive Matlab session
Contributor: Toni Lastusilta
$offtext
$onecho > intro02_driver.m
% Matlab in control
% Write GAMS program "makedata.gms" from Matlab.
% Execute the GAMS program and display the result in the
% created file "foo1.gdx". Write the result into foo2.gdx
% and display the content.
% Create foo1.gdx
fName = 'makedata.gms'; %# GAMS program name
fid = fopen(fName,'w'); %# Open the file for writing
if fid ~= -1
str_gams1=['*GAMS Program that creates foo1.gdx \r\n' ...
'Set i /1*2/ \r\n' ...
' j /1*2/; \r\n' ...
'Parameter A(i) Vector A /1 1 , 2 3/ \r\n' ...
' B(i,j) Matix B /1.1 1 , 1.2 3, \r\n' ...
' 2.1 5 , 2.2 7/; \r\n' ...
'Execute_UnloadIdx "foo1.gdx" A,B; \r\n' ...
];
fprintf(fid,str_gams1);
fclose(fid);
else
error('Error creating makedata.gms');
end
% Run GAMS
system 'gams makedata.gms lo=3';
%Display content of foo1.gdx
irgdx('foo1','A','B');
A
B
C=A;D=B;
iwgdx('foo2','C','D');
gdxWhos('foo2.gdx');
gdxInfo('foo2.gdx');
%Display foo2.gdx in the GAMSIDE
if ispc system('start gamside foo2.gdx'); end
open intro02_driver
$offecho
*call Matlab
$set WHICH which
$if not %system.filesys% == UNIX $set WHICH where
$call %WHICH% matlab
$ifThen errorLevel 1
$clearError
$abort.noerror 'Matlab is not available!';
$else
$call.Async matlab -r "cd %GAMS.cdir%;intro02_driver" -nosplash -nodisplay
$endIf