forked from NOAA-EMC/global-workflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwave_tar.sh
executable file
·223 lines (186 loc) · 6.39 KB
/
wave_tar.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
#! /usr/bin/env bash
###############################################################################
# #
# This script tars the sectral or bulletin files into a single file and #
# puts it into /com. This is a separate script to enable it to be run in #
# parallel using poe. It also tars the spectral and bulletin files of the #
# old grids that are generated for backward compatibility #
# #
# Remarks : #
# - Shell script variables controling time, directories etc. are set in the #
# mother script. #
# - This script runs in the work directory designated in the mother script. #
# Under this directory it geneates a work directory TAR_$type_$ID which is #
# removed if this script exits normally. #
# - See section 0.c for variables that need to be set. #
# #
# Origination: Hendrik Tolman March 13, 2007 #
# Update log #
# Nov2019 JHAlves - Merging wave scripts to global workflow #
# 2020-06-10 J-Henrique Alves Ported R&D machine Hera
# #
###############################################################################
#
# --------------------------------------------------------------------------- #
# 0. Preparations
source "${USHgfs}/preamble.sh"
# 0.a Basic modes of operation
cd "${DATA}"
echo "Making TAR FILE"
alertName=$(echo $RUN|tr [a-z] [A-Z])
set +x
echo ' '
echo '+--------------------------------+'
echo '! Make tar file |'
echo '+--------------------------------+'
echo " ID : $1"
echo " Type : $2"
echo " Number of files : $3"
set_trace
# 0.b Check if type set
if [[ "$#" -lt '3' ]]
then
set +x
echo ' '
echo '********************************************'
echo '*** VARIABLES IN ww3_tar.sh NOT SET ***'
echo '********************************************'
echo ' '
set_trace
exit 1
else
ID=$1
type=$2
nb=$3
fi
filext=$type
if [[ "$type" = "ibp" ]]; then filext='spec'; fi
if [[ "$type" = "ibpbull" ]]; then filext='bull'; fi
if [[ "$type" = "ibpcbull" ]]; then filext='cbull'; fi
rm -rf TAR_${filext}_$ID
mkdir TAR_${filext}_$ID
# this directory is used only for error capturing
# 0.c Define directories and the search path.
# The tested variables should be exported by the postprocessor script.
if [[ -z "${cycle}" ]] || [[ -z "${COMOUT_WAVE_STATION}" ]] || [[ -z "${WAV_MOD_TAG}" ]] || \
[[ -z "${SENDDBN}" ]] || [[ -z "${STA_DIR}" ]]; then
set +x
echo ' '
echo '*****************************************************'
echo '*** EXPORTED VARIABLES IN ww3_tar.sh NOT SET ***'
echo '*****************************************************'
echo ' '
set_trace
exit 2
fi
cd "${STA_DIR}/${filext}"
# --------------------------------------------------------------------------- #
# 2. Generate tar file (spectral files are compressed)
set +x
echo ' '
echo ' Making tar file ...'
set_trace
countMAX=5
tardone='no'
sleep_interval=10
while [[ "${tardone}" = "no" ]]
do
nf=$(ls | awk '/'$ID.*.$filext'/ {a++} END {print a}')
nbm2=$(( $nb - 2 ))
if [[ "${nf}" -ge "${nbm2}" ]]
then
tar -cf "${ID}.${cycle}.${type}_tar" ./${ID}.*.${filext}
exit=$?
filename="${ID}.${cycle}.${type}_tar"
if ! wait_for_file "${filename}" "${sleep_interval}" "${countMAX}" ; then
echo "FATAL ERROR: File ${filename} not found after waiting $(( sleep_interval * (countMAX + 1) )) secs"
exit 3
fi
if [[ "${exit}" != '0' ]]
then
set +x
echo ' '
echo '***************************************** '
echo '*** FATAL ERROR : TAR CREATION FAILED *** '
echo '***************************************** '
echo ' '
set_trace
exit 3
fi
if [[ -f "${ID}.${cycle}.${type}_tar" ]]
then
tardone='yes'
fi
fi
done
if [[ "${tardone}" = 'no' ]]
then
set +x
echo ' '
echo '***************************************** '
echo '*** FATAL ERROR : TAR CREATION FAILED *** '
echo '***************************************** '
echo ' '
set_trace
exit 3
fi
if [[ "${type}" = 'spec' ]]
then
if [[ -s "${ID}.${cycle}.${type}_tar" ]]
then
file_name="${ID}.${cycle}.${type}_tar.gz"
/usr/bin/gzip -c "${ID}.${cycle}.${type}_tar" > "${file_name}"
exit=$?
if [[ "${exit}" != '0' ]]
then
set +x
echo ' '
echo '***************************************************** '
echo '*** FATAL ERROR : SPECTRAL TAR COMPRESSION FAILED *** '
echo '***************************************************** '
echo ' '
set_trace
exit 4
fi
fi
else
file_name="${ID}.${cycle}.${type}_tar"
fi
# --------------------------------------------------------------------------- #
# 3. Move data to /com
set +x
echo ' '
echo " Moving tar file ${file_name} to ${COMOUT_WAVE_STATION} ..."
set_trace
cp "${file_name}" "${COMOUT_WAVE_STATION}/."
exit=$?
if [[ "${exit}" != '0' ]]
then
set +x
echo ' '
echo '************************************* '
echo '*** FATAL ERROR : TAR COPY FAILED *** '
echo '************************************* '
echo ' '
set_trace
exit 4
fi
if [[ "${SENDDBN}" = 'YES' ]]
then
set +x
echo ' '
echo " Alerting TAR file as ${COMOUT_WAVE_STATION}/${file_name}"
echo ' '
set_trace
"${DBNROOT}/bin/dbn_alert MODEL" "${alertName}_WAVE_TAR" "${job}" \
"${COMOUT_WAVE_STATION}/${file_name}"
fi
# --------------------------------------------------------------------------- #
# 4. Final clean up
cd "${DATA}"
if [[ ${KEEPDATA:-NO} == "NO" ]]; then
set -v
rm -rf ${STA_DIR}/${type}
set +v
fi
# End of ww3_tar.sh ----------------------------------------------------- #