/[MITgcm]/MITgcm/tools/tst_2+2
ViewVC logotype

Annotation of /MITgcm/tools/tst_2+2

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.12 - (hide annotations) (download)
Tue May 8 15:09:26 2012 UTC (8 years, 3 months ago) by jmc
Branch: MAIN
CVS Tags: checkpoint64y, checkpoint64x, checkpoint64z, checkpoint64q, checkpoint64p, checkpoint64s, checkpoint64r, checkpoint64u, checkpoint64t, checkpoint64w, checkpoint64v, checkpoint64i, checkpoint64h, checkpoint64k, checkpoint64j, checkpoint64m, checkpoint64l, checkpoint64o, checkpoint64n, checkpoint64a, checkpoint64c, checkpoint64b, checkpoint64e, checkpoint64d, checkpoint64g, checkpoint64f, checkpoint63p, checkpoint63q, checkpoint63r, checkpoint63s, checkpoint63n, checkpoint63o, checkpoint64, checkpoint65, checkpoint65r, checkpoint65p, checkpoint65q, checkpoint65j, checkpoint65k, checkpoint65h, checkpoint65i, checkpoint65n, checkpoint65o, checkpoint65l, checkpoint65m, checkpoint65b, checkpoint65c, checkpoint65a, checkpoint65f, checkpoint65g, checkpoint65d, checkpoint65e
Changes since 1.11: +7 -1 lines
test for non empty output file

