unload12.gms : Make sure that sameAs and diag cannot be exported to GDX

Description

"SameAs" and "diag" are pre-defined symbols. They should not be written to GDX like
user defined symbols (unless there are user defined symbols of the same name that
overwrite the predefined symbol).

Contributor: Lutz Westermann, January 2021


Small Model of Type : GAMS


Category : GAMS Test library


Main file : unload12.gms

$title 'Make sure that sameAs and diag cannot be exported to GDX' (UNLOAD12,SEQ=845)

$ontext
"SameAs" and "diag" are pre-defined symbols. They should not be written to GDX like
user defined symbols (unless there are user defined symbols of the same name that
overwrite the predefined symbol).

Contributor: Lutz Westermann, January 2021
$offtext

Set dummy /1/;

$gdxOut want.gdx
$unload  dummy
$gdxOut

* SameAs and diag should be skipped by default, when exporting all symbols to GDX
$onEcho > skip.gms
Set dummy /1/;

loop(dummy$sameas(dummy, '1'), Display 'something'; );

display diag;

$gdxOut allCT.gdx
$unload
$gdxOut

execute_unload 'allET.gdx';
$offEcho

$call.checkErrorLevel gams skip.gms lo=%GAMS.lo% gdx=allCL.gdx

$call.checkErrorLevel gdxdiff want.gdx allCL.gdx > %system.nullfile%
$call.checkErrorLevel gdxdiff want.gdx allCT.gdx > %system.nullfile%
$call.checkErrorLevel gdxdiff want.gdx allET.gdx > %system.nullfile%

* The user can overwrite the predefined symbols; in that case they should make it into the GDX file
Set sameAs(dummy, dummy) / 1.1 /
    diag                 / 2   /;

$gdxOut want2.gdx
$unload  dummy sameAs diag
$gdxOut

$onEcho > include.gms
Set dummy                / 1   /
    sameAs(dummy, dummy) / 1.1 /
    diag                 / 2   /;

loop(dummy$sameas(dummy, '1'), Display 'something'; );

display diag;

$gdxOut allCT.gdx
$unload
$gdxOut

execute_unload 'allET.gdx';
$offEcho

$call.checkErrorLevel gams include.gms lo=%GAMS.lo% gdx=allCL.gdx

$call.checkErrorLevel gdxdiff want2.gdx allCL.gdx > %system.nullfile%
$call.checkErrorLevel gdxdiff want2.gdx allCT.gdx > %system.nullfile%
$call.checkErrorLevel gdxdiff want2.gdx allET.gdx > %system.nullfile%

* Double check that want and want2 are not just the same
$call gdxdiff want.gdx want2.gdx > %system.nullfile%
$ifE errorlevel=0 $abort Diff expected

* Exporting predefined sameAs and Diff explicitly should result in an error
$onEcho > ctErrDiag.gms
Set dummy /1/;

loop(dummy$sameas(dummy, '1'), Display 'something'; );

display diag;

$gdxOut diag.gdx
$unload diag
$gdxOut
$offEcho
$call gams ctErrDiag.gms lo=%GAMS.lo%
$ifE errorlevel=0 $abort Error expected when exporting diag at CT

$onEcho > ctErrSA.gms
Set dummy /1/;

loop(dummy$sameas(dummy, '1'), Display 'something'; );

display diag;

$gdxOut SA.gdx
$unload sameAs
$gdxOut
$offEcho
$call gams ctErrSA.gms lo=%GAMS.lo%
$ifE errorlevel=0 $abort Error expected when exporting sameAs at CT

$onEcho > etErrDiag.gms
Set dummy /1/;

loop(dummy$sameas(dummy, '1'), Display 'something'; );

display diag;

execute_unload 'diag.gdx', diag;
$offEcho
$call gams etErrDiag.gms lo=%GAMS.lo%
$ifE errorlevel=0 $abort Error expected when exporting diag at ET

$onEcho > etErrSA.gms
Set dummy /1/;

loop(dummy$sameas(dummy, '1'), Display 'something'; );

display diag;

execute_unload 'SA.gdx', sameAs;
$offEcho
$call gams etErrSA.gms lo=%GAMS.lo%
$ifE errorlevel=0 $abort Error expected when exporting sameAs at ET