-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathprdgen.sh
executable file
·372 lines (321 loc) · 10.8 KB
/
prdgen.sh
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
#!/bin/bash
set -xa
# -----------------------------------------------------------
# UNIX Shell Script File
# Tested Operating System(s): RHEL 5,6
# Tested Run Level(s): 3, 5
# Shell Used: BASH shell
# Original Author(s): [email protected]
# File Creation Date: 08/22/2011
# Date Last Modified: 04/06/2015
#
# Version control: 1.17
#
# Support Team:
#
# Contributors: Andre Van Der Westhuijsen
# -----------------------------------------------------------
# ------------- Program Description and Details -------------
# -----------------------------------------------------------
#
# Script used to introduce the WMO headers
# into CG0, CG1 to CGn grib2 files
#
# -----------------------------------------------------------
# Setup our NWPS environment
if [ "${USHnwps}" == "" ]
then
echo "ERROR - Your USHnwps variable is not set"
export err=1; err_chk
fi
if [ ! -e ${USHnwps}/nwps_config.sh ]
then
"ERROR - Cannot find ${USHnwps}/nwps_config.sh"
export err=1; err_chk
fi
echo "" | tee -a ${LOGdir}/prdgen_cgn.log
#Defining the siteid
parmKSITE="K${SITEID}"
echo "prdgen_cgn .sh HAS BEGUN "
echo "COARSE OR NESTED GRID(S): ${N}"
echo "Starting NWPS PRODUCTS SCRIPT" | tee -a ${LOGdir}/prdgen_cgn.log
PARMwmo=${PARMnwps}/wmo_headers
# Here some variables are defined if the run is for CG0 to CG5
# For CG0 (the output of wave tracking) we need the number of wave systems
if [ "${N}" == "1" ]
then
# For CG1
cxini="0"
NumCGs="1"
elif [ "${N}" == "0" ]
then
#For CG0
hastracking="FALSE"
hastracking=$(cat ${RUNdir}/Tracking.flag)
if [ "${hastracking}" == "FALSE" ]
then
echo "WARNING: Wave tracking not activated. Not producing CG0 GRIB2 file for this run." | tee -a ${RUNdir}/Warn_Forecaster_${SITEID}.${PDY}.txt
msg="WARNING: Wave tracking not activated. Not producing CG0 GRIB2 file for this run."
postmsg "$jlogfile" "$msg"
exit 0
fi
cxini="-1"
NumCGs="1"
GRIB2dir="${GRIB2dir}/tracking"
NumSystems=$(cat ${RUNdir}/NumWaveSystems.txt)
if [ $NumSystems -eq 0 ]
then
echo "WARNING: No wave systems identified. Not producing CG0 GRIB2 file for this run." | tee -a ${RUNdir}/Warn_Forecaster_${SITEID}.${PDY}.txt
msg="WARNING: No wave systems identified. Not producing CG0 GRIB2 file for this run."
postmsg "$jlogfile" "$msg"
exit 0
fi
else
#If nest is true then the number of lines in ${RUNdir}/cgn_cmdfile
# equals the number of CG's in nesting
cxini="1"
if [ -e ${RUNdir}/cgn_cmdfile ]
then
NumCGs=$(wc -l < "${RUNdir}/cgn_cmdfile")
echo "Number of nested grids : ${NumCGs}" | tee -a ${LOGdir}/prdgen_cgn.log
else
echo "********************************" | tee -a ${LOGdir}/prdgen_cgn.log
echo "** NO NESTED GRIDS IN THIS RUN *" | tee -a ${LOGdir}/prdgen_cgn.log
echo "********************************" | tee -a ${LOGdir}/prdgen_cgn.log
fi
fi
# grids='CG1 CG2 CG3 CG4 CG5 CG0'
awipsgrib='yes'
awipsbull='no'
# 0.b Date and time stuff
date=$PDY
YMDH=${PDY}
set +x
echo ' '
echo ' ****************************'
echo ' *** NWPS PRODUCTS SCRIPT ***'
echo ' ****************************'
echo " $date $cycle"
echo ' '
echo "Starting at : `date`"
echo ' '
echo " AWIPS grib fields : $awipsgrib"
echo " Wave Grids : $grids"
echo ' '
[[ "$LOUD" = YES ]] && set -x
# --------------------------------------------------------------------------- #
# 1. Get necessary files
set +x
echo ' '
echo 'Preparing input files :'
echo '-----------------------'
[[ "$LOUD" = YES ]] && set -x
# 1.a Grib file (AWIPS and FAX charts)
if [ "$awipsgrib" = 'yes' ]
then
cx=${cxini}
for (( i = 0 ; i < ${NumCGs} ; i++ ))
do
cx=$(( $cx + 1 ))
grdID="CG${cx}"
echo "Preparing input file for: ${grdID}"
if [ ! -f gribfile.$grdID ]
then
set +x
echo " Copying grib2 from ${GRIB2dir}/${grdID}/"
[[ "$LOUD" = YES ]] && set -x
cd ${GRIB2dir}/${grdID}
#subfix="*${grdID}*grib2"
#file=`ls ${subfix}`
#file=$(ls ${GRIB2dir}/${grdID}/*${grdID}*grib2 | xargs -n 1 basename | tail -n 1)
cycle=$(awk '{print $1;}' ${RUNdir}/CYCLE)
if [ "${N}" == "0" ]
then
#cycle=${file:28:2}
grep "^INPGRID WIND" ${RUNdir}/inputCG1 > blah1
init=$(awk '{print $11;}' blah1)
echo "$init" > datetime
cut -c 1-4 datetime > year
cut -c 5-6 datetime > mon
cut -c 7-8 datetime > day
yyyy=$(cat year)
mon=$(cat mon)
dd=$(cat day)
file="${WFO}_${NET}_${grdID}_Trkng_${yyyy}${mon}${dd}_${cycle}00.grib2"
else
#cycle=${file:22:2}
grep "^INPGRID WIND" ${RUNdir}/input${grdID} > blah1
init=$(awk '{print $11;}' blah1)
echo "$init" > datetime
cut -c 1-4 datetime > year
cut -c 5-6 datetime > mon
cut -c 7-8 datetime > day
yyyy=$(cat year)
mon=$(cat mon)
dd=$(cat day)
file="${WFO}_${NET}_${grdID}_${yyyy}${mon}${dd}_${cycle}00.grib2"
fi
cp ${GRIB2dir}/${grdID}/$file ${RUNdir}/gribfile.$grdID
export err=$?; err_chk
fi
cd ${RUNdir}
if [ -f gribfile.$grdID ]
then
set +x
echo " gribfile.$grdID exists."
[[ "$LOUD" = YES ]] && set -x
else
echo "FATAL ERROR: NO GRIB FILE FOR GRID $grdID" | tee -a ${LOGdir}/prdgen_cgn.log
msg="FATAL ERROR: NO GRIB FILE FOR GRID $grdID"
postmsg "$jlogfile" "$msg"
export err=1; err_chk
set +x
echo ' '
echo '**************************** '
echo '*** ERROR : NO GRIB FILE *** '
echo '**************************** '
echo ' '
exit
[[ "$LOUD" = YES ]] && set -x
echo "$siteid $grdID prdgen_cgn : GRIB file missing."| tee -a ${LOGdir}/prdgen_cgn.log
awipsgrib='no'
export err=1; err_chk
fi
done
fi
# 1.g Input template files
if [ "$awipsgrib" = 'yes' ]
then
# for grdID in $grids
# do
cx=${cxini}
for (( i = 0 ; i < ${NumCGs} ; i++ ))
do
cx=$(( $cx + 1 ))
grdID="CG${cx}"
echo "Processing template file for: ${grdID}"
if [ "${grdID}" == "CG0" ]
then
header="$PARMwmo/grib2_${siteid}_nwps_${grdID}_Trkng_${NumSystems}_Sys"
cp ${header} awipsgrb.$grdID
export err=$?; err_chk
else
cp $PARMwmo/grib2_${siteid}_nwps_$grdID awipsgrb.$grdID
export err=$?; err_chk
fi
if [ -f awipsgrb.$grdID ]
then
set +x
echo " awipsgrb.$grdID copied."
else
echo "ABNORMAL EXIT: NO AWIPS GRIB FOR GRID $grdID" | tee -a ${LOGdir}/prdgen_cgn.log
set +x
echo ' '
echo '*************************************** '
echo '*** ERROR : NO AWIPS GRIB DATA FILE *** '
echo '*************************************** '
echo ' '
awipsgrib='no'
export err=1; err_chk
fi
done
fi
# 1.h Data summary
echo ' '
echo ' All data files accounted for.'
echo ' '
echo " AWIPSGRIB? : $awipsgrib"
echo ' '
# --------------------------------------------------------------------------- #
# 2. AWIPS product generation
# 2.a AWIPS GRIB file with headers
if [ "$awipsgrib" = 'yes' ]
then
cx=${cxini}
for (( i = 0 ; i < ${NumCGs} ; i++ ))
do
cx=$(( $cx + 1 ))
grdID="CG${cx}"
echo '------------------------------'
echo "AWIPS headers to GRIB file: ${grdID} "
echo '------------------------------'
# 2.a.1 Set up for tocgrib2
echo " Do set up for tocgrib2."
rm -f AWIPSGRIB
# 2.a.2 Make GRIB index
echo " Make GRIB index for tocgrib2."
#$utilexec/grb2index gribfile.$grdID gribindex.$grdID
$GRB2INDEX gribfile.$grdID gribindex.$grdID
OK=$?
if [ "$OK" != '0' ]
then
echo "ABNORMAL EXIT: ERROR IN grb2index NWPS_K${SITEID} for grid $grdID" | tee -a ${LOGdir}/prdgen_cgn.log
echo ' '
echo '******************************************** '
echo '*** FATAL ERROR : ERROR IN grb2index NWPS_K$SITEID} *** '
echo '******************************************** '
echo ' '
export err=1; err_chk
fi
# 2.a.3 Run AWIPS GRIB packing program tocgrib2
echo " Run tocgrib2"
export pgm=tocgrib2
export pgmout="tocgrib2_${grdID}.out"
. prep_step
export FORT11="gribfile.$grdID"
export FORT31="gribindex.$grdID"
export FORT51="AWIPSGRIB"
# $utilexec/tocgrib2 < awipsgrb.$grdID parm='KMFL' > "tocgrib2_${grdID}.out" 2>&1
#$utilexec/tocgrib2 < awipsgrb.$grdID parm='${parmKSITE}' > "tocgrib2_${grdID}.out" 2>&1
$TOCGRIB2 < awipsgrb.$grdID parm='${parmKSITE}' > "tocgrib2_${grdID}.out" 2>&1
OK=$?
if [ "$OK" != '0' ]
then
cat "tocgrib2_${grdID}.out"
echo "ABNORMAL EXIT: ERROR IN tocgrib2"| tee -a ${LOGdir}/prdgen_cgn.log
# postmsg "$jlogfile" "$msg"
echo ' '
echo '*************************************** '
echo '*** FATAL ERROR : ERROR IN tocgrib2 *** '
echo '*************************************** '
echo ' '
export err=1; err_chk
fi
# 2.a.7 Get the AWIPS grib bulletin out ...
echo " Get awips GRIB bulletins out ..."
if [ "$SENDCOM" = 'YES' ]
then
set +x
echo " Saving AWIPSGRIB as grib2.$cycle.awipsnwps_${siteid}_${grdID}"
echo " in $COMOUTwmo"
[[ "$LOUD" = YES ]] && set -x
cp AWIPSGRIB $COMOUTwmo/grib2.$cycle.awipsnwps_${siteid}_${grdID}
export err=$?; err_chk
fi
if [ "$SENDDBN" = 'YES' ]
then
echo " Sending grib2.$cycle.awipsnwps_${siteid}_${grdID} to DBNET."
$DBNROOT/bin/dbn_alert GRIB_LOW $NET $job $COMOUTwmo/grib2.$cycle.awipsnwps_${siteid}_${grdID}
fi
##rm -f "tocgrib2_${grdID}.out"
done
fi
# --------------------------------------------------------------------------- #
# 5. Clean up
set +x; [[ "$LOUD" = YES ]] && set -v
rm -f gribfile gribindex.* awipsgrb.*
set +v
# --------------------------------------------------------------------------- #
# 6. Ending output
set +x
echo ' '
echo ' '
echo "Ending at : `date`"
echo ' '
echo ' *** End of NWPS product generation ***'
echo ' '
[[ "$LOUD" = YES ]] && set -x
echo "$job completed normally" | tee -a ${LOGdir}/prdgen_cgn.log
date -u | tee -a ${LOGdir}/prdgen_cgn.log
exit 0
# End of NWPS product generation script -------------------------------------- #