User Tools

Site Tools


gams:getting_command_line_arguments_into_a_model

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
gams:getting_command_line_arguments_into_a_model [2008/01/16 15:27]
Franz Nelissen
gams:getting_command_line_arguments_into_a_model [2008/01/16 15:29] (current)
Franz Nelissen
Line 3: Line 3:
 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;''?//​ 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.  +One can pass the argument as a command line option using ''​- -''​. ​ In your GAMS program you have
- +
-The example from above could be done like this:<​code>​ +
-  gams dosomething.gms u1=10 +
-  SCALE = %gams.user1%;​ +
-</​code>​ +
-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: +
-<​code>​ +
-$set myscale 1 +
-$if not %gams.user1% == ""​ $set myscale %gams.user1% +
-SCALE = %myscale%;​ +
-</​code>​ +
- +
-Another approach is to pass the argument as a command line option using ''​- -''​. ​ In your GAMS program you have+
 <​code>​ <​code>​
 $if not set myscale $set myscale 10 $if not set myscale $set myscale 10
Line 31: Line 18:
 $setglobal myscale %myscale% ​ $setglobal myscale %myscale% ​
 </​code>​ </​code>​
 +
 +Another approach is to use the GAMS command line arguments ​ ''​user1''​ to ''​user5''​. 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:<​code>​
 +  gams dosomething.gms u1=10
 +  SCALE = %gams.user1%;​
 +</​code>​
 +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:
 +<​code>​
 +$set myscale 1
 +$if not %gams.user1% == ""​ $set myscale %gams.user1%
 +SCALE = %myscale%;
 +</​code>​
 +
 +
IMPRESSUM / LEGAL NOTICEPRIVACY POLICY gams/getting_command_line_arguments_into_a_model.txt · Last modified: 2008/01/16 15:29 by Franz Nelissen