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