Search code examples
globalgams-math

SetGlobal in execute in GAMS


Consider I want to execute to parameter (paramter1 and parameter2). I do the following:

$onEcho > Textfile.txt
par = parameter1   rng = parameter1!A1
par = parameter2   rng = parameter2!A1
$offEcho

execute_unload 'export.gdx', parameter1 parameter2;

But instead of writing that line two times, could I do something like this:

$setGlobal Parameter parameter1 parameter2

$onEcho > Textfile.txt
par = %parameter%   rng = %parameter%!A1
$offEcho

execute_unload 'export.gdx', %parameter%;

However, this code does not work. How can I specify mine parameters one place instead of writing them mulitple times?


Solution

  • In GAMS you can define macros, but for your purpose, $batInclude might be better:

    $onEchoV > execUnload.inc
    $echo par = %1   rng = %1!A1 > Textfile.txt
    execute_unload 'export.gdx', %1;
    $offEcho
    
    $batInclude execUnload.inc parameter1
    $batInclude execUnload.inc parameter2
    

    EDIT: Now, that I understood your question better, after discussing it in the comments, here is a new solution using the put facility:

    $setGlobal Parameter parameter1, parameter2
    
    Set exportPars / %Parameter% /;
    
    File fx / 'Textfile.txt' /;
    put fx;
    
    
    loop(exportPars,
       put 'par = ' exportPars.tl:0 '   rng = ' exportPars.tl:0 '!A1' /;
    );
    
    execute_unload 'export.gdx', %Parameter%;