#------------------------------------------------------------------------------
#                  GEOS-Chem Global Chemical Transport Model                  #
#------------------------------------------------------------------------------
#BOP
#
# !MODULE: Makefile (in the GeosCore subdirectory)
#
# !DESCRIPTION: This is the main GEOS-Chem makefile.  It compiles the 
# GEOS-Chem core source code files and bundles all of the object files (*.o) 
# into the libGeosCore.a library (located in the LIB directory).  Module files 
# (*.mod) are copied to the MOD directory.
#\\
#\\
# !REMARKS:
# To build the programs, call "make" with the following syntax:
#                                                                             .
#   make -jN TARGET REQUIRED-FLAGS [ OPTIONAL-FLAGS ]
#                                                                             .
# To display a complete list of options, type "make help".
#                                                                             .
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# %%% NOTE: Most of the time this Makefile will be called automatically    %%%
# %%% from the router Makefile in the top-level directory.  However, if    %%%
# %%% you are in the ./GeosCore directory, then you can call this Makefile %%%
# %%% to build the GEOS-Chem source code, libraries, and executables.      %%%
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#                                                                             .
# Makefile uses the following variables:
#                                                                             .
# Variable   Description
# --------   -----------
# SHELL      Specifies the shell for "make" to use (usually SHELL=/bin/sh)
# ROOTDIR    Specifies the root directory for the GEOS-Chem code
# BIN        Specifies the directory where executable files are stored
# BPCH       Specifies the directory where the G-C bpch routines are stored
# DOC        Specifies the directory for generating documentation w/ ProTeX
# EXE        Specifies the name of the executable file
# HDR        Specifies the directory where include files are found
# LIB        Specifies the directory where library files (*.a) are stored
# LINK       Specifies the link commands to the GEOS-Chem library files
# KPP        Specifies the directory where th KPP solver files reside
# MOD        Specifies the directory where module files (*.mod) are stored
# NCDF       Specifies the directory where netCDF utilities are stored
# OBJ        Specifies the list of object files (*.o) to be created.
# UTIL       Specifies the directory where the G-C utility modules are found
# AR         Sys var w/ name of library creator program (i.e., "ar", "ranlib")
# MAKE       Sys var w/ name of Make command (i.e, "make" or "gmake")
# NTRAC      Cmd line argument; specifies either 43 or 54 tracer simulation
# KPPSOLVER  Cmd line argument; specifies the type of integrator to use
#                                                                             .
# NOTE: CC, F90, FREEFORM, LD, R8 are included from "Makefile_header.mk".
#                                                                             .
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# %%% You can compile GEOS-Chem in parallel using the "make -jN" option!   %%%
# %%%                                                                      %%%
# %%% N = number of proceses that you want to run simultaneously (i.e.     %%%
# %%% (when one file is finished compiling, "make" will immediately start  %%%
# %%% on the next one).  Usually N is the # of processors on your system.  %%%
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#                                                                             .
# GEOS-Chem routines will be compiled in the following order, by directory:
# ----------------------------------------------------------------------------
# (1) NcdfUtil/            : NetCDF I/O modules
# (2) Headers/             : Header files (i.e. CMN_SIZE_mod.F, etc.)
# (3) KPP/                 : KPP solver routines
# (4) GeosUtil/            : GEOS-Chem utility modules (i.e. pressure_mod.F)
# (5) HEMCO/Core/          : HEMCO Core modules
# (6) HEMCO/Extensions/    : HEMCO Extensions modules
# (7) HEMCO/Interfaces/    : HEMCO Interface modules
# (7) ISOROPIA/            : ISORROPIA aerosol thermodyn equilibrium module
# (8) GeosCore/            : "Core" GEOS-Chem modules
#
# !REVISION HISTORY: 
#  16 Sep 2009 - R. Yantosca - Initial version
#  18 Sep 2009 - P. Le Sager - Removed -lKppInt
#  21 Sep 2009 - R. Yantosca - Now call Makefile in help directory to
#                              display the help screen options
#  19 Nov 2009 - R. Yantosca - Now compile the various GEOS-Chem utility
#                              modules in the GeosUtil subdirectory
#  19 Nov 2009 - R. Yantosca - Now compile the GEOS-Chem bpch module 
#                              separately in the GeosBpch subdirectory
#  19 Nov 2009 - R. Yantosca - Now list all object dependencies explicitly,
#                              to be able to use "make -j" (parallel make)
#  23 Nov 2009 - R. Yantosca - Remove "main.o" explicitly form the "exe"
#                              makefile target.  This will be now compiled in
#                              the proper sequence given the dependency
#                              ordering.  This allows "make -j" to work. 
#  23 Nov 2009 - R. Yantosca - Now don't copy module files; they will be
#                              automatically written to the mod directory
#  23 Nov 2009 - R. Yantosca - Removed libbpch; bundled that into libutil
#  23 Nov 2009 - R. Yantosca - Added separate target libcore.  lib is now
#                              a synonym for "libkpp libutil libcore"
#  01 Dec 2009 - R. Yantosca - Modified the "exe" target for SunStudio compiler
#                              which chokes at link time if the list of object
#                              files is not explicitly passed
#  02 Dec 2009 - R. Yantosca - Add conditional statements in dependencies list
#                              for the SunStudio compiler
#  11 Dec 2009 - R. Yantosca - Now get SHELL from Makefile_header.mk
#  21 Dec 2009 - R. Yantosca - Now get LINK from Makefile_header.mk
#  25 Jan 2010 - R. Yantosca - Whem making "realclean", also call "clean" in
#                              the $(GEOSTOM)/Makefile.  Also make sure to 
#                              remove executables in the $(BIN) directory.
#  28 Jan 2010 - C. Carouge  - Modifications for ISORROPIA II
#  08 Feb 2010 - C. Carouge  - Modifications for F. Paulot's isoprene scheme
#  10 May 2010 - R. Yantosca - Add dependency for RD_AOD.f
#  14 May 2010 - C. Carouge  - Updates for mercury simulation
#  20 Aug 2010 - R. Yantosca - Modifications for MERRA met fields
#  16 Feb 2011 - R. Yantosca - Add modifications for APM (G. Luo)
#  05 Aug 2011 - M. Long     - Now compile module files in Headers/ directory
#  04 Nov 2011 - R. Yantosca - Remove references to ESMF subdirectory
#  08 Dec 2011 - M. Payer    - Remove obsolete GEIA biogenic emissions routines
#  24 Jan 2012 - R. Yantosca - Also add libnc target to build netCDF utils
#  25 Jan 2012 - R. Yantosca - Add ncdfcheck target to check netCDF install
#  05 Apr 2012 - R. Yantosca - Now assume netCDF will always be used
#  05 Apr 2012 - R. Yantosca - Now retire rdlai.F, readlai.F
#  11 Apr 2012 - R. Yantosca - Now retire obsolete lai_mod.F
#  11 Apr 2012 - R. Yantosca - Reference modis_lai_mod.F90 in timeseries diag
#  11 Apr 2012 - R. Yantosca - Remove all references to obsolete lai_mod.F
#  12 Apr 2012 - R. Yantosca - Remove reference to findmon.F
#  19 Apr 2012 - R. Yantosca - Remove reference to rd_prof.F
#  30 Oct 2012 - R. Yantosca - Remove reference to rdsoil.F
#  27 Nov 2012 - R. Yantosca - Remove reference to getifsun.F
#  27 Mar 2013 - S.D. Eastham- Rolled photolysis functions together
#  30 May 2013 - R. Yantosca - Remove reference to GEOS-3 TPCORE routines 
#  13 Aug 2013 - M. Sulprizio- Remove reference to soaprod_mod.F (no longer
#                              needed) (SOAupdate, hotp 7/25/10)
#  20 Aug 2013 - R. Yantosca - Make sure Makefile target names are consistent
#  20 Sep 2013 - R. Yantosca - Bug fix for make realclean: Don't try to make
#                              clean unless we compile for target hpc
#  27 Jan 2014 - R. Yantosca - Add tomas_mod.o to wetscav_mod dependency list
#  03 Feb 2014 - R. Yantosca - Add linoz_mod.o to input_mod.o dependency list
#  21 Feb 2014 - M. Sulprizio- Removed reference to tropopause_mod.F. It is now
#                              obsolete because of the UCX updates.
#  18 Mar 2014 - R. Yantosca - Add tauclean target to remove TAU profile files
#  19 Mar 2014 - R. Yantosca - Now restore GTMM functionality
#  19 Mar 2014 - R. Yantosca - Add more visible comment section dividers
#  11 Apr 2014 - R. Yantosca - Add modules to input_mod.o dependencies list
#  23 Jun 2014 - R. Yantosca - Remove references to obsolete logical_mod.o
#  21 Jul 2014 - R. Yantosca - Now build HEMCO emissions modules after
#                              NcdfUtil and GeosUtil, but before GeosCore
#  22 Jul 2014 - R. Yantosca - Move hcox_paranox_mod.F90, paranox_util_mod.F90
#                              and hcox_driver_mod.F90 back to HEMCO/Extensions
#  24 Jul 2014 - R. Yantosca - Remove canopy_nox_mod.F, readfert.F, readclim.F,
#                              and readsoil.F. HEMCO makes all these obsolete.
#  15 Sep 2014 - M. Sulprizio- Remove global_oc_mod.F and global_bc_mod.F.
#                              HEMCO makes these obsolete.
#  23 Sep 2014 - M. Sulprizio- Removed global_hno3_mod.F and global_no3_mod.F.
#                              HEMCO makes these obsolete.
#  04 Jun 2015 - R. Yantosca - Add wipeout target to remove any leftover
#                              library, module, or executable files
#EOP
#------------------------------------------------------------------------------
#BOC

