forked from NOAA-EMC/global-workflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexglobal_diag.sh
executable file
·280 lines (243 loc) · 9.22 KB
/
exglobal_diag.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
#! /usr/bin/env bash
################################################################################
#### UNIX Script Documentation Block
# . .
# Script name: exglobal_diag.sh
# Script description: Creates diagnostic files after GSI analysis is performed
#
# Author: Cory Martin Org: NCEP/EMC Date: 2020-03-03
#
# Abstract: This script creates GSI diagnostic files after GSI exits successfully
#
# $Id$
#
# Attributes:
# Language: POSIX shell
#
################################################################################
# Set environment.
source "${USHgfs}/preamble.sh"
# Directories.
pwd=$(pwd)
# Base variables
CDATE="${PDY}${cyc}"
GDUMP=${GDUMP:-"gdas"}
# Utilities
export CHGRP_CMD=${CHGRP_CMD:-"chgrp ${group_name:-rstprod}"}
export NCLEN=${NCLEN:-${USHgfs}/getncdimlen}
export CATEXEC=${CATEXEC:-${ncdiag_ROOT:-${gsi_ncdiag_ROOT}}/bin/ncdiag_cat_serial.x}
COMPRESS=${COMPRESS:-gzip}
UNCOMPRESS=${UNCOMPRESS:-gunzip}
APRUNCFP=${APRUNCFP:-""}
# Diagnostic files options
netcdf_diag=${netcdf_diag:-".true."}
binary_diag=${binary_diag:-".false."}
# OPS flags
RUN=${RUN:-""}
SENDECF=${SENDECF:-"NO"}
SENDDBN=${SENDDBN:-"NO"}
# Guess files
# Analysis files
export APREFIX=${APREFIX:-""}
RADSTAT=${RADSTAT:-${COMOUT_ATMOS_ANALYSIS}/${APREFIX}radstat}
PCPSTAT=${PCPSTAT:-${COMOUT_ATMOS_ANALYSIS}/${APREFIX}pcpstat}
CNVSTAT=${CNVSTAT:-${COMOUT_ATMOS_ANALYSIS}/${APREFIX}cnvstat}
OZNSTAT=${OZNSTAT:-${COMOUT_ATMOS_ANALYSIS}/${APREFIX}oznstat}
# Remove stat file if file already exists
[[ -s $RADSTAT ]] && rm -f $RADSTAT
[[ -s $PCPSTAT ]] && rm -f $PCPSTAT
[[ -s $CNVSTAT ]] && rm -f $CNVSTAT
[[ -s $OZNSTAT ]] && rm -f $OZNSTAT
# Obs diag
GENDIAG=${GENDIAG:-"YES"}
DIAG_SUFFIX=${DIAG_SUFFIX:-""}
if [ $netcdf_diag = ".true." ] ; then
DIAG_SUFFIX="${DIAG_SUFFIX}.nc4"
fi
DIAG_COMPRESS=${DIAG_COMPRESS:-"YES"}
DIAG_TARBALL=${DIAG_TARBALL:-"YES"}
USE_CFP=${USE_CFP:-"NO"}
CFP_MP=${CFP_MP:-"NO"}
nm=""
if [ $CFP_MP = "YES" ]; then
nm=0
fi
DIAG_DIR=${DIAG_DIR:-${COMOUT_ATMOS_ANALYSIS}/gsidiags}
REMOVE_DIAG_DIR=${REMOVE_DIAG_DIR:-"NO"}
# Set script / GSI control parameters
lrun_subdirs=${lrun_subdirs:-".true."}
################################################################################
# If requested, generate diagnostic files
if [ $GENDIAG = "YES" ] ; then
if [ $lrun_subdirs = ".true." ] ; then
for pe in $DIAG_DIR/dir.*; do
pedir="$(basename -- $pe)"
$NLN $pe $DATA/$pedir
done
else
err_exit "***FATAL ERROR*** lrun_subdirs must be true. Abort job"
fi
# Set up lists and variables for various types of diagnostic files.
ntype=3
diagtype[0]="conv conv_gps conv_ps conv_pw conv_q conv_sst conv_t conv_tcp conv_uv conv_spd"
diagtype[1]="pcp_ssmi_dmsp pcp_tmi_trmm"
diagtype[2]="sbuv2_n16 sbuv2_n17 sbuv2_n18 sbuv2_n19 gome_metop-a gome_metop-b omi_aura mls30_aura ompsnp_npp ompstc8_npp ompstc8_n20 ompsnp_n20 ompstc8_n21 ompsnp_n21 ompslp_npp gome_metop-c"
diagtype[3]="msu_n14 sndr_g08 sndr_g11 sndr_g12 sndr_g13 sndr_g08_prep sndr_g11_prep sndr_g12_prep sndr_g13_prep sndrd1_g11 sndrd2_g11 sndrd3_g11 sndrd4_g11 sndrd1_g12 sndrd2_g12 sndrd3_g12 sndrd4_g12 sndrd1_g13 sndrd2_g13 sndrd3_g13 sndrd4_g13 sndrd1_g14 sndrd2_g14 sndrd3_g14 sndrd4_g14 sndrd1_g15 sndrd2_g15 sndrd3_g15 sndrd4_g15 amsua_n15 amsua_n16 amsua_n17 amsub_n15 amsub_n16 amsub_n17 hsb_aqua airs_aqua amsua_aqua imgr_g08 imgr_g11 imgr_g12 imgr_g14 imgr_g15 ssmi_f13 ssmi_f15 amsua_n18 amsua_metop-a mhs_n18 mhs_metop-a amsre_low_aqua amsre_mid_aqua amsre_hig_aqua ssmis_f16 ssmis_f17 ssmis_f18 ssmis_f19 ssmis_f20 iasi_metop-a amsua_n19 mhs_n19 seviri_m08 seviri_m09 seviri_m10 seviri_m11 cris_npp cris-fsr_npp cris-fsr_n20 atms_npp atms_n20 amsua_metop-b mhs_metop-b iasi_metop-b avhrr_metop-b avhrr_n18 avhrr_n19 avhrr_metop-a amsr2_gcom-w1 gmi_gpm saphir_meghat ahi_himawari8 abi_g16 abi_g17 amsua_metop-c mhs_metop-c iasi_metop-c avhrr_metop-c viirs-m_npp viirs-m_j1 abi_g18 ahi_himawari9 viirs-m_j2 cris-fsr_n21 atms_n21"
diaglist[0]=listcnv
diaglist[1]=listpcp
diaglist[2]=listozn
diaglist[3]=listrad
diagfile[0]=$CNVSTAT
diagfile[1]=$PCPSTAT
diagfile[2]=$OZNSTAT
diagfile[3]=$RADSTAT
numfile[0]=0
numfile[1]=0
numfile[2]=0
numfile[3]=0
# Set diagnostic file prefix based on lrun_subdirs variable
if [ $lrun_subdirs = ".true." ]; then
prefix=" dir.*/"
else
prefix="pe*"
fi
if [ $USE_CFP = "YES" ]; then
[[ -f $DATA/diag.sh ]] && rm $DATA/diag.sh
[[ -f $DATA/mp_diag.sh ]] && rm $DATA/mp_diag.sh
cat > $DATA/diag.sh << EOFdiag
#!/bin/sh
lrun_subdirs=\$1
binary_diag=\$2
type=\$3
loop=\$4
string=\$5
CDATE=\$6
DIAG_COMPRESS=\$7
DIAG_SUFFIX=\$8
if [ \$lrun_subdirs = ".true." ]; then
prefix=" dir.*/"
else
prefix="pe*"
fi
file=diag_\${type}_\${string}.\${CDATE}\${DIAG_SUFFIX}
if [ \$binary_diag = ".true." ]; then
cat \${prefix}\${type}_\${loop}* > \$file
else
$CATEXEC -o \$file \${prefix}\${type}_\${loop}*
fi
if [ \$DIAG_COMPRESS = "YES" ]; then
$COMPRESS \$file
fi
EOFdiag
chmod 755 $DATA/diag.sh
fi
# Collect diagnostic files as a function of loop and type.
# Loop over first and last outer loops to generate innovation
# diagnostic files for indicated observation types (groups)
#
# NOTE: Since we set miter=2 in GSI namelist SETUP, outer
# loop 03 will contain innovations with respect to
# the analysis. Creation of o-a innovation files
# is triggered by write_diag(3)=.true. The setting
# write_diag(1)=.true. turns on creation of o-g
# innovation files.
loops="01 03"
for loop in $loops; do
case $loop in
01) string=ges;;
03) string=anl;;
*) string=$loop;;
esac
echo $(date) START loop $string >&2
n=-1
while [ $((n+=1)) -le $ntype ] ;do
for type in $(echo ${diagtype[n]}); do
count=$(ls ${prefix}${type}_${loop}* 2>/dev/null | wc -l)
if [ $count -gt 1 ]; then
if [ $USE_CFP = "YES" ]; then
echo "$nm $DATA/diag.sh $lrun_subdirs $binary_diag $type $loop $string $CDATE $DIAG_COMPRESS $DIAG_SUFFIX" | tee -a $DATA/mp_diag.sh
if [ ${CFP_MP:-"NO"} = "YES" ]; then
nm=$((nm+1))
fi
else
if [ $binary_diag = ".true." ]; then
cat ${prefix}${type}_${loop}* > diag_${type}_${string}.${CDATE}${DIAG_SUFFIX}
else
$CATEXEC -o diag_${type}_${string}.${CDATE}${DIAG_SUFFIX} ${prefix}${type}_${loop}*
fi
fi
echo "diag_${type}_${string}.${CDATE}*" >> ${diaglist[n]}
numfile[n]=$(expr ${numfile[n]} + 1)
elif [ $count -eq 1 ]; then
cat ${prefix}${type}_${loop}* > diag_${type}_${string}.${CDATE}${DIAG_SUFFIX}
if [ $DIAG_COMPRESS = "YES" ]; then
$COMPRESS diag_${type}_${string}.${CDATE}${DIAG_SUFFIX}
fi
echo "diag_${type}_${string}.${CDATE}*" >> ${diaglist[n]}
numfile[n]=$(expr ${numfile[n]} + 1)
fi
done
done
echo $(date) END loop $string >&2
done
# We should already be in $DATA, but extra cd to be sure.
cd $DATA
# If requested, compress diagnostic files
if [ $DIAG_COMPRESS = "YES" -a $USE_CFP = "NO" ]; then
echo $(date) START $COMPRESS diagnostic files >&2
for file in $(ls diag_*${CDATE}${DIAG_SUFFIX}); do
$COMPRESS $file
done
echo $(date) END $COMPRESS diagnostic files >&2
fi
if [ $USE_CFP = "YES" ] ; then
chmod 755 $DATA/mp_diag.sh
ncmd=$(cat $DATA/mp_diag.sh | wc -l)
if [ $ncmd -gt 0 ]; then
ncmd_max=$((ncmd < max_tasks_per_node ? ncmd : max_tasks_per_node))
APRUNCFP_DIAG=$(eval echo $APRUNCFP)
$APRUNCFP_DIAG $DATA/mp_diag.sh
export err=$?; err_chk
fi
fi
# Restrict diagnostic files containing rstprod data
rlist="conv_gps conv_ps conv_pw conv_q conv_sst conv_t conv_uv saphir"
for rtype in $rlist; do
for rfile in *"${rtype}"*; do
if [[ -s "${rfile}" ]]; then
${CHGRP_CMD} "${rfile}"
fi
done
done
# If requested, create diagnostic file tarballs
if [ $DIAG_TARBALL = "YES" ]; then
echo $(date) START tar diagnostic files >&2
n=-1
while [ $((n+=1)) -le $ntype ] ;do
TAROPTS="-uvf"
if [ ! -s ${diagfile[n]} ]; then
TAROPTS="-cvf"
fi
if [ ${numfile[n]} -gt 0 ]; then
tar $TAROPTS ${diagfile[n]} $(cat ${diaglist[n]})
export err=$?; err_chk
fi
done
# Restrict CNVSTAT
chmod 750 $CNVSTAT
${CHGRP_CMD} $CNVSTAT
# Restrict RADSTAT
chmod 750 $RADSTAT
${CHGRP_CMD} $RADSTAT
echo $(date) END tar diagnostic files >&2
fi
fi # End diagnostic file generation block - if [ $GENDIAG = "YES" ]
################################################################################
# Postprocessing
# If no processing error, remove $DIAG_DIR
if [[ "$REMOVE_DIAG_DIR" = "YES" && "$err" = "0" ]]; then
rm -rf $DIAG_DIR
fi
cd $pwd
[[ "${mkdata:-YES}" = "YES" ]] && rm -rf $DATA
exit $err