Fex2.gms : Test expert level Fortran API to read and write GDX, set options and execute GAMS

Description

Contributor: Lutz Westermann, October 2012


Small Model of Type : Fortran


Category : GAMS API library


Main file : Fex2.gms

$TITLE 'Test expert level Fortran API to read and write GDX, set options and execute GAMS' (FEX2,SEQ=17)

$ontext
Contributor: Lutz Westermann, October 2012
$offtext


$set srcRoot  %gams.sysdir%apifiles%system.dirsep%Fortran%system.dirsep%
$set srcRootC %gams.sysdir%apifiles%system.dirsep%C%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
$  ifThen %system.buildcode% == SOX
$    set FCOMP  f90
$  else
$    set FCOMP  gfortran
$  endIf
$  set CCOMP  gcc
$  set LIB    ar ruv
$  set LIBOP
$  set LIBEX  a
$  set OBJEX  o
$  set SYMSTY -DAPIWRAP_LCASE_DECOR
$  ifThen %system.filesys% == UNIX
$    set OUT -oxp_example2
$    set FLAGS -m64 -ldl
$  else
$    set OUT -oxp_example2.exe
$    ifThen %system.buildcode% == VS8
$      set FLAGS -m32
$    else
$      set FLAGS -m64
$    endIf
$  endIf
$elseIf %COMPILER% == INTEL
$  set FCOMP  ifort
$  set CCOMP  cl
$  set LIB    lib
$  set LIBOP  -out:
$  set LIBEX  lib
$  set OBJEX  obj
$  set FLAGS
$  set SYMSTY -DAPIWRAP_LCASE_NODECOR
$  set OUT    -Fexp_example2.exe
$else
$  abort Unknown compiler: %COMPILER%
$endIf

$call rm -rf demanddata.gdx

$call %FCOMP% -c "%srcRoot%api%system.dirsep%gamsxf9def.f90" %FLAGS%
$if errorlevel 1 $abort 'Problem compiling gamsxf9def.f90'
$call %FCOMP% -c "%srcRoot%api%system.dirsep%gdxf9def.f90" %FLAGS%
$if errorlevel 1 $abort 'Problem compiling gdxf9def.f90'
$call %FCOMP% -c "%srcRoot%api%system.dirsep%optf9def.f90" %FLAGS%
$if errorlevel 1 $abort 'Problem compiling optf9def.f90'

$call %CCOMP% %SYMSTY% -c "%srcRoot%api%system.dirsep%gamsxf9glu.c" -I"%srcRoot%api" -I"%srcRoot%api" %FLAGS%
$if errorlevel 1 $abort 'Problem compiling gamsxf9glu.c'
$call %CCOMP% %SYMSTY% -c "%srcRoot%api%system.dirsep%gdxf9glu.c" -I"%srcRootC%api" -I"%srcRoot%api" %FLAGS%
$if errorlevel 1 $abort 'Problem compiling gdxf9glu.c'
$call %CCOMP% %SYMSTY% -c "%srcRoot%api%system.dirsep%optf9glu.c" -I"%srcRootC%api" -I"%srcRoot%api" %FLAGS%
$if errorlevel 1 $abort 'Problem compiling optf9glu.c'

$call %LIB% %LIBOP%gamsxf90lib.%LIBEX% gamsxf9def.%OBJEX% gamsxf9glu.%OBJEX%
$if errorlevel 1 $abort 'Problem creating gamsx lib file'
$call %LIB% %LIBOP%gdxf90lib.%LIBEX% gdxf9def.%OBJEX% gdxf9glu.%OBJEX%
$if errorlevel 1 $abort 'Problem creating gdx lib file'
$call %LIB% %LIBOP%optf90lib.%LIBEX% optf9def.%OBJEX% optf9glu.%OBJEX%
$if errorlevel 1 $abort 'Problem creating opt lib file'

$call %FCOMP% -c "%srcRoot%api%system.dirsep%gamsglobals_mod.f90" "%srcRoot%xp_example2.f90" %FLAGS%
$if errorlevel 1 $abort 'Problem compiling xp_example2.f90'
$call %FCOMP% %OUT% gamsglobals_mod.%OBJEX% xp_example2.%OBJEX% gamsxf90lib.%LIBEX% gdxf90lib.%LIBEX% optf90lib.%LIBEX% %FLAGS%
$if errorlevel 1 $abort 'Problem while linking'
$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'