###############################################################################
###                                                                         ###
###  Initialization section                                                 ###
###                                                                         ###
###############################################################################

# Directories
ROOT    :=..
APM     :=$(ROOT)/GeosApm
BIN     :=$(ROOT)/bin
BPCH    :=$(ROOT)/GeosBpch
DOC     :=$(ROOT)/doc
GIGC    :=$(ROOT)/GIGC
GTMM    :=$(ROOT)/GTMM
HEMCO   :=$(ROOT)/HEMCO
HDR     :=$(ROOT)/Headers
HELP    :=$(ROOT)/help
ISO     :=$(ROOT)/ISOROPIA
LIB     :=$(ROOT)/lib
KPP     :=$(ROOT)/KPP
MOD     :=$(ROOT)/mod
NCDF    :=$(ROOT)/NcdfUtil
RAD     :=$(ROOT)/GeosRad
UTIL    :=$(ROOT)/GeosUtil
DYN     :=$(GIGC)/FVdycoreCubed_GridComp

# Executables
EXE     :=geos
TOM     :=geostomas

# Include header file.  This returns CC, F90, FREEFORM, LD, R8, SHELL,
# as well as the default Makefile compilation rules for source code files.
include $(ROOT)/Makefile_header.mk

# List of source files: everything ending in .F or .F90
SOURCES :=$(wildcard *.F) $(wildcard *.F90)

