-
Notifications
You must be signed in to change notification settings - Fork 177
/
Copy pathexglobal_archive.sh
executable file
·388 lines (327 loc) · 13.4 KB
/
exglobal_archive.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
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
#! /usr/bin/env bash
source "${HOMEgfs}/ush/preamble.sh"
##############################################
# Begin JOB SPECIFIC work
##############################################
# ICS are restarts and always lag INC by $assim_freq hours
ARCHINC_CYC=${ARCH_CYC}
ARCHICS_CYC=$((ARCH_CYC-assim_freq))
if [ "${ARCHICS_CYC}" -lt 0 ]; then
ARCHICS_CYC=$((ARCHICS_CYC+24))
fi
# CURRENT CYCLE
APREFIX="${CDUMP}.t${cyc}z."
ASUFFIX=${ASUFFIX:-${SUFFIX}}
if [ "${ASUFFIX}" = ".nc" ]; then
format="netcdf"
else
format="nemsio"
fi
# Realtime parallels run GFS MOS on 1 day delay
# If realtime parallel, back up CDATE_MOS one day
CDATE_MOS=${CDATE}
if [ "${REALTIME}" = "YES" ]; then
CDATE_MOS=$(${NDATE} -24 "${CDATE}")
fi
PDY_MOS=$(echo "${CDATE_MOS}" | cut -c1-8)
###############################################################
# Archive online for verification and diagnostics
###############################################################
COMIN=${COMINatmos:-"${ROTDIR}/${CDUMP}.${PDY}/${cyc}/atmos"}
cd "${COMIN}"
source "${HOMEgfs}/ush/file_utils.sh"
[[ ! -d ${ARCDIR} ]] && mkdir -p "${ARCDIR}"
nb_copy "${APREFIX}"gsistat "${ARCDIR}"/gsistat."${CDUMP}"."${CDATE}"
nb_copy "${APREFIX}"pgrb2.1p00.anl "${ARCDIR}"/pgbanl."${CDUMP}"."${CDATE}".grib2
# Archive 1 degree forecast GRIB2 files for verification
if [ "${CDUMP}" = "gfs" ]; then
fhmax=${FHMAX_GFS}
fhr=0
while [ "${fhr}" -le "${fhmax}" ]; do
fhr2=$(printf %02i "${fhr}")
fhr3=$(printf %03i "${fhr}")
nb_copy "${APREFIX}"pgrb2.1p00.f"${fhr3}" "${ARCDIR}"/pgbf"${fhr2}"."${CDUMP}"."${CDATE}".grib2
fhr=$((10#${fhr} + 10#${FHOUT_GFS} ))
done
fi
if [ "${CDUMP}" = "gdas" ]; then
flist="000 003 006 009"
for fhr in ${flist}; do
fname=${APREFIX}pgrb2.1p00.f${fhr}
fhr2=$(printf %02i $((10#${fhr})))
nb_copy "${fname}" "${ARCDIR}"/pgbf"${fhr2}"."${CDUMP}"."${CDATE}".grib2
done
fi
if [ -s avno.t"${cyc}"z.cyclone.trackatcfunix ]; then
PLSOT4=$(echo "${PSLOT}"|cut -c 1-4 |tr '[a-z]' '[A-Z]')
cat avno.t"${cyc}"z.cyclone.trackatcfunix | sed s:AVNO:"${PLSOT4}":g > "${ARCDIR}"/atcfunix."${CDUMP}"."${CDATE}"
cat avnop.t"${cyc}"z.cyclone.trackatcfunix | sed s:AVNO:"${PLSOT4}":g > "${ARCDIR}"/atcfunixp."${CDUMP}"."${CDATE}"
fi
if [ "${CDUMP}" = "gdas" ] && [ -s gdas.t"${cyc}"z.cyclone.trackatcfunix ]; then
PLSOT4=$(echo "${PSLOT}"|cut -c 1-4 |tr '[a-z]' '[A-Z]')
cat gdas.t"${cyc}"z.cyclone.trackatcfunix | sed s:AVNO:"${PLSOT4}":g > "${ARCDIR}"/atcfunix."${CDUMP}"."${CDATE}"
cat gdasp.t"${cyc}"z.cyclone.trackatcfunix | sed s:AVNO:"${PLSOT4}":g > "${ARCDIR}"/atcfunixp."${CDUMP}"."${CDATE}"
fi
if [ "${CDUMP}" = "gfs" ]; then
nb_copy storms.gfso.atcf_gen."${CDATE}" "${ARCDIR}"/.
nb_copy storms.gfso.atcf_gen.altg."${CDATE}" "${ARCDIR}"/.
nb_copy trak.gfso.atcfunix."${CDATE}" "${ARCDIR}"/.
nb_copy trak.gfso.atcfunix.altg."${CDATE}" "${ARCDIR}"/.
mkdir -p "${ARCDIR}"/tracker."${CDATE}"/"${CDUMP}"
blist="epac natl"
for basin in ${blist}; do
if [[ -f ${basin} ]]; then
cp -rp "${basin}" "${ARCDIR}"/tracker."${CDATE}"/"${CDUMP}"
fi
done
fi
# Archive required gaussian gfs forecast files for Fit2Obs
if [ "${CDUMP}" = "gfs" ] && [ "${FITSARC}" = "YES" ]; then
VFYARC=${VFYARC:-${ROTDIR}/vrfyarch}
[[ ! -d ${VFYARC} ]] && mkdir -p "${VFYARC}"
mkdir -p "${VFYARC}"/"${CDUMP}"."${PDY}"/"${cyc}"
prefix=${CDUMP}.t${cyc}z
fhmax=${FHMAX_FITS:-${FHMAX_GFS}}
fhr=0
while [[ ${fhr} -le ${fhmax} ]]; do
fhr3=$(printf %03i "${fhr}")
sfcfile=${prefix}.sfcf${fhr3}${ASUFFIX}
sigfile=${prefix}.atmf${fhr3}${ASUFFIX}
nb_copy "${sfcfile}" "${VFYARC}"/"${CDUMP}"."${PDY}"/"${cyc}"/
nb_copy "${sigfile}" "${VFYARC}"/"${CDUMP}"."${PDY}"/"${cyc}"/
(( fhr = 10#${fhr} + 6 ))
done
fi
###############################################################
# Archive data either to HPSS or locally
if [[ ${HPSSARCH} = "YES" || ${LOCALARCH} = "YES" ]]; then
###############################################################
# --set the archiving command and create local directories, if necessary
TARCMD="htar"
if [[ ${LOCALARCH} = "YES" ]]; then
TARCMD="tar"
[ ! -d "${ATARDIR}"/"${CDATE}" ] && mkdir -p "${ATARDIR}"/"${CDATE}"
[ ! -d "${ATARDIR}"/"${CDATE_MOS}" ] && [ -d "${ROTDIR}"/gfsmos."${PDY_MOS}" ] && [ "${cyc}" -eq 18 ] && mkdir -p "${ATARDIR}"/"${CDATE_MOS}"
fi
#--determine when to save ICs for warm start and forecast-only runs
SAVEWARMICA="NO"
SAVEWARMICB="NO"
SAVEFCSTIC="NO"
firstday=$(${NDATE} +24 "${SDATE}")
mm=$(echo "${CDATE}"|cut -c 5-6)
dd=$(echo "${CDATE}"|cut -c 7-8)
nday=$(( (10#${mm}-1)*30+10#${dd} ))
mod=$((nday % ARCH_WARMICFREQ))
if [ "${CDATE}" -eq "${firstday}" ] && [ "${cyc}" -eq "${ARCHINC_CYC}" ]; then SAVEWARMICA="YES" ; fi
if [ "${CDATE}" -eq "${firstday}" ] && [ "${cyc}" -eq "${ARCHICS_CYC}" ]; then SAVEWARMICB="YES" ; fi
if [ "${mod}" -eq 0 ] && [ "${cyc}" -eq "${ARCHINC_CYC}" ]; then SAVEWARMICA="YES" ; fi
if [ "${mod}" -eq 0 ] && [ "${cyc}" -eq "${ARCHICS_CYC}" ]; then SAVEWARMICB="YES" ; fi
if [ "${ARCHICS_CYC}" -eq 18 ]; then
nday1=$((nday+1))
mod1=$((nday1 % ARCH_WARMICFREQ))
if [ "${mod1}" -eq 0 ] && [ "${cyc}" -eq "${ARCHICS_CYC}" ] ; then SAVEWARMICB="YES" ; fi
if [ "${mod1}" -ne 0 ] && [ "${cyc}" -eq "${ARCHICS_CYC}" ] ; then SAVEWARMICB="NO" ; fi
if [ "${CDATE}" -eq "${SDATE}" ] && [ "${cyc}" -eq "${ARCHICS_CYC}" ] ; then SAVEWARMICB="YES" ; fi
fi
mod=$((nday % ARCH_FCSTICFREQ))
if [ "${mod}" -eq 0 ] || [ "${CDATE}" -eq "${firstday}" ]; then SAVEFCSTIC="YES" ; fi
ARCH_LIST="${COMIN}/archlist"
[[ -d ${ARCH_LIST} ]] && rm -rf "${ARCH_LIST}"
mkdir -p "${ARCH_LIST}"
cd "${ARCH_LIST}"
"${HOMEgfs}"/ush/hpssarch_gen.sh "${CDUMP}"
status=$?
if [ "${status}" -ne 0 ]; then
echo "${HOMEgfs}/ush/hpssarch_gen.sh ${CDUMP} failed, ABORT!"
exit "${status}"
fi
cd "${ROTDIR}"
if [ "${CDUMP}" = "gfs" ]; then
targrp_list="gfsa gfsb"
if [ "${ARCH_GAUSSIAN:-"NO"}" = "YES" ]; then
targrp_list="${targrp_list} gfs_flux gfs_${format}b gfs_pgrb2b"
if [ "${MODE}" = "cycled" ]; then
targrp_list="${targrp_list} gfs_${format}a"
fi
fi
if [ "${DO_WAVE}" = "YES" ] && [ "${WAVE_CDUMP}" != "gdas" ]; then
targrp_list="${targrp_list} gfswave"
fi
if [ "${DO_OCN}" = "YES" ]; then
targrp_list="${targrp_list} ocn_ice_grib2_0p5 ocn_ice_grib2_0p25 ocn_2D ocn_3D ocn_xsect ocn_daily gfs_flux_1p00"
fi
if [ "${DO_ICE}" = "YES" ]; then
targrp_list="${targrp_list} ice"
fi
# Aerosols
if [ "${DO_AERO}" = "YES" ]; then
for targrp in chem; do
${TARCMD} -P -cvf "${ATARDIR}"/"${CDATE}"/"${targrp}".tar $(cat "${ARCH_LIST}"/"${targrp}".txt)
status=$?
if [ "${status}" -ne 0 ] && [ "${CDATE}" -ge "${firstday}" ]; then
echo "HTAR ${CDATE} ${targrp}.tar failed"
exit "${status}"
fi
done
fi
#for restarts
if [ "${SAVEFCSTIC}" = "YES" ]; then
targrp_list="${targrp_list} gfs_restarta"
fi
#for downstream products
if [ "${DO_BUFRSND}" = "YES" ] || [ "${WAFSF}" = "YES" ]; then
targrp_list="${targrp_list} gfs_downstream"
fi
#--save mdl gfsmos output from all cycles in the 18Z archive directory
if [ -d gfsmos."${PDY_MOS}" ] && [ "${cyc}" -eq 18 ]; then
set +e
${TARCMD} -P -cvf "${ATARDIR}"/"${CDATE_MOS}"/gfsmos.tar ./gfsmos."${PDY_MOS}"
status=$?
if [ "${status}" -ne 0 ] && [ "${CDATE}" -ge "${firstday}" ]; then
echo "$(echo "${TARCMD}" | tr 'a-z' 'A-Z') ${CDATE} gfsmos.tar failed"
exit "${status}"
fi
set_strict
fi
elif [ "${CDUMP}" = "gdas" ]; then
targrp_list="gdas"
#gdaswave
if [ "${DO_WAVE}" = "YES" ]; then
targrp_list="${targrp_list} gdaswave"
fi
if [ "${SAVEWARMICA}" = "YES" ] || [ "${SAVEFCSTIC}" = "YES" ]; then
targrp_list="${targrp_list} gdas_restarta"
if [ "${DO_WAVE}" = "YES" ]; then
targrp_list="${targrp_list} gdaswave_restart"
fi
fi
if [ "${SAVEWARMICB}" = "YES" ] || [ "${SAVEFCSTIC}" = "YES" ]; then
targrp_list="${targrp_list} gdas_restartb"
fi
fi
# Turn on extended globbing options
shopt -s extglob
for targrp in ${targrp_list}; do
set +e
${TARCMD} -P -cvf "${ATARDIR}"/"${CDATE}"/"${targrp}".tar $(cat "${ARCH_LIST}"/"${targrp}".txt)
status=$?
if [ "${status}" -ne 0 ] && [ "${CDATE}" -ge "${firstday}" ]; then
echo "$(echo "${TARCMD}" | tr 'a-z' 'A-Z') ${CDATE} ${targrp}.tar failed"
exit "${status}"
fi
set_strict
done
# Turn extended globbing back off
shopt -u extglob
###############################################################
fi ##end of HPSS archive
###############################################################
###############################################################
# Clean up previous cycles; various depths
# PRIOR CYCLE: Leave the prior cycle alone
GDATE=$(${NDATE} -"${assim_freq}" "${CDATE}")
# PREVIOUS to the PRIOR CYCLE
GDATE=$(${NDATE} -"${assim_freq}" "${GDATE}")
gPDY=$(echo "${GDATE}" | cut -c1-8)
gcyc=$(echo "${GDATE}" | cut -c9-10)
# Remove the TMPDIR directory
COMIN="${RUNDIR}/${GDATE}"
[[ -d ${COMIN} ]] && rm -rf "${COMIN}"
if [[ "${DELETE_COM_IN_ARCHIVE_JOB:-YES}" == NO ]] ; then
exit 0
fi
# Step back every assim_freq hours and remove old rotating directories
# for successful cycles (defaults from 24h to 120h). If GLDAS is
# active, retain files needed by GLDAS update. Independent of GLDAS,
# retain files needed by Fit2Obs
DO_GLDAS=${DO_GLDAS:-"NO"}
GDATEEND=$(${NDATE} -"${RMOLDEND:-24}" "${CDATE}")
GDATE=$(${NDATE} -"${RMOLDSTD:-120}" "${CDATE}")
GLDAS_DATE=$(${NDATE} -96 "${CDATE}")
RTOFS_DATE=$(${NDATE} -48 "${CDATE}")
while [ "${GDATE}" -le "${GDATEEND}" ]; do
gPDY=$(echo "${GDATE}" | cut -c1-8)
gcyc=$(echo "${GDATE}" | cut -c9-10)
COMIN="${ROTDIR}/${CDUMP}.${gPDY}/${gcyc}/atmos"
COMINwave="${ROTDIR}/${CDUMP}.${gPDY}/${gcyc}/wave"
COMINrtofs="${ROTDIR}/rtofs.${gPDY}"
if [ -d "${COMIN}" ]; then
rocotolog="${EXPDIR}/logs/${GDATE}.log"
if [ -f "${rocotolog}" ]; then
set +e
testend=$(tail -n 1 "${rocotolog}" | grep "This cycle is complete: Success")
rc=$?
set_strict
if [ "${rc}" -eq 0 ]; then
if [ -d "${COMINwave}" ]; then rm -rf "${COMINwave}" ; fi
if [ -d "${COMINrtofs}" ] && [ "${GDATE}" -lt "${RTOFS_DATE}" ]; then rm -rf "${COMINrtofs}" ; fi
if [ "${CDUMP}" != "gdas" ] || [ "${DO_GLDAS}" = "NO" ] || [ "${GDATE}" -lt "${GLDAS_DATE}" ]; then
if [ "${CDUMP}" = "gdas" ]; then
for file in $(ls "${COMIN}" |grep -v prepbufr |grep -v cnvstat |grep -v atmanl.nc); do
rm -rf "${COMIN}"/"${file}"
done
else
rm -rf "${COMIN}"
fi
else
if [ "${DO_GLDAS}" = "YES" ]; then
for file in $(ls "${COMIN}" |grep -v sflux |grep -v RESTART |grep -v prepbufr |grep -v cnvstat |grep -v atmanl.nc); do
rm -rf "${COMIN}"/"${file}"
done
for file in $(ls "${COMIN}"/RESTART |grep -v sfcanl ); do
rm -rf "${COMIN}"/RESTART/"${file}"
done
else
for file in $(ls "${COMIN}" |grep -v prepbufr |grep -v cnvstat |grep -v atmanl.nc); do
rm -rf "${COMIN}"/"${file}"
done
fi
fi
fi
fi
fi
# Remove any empty directories
if [ -d "${COMIN}" ]; then
[[ ! "$(ls -A "${COMIN}")" ]] && rm -rf "${COMIN}"
fi
if [ -d "${COMINwave}" ]; then
[[ ! "$(ls -A "${COMINwave}")" ]] && rm -rf "${COMINwave}"
fi
# Remove mdl gfsmos directory
if [ "${CDUMP}" = "gfs" ]; then
COMIN="${ROTDIR}/gfsmos.${gPDY}"
if [ -d "${COMIN}" ] && [ "${GDATE}" -lt "${CDATE_MOS}" ]; then rm -rf "${COMIN}" ; fi
fi
GDATE=$(${NDATE} +"${assim_freq}" "${GDATE}")
done
# Remove archived gaussian files used for Fit2Obs in $VFYARC that are
# $FHMAX_FITS plus a delta before $CDATE. Touch existing archived
# gaussian files to prevent the files from being removed by automatic
# scrubber present on some machines.
if [ "${CDUMP}" = "gfs" ]; then
fhmax=$((FHMAX_FITS+36))
RDATE=$(${NDATE} -"${fhmax}" "${CDATE}")
rPDY=$(echo "${RDATE}" | cut -c1-8)
COMIN="${VFYARC}/${CDUMP}.${rPDY}"
[[ -d ${COMIN} ]] && rm -rf "${COMIN}"
TDATE=$(${NDATE} -"${FHMAX_FITS}" "${CDATE}")
while [ "${TDATE}" -lt "${CDATE}" ]; do
tPDY=$(echo "${TDATE}" | cut -c1-8)
tcyc=$(echo "${TDATE}" | cut -c9-10)
TDIR=${VFYARC}/${CDUMP}.${tPDY}/${tcyc}
[[ -d ${TDIR} ]] && touch "${TDIR}"/*
TDATE=$(${NDATE} +6 "${TDATE}")
done
fi
# Remove $CDUMP.$rPDY for the older of GDATE or RDATE
GDATE=$(${NDATE} -"${RMOLDSTD:-120}" "${CDATE}")
fhmax=${FHMAX_GFS}
RDATE=$(${NDATE} -"${fhmax}" "${CDATE}")
if [ "${GDATE}" -lt "${RDATE}" ]; then
RDATE=${GDATE}
fi
rPDY=$(echo "${RDATE}" | cut -c1-8)
COMIN="${ROTDIR}/${CDUMP}.${rPDY}"
[[ -d ${COMIN} ]] && rm -rf "${COMIN}"
###############################################################
exit 0