/[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.1 - (hide annotations) (download)
Tue Dec 25 22:07:54 2007 UTC (13 years, 9 months ago) by jmc
Branch: MAIN
CVS Tags: checkpoint60, checkpoint61, checkpoint59q, checkpoint59p, checkpoint59r, checkpoint59m, checkpoint59o, checkpoint59n, checkpoint61f, checkpoint61g, checkpoint61d, checkpoint61e, checkpoint61b, checkpoint61c, checkpoint61a, checkpoint61h, checkpoint61i
moved from Contrib/jmc_script

1 jmc 1.1 #! /usr/bin/env bash
2    
3     # $Header: /u/gcmpack/MITgcm_contrib/jmc_script/tst_2+2,v 1.2 2007/11/28 22:54:46 jmc Exp $
4     # $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     echo ' rnp_loc:' $1 $2
11     # 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     mv $yy $zz
17     done
18     }
19    
20     #---------------------------
21    
22     #- default:
23     Nit=2
24     prt=1 # 1 = print some informations ; 2 = print more informations
25     action=1
26     cmd='mv -f'
27     tmpDir='temp_tst'
28    
29     #- executable:
30     mpi=0
31     if [ $mpi -ge 1 ]
32     then gcmExc=run_ifc_mpi
33     else gcmExc=mitgcmuv
34     fi
35    
36     #- exit status:
37     # 0 -> test is successful
38     # 1 -> fail in 1rst run
39     # 2 -> fail in 2nd run
40     # 3 -> fail in 3rd run
41     # 4 -> pickup*.data (written at the end of 2+2 & 4 it run) are different
42     # 5 -> pickup*.meta (written at the end of 2+2 & 4 it run) are different
43     # 6 -> missing 'data.tst' file (removed or not yet generated ?)
44     # 7 -> missing standard output from previous run
45     # 8 -> missing information (in standard output of previous run) about pickup
46     # 9 -> error in argument list
47    
48     nArg=$#
49     if [ $nArg -ge 3 ]
50     then
51     if test $2 = '-exe' ; then gcmExc=$3 ; nArg=`expr $nArg - 2` ; fi
52     if test $1 = '-exe' ; then gcmExc=$2 ; shift ; shift ; nArg=$# ; fi
53     fi
54    
55     case $nArg in
56     1) ;;
57     *) echo "Usage: `basename $0` flag [-exe EXECUTABLE]"
58     echo " Check restart: compare 1 run of 2 x $Nit it long"
59     echo " with 2 consecutive runs of $Nit it long each"
60     echo " where: flag = 0 -> prepare (from a previous run) pickup & data files"
61     echo " flag = 1 -> do the 3 runs (with EXECUTABLE, default=mitgcmuv)"
62     echo " flag = 2 -> compare std_outp"
63     echo " flag = 3 -> compare pickup files"
64     echo " flag = 4 -> clean-up output files"
65     echo " flag = All -> do 0,1,2,3,4 sequentially"
66     exit 9 ;;
67     esac
68     flag=$1
69    
70     #=========================
71    
72     if test $flag = '0' -o $flag = 'All' ; then
73     #----------------------------------------------------------------------
74     # last pickup written (from previous run):
75     if [ $mpi -ge 1 ]
76     then outpRun='STDOUT.0000'
77     else outpRun='output.txt'
78     fi
79     if test -r $outpRun
80     then
81     # grep ' %CHECKPOINT ' $outpRun | tail -1
82     lastPick=`grep ' %CHECKPOINT ' $outpRun | sed 's/^.*%CHECKPOINT //' | tail -1`
83     if test "x$lastPick" = x
84     then
85     echo "no pickup information written in '$outpRun' from previous run"
86     exit 8
87     else
88     iter=`echo $lastPick | awk '{print $1}'`
89     zz=`echo $lastPick | awk '{print $2}'`
90     echo "from previous run std.outp, lastPick='$lastPick' ; iter='$iter' ; zz='$zz'"
91     fi
92     else
93     echo "no standard output file '$outpRun' from previous run"
94     exit 7
95     fi
96    
97     #- rename pickup (if needed)
98     sufx=`printf "%10.10i\n" $iter`
99     if test $zz = $sufx
100     then
101     echo "no need to change pickup sufix"
102     else
103     # echo "rename pickup sufix: $zz -> $sufx"
104     listP=`ls pickup*.${zz}* 2> /dev/null | sed 's/\..*//g' | uniq`
105     if test "x$listP" = x
106     then echo ' rename' $zz '->' $sufx ': no file to rename'
107     else
108     if [ $prt -ge 1 ] ; then echo ' rename' $zz '->' $sufx 'for all:' $listP ; fi
109     for yy in $listP
110     do
111     listF=`ls -1 $yy.${zz}*`
112     for xx in $listF
113     do
114     new=`echo $xx | sed "s/^$yy\.$zz/$yy\.$sufx/"`
115     if [ $prt -ge 2 ] ; then echo ' '$cmd $xx $new ; fi
116     if test $action = 1 ; then $cmd $xx $new ; fi
117     done
118     done
119     fi
120     fi
121     #-------------------------
122     echo "prepare parameter file 'data.tst' :"
123     cp -p -f data data.tst
124     listOut='startTime endTime nIter0 nTimeSteps nEndIter chkPtFreq pChkPtFreq globalFiles'
125     listOut=$listOut' useSingleCpuIO pickupSuff usePickupBeforeC54 mdsioLocalDir'
126     #- comment out (in data.tst) all parameters from list: 'listOut'
127     for yy in $listOut
128     do
129     if [ $prt -ge 2 ] ; then echo -n ' commenting out:' $yy ; fi
130     nn=`grep -i -c "^ *$yy *=" data.tst`
131     if [ $nn -ge 1 ]
132     then
133     listN=`grep -i -n "^ *$yy *=" data.tst | sed 's/:.*$//'`
134     if [ $prt -ge 2 ] ; then echo " : found on line: $listN" ; fi
135     for ll in $listN
136     do
137     sed "$ll s/^./#&/" data.tst > data.tmp_$$
138     # diff data.tmp_$$ data.tst
139     mv -f data.tmp_$$ data.tst
140     done
141     else if [ $prt -ge 2 ] ; then echo ' : not found' ; fi
142     fi
143     done
144     if [ $prt -ge 2 ] ; then echo ' ' ; fi
145     # add nIter0 & nTimeSteps in namelist "PARM03":
146     Dbl=`expr $Nit \* 2`
147     sed "/^ *\&PARM03/a \ nTimeSteps=$Dbl," data.tst > data.tmp_$$
148     mv -f data.tmp_$$ data.tst
149     sed "/^ *\&PARM03/a \ nIter0=$iter," data.tst > data.tmp_$$
150     mv -f data.tmp_$$ data.tst
151     echo "prepare file 'data.tst' : done"
152     if [ $prt -ge 1 ] ; then
153     echo ' diff data.tst data' ; diff data.tst data ; echo ' ' ;
154     fi
155     #---- clean up current dir: move output to temp_tst dir:
156     if test $action = 1 ; then
157     rm -rf $tmpDir
158     mkdir $tmpDir
159     mv -f *.data $tmpDir
160     mv -f *.meta $tmpDir
161     mv -f *.txt $tmpDir
162     listS=`ls $tmpDir/pickup*.${sufx}* 2> /dev/null | head -1`
163     if test "x$listS" != x ; then mv $tmpDir/pickup*.${sufx}* . ; fi
164     #- move main parameter file "data":
165     mv -f data $tmpDir
166     #- do not deal with MNC pickup at all:
167     cp -p -f data.pkg data.tmp_$$
168     mv -f data.pkg $tmpDir
169     mv -f data.tmp_$$ data.pkg
170     yy='useMNC'
171     if [ $prt -ge 2 ] ; then echo -n " commenting out: $yy in data.pkg" ; fi
172     nn=`grep -i -c "^ *$yy *=" data.pkg`
173     if [ $nn -ge 1 ]
174     then
175     listN=`grep -i -n "^ *$yy *=" data.pkg | sed 's/:.*$//'`
176     if [ $prt -ge 2 ] ; then echo " : found on line: $listN" ; fi
177     for ll in $listN
178     do
179     sed "$ll s/^./#&/" data.pkg > data.tmp_$$
180     if [ $prt -ge 1 ] ; then echo ' changes in data.pkg'
181     diff data.tmp_$$ data.pkg ; echo ' ' ; fi
182     mv -f data.tmp_$$ data.pkg
183     done
184     else if [ $prt -ge 2 ] ; then echo ' : not found' ; echo ' ' ; fi
185     fi
186     fi
187     #----------------------------------------------------------------------
188     fi
189    
190     #=========================
191    
192     if test -r data.tst ; then
193     #- extract length of runs & starting iter number from file "data.tst"
194     num0=`sed -n 's/^ nIter0=//p' data.tst | sed 's/,//g' | sed 's/ //g'`
195     Dbl=`sed -n 's/^ nTimeSteps=//p' data.tst | sed 's/,//g'`
196     Nit=`expr $Dbl / 2`
197     # Nit = Nb of iter of 2nd & 3rd run (1rst one is 2 x Nit iter long)
198     else
199     echo '=> Need a readable "data.tst" file for the 2 x Nit iterations run'
200     exit 6
201     fi
202    
203     #- dir where to put the results :
204     dir1=res_2it
205     dir2=res_1iA
206     dir3=res_1iB
207    
208     #---------------------------
209     num1=`expr $num0 + $Nit`
210     num2=`expr $num0 + $Dbl`
211     num0c=`printf "%10.10i\n" $num0`
212     num1c=`printf "%10.10i\n" $num1`
213     num2c=`printf "%10.10i\n" $num2`
214     echo " start-end iter: $num0 , $num1 , $num2"
215     echo " sufix: '$num0c' '$num1c' '$num2c'"
216     echo ' gcmExc='$gcmExc
217     #exit
218     #---------------------------
219    
220     if test $flag = '1' -o $flag = 'All' ; then
221     #----------------------------------------------------------------------
222     #- check at the end of each run for pickup with prefix:
223     pref='pickup'
224     offLine=`grep -i -c '^ *useOffLine *= *\.TRUE\.' data.pkg`
225     if [ $offLine -ge 1 ] ; then pref='pickup_ptracers' ; fi
226     #---------------------------
227     if test -d $dir1 -o -d $dir2 -o -d $dir3
228     then echo -n 'remove dir: '
229     if test -d $dir1 ; then echo -n $dir1 ' , ' ; rm -r $dir1 ; fi
230     if test -d $dir2 ; then echo -n $dir2 ' , ' ; rm -r $dir2 ; fi
231     if test -d $dir3 ; then echo -n $dir3 ' , ' ; rm -r $dir3 ; fi
232     echo ' '
233     fi
234     mkdir $dir1 $dir2 $dir3
235     rm -f STDERR.0000
236    
237     #--- 1rst run ( 2 x Nit iter )
238     cp -p data.tst data
239     echo '==> START RUN 2 x' $Nit 'it'
240     if [ $mpi -ge 1 ]
241     then ./$gcmExc std_outp.2it > TTT.out.2it 2>&1
242     else ./$gcmExc > std_outp.2it
243     fi
244     mv STDERR.0000 std__err.2it
245     out=`egrep -c 'STOP ABNORMAL END' std_outp.2it`
246     if test $out != 0
247     then echo "==> RUN 2 x $Nit it : ABNORMAL END => exit" ; exit 1 ; fi
248     if test -f $pref.ckptA.001.001.data
249     then echo "==> END RUN 2 x $Nit it"
250     else echo "==> RUN 2 x $Nit it STOP without writing $pref => exit" ; exit 1 ; fi
251     listP=`ls pickup*.ckptA* | sed 's/\..*//g' | uniq`
252     echo ' listP=' $listP
253     for xx in $listP
254     do
255     rnp_loc $xx.ckptA $xx.$num2c
256     done
257     mv *.0??.0??.* $dir1
258     txtF=`ls -1 *.txt 2> /dev/null`
259     mv R?.data R?.meta DR?.data DR?.meta $txtF $dir1
260     listS=`ls $dir1/pickup*.${num0c}* 2> /dev/null | head -1`
261     if test "x$listS" != x ; then mv $dir1/pickup*.${num0c}* . ; fi
262     #--- 2nd run ( Nit iter , restart from same Iter = num0 as 1rst run )
263     sed "s/^ nTimeSteps=$Dbl/ nTimeSteps=$Nit/g" data.tst > data
264     echo '==> START RUN 1iA'
265     if [ $mpi -ge 1 ]
266     then ./$gcmExc std_outp.1iA > TTT.out.1iA 2>&1
267     else ./$gcmExc > std_outp.1iA
268     fi
269     mv STDERR.0000 std__err.1iA
270     out=`egrep -c 'STOP ABNORMAL END' std_outp.1iA`
271     if test $out != 0
272     then echo "==> RUN 1iA : ABNORMAL END => exit" ; exit 2 ; fi
273     if test -f $pref.ckptA.001.001.data
274     then echo "==> END RUN 1iA"
275     else echo "==> RUN 1iA STOP without writing $pref => exit" ; exit 2 ; fi
276     for xx in $listP
277     do
278     rnp_loc $xx.ckptA $xx.$num1c
279     done
280     mv *.0??.0??.* $dir2
281     txtF=`ls -1 *.txt 2> /dev/null`
282     mv R?.data R?.meta DR?.data DR?.meta $txtF $dir2
283     listS=`ls $dir2/pickup*.${num0c}* 2> /dev/null | head -1`
284     if test "x$listS" != x ; then mv $dir2/pickup*.${num0c}* . ; fi
285     #--- 3rd run ( Nit iter , restart from 2nd )
286     ln -s $dir2/pickup*.$num1c.* .
287     sed "s/^ nIter0=$num0/ nIter0=$num1/g" data > data.tmp
288     mv -f data.tmp data
289     echo '==> START RUN 1iB'
290     if [ $mpi -ge 1 ]
291     then ./$gcmExc std_outp.1iB > TTT.out.1iB 2>&1
292     else ./$gcmExc > std_outp.1iB
293     fi
294     mv STDERR.0000 std__err.1iB
295     out=`egrep -c 'STOP ABNORMAL END' std_outp.1iB`
296     if test $out != 0
297     then echo "==> RUN 1iB : ABNORMAL END => exit" ; exit 3 ; fi
298     if test -f $pref.ckptA.001.001.data
299     then echo "==> END RUN 1iB"
300     else echo "==> RUN 1iB STOP without writing $pref => exit" ; exit 3 ; fi
301     for xx in $listP
302     do
303     rnp_loc $xx.ckptA $xx.$num2c
304     done
305     mv *.0??.0??.* $dir3
306     txtF=`ls -1 *.txt 2> /dev/null`
307     mv R?.data R?.meta DR?.data DR?.meta $txtF $dir3
308     listS=`ls $dir3/pickup*.${num0c}* 2> /dev/null | head -1`
309     if test "x$listS" != x ; then mv $dir3/pickup*.${num0c}* . ; fi
310     rm $dir3/pickup*.$num1c.*
311     rm data
312     #----------------------------------------------------------------------
313     fi
314    
315     if test $flag = '2' -o $flag = 'All' ; then
316     #----------------------------------------------------------------------
317     echo ' ' ; echo '== compare cg2d_init_res :'
318     echo ' run 1iA:'
319     grep "cg2d_init_res" std_outp.1iA \
320     | sed 's/.* cg2d_init_res =//'
321     echo ' run 1iB:'
322     grep "cg2d_init_res" std_outp.1iB \
323     | sed 's/.* cg2d_init_res =//'
324     echo ' run 2it:'
325     grep "cg2d_init_res" std_outp.2it \
326     | sed 's/.* cg2d_init_res =//'
327     #----------------------------------------------------------------------
328     fi
329    
330     if test $flag = '3' -o $flag = 'All' ; then
331     #----------------------------------------------------------------------
332     echo ' '
333     echo "== diff pickup files : end of 1rst run (2x$Nit it) & end of 3rd run (2nd $Nit it)"
334     listP=`( cd $dir1 ; ls pickup*.$num2c* | sed 's/\..*//g' | uniq )`
335     chkmeta='Y'
336     for yy in $listP
337     do
338     listY=`(cd $dir1 ; ls $yy.$num2c.*.data | sed "s/$yy\.$num2c\.//" | sed "s/\.data//")`
339     zz=$yy.$num2c
340     echo '--> file='$zz', listY='$listY
341     for xx in $listY
342     do
343     echo ' diff' $dir1/$zz.$xx.data $dir3
344     diff $dir1/$zz.$xx.data $dir3
345     out=$?
346     if test $out != 0 ; then
347     echo 'Diff outp=' $out ' ==> stop'
348     exit 4
349     fi
350     if test $chkmeta = 'Y' -a -f $dir1/$zz.$xx.meta ; then
351     echo ' diff' $dir1/$zz.$xx.meta $dir3
352     diff $dir1/$zz.$xx.meta $dir3
353     out=$?
354     if test $out != 0 ; then
355     echo 'Diff outp=' $out ' ==> stop'
356     exit 5
357     fi
358     fi
359     done
360     done
361     #----------------------------------------------------------------------
362     fi
363    
364     if test $flag = '4' -o $flag = 'All' ; then
365     #-------------
366     echo ' '
367     echo "== clean-up and reset :"
368     echo '--> remove output dir and output files:'
369     echo ' rm -rf' $dir1 $dir2 $dir3
370     rm -rf $dir1 $dir2 $dir3
371     echo ' rm -f' std_????.?i?
372     rm -f std_????.?i?
373     echo ' rm -f' data.pkg data.tst
374     rm -f data.pkg data.tst
375     #- move back files from temp_tst dir:
376     if test -d $tmpDir ; then
377     echo "--> move back files from 'temp_tst' dir."
378     cd $tmpDir ; mv -f * .. ; cd ..
379     rmdir $tmpDir
380     fi
381     #-------------
382     fi
383     exit 0

  ViewVC Help
Powered by ViewVC 1.1.22