-
Notifications
You must be signed in to change notification settings - Fork 177
/
Copy pathexglobal_archive.sh
executable file
·315 lines (269 loc) · 11.7 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
#! /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="${RUN}.t${cyc}z."
# Realtime parallels run GFS MOS on 1 day delay
# If realtime parallel, back up CDATE_MOS one day
# Ignore possible spelling error (nothing is misspelled)
# shellcheck disable=SC2153
CDATE_MOS=${PDY}${cyc}
if [ "${REALTIME}" = "YES" ]; then
CDATE_MOS=$(${NDATE} -24 "${PDY}${cyc}")
fi
PDY_MOS="${CDATE_MOS:0:8}"
###############################################################
# Archive online for verification and diagnostics
###############################################################
source "${HOMEgfs}/ush/file_utils.sh"
[[ ! -d ${ARCDIR} ]] && mkdir -p "${ARCDIR}"
nb_copy "${COM_ATMOS_ANALYSIS}/${APREFIX}gsistat" "${ARCDIR}/gsistat.${RUN}.${PDY}${cyc}"
nb_copy "${COM_CHEM_ANALYSIS}/${APREFIX}aerostat" "${ARCDIR}/aerostat.${RUN}.${PDY}${cyc}"
nb_copy "${COM_ATMOS_GRIB_1p00}/${APREFIX}pgrb2.1p00.anl" "${ARCDIR}/pgbanl.${RUN}.${PDY}${cyc}.grib2"
# Archive 1 degree forecast GRIB2 files for verification
if [[ "${RUN}" == "gfs" ]]; then
fhmax=${FHMAX_GFS}
fhr=0
while [ "${fhr}" -le "${fhmax}" ]; do
fhr2=$(printf %02i "${fhr}")
fhr3=$(printf %03i "${fhr}")
nb_copy "${COM_ATMOS_GRIB_1p00}/${APREFIX}pgrb2.1p00.f${fhr3}" "${ARCDIR}/pgbf${fhr2}.${RUN}.${PDY}${cyc}.grib2"
fhr=$((10#${fhr} + 10#${FHOUT_GFS} ))
done
fi
if [[ "${RUN}" == "gdas" ]]; then
flist="000 003 006 009"
for fhr in ${flist}; do
fname="${COM_ATMOS_GRIB_1p00}/${APREFIX}pgrb2.1p00.f${fhr}"
# TODO Shouldn't the archived files also use three-digit tags?
fhr2=$(printf %02i $((10#${fhr})))
nb_copy "${fname}" "${ARCDIR}/pgbf${fhr2}.${RUN}.${PDY}${cyc}.grib2"
done
fi
if [[ -s "${COM_ATMOS_TRACK}/avno.t${cyc}z.cyclone.trackatcfunix" ]]; then
# shellcheck disable=2153
PSLOT4=${PSLOT:0:4}
# shellcheck disable=
PSLOT4=${PSLOT4^^}
sed "s:AVNO:${PSLOT4}:g" < "${COM_ATMOS_TRACK}/avno.t${cyc}z.cyclone.trackatcfunix" \
> "${ARCDIR}/atcfunix.${RUN}.${PDY}${cyc}"
sed "s:AVNO:${PSLOT4}:g" < "${COM_ATMOS_TRACK}/avnop.t${cyc}z.cyclone.trackatcfunix" \
> "${ARCDIR}/atcfunixp.${RUN}.${PDY}${cyc}"
fi
if [[ "${RUN}" == "gdas" ]] && [[ -s "${COM_ATMOS_TRACK}/gdas.t${cyc}z.cyclone.trackatcfunix" ]]; then
# shellcheck disable=2153
PSLOT4=${PSLOT:0:4}
# shellcheck disable=
PSLOT4=${PSLOT4^^}
sed "s:AVNO:${PSLOT4}:g" < "${COM_ATMOS_TRACK}/gdas.t${cyc}z.cyclone.trackatcfunix" \
> "${ARCDIR}/atcfunix.${RUN}.${PDY}${cyc}"
sed "s:AVNO:${PSLOT4}:g" < "${COM_ATMOS_TRACK}/gdasp.t${cyc}z.cyclone.trackatcfunix" \
> "${ARCDIR}/atcfunixp.${RUN}.${PDY}${cyc}"
fi
if [ "${RUN}" = "gfs" ]; then
nb_copy "${COM_ATMOS_GENESIS}/storms.gfso.atcf_gen.${PDY}${cyc}" "${ARCDIR}/."
nb_copy "${COM_ATMOS_GENESIS}/storms.gfso.atcf_gen.altg.${PDY}${cyc}" "${ARCDIR}/."
nb_copy "${COM_ATMOS_TRACK}/trak.gfso.atcfunix.${PDY}${cyc}" "${ARCDIR}/."
nb_copy "${COM_ATMOS_TRACK}/trak.gfso.atcfunix.altg.${PDY}${cyc}" "${ARCDIR}/."
mkdir -p "${ARCDIR}/tracker.${PDY}${cyc}/${RUN}"
blist="epac natl"
for basin in ${blist}; do
if [[ -f ${basin} ]]; then
cp -rp "${COM_ATMOS_TRACK}/${basin}" "${ARCDIR}/tracker.${PDY}${cyc}/${RUN}"
fi
done
fi
# Archive required gaussian gfs forecast files for Fit2Obs
if [[ "${RUN}" == "gfs" ]] && [[ "${FITSARC}" = "YES" ]]; then
VFYARC=${VFYARC:-${ROTDIR}/vrfyarch}
[[ ! -d ${VFYARC} ]] && mkdir -p "${VFYARC}"
mkdir -p "${VFYARC}/${RUN}.${PDY}/${cyc}"
prefix="${RUN}.t${cyc}z"
fhmax=${FHMAX_FITS:-${FHMAX_GFS}}
fhr=0
while [[ ${fhr} -le ${fhmax} ]]; do
fhr3=$(printf %03i "${fhr}")
sfcfile="${COM_ATMOS_HISTORY}/${prefix}.sfcf${fhr3}.nc"
sigfile="${COM_ATMOS_HISTORY}/${prefix}.atmf${fhr3}.nc"
nb_copy "${sfcfile}" "${VFYARC}/${RUN}.${PDY}/${cyc}/"
nb_copy "${sigfile}" "${VFYARC}/${RUN}.${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"
HSICMD="hsi"
if [[ ${LOCALARCH} = "YES" ]]; then
TARCMD="tar"
HSICMD=''
[[ ! -d "${ATARDIR}/${PDY}${cyc}" ]] && mkdir -p "${ATARDIR}/${PDY}${cyc}"
[[ ! -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="${PDY:2:2}"
dd="${PDY:4:2}"
# TODO: This math yields multiple dates sharing the same nday
nday=$(( (10#${mm}-1)*30+10#${dd} ))
mod=$((nday % ARCH_WARMICFREQ))
if [[ "${PDY}${cyc}" -eq "${firstday}" ]] && [[ "${cyc}" -eq "${ARCHINC_CYC}" ]]; then SAVEWARMICA="YES" ; fi
if [[ "${PDY}${cyc}" -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 [[ "${PDY}${cyc}" -eq "${SDATE}" ]] && [[ "${cyc}" -eq "${ARCHICS_CYC}" ]] ; then SAVEWARMICB="YES" ; fi
fi
mod=$((nday % ARCH_FCSTICFREQ))
if [[ "${mod}" -eq 0 ]] || [[ "${PDY}${cyc}" -eq "${firstday}" ]]; then SAVEFCSTIC="YES" ; fi
cd "${DATA}" || exit 2
"${HOMEgfs}/ush/hpssarch_gen.sh" "${RUN}"
status=$?
if [ "${status}" -ne 0 ]; then
echo "${HOMEgfs}/ush/hpssarch_gen.sh ${RUN} failed, ABORT!"
exit "${status}"
fi
cd "${ROTDIR}" || exit 2
if [[ "${RUN}" = "gfs" ]]; then
targrp_list="gfsa gfsb"
if [ "${ARCH_GAUSSIAN:-"NO"}" = "YES" ]; then
targrp_list="${targrp_list} gfs_flux gfs_netcdfb gfs_pgrb2b"
if [ "${MODE}" = "cycled" ]; then
targrp_list="${targrp_list} gfs_netcdfa"
fi
fi
if [ "${DO_WAVE}" = "YES" ]; 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
# TODO: Why is this tar being done here instead of being added to the list?
${TARCMD} -P -cvf "${ATARDIR}/${PDY}${cyc}/${targrp}.tar" $(cat "${DATA}/${targrp}.txt")
status=$?
if [[ "${status}" -ne 0 ]] && [[ "${PDY}${cyc}" -ge "${firstday}" ]]; then
echo "HTAR ${PDY}${cyc} ${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" ]; 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
# TODO: Why is this tar being done here instead of being added to the list?
${TARCMD} -P -cvf "${ATARDIR}/${CDATE_MOS}/gfsmos.tar" "./gfsmos.${PDY_MOS}"
status=$?
if [[ "${status}" -ne 0 ]] && [[ "${PDY}${cyc}" -ge "${firstday}" ]]; then
echo "${TARCMD^^} ${PDY}${cyc} gfsmos.tar failed"
exit "${status}"
fi
set_strict
fi
elif [[ "${RUN}" = "gdas" ]]; then
targrp_list="gdas"
#gdaswave
if [ "${DO_WAVE}" = "YES" ]; then
targrp_list="${targrp_list} gdaswave"
fi
#gdasocean
if [ "${DO_OCN}" = "YES" ]; then
targrp_list="${targrp_list} gdasocean gdasocean_analysis"
fi
#gdasice
if [ "${DO_ICE}" = "YES" ]; then
targrp_list="${targrp_list} gdasice"
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
if [ "${DO_OCN}" = "YES" ]; then targrp_list="${targrp_list} gdasocean_restart"; fi
if [ "${DO_ICE}" = "YES" ]; then targrp_list="${targrp_list} gdasice_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
# Test whether gdas.tar or gdas_restarta.tar will have rstprod data
has_rstprod="NO"
case ${targrp} in
'gdas'|'gdas_restarta')
# Test for rstprod in each archived file
while IFS= read -r file; do
if [[ -f ${file} ]]; then
group=$( stat -c "%G" "${file}" )
if [[ "${group}" == "rstprod" ]]; then
has_rstprod="YES"
break
fi
fi
done < "${DATA}/${targrp}.txt"
;;
*) ;;
esac
# Create the tarball
tar_fl="${ATARDIR}/${PDY}${cyc}/${targrp}.tar"
${TARCMD} -P -cvf "${tar_fl}" $(cat "${DATA}/${targrp}.txt")
status=$?
# Change group to rstprod if it was found even if htar/tar failed in case of partial creation
if [[ "${has_rstprod}" == "YES" ]]; then
${HSICMD} chgrp rstprod "${tar_fl}"
stat_chgrp=$?
${HSICMD} chmod 640 "${tar_fl}"
stat_chgrp=$((stat_chgrp+$?))
if [ "${stat_chgrp}" -gt 0 ]; then
echo "FATAL ERROR: Unable to properly restrict ${tar_fl}!"
echo "Attempting to delete ${tar_fl}"
${HSICMD} rm "${tar_fl}"
echo "Please verify that ${tar_fl} was deleted!"
exit "${stat_chgrp}"
fi
fi
# For safety, test if the htar/tar command failed after changing groups
if [[ "${status}" -ne 0 ]] && [[ "${PDY}${cyc}" -ge "${firstday}" ]]; then
echo "FATAL ERROR: ${TARCMD} ${tar_fl} failed"
exit "${status}"
fi
set_strict
done
# Turn extended globbing back off
shopt -u extglob
###############################################################
fi ##end of HPSS archive
###############################################################
exit 0