load16.gms : Test implicit dimension setting when loading a symbol

Description

This test deals with symbols with unknown dimension when they get loaded
at compile- and execution time. At compile time, the dimension should be
defined by the source (GDX or embedded code). At execution time, the
dimension for sets get set to 1, for other symbols it gets set to 0
(if that does not match the actual dimension, an error will follow).

Contributor: Lutz Westermann, June 2022


Small Model of Type : GAMS


Category : GAMS Test library


Main file : load16.gms

$title Test implicit dimension setting when loading a symbol (LOAD16,SEQ=906)

$onText
This test deals with symbols with unknown dimension when they get loaded
at compile- and execution time. At compile time, the dimension should be
defined by the source (GDX or embedded code). At execution time, the
dimension for sets get set to 1, for other symbols it gets set to 0
(if that does not match the actual dimension, an error will follow).

Contributor: Lutz Westermann, June 2022
$offText


********************************************************************
* Prepare GDX File with data
$onEcho > data.gms
Set       i1dim        / i1*i3         /
          i2dim(*,*)   / #i1dim:#i1dim /;
Parameter p0dim        / 1895          /
          p1dim(i1dim) / #i1dim 1      /;        
$offEcho
$call.checkErrorLevel gams data.gms lo=%GAMS.lo% gdx=data


********************************************************************
* Load from GDX at compile time
$onEcho > test.gms
Set       i1dim, i2dim;
Parameter p0dim, p1dim;

$gdxIn data.gdx
$load i1dim i2dim p0dim p1dim
$if not dimension 1 i1dim $abort expect dim=1 for i1dim
$if not dimension 2 i2dim $abort expect dim=2 for i2dim
$if not dimension 0 p0dim $abort expect dim=0 for p0dim
$if not dimension 1 p1dim $abort expect dim=1 for p1dim
$offEcho
$call.checkErrorLevel gams test.gms lo=%GAMS.lo% gdx=test


********************************************************************
* Load from embedded code at compile time
$onEcho > test.gms
Set       i1dim, i2dim;
Parameter p0dim, p1dim;

$onEmbeddedCode Connect:
- GDXReader:
    file: data.gdx
    symbols: [{name: i1dim}, {name: i2dim}, {name: p0dim}, {name: p1dim} ]
- GAMSWriter:
    symbols: all
$offEmbeddedCode
$if not dimension 1 i1dim $abort expect dim=1 for i1dim
$if not dimension 2 i2dim $abort expect dim=2 for i2dim
$if not dimension 0 p0dim $abort expect dim=0 for p0dim
$if not dimension 1 p1dim $abort expect dim=1 for p1dim
$offEcho
$call.checkErrorLevel gams test.gms lo=%GAMS.lo% gdx=test


********************************************************************
* Load from GDX at execution time - the "good" symbols
$onEcho > test.gms
Set       dummy  / i1*i3 /;
Set       i1dim;
Parameter p0dim;

execute_load 'data.gdx', i1dim, p0dim;
$if not dimension 1 i1dim $abort expect dim=1 for i1dim
$if not dimension 0 p0dim $abort expect dim=0 for p0dim
$offEcho
$call.checkErrorLevel gams test.gms lo=%GAMS.lo% gdx=test


********************************************************************
* Load from embedded code at execution time - the "good" symbols
$onEcho > test.gms
Set       dummy  / i1*i3 /;
Set       i1dim;
Parameter p0dim;

EmbeddedCode Connect:
- GDXReader:
    file: data.gdx
    symbols: [{name: i1dim}, {name: p0dim} ]
- GAMSWriter:
    symbols: all
endEmbeddedCode i1dim, p0dim
$if not dimension 1 i1dim $abort expect dim=1 for i1dim
$if not dimension 0 p0dim $abort expect dim=0 for p0dim
$offEcho
$call.checkErrorLevel gams test.gms lo=%GAMS.lo% gdx=test


********************************************************************
* Load from GDX at execution time - the "bad" symbols
$onEcho > test.gms
Set       dummy  / i1*i3 /;
Set       i2dim;
Parameter p1dim;

execute_load 'data.gdx', i2dim, p1dim;
$offEcho
$call gams test.gms lo=%GAMS.lo% gdx=test
$ifE errorlevel=0 $abort Error expected at line %system.line%


********************************************************************
* Load from embedded code at execution time - the "bad" symbols
$onEcho > test.gms
Set       dummy  / i1*i3 /;
Set       i2dim;
Parameter p1dim;

EmbeddedCode Connect:
- GDXReader:
    file: data.gdx
    symbols: [{name: i2dim}, {name: p1dim} ]
- GAMSWriter:
    symbols: all
endEmbeddedCode i2dim, p1dim
$offEcho
$call gams test.gms lo=%GAMS.lo% gdx=test
$ifE errorlevel=0 $abort Error expected at line %system.line%