#!/bin/bash
#
#
#  These are the build options used with the Intel 10.x compiler for
#  testing on Beagle.
#
#  Use after
#
#    module add darwin
#    module add mitgcm
#
#  (tested with darwin/20090605 mitgcm/20090605, i.e.,
#  intel/10.0.025 mx/1.0 netcdf/3.6.2/intel-10.0.025 mpich-mx/1.2.7..7/intel-10.0.025)
#
#  These modules set FFLAGS, CFLAGS and CPPFLAGS for mpich and netcdf.
#
#  The SGE -V option for exporting environment variables may also be
#  helpful if you encounter missing-library problems.  Or,
#  alternatively, one may choose to link with one of the intel
#  "-static" or "-i-static" flags.

FC='mpif77'
CC='mpicc'
F90C='mpif90 -fixed -c '
LINK='mpif77'
for path in $(echo "$CPATH" | sed 's/:/ /g'); do
  CPPFLAGS="$CPPFLAGS -I$path"
done
INCLUDES="$CPPFLAGS"
# for static linkage:
#LIBS="$LDFLAGS -static"
# for dynamic linkage:
LIBS="$LDFLAGS -shared-intel"


# -DIFORT turns on ifort-specific declarations in darwin (RAND is not an intrinsic)
DEFINES='-DALLOW_USE_MPI -DALWAYS_USE_MPI -DWORDLENGTH=4 -DIFORT'
CPP='cpp  -traditional -P'
EXTENDED_SRC_FLAG='-132'
GET_FC_VERSION="--version"
#OMPFLAG='-openmp'

NOOPTFILES='mds_byteswapr8.F mds_byteswapr4.F mds_byteswapi4.F mom_calc_ke.F mon_ke.F'

if test "x$IEEE" = x ; then
    #  No need for IEEE-754
    NOOPTFLAGS='-O2'
    # use this for exact checkpointing (slightly slower):
    FOPTIM='-O2 -pc64 -mieee-fp -align'
    # use this for flighty faster execution but with roundoff errors in checkpointing:
    # FOPTIM='-O2 -align'
    # ifort options:
    # -132        fixed-form line length is 132 characters
    # -r8         REAL is REAL*8
    # -i4         INTEGER is INTEGER*4
    # -w95        don't warn about use of Fortran 95 extensions
    # -W0         disable all warning messages
    # -WB         turns a compile-time bounds check error into a warning
    # -xT         optimize for Intel Core2 and Xeon 51xx
    # -fno-alias  don't assume aliasing (assume that different variables DON'T refer to the same memory location)
    # -assume byterecl     record length in OPEN statements is in bytes
    # -convert big_endian  binary files contain big-endian data
    # -shared-intel        avoids static library mismatch (?)
    FFLAGS="$FFLAGS -w95 -W0 -WB -xT -fno-alias -assume byterecl -convert big_endian"
else
    #  Try to follow IEEE-754
    NOOPTFLAGS='-O0'
    # -CB         check bounds
    # FOPTIM='-O0 -noalign -CA -CB -CU -CV -CS'
    FOPTIM='-O0 -noalign'
    # -pc64       round floating point values to 64 bits
    # one could also try
    # -mp         maintain precision
    FFLAGS="$FFLAGS -pc64 -w95 -W0 -WB -xT -fno-alias -assume byterecl -convert big_endian"
fi
#- might want to use '-r8' for fizhi pkg:
#FFLAGS="$FFLAGS -r8"

F90FLAGS=$FFLAGS
F90OPTIM=$FOPTIM

NOOPTFILES=$NOOPTFILES' mds_byteswap.F'

