/[MITgcm]/MITgcm_contrib/jmc_script/tst_2+2_cpl
ViewVC logotype

Contents of /MITgcm_contrib/jmc_script/tst_2+2_cpl

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


Revision 1.8 - (show annotations) (download)
Fri Oct 22 03:10:56 2010 UTC (13 years, 6 months ago) by jmc
Branch: MAIN
Changes since 1.7: +31 -2 lines
add option for a clean-up

1 #! /usr/bin/env bash
2
3 # $Header: /u/gcmpack/MITgcm_contrib/jmc_script/tst_2+2_cpl,v 1.7 2009/12/26 23:43:22 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 dif_tiles()
21 {
22 # dif_data_loc dd1 dd2 file
23 # for all tiles ==> do diff dd1/file dd2/file'
24 dd1=$1 ; dd2=$2 ; zz=$3
25 chkmeta='Y'
26 listY=`(cd $dd1 ; ls $zz.*.data | sed "s/$zz\.//" | sed "s/\.data//")`
27 echo '--> file='$zz', listY='$listY
28 for yy in $listY
29 do
30 echo diff $dd1/$zz.$yy.data $dd2
31 diff $dd1/$zz.$yy.data $dd2
32 out=$?
33 if test $out != 0
34 then echo 'Diff outp=' $out ' ==> stop'
35 exit ; fi
36 if test $chkmeta = 'Y'
37 then
38 echo diff $dd1/$zz.$yy.meta $dd2
39 diff $dd1/$zz.$yy.meta $dd2
40 out=$?
41 if test $out != 0
42 then echo 'Diff outp=' $out ' ==> stop'
43 exit ; fi
44 fi
45 done
46 }
47
48 if test -f input_ocn/data.tst
49 then
50 noc0=`sed -n 's/nIter0=//p' input_ocn/data.tst | sed 's/,//g' | sed 's/ //g'`
51 Dbl=`sed -n 's/nTimeSteps=//p' input_ocn/data.tst | sed 's/,//g'`
52 NiOc=`expr $Dbl / 2`
53 Nit=$NiOc
54 else
55 echo " file: 'input_ocn/data.tst' not found"
56 NiOc=0 ; Nit=2
57 fi
58 if test -f input_atm/data.tst
59 then
60 nat0=`sed -n 's/nIter0=//p' input_atm/data.tst | sed 's/,//g' | sed 's/ //g'`
61 Dbl=`sed -n 's/nTimeSteps=//p' input_atm/data.tst | sed 's/,//g'`
62 NiAt=`expr $Dbl / 2`
63 else
64 echo " file: 'input_atm/data.tst' not found"
65 NiAt=0
66 fi
67
68 #- parse options:
69 CMD='run_cpl_test'
70 MTH=
71 argList=$*
72 for xx in $argList
73 do
74 if test $xx = '-mth' ; then MTH=$xx ; shift ; continue ; fi
75 if test -x ${CMD}_$xx ; then CMD="${CMD}_$xx" ; shift ; continue ; fi
76 done
77
78 if [ $# -ne 1 ]
79 then
80 echo "Usage: `basename $0` [opt] flag"
81 echo " Check restart of coupled set-up: compare 1 run of 2 x $Nit it long"
82 echo " with 2 consecutive runs of $Nit it long each"
83 echo "opt = -mth : run script '$CMD' with option '-mth'"
84 echo "opt = sufx : run script 'run_cpl_test_{sufx}'"
85 echo " where: flag = 0 -> prepare for 1rst run"
86 echo " flag = r1 -> do 1rst run and step 1"
87 echo " flag = 1 -> move res. after 1rst run & prepare for 2nd"
88 echo " flag = r2 -> do 2nd run and step 2"
89 echo " flag = 2 -> move res. after 2nd run & prepare for 3rd"
90 echo " flag = r3 -> do 3rd run and step 3"
91 echo " flag = 3 -> move res. after 3rd run"
92 echo " flag=(r)N+ , N=1,2,3 => do steps (+run) from: (r)N to 3"
93 echo " flag = 4 -> compare Ocean results"
94 echo " flag = 5 -> compare Atmos results"
95 echo " flag = 6 -> diff pickup files"
96 echo " flag = 7 -> clean-up output files"
97 exit
98 fi
99 if test $NiAt = 0 -o $NiOc = 0
100 then
101 echo " needs 2 data files: 'input_ocn/data.tst' & 'input_atm/data.tst'"
102 echo " (corresponding to 1rst run) to continue"
103 exit
104 fi
105 arg1=$1
106 xx=`echo $arg1 | sed 's/\+$//'`
107 if test $xx != $arg1
108 then kUp=`echo $xx | sed 's/^r//'` ; arg1=$xx
109 else kUp=9 ; fi
110 xx=`echo $arg1 | sed 's/^r//'`
111 if test $xx != $arg1 ; then doRun=1 ; arg1=$xx ; else doRun=0 ; fi
112 ksel=$arg1
113
114 CMD="./${CMD} $MTH 3"
115 echo " doRun='$doRun' ; ksel='$ksel' ; kUp='$kUp' ; command='$CMD'"
116
117 #make sure that local dir & ~jmc/bin is in the path:
118 #export PATH=${PATH}:.
119
120 Nit=$NiOc
121 Dbl=`expr $Nit + $Nit`
122 noc1=`expr $noc0 + $Nit`
123 noc2=`expr $noc0 + $Dbl`
124 noc0c=`printf "%10.10i\n" $noc0`
125 noc1c=`printf "%10.10i\n" $noc1`
126 noc2c=`printf "%10.10i\n" $noc2`
127 echo ' Oce (rank_1):' $noc0 $noc1 $noc2
128 echo ' ' $noc0c $noc1c $noc2c
129
130 Nit=$NiAt
131 Dbl=`expr $Nit + $Nit`
132 nat1=`expr $nat0 + $Nit`
133 nat2=`expr $nat0 + $Dbl`
134 nat0c=`printf "%10.10i\n" $nat0`
135 nat1c=`printf "%10.10i\n" $nat1`
136 nat2c=`printf "%10.10i\n" $nat2`
137 echo ' Atm (rank_2):' $nat0 $nat1 $nat2
138 echo ' ' $nat0c $nat1c $nat2c
139
140 listOc="pickup"
141 listAt="pickup pickup_cpl pickup_ic pickup_land"
142
143 #- dir where to put the results :
144 dir1=res_2it
145 dir2=res_1iA
146 dir3=res_1iB
147
148 #-- after a run, rename pickup file to restart
149 if test $ksel = 0
150 then
151 echo ' '
152 cd rank_1
153 for xx in $listOc
154 do rnp_loc $xx.ckptA $xx.$noc0c
155 done
156 cd ../rank_2
157 for xx in $listAt
158 do rnp_loc $xx.ckptA $xx.$nat0c
159 done
160 cd ..
161 #-- prepare for running Dbl
162 echo '=> prepare for running Dbl:'
163 Dbl=`expr $NiOc + $NiOc`
164 sed "1 s/[0-9]*/$Dbl/" input_cpl/data > rank_0/data
165 cp -p input_ocn/data.tst rank_1/data
166 cp -p input_atm/data.tst rank_2/data
167 echo 'rank_0/data:' `head -1 rank_0/data`
168 egrep 'nIter0|nTimeSteps' rank_?/data
169 fi
170
171 #-- run & post-process Dbl:
172 if [ $ksel -eq 1 -o $kUp -le 1 ]
173 then
174 echo ' '
175 #-- run coupled test (Dbl):
176 if [ $doRun -eq 1 -o $kUp -lt 1 ]
177 then
178 echo "=> run (Dbl): $CMD"
179 $CMD
180 fi
181 #-- after running Dbl:
182 rm -rf $dir1
183 mkdir $dir1
184 echo '=> move STDOUT to' $dir1
185 mv rank_1/STDOUT* $dir1/ocnSTDOUT.2it
186 mv rank_2/STDOUT* $dir1/atmSTDOUT.2it
187
188 mkdir $dir1/ocn
189 cd rank_1
190 for xx in $listOc
191 do
192 rnp_loc $xx.ckptA $xx.$noc2c
193 done
194 echo 'move pickups to' $dir1/ocn
195 mv pickup*.$noc2c.* ../$dir1/ocn
196 cd ..
197
198 mkdir $dir1/atm
199 cd rank_2
200 for xx in $listAt
201 do
202 rnp_loc $xx.ckptA $xx.$nat2c
203 done
204 echo 'move pickups to' $dir1/atm
205 mv pickup*.$nat2c.* ../$dir1/atm
206 cd ..
207
208 #-- prepare for running 1iA
209 echo '=> prepare for running 1iA:'
210 Nit=$NiOc
211 Dbl=`expr $Nit + $Nit`
212 sed "1 s/[0-9]*/$Nit/" input_cpl/data > rank_0/data
213 sed "s/^ nTimeSteps=$Dbl/ nTimeSteps=$Nit/g" input_ocn/data.tst > rank_1/data
214 Nit=$NiAt
215 Dbl=`expr $Nit + $Nit`
216 sed "s/^ nTimeSteps=$Dbl/ nTimeSteps=$Nit/g" input_atm/data.tst > rank_2/data
217 echo 'rank_0/data:' `head -1 rank_0/data`
218 egrep 'nIter0|nTimeSteps' rank_?/data
219 fi
220
221 #-- run & post-process 1iA:
222 if [ $ksel -eq 2 -o $kUp -le 2 ]
223 then
224 echo ' '
225 #-- run coupled test (1iA):
226 if [ $doRun -eq 1 -o $kUp -lt 2 ]
227 then
228 echo "=> run (1iA): $CMD"
229 $CMD
230 fi
231 #-- after running 1iA
232 rm -rf $dir2
233 mkdir $dir2
234 echo '=> move STDOUT to' $dir2
235 mv rank_1/STDOUT* $dir2/ocnSTDOUT.1iA
236 mv rank_2/STDOUT* $dir2/atmSTDOUT.1iA
237
238 mkdir $dir2/ocn
239 cd rank_1
240 for xx in $listOc
241 do
242 rnp_loc $xx.ckptA $xx.$noc1c
243 done
244 echo 'move pickups to' $dir2/ocn
245 mv pickup*.$noc1c.* ../$dir2/ocn
246 cd ..
247
248 mkdir $dir2/atm
249 cd rank_2
250 for xx in $listAt
251 do
252 rnp_loc $xx.ckptA $xx.$nat1c
253 done
254 echo 'move pickups to' $dir2/atm
255 mv pickup*.$nat1c.* ../$dir2/atm
256 cd ..
257
258 #-- prepare for running 1iB
259 echo '=> prepare for running 1iB:'
260 cd rank_1
261 sed "s/^ nIter0=$noc0/ nIter0=$noc1/g" data > data.tmp
262 mv -f data.tmp data
263 ln -s ../$dir2/ocn/* .
264 cd ../rank_2
265 sed "s/^ nIter0=$nat0/ nIter0=$nat1/g" data > data.tmp
266 mv -f data.tmp data
267 ln -s ../$dir2/atm/* .
268 cd ..
269 echo 'rank_0/data:' `head -1 rank_0/data`
270 egrep 'nIter0|nTimeSteps' rank_?/data
271 fi
272
273 #-- run & post-process 1iB:
274 if [ $ksel -eq 3 -o $kUp -le 3 ]
275 then
276 echo ' '
277 #-- run coupled test (1iB):
278 if [ $doRun -eq 1 -o $kUp -lt 3 ]
279 then
280 echo "=> run (1iB): $CMD"
281 $CMD
282 fi
283 #-- after running 1iB
284 rm -rf $dir3
285 mkdir $dir3
286 echo '=> move STDOUT to' $dir3
287 mv rank_1/STDOUT* $dir3/ocnSTDOUT.1iB
288 mv rank_2/STDOUT* $dir3/atmSTDOUT.1iB
289
290 mkdir $dir3/ocn
291 cd rank_1
292 for xx in $listOc
293 do rnp_loc $xx.ckptA $xx.$noc2c
294 done
295 echo 'move pickups to' $dir3/ocn
296 mv pickup*.$noc2c.* ../$dir3/ocn
297 rm -f pickup*.$noc1c.*
298 cd ..
299
300 mkdir $dir3/atm
301 cd rank_2
302 for xx in $listAt
303 do rnp_loc $xx.ckptA $xx.$nat2c
304 done
305 echo 'move pickups to' $dir3/atm
306 mv pickup*.$nat2c.* ../$dir3/atm
307 rm -f pickup*.$nat1c.*
308 cd ..
309 echo '=> restore std data files'
310 cp -p input_cpl/data rank_0
311 cp -p input_ocn/data rank_1
312 cp -p input_atm/data rank_2
313 fi
314
315 #-- compare output:
316 if test $ksel = 4
317 then
318 rm -f ocn.txt
319 echo ' run 2it: ---------- ' > tmp1.txt
320 grep "cg2d_init_res" $dir1/ocnSTDOUT.2it \
321 | sed 's/.* cg2d_init_res =//' >> tmp1.txt
322 Nit=`expr $NiOc + 2`
323 sed "$Nit i \ ... 2it continue ..." tmp1.txt > tmp2.txt
324 rm -f tmp1.txt
325 echo ' run 1iA: ---------- ' > tmp1.txt
326 grep "cg2d_init_res" $dir2/ocnSTDOUT.1iA \
327 | sed 's/.* cg2d_init_res =//' >> tmp1.txt
328 echo ' run 1iB: ---------- ' >> tmp1.txt
329 grep "cg2d_init_res" $dir3/ocnSTDOUT.1iB \
330 | sed 's/.* cg2d_init_res =//' >> tmp1.txt
331 nl tmp1.txt > tmp1.ttt
332 nl tmp2.txt > tmp2.ttt
333 join tmp1.ttt tmp2.ttt | sed 's/[0-9]*//' > ocn.txt
334 rm -f tmp1.ttt tmp2.ttt tmp1.txt tmp2.txt
335 echo ' ' ; echo '-- compare cg2d_init_res (Ocean):'
336 cat ocn.txt
337 exit
338 fi
339
340 if test $ksel = 5
341 then
342 rm -f atm.txt
343 echo ' run 2it: ---------- ' > tmp1.txt
344 grep "cg2d_init_res" $dir1/atmSTDOUT.2it \
345 | sed 's/.* cg2d_init_res =//' >> tmp1.txt
346 Nit=`expr $NiAt + 2`
347 sed "$Nit i \ ... 2it continue ..." tmp1.txt > tmp2.txt
348 rm -f tmp1.txt
349 echo ' run 1iA: ---------- ' > tmp1.txt
350 grep "cg2d_init_res" $dir2/atmSTDOUT.1iA \
351 | sed 's/.* cg2d_init_res =//' >> tmp1.txt
352 echo ' run 1iB: ---------- ' >> tmp1.txt
353 grep "cg2d_init_res" $dir3/atmSTDOUT.1iB \
354 | sed 's/.* cg2d_init_res =//' >> tmp1.txt
355 nl tmp1.txt > tmp1.ttt
356 nl tmp2.txt > tmp2.ttt
357 join tmp1.ttt tmp2.ttt | sed 's/[0-9]*//' > atm.txt
358 rm -f tmp1.ttt tmp2.ttt tmp1.txt tmp2.txt
359 echo ' ' ; echo '-- compare cg2d_init_res (Atmos):'
360 cat atm.txt
361 exit
362 fi
363
364 #- compare pickup file:
365 if test $ksel = 6
366 then
367 echo ' ' ; echo '=== compare Ocn pickups: =============='
368 for xx in $listOc
369 do
370 dif_tiles $dir1/ocn $dir3/ocn $xx.$noc2c
371 done
372 echo ' ' ; echo '=== compare Atm pickups: =============='
373 for xx in $listAt
374 do
375 dif_tiles $dir1/atm $dir3/atm $xx.$nat2c
376 done
377 exit
378 fi
379
380 #- clean-up and reset:
381 if test $ksel = 7
382 then
383 echo "== clean-up and reset :"
384 # echo '--> remove pickup*.'$noc0c'* sym-links:'
385 # cd rank_1
386 # listS=`find . ! -name . -prune -type l -name 'pickup*.'${noc0c}'*'`
387 # if [ $prt -ge 2 ] ; then echo ' in rank_1: rm' $listS ; fi
388 # rm -f $listS
389 # echo '--> remove pickup*.'$nat0c'* sym-links:'
390 # cd ../rank_2
391 # listS=`find . ! -name . -prune -type l -name 'pickup*.'${nat0c}'*'`
392 # if [ $prt -ge 2 ] ; then echo ' in rank_2: rm' $listS ; fi
393 # rm -f $listS
394 # cd ..
395 echo '--> remove output dir and output files:'
396 echo ' rm -rf' $dir1 $dir2 $dir3
397 rm -rf $dir1 $dir2 $dir3
398 rm -f atm.txt ocn.txt
399 #- move back files from temp_tst dir:
400 #if test -d $tmpDir ; then
401 # echo "--> move back files from 'temp_tst' dir."
402 # cd $tmpDir ; mv -f * .. ; cd ..
403 # rmdir $tmpDir
404 #fi
405 exit
406 fi

  ViewVC Help
Powered by ViewVC 1.1.22