-
Notifications
You must be signed in to change notification settings - Fork 105
/
Makefile
385 lines (330 loc) · 11.3 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
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 =
# 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 =
# 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 =
# 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<include path 1> -I<include path 2> -I<...> -I<include path n>
# LIBRARIES needs to be of the form ( no quotes around the string):
# LIBRARIES = '-L<netcdf library path> -lnetcdff -L<blas library path> -lblas -L<etc> -l<etc>'
# If none of this makes sense, please talk to your system
# administrator.
##INCLUDES =
##LIBRARIES =
# 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))