-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathprepinpt
executable file
·267 lines (240 loc) · 5.56 KB
/
prepinpt
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
#!/bin/bash
mydir=`dirname $0`
cd "$mydir"
mydir=`pwd -P`
wrfrun="$mydir/../WRFV3/run"
pyprog="$mydir/CONFIG/autowrf_namelist_main.py"
checkonly=false
finishonly=false
metonly=false
doreal=true # only used if metonly is true
chemonly=false
wpsargs=""
dosplit=false
splitargs=""
while [ $# -gt 0 ]; do
case "$1" in
--check-only)
checkonly=true
;;
--finish-only)
finishonly=true
;;
--met-only)
metonly=true
pcargs="--met-only"
;;
--chem-only)
chemonly=true
pcargs="--chem-only"
;;
--noreal)
doreal=false
;;
--wpsdir*)
wpsdir=${1#*=}
wpsargs="$wpsargs $wpsdir"
;;
--splitmet)
dosplit=true
pcargs="--met-only"
;;
--ndays*|--submitfile*)
splitargs="$splitargs $1"
;;
esac
shift
done
# Do a quick check of the most important namelist options
# before starting the prep
PREPINPUT/precheck $pcargs
chkexit=$?
if [ $chkexit -ne 0 ]; then
exit $chkexit
fi
if $checkonly; then
exit 0
fi
if $finishonly; then
cd ../WRFV3/run
pwd
ls met_em* >& /dev/null
if [ $? -eq 0 ]; then
# Met files linked in WRFV3/run, no need to redo
dowps=false
else
dowps=true
fi
if [ -f wrfem_00to12Z -a -f wrfem_12to24Z ]; then
doemiss=false
else
doemiss=true
fi
if [ -f wrfchemi_00z_d01 -a -f wrfchemi_12z_d01 ]; then
doconv=false
else
doconv=true
fi
if [ -f wrfbiochemi_d01 ]; then
domegan=false
else
domegan=true
fi
domozbc=true
cd "$mydir"
elif $metonly; then
dowps=true
doemiss=false
doconv=false
domegan=false
domozbc=false
elif $chemonly; then
dowps=false
doemiss=true
doconv=true
domegan=true
domozbc=true
else
dowps=true
doemiss=true
doconv=true
domegan=true
domozbc=true
fi
# Are we doing FDDA nudging? If so, we'll want to turn that
# off for each run of real.exe EXCEPT the last one
python $pyprog --check-wrf-opt --grid_fdda=1
fdda_check=$?
if [[ $fdda_check == 0 ]]; then
export FDDA_ON=1
fi
# If doing met splitting, do it now and then stop
if $dosplit; then
$mydir/PREPINPUT/splitwps $splitargs
exit $?
fi
# Ensure that namelist.input is linked
# Backup only if not already a link to somewhere
cd ../WRFV3/run
if [ -f namelist.input ]; then
lnk=`readlink namelist.input`
if [ ! -z $lnk ]; then
mv namelist.input namelist.input.autowrf-backup
fi
fi
ln -sf "$mydir/CONFIG/namelist.input"
cd "$mydir"
# The exit status needs to be 0 if everything works,
# otherwise have bits representing which one failed
# start as 011111 and remove 1's as things succeed
# = 2+4+8+16+32 = 62
# 2 = WPS
# 4 = emiss_v0x
# 8 = convert_emiss
# 16 = MEGAN
# 32 = MOZBC
# 64 = postcheck.py - should run for any case
# 1 = real.exe after WPS during met-only
exitstat=0
if $metonly && $doreal; then
exitstat=$((exitstat+1))
fi
if $dowps; then
exitstat=$((exitstat+2))
fi
if $doemiss; then
exitstat=$((exitstat+4))
fi
if $doconv; then
exitstat=$((exitstat+8))
fi
if $domegan; then
exitstat=$((exitstat+16))
fi
if $domozbc; then
exitstat=$((exitstat+32))
fi
if $dowps; then
echo "Running WPS..."
PREPINPUT/prepwps $wpsargs
wpsexit=$?
if [ $wpsexit -eq 0 ]; then
exitstat=$((exitstat-2))
fi
else
echo "Not running WPS, either met files exist or chem-only requested."
fi
if $metonly; then
if $doreal; then
if [ $wpsexit -eq 0 ]; then
echo "Running real.exe since only the meterology has been requested."
cd ../WRFV3/run
python $pyprog tempmod --emiss_opt=0 --bio_emiss_opt=0 --restart=.false.
./real.exe
realexit=$?
if [ $realexit -eq 0 ]; then
exitstat=$((exitstat-1))
fi
python "$mydir/PREPINPUT/postcheck.py" --mode=met "$wrfrun/wrfinput_d01" "$wrfrun/wrfbdy_d01"
postexit=$?
if [ $postexit -ne 0 ]; then
exitstat=$((exitstat+64))
fi
else
echo "WPS failed, not running real.exe."
fi
fi
exit $exitstat
fi
if $doemiss; then
echo "Running emiss_v04..."
PREPINPUT/prepnei_intermediate
neiexit=$?
if [ $neiexit -eq 0 ]; then
exitstat=$((exitstat-4))
fi
else
echo "wrfem files found, skipping emiss_v04"
fi
if $doconv; then
if [ -f $wrfrun/wrfem_00to12z_d01 -a -f $wrfrun/wrfem_12to24z_d01 ]; then
echo "Running convert_emiss.exe"
PREPINPUT/prepnei_convert
convexit=$?
if [ $convexit -eq 0 ]; then
exitstat=$((exitstat-8))
fi
else
echo "wrfem_00to12z_d01 and/or wrfem_12to24z_d01 not present in"
echo "$wrfrun, cannot execute convert_emiss.exe"
fi
else
echo "wrfchemi files detected, skipping convert_emiss.exe"
fi
if $domegan; then
echo "Running MEGAN"
PREPINPUT/prepmegan
meganexit=$?
if [ $meganexit -eq 0 ]; then
exitstat=$((exitstat-16))
fi
else
echo "wrfbiochemi file found, skipping MEGAN"
fi
if $domozbc; then
echo "Running MOZBC..."
PREPINPUT/prepmozbc
mozbcexit=$?
if [ $mozbcexit -eq 0 ]; then
exitstat=$((exitstat-32))
fi
postchk_mode="both"
else
postchk_mode="met"
fi
python "$mydir/PREPINPUT/postcheck.py" --mode=$postchk_mode "$wrfrun/wrfinput_d01" "$wrfrun/wrfbdy_d01"
postexit=$?
if [ $postexit -ne 0 ]; then
exitstat=$((exitstat+64))
fi
exit $exitstat