SHELL=/bin/sh

#
# makefile for ARPS version 3.0 to run under Unix system 
# Costomized and tested for IBM RISC/6000 running IBM AIX Version 3.2.
# Author: Ming Xue, CAPS/OU
#
# To invoke it, do 
#    make -f make.arps30 arps30.ibm
#
# For CRAY system, do 
#   make -f make.arps30 "LDR=cf77" "FFALGS= -Zv -F" arps30.cray
# which replaces the default loader by cf77 and default compiler flags
# by -Zv -F.
#
# For other systems, do 
#   make -f make.arps30 "LDR= loader_name" "FFALGS= compiler_flags" arps30.general
# where loader_name and compiler_flags are defined for perticular system. 
#
# There is a master makefile 'makefile' that contols the choice of system.
# e.g. for the CRAY system it is equivalent to do
#  make -f makefile arps30.cray
#

#
# List of ARPS30 model source files:
#

CO = co -l
CI = ci -l

ARPSSRCS = arps30.f solve3d.f step3d.f force3d.f tmix3d.f advct3d.f  \
           bc3d.f init3d.f inibase3d.f out3d.f outlib3d.f energy3d.f \
           cmix3d.f bcdif3d.f micro3d_old.f rst3d.f sfcphy3d.f raydmp3d.f \
           chksym3d.f operat3d.f divg3d.f radbc3d.f arpslib3d.f 

DUMPSRCS.ibm     = dump3d.f hdfdump3d.f pakdump3d.f svidump3d.f
DUMPSRCS.cray    = dump3d.f hdfdump3d.f pakdmpstub.f svidmpstub.f
DUMPSRCS.general = dump3d.f hdfdmpstub.f pakdmpstub.f svidmpstub.f

READSRCS.ibm     = read3d.f hdfread3d.f pakread3d.f 
READSRCS.cray    = read3d.f hdfread3d.f pakredstub.f 
READSRCS.general = read3d.f hdfredstub.f pakredstub.f 

ARPSSRCS.ibm     = $(ARPSSRCS) $(DUMPSRCS.ibm)
ARPSSRCS.cray    = $(ARPSSRCS) $(DUMPSRCS.cray)
ARPSSRCS.general = $(ARPSSRCS) $(DUMPSRCS.general)

PLTSRCS     = arpsplt25.f  arpspltlib.f 
NCARPLTSRCS = $(PLTSRCS) $(READSRCS) wirfrmstub.f
POSTPLTSRCS = $(PLTSRCS) $(READSRCS) wirfrmstub.f

CVTSRCS      = arpscvt10.f outlib3d.f
CVTSRCS.ibm  = $(CVTSRCS) $(DUMPSRCS.ibm) $(READSRCS.ibm)
CVTSRCS.cray = $(CVTSRCS) $(DUMPSRCS.cray) $(READSRCS.cray)

PRTSRCS      = arpsprt11.f arpsprtlib.f outlib3d.f 
PRTSRCS.ibm  = $(PRTSRCS) $(READSRCS.ibm)
PRTSRCS.cray = $(PRTSRCS) $(READSRCS.cray)

#
# List of include files
#
ARPSINC = dims.inc phycst.inc globcst.inc bndry.inc debug.inc grafibm.inc
ARPSPLTINC = dims.inc phycst.inc globcst.inc
ARPSCVTINC = dims.inc globcst.inc indtflg.inc grafibm.inc
ARPSPRTINC = dims.inc globcst.inc indtflg.inc 
ALLINC = dims.inc phycst.inc globcst.inc bndry.inc debug.inc grafibm.inc \
         indtflg.inc grafibm.inc
#
# List of documentation/information files: 
#
DOCS = README AboutThisVersion Subroutine.list \
       arps30.tree arpsplt.tree arpscvt.tree arpsprt.tree
#
# List of makefiles
#
MAKEFILES = makefile make.arps30.f77

#
# List of files grouped according to the function.
#
ARPS30.all = $(ARPSSRCS) $(DUMPSRCS.ibm) $(DUMPSRCS.general) $(ARPSINC) \
           may20.snd arps30.input $(MAKEFILES)

ARPSPLT.all = $(PLTSRCS) $(DUMPSRCS.ibm) $(DUMPSRCS.general) $(ARPSPLTINC) \
           wirfrmstub.f arpsplt.input $(MAKEFILES)

