From bd62910c76b4d45fad3e06285e5a2bed9de8c259 Mon Sep 17 00:00:00 2001 From: DaveCasson Date: Tue, 8 Oct 2024 15:56:12 -0600 Subject: [PATCH 1/3] Update modelwrite.f90 to add in hruId to restart files The need for the hruId index has been discussed in several issues. Notably https://github.com/CH-Earth/summa/issues/253 Also https://github.com/CH-Earth/summa/pull/419, https://github.com/CH-Earth/summa/issues/401 This PR adds writing of hruId to the restart file without modification to other code and while using the existing hruInfo structure. --- build/Makefile.local | 385 +++++++++++++++++++++++++++++ build/source/netcdf/modelwrite.f90 | 46 +++- 2 files changed, 425 insertions(+), 6 deletions(-) create mode 100644 build/Makefile.local mode change 100755 => 100644 build/source/netcdf/modelwrite.f90 diff --git a/build/Makefile.local b/build/Makefile.local new file mode 100644 index 000000000..0c57fa704 --- /dev/null +++ b/build/Makefile.local @@ -0,0 +1,385 @@ +#======================================================================== +# Makefile to compile SUMMA +#======================================================================== +# +# Recommended use: Copy this file to Makefile.local, edit it to your +# heart's content, and then run `make -f build/Makefile.local` from +# your top level SUMMA directory. Don't include the Makefile.local in +# any pull requests you make. +# +# Note that Makefile configurations that we commonly use can be found on +# the SUMMA wiki at: +# https://github.com/NCAR/summa/wiki/SUMMA-Makefile-Part-0-configuration +# feel free to add yours to that page. +# +# To troubleshoot your paths and setup, type 'make check' +# +# At a minimum you will need to set the following: +# * F_MASTER - top level summa directory +# * FC - compiler suite +# * FC_EXE - compiler executable +# * INCLUDES - path to include files +# * LIBRARIES - path to and libraries to include +# +# Some further options can be specified for OpenMP, etc. See in Part 0 of +# the Makefile. You don't need to make any changes in PART 1 and +# following unless you are doing SUMMA development and changed what +# needs to be compiled + +#======================================================================== +# PART 0: User-configurable part +#======================================================================== + +# The variables can be specified in one of two ways: +# * delete the '##' in front of the variable, fill out the entry, +# save the file and run make +# * make no changes to this file, but specify the variables in your +# environment before you run make + +# Define core directory below which everything resides. This is the +# parent directory of the 'build' directory +F_MASTER = /Users/dcasson/Github/summa + +# Define the Fortran Compiler. If you are using gfortran, then this needs +# to be version 6 or higher. This variable is simply used to select the right +# compiler flags in the ifeq statements in this Makefile. The compiler +# executable is set separately as FC_EXE +# Currently this is either gfortran or ifort +FC=gfortran + +# Define the path for the compiler executable. This is the actual executable +# that is invoked. For example, FC=gfortran and FC_EXE=/usr/bin-gfortran-mp-6 +# FC and FC_EXE have to be consistent +FC_EXE =/opt/homebrew/bin/gfortran + +# Define the NetCDF and LAPACK libraries and path to include files. +# INCLUDES needs to be of the form (no quotes around the string): +# INCLUDES = -I -I -I<...> -I +# LIBRARIES needs to be of the form ( no quotes around the string): +# LIBRARIES = '-L -lnetcdff -L -lblas -L -l' +# If none of this makes sense, please talk to your system +# administrator. +INCLUDES =-I/opt/homebrew/opt/netcdf-fortran/include -I/opt/homebrew/opt/lapack/include -I/opt/homebrew/opt/openblas/include +LIBRARIES =-L/opt/homebrew/opt/netcdf-fortran/lib -lnetcdff -L/opt/homebrew/opt/lapack/lib -lblas -L/opt/homebrew/opt/openblas/lib -lopenblas + +# Eventually we plan move to a real configure script, but for now we like +# to keep track of successful compilations of SUMMA on different platforms +# and with different compilers. If you are successful compiling SUMMA, +# please add your configuration (operating system and compiler plus +# part 0 of the Makefile) to the SUMMA wiki on github. + +# Define compiler flags. If you use a different compiler, +# you will need to figure out what the equivalent flags are +# and may need to update this section + +# ------------ define compiler flags ---------------------------------------- + +# define open MP flags +isOpenMP = +FLAGS_OMP = +LIBOPENMP = + +# Define compiler flags. If you use a different compiler, +# you will need to figure out what the equivalent flags are +# and may need to update this section + +# gfortran compiler flags +ifeq "$(FC)" "gfortran" + + ifeq "$(isOpenMP)" "yes" + FLAGS_OMP = -fopenmp + endif + +# Production runs +FLAGS_NOAH = -O3 -ffree-form -ffree-line-length-none -fmax-errors=0 $(FLAGS_OMP) +FLAGS_COMM = -O3 -ffree-line-length-none -fmax-errors=0 $(FLAGS_OMP) +FLAGS_SUMMA = -O3 -ffree-line-length-none -fmax-errors=0 $(FLAGS_OMP) + +# Debug runs +#FLAGS_NOAH = -p -g -ffree-form -ffree-line-length-none -fmax-errors=0 -fbacktrace -Wno-unused -Wno-unused-dummy-argument +#FLAGS_COMM = -p -g -Wall -ffree-line-length-none -fmax-errors=0 -fbacktrace -fcheck=bounds +#FLAGS_SUMMA = -p -g -Wall -ffree-line-length-none -fmax-errors=0 -fbacktrace -fcheck=bounds + +endif + +# ifort compiler flags +ifeq "$(FC)" "ifort" + + ifeq "$(isOpenMP)" "yes" + FLAGS_OMP = -qopenmp + endif + +# Production runs +FLAGS_NOAH = -O3 -noerror_limit -FR -auto -fltconsistency $(FLAGS_OMP) +FLAGS_COMM = -O3 -FR -auto -fltconsistency -fpe0 $(FLAGS_OMP) +FLAGS_SUMMA = -O3 -FR -auto -fltconsistency -fpe0 $(FLAGS_OMP) + +# Debug runs +#FLAGS_NOAH = -O0 -p -g -warn nounused -noerror_limit -FR -auto -WB -traceback -fltconsistency +#FLAGS_COMM = -O0 -p -g -debug -warn all -check all -FR -auto -WB -traceback -fltconsistency -fpe0 +#FLAGS_SUMMA = -O0 -p -g -debug -warn all -check all -FR -auto -WB -traceback -fltconsistency -fpe0 +endif + +#======================================================================== +# PART 1: Define directory paths +#======================================================================== + +# Core directory that contains source code +F_KORE_DIR = $(F_MASTER)/build/source + +# Location of the compiled modules +MOD_PATH = $(F_MASTER)/build + +# Define the directory for the executables +EXE_PATH = $(F_MASTER)/bin + +#======================================================================== +# PART 2: Assemble all of the SUMMA sub-routines +#======================================================================== + +# Define directories +DRIVER_DIR = $(F_KORE_DIR)/driver +HOOKUP_DIR = $(F_KORE_DIR)/hookup +NETCDF_DIR = $(F_KORE_DIR)/netcdf +DSHARE_DIR = $(F_KORE_DIR)/dshare +NUMREC_DIR = $(F_KORE_DIR)/numrec +NOAHMP_DIR = $(F_KORE_DIR)/noah-mp +ENGINE_DIR = $(F_KORE_DIR)/engine + +# utilities +SUMMA_NRUTIL= \ + nrtype.f90 \ + f2008funcs.f90 \ + nr_utility.f90 +NRUTIL = $(patsubst %, $(ENGINE_DIR)/%, $(SUMMA_NRUTIL)) + +# +# Numerical recipes procedures +# NOTE: all numerical recipes procedures are now replaced with free versions +SUMMA_NRPROC= \ + expIntegral.f90 \ + spline_int.f90 +NRPROC = $(patsubst %, $(ENGINE_DIR)/%, $(SUMMA_NRPROC)) + +# Hook-up modules (set files and directory paths) +SUMMA_HOOKUP= \ + ascii_util.f90 \ + summaFileManager.f90 +HOOKUP = $(patsubst %, $(HOOKUP_DIR)/%, $(SUMMA_HOOKUP)) + +# Data modules +SUMMA_DATAMS= \ + multiconst.f90 \ + var_lookup.f90 \ + data_types.f90 \ + globalData.f90 \ + flxMapping.f90 \ + get_ixname.f90 \ + popMetadat.f90 \ + outpt_stat.f90 +DATAMS = $(patsubst %, $(DSHARE_DIR)/%, $(SUMMA_DATAMS)) + +# utility modules +SUMMA_UTILMS= \ + time_utils.f90 \ + mDecisions.f90 \ + snow_utils.f90 \ + soil_utils.f90 \ + updatState.f90 \ + matrixOper.f90 +UTILMS = $(patsubst %, $(ENGINE_DIR)/%, $(SUMMA_UTILMS)) + +# Model guts +SUMMA_MODGUT= \ + MODGUT = $(patsubst %, $(ENGINE_DIR)/%, $(SUMMA_MODGUT)) + +# Solver +SUMMA_SOLVER= \ + vegPhenlgy.f90 \ + diagn_evar.f90 \ + stomResist.f90 \ + groundwatr.f90 \ + vegSWavRad.f90 \ + vegNrgFlux.f90 \ + ssdNrgFlux.f90 \ + vegLiqFlux.f90 \ + snowLiqFlx.f90 \ + soilLiqFlx.f90 \ + bigAquifer.f90 \ + computFlux.f90 \ + computResid.f90 \ + computJacob.f90 \ + eval8summa.f90 \ + summaSolve.f90 \ + systemSolv.f90 \ + varSubstep.f90 \ + opSplittin.f90 \ + coupled_em.f90 \ + run_oneHRU.f90 \ + run_oneGRU.f90 +SOLVER = $(patsubst %, $(ENGINE_DIR)/%, $(SUMMA_SOLVER)) + +# Define routines for SUMMA preliminaries +SUMMA_PRELIM= \ + conv_funcs.f90 \ + sunGeomtry.f90 \ + convE2Temp.f90 \ + allocspace.f90 \ + checkStruc.f90 \ + childStruc.f90 \ + ffile_info.f90 \ + read_attrb.f90 \ + read_pinit.f90 \ + pOverwrite.f90 \ + read_param.f90 \ + paramCheck.f90 \ + check_icond.f90 +PRELIM = $(patsubst %, $(ENGINE_DIR)/%, $(SUMMA_PRELIM)) + +SUMMA_NOAHMP= \ + module_model_constants.F \ + module_sf_noahutl.F \ + module_sf_noahlsm.F \ + module_sf_noahmplsm.F + +NOAHMP = $(patsubst %, $(NOAHMP_DIR)/%, $(SUMMA_NOAHMP)) + +# Define routines for the SUMMA model runs +SUMMA_MODRUN = \ + indexState.f90 \ + getVectorz.f90 \ + updateVars.f90 \ + var_derive.f90 \ + read_force.f90 \ + derivforce.f90 \ + snowAlbedo.f90 \ + canopySnow.f90 \ + tempAdjust.f90 \ + snwCompact.f90 \ + layerMerge.f90 \ + layerDivide.f90 \ + volicePack.f90 \ + qTimeDelay.f90 +MODRUN = $(patsubst %, $(ENGINE_DIR)/%, $(SUMMA_MODRUN)) + +# Define routines for the solver +SUMMA_MSOLVE = \ + +# Define NetCDF routines +SUMMA_NETCDF = \ + netcdf_util.f90 \ + def_output.f90 \ + modelwrite.f90 \ + read_icond.f90 +NETCDF = $(patsubst %, $(NETCDF_DIR)/%, $(SUMMA_NETCDF)) + +# ... stitch together common programs +COMM_ALL = $(NRUTIL) $(NRPROC) $(HOOKUP) $(DATAMS) $(UTILMS) + +# ... stitch together SUMMA programs +SUMMA_ALL = $(NETCDF) $(PRELIM) $(MODRUN) $(SOLVER) + +# Define the driver routine +SUMMA_DRIVER= \ + summa_type.f90 \ + summa_util.f90 \ + summa_alarms.f90 \ + summa_globalData.f90 \ + summa_defineOutput.f90 \ + summa_init.f90 \ + summa_setup.f90 \ + summa_restart.f90 \ + summa_forcing.f90 \ + summa_modelRun.f90 \ + summa_writeOutput.f90 \ + summa_driver.f90 +DRIVER = $(patsubst %, $(DRIVER_DIR)/%, $(SUMMA_DRIVER)) + +# Define the executable +DRIVER__EX = summa.exe + +# Define version number +VERSIONFILE = $(DRIVER_DIR)/summaversion.inc +BULTTIM = $(shell date) +GITBRCH = $(shell git describe --long --all --always | sed -e's/heads\///') +GITHASH = $(shell git rev-parse HEAD) +VERSION = $(shell git show-ref --tags | grep $GITHASH | sed 's/.*tags\///' | grep . || echo "undefined") + +#======================================================================== +# PART 3: Checks +#====================================================================== +# make sure that the paths are defined. These are just some high level checks +ifndef F_MASTER + $(error F_MASTER is undefined) +endif +ifndef FC + $(error FC is undefined: Specify your compiler) +endif +ifndef FC_EXE + $(error FC_EXE is undefined: Specify your compiler executable) +endif +ifndef FLAGS_SUMMA + $(error Specify flags for your compiler: $(FC)) +endif +ifndef INCLUDES + $(error INCLUDES is undefined) +endif +ifndef LIBRARIES + $(error LIBRARIES is undefined) +endif + +#======================================================================== +# PART 4: compilation +#====================================================================== + +# Compile +all: compile_noah compile_comm compile_summa link clean install + +check: + $(info) + $(info Displaying make variables:) + $(info F_MASTER : $(F_MASTER)) + $(info EXE_PATH : $(EXE_PATH)) + $(info FC : $(FC)) + $(info INCLUDES : $(INCLUDES)) + $(info LIBRARIES : $(LIBRARIES)) + $(info FLAGS_NOAH : $(FLAGS_NOAH)) + $(info FLAGS_COMM : $(FLAGS_COMM)) + $(info FLAGS_SUMMA: $(FLAGS_SUMMA)) + $(info) + +# update version information +update_version: + echo "character(len=64), parameter :: summaVersion = '${VERSION}'" > $(VERSIONFILE) + echo "character(len=64), parameter :: buildTime = '${BULTTIM}'" >> $(VERSIONFILE) + echo "character(len=64), parameter :: gitBranch = '${GITBRCH}'" >> $(VERSIONFILE) + echo "character(len=64), parameter :: gitHash = '${GITHASH}'" >> $(VERSIONFILE) + +# compile Noah-MP routines +compile_noah: + $(FC_EXE) $(FLAGS_NOAH) -c $(NRUTIL) $(NOAHMP) + +# compile common routines +compile_comm: + $(FC_EXE) $(FLAGS_COMM) -c $(COMM_ALL) $(INCLUDES) + +# compile SUMMA routines +compile_summa: update_version + $(FC_EXE) $(FLAGS_SUMMA) -c $(SUMMA_ALL) $(DRIVER) \ + $(INCLUDES) + +# link routines +link: + $(FC_EXE) -g *.o $(LIBRARIES) -o $(DRIVER__EX) + +# Remove object files +clean: + rm -f *.o + rm -f *.mod + rm -f soil_veg_gen_parm__genmod.f90 + +# Copy the executable to the bin directory +install: + @mkdir -p $(EXE_PATH) + @mv $(DRIVER__EX) $(EXE_PATH) + $(info $(DRIVER__EX) successfully installed in $(EXE_PATH)) diff --git a/build/source/netcdf/modelwrite.f90 b/build/source/netcdf/modelwrite.f90 old mode 100755 new mode 100644 index d66e0df02..7c0c1275c --- a/build/source/netcdf/modelwrite.f90 +++ b/build/source/netcdf/modelwrite.f90 @@ -34,7 +34,7 @@ module modelwrite_module USE globalData,only:gru_struc ! gru->hru mapping structure ! netcdf deflate level -USE globalData,only: outputCompressionLevel +USE globalData,only: outputCompressionLevel ! provide access to the derived types to define the data structures USE data_types,only:& @@ -65,7 +65,7 @@ module modelwrite_module ! vector lengths USE var_lookup, only: maxvarFreq ! number of output frequencies USE var_lookup, only: maxvarStat ! number of statistics - + implicit none private @@ -439,7 +439,7 @@ subroutine writeTime(finalizeStats,outputTimestep,meta,dat,err,message) end subroutine writeTime ! ********************************************************************************************************* - ! public subroutine printRestartFile: print a re-start file + ! public subroutine writeRestart: write a re-start file ! ********************************************************************************************************* subroutine writeRestart(filename, & ! intent(in): name of restart file nGRU, & ! intent(in): number of GRUs @@ -467,7 +467,7 @@ subroutine writeRestart(filename, & ! intent(in): name of restart file USE netcdf_util_module,only:nc_file_close ! close netcdf file USE netcdf_util_module,only:nc_file_open ! open netcdf file USE globalData,only:nTimeDelay ! number of timesteps in the time delay histogram - + implicit none ! -------------------------------------------------------------------------------------------------------- ! input @@ -533,6 +533,10 @@ subroutine writeRestart(filename, & ! intent(in): name of restart file integer(i4b) :: iVar ! variable index logical(lgt) :: okLength ! flag to check if the vector length is OK character(len=256) :: cmessage ! downstream error message + + ! Declare NetCDF variable ID for hru_id + integer(i4b) :: ncHruIdID ! NetCDF variable ID for hru_id + integer(i4b), allocatable :: hruIds(:) ! Array to store hru_ids as integer(4) ! -------------------------------------------------------------------------------------------------------- ! initialize error control @@ -567,6 +571,18 @@ subroutine writeRestart(filename, & ! intent(in): name of restart file ! re-initialize error control err=0; message='writeRestart/' + ! Define hruId variable + err = nf90_def_var(ncid, 'hruId', nf90_int, (/hruDimID/), ncHruIdID) + message = 'writeRestart/defining hruId variable' + call netcdf_err(err, message) + if (err /= 0) return + + ! Add attributes to hruId variable + err = nf90_put_att(ncid, ncHruIdID, 'long_name', 'Hydrologic Response Unit ID') + call netcdf_err(err, message) + err = nf90_put_att(ncid, ncHruIdID, 'units', '1') + call netcdf_err(err, message) + ! define prognostic variables do iVar = 1,nProgVars if (prog_meta(iVar)%varType==iLookvarType%unknown) cycle @@ -617,6 +633,24 @@ subroutine writeRestart(filename, & ! intent(in): name of restart file ! end definition phase err = nf90_enddef(ncid); call netcdf_err(err,message); if (err/=0) return + ! Allocate and fill hruIds array + allocate(hruIds(nHRU)) + do iGRU = 1, nGRU + do iHRU = 1, gru_struc(iGRU)%hruCount + cHRU = gru_struc(iGRU)%hruInfo(iHRU)%hru_ix + hruIds(cHRU) = int(gru_struc(iGRU)%hruInfo(iHRU)%hru_id, kind=i4b) + end do + end do + + ! Write hruId data + err = nf90_put_var(ncid, ncHruIdID, hruIds) + message = 'writeRestart/writing hruId data' + call netcdf_err(err, message) + if (err /= 0) return + + ! Deallocate hruIds array + deallocate(hruIds) + ! write variables do iGRU = 1,nGRU do iHRU = 1,gru_struc(iGRU)%hruCount @@ -677,10 +711,10 @@ subroutine writeRestart(filename, & ! intent(in): name of restart file err=nf90_put_var(ncid,ncSoilID,(/indx_data%gru(iGRU)%hru(iHRU)%var(iLookIndex%nSoil)%dat/),start=(/cHRU/),count=(/1/)) end do ! iHRU loop - + ! write selected basin variables err=nf90_put_var(ncid,ncVarID(nProgVars+1),(/bvar_data%gru(iGRU)%var(iLookBVAR%routingRunoffFuture)%dat/), start=(/iGRU/),count=(/1,nTimeDelay/)) - + end do ! iGRU loop ! close file From 6d690e71927519b278da36ece9c568cfbba6088f Mon Sep 17 00:00:00 2001 From: DaveCasson Date: Tue, 8 Oct 2024 15:58:02 -0600 Subject: [PATCH 2/3] Update whats-new.md --- docs/whats-new.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/whats-new.md b/docs/whats-new.md index 9702ad8f3..18b5e993e 100644 --- a/docs/whats-new.md +++ b/docs/whats-new.md @@ -7,6 +7,7 @@ This page provides simple, high-level documentation about what has changed in ea ### Minor changes - Updated SWE balance check in coupled_em for cases where all snow melts in one of the substeps +- Added writing of hruId to restart files ## Version 3.2.0 ### Major changes From 37598c89bba571efd648a075902006ab0bfbf11f Mon Sep 17 00:00:00 2001 From: DaveCasson Date: Tue, 8 Oct 2024 16:00:27 -0600 Subject: [PATCH 3/3] Delete Makefile.local --- build/Makefile.local | 385 ------------------------------------------- 1 file changed, 385 deletions(-) delete mode 100644 build/Makefile.local diff --git a/build/Makefile.local b/build/Makefile.local deleted file mode 100644 index 0c57fa704..000000000 --- a/build/Makefile.local +++ /dev/null @@ -1,385 +0,0 @@ -#======================================================================== -# Makefile to compile SUMMA -#======================================================================== -# -# Recommended use: Copy this file to Makefile.local, edit it to your -# heart's content, and then run `make -f build/Makefile.local` from -# your top level SUMMA directory. Don't include the Makefile.local in -# any pull requests you make. -# -# Note that Makefile configurations that we commonly use can be found on -# the SUMMA wiki at: -# https://github.com/NCAR/summa/wiki/SUMMA-Makefile-Part-0-configuration -# feel free to add yours to that page. -# -# To troubleshoot your paths and setup, type 'make check' -# -# At a minimum you will need to set the following: -# * F_MASTER - top level summa directory -# * FC - compiler suite -# * FC_EXE - compiler executable -# * INCLUDES - path to include files -# * LIBRARIES - path to and libraries to include -# -# Some further options can be specified for OpenMP, etc. See in Part 0 of -# the Makefile. You don't need to make any changes in PART 1 and -# following unless you are doing SUMMA development and changed what -# needs to be compiled - -#======================================================================== -# PART 0: User-configurable part -#======================================================================== - -# The variables can be specified in one of two ways: -# * delete the '##' in front of the variable, fill out the entry, -# save the file and run make -# * make no changes to this file, but specify the variables in your -# environment before you run make - -# Define core directory below which everything resides. This is the -# parent directory of the 'build' directory -F_MASTER = /Users/dcasson/Github/summa - -# Define the Fortran Compiler. If you are using gfortran, then this needs -# to be version 6 or higher. This variable is simply used to select the right -# compiler flags in the ifeq statements in this Makefile. The compiler -# executable is set separately as FC_EXE -# Currently this is either gfortran or ifort -FC=gfortran - -# Define the path for the compiler executable. This is the actual executable -# that is invoked. For example, FC=gfortran and FC_EXE=/usr/bin-gfortran-mp-6 -# FC and FC_EXE have to be consistent -FC_EXE =/opt/homebrew/bin/gfortran - -# Define the NetCDF and LAPACK libraries and path to include files. -# INCLUDES needs to be of the form (no quotes around the string): -# INCLUDES = -I -I -I<...> -I -# LIBRARIES needs to be of the form ( no quotes around the string): -# LIBRARIES = '-L -lnetcdff -L -lblas -L -l' -# If none of this makes sense, please talk to your system -# administrator. -INCLUDES =-I/opt/homebrew/opt/netcdf-fortran/include -I/opt/homebrew/opt/lapack/include -I/opt/homebrew/opt/openblas/include -LIBRARIES =-L/opt/homebrew/opt/netcdf-fortran/lib -lnetcdff -L/opt/homebrew/opt/lapack/lib -lblas -L/opt/homebrew/opt/openblas/lib -lopenblas - -# Eventually we plan move to a real configure script, but for now we like -# to keep track of successful compilations of SUMMA on different platforms -# and with different compilers. If you are successful compiling SUMMA, -# please add your configuration (operating system and compiler plus -# part 0 of the Makefile) to the SUMMA wiki on github. - -# Define compiler flags. If you use a different compiler, -# you will need to figure out what the equivalent flags are -# and may need to update this section - -# ------------ define compiler flags ---------------------------------------- - -# define open MP flags -isOpenMP = -FLAGS_OMP = -LIBOPENMP = - -# Define compiler flags. If you use a different compiler, -# you will need to figure out what the equivalent flags are -# and may need to update this section - -# gfortran compiler flags -ifeq "$(FC)" "gfortran" - - ifeq "$(isOpenMP)" "yes" - FLAGS_OMP = -fopenmp - endif - -# Production runs -FLAGS_NOAH = -O3 -ffree-form -ffree-line-length-none -fmax-errors=0 $(FLAGS_OMP) -FLAGS_COMM = -O3 -ffree-line-length-none -fmax-errors=0 $(FLAGS_OMP) -FLAGS_SUMMA = -O3 -ffree-line-length-none -fmax-errors=0 $(FLAGS_OMP) - -# Debug runs -#FLAGS_NOAH = -p -g -ffree-form -ffree-line-length-none -fmax-errors=0 -fbacktrace -Wno-unused -Wno-unused-dummy-argument -#FLAGS_COMM = -p -g -Wall -ffree-line-length-none -fmax-errors=0 -fbacktrace -fcheck=bounds -#FLAGS_SUMMA = -p -g -Wall -ffree-line-length-none -fmax-errors=0 -fbacktrace -fcheck=bounds - -endif - -# ifort compiler flags -ifeq "$(FC)" "ifort" - - ifeq "$(isOpenMP)" "yes" - FLAGS_OMP = -qopenmp - endif - -# Production runs -FLAGS_NOAH = -O3 -noerror_limit -FR -auto -fltconsistency $(FLAGS_OMP) -FLAGS_COMM = -O3 -FR -auto -fltconsistency -fpe0 $(FLAGS_OMP) -FLAGS_SUMMA = -O3 -FR -auto -fltconsistency -fpe0 $(FLAGS_OMP) - -# Debug runs -#FLAGS_NOAH = -O0 -p -g -warn nounused -noerror_limit -FR -auto -WB -traceback -fltconsistency -#FLAGS_COMM = -O0 -p -g -debug -warn all -check all -FR -auto -WB -traceback -fltconsistency -fpe0 -#FLAGS_SUMMA = -O0 -p -g -debug -warn all -check all -FR -auto -WB -traceback -fltconsistency -fpe0 -endif - -#======================================================================== -# PART 1: Define directory paths -#======================================================================== - -# Core directory that contains source code -F_KORE_DIR = $(F_MASTER)/build/source - -# Location of the compiled modules -MOD_PATH = $(F_MASTER)/build - -# Define the directory for the executables -EXE_PATH = $(F_MASTER)/bin - -#======================================================================== -# PART 2: Assemble all of the SUMMA sub-routines -#======================================================================== - -# Define directories -DRIVER_DIR = $(F_KORE_DIR)/driver -HOOKUP_DIR = $(F_KORE_DIR)/hookup -NETCDF_DIR = $(F_KORE_DIR)/netcdf -DSHARE_DIR = $(F_KORE_DIR)/dshare -NUMREC_DIR = $(F_KORE_DIR)/numrec -NOAHMP_DIR = $(F_KORE_DIR)/noah-mp -ENGINE_DIR = $(F_KORE_DIR)/engine - -# utilities -SUMMA_NRUTIL= \ - nrtype.f90 \ - f2008funcs.f90 \ - nr_utility.f90 -NRUTIL = $(patsubst %, $(ENGINE_DIR)/%, $(SUMMA_NRUTIL)) - -# -# Numerical recipes procedures -# NOTE: all numerical recipes procedures are now replaced with free versions -SUMMA_NRPROC= \ - expIntegral.f90 \ - spline_int.f90 -NRPROC = $(patsubst %, $(ENGINE_DIR)/%, $(SUMMA_NRPROC)) - -# Hook-up modules (set files and directory paths) -SUMMA_HOOKUP= \ - ascii_util.f90 \ - summaFileManager.f90 -HOOKUP = $(patsubst %, $(HOOKUP_DIR)/%, $(SUMMA_HOOKUP)) - -# Data modules -SUMMA_DATAMS= \ - multiconst.f90 \ - var_lookup.f90 \ - data_types.f90 \ - globalData.f90 \ - flxMapping.f90 \ - get_ixname.f90 \ - popMetadat.f90 \ - outpt_stat.f90 -DATAMS = $(patsubst %, $(DSHARE_DIR)/%, $(SUMMA_DATAMS)) - -# utility modules -SUMMA_UTILMS= \ - time_utils.f90 \ - mDecisions.f90 \ - snow_utils.f90 \ - soil_utils.f90 \ - updatState.f90 \ - matrixOper.f90 -UTILMS = $(patsubst %, $(ENGINE_DIR)/%, $(SUMMA_UTILMS)) - -# Model guts -SUMMA_MODGUT= \ - MODGUT = $(patsubst %, $(ENGINE_DIR)/%, $(SUMMA_MODGUT)) - -# Solver -SUMMA_SOLVER= \ - vegPhenlgy.f90 \ - diagn_evar.f90 \ - stomResist.f90 \ - groundwatr.f90 \ - vegSWavRad.f90 \ - vegNrgFlux.f90 \ - ssdNrgFlux.f90 \ - vegLiqFlux.f90 \ - snowLiqFlx.f90 \ - soilLiqFlx.f90 \ - bigAquifer.f90 \ - computFlux.f90 \ - computResid.f90 \ - computJacob.f90 \ - eval8summa.f90 \ - summaSolve.f90 \ - systemSolv.f90 \ - varSubstep.f90 \ - opSplittin.f90 \ - coupled_em.f90 \ - run_oneHRU.f90 \ - run_oneGRU.f90 -SOLVER = $(patsubst %, $(ENGINE_DIR)/%, $(SUMMA_SOLVER)) - -# Define routines for SUMMA preliminaries -SUMMA_PRELIM= \ - conv_funcs.f90 \ - sunGeomtry.f90 \ - convE2Temp.f90 \ - allocspace.f90 \ - checkStruc.f90 \ - childStruc.f90 \ - ffile_info.f90 \ - read_attrb.f90 \ - read_pinit.f90 \ - pOverwrite.f90 \ - read_param.f90 \ - paramCheck.f90 \ - check_icond.f90 -PRELIM = $(patsubst %, $(ENGINE_DIR)/%, $(SUMMA_PRELIM)) - -SUMMA_NOAHMP= \ - module_model_constants.F \ - module_sf_noahutl.F \ - module_sf_noahlsm.F \ - module_sf_noahmplsm.F - -NOAHMP = $(patsubst %, $(NOAHMP_DIR)/%, $(SUMMA_NOAHMP)) - -# Define routines for the SUMMA model runs -SUMMA_MODRUN = \ - indexState.f90 \ - getVectorz.f90 \ - updateVars.f90 \ - var_derive.f90 \ - read_force.f90 \ - derivforce.f90 \ - snowAlbedo.f90 \ - canopySnow.f90 \ - tempAdjust.f90 \ - snwCompact.f90 \ - layerMerge.f90 \ - layerDivide.f90 \ - volicePack.f90 \ - qTimeDelay.f90 -MODRUN = $(patsubst %, $(ENGINE_DIR)/%, $(SUMMA_MODRUN)) - -# Define routines for the solver -SUMMA_MSOLVE = \ - -# Define NetCDF routines -SUMMA_NETCDF = \ - netcdf_util.f90 \ - def_output.f90 \ - modelwrite.f90 \ - read_icond.f90 -NETCDF = $(patsubst %, $(NETCDF_DIR)/%, $(SUMMA_NETCDF)) - -# ... stitch together common programs -COMM_ALL = $(NRUTIL) $(NRPROC) $(HOOKUP) $(DATAMS) $(UTILMS) - -# ... stitch together SUMMA programs -SUMMA_ALL = $(NETCDF) $(PRELIM) $(MODRUN) $(SOLVER) - -# Define the driver routine -SUMMA_DRIVER= \ - summa_type.f90 \ - summa_util.f90 \ - summa_alarms.f90 \ - summa_globalData.f90 \ - summa_defineOutput.f90 \ - summa_init.f90 \ - summa_setup.f90 \ - summa_restart.f90 \ - summa_forcing.f90 \ - summa_modelRun.f90 \ - summa_writeOutput.f90 \ - summa_driver.f90 -DRIVER = $(patsubst %, $(DRIVER_DIR)/%, $(SUMMA_DRIVER)) - -# Define the executable -DRIVER__EX = summa.exe - -# Define version number -VERSIONFILE = $(DRIVER_DIR)/summaversion.inc -BULTTIM = $(shell date) -GITBRCH = $(shell git describe --long --all --always | sed -e's/heads\///') -GITHASH = $(shell git rev-parse HEAD) -VERSION = $(shell git show-ref --tags | grep $GITHASH | sed 's/.*tags\///' | grep . || echo "undefined") - -#======================================================================== -# PART 3: Checks -#====================================================================== -# make sure that the paths are defined. These are just some high level checks -ifndef F_MASTER - $(error F_MASTER is undefined) -endif -ifndef FC - $(error FC is undefined: Specify your compiler) -endif -ifndef FC_EXE - $(error FC_EXE is undefined: Specify your compiler executable) -endif -ifndef FLAGS_SUMMA - $(error Specify flags for your compiler: $(FC)) -endif -ifndef INCLUDES - $(error INCLUDES is undefined) -endif -ifndef LIBRARIES - $(error LIBRARIES is undefined) -endif - -#======================================================================== -# PART 4: compilation -#====================================================================== - -# Compile -all: compile_noah compile_comm compile_summa link clean install - -check: - $(info) - $(info Displaying make variables:) - $(info F_MASTER : $(F_MASTER)) - $(info EXE_PATH : $(EXE_PATH)) - $(info FC : $(FC)) - $(info INCLUDES : $(INCLUDES)) - $(info LIBRARIES : $(LIBRARIES)) - $(info FLAGS_NOAH : $(FLAGS_NOAH)) - $(info FLAGS_COMM : $(FLAGS_COMM)) - $(info FLAGS_SUMMA: $(FLAGS_SUMMA)) - $(info) - -# update version information -update_version: - echo "character(len=64), parameter :: summaVersion = '${VERSION}'" > $(VERSIONFILE) - echo "character(len=64), parameter :: buildTime = '${BULTTIM}'" >> $(VERSIONFILE) - echo "character(len=64), parameter :: gitBranch = '${GITBRCH}'" >> $(VERSIONFILE) - echo "character(len=64), parameter :: gitHash = '${GITHASH}'" >> $(VERSIONFILE) - -# compile Noah-MP routines -compile_noah: - $(FC_EXE) $(FLAGS_NOAH) -c $(NRUTIL) $(NOAHMP) - -# compile common routines -compile_comm: - $(FC_EXE) $(FLAGS_COMM) -c $(COMM_ALL) $(INCLUDES) - -# compile SUMMA routines -compile_summa: update_version - $(FC_EXE) $(FLAGS_SUMMA) -c $(SUMMA_ALL) $(DRIVER) \ - $(INCLUDES) - -# link routines -link: - $(FC_EXE) -g *.o $(LIBRARIES) -o $(DRIVER__EX) - -# Remove object files -clean: - rm -f *.o - rm -f *.mod - rm -f soil_veg_gen_parm__genmod.f90 - -# Copy the executable to the bin directory -install: - @mkdir -p $(EXE_PATH) - @mv $(DRIVER__EX) $(EXE_PATH) - $(info $(DRIVER__EX) successfully installed in $(EXE_PATH))