#
UNAMES = $(shell uname -s)
UNAMEM = $(findstring CRAY,$(shell uname -m))
#
#UNAME = $(shell /usr/local/bin/Uname)  # this does not seem to work
#----------------------------------------------------------------------
# CRAY under UNICOS (J90 or J90se):
# 
ifeq ($(UNAMEM),CRAY)
#ifeq ($(UNAME),unicos)
#CRAY_begin
#
EXEC = tgcm.unicos
FC      = f90
#
# For code that has both OMP and MIC/DIR directives, use f90 -xomp
# for MIC/DIR directives only, or f90 -xmic,dir for OMP directives only:
# $(CF) -c -I/usr/local/include $(FFLAGS) mkcdf.f
#
 FFLAGS = -xmic,dir -m4 -O2 -F overindex,nofastint -I/usr/local/include \
          -DUNICOS -DMSS
# MIC/DIR dirs
#FFLAGS = -xomp -m4 -O overindex,nofastint -DUNICOS -eX # MIC/DIR dirs + atx
#FFLAGS = -xmic,dir -m4 -O overindex,nofastint -DUNICOS # OMP dirs
#FFLAGS = -xmic,dir -m4 -O overindex,nofastint -DUNICOS -eX  # OMP dirs + atx
#
#FFLAGS = -m4 -O overindex,nofastint -DUNICOS -ef   # for perf
#FFLAGS = -m4 -O overindex,nofastint -DUNICOS -eX   # for atx
#
LIBS = -L /usr/local/lib -l ncarg,ncarg_gks,ncarg_c,X11,ncarm, \
       -l ncaro,mss,alfpack,ecmfft,fitpack,fishpak,fftpack,hpf,netcdf
LDFLAGS = -Wl"-f zeros -M,stat"
#CRAY_end
endif
#
#----------------------------------------------------------------------
# SGI O2K running IRIX64:
#
# Run scripts on ute and utefe should use (e.g. $TGCMROOT/bin/tgcm.exec):
# module load MIPSpro
# module load mpt
#
ifeq ($(UNAMES),IRIX64)
#ifeq ($(UNAME),irix)
EXEC    = tgcm.irix
FC      = f90
#
#    -mp       Generates multiprocessing code for the files being compiled.
#              This option causes the compiler to recognize all
#              multiprocessing directives and enables all -MP options.
#
MP      = -mp
#ABI     = -64
ISA     = -mips4
TARG    = -r10000
HOSTARCH    = $(MP) $(ABI) $(ISA) $(TARG)
#OLEVEL = -Ofast=ip27
OLEVEL  = -O3
FOPTS   = -r8 -OPT:IEEE_arithmetic=3:reorg_common=OFF -xdir,mic -DIRIX \
  -macro_expand -I/usr/local/include -DMSS
LIBS = \
  -L /usr/lib32/mips4 -lffio -lcomplib.sgimath -lblas_mp -lfpe \
  -L /usr/local/lib32/r4i4 -lmss -lnetcdf
#FFLAGS  = $(HOSTARCH) $(OLEVEL) $(FOPTS) $(DEBUG)
 FFLAGS  = $(HOSTARCH) $(OLEVEL) $(FOPTS)
LDFLAGS = $(HOSTARCH) $(OLEVEL)
endif
#----------------------------------------------------------------------
# IBM SP: AIX
#
ifeq ($(UNAMES),AIX)
EXEC    = tgcm.aix
#
# For profiling:
# Use -pg for gprof or xprofiler (must also be in LDFLAGS below)
#   Add -g to -pg for profiling at source level.
#   After execution, gmon.out.x files will be produced. To run
#   gprof on task 0, use: "gprof tgcm.aix gmon.out.0"
#
# Use mpxlf_r for MPI, xlf90_r for OpenMP.
#
# 5/00: use -lmass with care -- it can cause fpe trapping problems.
#
# - - - - - - - - - - - - - - - - - 
#
# For MPI:
#
 FC = mpxlf_r
 FFLAGS= -qfixed -qarch=pwr3 -qtune=pwr3 -qrealsize=8 \
 	-qalias=noaryovrlp -g -WF,-DMPI,-DAIX,-DMSS \
 	-qflttrap=zero:invalid:enable -qsigtrap=xl__trcedump \
	-I/usr/local/include
 LIBS = -L /usr/local/lib32/r4i4 -lnetcdf -lmss