ARPSCVT.all = $(CVTSRCS) $(DUMPSRCS.ibm) $(DUMPSRCS.general) $(READSRCS.ibm) \
              $(READSRCS.general) $(ARPSCVTINC) arpscvt.input $(MAKEFILES)

ARPSPRT.all = $(PRTSRCS) $(READSRCS.ibm) $(READSRCS.general) \
              $(ARPSPRTINC) arpsprt.input $(MAKEFILES)

ALLFILES = $(ARPSSRCS) $(DUMPSRCS.ibm) $(DUMPSRCS.general) \
           $(ALLINC) may20.snd arps30.input \
           $(PLTSRCS) wirfrmstub.f arpsplt.input $(PRTSRCS) arpsprt.input \
           $(CVTSRCS) arpscvt.input $(READSRCS.ibm) $(READSRCS.general) \
           $(DOCS) $(MAKEFILES) arpspltmax.f arpspltmax.input

#
# List of object code to be produced: 
#
ARPSOBJS = arps30.o solve3d.o step3d.o force3d.o tmix3d.o advct3d.o  \
           bc3d.o init3d.o inibase3d.o out3d.o outlib3d.o energy3d.o \
           cmix3d.o bcdif3d.o micro3d_old.o rst3d.o sfcphy3d.o raydmp3d.o \
           chksym3d.o operat3d.o divg3d.o radbc3d.o arpslib3d.o 

DUMPOBJS.ibm     = dump3d.o hdfdump3d.o pakdump3d.o svidump3d.o
DUMPOBJS.cray    = dump3d.o hdfdump3d.o pakdmpstub.o svidmpstub.o
DUMPOBJS.general = dump3d.o hdfdmpstub.o pakdmpstub.o svidmpstub.o

READOBJS.ibm     = read3d.o hdfread3d.o pakread3d.o 
READOBJS.cray    = read3d.o hdfread3d.o pakredstub.o 
READOBJS.general = read3d.o hdfredstub.o pakredstub.o 

ARPSOBJS.ibm     = $(ARPSOBJS) $(DUMPOBJS.ibm)
ARPSOBJS.cray    = $(ARPSOBJS) $(DUMPOBJS.cray)
ARPSOBJS.general = $(ARPSOBJS) $(DUMPOBJS.general)

PLTOBJS     = arpsplt25.o  arpspltlib.o 
NCARPLTOBJS = $(PLTOBJS) $(READOBJS.ibm) wirfrmstub.o
POSTPLTOBJS = $(PLTOBJS) $(READOBJS.ibm) wirfrmstub.o

CVTOBJS      = arpscvt10.o outlib3d.o
CVTOBJS.ibm  = $(CVTOBJS) $(DUMPOBJS.ibm) $(READOBJS.ibm)
CVTOBJS.cray = $(CVTOBJS) $(DUMPOBJS.cray) $(READOBJS.cray)

PRTOBJS      = arpsprt11.o arpsprtlib.o outlib3d.o 
PRTOBJS.ibm  = $(PRTOBJS) $(READOBJS.ibm)
PRTOBJS.cray = $(PRTOBJS) $(READOBJS.cray)

#
# Executable commands to be generated by this make file:
#

ARPSCMD =	arps30_f77  
PLTCMD.ncar  = arpspltncar
PLTCMD.post  = arpspltpost
CVTCMD  = arpscvt
PRTCMD  = arpsprt
 
#
# Default name of the loader, can be replaced on the command line for other system
#
LDR = f77

#
# Link HDF and  Savi3D libraries if availabel
#
 
LIBS.ibm  = -ldf  -L/usr/local/savi3D/lib -lGraf32 
LIBS.cray = -ldf  
LIBS.general= 
PLTLIBS = -ldf
 
LDFLAGS     = 
#
# Compiler options for IBM/6000, can be replaced on the command line 
# for other system
#

FFLAGS =  -O -Q -NA16384 -ND6912 
# FFLAGS =  -F -Zv

default: arps30.general

 
########################################################################
#
# Compile and link ARPS30 model for IBM system, and generate executable 
# arps30
#
########################################################################
 
$(ARPSCMD):           $(ARPSSRCS.ibm)
arps30.ibm:           $(ARPSOBJS.ibm)
	$(LDR) -o $(ARPSCMD) $(ARPSOBJS.ibm) $(LDFLAGS) $(LIBS.ibm)
 
