Saving and Using a Script

Top  Previous  Next

The IDE has a facility to allow one to run a set of pre specified commands though the Utilities>script menu choice,   A script can be a set of pre specified commands stored in a text file and can be built either manually or by recording commands much as one can do with spreadsheet macros.

The most important commands that can be used in a script are as follows

 Fileopen - Opens a GAMS job

 Filerun - Runs a GAMS job

 Filewait - Waits until a running GAMS job is complete

 

The general format of these commands is

 

 Fileopen;filename;

 Filerun;filename;command line parameters

 Filewait;filename;

 

where

filename gives the name of the file to be run which is proceeded by %ProjDir% if it is in the project directory and otherwise needs the full path specified.

command line parameters gives any command line parameters that are to be associated with the GAMS job.

Example

 One could manually prepare a script file (script.txt) as follows

fileopen;%ProjDir%trandata.gms;

filerun;%ProjDir%trandata.gms; s=r1

filewait;%ProjDir%trandata.gms;

fileopen;%ProjDir%trandata.gms;

filerun;%ProjDir%tranmodl.gms; r=r1 s=r2

filewait;%ProjDir%tranmodl.gms;

fileopen;%ProjDir%trandata.gms;

filerun;%ProjDir%tranrept.gms; r=r2

filewait;%ProjDir%tranrept.gms;

 

which implements the save restart example from above.

 

One cam also use the command

 

 Message;text to put in message box;

 

that inserts a yes no message box to inform the user but note this requires a mouse click answer and stops the job until it gets that answer.

 

Example (script1.txt)

 

*GAMSIDE script V1

filerun;%ProjDir%trandata.gms; s=r1

filewait;%ProjDir%trandata.gms;

message;Data job done   ;

filerun;%ProjDir%tranmodl.gms; r=r1 s=r2

filewait;%ProjDir%tranmodl.gms;

message;Model job done ;

filerun;%ProjDir%tranrept.gms; r=r2

filewait;%ProjDir%tranrept.gms;

message;Whole job done   ;

Notes

The script is run by using utilities>script>play and then giving the name of the script file and pressing open.
The script file itself must be saved before use if it is any different for the copy on the disk
When the script begins all the files but the script file itself if open are saved so the GMS files will be updated
Lines beginning with an * in column1 are treated as comments and ignored.
When the filerun is performed the model is run with the run history placed in the process window and the LST file is automatically opened afterwards.
The scripting is tricky to use and not very well supported in error messages so it is best to record the steps using the utilities>scropt>record dialogue then going through the steps with the mouse to encompass all one wants to do followed by a utilities>script>stop recording.  The script is then placed in a text file and can be edited if needed.
A number of other scripting commands are allowed as in the table below

 

Command

Function

ViewClose;fileidentifier;

Closes a file

FileClose;fileidentifier;

Closes a file

FileSave;fileidentifier;

Saves a file

FileSaveAll;fileidentifier;

Saves all files

FileCompile;fileidentifier;Command line parameters

Compiles a GAMS job