forked from NCAR/MPAS-Workflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RTPP.csh
executable file
·266 lines (228 loc) · 7.58 KB
/
RTPP.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
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
#!/bin/csh -f
date
# Setup environment
# =================
source config/model.csh
source config/experiment.csh
source config/tools.csh
source config/modeldata.csh
source config/mpas/variables.csh
source config/builds.csh
source config/environmentJEDI.csh
source config/applications/rtpp.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
if (${nMembers} < 2) then
exit 0
endif
# static work directory
set self_WorkDir = $CyclingRTPPDir
echo "WorkDir = ${self_WorkDir}"
mkdir -p ${self_WorkDir}
cd ${self_WorkDir}
# build, executable, yaml
set myBuildDir = ${RTPPBuildDir}
set myEXE = ${RTPPEXE}
set myYAML = ${self_WorkDir}/$appyaml
# other static variables
#set bgPrefix = $FCFilePrefix
#set bgDirs = ($prevCyclingFCDirs)
set bgPrefix = $BGFilePrefix
set bgDirs = ($CyclingDAInDirs)
set anPrefix = $ANFilePrefix
set anDirs = ($CyclingDAOutDirs)
# Remove old logs
rm jedi.log*
# ================================================================================================
## copy static fields
rm ${localStaticFieldsPrefix}*.nc
rm ${localStaticFieldsPrefix}*.nc-lock
set localStaticFieldsFile = ${localStaticFieldsFileEnsemble}
rm ${localStaticFieldsFile}
set StaticMemDir = `${memberDir} 2 1 "${staticMemFmt}"`
set memberStaticFieldsFile = ${StaticFieldsDirEnsemble}${StaticMemDir}/${StaticFieldsFileEnsemble}
ln -sfv ${memberStaticFieldsFile} ${localStaticFieldsFile}${OrigFileSuffix}
cp -v ${memberStaticFieldsFile} ${localStaticFieldsFile}
## create RTPP mean output file to be overwritten by MPAS-JEDI RTPPEXE application
set memDir = `${memberDir} 2 0 "${flowMemFmt}"`
set meanDir = ${CyclingDAOutDir}${memDir}
mkdir -p ${meanDir}
set firstANFile = $anDirs[1]/${anPrefix}.$thisMPASFileDate.nc
cp ${firstANFile} ${meanDir}
# ====================
# Model-specific files
# ====================
## link MPAS mesh graph info
ln -sfv $GraphInfoDir/x1.${nCellsEnsemble}.graph.info* .
## link lookup tables
foreach fileGlob ($MPASLookupFileGlobs)
ln -sfv ${MPASLookupDir}/*${fileGlob} .
end
## link/copy stream_list/streams configs
foreach staticfile ( \
stream_list.${MPASCore}.background \
stream_list.${MPASCore}.analysis \
stream_list.${MPASCore}.ensemble \
stream_list.${MPASCore}.control \
)
ln -sfv $ModelConfigDir/${AppName}/$staticfile .
end
rm ${StreamsFile}
cp -v $ModelConfigDir/${AppName}/${StreamsFile} .
sed -i 's@nCells@'${nCellsEnsemble}'@' ${StreamsFile}
sed -i 's@TemplateFieldsPrefix@'${self_WorkDir}'/'${TemplateFieldsPrefix}'@' ${StreamsFile}
sed -i 's@StaticFieldsPrefix@'${self_WorkDir}'/'${localStaticFieldsPrefix}'@' ${StreamsFile}
sed -i 's@{{PRECISION}}@'${model__precision}'@' ${StreamsFile}
# determine analysis output precision
ncdump -h ${firstANFile} | grep uReconstruct | grep double
if ($status == 0) then
set analysisPrecision=double
else
ncdump -h ${firstANFile} | grep uReconstruct | grep float
if ($status == 0) then
set analysisPrecision=single
else
echo "ERROR in $0 : cannot determine analysis precision" > ./FAIL
exit 1
endif
endif
sed -i 's@{{analysisPRECISION}}@'${analysisPrecision}'@' ${StreamsFile}
## copy/modify dynamic namelist
rm $NamelistFile
cp -v $ModelConfigDir/${AppName}/${NamelistFile} .
sed -i 's@startTime@'${thisMPASNamelistDate}'@' $NamelistFile
sed -i 's@blockDecompPrefix@'${self_WorkDir}'/x1.'${nCellsEnsemble}'@' ${NamelistFile}
sed -i 's@modelDT@'${TimeStep}'@' $NamelistFile
sed -i 's@diffusionLengthScale@'${DiffusionLengthScale}'@' $NamelistFile
## MPASJEDI variable configs
foreach file ($MPASJEDIVariablesFiles)
ln -sfv $ModelConfigDir/$file .
end
# =============
# Generate yaml
# =============
## Copy jedi/applications yaml
set thisYAML = orig.yaml
cp -v ${ConfigDir}/jedi/applications/${AppName}.yaml $thisYAML
## RTPP inflation factor
sed -i 's@{{relaxationFactor}}@'${rtpp__relaxationFactor}'@g' $thisYAML
## streams
sed -i 's@{{EnsembleStreamsFile}}@'${self_WorkDir}'/'${StreamsFile}'@' $thisYAML
## namelist
sed -i 's@{{EnsembleNamelistFile}}@'${self_WorkDir}'/'${NamelistFile}'@' $thisYAML
## revise current date
sed -i 's@{{thisISO8601Date}}@'${thisISO8601Date}'@g' $thisYAML
# use one of the analyses as the TemplateFieldsFileOuter
set meshFile = ${firstANFile}
ln -sfv $meshFile ${TemplateFieldsFileOuter}
## file naming
sed -i 's@{{MemberDir}}@/mem%{member}%@g' $thisYAML
sed -i 's@{{anStatePrefix}}@'${anPrefix}'@g' $thisYAML
sed -i 's@{{anStateDir}}@'${CyclingDAOutDir}'@g' $thisYAML
set prevYAML = $thisYAML
## state and analysis variable configs
# Note: includes model forecast variables that need to be
# averaged and/or remain constant through RTPP
set AnalysisVariables = ( \
$StandardAnalysisVariables \
pressure_p \
pressure \
rho \
theta \
u \
qv \
)
foreach hydro ($MPASHydroIncrementVariables)
set AnalysisVariables = ($AnalysisVariables $hydro)
end
set StateVariables = ( \
$AnalysisVariables \
)
foreach VarGroup (Analysis State)
if (${VarGroup} == Analysis) then
set Variables = ($AnalysisVariables)
endif
if (${VarGroup} == State) then
set Variables = ($StateVariables)
endif
set VarSub = ""
foreach var ($Variables)
set VarSub = "$VarSub$var,"
end
# remove trailing comma
set VarSub = `echo "$VarSub" | sed 's/.$//'`
sed -i 's@{{'$VarGroup'Variables}}@'$VarSub'@' $prevYAML
end
## fill in ensemble B config and link/copy analysis ensemble members
set indent = "`${nSpaces} 2`"
foreach PMatrix (Pb Pa)
if ($PMatrix == Pb) then
set ensPDirs = ($bgDirs)
set ensPFilePrefix = ${bgPrefix}
endif
if ($PMatrix == Pa) then
set ensPDirs = ($anDirs)
set ensPFilePrefix = ${anPrefix}
endif
set enspsed = Ensemble${PMatrix}Members
cat >! ${enspsed}SEDF.yaml << EOF
/{{${enspsed}}}/c\
EOF
set ensPFile = ${ensPFilePrefix}.${thisMPASFileDate}.nc
set anBeforeRTPPDir = ${anDir}BeforeRTPP
mkdir ${anBeforeRTPPDir}
rm ${anDir}
ln -sf ${anBeforeRTPPDir} ${anDir}
set member = 1
while ( $member <= ${nMembers} )
set ensPDir = $ensPDirs[$member]
set ensPFileBeforeRTPP = ${ensPDir}/${ensPFile}
## copy original analysis files for diagnosing RTPP behavior
if ($PMatrix == Pa) then
set memDir = "."`${memberDir} 2 $member "${flowMemFmt}"`
set tempAnalysisCopyDir = ${anDir}/${memDir}
# Restore ${ensPFileBeforeRTPP} with original files if ${tempAnalysisCopyDir}/${ensPFile} already exists
if ( -f "${tempAnalysisCopyDir}/${ensPFile}" ) then
rm ${ensPFileBeforeRTPP}
cp -v ${tempAnalysisCopyDir}/${ensPFile} ${ensPFileBeforeRTPP}
else
rm -r ${tempAnalysisCopyDir}
mkdir -p ${tempAnalysisCopyDir}
cp -v ${ensPFileBeforeRTPP} ${tempAnalysisCopyDir}/
endif
endif
set filename = ${ensPFileBeforeRTPP}
if ( $member < ${nMembers} ) then
set filename = ${filename}\\
endif
cat >>! ${enspsed}SEDF.yaml << EOF
${indent}- <<: *stateReadConfig\
${indent} filename: ${filename}
EOF
@ member++
end
set thisYAML = orig${PMatrix}.yaml
sed -f ${enspsed}SEDF.yaml $prevYAML >! $thisYAML
rm ${enspsed}SEDF.yaml
set prevYAML = $thisYAML
end
mv $prevYAML $appyaml
# Run the executable
# ==================
ln -sfv ${myBuildDir}/${myEXE} ./
mpiexec ./${myEXE} $myYAML ./jedi.log >& jedi.log.all
# Check status
# ============
grep 'Run: Finishing oops.* with status = 0' jedi.log
if ( $status != 0 ) then
echo "ERROR in $0 : jedi application failed" > ./FAIL
exit 1
endif
## change static fields to a link, keeping for transparency
rm ${localStaticFieldsFile}
mv ${localStaticFieldsFile}${OrigFileSuffix} ${localStaticFieldsFile}
date
exit 0