Execute

Top  Previous  Next

This command uses the syntax

 

Execute commandtoexecuteinOS

or

Execute =commandtoexecuteinOS

 

to execute a program or OS command specified by commandtoexecuteinOS.  The execution occurs during the GAMS program execution.  The = may be needed to make GAMS wait until the program is done as discussed in the Notes section below.  Since this occurs during execution one cannot use the compile time $Include to incorporate the results of that external run into the GAMS code except through a GAMS from GAMS approach as discussed below or through save and restart use (see the Save Restart chapter).

Notes:

The Execute statement may need to include an = before the name of the program called as follows.

 Execute '=XLS2gms "i=c:\my documents\test.xls" o=d:\tmp\test.inc'

 

 This is required to make GAMS wait until a program is finished.  This is needed for programs that are true windows applications.  One can see if this is the case by running a program from the DOS command prompt.  If control is returned to the command prompt before the program is finished then the = is needed.  A technical explanation of why this is necessary can be found in the Xls2gms section of http://www.gams.com/interface/interface.html.

Examples:

(gnupltxy.gms)

Execute is used in Gnupltxy to graph data generated within a GAMS program.  It accomplishes this by first saving the data to a file using put commands then executing the wgnuplot program which in turn reads that file.  The Execute command can also involve DOS commands as illustrated below

 

put 'plot ';

 

loop(%gp_scen%,

  if (gp_count > 1, put ',';);

  file.nw = 0

 

  put  '\'/' "gnuplot.dat" index ',(gp_count-1):0:0,

        ' using 1:2 "%lf%lf" title "',%gp_scen%.tl,'"';

 

  file.nw = 6;

  gp_count = gp_count + 1;

); put /;

$if  "%gp_term%"=="windows" execute 'if exist gnuplot.ini del gnuplot.ini >nul';

$if  "%gp_term%"=="windows" execute 'copy gnuplot.inp gnuplot.ini >nul';

$if  "%gp_term%"=="windows" execute 'wgnuplot';

$if not "%gp_term%"=="windows" execute 'wgnuplot gnuplot.inp';