#
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 = -G1 -xmic,dir -m4 -O 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 \
  -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:
# (as of 5/31/00, this is how tgcm14a is compiled. To run
#  with OpenMP only or for serial debug as below, must
#  recompile entire source)  
#
 FC = mpxlf_r
 FFLAGS= -qfixed -qarch=pwr3 -qtune=pwr3 -qrealsize=8 \
 	-qalias=noaryovrlp -O3 -qstrict -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 \
#	-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 -O3 -qstrict -WF,-DAIX \
#	-qflttrap=zero:invalid:enable -qsigtrap=xl__trcedump \
#	-I/usr/local/include
#LIBS = -L /usr/local/lib32/r4i4 -lmass -lnetcdf -lmss
# - - - - - - - - - - - - - - - - - 
#
LDFLAGS = -bloadmap:loadmap
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 -fpe2 -O3 \
#	-I/usr/local/include -DOSF1 -align dcommons
#LDFLAGS = -omp
#
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# For interactive runs on prospect, can use (e.g., for 12 tasks):
# prun -n12 -t -v sh -c "tgcm.osf < tgcm14a.inp" > & ! tgcm.osf.out &
#
#FFLAGS  = -arch ev6 -real_size 64 -fpe2 -O5 -DOSF1 -DMPI \
#	-I/usr/local/include -align dcommons
#LDFLAGS = -lmpi -lelan
#
#LIBS    = -L/usr/local/lib -lnetcdf -lmss -lmpi -lelan
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# For hybrid MPI/OpenMP:
#
# Interactive runs using prun command e.g., prun -n2 -c4 for 
#   2 nodes (MPI tasks) with 4 cpus (threads) per node, 8 total procs.
# 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/node) run:
# prun -n3 -c4 -B1 -t -v sh -c "tgcm.osf < tgcm14a.inp" >&! tgcm.osf.out &
#   -B1 means start at node 1 (of 8, 0-7) (node 0 is used for i/o, etc)
# (Use rinfo -a to see current activity on the machine)
#
FFLAGS  = -arch ev6 -omp -real_size 64 -fpe2 -O3 \
	-I/usr/local/include -DOSF1 -DMPI -DMSS -align dcommons
LDFLAGS = -omp -lmpi -lelan
LIBS    = -L/usr/local/lib -lnetcdf -lmss -lmpi -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
