How do I: create a dynamic file name based on the set element I am looping over

175 views
Skip to first unread message

AC

unread,
Feb 6, 2012, 10:29:27 PM2/6/12
to gamsworld
Hi

We want to loop over a set of scenarios, and for each scenario write a
report where the filename contains the scenario. For example if I had
2 scenarios x and y I would want my report file to be report_x.csv and
report_y.csv

I think I can do this using $batlinclude, something roughly like:

loop (scenario) do

$batinclude active_file_name scenario

put "report starts here";
:
putclose;

endloop;

and the file activate_file_name.gms will simply be something like:

put report_%1


I have not actually tried the above yet to check it works [and as I
type i realise I would need something similar to do the initial file
declarations]. My question is whether there is a better/easier way to
do this?


Thanks
AndyC

Michael Bussieck

unread,
Feb 7, 2012, 2:55:29 AM2/7/12
to gamsworld
You can use the put_utility 'ren' for this. The following document has
the details: http://www.gams.com/mccarl/pututility.pdf

Hope this helps,
Michael Bussieck - GAMSWorld Coordinator

AC

unread,
Feb 7, 2012, 4:44:28 PM2/7/12
to gamsworld
That's awesome, thanks Michael
Reply all
Reply to author
Forward
0 new messages