1 jmc 1.1 #! /usr/bin/env bash
2    
3 jmc 1.12 # $Header: /u/gcmpack/MITgcm/tools/tst_2+2,v 1.11 2011/11/05 13:32:53 jmc Exp $
4 jmc 1.1 # $Name: $
5    
6     rnp_loc()
7     {
8     # rnp_loc arg_1 arg_2
9     # rename files with prefix = 'arg_1' to files with prefix = 'arg_2'
10 jmc 1.8 if [ $prt -ge 1 ] ; then echo ' rnp_loc:' $1 $2 ; fi
11 jmc 1.1 # rnp -s $1 $2
12     listY=`ls -1 $1*`
13     for yy in $listY
14     do
15     zz=`echo $yy | sed "s/^$1/$2/"`
16 jmc 1.8 if [ $prt -ge 2 ] ; then echo ' '$cmdMV $yy $zz ; fi
17     if test $action = 1 ; then $cmdMV $yy $zz ; fi
18 jmc 1.1 done
19     }
20    
21 jmc 1.8 #-----------
22    
23     move_outp()
24     {
25     # move_outp arg_1
26     # move mitgcm output files to directory 'arg_1'
27     if [ $prt -ge 1 ] ; then echo ' move_outp:' $1 ; fi
28     mv *.data *.meta $1
29     listF=`ls -1 *.txt STD???.00?? 2> /dev/null`
30     if test "x$listF" != x ; then mv $listF $1 ; fi
31     #- move back sym link:
32     listL=`find $1 -type l`
33     ttd=`echo $listL | wc -w`
34     #echo "ttd=$ttd"
35     if test $ttd != 0 ; then
36     #echo "listL='$listL'"
37     if [ $prt -ge 2 ] ; then echo " mv back:" $listL | sed "s/$1\///g" ; fi
38     mv $listL .
39     fi
40     }
41    
42 jmc 1.1 #---------------------------
43    
44     #- exit status:
45     # 0 -> test is successful
46 jmc 1.2 # 1 -> fail in 1rst run
47     # 2 -> fail in 2nd run
48     # 3 -> fail in 3rd run
49 jmc 1.1 # 4 -> pickup*.data (written at the end of 2+2 & 4 it run) are different
50     # 5 -> pickup*.meta (written at the end of 2+2 & 4 it run) are different
51     # 6 -> missing 'data.tst' file (removed or not yet generated ?)
52 jmc 1.10 # 7 -> missing executable or standard output from previous run
53 jmc 1.1 # 8 -> missing information (in standard output of previous run) about pickup
54     # 9 -> error in argument list
55    
56 jmc 1.2 #- default:
57     Nit=2
58     prt=1 # 1 = print some informations ; 2 = print more informations
59     action=1
60     cmdMV='mv -f'
61     tmpDir='temp_tst'
62 jmc 1.3 wait2run=0 # if needs sometime for file system syncro on all nodes
63 jmc 1.2
64     #- default executable, command-line , using MPI:
65     gcmEXE=./mitgcmuv
66     cmdEXE=
67     mpi=0
68    
69 jmc 1.1 nArg=$#
70 jmc 1.2 prev=
71     for xx ; do
72     #echo "xx='$xx'"
73     # If the previous option needs an argument, assign it.
74     if test -n "$prev"; then
75     eval "$prev=\$xx"
76     prev=
77     nArg=`expr $nArg - 2`
78     continue
79     fi
80    
81     case $xx in
82     -mpi ) mpi=1 ; nArg=`expr $nArg - 1` ;;
83     -exe ) prev=gcmEXE ;;
84     -command ) prev=cmdEXE ;;
85     *) flag=$xx ;;
86     esac
87     done
88 jmc 1.4 #echo "cmdEXE='$cmdEXE'"
89     #echo "nArg=$nArg ; mpi=$mpi ; flag='$flag'"
90 jmc 1.1
91     case $nArg in
92     1) ;;
93 jmc 1.2 *) echo "Usage: `basename $0` flag [-mpi] [-exe EXECUTABLE] [-command COMMAND]"
94 jmc 1.1 echo " Check restart: compare 1 run of 2 x $Nit it long"
95     echo " with 2 consecutive runs of $Nit it long each"
96     echo " where: flag = 0 -> prepare (from a previous run) pickup & data files"
97 jmc 1.2 echo " flag = 1 -> do the 3 runs (using COMMAND"
98     echo " or simply using EXECUTABLE, default=$gcmEXE)"
99 jmc 1.1 echo " flag = 2 -> compare std_outp"
100     echo " flag = 3 -> compare pickup files"
101     echo " flag = 4 -> clean-up output files"
102 jmc 1.8 echo " flag = NC -> do 0,1,2,3 sequentially (no cleaning)"
103 jmc 1.1 echo " flag = All -> do 0,1,2,3,4 sequentially"
104     exit 9 ;;
105     esac
106 jmc 1.8 if test $flag = 'NC' -o $flag = 'All' ; then Multi=1 ; else Multi=0 ; fi
107 jmc 1.1
108 jmc 1.2 #-- set the run-command :
109     if test "x$cmdEXE" = x
110     then
111 jmc 1.3 if [ $mpi -ge 1 ] ; then
112     cmdEXE="mpirun -machinefile ../../mf -v -np 2 $gcmEXE"
113     else
114 jmc 1.2 cmdEXE=$gcmEXE
115 jmc 1.3 fi
116 jmc 1.2 fi
117 jmc 1.3 echo "cmdEXE='$cmdEXE'"
118 jmc 1.1 #=========================
119    
120 jmc 1.8 if test $flag = '0' -o $Multi = '1' ; then
121 jmc 1.1 #----------------------------------------------------------------------
122 jmc 1.10 # check for executable:
123 jmc 1.11 if test ! -x $gcmEXE ; then
124 jmc 1.10 echo "file '$gcmEXE' does not exist or is not executable"
125     exit 7
126     fi
127 jmc 1.1 # last pickup written (from previous run):
128 jmc 1.2 if [ $mpi -ge 1 ]
129 jmc 1.1 then outpRun='STDOUT.0000'
130     else outpRun='output.txt'
131     fi
132 jmc 1.2 if test -r $outpRun
133 jmc 1.1 then
134     # grep ' %CHECKPOINT ' $outpRun | tail -1
135     lastPick=`grep ' %CHECKPOINT ' $outpRun | sed 's/^.*%CHECKPOINT //' | tail -1`
136 jmc 1.2 if test "x$lastPick" = x
137     then
138 jmc 1.1 echo "no pickup information written in '$outpRun' from previous run"
139     exit 8
140     else
141     iter=`echo $lastPick | awk '{print $1}'`
142 jmc 1.8 sufx=`echo $lastPick | awk '{print $2}'`
143     echo "from previous run std.outp, lastPick='$lastPick' ; iter='$iter' ; sufx='$sufx'"
144 jmc 1.1 fi
145 jmc 1.2 else
146 jmc 1.1 echo "no standard output file '$outpRun' from previous run"
147     exit 7
148     fi
149    
150     #-------------------------
151     echo "prepare parameter file 'data.tst' :"
152     cp -p -f data data.tst
153 jmc 1.9 listOut='startTime endTime nIter0 nTimeSteps nEndIter chkPtFreq pChkPtFreq'
154     listOut=$listOut' pickupSuff usePickupBeforeC54 mdsioLocalDir pickupStrictlyMatch'
155 jmc 1.1 #- comment out (in data.tst) all parameters from list: 'listOut'
156     for yy in $listOut
157     do
158     if [ $prt -ge 2 ] ; then echo -n ' commenting out:' $yy ; fi
159     nn=`grep -i -c "^ *$yy *=" data.tst`
160     if [ $nn -ge 1 ]
161     then
162     listN=`grep -i -n "^ *$yy *=" data.tst | sed 's/:.*$//'`
163     if [ $prt -ge 2 ] ; then echo " : found on line: $listN" ; fi
164     for ll in $listN
165     do
166     sed "$ll s/^./#&/" data.tst > data.tmp_$$
167     # diff data.tmp_$$ data.tst
168     mv -f data.tmp_$$ data.tst
169     done
170     else if [ $prt -ge 2 ] ; then echo ' : not found' ; fi
171     fi
172     done
173     if [ $prt -ge 2 ] ; then echo ' ' ; fi
174     # add nIter0 & nTimeSteps in namelist "PARM03":
175     Dbl=`expr $Nit \* 2`
176     sed "/^ *\&PARM03/a \ nTimeSteps=$Dbl," data.tst > data.tmp_$$
177     mv -f data.tmp_$$ data.tst
178     sed "/^ *\&PARM03/a \ nIter0=$iter," data.tst > data.tmp_$$
179     mv -f data.tmp_$$ data.tst
180     echo "prepare file 'data.tst' : done"
181 jmc 1.2 if [ $prt -ge 1 ] ; then
182 jmc 1.1 echo ' diff data.tst data' ; diff data.tst data ; echo ' ' ;
183     fi
184     #---- clean up current dir: move output to temp_tst dir:
185     if test $action = 1 ; then
186     rm -rf $tmpDir
187     mkdir $tmpDir
188     mv -f *.data $tmpDir
189     mv -f *.meta $tmpDir
190 jmc 1.3 mv -f *.txt $tmpDir 2> /dev/null
191 jmc 1.2 mv -f STD???.0[0-9][0-9][0-9] $tmpDir
192 jmc 1.1 #- move main parameter file "data":
193     mv -f data $tmpDir
194     #- do not deal with MNC pickup at all:
195     cp -p -f data.pkg data.tmp_$$
196     mv -f data.pkg $tmpDir
197     mv -f data.tmp_$$ data.pkg
198     yy='useMNC'
199     if [ $prt -ge 2 ] ; then echo -n " commenting out: $yy in data.pkg" ; fi
200     nn=`grep -i -c "^ *$yy *=" data.pkg`
201     if [ $nn -ge 1 ]
202     then
203     listN=`grep -i -n "^ *$yy *=" data.pkg | sed 's/:.*$//'`
204     if [ $prt -ge 2 ] ; then echo " : found on line: $listN" ; fi
205     for ll in $listN
206     do
207     sed "$ll s/^./#&/" data.pkg > data.tmp_$$
208 jmc 1.2 if [ $prt -ge 1 ] ; then echo ' changes in data.pkg'
209 jmc 1.1 diff data.tmp_$$ data.pkg ; echo ' ' ; fi
210     mv -f data.tmp_$$ data.pkg
211     done
212     else if [ $prt -ge 2 ] ; then echo ' : not found' ; echo ' ' ; fi
213     fi
214     fi
215 jmc 1.8 #-------------------------
216     #-- link back pickup files
217     listS=`ls $tmpDir/pickup*.${sufx}* 2> /dev/null | head -1`
218 jmc 1.10 if test "x$listS" != x ; then
219 jmc 1.8 if [ $prt -ge 1 ] ; then echo ' link back:' $tmpDir'/pickup*.'${sufx}'*' ; fi
220     if test $action = 1 ; then ln -s $tmpDir/pickup*.${sufx}* . ; fi
221     fi
222     #- rename pickup (if needed)
223     nIt0c=`printf "%10.10i\n" $iter`
224     if test $sufx = $nIt0c
225     then
226     echo "no need to change pickup sufix"
227     else
228     listP=`ls pickup*.${sufx}* 2> /dev/null | sed 's/\..*//g' | uniq`
229     if test "x$listP" = x
230     then echo ' rename' $sufx '->' $nIt0c ': no file to rename'
231     else
232     if [ $prt -ge 1 ] ; then echo ' rename' $sufx '->' $nIt0c 'for all:' $listP ; fi
233     for yy in $listP
234     do
235     rnp_loc $yy.${sufx} $yy.$nIt0c
236     done
237     fi
238     fi
239 jmc 1.1 #----------------------------------------------------------------------
240     fi
241    
242     #=========================
243    
244     if test -r data.tst ; then
245     #- extract length of runs & starting iter number from file "data.tst"
246     num0=`sed -n 's/^ nIter0=//p' data.tst | sed 's/,//g' | sed 's/ //g'`
247     Dbl=`sed -n 's/^ nTimeSteps=//p' data.tst | sed 's/,//g'`
248     Nit=`expr $Dbl / 2`
249     # Nit = Nb of iter of 2nd & 3rd run (1rst one is 2 x Nit iter long)
250     else
251     echo '=> Need a readable "data.tst" file for the 2 x Nit iterations run'
252     exit 6
253     fi
254    
255     #- dir where to put the results :
256     dir1=res_2it
257     dir2=res_1iA
258     dir3=res_1iB
259    
260     #---------------------------
261     num1=`expr $num0 + $Nit`
262     num2=`expr $num0 + $Dbl`
263     num0c=`printf "%10.10i\n" $num0`
264     num1c=`printf "%10.10i\n" $num1`
265     num2c=`printf "%10.10i\n" $num2`
266     echo " start-end iter: $num0 , $num1 , $num2"
267     echo " sufix: '$num0c' '$num1c' '$num2c'"
268 jmc 1.2 echo ' cmdEXE='$cmdEXE
269 jmc 1.1 #exit
270     #---------------------------
271    
272 jmc 1.8 if test $flag = '1' -o $Multi = '1' ; then
273 jmc 1.1 #----------------------------------------------------------------------
274     #- check at the end of each run for pickup with prefix:
275     pref='pickup'
276     offLine=`grep -i -c '^ *useOffLine *= *\.TRUE\.' data.pkg`
277     if [ $offLine -ge 1 ] ; then pref='pickup_ptracers' ; fi
278     #---------------------------
279     if test -d $dir1 -o -d $dir2 -o -d $dir3
280     then echo -n 'remove dir: '
281     if test -d $dir1 ; then echo -n $dir1 ' , ' ; rm -r $dir1 ; fi
282     if test -d $dir2 ; then echo -n $dir2 ' , ' ; rm -r $dir2 ; fi
283     if test -d $dir3 ; then echo -n $dir3 ' , ' ; rm -r $dir3 ; fi
284     echo ' '
285     fi
286     mkdir $dir1 $dir2 $dir3
287     rm -f STDERR.0000
288    
289     #--- 1rst run ( 2 x Nit iter )
290     cp -p data.tst data
291     echo '==> START RUN 2 x' $Nit 'it'
292     if [ $mpi -ge 1 ]
293 jmc 1.10 then
294 jmc 1.3 sleep $wait2run
295     $cmdEXE > TTT.out.2it 2>&1
296     mv STDOUT.0000 std_outp.2it
297     cat TTT.out.2it
298 jmc 1.2 else $cmdEXE > std_outp.2it
299 jmc 1.1 fi
300 jmc 1.12 if test ! -s std_outp.2it
301     then echo "empty or no output file: 'std_outp.2it' => exit" ; exit 1 ; fi
302 jmc 1.1 mv STDERR.0000 std__err.2it
303     out=`egrep -c 'STOP ABNORMAL END' std_outp.2it`
304     if test $out != 0
305     then echo "==> RUN 2 x $Nit it : ABNORMAL END => exit" ; exit 1 ; fi
306 jmc 1.6 listF=`ls -1 $pref.ckptA*.data 2> /dev/null`
307     if test "x$listF" = x
308     then echo "==> RUN 2 x $Nit it STOP without writing $pref => exit" ; exit 1
309     else echo "==> END RUN 2 x $Nit it" ; fi
310 jmc 1.1 listP=`ls pickup*.ckptA* | sed 's/\..*//g' | uniq`
311     echo ' listP=' $listP
312     for xx in $listP
313     do
314     rnp_loc $xx.ckptA $xx.$num2c
315     done
316 jmc 1.8 move_outp $dir1
317 jmc 1.1 #--- 2nd run ( Nit iter , restart from same Iter = num0 as 1rst run )
318 jmc 1.3 sed "s/^ nTimeSteps=$Dbl/ nTimeSteps=$Nit/g" data.tst > data.tmp
319     mv -f data.tmp data
320 jmc 1.1 echo '==> START RUN 1iA'
321     if [ $mpi -ge 1 ]
322 jmc 1.10 then
323 jmc 1.3 sleep $wait2run
324     $cmdEXE > TTT.out.1iA 2>&1
325     mv STDOUT.0000 std_outp.1iA
326     cat TTT.out.1iA
327 jmc 1.2 else $cmdEXE > std_outp.1iA
328 jmc 1.1 fi
329 jmc 1.12 if test ! -s std_outp.1iA
330     then echo "empty or no output file: 'std_outp.1iA' => exit" ; exit 2 ; fi
331 jmc 1.1 mv STDERR.0000 std__err.1iA
332     out=`egrep -c 'STOP ABNORMAL END' std_outp.1iA`
333     if test $out != 0
334     then echo "==> RUN 1iA : ABNORMAL END => exit" ; exit 2 ; fi
335 jmc 1.6 listF=`ls -1 $pref.ckptA*.data 2> /dev/null`
336     if test "x$listF" = x
337     then echo "==> RUN 1iA STOP without writing $pref => exit" ; exit 2
338     else echo "==> END RUN 1iA" ; fi
339 jmc 1.1 for xx in $listP
340     do
341     rnp_loc $xx.ckptA $xx.$num1c
342     done
343 jmc 1.8 move_outp $dir2
344 jmc 1.1 #--- 3rd run ( Nit iter , restart from 2nd )
345     ln -s $dir2/pickup*.$num1c.* .
346     sed "s/^ nIter0=$num0/ nIter0=$num1/g" data > data.tmp
347     mv -f data.tmp data
348     echo '==> START RUN 1iB'
349     if [ $mpi -ge 1 ]
350 jmc 1.10 then
351 jmc 1.3 sleep $wait2run
352     $cmdEXE > TTT.out.1iB 2>&1
353     mv STDOUT.0000 std_outp.1iB
354     cat TTT.out.1iB
355 jmc 1.2 else $cmdEXE > std_outp.1iB
356 jmc 1.1 fi
357 jmc 1.12 if test ! -s std_outp.1iB
358     then echo "empty or no output file: 'std_outp.1iB' => exit" ; exit 3 ; fi
359 jmc 1.1 mv STDERR.0000 std__err.1iB
360     out=`egrep -c 'STOP ABNORMAL END' std_outp.1iB`
361     if test $out != 0
362     then echo "==> RUN 1iB : ABNORMAL END => exit" ; exit 3 ; fi
363 jmc 1.6 listF=`ls -1 $pref.ckptA*.data 2> /dev/null`
364     if test "x$listF" = x
365     then echo "==> RUN 1iB STOP without writing $pref => exit" ; exit 3
366     else echo "==> END RUN 1iB" ; fi
367 jmc 1.1 for xx in $listP
368     do
369     rnp_loc $xx.ckptA $xx.$num2c
370     done
371 jmc 1.8 # remove pickup*.$mun1c* sym-link:
372     find . ! -name . -prune -type l -name 'pickup*.'${num1c}'*' -exec rm {} \;
373     move_outp $dir3
374 jmc 1.1 rm data
375     #----------------------------------------------------------------------
376     fi
377    
378 jmc 1.8 if test $flag = '2' -o $Multi = '1' ; then
379 jmc 1.1 #----------------------------------------------------------------------
380 jmc 1.7 listCGini="2"
381     #-- check if using 3-D solver
382     nn=`grep -i -c "^ *nonHydrostatic *= *\.TRUE\." data.tst`
383 jmc 1.10 if [ $nn -eq 0 ] ; then
384 jmc 1.7 nn=`grep -i -c "^ *implicitIntGravWave *= *\.TRUE\." data.tst`
385     fi
386     if [ $nn -ge 1 ] ; then listCGini="$listCGini 3"; fi
387     for nn in $listCGini
388     do
389     echo ' ' ; echo "== compare cg${nn}d_init_res :"
390     echo ' run 1iA:'
391     grep "cg${nn}d_init_res" std_outp.1iA \
392     | sed "s/.* cg${nn}d_init_res =//"
393     echo ' run 1iB:'
394     grep "cg${nn}d_init_res" std_outp.1iB \
395     | sed "s/.* cg${nn}d_init_res =//"
396     echo ' run 2it:'
397     grep "cg${nn}d_init_res" std_outp.2it \
398     | sed "s/.* cg${nn}d_init_res =//"
399     done
400 jmc 1.1 #----------------------------------------------------------------------
401     fi
402    
403 jmc 1.8 if test $flag = '3' -o $Multi = '1' ; then
404 jmc 1.1 #----------------------------------------------------------------------
405 jmc 1.2 echo ' '
406 jmc 1.1 echo "== diff pickup files : end of 1rst run (2x$Nit it) & end of 3rd run (2nd $Nit it)"
407     listP=`( cd $dir1 ; ls pickup*.$num2c* | sed 's/\..*//g' | uniq )`
408     chkmeta='Y'
409     for yy in $listP
410     do
411 jmc 1.6 listY=`(cd $dir1 ; ls $yy.$num2c*.data | sed "s/$yy\.$num2c//" | sed "s/data$//")`
412 jmc 1.1 zz=$yy.$num2c
413     echo '--> file='$zz', listY='$listY
414     for xx in $listY
415     do
416 jmc 1.6 echo ' diff' $dir1/$zz${xx}data $dir3
417     diff $dir1/$zz${xx}data $dir3
418 jmc 1.1 out=$?
419     if test $out != 0 ; then
420     echo 'Diff outp=' $out ' ==> stop'
421     exit 4
422     fi
423 jmc 1.6 if test $chkmeta = 'Y' -a -f $dir1/$zz${xx}meta ; then
424     echo ' diff' $dir1/$zz${xx}meta $dir3
425     diff $dir1/$zz${xx}meta $dir3
426 jmc 1.1 out=$?
427 jmc 1.2 if test $out != 0 ; then
428 jmc 1.1 echo 'Diff outp=' $out ' ==> stop'
429     exit 5
430     fi
431     fi
432     done
433     done
434     #----------------------------------------------------------------------
435     fi
436    
437     if test $flag = '4' -o $flag = 'All' ; then
438     #-------------
439 jmc 1.2 echo ' '
440 jmc 1.1 echo "== clean-up and reset :"
441 jmc 1.8 echo '--> remove pickup*.'$num0c'* sym-links:'
442     #find . ! -name . -prune -type l -name 'pickup*.'${num0c}'*' -exec rm {} \;
443     listS=`find . ! -name . -prune -type l -name 'pickup*.'${num0c}'*'`
444     if [ $prt -ge 2 ] ; then echo ' rm' $listS ; fi
445     rm -f $listS
446 jmc 1.1 echo '--> remove output dir and output files:'
447     echo ' rm -rf' $dir1 $dir2 $dir3
448     rm -rf $dir1 $dir2 $dir3
449     echo ' rm -f' std_????.?i?
450     rm -f std_????.?i?
451 jmc 1.3 rm -f TTT.out.?i? 2> /dev/null
452 jmc 1.1 echo ' rm -f' data.pkg data.tst
453     rm -f data.pkg data.tst
454     #- move back files from temp_tst dir:
455     if test -d $tmpDir ; then
456     echo "--> move back files from 'temp_tst' dir."
457     cd $tmpDir ; mv -f * .. ; cd ..
458     rmdir $tmpDir
459     fi
460     #-------------
461     fi
462     exit 0

  ViewVC Help
Powered by ViewVC 1.1.22