User Tools

Site Tools


gams:getting_command_line_arguments_into_a_model

This is an old revision of the document!


Getting Command Line Arguments into a Model

Q: Is it possible to specify command line arguments in the GAMS call, e.g: gams dosomething.gms 10 and in dosomething.gms then set some scalar to 10, e.g: SCALE = $1;?

The GAMS command line arguments user1 to user5 will do the job. On the command line (or in the IDE parameter box) you can specify user1=10 (or u1=10) and inside the GAMS program you can refer to the parameter by using %gams.user1%. Note, that this is a compile time string replacement, so u1 to u5 are not restricted to numbers. If the string has delimiter character (e.g. space) you have to put quotes around your string.

The example from above could be done like this:

  gams dosomething.gms u1=10
  SCALE = %gams.user1%;

Note that if user1 is not defined the result would look like: SCALE =;, which would trigger a compilation error. In order to prevent this, you might specify a default and overwrite this if user1 is set:

$set myscale 1
$if not %gams.user1% == "" $set myscale %gams.user1%
SCALE = %myscale%;
IMPRESSUM / LEGAL NOTICEPRIVACY POLICY gams/getting_command_line_arguments_into_a_model.1186668897.txt.gz ยท Last modified: 2008/01/16 15:24 (external edit)