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;?
One can pass the argument as a command line option using
- -. In your GAMS program you have
$if not set myscale $set myscale 10
Now on the GAMS command line you can do:
gams myprogram --myscale=5
This has the advantage, that even if you don't define the string macro with
- -myscale on the command line, you still have it available with some default value. Note, that
myscale is a scoped string macro.
If you really need it global you could do the following:
$if not set myscale $set myscale 10 $setglobal myscale %myscale%
Another approach is to use the GAMS command line arguments
user5. On the command line (or in the IDE parameter box) you can specify
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%;