#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# User: Set here the F90 compiler and options
#       Pedefined compilers: INTEL, PGF, HPUX, LAHEY
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

COMPILER = GNU
#COMPILER = LAHEY
#COMPILER = INTEL
#COMPILER = PGF
#COMPILER = HPUX

FC_GNU     = g95
FOPT_GNU   = -cpp -O -pg -fbounds-check 
FC_LAHEY   = lf95
FOPT_LAHEY = -Cpp --pca
#FOPT_LAHEY = -Cpp --chk a,e,s,u --pca --ap -O0 -g --trap
FC_INTEL   = ifort 
FOPT_INTEL = -cpp -O -mp -pc80 -prec_div -tpp7 -implicitnone
FC_PGF     = pgf90
FOPT_PGF   = -Mpreprocess -O -fast -pc 80 -Kieee
FC_HPUX    = f90
FOPT_HPUX  = -O -u +Oall +check=on

# define FULL_ALGEBRA for non-sparse integration
FC   = $(FC_$(COMPILER))
FOPT = $(FOPT_$(COMPILER)) # -DFULL_ALGEBRA

LIBS =
#LIBS = -llapack -lblas

# Command to create Matlab mex gateway routines 
# Note: use $(FC) as the mex Fortran compiler
MEX  = mex

GENSRC = strato_Precision.f90  \
	 strato_Parameters.f90     \
	 strato_Global.f90  

GENOBJ = strato_Precision.o    \
	 strato_Parameters.o       \
	 strato_Global.o     

FUNSRC = strato_Function.f90 
FUNOBJ = strato_Function.o 

JACSRC = strato_JacobianSP.f90  strato_Jacobian.f90
JACOBJ = strato_JacobianSP.o    strato_Jacobian.o

HESSRC = strato_HessianSP.f90   strato_Hessian.f90
HESOBJ = strato_HessianSP.o     strato_Hessian.o

STMSRC = strato_StoichiomSP.f90 strato_Stoichiom.f90 
STMOBJ = strato_StoichiomSP.o   strato_Stoichiom.o

UTLSRC = strato_Rates.f90 strato_Util.f90 strato_Monitor.f90
UTLOBJ = strato_Rates.o   strato_Util.o   strato_Monitor.o

LASRC  = strato_LinearAlgebra.f90 
LAOBJ  = strato_LinearAlgebra.o   

STOCHSRC = strato_Stochastic.f90 
STOCHOBJ = strato_Stochastic.o 

MAINSRC = strato_Main.f90   strato_Initialize.f90   strato_Integrator.f90 strato_Model.f90
MAINOBJ = strato_Main.o     strato_Initialize.o     strato_Integrator.o   strato_Model.o 

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# User: modify the line below to include only the
#       objects needed by your application
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ALLOBJ = $(GENOBJ) $(FUNOBJ) $(JACOBJ) $(HESOBJ) $(STMOBJ) \
	 $(UTLOBJ) $(LAOBJ)

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# User: modify the line below to include only the
#       executables needed by your application
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
all:    exe

exe:	$(ALLOBJ) $(MAINOBJ) 
	$(FC) $(FOPT) $(ALLOBJ) $(MAINOBJ) $(LIBS) -o strato.exe

stochastic:$(ALLOBJ) $(STOCHOBJ) $(MAINOBJ)
	$(FC) $(FOPT) $(ALLOBJ) $(STOCHOBJ) $(MAINOBJ) $(LIBS) \
	-o strato_stochastic.exe

mex:    $(ALLOBJ)
	$(MEX) FC#$(FC) -fortran -O strato_mex_Fun.f90     $(ALLOBJ)
	$(MEX) FC#$(FC) -fortran -O strato_mex_Jac_SP.f90  $(ALLOBJ)
	$(MEX) FC#$(FC) -fortran -O strato_mex_Hessian.f90 $(ALLOBJ)

clean:
	rm -f strato*.o strato*.mod \
	strato*.dat strato.exe strato*.mexglx \
	strato.map

distclean:
	rm -f strato*.o strato*.mod \
	strato*.dat strato.exe strato.map \
	strato*.f90 strato_*.mexglx

strato_Precision.o: strato_Precision.f90 
	$(FC) $(FOPT) -c $<

strato_Parameters.o: strato_Parameters.f90 \
	            strato_Precision.o
	$(FC) $(FOPT) -c $<

strato_Monitor.o: strato_Monitor.f90 \
	             strato_Precision.o
	$(FC) $(FOPT) -c $<

strato_Global.o: strato_Global.f90 \
	            strato_Parameters.o strato_Precision.o
	$(FC) $(FOPT) -c $<

strato_Initialize.o: strato_Initialize.f90  $(GENOBJ) 
	$(FC) $(FOPT) -c $<

strato_Function.o: strato_Function.f90  $(GENOBJ) 
	$(FC) $(FOPT) -c $<

strato_Stochastic.o: strato_Stochastic.f90  $(GENOBJ) 
	$(FC) $(FOPT) -c $<

strato_JacobianSP.o: strato_JacobianSP.f90 $(GENOBJ)
	$(FC) $(FOPT) -c $<

strato_Jacobian.o: strato_Jacobian.f90  $(GENOBJ) strato_JacobianSP.o
	$(FC) $(FOPT) -c $<

strato_LinearAlgebra.o: strato_LinearAlgebra.f90 $(GENOBJ) strato_JacobianSP.o
	$(FC) $(FOPT) -c $<

strato_Rates.o: strato_Rates.f90  $(GENOBJ) 
	$(FC) $(FOPT) -c $<

strato_HessianSP.o: strato_HessianSP.f90  $(GENOBJ)
	$(FC) $(FOPT) -c $<

strato_Hessian.o:  strato_Hessian.f90 $(GENOBJ) strato_HessianSP.o
	$(FC) $(FOPT) -c $<

strato_StoichiomSP.o: strato_StoichiomSP.f90 $(GENOBJ)
	$(FC) $(FOPT) -c $<

strato_Stoichiom.o: strato_Stoichiom.f90  $(GENOBJ) strato_StoichiomSP.o
	$(FC) $(FOPT) -c $<

strato_Util.o: strato_Util.f90  $(GENOBJ) strato_Monitor.o
	$(FC) $(FOPT) -c $<

strato_Main.o: strato_Main.f90  $(ALLOBJ) strato_Initialize.o strato_Model.o strato_Integrator.o
	$(FC) $(FOPT) -c $<

strato_Model.o: strato_Model.f90  $(ALLOBJ) strato_Integrator.o
	$(FC) $(FOPT) -c $<

strato_Integrator.o: strato_Integrator.f90  $(ALLOBJ)
	$(FC) $(FOPT) -c $<