#
# Compile and link ARPS30 model for CRAY system, and generate executable 
# arps30
#
arps30.cray:           $(ARPSOBJS.cray)
	$(LDR) -o $(ARPSCMD) $(ARPSOBJS.cray) $(LDFLAGS) $(LIBS.cray)

#
# Compile and link ARPS30 model for a general system 
#
arps30.general:        $(ARPSOBJS.general)
	$(LDR) -o $(ARPSCMD) $(ARPSOBJS.general) $(LDFLAGS) $(LIBS.general)


########################################################################
#
# Graphic plotting: 
#
########################################################################

#
# Compile and link graphic plotting program for IBM system, 
# and generate executable arpsplt
#
arpspltncar:           $(NCARPLTOBJS)
	$(LDR) -o $(PLTCMD.ncar) $(NCARPLTOBJS) $(LDFLAGS) $(PLTLIBS)

arpspltpost:           $(POSTPLTOBJS)
	$(LDR) -o $(PLTCMD.post) $(POSTPLTOBJS) $(LDFLAGS) $(PLTLIBS)

 
#
# Compile and link graphic plotting program for CRAY system, 
# and generate executable arpsplt
#
 
arpsplt.cray:           $(PLTOBJS.cray)
	$(LDR.cray) -o $(PLTCMD) $(PLTOBJS.cray) $(LDFLAGS.cray) $(LIBS.cray)
 
########################################################################
#
# Data conversion:
#
########################################################################

#
# Compile and link data conversion program for IBM system, 
# and generate executable arpscvt
#
arpscvt.ibm:           $(CVTOBJS.ibm)
	$(LDR) -o $(CVTCMD) $(CVTOBJS.ibm) $(LDFLAGS.ibm) $(LIBS.ibm)

#
# Compile and link data conversion program for CRAY system, 
# and generate executable arpscvt
#
arpscvt.cray:           $(CVTOBJS.cray)
	$(LDR) -o $(CVTCMD) $(CVTOBJS.cray) $(LDFLAGS.cray) $(LIBS.cray)

########################################################################
#
# Data printing: 
#
########################################################################

#
# Compile and link data conversion program for IBM system, 
# and generate executable arpsprt
#
arpsprt.ibm:           $(PRTOBJS.ibm)
	$(LDR) -o $(PRTCMD) $(PRTOBJS.ibm) $(LDFLAGS.ibm) $(LIBS.ibm)

#
# Compile and link data conversion program for CRAY system, 
# and generate executable arpsprt
#
arpsprt.cray:           $(PRTOBJS.cray)
	$(LDR) -o $(PRTCMD) $(PRTOBJS.cray) $(LDFLAGS.cray) $(LIBS.cray)

########################################################################
#
# Cat all the source code files together into a single file 
#
########################################################################

arps30.src.ibm: $(ARPSSRCS.ibm)
	cat $(ARPSSRCS.ibm) > $@ 

arps30.src.cray: $(ARPSSRCS.cray)
	cat $(ARPSSRCS.cray) >  $@

Allfiles.tar: $(ALLFILES)
	/bin/tar -cvf $@ $(ALLFILES)
compare: $(ALLFILES)
	rcsdiff $(ALLFILES)

arps30.tar: $(ARPS30.all)
	/bin/tar -cvf $@ $(ARPS30.all)

arpsplt.tar: $(ARPSPLT.all)
	/bin/tar -cvf $@ $(ARPSPLT.all)

arpscvt.tar: $(ARPSCVT.all)
	/bin/tar -cvf $@ $(ARPSCVT.all)

arpsprt.tar: $(ARPSPRT.all)
	/bin/tar -cvf $@ $(ARPSPRT.all)

########################################################################
#
# Install a split version of ARPS code in directory ../$(SPLITDIR) 
#
########################################################################

SPLITDIR = arps30.split

