forked from NCAR/MPAS-Workflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
forecast.csh
executable file
·233 lines (203 loc) · 7.75 KB
/
forecast.csh
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
#!/bin/csh -f
date
# Process arguments
# =================
## args
# ArgMember: int, ensemble member [>= 1]
set ArgMember = "$1"
## arg checks
set test = `echo $ArgMember | grep '^[0-9]*$'`
set isNotInt = ($status)
if ( $isNotInt ) then
echo "ERROR in $0 : ArgMember ($ArgMember) must be an integer" > ./FAIL
exit 1
endif
if ( $ArgMember < 1 ) then
echo "ERROR in $0 : ArgMember ($ArgMember) must be > 0" > ./FAIL
exit 1
endif
# Setup environment
# =================
source config/experiment.csh
source config/filestructure.csh
source config/tools.csh
source config/modeldata.csh
source config/mpas/variables.csh
source config/mpas/${MPASGridDescriptor}/mesh.csh
source config/builds.csh
source config/environment.csh
set yymmdd = `echo ${CYLC_TASK_CYCLE_POINT} | cut -c 1-8`
set hh = `echo ${CYLC_TASK_CYCLE_POINT} | cut -c 10-11`
set thisCycleDate = ${yymmdd}${hh}
set thisValidDate = ${thisCycleDate}
source ./getCycleVars.csh
# templated work directory
set self_WorkDir = $WorkDirsTEMPLATE[$ArgMember]
echo "WorkDir = ${self_WorkDir}"
mkdir -p ${self_WorkDir}
cd ${self_WorkDir}
# other templated variables
set self_icStateDir = $StateDirsTEMPLATE[$ArgMember]
set self_fcLengthHR = fcLengthHRTEMPLATE
set self_fcIntervalHR = fcIntervalHRTEMPLATE
set config_run_duration = 0_${self_fcLengthHR}:00:00
set output_interval = 0_${self_fcIntervalHR}:00:00
set deleteZerothForecast = deleteZerothForecastTEMPLATE
# static variables
set self_icStatePrefix = ${ANFilePrefix}
set self_ModelConfigDir = $forecastModelConfigDir
# ================================================================================================
## copy static fields
rm ${localStaticFieldsPrefix}*.nc
rm ${localStaticFieldsPrefix}*.nc-lock
set localStaticFieldsFile = ${localStaticFieldsFileOuter}
rm ${localStaticFieldsFile}
set StaticMemDir = `${memberDir} ensemble $ArgMember "${staticMemFmt}"`
set memberStaticFieldsFile = ${StaticFieldsDirOuter}${StaticMemDir}/${StaticFieldsFileOuter}
ln -sfv ${memberStaticFieldsFile} ${localStaticFieldsFile}${OrigFileSuffix}
cp -v ${memberStaticFieldsFile} ${localStaticFieldsFile}
## link initial forecast state
set icFileExt = ${fileDate}.nc
set icFile = ${ICFilePrefix}.${icFileExt}
rm ./${icFile}
ln -sfv ${self_icStateDir}/${self_icStatePrefix}.${icFileExt} ./${icFile}
## link MPAS mesh graph info
rm ./x1.${MPASnCellsOuter}.graph.info*
ln -sfv $GraphInfoDir/x1.${MPASnCellsOuter}.graph.info* .
## link lookup tables
foreach fileGlob ($MPASLookupFileGlobs)
rm ./*${fileGlob}
ln -sfv ${MPASLookupDir}/*${fileGlob} .
end
## link stream_list configs
foreach staticfile ( \
stream_list.${MPASCore}.surface \
stream_list.${MPASCore}.diagnostics \
)
rm ./$staticfile
ln -sfv $self_ModelConfigDir/$staticfile .
end
## copy/modify dynamic streams file
rm ${StreamsFile}
cp -v $self_ModelConfigDir/${StreamsFile} .
sed -i 's@nCells@'${MPASnCellsOuter}'@' ${StreamsFile}
sed -i 's@outputInterval@'${output_interval}'@' ${StreamsFile}
sed -i 's@StaticFieldsPrefix@'${localStaticFieldsPrefix}'@' ${StreamsFile}
sed -i 's@ICFilePrefix@'${ICFilePrefix}'@' ${StreamsFile}
sed -i 's@FCFilePrefix@'${FCFilePrefix}'@' ${StreamsFile}
sed -i 's@forecastPrecision@'${forecastPrecision}'@' ${StreamsFile}
## copy/modify dynamic namelist
rm ${NamelistFile}
cp -v ${self_ModelConfigDir}/${NamelistFile} .
sed -i 's@startTime@'${NMLDate}'@' $NamelistFile
sed -i 's@fcLength@'${config_run_duration}'@' $NamelistFile
sed -i 's@nCells@'${MPASnCellsOuter}'@' $NamelistFile
sed -i 's@modelDT@'${MPASTimeStep}'@' $NamelistFile
sed -i 's@diffusionLengthScale@'${MPASDiffusionLengthScale}'@' $NamelistFile
if ( ${self_fcLengthHR} == 0 ) then
## zero-length forecast case (NOT CURRENTLY USED)
rm ./${icFile}_tmp
mv ./${icFile} ./${icFile}_tmp
rm ${FCFilePrefix}.${icFileExt}
cp ${icFile}_tmp ${FCFilePrefix}.${icFileExt}
rm ./${DIAGFilePrefix}.${icFileExt}
ln -sfv ${self_icStateDir}/${DIAGFilePrefix}.${icFileExt} ./
else
## remove previously generated forecasts
set fcDate = `$advanceCYMDH ${thisValidDate} ${self_fcIntervalHR}`
set finalFCDate = `$advanceCYMDH ${thisValidDate} ${self_fcLengthHR}`
while ( ${fcDate} <= ${finalFCDate} )
set yy = `echo ${fcDate} | cut -c 1-4`
set mm = `echo ${fcDate} | cut -c 5-6`
set dd = `echo ${fcDate} | cut -c 7-8`
set hh = `echo ${fcDate} | cut -c 9-10`
set fcFileDate = ${yy}-${mm}-${dd}_${hh}.00.00
set fcFileExt = ${fcFileDate}.nc
set fcFile = ${FCFilePrefix}.${fcFileExt}
rm ${fcFile}
set fcDate = `$advanceCYMDH ${fcDate} ${self_fcIntervalHR}`
setenv fcDate ${fcDate}
end
# Run the executable
# ==================
rm ./${ForecastEXE}
ln -sfv ${ForecastBuildDir}/${ForecastEXE} ./
mpiexec ./${ForecastEXE}
# Check status
# ============
grep "Finished running the ${MPASCore} core" log.${MPASCore}.0000.out
if ( $status != 0 ) then
echo "ERROR in $0 : MPAS-Model forecast failed" > ./FAIL
exit 1
endif
## change static fields to a link, keeping for transparency
rm ${localStaticFieldsFile}
mv ${localStaticFieldsFile}${OrigFileSuffix} ${localStaticFieldsFile}
endif
if ( "$deleteZerothForecast" == "True" ) then
# Optionally remove initial forecast file
# =======================================
set fcDate = ${thisValidDate}
set yy = `echo ${fcDate} | cut -c 1-4`
set mm = `echo ${fcDate} | cut -c 5-6`
set dd = `echo ${fcDate} | cut -c 7-8`
set hh = `echo ${fcDate} | cut -c 9-10`
set fcFileDate = ${yy}-${mm}-${dd}_${hh}.00.00
set fcFileExt = ${fcFileDate}.nc
set fcFile = ${FCFilePrefix}.${fcFileExt}
rm ${fcFile}
set diagFile = ${DIAGFilePrefix}.${fcFileExt}
rm ${diagFile}
endif
# Update/add fields to output for DA
# ==================================
#TODO: do this in a separate post-processing script
# either in parallel or using only single processor
# instead of full set of job processors
set fcDate = `$advanceCYMDH ${thisValidDate} ${self_fcIntervalHR}`
set finalFCDate = `$advanceCYMDH ${thisValidDate} ${self_fcLengthHR}`
while ( ${fcDate} <= ${finalFCDate} )
set yy = `echo ${fcDate} | cut -c 1-4`
set mm = `echo ${fcDate} | cut -c 5-6`
set dd = `echo ${fcDate} | cut -c 7-8`
set hh = `echo ${fcDate} | cut -c 9-10`
set fcFileDate = ${yy}-${mm}-${dd}_${hh}.00.00
set fcFileExt = ${fcFileDate}.nc
set fcFile = ${FCFilePrefix}.${fcFileExt}
## Update MPASSeaVariables from GFS/GEFS analyses
if ( ${updateSea} ) then
# first try member-specific state file (central GFS state when ArgMember==0)
set seaMemDir = `${memberDir} ens $ArgMember "${seaMemFmt}" -m ${seaMaxMembers}`
set SeaFile = ${SeaAnaDir}/${fcDate}${seaMemDir}/${SeaFilePrefix}.${fcFileExt}
ncks -A -v ${MPASSeaVariables} ${SeaFile} ${fcFile}
if ( $status != 0 ) then
echo "WARNING in $0 : ncks -A -v ${MPASSeaVariables} ${SeaFile} ${fcFile}" > ./WARNING
echo "WARNING in $0 : ncks could not add (${MPASSeaVariables}) to $fcFile" >> ./WARNING
# otherwise try central GFS state file
set SeaFile = ${deterministicSeaAnaDir}/${fcDate}/${SeaFilePrefix}.${fcFileExt}
ncks -A -v ${MPASSeaVariables} ${SeaFile} ${fcFile}
if ( $status != 0 ) then
echo "ERROR in $0 : ncks -A -v ${MPASSeaVariables} ${SeaFile} ${fcFile}" > ./FAIL
echo "ERROR in $0 : ncks could not add (${MPASSeaVariables}) to $fcFile" >> ./FAIL
exit 1
endif
endif
endif
## Add MPASJEDIDiagVariables to the next cycle bg file (if needed)
set copyDiags = 0
foreach var ({$MPASJEDIDiagVariables})
ncdump -h ${fcFile} | grep $var
if ( $status != 0 ) then
@ copyDiags++
endif
end
set diagFile = ${DIAGFilePrefix}.${fcFileExt}
if ( $copyDiags > 0 ) then
ncks -A -v ${MPASJEDIDiagVariables} ${diagFile} ${fcFile}
endif
# rm ${diagFile}
set fcDate = `$advanceCYMDH ${fcDate} ${self_fcIntervalHR}`
setenv fcDate ${fcDate}
end
date
exit 0