-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVIC_global_sim_0p25_1960-2024.sh
More file actions
363 lines (303 loc) · 14.4 KB
/
Copy pathVIC_global_sim_0p25_1960-2024.sh
File metadata and controls
363 lines (303 loc) · 14.4 KB
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
#!/bin/sh
#==========================================================
# CaMa-Flood sample go script (1) global 15min simulation
# -- Multi 1-year simulations (2000 spinup -> 2000 -> 2001)
# -- Daily runoff forcing (plain binary) at 1deg resolution
#
# (C) D.Yamazaki & E. Dutra (U-Tokyo/FCUL) Aug 2019
#
# Licensed under the Apache License, Version 2.0 (the "License");
# You may not use this file except in compliance with the License.
# You may obtain a copy of the License at: http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software distributed under the License is
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and limitations under the License.
#==========================================================
#*** PBS setting when needed
#PBS -N era5-runoff-glb_15min
#PBS -l select=1:ncpus=128:mem=256G
#PBS -q normal
#PBS -l walltime=24:00:00
#PBS -P 11004044
#PBS -o ./era5_drived_JULES_15min_output.txt
#PBS -e ./era5_drived_JULES_15min_error.txt
#================================================
# (0) Basic Setting (for workstation)
#*** 0a. Set CaMa-Flood base directory
CURRDIR="/home/petrichor/ymwang/snap/CAMA-FLOOD/cmf_v420/gosh/"
BASE=$CURRDIR/..
# BASE="/home/yamadai/work/CaMa_v411/cmf_v411_pkg" # setting for PBS in cluster
echo $BASE
#*** 0b. Set dynamic library if needed
export IFORTLIB="/opt/intel/lib:/opt/intel/mkl/lib"
export HDF5LIB="/opt/local/hdf5-1.10.5/lib"
export DYLD_LIBRARY_PATH="${HDF5LIB}:${IFORTLIB}:${DYLD_LIBRARY_PATH}"
#*** 0c. OpenMP thread number
export OMP_NUM_THREADS=128 # OpenMP cpu num
#================================================
# (1) Experiment setting
# -- some non-default options can be modified in NAMELIST section
#============================
#*** 1a. Experiment directory setting
EXP="using_runoff_VIC" # experiment name (output directory name)
RDIR=${BASE}/out/${EXP} # directory to run CaMa-Flood
EXE="MAIN_cmf" # Execute file name
PROG=${BASE}/src/${EXE} # location of Fortran main program
NMLIST="./input_cmf.nam" # standard namelist
LOGOUT="./log_CaMa.txt" # standard log output
#============================
#*** 1b. Model physics option
DT=86400 # base DT (modified in physics loop by LADPSTP)
LADPSTP=".TRUE." # .TRUE. for adaptive time step
LPTHOUT=".TRUE." # .TRUE. to activate bifurcation flow, mainly for delta simulation
LDAMOUT=".FALSE." # .TRUE. to activate reservoir operation (under development)
#============================
#*** 1c. simulation time
YSTA=1960 # start year ( from YSTA / Jan 1st _ 00:00)
YEND=2024 # end year (until YEND / Dec 31st _ 24:00)
SPINUP=0 # [0]: zero-storage start, [1]: from restart file
NSP=0 # spinup repeat time
#============================
#*** 1d. spinup setting
#* input restart file
LRESTART="" # see (3) set each year # TRUE. to use restart initial condition
CRESTSTO="" # see (3) set each year # input restart FIle
#* output restart file
CRESTDIR="./" # output restart file directory
CVNREST="restart" # output restart file prefix
LRESTCDF=".FALSE." # .TRUE. to use netCDF restart file
IFRQ_RST="0" # output restat frequency.
# [0]: only at last time, [1,2,3,...,24] hourly restart, [30]: monthly restart
#============================
#*** 1e. forcing setting
IFRQ_INP="24" # input forcing frequency: [1,2,3,...,24] hour
DROFUNIT="86400000" # [m/day->m/s] # runoff unit conversion
# #----- for plain binary runoff forcing
# LINPCDF=".FALSE." # true for netCDF runoff
# LINTERP=".TRUE." # .TRUE. to interporlate with input matrix
# CROFDIR="${BASE}/inp/test_1deg/runoff/" # runoff directory
# CROFPRE="Roff____" # runoff prefix/suffix
# CROFSUF=".one" # $(CROFPRE)YYYYMMDD$(CROFSUF)
# #----- for plain binary runoff forcing
LINPCDF=".FALSE." # true for netCDF runoff
LINTERP=".TRUE." # .TRUE. to interporlate with input matrix
CROFDIR="${BASE}/../../data/runoff_VIC/runoff/" # runoff directory
CROFPRE="Roff____" # runoff prefix/suffix
CROFSUF=".one" # $(CROFPRE)YYYYMMDD$(CROFSUF)
#============================
#*** 1f. river map & topography
FMAP="${BASE}/map/glb_noAntarctica_15min" # map directory
CDIMINFO="${FMAP}/diminfo_test-15min_nc.txt" # dimention information file
CINPMAT=${FMAP}/inpmat_test-15min_nc.bin # runoff input matrix for interporlation
#----- for plain binary map input
#** basic topography
LMAPCDF=".FALSE." # .TRUE. for netCDF map
CNEXTXY="${FMAP}/nextxy.bin" # downstream xy (river network map)
CGRAREA="${FMAP}/ctmare.bin" # unit-catchment area [m2]
CELEVTN="${FMAP}/elevtn.bin" # channel top elevation [m]
CNXTDST="${FMAP}/nxtdst.bin" # downstream distance [m]
CRIVLEN="${FMAP}/rivlen.bin" # channel length [m]
CFLDHGT="${FMAP}/fldhgt.bin" # floodplain elevation profile (height above 'elevtn') [m]
#** channel parameter
###CRIVWTH=${FMAP}/rivwth.bin" # channel width [m] (empirical power-low)
CRIVWTH="${FMAP}/rivwth_gwdlr.bin" # channel width [m] (GWD-LR + filled with empirical)
CRIVHGT="${FMAP}/rivhgt.bin" # channel depth [m] (empirical power-low)
CRIVMAN="${FMAP}/rivman.bin" # manning coefficient river (The one in flood plain is a global parameter; set $PMANFLD below.)
#** bifurcation channel info
CPTHOUT="${FMAP}/bifprm.txt" # bifurcation channel list
#============================
#*** 1h. Output Settings
IFRQ_OUT=24 # output frequency: [1,2,3,...,24] hour
LOUTCDF=".FALSE." # .TRUE. netCDF output, .FALSE. plain binary output
COUTDIR="./" # output directory
#CVARSOUT="outflw,storge,fldfrc,maxdph,flddph" # list output variable (comma separated)
CVARSOUT="rivout,rivsto,rivdph,rivvel,fldout,fldsto,flddph,fldfrc,fldare,sfcelv,outflw,storge,pthflw,pthout,maxsto,maxflw,maxdph" # list output variable (comma separated)
COUTTAG="" # see (3) set each year # output tag $(COUTDIR)/$(VARNAME)$(OUTTAG).bin
##### Model Parameters ################
PMANRIV="0.03D0" # manning coefficient river
PMANFLD="0.10D0" # manning coefficient floodplain
PCADP="0.7" # satety coefficient for CFL condition
PDSTMTH="10000.D0" # downstream distance at river mouth [m]
#================================================
# (2) Initial setting
#*** 2a. create running dir
mkdir -p ${RDIR}
cd ${RDIR}
#*** 2b. for new simulation, remove old files in running directory
if [ ${SPINUP} -eq 0 ]; then
rm -rf ${RDIR}/????-sp*
rm -rf ${RDIR}/*.bin
rm -rf ${RDIR}/*.pth
rm -rf ${RDIR}/*.vec
rm -rf ${RDIR}/*.nc
rm -rf ${RDIR}/*.log
rm -rf ${RDIR}/*.txt
rm -rf ${RDIR}/restart*
else
NSP=0 # restart, no spinup
fi
#================================================
# (3) For each simulation year, modify setting
#-- loop 1-year simulation from $YSTART to $YEND
ISP=1 ## spinup count
IYR=${YSTA} ## curent year
while [ ${IYR} -le ${YEND} ];
do
CYR=`printf %04d ${IYR}` ## update file name, bugfix in v3.96a
#*** 3a. modify restart setting
if [ ${SPINUP} -eq 0 ];then
LRESTART=".FALSE." ## from zero storage
CRESTSTO=""
else
LRESTART=".TRUE."
CRESTSTO="${CVNREST}${CYR}010100.bin" ## from restart file
if [ ${LRESTCDF} = ".TRUE." ]; then
CRESTSTO="${CVNREST}${CYR}010100.nc" ## from restart file
fi
fi
#*** 3b. update start-end year
SYEAR=$IYR
SMON=1
SDAY=1
SHOUR=0
EYEAR=`expr $SYEAR + 1`
EMON=1
EDAY=1
EHOUR=0
ln -sf $PROG $EXE
#*** 3c. update input / output file data
CSYEAR=`printf %04d ${SYEAR}`
COUTTAG=${CSYEAR} # output file tag
#================================================
# (4) Create NAMELIST for simulation year
# it is OK to remove optional variables (set to default in CaMa-Flood)
rm -f ${NMLIST}
#*** 0. config
cat >> ${NMLIST} << EOF
&NRUNVER
LADPSTP = ${LADPSTP} ! true: use adaptive time step
LPTHOUT = ${LPTHOUT} ! true: activate bifurcation scheme
LDAMOUT = ${LDAMOUT} ! true: activate dam operation (under development)
LRESTART = ${LRESTART} ! true: initial condition from restart file
/
&NDIMTIME
CDIMINFO = "${CDIMINFO}" ! text file for dimention information
DT = ${DT} ! time step length (sec)
IFRQ_INP = ${IFRQ_INP} ! input forcing update frequency (hour)
/
&NPARAM
PMANRIV = ${PMANRIV} ! manning coefficient river
PMANFLD = ${PMANFLD} ! manning coefficient floodplain
PDSTMTH = ${PDSTMTH} ! downstream distance at river mouth [m]
PCADP = ${PCADP} ! CFL coefficient
/
EOF
#*** 1. time
cat >> ${NMLIST} << EOF
&NSIMTIME
SYEAR = ${SYEAR} ! start year
SMON = ${SMON} ! month
SDAY = ${SDAY} ! day
SHOUR = ${SHOUR} ! houe
EYEAR = ${EYEAR} ! end year
EMON = ${EMON} ! month
EDAY = ${EDAY} ! day
EHOUR = ${EHOUR} ! hour
/
EOF
#*** 2. map
cat >> ${NMLIST} << EOF
&NMAP
LMAPCDF = ${LMAPCDF} ! * true for netCDF map input
CNEXTXY = "${CNEXTXY}" ! river network nextxy
CGRAREA = "${CGRAREA}" ! catchment area
CELEVTN = "${CELEVTN}" ! bank top elevation
CNXTDST = "${CNXTDST}" ! distance to next outlet
CRIVLEN = "${CRIVLEN}" ! river channel length
CFLDHGT = "${CFLDHGT}" ! floodplain elevation profile
CRIVWTH = "${CRIVWTH}" ! channel width
CRIVHGT = "${CRIVHGT}" ! channel depth
CRIVMAN = "${CRIVMAN}" ! river manning coefficient
CPTHOUT = "${CPTHOUT}" ! bifurcation channel table
/
EOF
#*** 3. restart
cat >> ${NMLIST} << EOF
&NRESTART
CRESTSTO = "${CRESTSTO}" ! restart file
CRESTDIR = "${CRESTDIR}" ! restart directory
CVNREST = "${CVNREST}" ! restart variable name
LRESTCDF = ${LRESTCDF} ! * true for netCDF restart file (double precision)
IFRQ_RST = ${IFRQ_RST} ! restart write frequency (1-24: hour, 0:end of run)
/
EOF
#*** 4. forcing
cat >> ${NMLIST} << EOF
&NFORCE
LINPCDF = ${LINPCDF} ! true for netCDF runoff
LINTERP = ${LINTERP} ! true for runoff interpolation using input matrix
CINPMAT = "${CINPMAT}" ! input matrix file name
DROFUNIT = ${DROFUNIT} ! runoff unit conversion
CROFDIR = "${CROFDIR}" ! runoff input directory
CROFPRE = "${CROFPRE}" ! runoff input prefix
CROFSUF = "${CROFSUF}" ! runoff input suffix
/
EOF
#*** 5. outputs
cat >> ${NMLIST} << EOF
&NOUTPUT
COUTDIR = "${COUTDIR}" ! OUTPUT DIRECTORY
CVARSOUT = "${CVARSOUT}" ! Comma-separated list of output variables to save
COUTTAG = "${COUTTAG}" ! Output Tag Name for each experiment
LOUTVEC = .FALSE ! TRUE FOR VECTORIAL OUTPUT, FALSE FOR NX,NY OUTPUT
LOUTCDF = ${LOUTCDF} ! * true for netcdf outptu false for binary
NDLEVEL = 0 ! * NETCDF DEFLATION LEVEL
IFRQ_OUT = ${IFRQ_OUT} ! output data write frequency (hour)
/
EOF
#================================================
# (5) Execute main program
echo "start: ${SYEAR}" `date` >> log.txt
time ./${EXE} >> log.txt
echo "end: ${SYEAR}" `date` >> log.txt
mv ${LOGOUT} log_CaMa-${CYR}.txt
#================================================
# (6) manage spin up
# if curent spinup time $ISP < required spinup time $NSP
# copy the restart file restart$(IYR+1) to restart${IYR}
# copy the outputs to directory "${IYR}-sp1"
SPINUP=1
if [ ${IYR} -eq ${YSTA} ];
then
if [ ${ISP} -le ${NSP} ];
then
IYR1=`expr ${IYR} + 1`
CYR1=`printf %04d ${IYR1}`
cp -f ${CVNREST}${CYR1}010100.bin ${CVNREST}${CYR}010100.bin-sp${ISP} 2> /dev/null
mv -f ${CVNREST}${CYR1}010100.bin ${CVNREST}${CYR}010100.bin 2> /dev/null
cp -f ${CVNREST}${CYR1}010100.bin.pth ${CVNREST}${CYR}010100.bin.pth-sp${ISP} 2> /dev/null
mv -f ${CVNREST}${CYR1}010100.bin.pth ${CVNREST}${CYR}010100.bin.pth 2> /dev/null
cp -f ${CVNREST}${CYR1}010100.nc ${CVNREST}${CYR}010100.nc-sp${ISP} 2> /dev/null
mv -f ${CVNREST}${CYR1}010100.nc ${CVNREST}${CYR}010100.nc 2> /dev/null
mkdir -p ${CYR}-sp${ISP}
mv -f ./${CVNREST}${CYR}010100.bin-sp${ISP} ${CYR}-sp${ISP} 2> /dev/null
mv -f ./${CVNREST}${CYR}010100.bin.pth-sp${ISP} ${CYR}-sp${ISP} 2> /dev/null
mv -f ./${CVNREST}${CYR}010100.nc-sp${ISP} ${CYR}-sp${ISP} 2> /dev/null
mv -f ./*${CYR}.bin ${CYR}-sp${ISP} 2> /dev/null
mv -f ./*${CYR}.pth ${CYR}-sp${ISP} 2> /dev/null
mv -f ./o_*${CYR}.nc ${CYR}-sp${ISP} 2> /dev/null
mv -f ./*${CYR}.log ${CYR}-sp${ISP} 2> /dev/null
mv -f ./log_CaMa-${CYR}.txt ${CYR}-sp${ISP} 2> /dev/null
ISP=`expr ${ISP} + 1`
else
ISP=0
IYR=`expr ${IYR} + 1`
fi
else
IYR=`expr ${IYR} + 1`
fi
#================================================
# (7) End of each year loop. Back to (3)
done # loop to next year simulation
exit 0