Putclose

Top  Previous  Next

The Putclose keyword is used to close a file during the execution of program.  Otherwise GAMS automatically closes files when it exits.

Example:

One application where this is useful involves writing an option file that controls a solver from within a GAMS model.  In that case, the file must be closed prior to the SOLVE statement and Putclose allows that to be done.  The following example shows the creation and closing of an option file for the MINOS solver as implemented in frstpart.gms.

 

FILE  OPT   MINOS option file  / MINOS5.OPT /;

Put OPT;

Put 'BEGIN'/

    '  Iteration limit        500'/

    '  Major damping parameter 0.5'/

    '  Feasibility tolerance   1.0E-7'/

    '  Scale all variables'/

    'END';

Putclose OPT;

 

One may also wish to report what loop one is on in a large model using commands like (comparw.gms)

 

$set console

$if %system.filesys% == UNIX  $set console /dev/tty

$if %system.filesys% == DOS $set console con

$if %system.filesys% == MS95  $set console con

$if %system.filesys% == MSNT  $set console con

$if "%console%." == "." abort "filesys not recognized";

file screen / '%console%' /;

 

followed by

 

loop(scenarios,

    put screen;

    put 'I am on scenario ' Scenarios.tl;

    putclose;

 

that writes to the screen (or DOS window that must be made visible in the IDE using file options execute).  In this case Putclose is necessary to cause the line to become visible.  One can also use Putclose to change the title of the DOS box.

Notes:

This program segment would be placed inside the GAMS model prior to the solve statement.
If the internal file name is omitted from the Putclose statement, the current Put file is closed.
After using the Putclose command, the file does not have to be redefined in order to use it again.  Simply make the file current and use Put statements as you normally would.  The existing file will either be overwritten or appended to depending on the value of the append file (.ap) suffix.