Accessing current file name

Hi all ! I’m trying to create a few lines of gams code that can be copied-pasted around in order to accomplish automatic unloading to an excel file. I use this:

EXECUTE_UNLOAD ‘v13c.gdx’;
execute ‘xlstalk -C v13c.xlsx’
execute ‘gdx2xls v13c.gdx v13c.xlsx’;
execute ‘xlstalk -O v13c.xlsx’

My next step is to change the strings detailing the file name from a fixed value to an automatic value, that appends the current .gms file name. Using & as concatenation and an invented global %filename% pseudo-code would be:

EXECUTE_UNLOAD %filename%&‘.gdx’;
execute ‘xlstalk -C %filename%&’.xlsx’
execute ‘gdx2xls %filename%&’.gdx’ %filename%&‘.xlsx’;
execute ‘xlstalk -O %filename%&’.xlsx’

Key Question: Is there a way to access the current file filename ? (since I can handle concatenation with puts)

Thanks in advance and sorry if the answer lies in plain sight but I wasn’t able to find it.
Regards!

Claudio


\

To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+unsubscribe@googlegroups.com.
To post to this group, send email to gamsworld@googlegroups.com.
Visit this group at http://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/d/optout.

Claudio,

At compile time GAMS gives you access to the GAMS file name you are running via %gams.input%. There is a command $setnames that splits this name up in directory, base file name and file extension. So with this you have everything you need:

$setnames %gams.input% d filename e
$log %d%
$log %filename%
$log %e%

EXECUTE_UNLOAD ‘%filename%.gdx’;
execute ‘xlstalk -C %filename%.xlsx’
execute ‘gdx2xls %filename%.gdx’ %filename%.xlsx’;
execute ‘xlstalk -O %filename%.xlsx’

No need to use & to concatenate strings.

Hope this helps,
Michael Bussieck - GAMSWorld Coordinator




On Friday, April 3, 2015 at 5:50:32 AM UTC-4, Claudio Delpino wrote:

Hi all ! I’m trying to create a few lines of gams code that can be copied-pasted around in order to accomplish automatic unloading to an excel file. I use this:

EXECUTE_UNLOAD ‘v13c.gdx’;
execute ‘xlstalk -C v13c.xlsx’
execute ‘gdx2xls v13c.gdx v13c.xlsx’;
execute ‘xlstalk -O v13c.xlsx’

My next step is to change the strings detailing the file name from a fixed value to an automatic value, that appends the current .gms file name. Using & as concatenation and an invented global %filename% pseudo-code would be:

EXECUTE_UNLOAD %filename%&‘.gdx’;
execute ‘xlstalk -C %filename%&’.xlsx’
execute ‘gdx2xls %filename%&’.gdx’ %filename%&‘.xlsx’;
execute ‘xlstalk -O %filename%&’.xlsx’

Key Question: Is there a way to access the current file filename ? (since I can handle concatenation with puts)

Thanks in advance and sorry if the answer lies in plain sight but I wasn’t able to find it.
Regards!

Claudio


\

To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+unsubscribe@googlegroups.com.
To post to this group, send email to gamsworld@googlegroups.com.
Visit this group at http://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/d/optout.

Michael: Thought this was a lost one, thank you very much !!!

Just so that this is not a void mail, here’s the file for $include in case it’s useful for anyone.

Thank you again and regards!

Claudio



On Thu, Apr 23, 2015 at 4:11 AM, Michael Bussieck wrote:

Claudio,

At compile time GAMS gives you access to the GAMS file name you are running via %gams.input%. There is a command $setnames that splits this name up in directory, base file name and file extension. So with this you have everything you need:

$setnames %gams.input% d filename e
$log %d%
$log %filename%
$log %e%

EXECUTE_UNLOAD ‘%filename%.gdx’;
execute ‘xlstalk -C %filename%.xlsx’
execute ‘gdx2xls %filename%.gdx’ %filename%.xlsx’;
execute ‘xlstalk -O %filename%.xlsx’

No need to use & to concatenate strings.

Hope this helps,
Michael Bussieck - GAMSWorld Coordinator




On Friday, April 3, 2015 at 5:50:32 AM UTC-4, Claudio Delpino wrote:

Hi all ! I’m trying to create a few lines of gams code that can be copied-pasted around in order to accomplish automatic unloading to an excel file. I use this:

EXECUTE_UNLOAD ‘v13c.gdx’;
execute ‘xlstalk -C v13c.xlsx’
execute ‘gdx2xls v13c.gdx v13c.xlsx’;
execute ‘xlstalk -O v13c.xlsx’

My next step is to change the strings detailing the file name from a fixed value to an automatic value, that appends the current .gms file name. Using & as concatenation and an invented global %filename% pseudo-code would be:

EXECUTE_UNLOAD %filename%&‘.gdx’;
execute ‘xlstalk -C %filename%&’.xlsx’
execute ‘gdx2xls %filename%&’.gdx’ %filename%&‘.xlsx’;
execute ‘xlstalk -O %filename%&’.xlsx’

Key Question: Is there a way to access the current file filename ? (since I can handle concatenation with puts)

Thanks in advance and sorry if the answer lies in plain sight but I wasn’t able to find it.
Regards!

Claudio


\

autoxls.inc (651 Bytes)