arps30.split: arps30.src.ibm $(ARPSSRCS.ibm) Allfiles.tar $(ALLFILES)
	-mkdir ../$(SPLITDIR); /bin/rm ../$(SPLITDIR)/*; \
      mv arps30.src.ibm ../$(SPLITDIR); mv Allfiles.tar ../$(SPLITDIR); \
      cd ../$(SPLITDIR) ; /bin/tar -xvf Allfiles.tar ; /bin/rm *.f; \
      fsplit arps30.src.ibm; /bin/rm Allfiles.tar
#
# To check out from RCS all the files needed to run ARPS from RCS
#

get_arps30: force   
	co $(ARPS30.all); chmod u+w $(ARPS30.all)

#
# To check out from RCS all the files needed to run the plotting program
#

get_arpsplt: force   
	co $(ARPSPLT.all); chmod u+w $(ARPSPLT.all)

#
# To check out from RCS all the files needed to run the conversion program
#

get_arpscvt: force   
	co $(ARPSCVT.all); chmod u+w $(ARPSCVT.all)

#
# To check out from RCS all the files needed to run the printing program
#

get_arpsprt: force   
	co $(ARPSPRT.all); chmod u+w $(ARPSPRT.all)

#
# To check out from RCS all the files to do with ARPS 
#

get_all: force       
	co $(ALLFILES); chmod u+w $(ALLFILES)

########################################################################
#
# Check in files into RCS 
#
########################################################################

arps30.checkin: $(ARPSSRCS.ibm)
	ci $(ARPSSRCS.ibm)

checkin.allfiles: $(ALLFILES)
	/usr/local/bin/ci $(ALLFILES)

########################################################################
#
# Check out all source files in RCS 
#
########################################################################

arps30.checkout: $(ARPSSRCS.ibm)
	co $(ARPSSRCS.ibm)
 
########################################################################
#
# Object code dependency list:
#
########################################################################
 

#
# ARPS model:
#
 
arps30.o    	: arps30.f	dims.inc phycst.inc globcst.inc bndry.inc debug.inc
init3d.o	: init3d.f	phycst.inc globcst.inc debug.inc
inibase3d.o	: inibase3d.f	phycst.inc globcst.inc debug.inc
solve3d.o	: solve3d.f	phycst.inc globcst.inc debug.inc
step3d.o	: step3d.f	phycst.inc globcst.inc debug.inc
advct3d.o	: advct3d.f	phycst.inc globcst.inc  debug.inc
tmix3d.o	: tmix3d.f	phycst.inc globcst.inc debug.inc
force3d.o	: force3d.f	phycst.inc globcst.inc debug.inc
bc3d.o 		: bc3d.f	debug.inc
out3d.o		: out3d.f	phycst.inc globcst.inc debug.inc
outlib3d.o	: outlib3d.f	phycst.inc globcst.inc debug.inc
energy3d.o	: energy3d.f	phycst.inc globcst.inc debug.inc
chksym3d.o  	: chksym3d.f 
cmix3d.o    	: cmix3d.f	phycst.inc globcst.inc bndry.inc debug.inc
micro3d_old.o   : micro3d_old.f	phycst.inc globcst.inc bndry.inc debug.inc
bcdif3d.o   	: bcdif3d.f	debug.inc
rst3d.o     	: rst3d.f	globcst.inc debug.inc 
sfcphy3d.o  	: sfcphy3d.f	globcst.inc debug.inc
raydmp3d.o  	: raydmp3d.f	globcst.inc debug.inc
operat3d.o	: operat3d.f	debug.inc
divg3d.o	: divg3d.f	globcst.inc debug.inc
radbc3d.o	: radbc3d.f	globcst.inc phycst.inc bndry.inc
arpslib3d.o 	: arpslib3d.f
dump3d.o	: dump3d.f	phycst.inc globcst.inc debug.inc
hdfdump3d.o	: hdfdump3d.f	phycst.inc globcst.inc debug.inc
pakdump3d.o	: pakdump3d.f	phycst.inc globcst.inc debug.inc
svidump3d.o	: svidump3d.f	phycst.inc globcst.inc debug.inc grafibm.inc
hdfdmpstub.o	: hdfdmpstub.f
pakdmpstub.o	: pakdmpstub.f
svidmpstub.o    : svidmpstub.f 

#
# Plotting program files: 
#

arpsplt25.o 	: arpsplt25.f dims.inc globcst.inc
arpspltlib.o 	: arpspltlib.f phycst.inc
wirfrmstub.o 	: wirfrmstub.f

read3d.o	: read3d.f globcst.inc indtflg.inc
hdfread3d.o	: hdfread3d.f globcst.inc indtflg.inc
pakread3d.o	: pakread3d.f globcst.inc indtflg.inc
hdfredstub.o	: hdfredstub.f
pakredstub.o	: pakredstub.f

#
# Data conversion files
#

arpscvt10.o	: arpscvt10.f dims.inc globcst.inc indtflg.inc

#
# Print files: 
#

arpsprt11.o	: arpsprt11.f dims.inc globcst.inc indtflg.inc
arpsprtlib.o	: arpsprtlib.f

force:
