forked from CICE-Consortium/CICE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
create.case
executable file
·560 lines (483 loc) · 15.1 KB
/
create.case
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
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
#!/bin/csh -f
echo " "
echo "${0}:"
set ICE_SANDBOX = `pwd`
set ICE_SCRIPTS = ${ICE_SANDBOX}/configuration/scripts
set initargv = ( $argv[*] )
set helpheader = 0
set dash = "-"
set spval = "UnDeFiNeD"
set mach = $spval
set case = $spval
set test = $spval
set grid = gx3
set pesx = 4x1
set sets = ""
set bdir = $spval
set testid = $spval
set testsuite = $spval
set baseCom = $spval # Baseline compare
set baseGen = $spval # Baseline generate
set bfbcomp = $spval # BFB compare
if ($#argv < 1) then
set helpheader = 1
endif
# check for -h
while (1)
if ($#argv < 1) break;
if ("$argv[1]" =~ ${dash}h* ) then
set helpheader = 1
endif
shift argv
end
#------------------------------------------------------------
# Help output
if ( $helpheader ) then
cat << EOF1
NAME
create.case - creates a CICE case directory
-h help
-c case, case directory/name
-m machine, machine name (required)
Available -m options are in configuration/scripts/machines and include:
EOF1
set soptions1 = `ls -1 configuration/scripts/machines | grep Macros | sed 's/Macros.//g' `
set soptions = `echo $soptions1 | fmt -1 | sort `
foreach sopt ($soptions)
echo " $sopt"
end
cat << EOF1
-p tasks x threads, mxn (default is 4x1)
-g grid, grid (default = gx3)
-s build and namelist mod files, comma separated with no spaces (default = " ")
Available -s options are in configuration/scripts/options and include:
EOF1
set soptions1 = `ls -1 configuration/scripts/options | grep set_ | sed 's/set_nml.//g' | sed 's/set_env.//g' `
set soptions = `echo $soptions1 | fmt -1 | sort `
foreach sopt ($soptions)
echo " $sopt"
end
cat << EOF1
-- For testing purposes --
-t test, test name (cannot be selected if -c is selected)
Available tests are in configuration/scripts/tests and include:
EOF1
set soptions1 = `ls -1 configuration/scripts/tests | grep test_ | sed 's/test_//g' | sed 's/.script//g' `
set soptions = `echo $soptions1 | fmt -1 | sort `
foreach sopt ($soptions)
echo " $sopt"
end
cat << EOF1
-bd baseline directory, high level directory where baselines are stored
-bg cice version name for generate, directory under the baseline directory where baselines are stored
-bc cice version name for compare, directory under the baseline directory where baselines are stored
-testid test ID, user-defined indentifier for test (REQUIRED if using -t or -ts)
-ts test suite, pre-defined set of tests to run in column text format. Current set of predefined tests:
- "base_suite": runs general set of tests including smoke with debug, restart, etc.
-td difference output against another case
EXAMPLES:
create.case -h
create.case -c ~/caseA -m yellowstone
create.case -p 32x4 -g gx1 -m gordon -c caseB
create.case -c ~/caseC -m spirit -s diag1,writeicf
create.case -t restart -p 8x1 -g gx1 -m cheyenne -s diag1,debug -testid myid
For more testing examples, please view README.test
EOF1
exit -1
endif
#------------------------------------------------------------
# Read in command line arguments
set argv = ( $initargv[*] )
while (1)
if ( $#argv < 1 ) break;
set option = $argv[1];
shift argv
if ( $#argv < 1 ) then
echo "${0}: ERROR1 in $option"
exit -1
endif
if ($argv[1] =~ $dash* ) then
echo "${0}: ERROR2 in $option"
exit -1
endif
switch ( $option )
case "-m":
set mach = $argv[1]
breaksw
case "-c":
set case = $argv[1]
breaksw
case "-t":
set test = $argv[1]
breaksw
case "-g":
set grid = $argv[1]
breaksw
case "-p":
set pesx = $argv[1]
breaksw
case "-s":
set sets = $argv[1]
breaksw
case "-bd":
set bdir = $argv[1]
breaksw
case "-bc":
set baseCom = $argv[1]
breaksw
case "-bg":
set baseGen = $argv[1]
breaksw
case "-td":
set bfbcomp = $argv[1]
breaksw
case "-ts":
set testsuite = $argv[1]
breaksw
case "-testid":
set testid = $argv[1]
breaksw
default:
echo "${0}: ERROR unknown option $option, use -h for help"
exit -1
breaksw
endsw
shift argv
end
if ($mach == $spval) then
echo "${0}: ERROR in arguments, -m required"
exit -1
endif
if ($case == $spval && $test == $spval && $testsuite == $spval) then
echo "${0}: ERROR in arguments, -c, -t, or -ts required"
exit -1
endif
if ($case != $spval && $test != $spval) then
echo "${0}: ERROR in arguments, cannot use both -c and -t"
exit -1
endif
if ($case != $spval && $testsuite != $spval) then
echo "${0}: ERROR in arguments, cannot use both -c and -ts"
exit -1
endif
if ($testsuite != $spval && $test != $spval) then
echo "${0}: ERROR in arguments, cannot use both -ts and -t"
exit -1
endif
# tcraig, lets find another way to validate argument
#if ($test != $spval && $test != 'smoke' && $test != '10day' && $test != 'annual' \
# && $test != 'restart') then
# echo "${0}: ERROR in arguments. $test is not a valid test"
# exit -1
#endif
if (($testsuite != $spval || $test != $spval) && $testid == $spval) then
echo "${0}: ERROR in arguments. -testid must be passed if using -ts or -t"
exit -1
endif
# Check to see if this is a test-suite run. If so, loop through the various
# tests and create a separate folder for each
if ( $testsuite != $spval ) then
set tsdir = "${testsuite}.${testid}"
if (-e ${testsuite}) then
set tsfile = "${testsuite}"
else
if (-e ${ICE_SCRIPTS}/tests/${testsuite}.ts) then
set tsfile = "${ICE_SCRIPTS}/tests/${testsuite}.ts"
else
echo "${0}: ERROR, cannot find testsuite file ${testsuite}, also checked ${ICE_SCRIPTS}/tests/${testsuite}.ts"
exit -1
endif
endif
mkdir ./${tsdir}
cp -f ${ICE_SCRIPTS}/tests/timeseries.csh ./${tsdir}
if ("$testid" =~ reg*) then
cp -f ${ICE_SCRIPTS}/tests/CTest/CTestConfig.cmake ./${tsdir}
cp -f ${ICE_SCRIPTS}/tests/CTest/CTestTestfile.cmake ./${tsdir}
cp -f ${ICE_SCRIPTS}/tests/CTest/steer.cmake ./${tsdir}
endif
cat >! ./${tsdir}/suite.run << EOF0
#!/bin/csh -f
EOF0
cat >! ./${tsdir}/results.csh << EOF0
#!/bin/csh -f
rm -f results.log
EOF0
chmod +x ./${tsdir}/suite.run
chmod +x ./${tsdir}/results.csh
foreach line ( "`cat $tsfile`" )
# Check if line is a comment line
if ( $line:q =~ '#'* || $line:q =~ '$'* || $line:q =~ '!'* ) then
echo "skipping line: $line"
continue
endif
# Obtain the test name, sets, grid, and PE information from .ts file
set test = `echo $line | cut -d' ' -f1`
set grid = `echo $line | cut -d' ' -f2`
set pesx = `echo $line | cut -d' ' -f3`
set sets_tmp = `echo $line | cut -d' ' -f4`
set bfbcomp_tmp = `echo $line | cut -d' ' -f5`
# Create a new sets_base variable to store sets passed to create.case
if (! $?sets_base ) then
set sets_base = "$sets"
endif
# Append sets from .ts file to the $sets variable
if ( $sets_tmp == "none" ) then
set sets = "$sets_base"
else
if ( $sets_base == "" ) then
set sets = "$sets_tmp"
else
set sets = "$sets_base,$sets_tmp"
# Remove duplictes in the sets variable
set sets = "`echo $sets | sed -e 's/\b\([a-z]\+\)[ ,\n]\1/\1/g'`"
endif
endif
# Create a new bfbcomp_base variable to store bfbcomp passed to create.case
if (! $?bfbcomp_base ) then
set bfbcomp_base = "$bfbcomp"
endif
# Use bfbcomp_base or bfbcomp_tmp
if ( $bfbcomp_tmp == "" ) then
set bfbcomp = "$bfbcomp_base"
else
set bfbcomp = "$bfbcomp_tmp"
endif
endif
if ($case =~ $spval) then
if ($sets != "") then
set soptions = `echo $sets | sed 's/,/_/g'`
# Only include $testid in testname if this is not a baseline-generating run
set testname_noid = "${mach}_${test}_${grid}_${pesx}_${soptions}"
set testname_base = "${mach}_${test}_${grid}_${pesx}_${soptions}.${testid}"
else
set testname_noid = "${mach}_${test}_${grid}_${pesx}"
set testname_base = "${mach}_${test}_${grid}_${pesx}.${testid}"
endif
if ($testsuite != $spval) then
set testname = "${tsdir}/$testname_base"
else
set testname = "$testname_base"
endif
set case = ${testname}
endif
if (-d $case) then
echo "${0}: ERROR, case $case already exists"
exit -1
endif
mkdir -p $case
echo "`date`${0} $initargv[*]" > $case/README.case
#------------------------------------------------------------
# Setup case directory, copy files to case directory
cd ${case}
set casedir = `pwd`
set casescr = "${casedir}/casescripts"
if !( -d ${casescr}) mkdir ${casescr}
# from basic script dir to case
foreach file (cice.build cice.settings Makefile ice_in makdep.c)
if !(-e ${ICE_SCRIPTS}/$file) then
echo "${0}: ERROR, ${ICE_SCRIPTS}/$file not found"
exit -1
endif
cp -f -p ${ICE_SCRIPTS}/$file ${casedir}
end
# from machines dir to case
foreach file (env.${mach} Macros.${mach})
if !(-e ${ICE_SCRIPTS}/machines/$file) then
echo "${0}: ERROR, ${ICE_SCRIPTS}/machines/$file not found"
exit -1
endif
cp -f -p ${ICE_SCRIPTS}/machines/$file ${casedir}
end
# from basic script dir to casescr
foreach file (parse_namelist.sh parse_settings.sh cice_decomp.csh cice.run.setup.csh cice.test.setup.csh)
if !(-e ${ICE_SCRIPTS}/$file) then
echo "${0}: ERROR, ${ICE_SCRIPTS}/$file not found"
exit -1
endif
cp -f -p ${ICE_SCRIPTS}/$file ${casescr}
end
if ($case =~ */*) then
set casename = $case:t
else
set casename = $case
endif
cd ${casedir}
source ./env.${mach} || exit 2
echo ICE_SANDBOX = ${ICE_SANDBOX}
echo ICE_CASENAME = ${casename}
echo ICE_CASEDIR = ${casedir}
echo ICE_MACHINE = ${mach}
#------------------------------------------------------------
# Compute a default blocksize
set chck = `echo ${pesx} | sed 's/^[0-9][0-9]*x[0-9][0-9]*$/OK/'`
if (${chck} == OK) then
set task = `echo ${pesx} | sed s/x.\*//`
set thrd = `echo ${pesx} | sed s/.\*x//`
else
echo "${0}: ERROR in -p argument, ${pesx}, must be mxn"
exit -1
endif
setenv ICE_DECOMP_GRID ${grid}
setenv ICE_DECOMP_NTASK ${task}
setenv ICE_DECOMP_NTHRD ${thrd}
source ${casescr}/cice_decomp.csh
if ($status != 0) then
echo "${0}: ERROR, cice_decomp.csh aborted"
exit -1
endif
#------------------------------------------------------------
# Copy in and update cice.settings and ice_in files
set fimods = ${casescr}/ice_in.mods
set fsmods = ${casescr}/cice.settings.mods
cp ice_in ${casescr}/ice_in.base
cp cice.settings ${casescr}/cice.settings.base
if (-e ${fimods}) rm ${fimods}
if (-e ${fsmods}) rm ${fsmods}
cat >! ${fimods} << EOF1
nprocs = ${task}
atm_data_dir = '${ICE_MACHINE_INPUTDATA}/'
distribution_type = '${ICE_DECOMP_DECOMP}'
processor_shape = '${ICE_DECOMP_DSHAPE}'
ice_ic = '${ICE_DECOMP_INITFILE}'
grid_file = '${ICE_DECOMP_GRIDFILE}'
kmt_file = '${ICE_DECOMP_KMTFILE}'
EOF1
# If this is a baseline-compare test, modify ICE_RUNDIR
if ($bdir != $spval) then
setenv basedir_tmp ${bdir}
else
setenv basedir_tmp ${ICE_MACHINE_BASELINE}
endif
cat >! ${fsmods} << EOF1
setenv ICE_SANDBOX ${ICE_SANDBOX}
setenv ICE_SCRIPTS ${ICE_SCRIPTS}
setenv ICE_CASENAME ${casename}
setenv ICE_CASEDIR ${casedir}
setenv ICE_MACHINE ${mach}
setenv ICE_RUNDIR ${ICE_MACHINE_WKDIR}/${casename}
setenv ICE_GRID ${grid}
setenv ICE_NXGLOB ${ICE_DECOMP_NXGLOB}
setenv ICE_NYGLOB ${ICE_DECOMP_NYGLOB}
setenv ICE_NTASKS ${task}
setenv ICE_NTHRDS ${thrd}
setenv ICE_DECOMP ${ICE_DECOMP_DECOMP}
setenv ICE_DSHAPE ${ICE_DECOMP_DSHAPE}
setenv ICE_MXBLCKS ${ICE_DECOMP_MXBLCKS}
setenv ICE_BLCKX ${ICE_DECOMP_BLCKX}
setenv ICE_BLCKY ${ICE_DECOMP_BLCKY}
setenv ICE_RSTPFILE ${ICE_DECOMP_RSTPFILE}
setenv ICE_BASELINE ${basedir_tmp}
setenv ICE_BASEGEN ${baseGen}
setenv ICE_BASECOM ${baseCom}
setenv ICE_SPVAL ${spval}
EOF1
if ($bfbcomp != $spval) then
echo "setenv ICE_BFBCOMP ${mach}_${bfbcomp}.${testid}" >> ${fsmods}
else
echo "setenv ICE_BFBCOMP ${spval}" >> ${fsmods}
endif
if ($test != $spval) then
echo "setenv ICE_TEST ${test}" >> ${fsmods}
echo "setenv ICE_TESTNAME ${testname_noid}" >> ${fsmods}
else
echo "setenv ICE_TEST ${spval}" >> ${fsmods}
echo "setenv ICE_TESTNAME ${spval}" >> ${fsmods}
endif
if ($sets != "") then
set setsx = `echo $sets | sed 's/,/ /g'`
else
set setsx = ""
endif
if ($test != $spval) then
set testx = ${test}
# from test options to casescr in case any test time changes are applied
cp -f -p ${ICE_SCRIPTS}/options/test_nml.${test}* ${casescr} >& /dev/null
else
set testx = ""
endif
foreach name ($testx $grid $setsx)
set found = 0
if (-e ${ICE_SCRIPTS}/options/set_nml.${name}) then
cat ${ICE_SCRIPTS}/options/set_nml.${name} >> ${fimods}
echo "adding namelist mods set_nml.${name}"
echo "`date`${0} adding namelist modes set_nml.${name}" > ${casedir}/README.case
set found = 1
endif
if (-e ${ICE_SCRIPTS}/options/set_env.${name}) then
cat ${ICE_SCRIPTS}/options/set_env.${name} >> ${fsmods}
echo "adding env mods set_env.${name}"
echo "`date`${0} adding namelist modes set_env.${name}" > ${casedir}/README.case
set found = 1
endif
if (${found} == 0) then
echo "${0}: ERROR, ${ICE_SCRIPTS}/options/set_[nml,env].${name} not found"
exit -1
endif
end
${casescr}/parse_settings.sh cice.settings ${fsmods}
${casescr}/parse_namelist.sh ice_in ${fimods}
#------------------------------------------------------------
# Generate run script
source ./cice.settings
source ./env.${mach} || exit 2
${casescr}/cice.run.setup.csh
if ($status != 0) then
echo "${0}: ERROR, cice.run.setup.csh aborted"
exit -1
endif
#------------------------------------------------------------
if ($test != $spval) then
# Print information to stdout
echo "Creating scripts for $test test"
# Generate test script
${casescr}/cice.test.setup.csh
if ($status != 0) then
echo "${0}: ERROR, cice.test.setup.csh aborted"
exit -1
endif
# Initial test_output file
echo "#---" >! test_output
echo "PEND ${testname_noid} " >> test_output
endif
if ( $testsuite != $spval ) then
cd ${ICE_SANDBOX}
# Write build and run commands to suite.run
cat >> ./${tsdir}/results.csh << EOF
cat $testname_base/test_output >> results.log
EOF
cat >> ./${tsdir}/suite.run << EOF
cd $testname_base
./cice.build
./cice.submit
cd ..
EOF
# Reset case for the next test in suite
set case = $spval
echo ""
echo "---"
echo ""
# This is the foreach end for the testsuite
end
# Add code to results.csh to count the number of failures
cat >> ./${tsdir}/results.csh << EOF
cat ./results.log
set pends = \`cat ./results.log | grep PEND | wc -l\`
set failures = \`cat ./results.log | grep FAIL | wc -l\`
set success = \`cat ./results.log | grep PASS | wc -l\`
set comments = \`cat ./results.log | grep "#" | wc -l\`
set alltotal = \`cat ./results.log | wc -l\`
@ total = \$alltotal - \$comments
echo ""
echo "\$success of \$total tests PASSED"
echo "\$failures of \$total tests FAILED"
echo "\$pends of \$total tests PENDING"
EOF
# build and submit tests
cd ${tsdir}
./suite.run
cd ${ICE_SANDBOX}
endif
echo " "
echo "${0} done"
echo " "
exit 0