#
# Included makefile for Intel ifort compiler on NCAR yellowstone:
# As of 2017, cheyenne is using intel 17.0.1
#
F90      = ifort
MPIF90   = mpif90
MPIRUN   = mpiexec_mpt
FFLAGS   = -r8 -heap-arrays -traceback -mcmodel=medium
LDFLAGS  = -mcmodel=medium
#
# See https://www2.cisl.ucar.edu/resources/computational-systems/cheyenne/code-development-support
#FFLAGS += 
#
# DBGFLAGS are used by the Makefile only if the job script
# has "set debug = true"
#
DBGFLAGS = -O0 -warn all,nounused -check all,noarg_temp_created -debug full,extended -nogen-interfaces
#
# -fpe-all=0 traps all floating point exceptions. The model is not
#   guaranteed not to crash if this option is set.
#
#DBGFLAGS += -fpe-all=0
#
# Makefile will use OPTIM = -g if set debug=TRUE in job script.
OPTIM    = -O3
LIBS     = -lcurl
HOST     = $(shell hostname)
#
# Library and Include file paths:
#
# ESMF lib on yellowstone:
# (tiegcm-ch.job does "module load esmf_libs/7.0.0")
#
#ESMF_LIBDIR = /glade/u/apps/ch/opt/esmf/7.0.0-ncdfio-mpi/intel/16.0.3/lib/libO/Linux.intel.64.mpi.default
export ESMF_LIBDIR
LIB_ESMF = $(ESMF_LIBDIR)
include $(LIB_ESMF)/esmf.mk
LIBS = -L$(LIB_ESMF) -Wl,-rpath=$(LIB_ESMF) -lesmf
#
# Make machines.ini file for MPI execution: 
#
prereq: machines.ini mpirun.command
machines.ini: export HN=$(HOST)
machines.ini: export NP=$(NPROC)
machines.ini: FORCE
	@echo "Making machines.ini.."
	@echo `hostname` > machines.ini
	@awk 'BEGIN{ for (i=2; i <= ENVIRON["NP"]; i++) print ENVIRON["HN"] }' >> machines.ini

mpirun.command: FORCE
	@echo "Making mpirun.command: MPIRUN=$(MPIRUN)"
	@echo $(MPIRUN) > mpirun.command

FORCE: