/[MITgcm]/MITgcm_contrib/jmc_script/comp_res
ViewVC logotype

Annotation of /MITgcm_contrib/jmc_script/comp_res

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


Revision 1.1 - (hide annotations) (download)
Thu Mar 17 19:59:54 2022 UTC (3 years, 3 months ago) by jmc
Branch: MAIN
CVS Tags: HEAD
add simple script "comp_res" to compare MONITOR output from 2 standard output-files
(similar to what is done within testreport but made availabe outside testreport).

1 jmc 1.1 #! /usr/bin/env bash
2    
3     # $Header: $
4     # $Name: $
5     #set -x
6    
7     comp_1fld()
8     {
9     # comp_1fld select_string select_var print_var file_1 file_2
10     echo ' ' >> $logfil
11     uu="$1$2"
12     egrep "${uu}" $4 | sed 's/.*=//' | nl > tmp1.txt
13     egrep "${uu}" $5 | sed 's/.*=//' | nl > tmp2.txt
14     if test -s tmp1.txt ; then nl1=`sed -n '$=' tmp1.txt` ; else nl1=0 ; fi
15     if test -s tmp2.txt ; then nl2=`sed -n '$=' tmp2.txt` ; else nl2=0 ; fi
16     if [ $nl1 -ne $nl2 ] ; then
17     cmp=0
18     echo $cmp $3 ' ; nb output:' $nl1 $nl2
19     echo $cmp $3 ' ; nb output:' $nl1 $nl2 >> $logfil
20     rm -f tmp1.txt tmp2.txt
21     elif [ $nl1 -le 1 ] ; then
22     cmp=16
23     echo '--' $3 ' ; not enough output:' $nl1 $nl2
24     echo '--' $3 ' ; not enough output:' $nl1 $nl2 >> $logfil
25     rm -f tmp1.txt tmp2.txt
26     else
27     join tmp1.txt tmp2.txt > tmp3.txt
28     cmp=`$compex < tmp3.txt 2> tmp4.txt`
29     err=`egrep -c ' error ' tmp4.txt`
30     if [ $err -ge 1 ] ; then
31     echo $cmp $3 ':' $compex 'gives' $err 'error(s)'
32     echo $cmp $3 ':' $compex 'gives' $err 'error(s)' >> $logfil
33     cmp=0
34     elif test -s tmp4.txt ; then
35     cat tmp4.txt
36     echo $cmp $3 ' <- set to 0'
37     echo $cmp $3 ' <- set to 0' >> $logfil
38     cmp=0
39     else
40     printf '%2i %s\n' $cmp $3
41     printf '%2i %s\n' $cmp $3 >> $logfil
42     fi
43     if test -f cmpnum.log
44     then cat cmpnum.log >> $logfil ; rm -f cmpnum.log ; fi
45     rm -f tmp1.txt tmp2.txt tmp3.txt tmp4.txt
46     fi
47     if [ $cmp -lt $gMin ] ; then gMin=$cmp ; fi
48     }
49    
50     kAd=0
51     if [ $# -ge 3 ] ; then
52     if test $3 = 'AD' ; then
53     kAd=1 ; fil1=$1 ; fil2=$2 ; shift
54     fi
55     fi
56     case $# in
57     2|3) ;;
58     *) echo "Usage: `basename $0` outp_file_1 outp_file_2 [AD][D,nh,ad,tl,S,I,L,#]"
59     echo " compare output from DEBUG_STATS (=D) or from [AD] MONITOR, with:"
60     echo " nh (+cg3d) ; ad= Adj.Grad ; tl= Tang.Lin ; S= SeaIce only ;"
61     echo " E= exf ; I= ThSI ; L= land ; M= StreamIce ; # = number of pTrac"
62     exit ;;
63     esac
64     if test $kAd = 0 ; then fil1=$1 ; fil2=$2 ; fi
65     flag=0
66     if test $# = 3 ; then flag=$3 ; fi
67     logfil=comp_res.log
68    
69     echo 'flag=' $flag ' ; file_1 file_2 =' $fil1 $fil2
70    
71     #platform=`uname -i`
72     platform=`uname -m`
73     exDir=`echo $HOME/mitgcm/bin`
74     compex=`ls $exDir/cmpnum.$platform 2>/dev/null`
75     if test x$compex = x
76     then compex=`ls $exDir/cmpnum 2>/dev/null` ; fi
77     if test x$compex = x
78     then echo "executable: $exDir/cmpnum not found" ; exit ; fi
79     #echo $compex
80     if test -x $compex
81     then echo ' use executable:' $compex
82     else echo "executable: $compex not found" ; exit
83     fi
84    
85     echo 'flag=' $flag ' ; file_1 file_2 =' $fil1 $fil2 > $logfil
86     echo ' use executable:' $compex >> $logfil
87    
88     listA='eta uvel vvel wvel theta salt'
89     listB='u v w W'
90     listC='pe_b ke_max ke_mean vort_r_min vort_r_max vort_a_sd vort_p_sd cg2d'
91     if test $flag = 'nh'; then listC=$listC' cg3d' ; flag=0; fi
92    
93     listS='_min _max _mean _sd _del2'
94    
95     listDy='EtaN Uvel Vvel Wvel Theta Salt Gu Gv Gt Gs GuNm1 GvNm1 GtNm1 GsNm1 cg2d_b cg2d_x'
96     #listDy='Gu Gv cg2d_b'
97     listDb=' min max mean S.D.'
98    
99     listE='ustress vstress hflux sflux uwind vwind wspeed atemp aqh precip swflux lwflux swdown lwdown'
100     if test $kAd = 0 ; then listE="$listE evap" ; fi
101    
102     listSI='uice vice area heff hsnow'
103    
104     listI='Ice_Area IceH_ave IceH_max SnwH_ave Tsrf_ave Tic1_ave Tic2_ave'
105     listH='_S _N'
106    
107     listL='SnwH_ave TotEnerg Tsrf_ave Tgr1_ave Tgr2_ave grdW_ave'
108     listZ='_S _T _N'
109    
110     listAD='Cost AdGrd FDGrd'
111     #- with old ADM output:
112     #listAD='cost grad'
113     listTL='tlCst tlGrd fwGrd'
114    
115     gMin=16;
116    
117     if test $flag = 0
118     then
119     zz='MON dynstat_'
120     if test $kAd = 1 ; then zz='MON ad_dynstat_' ; fi
121     for yy in $listA
122     do
123     for ss in $listS
124     do
125     xx=${yy}$ss
126     if test $kAd = 1 ; then xx='ad'$xx ; fi
127     comp_1fld "$zz" $xx $xx $fil1 $fil2
128     done
129     done
130     fi
131    
132     if test $flag = 0 -a $kAd = 0
133     then
134     zz='MON advcfl_'
135     for yy in $listB
136     do
137     xx='CFL_'$yy
138     comp_1fld "$zz" $yy $xx $fil1 $fil2
139     done
140     fi
141    
142     if test $flag = 0 -a $kAd = 0
143     then
144     for xx in $listC
145     do
146     # echo ' ' >> $logfil
147     zz='MON '
148     if test $xx = cg2d -o $xx = cg3d ; then zz=$xx; yy=_init_res ; else yy=$xx ; fi
149     #echo $yy
150     comp_1fld "$zz" $yy $xx $fil1 $fil2
151     done
152     fi
153    
154     if test $flag = 'D'
155     then
156     for yy in $listDy
157     do
158     for xx in $listDb
159     do
160     zz=${yy}' .*'$xx
161     comp_1fld "$zz" '=' "${yy}[${xx}]" $fil1 $fil2
162     done
163     done
164     echo 'Minimum match= ' $gMin
165     exit
166     fi
167    
168     if test $flag = 'E' -a $kAd = 0
169     then
170     zz='MON exf_'
171     for yy in $listE
172     do
173     for ss in $listS
174     do
175     xx=${yy}$ss
176     comp_1fld "$zz" $xx $xx $fil1 $fil2
177     done
178     done
179     echo 'Minimum match= ' $gMin
180     exit
181     fi
182     if test $flag = 'E' -a $kAd = 1
183     then
184     zz='MON ad_exf_'
185     for yy in $listE
186     do
187     for ss in $listS
188     do
189     xx='ad'${yy}$ss
190     comp_1fld "$zz" $xx $xx $fil1 $fil2
191     done
192     done
193     echo 'Minimum match= ' $gMin
194     exit
195     fi
196    
197     if test $flag = 'S'
198     then
199     zz='MON seaice_'
200     for yy in $listSI
201     do
202     for ss in $listS
203     do
204     xx=${yy}$ss
205     comp_1fld "$zz" $xx $xx $fil1 $fil2
206     done
207     done
208     echo 'Minimum match= ' $gMin
209     exit
210     fi
211    
212     if test $flag = 'I'
213     then
214     zz='MON thSI_'
215     for yy in $listI
216     do
217     for ss in $listH
218     do
219     xx=${yy}$ss
220     comp_1fld "$zz" $xx $xx $fil1 $fil2
221     done
222     done
223     echo 'Minimum match= ' $gMin
224     exit
225     fi
226    
227     if test $flag = 'L'
228     then
229     zz='MON land_'
230     for yy in $listL
231     do
232     for ss in $listZ
233     do
234     xx=${yy}$ss
235     comp_1fld "$zz" $xx $xx $fil1 $fil2
236     done
237     done
238     echo 'Minimum match= ' $gMin
239     exit
240     fi
241    
242     if test $flag = 'M'
243     then
244     listM='StrmIc'
245     zz='STREAMICE_'
246     listN='FP_ERR'
247     for yy in $listM
248     do
249     for ss in $listN
250     do
251     xx=$ss
252     comp_1fld "$zz" $xx $yy $fil1 $fil2
253     done
254     done
255     echo 'Minimum match= ' $gMin
256     exit
257     fi
258    
259     if test $flag = 'ad'
260     then
261     zz=' ADM '
262     #- with old ADM output:
263     # zz=' ADM precision_derivative_'
264     echo $fil1 ' output ADM:'
265     grep "$zz" $fil1 | sed "s/.*$zz/ /"
266     echo $fil2 ' output ADM:'
267     grep "$zz" $fil2 | sed "s/.*$zz/ /"
268     for yy in $listAD
269     do
270     case $yy in
271     'Cost') xx='ref_cost_function' ;;
272     'AdGrd') xx='adjoint_gradient' ;;
273     'FDGrd') xx='finite-diff_grad' ;;
274     *) xx=$yy ;;
275     esac
276     for ss in 'result'
277     do
278     comp_1fld "$zz" $xx $yy $fil1 $fil2
279     done
280     done
281     echo 'Minimum match= ' $gMin
282     exit
283     fi
284    
285     if test $flag = 'tl'
286     then
287     zz=' TLM '
288     echo $fil1 ' output TLM:'
289     grep "$zz" $fil1 | sed "s/.*$zz/ /"
290     echo $fil2 ' output TLM:'
291     grep "$zz" $fil2 | sed "s/.*$zz/ /"
292     for yy in $listTL
293     do
294     case $yy in
295     'tlCst') xx='ref_cost_function' ;;
296     'tlGrd') xx='tangent-lin_grad' ;;
297     'fwGrd') xx='finite-diff_grad' ;;
298     *) xx=$yy ;;
299     esac
300     for ss in 'result'
301     do
302     comp_1fld "$zz" $xx $yy $fil1 $fil2
303     done
304     done
305     echo 'Minimum match= ' $gMin
306     exit
307     fi
308    
309     if [ $flag -ge 1 -a $flag -le 9 ]
310     then
311     zz='MON trcstat_'
312     if test $kAd = 1 ; then zz='MON ad_trcstat_' ; fi
313     it=1
314     while [ $it -le $flag ]
315     do
316     yy='ptracer0'$it
317     if test $kAd = 1 ; then yy='ad'$yy ; fi
318     for ss in $listS
319     do
320     xx=${yy}$ss
321     comp_1fld "$zz" $xx $xx $fil1 $fil2
322     done
323     it=`expr $it + 1`
324     done
325     fi
326    
327     echo 'Minimum match= ' $gMin
328     exit

  ViewVC Help
Powered by ViewVC 1.1.22