save3.gms : Test DCO save

Description

Tests the DCO $[x]save[.keepCode] to produce save file during the
compilation phase.

Contributor: Michael Bussieck, January 2023


Small Model of Type : GAMS


Category : GAMS Test library


Main file : save3.gms

$title 'Test DCO save3' (SAVE3,SEQ=924)

$onText
Tests the DCO $[x]save[.keepCode] to produce save file during the 
compilation phase.

Contributor: Michael Bussieck, January 2023
$offText

$onEchoV > chk4sym.gms
$if not set symName $abort symName not set
$if not declared %symName% $abort unknown symbol %symName%
$offEcho

set i /1*5/; parameter p(i) / 1*5 0 /;

$save save_test
$call.checkErrorLevel gams chk4sym restart=save_test lo=2 --symName i
$call.checkErrorLevel gams chk4sym restart=save_test lo=2 --symName p

$xsave xsave_test
$call.checkErrorLevel gams chk4sym restart=xsave_test lo=2 --symName i
$call.checkErrorLevel gams chk4sym restart=xsave_test lo=2 --symName p

variable x(i); equation e(i); e(i).. x(i) =e= 0;

$save save_test
$call.checkErrorLevel gams chk4sym restart=save_test lo=2 --symName i
$call.checkErrorLevel gams chk4sym restart=save_test lo=2 --symName p
$call.checkErrorLevel gams chk4sym restart=save_test lo=2 --symName x
$call.checkErrorLevel gams chk4sym restart=save_test lo=2 --symName e
$call                 gams chk4sym restart=save_test lo=2 --symName f
$if not errorLevel 1 $abort expect equation f to be unknown (save)

$xsave xsave_test
$call.checkErrorLevel gams chk4sym restart=xsave_test lo=2 --symName i
$call.checkErrorLevel gams chk4sym restart=xsave_test lo=2 --symName p
$call.checkErrorLevel gams chk4sym restart=xsave_test lo=2 --symName x
$call.checkErrorLevel gams chk4sym restart=xsave_test lo=2 --symName e
$call                 gams chk4sym restart=xsave_test lo=2 --symName f
$if not errorLevel 1 $abort expect equation f to be unknown (xsave)

equation f(i); f(i).. x(i) =e= 0;

$onEchoV > checkpsum.gms
$if not set SUMP $abort SUMP not set
scalar psum; psum = sum(i,p(i));
abort$(psum<>%SUMP%) 'wrong sum %SUMP% not equal to', psum;
$offEcho

p(i) = 1;

$save save_test
$call.checkErrorLevel gams checkpsum restart=save_test lo=2 --sumP=0

$xsave xsave_test
$call.checkErrorLevel gams checkpsum restart=xsave_test lo=2 --sumP=0

$save.keepCode save_test
$call.checkErrorLevel gams checkpsum restart=save_test lo=2 --sumP=5

$xsave.keepCode xsave_test
$call.checkErrorLevel gams checkpsum restart=xsave_test lo=2 --sumP=5

p(i) = 2;

$save.keepCode save_test
$call.checkErrorLevel gams checkpsum restart=save_test lo=2 --sumP=10

$xsave.keepCode xsave_test
$call.checkErrorLevel gams checkpsum restart=xsave_test lo=2 --sumP=10

* Make sure we can't use $save inside declaration
$onEchoV > decla.gms
set i /
1
$save.keepCode save_test
2
3 /;
$offEcho
$call gams decla lo=2
$if not errorLevel 1 $abort expect decla.gms to fail (save)

* Make sure we can't use $xsave inside declaration
$onEchoV > decla.gms
set i /
1
$xsave.keepCode xsave_test
2
3 /;
$offEcho
$call gams decla lo=2
$if not errorLevel 1 $abort expect decla.gms to fail (xsave)

* Make sure we can't use $save.keepCode inside if/loop body
$onEchoV > if.gms
if (1,
$save.keepCode save_test
   display 'test';
);
$offEcho
$call gams if lo=2 
$if not errorLevel 1 $abort expect if.gms to fail (save)

* Make sure we can't use $xsave.keepCode inside if/loop body
$onEchoV > if.gms
if (1,
$xsave.keepCode xsave_test
   display 'test';
);
$offEcho
$call gams if lo=2 
$if not errorLevel 1 $abort expect if.gms to fail (xsave)

$onEchoV > loop.gms
set i /1*5/;
loop (i,
$save.keepCode save_test
   display 'test';
);
$offEcho
$call gams loop lo=2 
$if not errorLevel 1 $abort expect loop.gms to fail (save)

$onEchoV > loop.gms
set i /1*5/;
loop (i,
$xsave.keepCode xsave_test
   display 'test';
);
$offEcho
$call gams loop lo=2 
$if not errorLevel 1 $abort expect loop.gms to fail (xsave)