forked from NOAA-EMC/global-workflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwave_outp_spec.sh
executable file
·242 lines (210 loc) · 6.96 KB
/
wave_outp_spec.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
#! /usr/bin/env bash
################################################################################
#
# UNIX Script Documentation Block
# Script name: wave_outp_spec.sh
# Script description: Generates ASCII data files with the wave spectral data
#
# Author: Hendrik Tolman Org: NCEP/EMC Date: 2007-03-17
# Abstract: Creates grib2 files from WW3 binary output
#
# Script history log:
# 2019-11-02 J-Henrique Alves Ported to global-workflow.
# 2020-06-10 J-Henrique Alves Ported to R&D machine Hera
#
# $Id$
#
# Attributes:
# Language: Bourne-again (BASH) shell
#
################################################################################
# --------------------------------------------------------------------------- #
# 0. Preparations
source "$HOMEgfs/ush/preamble.sh"
# 0.a Basic modes of operation
bloc=$1
ymdh=$2
specdir=$3
workdir=$4
YMDHE=$($NDATE $FHMAX_WAV_PNT $CDATE)
cd $workdir
rm -rf ${specdir}_${bloc}
mkdir ${specdir}_${bloc}
err=$?
if [ "$err" != '0' ]
then
set +x
echo ' '
echo '****************************************************************************** '
echo '*** FATAL ERROR : ERROR IN ww3_outp_spec (COULD NOT CREATE TEMP DIRECTORY) *** '
echo '****************************************************************************** '
echo ' '
${TRACE_ON:-set -x}
exit 1
fi
cd ${specdir}_${bloc}
set +x
echo ' '
echo '+--------------------------------+'
echo '! Make spectral file |'
echo '+--------------------------------+'
echo " Model ID : $WAV_MOD_TAG"
${TRACE_ON:-set -x}
# 0.b Check if buoy location set
if [ "$#" -lt '1' ]
then
set +x
echo ' '
echo '***********************************************'
echo '*** LOCATION ID IN ww3_outp_spec.sh NOT SET ***'
echo '***********************************************'
echo ' '
${TRACE_ON:-set -x}
exit 1
else
buoy=$bloc
grep $buoy ${DATA}/buoy_log.ww3 > tmp_list.loc
while read line
do
buoy_name=$(echo $line | awk '{print $2}')
if [ $buoy = $buoy_name ]
then
point=$(echo $line | awk '{ print $1 }')
set +x
echo " Location ID/# : $buoy (${point})"
echo " Spectral output start time : $ymdh "
echo ' '
${TRACE_ON:-set -x}
break
fi
done < tmp_list.loc
if [ -z "$point" ]
then
set +x
echo '******************************************************'
echo '*** LOCATION ID IN ww3_outp_spec.sh NOT RECOGNIZED ***'
echo '******************************************************'
echo ' '
${TRACE_ON:-set -x}
exit 2
fi
fi
# 0.c Define directories and the search path.
# The tested variables should be exported by the postprocessor script.
if [ -z "$CDATE" ] || [ -z "$dtspec" ] || [ -z "$EXECwave" ] || \
[ -z "$WAV_MOD_TAG" ] || [ -z "${STA_DIR}" ]
then
set +x
echo ' '
echo '******************************************************'
echo '*** EXPORTED VARIABLES IN ww3_outp_spec.sh NOT SET ***'
echo '******************************************************'
echo ' '
${TRACE_ON:-set -x}
exit 3
fi
# 0.d Starting time for output
tstart="$(echo $ymdh | cut -c1-8) $(echo $ymdh | cut -c9-10)0000"
YMD="$(echo $ymdh | cut -c1-8)"
HMS="$(echo $ymdh | cut -c9-10)0000"
set +x
echo " Output starts at $tstart."
echo ' '
${TRACE_ON:-set -x}
# 0.e sync important files
# $FSYNC ${DATA}/mod_def.${waveuoutpGRD}
# $FSYNC ${DATA}/out_pnt.${waveuoutpGRD}
# $FSYNC ${DATA}/ww3_outp_spec.inp.tmpl
# 0.f Links to mother directory
ln -s ${DATA}/output_${ymdh}0000/mod_def.${waveuoutpGRD} ./mod_def.ww3
ln -s ${DATA}/output_${ymdh}0000/out_pnt.${waveuoutpGRD} ./out_pnt.ww3
# --------------------------------------------------------------------------- #
# 2. Generate spectral data file
# 2.a Input file for postprocessor
set +x
echo " Generate input file for ww3_outp."
${TRACE_ON:-set -x}
if [ "$specdir" = "bull" ]
then
tstart="$(echo $ymdh | cut -c1-8) $(echo $ymdh | cut -c9-10)0000"
truntime="$(echo $CDATE | cut -c1-8) $(echo $CDATE | cut -c9-10)0000"
sed -e "s/TIME/$tstart/g" \
-e "s/DT/$dtspec/g" \
-e "s/POINT/$point/g" \
-e "s/REFT/$truntime/g" \
${DATA}/ww3_outp_bull.inp.tmpl > ww3_outp.inp
outfile=${buoy}.bull
coutfile=${buoy}.cbull
else
sed -e "s/TIME/$tstart/g" \
-e "s/DT/$dtspec/g" \
-e "s/POINT/$point/g" \
-e "s/ITYPE/1/g" \
-e "s/FORMAT/F/g" \
${DATA}/ww3_outp_spec.inp.tmpl > ww3_outp.inp
outfile=ww3.$(echo $tstart | cut -c3-8)$(echo $tstart | cut -c10-11).spc
fi
# 2.b Run the postprocessor
set +x
echo " Executing $EXECwave/ww3_outp"
${TRACE_ON:-set -x}
export pgm=ww3_outp;. prep_step
$EXECwave/ww3_outp 1> outp_${specdir}_${buoy}.out 2>&1
export err=$?;err_chk
if [ "$err" != '0' ]
then
set +x
echo ' '
echo '******************************************** '
echo '*** FATAL ERROR : ERROR IN ww3_outp *** '
echo '******************************************** '
echo ' '
${TRACE_ON:-set -x}
exit 4
fi
# --------------------------------------------------------------------------- #
# 3. Clean up
# 3.a Move data to directory for station ascii files
if [ -f $outfile ]
then
if [ "${ymdh}" = "${CDATE}" ]
then
if [ "$specdir" = "bull" ]
then
cat $outfile | sed -e '9,$d' >> ${STA_DIR}/${specdir}fhr/$WAV_MOD_TAG.${ymdh}.$buoy.bull
cat $coutfile | sed -e '8,$d' >> ${STA_DIR}/c${specdir}fhr/$WAV_MOD_TAG.${ymdh}.$buoy.cbull
else
cat $outfile >> ${STA_DIR}/${specdir}fhr/$WAV_MOD_TAG.${ymdh}.$buoy.spec
fi
elif [ "${ymdh}" = "${YMDHE}" ]
then
if [ "$specdir" = "bull" ]
then
cat $outfile | sed -e '1,7d' >> ${STA_DIR}/${specdir}fhr/$WAV_MOD_TAG.${ymdh}.$buoy.bull
cat $coutfile | sed -e '1,6d' >> ${STA_DIR}/c${specdir}fhr/$WAV_MOD_TAG.${ymdh}.$buoy.cbull
else
cat $outfile | sed -n "/^${YMD} ${HMS}$/,\$p" >> ${STA_DIR}/${specdir}fhr/$WAV_MOD_TAG.${ymdh}.$buoy.spec
fi
else
if [ "$specdir" = "bull" ]
then
cat $outfile | sed -e '1,7d' | sed -e '2,$d' >> ${STA_DIR}/${specdir}fhr/$WAV_MOD_TAG.${ymdh}.$buoy.bull
cat $coutfile | sed -e '1,6d' | sed -e '2,$d' >> ${STA_DIR}/c${specdir}fhr/$WAV_MOD_TAG.${ymdh}.$buoy.cbull
else
cat $outfile | sed -n "/^${YMD} ${HMS}$/,\$p" >> ${STA_DIR}/${specdir}fhr/$WAV_MOD_TAG.${ymdh}.$buoy.spec
fi
fi
else
set +x
echo ' '
echo '***************************************************************** '
echo '*** FATAL ERROR : OUTPUT DATA FILE FOR BOUY $bouy NOT FOUND *** '
echo '***************************************************************** '
echo ' '
${TRACE_ON:-set -x}
exit 5
fi
# 3.b Clean up the rest
cd ..
rm -rf ${specdir}_${bloc}
# End of ww3_outp_spec.sh ---------------------------------------------------- #