forked from NOAA-EMC/WW3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathw3_setup
executable file
·470 lines (423 loc) · 15.3 KB
/
w3_setup
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
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
#!/bin/bash -e
# --------------------------------------------------------------------------- #
# #
# Script for setting up (installing) WAVEWATCH III. #
# #
# --------------------------------------------------------------------------- #
# --------------------------------------------------------------------------- #
# 0. Process command line arguments #
# --------------------------------------------------------------------------- #
# 0.a Error message function
errmsg ()
{
echo "" 2>&1
while [ $# != 0 ]
do
echo "ERROR: $1" 2>&1
shift
done
echo "" 2>&1
}
# 0.b Usage function
myname="`basename $0`" #name of script
optstr="c:hqs:et:" #option string for getopt function
usage ()
{
cat 2>&1 << EOF
Usage: $myname source_dir Options
Required:
source_dir : path to model dir of WW3 source
Options:
-c cmplr : setup comp & link files for specified cmplr (see manual section 5.6)
-s swtch : setup switch file for specified swtch (see manual section 5.8)
-h : print usage and exit
-q : do not prompt for changes to existing WW3 environment
-e : edit switch file
-t tdir : set path for scratch directory to tdir
EOF
}
# 0.c Setup array of command-line arguments
args=`getopt $optstr $*`
if [ $? != 0 ]
then
usage
exit 1
fi
set -- $args
# 0.d Process command-line options
while :
do
case "$1" in
-c) shift; cmplr="$1" ;;
-h) help=1 ;;
-q) no_prompt=1 ;;
-s) shift; swtch="$1" ;;
-e) edit=1 ;;
-t) shift; tdir="$1" ;;
--) break ;;
esac
shift
done
shift #remove the trailing --
if [ $help ]
then
usage
exit 1
fi
# 0.e Get required arguments
if [ ! $# = 0 ]
then
path_s="$1" ; shift
else
usage
exit 1
fi
# --------------------------------------------------------------------------- #
# 1. Preparations #
# --------------------------------------------------------------------------- #
# 1.a ID header - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
echo ' '
echo ' *****************************'
echo ' *** WAVEWATCH III setup ***'
echo ' *****************************'
echo ' '
# 1.b Convert source path from "relative" to "absolute"
if [ ! -d $path_s ]
then
errmsg "$path_s not found"
usage
exit 1
fi
path_s="`cd $path_s 1>/dev/null 2>&1 && pwd`"
# 1.c Paths to source subdirectories
path_b="$path_s/bin"
if [ ! -d $path_b ]
then
errmsg "$path_b not found"
exit 1
fi
path_a="$path_s/tools"
if [ ! -d $path_a ]
then
errmsg "$path_a not found"
exit 1
fi
# --------------------------------------------------------------------------- #
# 2. Set up WWATCH3 environment #
# --------------------------------------------------------------------------- #
# 2.a Environment file
if [[ "$0" = /* ]]
then
path_bin=$(dirname $0)
else
path_bin="${PWD}/$(dirname $0)"
fi
path_bin="`cd $path_bin 1>/dev/null 2>&1 && pwd`"
echo ' '
if [ -e $path_bin/wwatch3.env ]
then
ww3_env=$path_bin/wwatch3.env
echo "[INFO] local env file wwatch3.env found in $ww3_env"
elif [ -e ${HOME}/.wwatch3.env ]
then
cp ${HOME}/.wwatch3.env $path_bin/wwatch3.env
ww3_env=$path_bin/wwatch3.env
echo "[INFO] global env file wwatch3.env copied in $ww3_env"
elif [ ! -z ${WWATCH3_ENV} ]
then
ww3_env=${WWATCH3_ENV}
echo "[INFO] user defined env file wwatch3.env found in $ww3_env"
else
ww3_env=$path_bin/wwatch3.env
echo "[INFO] local env file wwatch3.env created in $ww3_env"
fi
# 2.b Check for existing environment and set defaults
if [ -f $ww3_env ]
then
echo " Setup file $ww3_env found"
echo " Source directory : $path_s"
set `grep WWATCH3_TMP $ww3_env` ; shift
if [ $tdir ]
then
temp_dir=$tdir
else
temp_dir="$*"
fi
echo " Scratch directory : $temp_dir"
set `grep WWATCH3_SOURCE $ww3_env` ; shift
source="$*"
echo " Save source code : $source"
set `grep WWATCH3_LIST $ww3_env` ; shift
list="$*"
echo " Save listings : $list"
else
echo " Setup file $ww3_env not found"
if [ $tdir ]
then
temp_dir=$tdir
else
temp_dir=$(dirname $path_bin)/tmp
fi
source=yes
list=yes
echo ' '
echo " Default set up :"
echo " Scratch directory : $temp_dir"
echo " Save sources : $source"
echo " Save listings : $list"
fi
if [ $no_prompt ]
then
do_set='n'
else
OK="$NULL"
until [ "$OK" = 'y' ] || [ "$OK" = 'Y' ] || \
[ "$OK" = 'n' ] || [ "$OK" = 'N' ]
do
echo -n " Update settings ? [y/n] "
read OK
case $OK in
'y'|'Y') do_set='y' ;;
'n'|'N') do_set='n' ;;
esac
done
fi
# 2.c Get user input for new environment
if [ "$do_set" = 'y' ]
then
# Get user input for new set-up
echo ' '
echo " Creating new set-up :"
OK="$NULL"
until [ "$OK" = 'y' ] || [ "$OK" = 'Y' ]
do
echo ' '
OK="$NULL"
until [ "$OK" = 'y' ]
do
echo -n " Scratch space [$temp_dir] : "
instr="$NULL" ; read instr
if [ -n "$instr" ]
then
temp_dir="$instr"
fi
if [ -n "$temp_dir" ]
then
if [ -d $temp_dir ]
then
OK='y'
else
if `mkdir $temp_dir` 2> /dev/null
then
OK='y'
fi
rmdir $temp_dir
fi
fi
done
echo -n " Save source code files (*.f) [$source] : "
instr="$NULL" ; read instr
if [ -n "$instr" ]
then
if [ "$instr" = 'yes' ] || [ "$instr" = 'YES' ]
then
source='yes'
else
source='no'
fi
fi
echo -n " Save listing files [$list] : "
instr="$NULL" ; read instr
if [ -n "$instr" ]
then
if [ "$instr" = 'yes' ] || [ "$instr" = 'YES' ]
then
list='yes'
else
list='no'
fi
fi
echo ' '
echo " Modified set up :"
echo " Scratch directory : $temp_dir"
echo " Save sources : $source"
echo " Save listings : $list"
echo -n " New settings OK ? [y/n] "
read OK
done
fi
# 2.d Create new environment file
rm -f $ww3_env
echo '#' > $ww3_env
echo '# Environment variables for wavewatch III' >> $ww3_env
echo '# ---------------------------------------' >> $ww3_env
echo '#' >> $ww3_env
echo ' ' >> $ww3_env
echo "WWATCH3_DIR $path_s" >> $ww3_env
echo "WWATCH3_TMP $temp_dir" >> $ww3_env
echo "WWATCH3_SOURCE $source" >> $ww3_env
echo "WWATCH3_LIST $list" >> $ww3_env
echo ' ' >> $ww3_env
# --------------------------------------------------------------------------- #
# 3. Set up other WWATCH3 files #
# --------------------------------------------------------------------------- #
# 3.c Setup comp & link files
if [ $cmplr ]
then
echo ' '
echo ' Setup comp & link files'
if [ -f $path_b/comp.$cmplr ]
then
rm -f $path_b/comp
cp -f $path_b/comp.$cmplr $path_b/comp
echo " copy $path_b/comp.$cmplr => $path_b/comp"
elif [ "$cmplr" == "mpt" ] || [ "$cmplr" == "mpt_debug" ] || \
[ "$cmplr" == "datarmor_mpt" ] || [ "$cmplr" == "datarmor_mpt_debug" ] || \
[ "$cmplr" == "intel" ] || [ "$cmplr" == "intel_debug" ] || \
[ "$cmplr" == "so_intel" ] || [ "$cmplr" == "so_intel_debug" ] || \
[ "$cmplr" == "datarmor_intel" ] || [ "$cmplr" == "datarmor_intel_debug" ] || \
[ "$cmplr" == "gnu" ] || [ "$cmplr" == "gnu_debug" ] || \
[ "$cmplr" == "hera.intel" ] || [ "$cmplr" == "orion.intel" ] || \
[ "$cmplr" == "hera.gnu" ] || [ "$cmplr" == "jet.intel" ] || \
[ "$cmplr" == "stampede.intel" ] || [ "$cmplr" == "gaea.intel" ] || \
[ "$cmplr" == "wcoss2" ] || [ "$cmplr" == "s4.intel" ] || \
[ "$cmplr" == "expanse.intel" ] || \
[ "$cmplr" == "cheyenne.intel" ] || [ "$cmplr" == "cheyenne.gnu" ] || \
[ "$cmplr" == "wcoss_cray" ] || [ "$cmplr" == "wcoss_dell_p3" ] || \
[ "$cmplr" == "datarmor_gnu" ] || [ "$cmplr" == "datarmor_gnu_debug" ] || \
[ "$cmplr" == "pgi" ] || [ "$cmplr" == "pgi_debug" ] || \
[ "$cmplr" == "datarmor_pgi" ] || [ "$cmplr" == "datarmor_pgi_debug" ] || \
[ "$cmplr" == "ukmo_cray" ] || [ "$cmplr" == "ukmo_cray_debug" ] || \
[ "$cmplr" == "ukmo_cray_gnu" ] || [ "$cmplr" == "ukmo_cray_gnu_debug" ] || \
[ "$cmplr" == "ukmo_cray_intel" ] || [ "$cmplr" == "ukmo_cray_intel_debug" ]; then
source $path_b/cmplr.env
sed -e "s/<optc>/$optc/" -e "s/<comp_seq>/$comp_seq/" -e "s/<comp_mpi>/$comp_mpi/" -e "s/<optomp>/$optomp/" -e "s/<err_pattern>/$err_pattern/" -e "s/<warn_pattern>/$warn_pattern/" $path_b/comp.tmpl > $path_b/comp
echo " sed $path_b/comp.tmpl => $path_b/comp"
else
errmsg "$path_b/comp.$cmplr not found"
exit 1
fi
if [ -f $path_b/link.$cmplr ]
then
rm -f $path_b/link
cp -f $path_b/link.$cmplr $path_b/link
echo " copy $path_b/link.$cmplr => $path_b/link"
elif [ "$cmplr" == "mpt" ] || [ "$cmplr" == "mpt_debug" ] || \
[ "$cmplr" == "datarmor_mpt" ] || [ "$cmplr" == "datarmor_mpt_debug" ] || \
[ "$cmplr" == "intel" ] || [ "$cmplr" == "intel_debug" ] || \
[ "$cmplr" == "so_intel" ] || [ "$cmplr" == "so_intel_debug" ] || \
[ "$cmplr" == "datarmor_intel" ] || [ "$cmplr" == "datarmor_intel_debug" ] || \
[ "$cmplr" == "gnu" ] || [ "$cmplr" == "gnu_debug" ] || \
[ "$cmplr" == "hera.intel" ] || [ "$cmplr" == "orion.intel" ] || \
[ "$cmplr" == "hera.gnu" ] || [ "$cmplr" == "jet.intel" ] || \
[ "$cmplr" == "stampede.intel" ] || [ "$cmplr" == "gaea.intel" ] || \
[ "$cmplr" == "wcoss2" ] || [ "$cmplr" == "s4.intel" ] || \
[ "$cmplr" == "expanse.intel" ] || \
[ "$cmplr" == "cheyenne.intel" ] || [ "$cmplr" == "cheyenne.gnu" ] || \
[ "$cmplr" == "wcoss_cray" ] || [ "$cmplr" == "wcoss_dell_p3" ] || \
[ "$cmplr" == "datarmor_gnu" ] || [ "$cmplr" == "datarmor_gnu_debug" ] || \
[ "$cmplr" == "pgi" ] || [ "$cmplr" == "pgi_debug" ] || \
[ "$cmplr" == "datarmor_pgi" ] || [ "$cmplr" == "datarmor_pgi_debug" ] || \
[ "$cmplr" == "ukmo_cray" ] || [ "$cmplr" == "ukmo_cray_debug" ] || \
[ "$cmplr" == "ukmo_cray_gnu" ] || [ "$cmplr" == "ukmo_cray_gnu_debug" ] || \
[ "$cmplr" == "ukmo_cray_intel" ] || [ "$cmplr" == "ukmo_cray_intel_debug" ]; then
source $path_b/cmplr.env
sed -e "s/<optl>/$optl/" -e "s/<comp_seq>/$comp_seq/" -e "s/<comp_mpi>/$comp_mpi/" -e "s/<optomp>/$optomp/" $path_b/link.tmpl > $path_b/link
echo " sed $path_b/link.tmpl => $path_b/link"
else
errmsg "$path_b/link.$cmplr not found"
exit 1
fi
if [ -f $path_b/ad3.$cmplr ]
then
rm -f $path_b/ad3
cp -f $path_b/ad3.$cmplr $path_b/ad3
echo " copy $path_b/ad3.$cmplr => $path_b/ad3"
elif [ "$cmplr" == "mpt" ] || [ "$cmplr" == "mpt_debug" ] || \
[ "$cmplr" == "datarmor_mpt" ] || [ "$cmplr" == "datarmor_mpt_debug" ] || \
[ "$cmplr" == "intel" ] || [ "$cmplr" == "intel_debug" ] || \
[ "$cmplr" == "so_intel" ] || [ "$cmplr" == "so_intel_debug" ] || \
[ "$cmplr" == "datarmor_intel" ] || [ "$cmplr" == "datarmor_intel_debug" ] || \
[ "$cmplr" == "gnu" ] || [ "$cmplr" == "gnu_debug" ] || \
[ "$cmplr" == "hera.intel" ] || [ "$cmplr" == "orion.intel" ] || \
[ "$cmplr" == "hera.gnu" ] || [ "$cmplr" == "jet.intel" ] || \
[ "$cmplr" == "stampede.intel" ] || [ "$cmplr" == "gaea.intel" ] || \
[ "$cmplr" == "wcoss2" ] || [ "$cmplr" == "s4.intel" ] || \
[ "$cmplr" == "cheyenne.intel" ] || [ "$cmplr" == "cheyenne.gnu" ] || \
[ "$cmplr" == "wcoss_cray" ] || [ "$cmplr" == "wcoss_dell_p3" ] || \
[ "$cmplr" == "datarmor_gnu" ] || [ "$cmplr" == "datarmor_gnu_debug" ] || \
[ "$cmplr" == "pgi" ] || [ "$cmplr" == "pgi_debug" ] || \
[ "$cmplr" == "datarmor_pgi" ] || [ "$cmplr" == "datarmor_pgi_debug" ] || \
[ "$cmplr" == "ukmo_cray" ] || [ "$cmplr" == "ukmo_cray_debug" ] || \
[ "$cmplr" == "ukmo_cray_gnu" ] || [ "$cmplr" == "ukmo_cray_gnu_debug" ] || \
[ "$cmplr" == "ukmo_cray_intel" ] || [ "$cmplr" == "ukmo_cray_intel_debug" ]; then
source $path_b/cmplr.env
sed -e "s/<comp_seq>/$comp_seq/" -e "s/<cppad3procflag>/$cppad3procflag/" -e "s/<cppad3flag2>/$cppad3flag2/" -e "s/<cppad3flag3>/$cppad3flag3/" -e "s/<cppad3flag4>/$cppad3flag4/" -e "s/<endian>/${endian}/" $path_b/ad3.tmpl > $path_b/ad3
echo " sed $path_b/ad3.tmpl => $path_b/ad3"
else
errmsg "$path_b/ad3.$cmplr not found"
exit 1
fi
chmod 775 $path_b/comp $path_b/link $path_b/ad3
fi
# 3.d Setup switch file
if [ $swtch ]
then
echo ' '
echo ' Setup switch file'
if [ -f $path_b/switch_$swtch ]
then
rm -f $path_b/switch
cp -f $path_b/switch_$swtch $path_b/switch
echo " $path_b/switch_$swtch => $path_b/switch"
else
errmsg "$path_b/switch_$swtch not found"
exit 1
fi
fi
# 3.e Edit switch file
if [ $edit ]
then
echo " Edit $path_b/switch"
if [ ! -f $path_b/switch ]
then
errmsg "$path_b/switch not found"
exit 1
fi
if [ $EDITOR ]
then
if $EDITOR $path_b/switch
then :
else
errmsg "Error occured during edit of $path_b/switch"
exit 1
fi
else
errmsg "the EDITOR environment variable must be set"
exit 1
fi
fi
# --------------------------------------------------------------------------- #
# 4. Create WWATCH3 required model subdirectories #
# --------------------------------------------------------------------------- #
echo ' '
echo ' Create required model subdirectories'
if [ ! -d $path_s/exe ]
then
mkdir $path_s/exe
fi
if [ ! -d $path_s/obj ]
then
mkdir $path_s/obj
fi
if [ ! -d $path_s/mod ]
then
mkdir $path_s/mod
fi
# --------------------------------------------------------------------------- #
echo ' '
echo 'Finished setting up WAVEWATCH III'
echo ' '
# --------------------------------------------------------------------------- #
# End of script #
# --------------------------------------------------------------------------- #