#! /usr/bin/env bash

# Used to run testreport on pleiades after OS changed from SLES to TOSS (v.3),
# using either recent intel compiler:
#   > module load comp-intel/2020.4.304
# or using older intel compiler:
#   > module load comp-intel/2016.2.181
#- and, with MPI:
#   > module load mpi-hpe/mpt.2.25
#   > module load hdf4/4.2.12 hdf5/1.8.18_mpt netcdf/4.4.1.1_mpt
#- and without:
#   > module load hdf4/4.2.12 hdf5/1.8.18_serial netcdf/4.4.1.1_serial
#- Note: in both cases, the last line of 3 module setting is for NetCDF
#        (could be skipped if not using at all this type of I/O).

CC=icc
FC=ifort
F90C=ifort
LINK="$F90C -shared-intel"

CPP='/lib/cpp -traditional -P'
DEFINES='-DWORDLENGTH=4 -DINTEL_COMMITQQ'
F90FIXEDFORMAT='-fixed -Tf'
EXTENDED_SRC_FLAG='-132'
GET_FC_VERSION="--version"
OMPFLAG='-qopenmp'

#NOOPTFLAGS='-O1 -fp-model precise'
NOOPTFLAGS='-O0'
NOOPTFILES=''

CFLAGS='-O0'
FFLAGS="$FFLAGS -convert big_endian -assume byterecl"

#- for big setups, compile & link with "-fPIC" or set memory-model to "medium":
CFLAGS="$CFLAGS -fPIC"
FFLAGS="$FFLAGS -fPIC"
#- For really big executable (> 2 GB), uncomment following 2 lines
#FFLAGS="$FFLAGS -mcmodel=medium -shared-intel"
#CFLAGS="$CFLAGS -mcmodel=medium -shared-intel"
#- might want to use '-r8' for fizhi pkg:
#FFLAGS="$FFLAGS -r8"

FFLAGS="$FFLAGS -W0 -WB"
if test "x$IEEE" = x ; then     #- with optimisation:
    FOPTIM='-O2 -ipo -fp-model precise -align -axCORE-AVX2 -xSSE4.2 -traceback -ftz'
    NOOPTFILES='seaice_growth.F calc_oce_mxlayer.F fizhi_lsm.F fizhi_clockstuff.F ini_parms.F'
    NOOPTFILES="$NOOPTFILES obcs_init_fixed.F"
else
  if test "x$DEVEL" = x ; then  #- no optimisation + IEEE :
    FOPTIM='-O0 -noalign'
  else                          #- development/check options:
   #FFLAGS="$FFLAGS -debug all -debug-parameters all -fp-model strict"
    FOPTIM="-O0 -noalign -g -traceback"
    NOOPTFLAGS=$FOPTIM
    NOOPTFILES='adread_adwrite.F'
    FOPTIM="$FOPTIM -warn all -warn nounused"
    FOPTIM="$FOPTIM -fpe0 -ftz -fp-stack-check -check all -ftrapuv"
  fi
fi

F90FLAGS=$FFLAGS
F90OPTIM=$FOPTIM

INCLUDEDIRS=''
INCLUDES=''
LIBS=''

if [ -n "$MPI_ROOT" -a "x$MPI" = xtrue ] ; then
    if [ -z "$MPI_INC_DIR" ]; then
      MPI_INC_DIR="${MPI_ROOT}/include"
    fi
    LIBS="$LIBS -L${MPI_ROOT}/lib -lmpi"
fi

if [ -n "$MPI_INC_DIR" -a "x$MPI" = xtrue ] ; then
    INCLUDES="$INCLUDES -I${MPI_INC_DIR}"
    #INCLUDEDIRS="$INCLUDEDIRS $MPI_INC_DIR"
    #- used for parallel (MPI) DIVA
    MPIINCLUDEDIR="$MPI_INC_DIR"
    #MPI_HEADER_FILES='mpif.h mpiof.h'
fi

if [ "x$NETCDF" != x ] ; then
    INCLUDES="$INCLUDES -I${NETCDF}/include"
    #INCLUDEDIRS="$INCLUDEDIRS ${NETCDF}/include"
    LIBS="$LIBS -L${NETCDF}/lib"
fi
