Q: Hi, for my model I have to import data from different spreadsheets using gdxxrw. Is there a way to call gdxxrw only, if the particular spreadsheet has been changed? If it has not been changed, I just want to use the old gdx file, because in that case the import is much faster..
Distribution 23.1 introduced the new GDXXRW option CheckDate
to regenerate output only if the input file is more recent than output file.
c:\temp>gdxxrw.exe i=test.xls o=test.gdx Checkdate GDXXRW Jul 13, 2009 23.1.2 WIN 11128.12235 VIS x86/MS Windows Input file : c:\temp\test.xls Output file: c:\temp\test.gdx No new file written (CheckDate is active) Total time = 295 Ms c:\temp>
Older distributions:
A quick and simple test, whether a particular spreadsheet is older than the corresponding gdx file can be done using the program test, which is included in the GAMS Unix utilities. The example below is based on the model herves from the GAMS model library:
* Only read from spreadsheet if XLS file is more recent than GDX file $call =test "%gdx%" -nt "%xls%" $if not errorlevel 1 $goto skipgdxxrw $call gdxxrw "%xls%" output="%gdx%" par=raw rng="%rng%" rdim=2 cdim=1 set=rr rng="%rows%" rdim=2 values=NoData trace=2 $label skipgdxxrw $gdxin "%gdx%" // open GDX file ...
A more compact version is:
* Only read from spreadsheet if XLS file is more recent than GDX file $call test "%gdx%" -nt "%xls%" || gdxxrw "%xls%" output="%gdx%" par=raw rng="%rng%" rdim=2 cdim=1 set=rr rng="%rows%" rdim=2 values=NoData trace=2 $gdxin "%gdx%" // open GDX file ...
With more sophisticated dependencies between your input files you can use a Makefile and the UNIX make program, which is also included in the GAMS Unix utilities:
$onecho > "%gams.scrdir%Makefile.scr" %gdx%: %xls% %system.tab%gdxxrw "%xls%" output="%gdx%" par=raw rng="%rng%" rdim=2 cdim=1 set=rr rng="%rows%" rdim=2 values=NoData trace=2 $offecho * empty rows will be reported $call =make -f "%gams.scrdir%Makefile.scr" $if errorlevel 1 $abort Something wrong with reading raw data from %xls% $label skipgdxxrw $gdxin "%gdx%" // open GDX file $load raw rr // load data into gams $gdxin // close gdx file