-
Notifications
You must be signed in to change notification settings - Fork 176
/
Copy pathexgfs_wave_init.sh
executable file
·214 lines (180 loc) · 5.8 KB
/
exgfs_wave_init.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
#! /usr/bin/env bash
################################################################################
#
# UNIX Script Documentation Block
# Script name: exwave_init.sh
# Script description: Creates model definition files for WW3
#
# Author: Jose-Henrique Alves Org: NCEP/EMC Date: 2019-04-20
# Abstract: This script is the init config for the global multi_grid wave model.
# It creates model definition files with all configurations of spatial
# and spectral grids, as well as physics parameters and time steps.
#
# Script history log:
# 2019-05-06 J-Henrique Alves First Version.
# 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
err=0
cd $DATA
set +x
echo ' '
echo ' ********************************'
echo ' *** MWW3 INIT CONFIG SCRIPT ***'
echo ' ********************************'
echo ' Initial configuration script'
echo " Model identifier : ${CDUMP}wave"
echo ' '
echo "Starting at : $(date)"
echo ' '
${TRACE_ON:-set -x}
# Script will run only if pre-defined NTASKS
# The actual work is distributed over these tasks.
if [ -z ${NTASKS} ]
then
echo "FATAL ERROR: requires NTASKS to be set "
err=1; export err;${errchk}
fi
set +x
echo ' '
echo " Script set to run with $NTASKS tasks "
echo ' '
${TRACE_ON:-set -x}
# --------------------------------------------------------------------------- #
# 1. Get files that are used by most child scripts
set +x
echo 'Preparing input files :'
echo '-----------------------'
echo ' '
${TRACE_ON:-set -x}
# 1.a Model definition files
nmoddef=0
rm -f cmdfile
touch cmdfile
chmod 744 cmdfile
# Eliminate duplicate grids
array=($WAVECUR_FID $WAVEICE_FID $WAVEWND_FID $waveuoutpGRD $waveGRD $waveesmfGRD $wavepostGRD $waveinterpGRD)
grdALL=$(printf "%s\n" "${array[@]}" | sort -u | tr '\n' ' ')
for grdID in ${grdALL}
do
if [ -f "$COMIN/rundata/${CDUMP}wave.mod_def.${grdID}" ]
then
set +x
echo " Mod def file for $grdID found in ${COMIN}/rundata. copying ...."
${TRACE_ON:-set -x}
cp $COMIN/rundata/${CDUMP}wave.mod_def.${grdID} mod_def.$grdID
else
set +x
echo " Mod def file for $grdID not found in ${COMIN}/rundata. Setting up to generate ..."
echo ' '
${TRACE_ON:-set -x}
if [ -f $PARMwave/ww3_grid.inp.$grdID ]
then
cp $PARMwave/ww3_grid.inp.$grdID ww3_grid.inp.$grdID
fi
if [ -f ww3_grid.inp.$grdID ]
then
set +x
echo ' '
echo " ww3_grid.inp.$grdID copied ($PARMwave/ww3_grid.inp.$grdID)."
echo ' '
${TRACE_ON:-set -x}
else
set +x
echo ' '
echo '*********************************************************** '
echo '*** FATAL ERROR : NO INP FILE FOR MODEL DEFINITION FILE *** '
echo '*********************************************************** '
echo " grdID = $grdID"
echo ' '
${TRACE_ON:-set -x}
err=2;export err;${errchk}
fi
[[ ! -d $COMOUT/rundata ]] && mkdir -m 775 -p $COMOUT/rundata
if [ ${CFP_MP:-"NO"} = "YES" ]; then
echo "$nmoddef $USHwave/wave_grid_moddef.sh $grdID > $grdID.out 2>&1" >> cmdfile
else
echo "$USHwave/wave_grid_moddef.sh $grdID > $grdID.out 2>&1" >> cmdfile
fi
nmoddef=$(expr $nmoddef + 1)
fi
done
# 1.a.1 Execute parallel or serialpoe
if [ "$nmoddef" -gt '0' ]
then
set +x
echo ' '
echo " Generating $nmoddef mod def files"
echo ' '
${TRACE_ON:-set -x}
# Set number of processes for mpmd
wavenproc=$(wc -l cmdfile | awk '{print $1}')
wavenproc=$(echo $((${wavenproc}<${NTASKS}?${wavenproc}:${NTASKS})))
# 1.a.3 Execute the serial or parallel cmdfile
set +x
echo ' '
echo " Executing the mod_def command file at : $(date)"
echo ' ------------------------------------'
echo ' '
${TRACE_ON:-set -x}
if [ "$NTASKS" -gt '1' ]
then
if [ ${CFP_MP:-"NO"} = "YES" ]; then
${wavempexec} -n ${wavenproc} ${wave_mpmd} cmdfile
else
${wavempexec} ${wavenproc} ${wave_mpmd} cmdfile
fi
exit=$?
else
./cmdfile
exit=$?
fi
if [ "$exit" != '0' ]
then
set +x
echo ' '
echo '********************************************************'
echo '*** FATAL ERROR: POE FAILURE DURING RAW DATA COPYING ***'
echo '********************************************************'
echo ' See Details Below '
echo ' '
${TRACE_ON:-set -x}
fi
fi
# 1.a.3 File check
for grdID in ${grdALL}
do
if [ -f ${COMOUT}/rundata/${CDUMP}wave.mod_def.$grdID ]
then
set +x
echo ' '
echo " mod_def.$grdID succesfully created/copied "
echo ' '
${TRACE_ON:-set -x}
else
set +x
echo ' '
echo '********************************************** '
echo '*** FATAL ERROR : NO MODEL DEFINITION FILE *** '
echo '********************************************** '
echo " grdID = $grdID"
echo ' '
sed "s/^/$grdID.out : /g" $grdID.out
${TRACE_ON:-set -x}
err=3;export err;${errchk}
fi
done
# --------------------------------------------------------------------------- #
# 2. Ending
# End of MWW3 init config script ------------------------------------------- #