How to make a datetime stamp for prefixing to reports Topic is solved

Problems with syntax of GAMS
Post Reply
AndrewC
User
User
Posts: 17
Joined: 5 years ago

How to make a datetime stamp for prefixing to reports

Post by AndrewC »

I want to make a datetime stamp when the model starts and then prefix this to all the reports the GAMS code creates during execution.

I tried the following but it doesn't seem to evaluate the date functions at compile time:

{ Create the report prefix Gregorian datetime stamp }
$setglobal REPORT_PREFIX gYear(JNow)gMonth(JNow)gDay(JNow)_gHour(JNow)gMinute(JNow)gSecond(JNow)_
file f_debug /results\%REPORT_PREFIX%_debug.csv/;

The compile time error given is:

{ Create the report prefix Gregorian datetime stamp }
103 file f_debug /results\gYear(JNow)gMonth(JNow)gDay(JNow)_gHour(JNow)gMinute(JNow)gSecond(JNow)__debug.csv/;
104 puclose f_debug "debug";
**** $140 $36
**** 36 '=' or '..' or ':=' or '$=' operator expected
**** rest of statement ignored
**** 140 Unknown symbol

Can someone point me in the right direction, or give me the terms to search the GAMS help for.

Thanks
AndyC
User avatar
bussieck
Moderator
Moderator
Posts: 1043
Joined: 7 years ago

Re: How to make a datetime stamp for prefixing to reports

Post by bussieck »

The put_utility "ren", see https://www.gams.com/42/docs/UG_Put.html#UG_Put_PutUtil, allows to dynamically change the put file name as shown in the following example:

Code: Select all

set i / 1*5 /;
file f_debug / debug.csv /; put f_debug;
loop(i,
  put_utility 'ren' / 'results_' gYear(JNow):0:0 gMonth(JNow):0:0 gDay(JNow):0:0 '_' gHour(JNow):0:0 gMinute(JNow):0:0 gSecond(JNow):0:0 '__debug.csv';
  put i.tl /;
  display$sleep(1.5) 'sleep some time';
);  
-Michael
Post Reply