# List of object files (replace .F and .F90 with .o)
TMP     :=$(SOURCES:.F=.o)
OBJECTS :=$(TMP:.F90=.o)

# List of module files.  Convert to lowercase, then prefix directory name.
MODULES :=$(OBJECTS:.o=.mod)
MODULES :=$(shell echo $(MODULES) | tr A-Z a-z)
MODULES :=$(foreach I,$(MODULES),$(MOD)/$(I))

# Library file
LIBRARY :=libcore.a

###############################################################################
###                                                                         ###
###  Makefile targets: type "make help" for a complete listing!             ###
###                                                                         ###
###############################################################################

.PHONY: clean realclean doc docclean help distclean tauclean wipeout

all:                                               # Build libraries
	@$(MAKE) lib                               #  and the executable
ifeq ($(UNAME),Darwin)
	ranlib -c ../lib/*
endif
	@$(MAKE) exe

tomas:
	@$(MAKE) TOMAS=yes lib                     # TOMAS, 30 bins (default)
	@$(MAKE) TOMAS=yes tomexe

tomas40:
	@$(MAKE) TOMAS40=yes lib                   # TOMAS, 40 bins
	@$(MAKE) TOMAS40=yes tomexe

tomas12:
	@$(MAKE) TOMAS12=yes lib                   # TOMAS, 12 bins
	@$(MAKE) TOMAS12=yes tomexe

tomas15:
	@$(MAKE) TOMAS15=yes lib                   # TOMAS, 15 bins
	@$(MAKE) TOMAS15=yes tomexe

hpc:						   # Build ESMF & MAPL
	@$(MAKE) baselibs			   # compile for HPC environment
	@$(MAKE) lib
	@$(MAKE) libgigc
ifeq ($(UNAME),Darwin)
	ranlib -c ../lib/*
endif
	@$(MAKE) exe

lib:                                               # Build all G-C libraries
	@$(MAKE) libnc
	@$(MAKE) libheaders         		  
	@$(MAKE) libkpp             		  
	@$(MAKE) libutil 
	@$(MAKE) libhemco
	@$(MAKE) libiso
	@$(MAKE) librad
	@$(MAKE) libcore			  

libcore: $(OBJECTS)                                # Build code in GeosCore/

libgigc:
	@$(MAKE) -C $(DYN) install
	@$(MAKE) -C $(GIGC) lib

libheaders:                                        # Build code in Headers/ 
	@$(MAKE) -C $(HDR)			  

libhemco:                                      
	@$(MAKE) -C $(HEMCO) lib

libiso:                                            # Build code in ISOROPIA/
	@$(MAKE) -C $(ISO)			  

librad:                                            # Build code in GeosRad/
ifeq ($(RRTMG_NEEDED),1)
	@$(MAKE) -C $(RAD)			  
endif

libkpp:                                            # Build code in KPP/
	@$(MAKE) -C $(KPP)			  

libnc:                                             # Build code in NcdfUtil/
	@$(MAKE) -C $(NCDF) libnc

libutil:                                           # Build code in GeosUtil/
	@$(MAKE) -C $(UTIL)			  

baselibs:
	@$(MAKE) -C $(GIGC) baselibs

ncdfcheck:                                         # Check netCDF library
	@$(MAKE) libnc
	@$(MAKE) -C $(NCDF) ncdfcheck

exe:                                               # Build executable
	$(LD) $(OBJECTS) $(LINK) -o $(EXE)
	cp -f $(EXE) $(BIN)

tomexe:                                            # Build executable
	$(LD) $(OBJECTS) $(LINK) -o $(TOM)
	cp -f $(TOM) $(BIN)

clean:                                             # Remove files here
	@echo "===> Making clean in directory: GeosCore <==="
	@rm -f $(OBJECTS) $(MODULES) $(LIBRARY) $(LIB)/$(LIBRARY)
	@rm -f $(EXE) $(BIN)/$(EXE)
	@rm -f $(TOM) $(BIN)/$(TOM)

distclean:                                         # Synonym for "realclean"
	@$(MAKE) realclean

realclean:                                         # Remove files everywhere
	@$(MAKE) clean
	@$(MAKE) -C $(APM)   clean
	@$(MAKE) -C $(GTMM)  clean
	@$(MAKE) -C $(HEMCO) clean
	@$(MAKE) -C $(HDR)   clean
	@$(MAKE) -C $(ISO)   clean
	@$(MAKE) -C $(KPP)   realclean
	@$(MAKE) -C $(NCDF)  clean
ifeq ($(RRTMG_CLEAN),1)
	@$(MAKE) -C $(RAD)   clean
endif
	@$(MAKE) -C $(UTIL)  clean
	@$(MAKE) docclean
ifeq ($(HPC),yes)
	@$(MAKE) -C $(GIGC) clean
endif

wipeout:
	rm -f $(LIB)/*.a
	rm -f $(MOD)/*.mod
	rm -f $(BIN)/geos*

doc:                                               # Build documentation
	@$(MAKE) -C $(DOC) doc

docclean:                                          # Remove documentation
	@$(MAKE) -C $(DOC) clean

help:                                              # Show help screen
	@$(MAKE) -C $(HELP) help

debug:
	@echo "Targets : $(MAKECMDGOALS)"
	@echo "ROOT    : $(ROOT)"
	@echo "LIB     : $(LIB)"
	@echo "MOD     : $(MOD)"
	@echo "F90     : $(F90)"
	@echo "OBJECTS : $(OBJECTS)"
	@echo "MODULES : $(MODULES)"
	@echo "LIBRARY : $(LIBRARY)"

###############################################################################
###                                                                         ###
###  Targets for Hg simulation with Global Terrestrial Mercury Model        ###
###                                                                         ###
###############################################################################

allhg:                                             # Build Hg/GTMM executable
	@$(MAKE) GTMM_Hg=yes libhg
	@$(MAKE) GTMM_Hg=yes exehg

libhg:                                             # Compile HG/GTMM code
	@$(MAKE) GTMM_Hg=yes libgtmm           		     
	@$(MAKE) GTMM_Hg=yes lib

libgtmm:                                           # Compile GTMM model code
	@$(MAKE) -C $(GTMM) GTMM_Hg=yes

exehg:                                             # Create Hg/GTMM exec file
	$(LD) $(OBJECTS) $(LINK) -o $(EXE)
	cp -f $(EXE) $(BIN)

###############################################################################
###                                                                         ###
###  Dependencies listing                                                   ###
###  (grep "USE " to get the list of module references!)                    ###
###                                                                         ###
###  From this list of dependencies, the "make" utility will figure out     ###
###  correct order of compilation (so we don't have to do that ourselves).  ###
###  This also allows us to compile on multiple processors with "make -j".  ###
###                                                                         ###
###  NOTES:                                                                 ###
###  (1) Only specify object-file dependencies that are within this         ###
###       directory.  Object files in other directories will be referenced  ### 
###       at link-time.                                                     ###
###  (2) For "make -jN" (i.e. compile N files simultaneously), all files    ###
###       in this directory must have a listed dependency.                  ###
###                                                                         ###
###############################################################################

a3_read_mod.o               : a3_read_mod.F                                  \
                              diag_mod.o

a6_read_mod.o               : a6_read_mod.F                                  \
                              dao_mod.o               diag_mod.o              

aerosol_mod.o               : aerosol_mod.F                                  \
                              chemgrid_mod.o          comode_mod.o           \
                              dao_mod.o               diag_mod.o             \
                              tracerid_mod.o          ucx_mod.o

backsub.o                   : backsub.F

benchmark_mod.o             : benchmark_mod.F                                \
                              tracerid_mod.o

bromocarb_mod.o             : bromocarb_mod.F         dao_mod.o              \
                              pbl_mix_mod.o           tracer_mod.o

c2h6_mod.o                  : c2h6_mod.F                                     \
                              diag_mod.o              tracer_mod.o           \
                              tracerid_mod.o

calcrate.o                  : calcrate.F                                     \
                              comode_mod.o            dao_mod.o              \
                              diag_mod.o              drydep_mod.o           \
                              pbl_mix_mod.o           planeflight_mod.o      \
                              tracerid_mod.o          cldice_HBrHOBr_rxn.o   \
                              ucx_mod.o               hcoi_gc_main_mod.o

carbon_mod.o                : carbon_mod.F                                   \
                              chemgrid_mod.o                                 \
                              comode_mod.o            dao_mod.o              \
                              diag_mod.o              drydep_mod.o           \
                              future_emissions_mod.o  pbl_mix_mod.o          \
                              tomas_mod.o             tracer_mod.o           \
                              tracerid_mod.o          vdiff_pre_mod.o        \
                              hcoi_gc_main_mod.o

chemdr.o                    : chemdr.F                                       \
                              aerosol_mod.o           chemgrid_mod.o         \
                              comode_mod.o            dao_mod.o              \
                              diag_oh_mod.o           diag_pl_mod.o          \
                              dust_mod.o              future_emissions_mod.o \
                              planeflight_mod.o       restart_mod.o          \
                              tracerid_mod.o

chemgrid_mod.o              : chemgrid_mod.F                                 \
                              comode_mod.o            dao_mod.o              \
                              diag_mod.o              

chemistry_mod.o             : chemistry_mod.F                                \
                              aerosol_mod.o           isoropiaII_mod.o       \
                              c2h6_mod.o              carbon_mod.o           \
                              comode_mod.o            dust_mod.o             \
                              drydep_mod.o            global_ch4_mod.o       \
                              mercury_mod.o           optdepth_mod.o         \
                              pops_mod.o              rpmares_mod.o          \
                              RnPbBe_mod.o            seasalt_mod.o          \
                              strat_chem_mod.o        sulfate_mod.o          \
                              tagged_co_mod.o         tagged_ox_mod.o        \
                              tomas_mod.o             tracerid_mod.o

cleanup.o                   : cleanup.F                                      \
                              aerosol_mod.o                                  \
                              bromocarb_mod.o         c2h6_mod.o             \
                              carbon_mod.o            chemgrid_mod.o         \
                              co2_mod.o               comode_mod.o           \
                              dao_mod.o               depo_mercury_mod.o     \
                              diag_mod.o              diag03_mod.o           \
                              diag04_mod.o            diag41_mod.o           \
                              diag50_mod.o            diag51_mod.o           \
                              diag51b_mod.o           diag53_mod.o           \
                              diag_oh_mod.o           diag_pl_mod.o          \
                              drydep_mod.o            dust_mod.o             \
                              diagnostics_mod.o       emissions_mod.o        \
                              global_ch4_mod.o        wetscav_mod.o          \
                              isoropiaII_mod.o        land_mercury_mod.o     \
                              seasalt_mod.o           linoz_mod.o            \
                              strat_chem_mod.o        mercury_mod.o          \
                              modis_lai_mod.o         ocean_mercury_mod.o    \
                              pbl_mix_mod.o           pjc_pfix_mod.o         \
                              planeflight_mod.o       sulfate_mod.o          \
                              tagged_co_mod.o         tomas_mod.o            \
                              toms_mod.o              tracer_mod.o           \
                              transport_mod.o         ucx_mod.o              \
                              uvalbedo_mod.o          tpcore_fvdas_mod.o     \
                              tpcore_geos5_window_mod.o                      \
                              tpcore_geosfp_window_mod.o                     \
                              rrtmg_rad_transfer_mod.o

cldice_HBrHOBr_rxn.o        : cldice_HBrHOBr_rxn.F

co2_mod.o                   : co2_mod.F                                      \
                              diag04_mod.o            tracerid_mod.o         \
                              hcoi_gc_main_mod.o

comode_mod.o                : comode_mod.F

convection_mod.o            : convection_mod.F                               \
                              diag_mod.o              depo_mercury_mod.o     \
                              fvdas_convect_mod.o     wetscav_mod.o          \
                              gcap_convect_mod.o      mercury_mod.o          \
                              tracer_mod.o            tracerid_mod.o

dao_mod.o                   : dao_mod.F                              

decomp.o                    : decomp.F

depo_mercury_mod.o          : depo_mercury_mod.F                             \
                              dao_mod.o               diag_mod.o             \
                              tracerid_mod.o         

diag03_mod.o                : diag03_mod.F                                   \
                              tracerid_mod.o

diag04_mod.o                : diag04_mod.F

diag1.o                     : diag1.F                                        \
                              chemgrid_mod.o          dao_mod.o              \
                              diag03_mod.o            diag_mod.o             \
                              tracer_mod.o            tracerid_mod.o

diag3.o                     : diag3.F                                        \
                              diag_mod.o              diag03_mod.o           \
                              diag04_mod.o            diag41_mod.o           \
                              diag42_mod.o            diag53_mod.o           \
                              diag56_mod.o            diag_pl_mod.o          \
                              depo_mercury_mod.o      drydep_mod.o           \
                              tomas_mod.o             tracerid_mod.o         \
                              wetscav_mod.o           hcoi_gc_main_mod.o

diag41_mod.o                : diag41_mod.F                                   \
                              pbl_mix_mod.o

diag42_mod.o                : diag42_mod.F                                   \
                              carbon_mod.o            tracerid_mod.o

diag48_mod.o                : diag48_mod.F                                   \
                              pbl_mix_mod.o           tracerid_mod.o         \
                              tracer_mod.o

diag49_mod.o                : diag49_mod.F                                   \
                              modis_lai_mod.o         pbl_mix_mod.o          \
                              tracer_mod.o            tracerid_mod.o

diag50_mod.o                : diag50_mod.F                                   \
                              chemgrid_mod.o          comode_mod.o           \
                              pbl_mix_mod.o           tracer_mod.o           \
                              tracerid_mod.o

diag51_mod.o                : diag51_mod.F                                   \
                              chemgrid_mod.o          modis_lai_mod.o        \
                              pbl_mix_mod.o           tracer_mod.o           \
                              tracerid_mod.o

diag51b_mod.o               : diag51b_mod.F                                  \
                              chemgrid_mod.o          modis_lai_mod.o        \
                              pbl_mix_mod.o           tracer_mod.o           \
                              tracerid_mod.o

diag53_mod.o                : diag53_mod.F

diag56_mod.o                : diag56_mod.F

diag63_mod.o                : diag63_mod.F                                   \
                              diag_mod.o              pbl_mix_mod.o          \
                              tracerid_mod.o          hcoi_gc_main_mod.o

diagnostics_mod.o           : diagnostics_mod.F90                            \
                              drydep_mod.o                                   \
                              hcoi_gc_main_mod.o                             \
                              tracer_mod.o                                   \
                              tracerid_mod.o                                 \
                              wetscav_mod.o

diag_2pm.o                  : diag_2pm.F                                     \
                              chemgrid_mod.o          diag_mod.o


diag_mod.o                  : diag_mod.F

diag_oh_mod.o               : diag_oh_mod.F                                  \
                              comode_mod.o            tracerid_mod.o         \
                              tracer_mod.o  

diag_pl_mod.o               : diag_pl_mod.F                                  \
                              comode_mod.o            tracerid_mod.o         \
                              tracer_mod.o

drydep_mod.o                : drydep_mod.F                                   \
                              comode_mod.o            dao_mod.o              \
                              diag_mod.o              get_ndep_mod.o         \
                              pbl_mix_mod.o           tomas_mod.o            \
                              tracerid_mod.o

diagoh.o                    : diagoh.F                                       \
                              diag_mod.o

dust_mod.o                  : dust_mod.F                                     \
                              comode_mod.o            diag_mod.o             \
                              drydep_mod.o            hcoi_gc_main_mod.o     \
                              tomas_mod.o             tracerid_mod.o

emissions_mod.o             : emissions_mod.F90                              \
                              bromocarb_mod.o                                \
                              carbon_mod.o            co2_mod.o              \
                              dust_mod.o              global_ch4_mod.o       \
                              hcoi_gc_main_mod.o      tracerid_mod.o         \
                              ucx_mod.o 

exchange_mod.o              : exchange_mod.F                                 \
	                      tpcore_bc_mod.o         dao_mod.o              \
			      tracer_mod.o

fast_jx_mod.o               : fast_jx_mod.F                                  \
                              chemgrid_mod.o          dao_mod.o              \
                              toms_mod.o              tracerid_mod.o

future_emissions_mod.o      : future_emissions_mod.F

fvdas_convect_mod.o         : fvdas_convect_mod.F                            \
                              diag_mod.o              depo_mercury_mod.o     \
                              tracerid_mod.o          tracer_mod.o

gamap_mod.o                 : gamap_mod.F                                    \
                              diag03_mod.o            diag04_mod.o           \
                              diag41_mod.o            diag42_mod.o           \
                              diag48_mod.o            diag49_mod.o           \
                              diag50_mod.o            diag51_mod.o           \
                              diag51b_mod.o           diag53_mod.o           \
                              diag56_mod.o            diag63_mod.o           \
                              diag_pl_mod.o  	      drydep_mod.o           \
                              tomas_mod.o             tracerid_mod.o         \
                              tracer_mod.o            wetscav_mod.o

ifeq ($(COMPILER),sun)
	$(F90) -O0 -c $<
endif

gasconc.o                   : gasconc.F                                      \
                              chemgrid_mod.o          comode_mod.o           \
                              drydep_mod.o

gcap_convect_mod.o          : gcap_convect_mod.F                             \
                              diag_mod.o

gcap_read_mod.o             : gcap_read_mod.F                                \
                              diag_mod.o

geosfp_read_mod.o           : geosfp_read_mod.F90                            \
                              dao_mod.o               diag_mod.o

get_global_ch4.o            : get_global_ch4.F                               \
                              future_emissions_mod.o

get_ndep_mod.o              : get_ndep_mod.F                                 \
                              tracerid_mod.o

gigc_environment_mod.o      : gigc_environment_mod.F90                       \
			      tracer_mod.o            vdiff_pre_mod.o        \
                              get_ndep_mod.o

global_br_mod.o             : global_br_mod.F                                \
                              chemgrid_mod.o          ocean_mercury_mod.o

global_ch4_mod.o            : global_ch4_mod.F                               \
                              diag_mod.o                                     \
                              diag_oh_mod.o           tracer_mod.o           \
                              vdiff_pre_mod.o         hcoi_gc_main_mod.o

hcoi_gc_diagn_mod.o         : hcoi_gc_diagn_mod.F90                          \
                              hcoi_gc_diagn_include.H                        \
                              diag_mod.o              diag53_mod.o           \
                              diag56_mod.o            tracerid_mod.o

hcoi_gc_main_mod.o          : hcoi_gc_main_mod.F90                           \
                              tracerid_mod.o          get_ndep_mod.o         \
                              drydep_mod.o            modis_lai_mod.o        \
                              fast_jx_mod.o           hcoi_gc_diagn_mod.o    \
                              tomas_mod.o

i6_read_mod.o               : i6_read_mod.F                                  \
                              diag_mod.o              

initialize.o                : initialize.F                                   \
                              diag_mod.o              diag03_mod.o           \
                              diag04_mod.o            diag41_mod.o           \
                              diag42_mod.o            diag53_mod.o           \
                              diag56_mod.o            diag_pl_mod.o

input_mod.o                 : input_mod.F                                    \
                              aerosol_mod.o           benchmark_mod.o        \
                              fvdas_convect_mod.o     carbon_mod.o           \
                              chemgrid_mod.o          depo_mercury_mod.o     \
                              diag03_mod.o            diag04_mod.o           \
                              diag41_mod.o            diag42_mod.o  	     \
                              diag48_mod.o            diag49_mod.o  	     \
                              diag50_mod.o            diag51_mod.o  	     \
                              diag51b_mod.o           diag56_mod.o  	     \
                              diag63_mod.o            diag_oh_mod.o          \
                              diag_pl_mod.o           drydep_mod.o           \
                              dust_mod.o              pops_mod.o             \
                              future_emissions_mod.o  gamap_mod.o            \
                              land_mercury_mod.o      co2_mod.o              \
                              linoz_mod.o             vdiff_pre_mod.o        \
                              mercury_mod.o           modis_lai_mod.o        \
                              ocean_mercury_mod.o     planeflight_mod.o      \
                              restart_mod.o           seasalt_mod.o          \
                              sulfate_mod.o           tomas_mod.o            \
                              tpcore_bc_mod.o         tracerid_mod.o         \
                              tracer_mod.o            transport_mod.o        \
                              wetscav_mod.o           tagged_co_mod.o        \
                              tagged_ox_mod.o         global_ch4_mod.o       \
                              c2h6_mod.o

isoropiaII_mod.o            : isoropiaII_mod.F                               \
                              chemgrid_mod.o          tracerid_mod.o

jsparse.o                   : jsparse.F               comode_mod.o

ksparse.o                   : ksparse.F

land_mercury_mod.o          : land_mercury_mod.F                             \
                              dao_mod.o               tracerid_mod.o         \
                              depo_mercury_mod.o      modis_lai_mod.o        \
                              hcoi_gc_main_mod.o

linoz_mod.o                 : linoz_mod.F                                    \
                              chemgrid_mod.o          tracerid_mod.o

lump.o                      : lump.F                                         \
                              comode_mod.o            tracerid_mod.o

main.o                      : main.F                                         \
                              a3_read_mod.o           a6_read_mod.o          \
                              benchmark_mod.o                                \
                              chemgrid_mod.o          chemistry_mod.o        \
                              carbon_mod.o            convection_mod.o       \
                              comode_mod.o            diag_mod.o             \
                              diagnostics_mod.o                              \
                              diag41_mod.o            diag42_mod.o           \
                              diag48_mod.o            diag49_mod.o           \
                              diag50_mod.o            diag51_mod.o           \
                              diag51b_mod.o           diag63_mod.o           \
                              diag_oh_mod.o           dao_mod.o              \
                              depo_mercury_mod.o      drydep_mod.o           \
                              toms_mod.o              gcap_read_mod.o        \
                              geosfp_read_mod.o       gigc_environment_mod.o \
                              global_ch4_mod.o        i6_read_mod.o          \
                              input_mod.o             linoz_mod.o            \
                              mapping_mod.o           toms_mod.o             \
                              mercury_mod.o           merra_cn_mod.o         \
                              merra_a1_mod.o          merra_a3_mod.o         \
                              merra_i6_mod.o          modis_lai_mod.o        \
                              ocean_mercury_mod.o     olson_landmap_mod.o    \
                              pbl_mix_mod.o           planeflight_mod.o      \
                              restart_mod.o           tracer_mod.o           \
                              strat_chem_mod.o        transport_mod.o        \
                              tpcore_bc_mod.o         uvalbedo_mod.o         \
                              tracerid_mod.o          wetscav_mod.o          \
                              ucx_mod.o               vdiff_mod.o            \
                              emissions_mod.o         cleanup.o              \
                              mixing_mod.o                                   \
                              rrtmg_rad_transfer_mod.o

mapping_mod.o               : mapping_mod.F90                              

mercury_mod.o               : mercury_mod.F                                  \
                              chemgrid_mod.o          dao_mod.o              \
                              depo_mercury_mod.o      diag03_mod.o           \
                              diag_mod.o              drydep_mod.o           \
                              global_br_mod.o         vdiff_pre_mod.o        \
                              land_mercury_mod.o      hcoi_gc_main_mod.o     \
                              ocean_mercury_mod.o     tracerid_mod.o         \
                              pbl_mix_mod.o

merra_a1_mod.o              : merra_a1_mod.F                                 \
                              diag_mod.o

merra_a3_mod.o              : merra_a3_mod.F                                 \
                              dao_mod.o               diag_mod.o

merra_cn_mod.o              : merra_cn_mod.F                                 \
                              diag_mod.o

merra_i6_mod.o              : merra_i6_mod.F

mixing_mod.o                : mixing_mod.F90                                 \
                              chemgrid_mod.o                                 \
                              dao_mod.o                                      \
                              diag_mod.o                                     \
                              drydep_mod.o                                   \
                              hcoi_gc_main_mod.o                             \
                              get_ndep_mod.o                                 \
                              pbl_mix_mod.o                                  \
                              tracerid_mod.o                                 \
                              vdiff_mod.o                                    

modis_lai_mod.o             : modis_lai_mod.F90       mapping_mod.o

nc_soilnox_read.o           : nc_soilnox_read.F90

ndxx_setup.o                : ndxx_setup.F                                   \
                              diag_mod.o                                     \
                              diag63_mod.o            diag_oh_mod.o          \
                              drydep_mod.o            planeflight_mod.o      \
                              tomas_mod.o             tracer_mod.o           \
                              tracerid_mod.o          wetscav_mod.o

ocean_mercury_mod.o         : ocean_mercury_mod.F                            \
                              dao_mod.o               depo_mercury_mod.o     \
                              diag03_mod.o            tracerid_mod.o


ohsave.o                    : ohsave.F                                       \
                              comode_mod.o            tracerid_mod.o

olson_landmap_mod.o         : olson_landmap_mod.F90                          \
                              mapping_mod.o

optdepth_mod.o              : optdepth_mod.F          diag_mod.o  

partition.o                 : partition.F                                    \
                              comode_mod.o            tracerid_mod.o

pbl_mix_mod.o               : pbl_mix_mod.F                                  \
                              diag_mod.o              tracer_mod.o

pderiv.o                    : pderiv.F

physproc.o                  : physproc.F                                     \
                              comode_mod.o            chemistry_mod.o

pjc_pfix_geos5_window_mod.o : pjc_pfix_geos5_window_mod.F

pjc_pfix_geosfp_window_mod.o: pjc_pfix_geosfp_window_mod.F

pjc_pfix_mod.o              : pjc_pfix_mod.F

planeflight_mod.o           : planeflight_mod.F                              \
                              chemgrid_mod.o          comode_mod.o           \
                              diag_mod.o              ocean_mercury_mod.o    \
                              tracer_mod.o

pops_mod.o           	    : pops_mod.F    	                             \
			      diag_mod.o	      diag53_mod.o           \
                              drydep_mod.o                                   \
                              pbl_mix_mod.o	      tracerid_mod.o         \
                              vdiff_pre_mod.o

readchem.o                  : readchem.F                                     \
                              diag_pl_mod.o           drydep_mod.o

reader.o                    : reader.F

read_jv_atms_dat.o          : read_jv_atms_dat.F90

restart_mod.o               : restart_mod.F                                  \
                              comode_mod.o            

RnPbBe_mod.o                : RnPbBe_mod.F                                   \
                              chemgrid_mod.o          diag_mod.o             \
                              tracerid_mod.o                                 \
                              hcoi_gc_main_mod.o

rrtmg_rad_transfer_mod.o    : rrtmg_rad_transfer_mod.F                        \
                              chemgrid_mod.o          comode_mod.o            \
                              diag_mod.o              set_prof_o3.o           \
                              toms_mod.o              tracerid_mod.o

rpmares_mod.o               : rpmares_mod.F                                  \
                              chemgrid_mod.o                                 \
                              tracer_mod.o            tracerid_mod.o

ruralbox.o                  : ruralbox.F                                     \
                              chemgrid_mod.o          comode_mod.o  

seasalt_mod.o               : seasalt_mod.F           dao_mod.o              \
                              diag_mod.o              drydep_mod.o           \
                              pbl_mix_mod.o           tomas_mod.o            \
                              tracerid_mod.o          vdiff_pre_mod.o        \
                              tracer_mod.o            hcoi_gc_main_mod.o

set_prof_o3.o               : set_prof_o3.F                                   

setemdep.o                  : setemdep.F                                     \
                              tracerid_mod.o

setemis.o                   : setemis.F                                      \
                              chemgrid_mod.o          comode_mod.o           \
                              pbl_mix_mod.o           tracerid_mod.o         \
                              hcoi_gc_main_mod.o

ucx_mod.o                   : ucx_mod.F                                      \
                              chemgrid_mod.o          global_ch4_mod.o       \
                              fast_jx_mod.o           hcoi_gc_main_mod.o     \
                              tracer_mod.o                                   \
                              tracerid_mod.o          future_emissions_mod.o

setmodel.o                  : setmodel.F

smvgear.o                   : smvgear.F                                      \
                              comode_mod.o

soil_nox_mod.o              : soil_nox_mod.F

strat_chem_mod.o            : strat_chem_mod.F90                             \
                              chemgrid_mod.o          dao_mod.o              \
                              linoz_mod.o             tagged_ox_mod.o        \
                              tracer_mod.o            tracerid_mod.o

subfun.o                    : subfun.F

sulfate_mod.o               : sulfate_mod.F                                  \
                              chemgrid_mod.o          comode_mod.o           \
                              dao_mod.o               diag_mod.o             \
                              drydep_mod.o                                   \
                              future_emissions_mod.o  get_ndep_mod.o         \
                              pbl_mix_mod.o                                  \
                              wetscav_mod.o           tomas_mod.o            \
                              tracer_mod.o            tracerid_mod.o         \
                              ucx_mod.o               uvalbedo_mod.o         \
                              vdiff_pre_mod.o         wetscav_mod.o

tagged_co_mod.o             : tagged_co_mod.F                                \
                              tracer_mod.o            hcoi_gc_main_mod.o     \
                              chemgrid_mod.o          diag_mod.o             \
                              diag_pl_mod.o           pbl_mix_mod.o          \
                              tracerid_mod.o

tagged_ox_mod.o             : tagged_ox_mod.F                                \
                              chemgrid_mod.o          diag_mod.o             \
                              diag_pl_mod.o           drydep_mod.o           \
                              pbl_mix_mod.o           tracerid_mod.o         \
                              hcoi_gc_main_mod.o

tcorr.o                     : tcorr.F

toms_mod.o                  : toms_mod.F

tpcore_bc_mod.o             : tpcore_bc_mod.F                                \
                              tracer_mod.o

tpcore_geos5_window_mod.o   : tpcore_geos5_window_mod.F90
ifeq ($(PRECISION),8)
	$(F90) -c $(FREEFORM) $(R8) $<
endif

tpcore_geosfp_window_mod.o  : tpcore_geosfp_window_mod.F90
ifeq ($(PRECISION),8)
	$(F90) -c $(FREEFORM) $(R8) $<
endif

tracer_mod.o                : tracer_mod.F

tracerid_mod.o              : tracerid_mod.F                                 \
                              tracer_mod.o

transport_mod.o             : transport_mod.F                                \
                              diag_mod.o              pjc_pfix_mod.o         \
                              tpcore_bc_mod.o         tpcore_fvdas_mod.o     \
                              tracer_mod.o                                   \
                              tpcore_geos5_window_mod.o                      \
                              tpcore_geosfp_window_mod.o                     \
                              pjc_pfix_geos5_window_mod.o                    \
                              pjc_pfix_geosfp_window_mod.o

update.o                    : update.F

uvalbedo_mod.o              : uvalbedo_mod.F90

vdiff_pre_mod.o             : vdiff_pre_mod.F90
ifeq ($(COMPILER),sun)
	$(F90) -O3 -c $<
endif

vdiff_mod.o                 : vdiff_mod.F90                                  \
                              comode_mod.o            dao_mod.o              \
                              depo_mercury_mod.o      diag_mod.o             \
                              drydep_mod.o            ocean_mercury_mod.o    \
                              pbl_mix_mod.o           vdiff_pre_mod.o        \
                              tracer_mod.o            tracerid_mod.o         \
                              hcoi_gc_main_mod.o      global_ch4_mod.o       \
                              mercury_mod.o      

wetscav_mod.o               : wetscav_mod.F                                  \
                              dao_mod.o               diag_mod.o             \
                              depo_mercury_mod.o      get_ndep_mod.o         \
                              tracerid_mod.o          tracer_mod.o           \
                              tomas_mod.o

###############################################################################
###                                                                         ###
###  Dependencies of files specific to the TOMAS microphysics simulation    ###
###                                                                         ###
###############################################################################

tomas_mod.o                 : tomas_mod.F                                    \
                              chemgrid_mod.o          dao_mod.o              \
                              diag_mod.o              diag_pl_mod.o          \
                              tracerid_mod.o          YuIMN_Code.o 

tomas_tpcore_mod.o          : tomas_tpcore_mod.F90                           \
                              tomas_mod.o             tracerid_mod.o


aero_drydep.o               : aero_drydep.F                                  \
                              chemgrid_mod.o          diag_mod.o             \
                              drydep_mod.o            dust_mod.o             \
                              pbl_mix_mod.o           tomas_mod.o            \
                              tracerid_mod.o

YuIMN_Code.o                : YuIMN_Code.F

#EOC
