Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

saving a copy of _dd_.gdx #4

Closed
mbussieck opened this issue Jun 4, 2020 · 6 comments
Closed

saving a copy of _dd_.gdx #4

mbussieck opened this issue Jun 4, 2020 · 6 comments

Comments

@mbussieck
Copy link

In prepxtra.mod a put_utility 'shell' is used to rename the _dd_.gdx file and store it in a different location with a file name that contains some kind of time stamp. This saving of the _dd_.gdx which is created and handled at compile time is done at execution time. Due to GAMS save/restart capabilities the compile and execution phase can happen at very different times and even on different machines. It would be cleaner if the saving of this file is done in the compilation phase of GAMS.

@Antti-L
Copy link
Collaborator

Antti-L commented Jun 4, 2020

Thanks. The saving of this file is already done at compile time. Only the renaming is done at execution phase, and that is because of the rename with a timestamp.

There is no standard use case for a restart file being created from TIMES, and so the compile and execution phases would occur at the same time under all normal use cases. However, if you can show how to conveniently create the timestamp at compile time (such that works both under latest and older GAMS versions), doing also the rename at compile time as you suggested will be implemented according to your suggestion. Thanks for contributing to improving TIMES.

@mbussieck
Copy link
Author

You can access the time routines via $eval at compile time. The printing of 02 if you have a 2 is not so easy and I resorted to printf which we ship for ages with the GAMS Windows system and is available on many POSIX systems. Nowadays, I would use embedded Python code to do such things, but I understand that TIMES should also run on older versions of GAMS, so I used the external tool solution. So the following works under Windows and Linux:

$if not %system.fileSys%==UNIX $set GDXPATH 'd:\tmp\'
$if     %system.fileSys%==UNIX $set GDXPATH '/tmp/'
$echo xx > _dd_.gdx
$set RUN_NAME demo_12

$eval JNOW jnow
$eval GSECOND GSECOND(%JNOW%)
$eval GMINUTE GMINUTE(%JNOW%)
$eval GHOUR GHOUR(%JNOW%)
$eval GDAY GDAY(%JNOW%)
$eval GMONTH GMONTH(%JNOW%)
$eval GYEAR GYEAR(%JNOW%)
$echon $call mv -f _dd_.gdx %GDXPATH%%RUN_NAME%~Data_ > "%gams.scrDir%mv.%gams.scrExt%"
$escape &
$call printf "%&02d%&02d%&02d_%&02d%&02d%&02d.gdx" %GYEAR% %GMONTH% %GDAY% %GHOUR% %GMINUTE% %GSECOND% >> "%gams.scrDir%mv.%gams.scrExt%"
$escape %
$if x==x $include "%gams.scrDir%mv.%gams.scrExt%" 

@Antti-L
Copy link
Collaborator

Antti-L commented Jun 4, 2020

Thanks for the proposed method.
I see it works only with GAMS v23.6 or above, and so an additional test for the GAMS version must also be added, and another method be used when v23.5 or below is used. I guess that can be implemented so, even if losing a bit in compactness. 😊

@Antti-L
Copy link
Collaborator

Antti-L commented Jun 4, 2020

Here is a streamlined variant I tested on Windows, hopefully this would work also on Linux:

$EVAL GTIME GHOUR(JSTART)*10000+GMINUTE(JSTART)*100+GSECOND(JSTART)
$EVAL GDATE MOD(GYEAR(JSTART),100)*10000+GMONTH(JSTART)*100+GDAY(JSTART)
$ESCAPE &
$hiddencall printf "%&s%&06d_%&06d.gdx" "%GDXPATH%%RUN_NAME%~Data_" %GDATE% %GTIME% | xargs mv -f _dd_.gdx
$ESCAPE %

@mbussieck
Copy link
Author

I can confirm that this works also on Linux.

@Antti-L
Copy link
Collaborator

Antti-L commented Jun 9, 2020

This change (compile time rename of the data-only gdx file) will be in the next release. I know one user, @kanors-emr , who I expect to be affected by it, due to somewhat "non-standard" modes of usage, and therefore notified hereby in advance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants