################################################################################
# Makefile for the Orbital, Precessional, & Insolation Quantities
#	   for the Earth from -20Myr to +10Myr
################################################################################
#
#  Choice of the Parameters:
#     The default 
# CMAR = 0
# FGAM = 1
#     corresponds to the solution La93(0,1)
#     (See ReadMe File)
#
########################################################################
CMAR = 0
FGAM = 1
########################################################################

#  Program macros
FFLAGS = 
FOR    = f77 
LIBS = -lm 

.SUFFIXES: .f .o .par .lim
# Compilation rules
.f.o: 
	$(FOR) $(FFLAGS) -c $<
# Extraction of date limits for checking purposes
.par.lim:
	grep "date.*=" $< | tr -d '+ ' | sort > $*.lim

############################################################
# Preparation of Everything:
# 1) the executable programs (pgm)
# 2) The La93 solution using the CMAR and FGAM parameters
############################################################

pgm:	prepa integ clim prep insol

La93:	prec climate
	echo "Solution with CMAR=$(CMAR) and FGAM=$(FGAM) "
	echo "   Ready for insolation computations (run insola)"

# Short names:
#1) Programs
insol:	insola
clim:	climavar
prep:	prepinsol
#2) Data
bin:	ELL.BIN
prec:	PRECN.ASC
climate: CLIVARN.ASC SOLCLI.BIN

# Actual Files
insola:	insolsub.o insola.o
	$(FOR) $(FFLAGS) insolsub.o insola.o $(LIBS) -o insola

climavar:	climavar.o
	$(FOR) $(FFLAGS) climavar.o $(LIBS) -o climavar

prepinsol:	prepinsol.o
	$(FOR) $(FFLAGS) prepinsol.o $(LIBS) -o prepinsol

integ:	integ.o integsub.o
	$(FOR) $(FFLAGS) integ.o integsub.o $(LIBS) -o integ

prepa:	prepa.o
	$(FOR) $(FFLAGS) prepa.o $(LIBS) -o prepa
 
# BIN files
ELL.BIN: prepa prepa.par
	prepa

# Precession files. 
# Note that the parameters 'datedebut' and 'datefin' are compared
#      between the two parameter files, and make stops if the
#      dates differ.
PRECN.ASC: ELL.BIN integ integ.lim prepa.lim
	diff -b integ.lim prepa.lim
	(echo $(FGAM); echo $(CMAR); echo $(FGAM); echo $(CMAR)) | integ

# Climate Computations
CLIVARN.ASC: climavar climavar.par PRECN.ASC
	climavar

SOLCLI.BIN: PRECN.ASC prepinsol prepinsol.lim integ.lim prepa.lim
	diff -b integ.lim prepa.lim
	diff -b integ.lim prepinsol.lim
	prepinsol

# Cleanup files before contructing a new La93 solution
clean:
	rm -f *.o *.lim *trace core
	rm -f SOLCLI.BIN PREC?.ASC* CLIVAR?.ASC*

# Cleanup everything (all files which can be recreated)
CLEAN:	clean
	rm -f prepa integ climavar prepinsol insola
	rm -f *.BIN