# - - - - - - - - - - - - - - - - - 
#
# For OpenMP: 
# 4/19/00: -O5[4] -qstrict -qsmp=omp -qthreaded compiles, but 
#   crashes at end of lamdas. Reducing to -O3 -qstrict works.
# 6/9/00: is not crashing, but produces garbage NaN's
#   (is it necessary to make sure 4 threads are all on same node?)
#
#FC = xlf90_r
#FFLAGS= -qfixed -qarch=pwr3 -qtune=pwr3 -qrealsize=8 \
#	-qsmp=omp -qthreaded \
#	-qalias=noaryovrlp -O3 -qstrict -WF,-DAIX,-DMSS \
#	-qflttrap=zero:enable -qsigtrap=xl__trcedump \
#	-I/usr/local/include
#LIBS    = -L /usr/local/lib32/r4i4 -lnetcdf -lmss -lxlsmp
# - - - - - - - - - - - - - - - - - 
#
# For serial (no OpenMP or MPI) debug:
#
#FC = xlf90
#FFLAGS= -qfixed -qarch=pwr3 -qtune=pwr3 -qrealsize=8 \
#	-qalias=noaryovrlp -g -WF,-DAIX,-DMSS \
#	-qflttrap=zero:invalid:enable -qsigtrap=xl__trcedump \
#	-I/usr/local/include
#LIBS = -L /usr/local/lib32/r4i4 -lnetcdf -lmss
# - - - - - - - - - - - - - - - - - 
#
# -bmaxdata:0X70000000 is necessary for dz=0.25 vertical resolution.
LDFLAGS = -bloadmap:loadmap -bmaxdata:0X70000000
endif
#----------------------------------------------------------------------
# COMPAQ: OSF1 prospect (8 nodes, 4 pe/node)
# Use gmake. As of 6/00, no batch system is available (interactive only)
#
ifeq ($(UNAMES),OSF1)
#OSF1_begin
EXEC    = tgcm.osf
FC      = f90
#
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# For threaded OpenMP:
#
# 3/15/00: prospect generates internal compiler error if -omp,
#          -O5, and -fast are set. Works if -fast is removed.
# 4/00: works only with -O3 (and no -fast)
#
#FFLAGS  = -arch ev6 -omp -real_size 64 -O3 \
#	-I/usr/local/include -DOSF1 -DMSS -align dcommons
#LDFLAGS = -omp
#LIBS    = -L/usr/local/lib -lnetcdf -lmss -lelan
#
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# For mpi only:
# e.g., for 12 mpi tasks (no omp): ncpus=12, ntasks (nodes) = 3
# prun -n $ncpus -N $ntasks -t -v sh -c "$exec < $inp"
#
 FFLAGS  = -arch ev6 -real_size 64 -O3 \
	-I/usr/local/include -DOSF1 -DMPI -DMSS -align dcommons
 LDFLAGS = -lmpi -lelan
 LIBS    = -L/usr/local/lib -lnetcdf -lmss -lmpi -lelan
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# For hybrid MPI/OpenMP:
#
# Batch PBS jobs using prun command:
# OMP_NUM_THREADS should be set to the same number as -c in prun command.
# For example, to make a 12-proc (3 nodes 4 pe's/node) run:
# prun -n3 -c4 -t -v sh -c "tgcm.osf < tgcm14a.inp"
# (Use rinfo -a to see current activity on the machine)
#
# Can use -fpe2 to trap fpe's (e.g. overflows in chapmn and underflows in qrj),
#   but is slow. Can use -fpe0 -synchronous_exceptions to debug fpe's.
#
#FFLAGS  = -arch ev6 -omp -real_size 64 -O3 -fpe0 -synchronous_exceptions \
#	-I/usr/local/include -DOSF1 -DMPI -DMSS -align dcommons
#FFLAGS  = -arch ev6 -omp -real_size 64 -O3 \
#-I/usr/local/include -DOSF1 -DMPI -DMSS -align dcommons
#LDFLAGS = -omp -lmpi -lelan
#LIBS    = -L/usr/local/lib -lnetcdf -lmss -lmpi -lelan
#
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# For single-task runs for interactive debug (no omp or mpi):
# (interactive multi-task prun is not allowed) 
# Do not use fixed object code -- recompile entire code
#   (set COMPILE_ALL in run script)
# The default -fpe0 aborts on fpe's. Use -fpe2 to trap fpe's.
#
#FFLAGS  = -arch ev6 -real_size 64 -fpe0 -O3 \
#	-I/usr/local/include -DOSF1 -DMSS -align dcommons
#LDFLAGS =
#LIBS    = -L/usr/local/lib -lnetcdf -lmss -lelan
#
#OSF1_end
endif
#----------------------------------------------------------------------
# Sun:
#
ifeq ($(UNAMES),SunOS)
#SunOS_begin
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# For scd k2 Sun:
# fpversion shell command says -xtarget=ultra2 can be used.
#EXEC    = tgcm.sun
 FC      = /opt/fsc/SUNWspro/bin/f90
#
# For serial:
 FFLAGS  = -g -O -xtypemap=real:64,integer:32 -I/fs/local/include -DSUN
 LDFLAGS = 
#
# For OpenMP:
#FFLAGS  = -O3 -xtypemap=real:64,integer:32 -I/fs/local/include -DSUN \
#          -xtarget=ultra2 -ftrap=no%overflow -DMSS \
#          -mp=openmp -explicitpar -stackvar
#LDFLAGS = -O3 -explicitpar -mp=openmp
 LIBS    = -L/fs/local/lib -lnetcdf
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# For hao Sun:
# This currently does not work because the SunOS f90 compiler does not 
# support default 8-byte reals. Anyway, vishnu seg faults on input_mod.F.
#
#EXEC    = tgcm.sun
#FC      = f90
#FFLAGS  = -I/opt/local/include -DSUN
#LIBS    = -L/opt/local/lib -lnetcdf
#SunOS_end
endif
#----------------------------------------------------------------------
#EXEC_begin
#
include Objects
#OBJS = $(FSRCS:.f=.o) $(FSRCS:.F=.o)

.SUFFIXES: .F

$(EXEC):	$(OBJS)
	$(FC) -o $@ $(OBJS) $(LDFLAGS) $(LIBS)

include Depends

.f.o:
	$(FC) -c $(FFLAGS) $<
.F.o:
	$(FC) -c $(FFLAGS) $<
#EXEC_end
