1 | #!/bin/bash |
---|
2 | |
---|
3 | login=`whoami` |
---|
4 | |
---|
5 | hostname=`hostname` |
---|
6 | if [ ${hostname:0:5} = cicla ] ; then |
---|
7 | DODSDIR=/thredds/ipsl |
---|
8 | fi |
---|
9 | if [ ${hostname:0:5} = camel ] ; then |
---|
10 | DODSDIR=/thredds/ipsl |
---|
11 | fi |
---|
12 | if [ ${hostname:0:5} = irene ] ; then |
---|
13 | DODSDIR= |
---|
14 | fi |
---|
15 | if [ ${hostname:0:5} = jean- ] ; then |
---|
16 | DODSDIR= |
---|
17 | fi |
---|
18 | |
---|
19 | set -vx |
---|
20 | force_create=1 |
---|
21 | |
---|
22 | comp=$1 |
---|
23 | local=`pwd` |
---|
24 | |
---|
25 | for season in YEAR DJF JJA ; do |
---|
26 | |
---|
27 | |
---|
28 | cd $local |
---|
29 | |
---|
30 | if [ "$season" = "YEAR" ] ; then |
---|
31 | masks="ter oce NAtl Arct circA otrop glob eto weak conv subs NH SH PANET OCEMAR CONMAR" |
---|
32 | mask_figs="NAtl Arct circA glob ter oce otrop interH etoa etow etows circAa NAtla conv weak subs PANET OCEMAR CONMAR" |
---|
33 | else |
---|
34 | masks="NAtl Arct circA Sibe USA PANET OCEMAR CONMAR" |
---|
35 | mask_figs="NAtl Arct circA Sibe USA PANET OCEMAR CONMAR" |
---|
36 | fi |
---|
37 | |
---|
38 | WRK_D=$local/XMGR$$/$season |
---|
39 | if [ -d $WRK_D ] ; then WRK_D=$WRK_D$$ ; fi |
---|
40 | mkdir -p $WRK_D |
---|
41 | cd $WRK_D |
---|
42 | ln -s ../../mas*nc . |
---|
43 | |
---|
44 | comp=`basename $1` |
---|
45 | if [ -d $DODSDIR/$login/lmdz/MultiSimu ] ; then |
---|
46 | # Installation multi modele fabric |
---|
47 | COMP_D=$DODSDIR/$login/lmdz/MultiSimu/$comp |
---|
48 | CMOR_DIR=$DODSDIR/$login/lmdz/VLR/$season |
---|
49 | elif [ "$comp" = "$1" ] ; then |
---|
50 | # Installation locale |
---|
51 | COMP_D=. |
---|
52 | CMOR_DIR=. |
---|
53 | else |
---|
54 | # Path absolu |
---|
55 | COMP_D=$1 |
---|
56 | CMOR_DIR=. |
---|
57 | fi |
---|
58 | |
---|
59 | ############################################### |
---|
60 | # Liste des simulations de la comparasion $comp |
---|
61 | listsims="" ; listsimsy="" |
---|
62 | DEF_FILE=$COMP_D/def.txt ; if [ ! -f "$DEF_FILE" ] ; then renseigner $DEF_FILE ; exit ; fi |
---|
63 | for s in `awk ' {print $1"_"$2 } ' $DEF_FILE` ; do listsimsy="$listsimsy $s" ; done |
---|
64 | for s in `awk ' {print $1 } ' $DEF_FILE` ; do listsims="$listsims $s" ; done |
---|
65 | ############################################### |
---|
66 | |
---|
67 | echo $listsimsy |
---|
68 | ici=`pwd` |
---|
69 | |
---|
70 | for simy in OBS $listsimsy ; do |
---|
71 | sim=`echo $simy | sed -e 's/_[0-9][0-9][0-9][0-9]_[0-9][0-9][0-9][0-9]//'` |
---|
72 | years=`echo $simy | sed -e s/${sim}//` |
---|
73 | echo SIM $sim |
---|
74 | echo years $years |
---|
75 | |
---|
76 | |
---|
77 | SIM_DIR=$CMOR_DIR/$GR/$sim$years |
---|
78 | ETOA_DIR=$SIM_DIR/METRICS |
---|
79 | |
---|
80 | |
---|
81 | for mask in $masks ; do |
---|
82 | xmgr=$ETOA_DIR/$mask |
---|
83 | mkdir -p $ETOA_DIR |
---|
84 | if [ ! -f "$xmgr" -o "$force_create" = "1" ] ; then |
---|
85 | \rm -f $xmgr ; touch $xmgr |
---|
86 | if [ ! -d $SIM_DIR ] ; then echo $SIM_DIR absent ; exit ; fi |
---|
87 | set +e ; \rm resu$sim ; set -e |
---|
88 | for var in rsut clhcalipso cllcalipso clmcalipso cltcalipso clt hfls eva hfss hurs huss pr ts tas sst psl rldscs rlds rlus rlutcs rlut rsdscs rsds rsdt rsuscs rsus rsutcs prw ; do |
---|
89 | if [ -f "$SIM_DIR/NC/$var.nc" ] ; then |
---|
90 | if [ "$mask" = "glob" ] ; then |
---|
91 | val=`cdo output -fldmean -selvar,$var $SIM_DIR/NC/$var.nc` |
---|
92 | elif [ ! -f "mask$mask.nc" ] ; then |
---|
93 | echo Le fichier mask$mask.nc n existe pas ; exit |
---|
94 | else |
---|
95 | if [ 1 = 1 ] ; then |
---|
96 | if [ 1 = 0 ] && [ $var = "hfls" ] && [ $simy == "OBS" ]; then |
---|
97 | cdo remapcon,mask$mask.nc $SIM_DIR/NC/$var.nc_ocean-only tmp.nc |
---|
98 | val=`cdo output -fldmean -selvar,$var -mul tmp.nc mask$mask.nc` |
---|
99 | else |
---|
100 | cdo remapcon,mask$mask.nc $SIM_DIR/NC/$var.nc tmp.nc |
---|
101 | val=`cdo output -fldmean -selvar,$var -mul tmp.nc mask$mask.nc` |
---|
102 | fi |
---|
103 | else |
---|
104 | cdo remapcon,maskotrop.nc $SIM_DIR/NC/$var.nc tmp.nc |
---|
105 | cdo remapcon,maskotrop.nc mask$mask.nc mask.nc |
---|
106 | val=`cdo output -fldmean -selvar,$var -mul tmp.nc mask.nc` |
---|
107 | fi |
---|
108 | fi |
---|
109 | echo $mask $sim $var $val |
---|
110 | echo $var $val >> $xmgr |
---|
111 | else |
---|
112 | echo $var 999999 >> $xmgr |
---|
113 | fi |
---|
114 | done |
---|
115 | rsut=`grep '^rsut ' $xmgr | awk ' { print $2 } '` |
---|
116 | rsutcs=`grep '^rsutcs ' $xmgr | awk ' { print $2 } '` |
---|
117 | rlut=`grep '^rlut ' $xmgr | awk ' { print $2 } '` |
---|
118 | rlutcs=`grep '^rlutcs ' $xmgr | awk ' { print $2 } '` |
---|
119 | hfls=`grep '^hfls ' $xmgr | awk ' { print $2 } '` |
---|
120 | eva=`grep '^eva ' $xmgr | awk ' { print $2 } '` |
---|
121 | hfss=`grep '^hfss ' $xmgr | awk ' { print $2 } '` |
---|
122 | rlds=`grep '^rlds ' $xmgr | awk ' { print $2 } '` |
---|
123 | rldscs=`grep '^rldscs ' $xmgr | awk ' { print $2 } '` |
---|
124 | rsds=`grep '^rsds ' $xmgr | awk ' { print $2 } '` |
---|
125 | rsdscs=`grep '^rsdscs ' $xmgr | awk ' { print $2 } '` |
---|
126 | rlus=`grep '^rlus ' $xmgr | awk ' { print $2 } '` |
---|
127 | rsus=`grep '^rsus ' $xmgr | awk ' { print $2 } '` |
---|
128 | rsuscs=`grep '^rsuscs ' $xmgr | awk ' { print $2 } '` |
---|
129 | rsdt=`grep '^rsdt ' $xmgr | awk ' { print $2 } '` |
---|
130 | echo $rsut $rsutcs | awk ' { print "crest" , $2 - $1 } ' >> $xmgr |
---|
131 | echo $rlut $rlutcs | awk ' { print "crelt" , $2 - $1 } ' >> $xmgr |
---|
132 | echo $rsut $rsutcs $rlut $rlutcs | awk ' { print "cret" , $2 - $1 +$4 -$3 } ' >> $xmgr |
---|
133 | echo $rsdt $rsut | awk ' { print "rst" , $1 - $2 } ' >> $xmgr |
---|
134 | echo $rsdt $rsutcs | awk ' { print "rstcs" , $1 - $2 } ' >> $xmgr |
---|
135 | echo $rsdt $rsut $rlut | awk ' { print "rt" , $1 - $2 -$3 } ' >> $xmgr |
---|
136 | echo $hfls $hfss | awk ' { print "trbs" , $1 + $2 } ' >> $xmgr |
---|
137 | echo $rlds $rlus | awk ' { print "rls" , $1 - $2 } ' >> $xmgr |
---|
138 | echo $rsds $rsus | awk ' { print "rss" , $1 - $2 } ' >> $xmgr |
---|
139 | echo $rlds $rlus $rsds $rsus | awk ' { print "rs" , $1 - $2 +$3 - $4 } ' >> $xmgr |
---|
140 | echo $rlds $rldscs $rsds $rsdscs $rsus $rsuscs | awk ' { print "cres" , $1 - $2 + $3 - $4 - $5 + $6 } ' >> $xmgr |
---|
141 | echo $rlds $rldscs $rsds $rsdscs $rsus $rsuscs $hfls | awk ' { print "crehfls" , $1 - $2 + $3 - $4 - $5 + $6 - $7 } ' >> $xmgr |
---|
142 | echo $rlds $rlus $rsds $rsus $hfls $hfss | awk ' { print "bils" , $1 - $2 + $3 - $4 - $5 - $6 } ' >> $xmgr |
---|
143 | fi |
---|
144 | done |
---|
145 | |
---|
146 | # Masques combinés |
---|
147 | set +e |
---|
148 | paste $ETOA_DIR/otrop $ETOA_DIR/eto | awk ' { if ( $2 == 999999 || $4 == 999999 ) print $1 , 999999 ; else print $1 , $4 - $2 } ' >| $ETOA_DIR/etoa |
---|
149 | paste $ETOA_DIR/weak $ETOA_DIR/subs | awk ' { if ( $2 == 999999 || $4 == 999999 ) print $1 , 999999 ; else print $1 , $4 - $2 } ' >| $ETOA_DIR/etows |
---|
150 | paste $ETOA_DIR/weak $ETOA_DIR/eto | awk ' { if ( $2 == 999999 || $4 == 999999 ) print $1 , 999999 ; else print $1 , $4 - $2 } ' >| $ETOA_DIR/etow |
---|
151 | paste $ETOA_DIR/otrop $ETOA_DIR/circA | awk ' { if ( $2 == 999999 || $4 == 999999 ) print $1 , 999999 ; else print $1 , $4 - $2 } ' >| $ETOA_DIR/circAa |
---|
152 | paste $ETOA_DIR/NAtl $ETOA_DIR/otrop | awk ' { if ( $2 == 999999 || $4 == 999999 ) print $1 , 999999 ; else print $1 , $4 - $2 } ' >| $ETOA_DIR/NAtla |
---|
153 | paste $ETOA_DIR/SH $ETOA_DIR/NH | awk ' { if ( $2 == 999999 || $4 == 999999 ) print $1 , 999999 ; else print $1 , $4 - $2 } ' >| $ETOA_DIR/interH |
---|
154 | set -e |
---|
155 | |
---|
156 | done |
---|
157 | |
---|
158 | |
---|
159 | ######################################################################################### |
---|
160 | # Tracers |
---|
161 | ######################################################################################### |
---|
162 | |
---|
163 | |
---|
164 | |
---|
165 | cat <<eod>| descr |
---|
166 | clhcalipso 1 High Clouds |
---|
167 | cllcalipso 1 Low Clouds |
---|
168 | clmcalipso 1 Mid Clouds |
---|
169 | cltcalipso 1 Total Clouds |
---|
170 | clt 1 LMDZ Total Clouds |
---|
171 | hfls -1 -LE |
---|
172 | eva 1 Evaporation |
---|
173 | hfss -1 -H |
---|
174 | hurs 1 RHsrf |
---|
175 | huss 1 Surface specific humidity |
---|
176 | pr 10 PR*10 |
---|
177 | prw 1 PRW |
---|
178 | psl 1 SLP |
---|
179 | ts 10 Ts*10 |
---|
180 | sst 10 sst*10 |
---|
181 | tas 10 T2m*10 |
---|
182 | rlds 1 LWdn srf |
---|
183 | rldscs 1 LWdn srf Clr |
---|
184 | rlus -1 LWup Srf |
---|
185 | rlutcs -1 LW TOA Clr |
---|
186 | rlut -1 LW TOA |
---|
187 | rsdscs 1 SWdn srf Clr |
---|
188 | rsds 1 SWdn srf |
---|
189 | rsdt 1 SWdn TOA |
---|
190 | rsuscs -1 SWup srf Clr |
---|
191 | rsus -1 SWup srf |
---|
192 | rsutcs -1 SW TOA Clr |
---|
193 | rstcs -1 SW TOA Clr |
---|
194 | rsut -1 SW TOA |
---|
195 | crest 1 SW CRE TOA |
---|
196 | crelt 1 LW CRE TOA |
---|
197 | cres 1 CRE srf |
---|
198 | crehfls 1 CRE - LE |
---|
199 | cret 1 CRE TOA |
---|
200 | rst 1 SW TOA |
---|
201 | rt 1 SW+LW TOA |
---|
202 | trbs -1 -(LE+H) |
---|
203 | rls 1 LW srf |
---|
204 | rss 1 SW srf |
---|
205 | rs 1 SW+LW srf |
---|
206 | bils 1 Srf budget |
---|
207 | eod |
---|
208 | |
---|
209 | # ------------------- debut boucle sur les figures ---------------------------- |
---|
210 | for mask in $mask_figs ; do |
---|
211 | # ------------------- debut boucle sur les figures ---------------------------- |
---|
212 | |
---|
213 | case $mask in |
---|
214 | NAtla|circAa|etoa|etow|etows|oce|otrop) listevars="ts bils crehfls cres rs rss crest hfls tas cllcalipso clhcalipso " ;; |
---|
215 | interH|glob|ter|NAtl|circA|conv|weak|subs|PANET|CONMAR|OCEMAR) listevars="bils tas rt rlutcs crelt rsutcs crest cllcalipso clmcalipso clhcalipso pr" ;; |
---|
216 | Arct|Sibe|USA) listevars="tas rs rlds rsds crelt crest cllcalipso clmcalipso clhcalipso pr prw" ;; |
---|
217 | *) echo cas non prevu ; exit |
---|
218 | esac |
---|
219 | |
---|
220 | nvars=`echo $listevars | wc -w | awk ' { print $1 } '` |
---|
221 | case $mask in |
---|
222 | NAtl) yax="North Atlantic " ;; |
---|
223 | Arct) yax="Arctic ocean" ;; |
---|
224 | circA) yax="Circum Antartica " ;; |
---|
225 | Sibe) yax="Siberia " ;; |
---|
226 | USA) yax="US Gr. Plains " ;; |
---|
227 | glob) yax="Global " ;; |
---|
228 | ter) yax="Land " ;; |
---|
229 | oce) yax="Ocean " ;; |
---|
230 | otrop) yax="Tropical ocean " ;; |
---|
231 | interH) yax="Inter Hemispheric " ;; |
---|
232 | etoa) yax="ETOA " ;; |
---|
233 | etow) yax="ETO - Weak " ;; |
---|
234 | etows) yax="subs - Weak " ;; |
---|
235 | circAa) yax="Circum Antartic Anom. " ;; |
---|
236 | NAtla) yax="Nort Atlantic Anom. " ;; |
---|
237 | conv) yax="Convective regimes " ;; |
---|
238 | weak) yax="Weak convection " ;; |
---|
239 | subs) yax="Subsidences " ;; |
---|
240 | PANET) yax="Pacific Trop. NE" ;; |
---|
241 | CONMAR) yax="Terres Cont. Mar." ;; |
---|
242 | OCEMAR) yax="Ocean Cont. Mar." |
---|
243 | esac |
---|
244 | cat <<...eod>| tmp.param |
---|
245 | g0 type Chart |
---|
246 | world -0.5, -35, $nvars, 35 |
---|
247 | yaxis label "$yax Fluxes (W/m2) " |
---|
248 | xaxis ticklabel font 0 |
---|
249 | xaxis ticklabel color 1 |
---|
250 | xaxis tick place both |
---|
251 | xaxis tick spec type both |
---|
252 | xaxis tick spec 11 |
---|
253 | xaxis ticklabel char size 1.3 |
---|
254 | xaxis ticklabel angle 90 |
---|
255 | yaxis tick major 10 |
---|
256 | yaxis tick minor ticks 1 |
---|
257 | legend 1.20, 0.8 |
---|
258 | ...eod |
---|
259 | |
---|
260 | ii=0 |
---|
261 | for var in $listevars ; do |
---|
262 | fact=`grep "^$var " descr | awk ' { print $2 } '` |
---|
263 | titre=`grep "^$var " descr | sed -e 's/'$var'//' -e 's/'$fact'//'` |
---|
264 | cat <<......eod>> tmp.param |
---|
265 | xaxis tick major $ii, $ii |
---|
266 | xaxis ticklabel $ii, "$titre" |
---|
267 | ......eod |
---|
268 | (( ii = $ii + 1 )) |
---|
269 | done |
---|
270 | |
---|
271 | |
---|
272 | prev="" |
---|
273 | ip=0 |
---|
274 | listex="" |
---|
275 | echo LISTESIMSY $listsimsy |
---|
276 | for simy in $listsimsy ; do |
---|
277 | sim=`echo $simy | sed -e 's/_[0-9][0-9][0-9][0-9]_[0-9][0-9][0-9][0-9]//'` |
---|
278 | years=`echo $simy | sed -e s/${sim}//` |
---|
279 | echo $sim |
---|
280 | SIM_DIR=$CMOR_DIR/$sim$years/METRICS |
---|
281 | ls $SIM_DIR |
---|
282 | OBS_DIR=$CMOR_DIR/OBS/METRICS |
---|
283 | mkdir -p $WRK_D/$mask |
---|
284 | if [ "$sim" = "$prev" ] ; then # Cas ou on a plusieurs decennies de la meme simu |
---|
285 | (( ip = $ip + 1 )) |
---|
286 | xmgr=$WRK_D/$mask/$sim.$ip |
---|
287 | listex="$listex $sim.$ip" |
---|
288 | else |
---|
289 | xmgr=$WRK_D/$mask/$sim |
---|
290 | ip=0 ; prev=$sim |
---|
291 | listex="$listex $sim" |
---|
292 | fi |
---|
293 | rm -f $xmgr ; touch $xmgr |
---|
294 | for var in $listevars ; do |
---|
295 | echo var $var |
---|
296 | fact=`grep "^$var " descr | awk ' { print $2 } '` |
---|
297 | paste $OBS_DIR/$mask $SIM_DIR/$mask | grep "^$var " | awk ' { if ( $4 == 999999 ) print 0 ; else print '$fact' * ( $4 - $2 ) } ' >> $xmgr |
---|
298 | done |
---|
299 | done |
---|
300 | |
---|
301 | |
---|
302 | |
---|
303 | size=`echo $listsims | wc -w | awk ' { print 3. / $1 } '` |
---|
304 | for ii in 0 1 2 3 4 5 6 7 8 9 10 11 12 ; do |
---|
305 | echo "s$ii type bar" >> tmp.param |
---|
306 | echo "s$ii symbol fill pattern 1" >> tmp.param |
---|
307 | echo "s$ii symbol size $size" >> tmp.param |
---|
308 | echo "s$ii line linestyle 0" >> tmp.param |
---|
309 | echo "s$ii color $ii" >> tmp.param |
---|
310 | done |
---|
311 | |
---|
312 | cd $WRK_D/$mask |
---|
313 | pwd ; echo xmgrace $listex -param ../../../tmp.param -legend load -hardcopy -hdevice EPS -printfile tmp.eps |
---|
314 | xmgrace $listex -param ../../../tmp.param -legend load -hardcopy -hdevice EPS -printfile tmp.eps |
---|
315 | cp ../../../Colordef.txt . |
---|
316 | sed -i -e '32,47d' tmp.eps |
---|
317 | sed -i -e '31r Colordef.txt' tmp.eps |
---|
318 | epstopdf tmp.eps |
---|
319 | OUT_D=$COMP_D/METRICS/$season ; mkdir -p $OUT_D |
---|
320 | \mv -f tmp.pdf $OUT_D/$mask.pdf ; convert -density 144 $OUT_D/$mask.pdf $OUT_D/$mask.png |
---|
321 | cd ../../.. |
---|
322 | |
---|
323 | done |
---|
324 | |
---|
325 | cp mask*png $OUT_D |
---|
326 | done |
---|