CPPex2.gms : Test expert level C API to read and write GDX, set options, and execute GAMS in C++

Description

Contributor: Lutz Westermann, October 2012


Small Model of Type : C and CPP


Category : GAMS API library


Main file : CPPex2.gms

$TITLE 'Test expert level C API to read and write GDX, set options, and execute GAMS in C++' (CPPEX2,SEQ=15)

$ontext
Contributor: Lutz Westermann, October 2012
$offtext


$set srcRoot  %gams.sysdir%apifiles%system.dirsep%C++%system.dirsep%
$set srcRootC %gams.sysdir%apifiles%system.dirsep%C%system.dirsep%
$set exaDir   %srcRoot%xp_example2%system.dirsep%

$ifThen %system.filesys% == UNIX
$  if not set COMPILER $set COMPILER GNU
$else
$  if not set COMPILER $set COMPILER INTEL
$endIf

$ifThen %COMPILER% == GNU
$  set CPPCOMP g++
$  ifThen %system.filesys% == UNIX
$    set OUT -oxp_example2
$    set FLAGS -m64 -ldl -lpthread
$  else
$    set OUT -oxp_example2.exe
$    ifThen %system.buildcode% == VS8
$      set FLAGS -m32
$    else
$      set FLAGS -m64 -D_WIN32_WINNT=0x601 -DWINVER=0x0601
$    endIf
$  endIf
$elseIf %COMPILER% == INTEL
$  set CPPCOMP cl
$  set FLAGS
$  set OUT   -Fexp_example2.exe
$else
$  abort Unknown compiler: %COMPILER%
$endIf

$call rm -rf demanddata.gdx

$call.checkErrorLevel cp "%srcRootC%api%system.dirsep%gdxcc.c" .
$call.checkErrorLevel cp "%srcRootC%api%system.dirsep%optcc.c" .
$call.checkErrorLevel cp "%srcRootC%api%system.dirsep%gcmt.c" .
$call.checkErrorLevel cp "%exaDir%xp_example2.cpp" .
$call %CPPCOMP% xp_example2.cpp gdxcc.c optcc.c gcmt.c -I"%srcRoot%api" -I"%srcRootC%api" %OUT% %FLAGS%
$if errorlevel 1 $abort 'Problem compiling xp_example2.cpp'
$if %system.buildcode% == DEG $call install_name_tool -change $SYSLIBDIR/libstdc++.6.dylib "%gams.sysdir%/libstdc++.6.dylib" -change $SYSLIBDIR/libgcc_s.1.dylib "%gams.sysdir%/libgcc_s.1.dylib" xp_example2
$if %system.buildcode% == DEG $if errorlevel 1 $abort 'Problem adjusting library path'
$call .%system.dirsep%xp_example2 "%gams.sysdir%." model2.gms
$if errorlevel 1 $abort 'Problem executing xp_example2'
$call gdxdiff demanddata.gdx demandwant.gdx
$if errorlevel 1 $abort 'Demanddata not as expected'