1 | #!/bin/bash |
---|
2 | |
---|
3 | login=`whoami` |
---|
4 | |
---|
5 | hostname=`hostname` |
---|
6 | if [ ${hostname:0:5} = cicla ] ; then |
---|
7 | DODSDIR=/prodigfs/ipslfs/dods |
---|
8 | fi |
---|
9 | if [ ${hostname:0:5} = camel ] ; then |
---|
10 | DODSDIR=/prodigfs/ipslfs/dods |
---|
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 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 | hfss=`grep '^hfss ' $xmgr | awk ' { print $2 } '` |
---|
121 | rlds=`grep '^rlds ' $xmgr | awk ' { print $2 } '` |
---|
122 | rldscs=`grep '^rldscs ' $xmgr | awk ' { print $2 } '` |
---|
123 | rsds=`grep '^rsds ' $xmgr | awk ' { print $2 } '` |
---|
124 | rsdscs=`grep '^rsdscs ' $xmgr | awk ' { print $2 } '` |
---|
125 | rlus=`grep '^rlus ' $xmgr | awk ' { print $2 } '` |
---|
126 | rsus=`grep '^rsus ' $xmgr | awk ' { print $2 } '` |
---|
127 | rsuscs=`grep '^rsuscs ' $xmgr | awk ' { print $2 } '` |
---|
128 | rsdt=`grep '^rsdt ' $xmgr | awk ' { print $2 } '` |
---|
129 | echo $rsut $rsutcs | awk ' { print "crest" , $2 - $1 } ' >> $xmgr |
---|
130 | echo $rlut $rlutcs | awk ' { print "crelt" , $2 - $1 } ' >> $xmgr |
---|
131 | echo $rsut $rsutcs $rlut $rlutcs | awk ' { print "cret" , $2 - $1 +$4 -$3 } ' >> $xmgr |
---|
132 | echo $rsdt $rsut | awk ' { print "rst" , $1 - $2 } ' >> $xmgr |
---|
133 | echo $rsdt $rsutcs | awk ' { print "rstcs" , $1 - $2 } ' >> $xmgr |
---|
134 | echo $rsdt $rsut $rlut | awk ' { print "rt" , $1 - $2 -$3 } ' >> $xmgr |
---|
135 | echo $hfls $hfss | awk ' { print "trbs" , $1 + $2 } ' >> $xmgr |
---|
136 | echo $rlds $rlus | awk ' { print "rls" , $1 - $2 } ' >> $xmgr |
---|
137 | echo $rsds $rsus | awk ' { print "rss" , $1 - $2 } ' >> $xmgr |
---|
138 | echo $rlds $rlus $rsds $rsus | awk ' { print "rs" , $1 - $2 +$3 - $4 } ' >> $xmgr |
---|
139 | echo $rlds $rldscs $rsds $rsdscs $rsus $rsuscs | awk ' { print "cres" , $1 - $2 + $3 - $4 - $5 + $6 } ' >> $xmgr |
---|
140 | echo $rlds $rldscs $rsds $rsdscs $rsus $rsuscs $hfls | awk ' { print "crehfls" , $1 - $2 + $3 - $4 - $5 + $6 - $7 } ' >> $xmgr |
---|
141 | echo $rlds $rlus $rsds $rsus $hfls $hfss | awk ' { print "bils" , $1 - $2 + $3 - $4 - $5 - $6 } ' >> $xmgr |
---|
142 | fi |
---|
143 | done |
---|
144 | |
---|
145 | # Masques combinés |
---|
146 | set +e |
---|
147 | paste $ETOA_DIR/otrop $ETOA_DIR/eto | awk ' { if ( $2 == 999999 || $4 == 999999 ) print $1 , 999999 ; else print $1 , $4 - $2 } ' >| $ETOA_DIR/etoa |
---|
148 | paste $ETOA_DIR/weak $ETOA_DIR/subs | awk ' { if ( $2 == 999999 || $4 == 999999 ) print $1 , 999999 ; else print $1 , $4 - $2 } ' >| $ETOA_DIR/etows |
---|
149 | paste $ETOA_DIR/weak $ETOA_DIR/eto | awk ' { if ( $2 == 999999 || $4 == 999999 ) print $1 , 999999 ; else print $1 , $4 - $2 } ' >| $ETOA_DIR/etow |
---|
150 | paste $ETOA_DIR/otrop $ETOA_DIR/circA | awk ' { if ( $2 == 999999 || $4 == 999999 ) print $1 , 999999 ; else print $1 , $4 - $2 } ' >| $ETOA_DIR/circAa |
---|
151 | paste $ETOA_DIR/NAtl $ETOA_DIR/otrop | awk ' { if ( $2 == 999999 || $4 == 999999 ) print $1 , 999999 ; else print $1 , $4 - $2 } ' >| $ETOA_DIR/NAtla |
---|
152 | paste $ETOA_DIR/SH $ETOA_DIR/NH | awk ' { if ( $2 == 999999 || $4 == 999999 ) print $1 , 999999 ; else print $1 , $4 - $2 } ' >| $ETOA_DIR/interH |
---|
153 | set -e |
---|
154 | |
---|
155 | done |
---|
156 | |
---|
157 | |
---|
158 | ######################################################################################### |
---|
159 | # Tracers |
---|
160 | ######################################################################################### |
---|
161 | |
---|
162 | |
---|
163 | |
---|
164 | cat <<eod>| descr |
---|
165 | clhcalipso 1 High Clouds |
---|
166 | cllcalipso 1 Low Clouds |
---|
167 | clmcalipso 1 Mid Clouds |
---|
168 | cltcalipso 1 Total Clouds |
---|
169 | clt 1 LMDZ Total Clouds |
---|
170 | hfls -1 -LE |
---|
171 | hfss -1 -H |
---|
172 | hurs 1 RHsrf |
---|
173 | huss 1 Surface specific humidity |
---|
174 | pr 10 PR*10 |
---|
175 | prw 1 PRW |
---|
176 | psl 1 SLP |
---|
177 | ts 10 Ts*10 |
---|
178 | sst 10 sst*10 |
---|
179 | tas 10 T2m*10 |
---|
180 | rlds 1 LWdn srf |
---|
181 | rldscs 1 LWdn srf Clr |
---|
182 | rlus -1 LWup Srf |
---|
183 | rlutcs -1 LW TOA Clr |
---|
184 | rlut -1 LW TOA |
---|
185 | rsdscs 1 SWdn srf Clr |
---|
186 | rsds 1 SWdn srf |
---|
187 | rsdt 1 SWdn TOA |
---|
188 | rsuscs -1 SWup srf Clr |
---|
189 | rsus -1 SWup srf |
---|
190 | rsutcs -1 SW TOA Clr |
---|
191 | rstcs -1 SW TOA Clr |
---|
192 | rsut -1 SW TOA |
---|
193 | crest 1 SW CRE TOA |
---|
194 | crelt 1 LW CRE TOA |
---|
195 | cres 1 CRE srf |
---|
196 | crehfls 1 CRE - LE |
---|
197 | cret 1 CRE TOA |
---|
198 | rst 1 SW TOA |
---|
199 | rt 1 SW+LW TOA |
---|
200 | trbs -1 -(LE+H) |
---|
201 | rls 1 LW srf |
---|
202 | rss 1 SW srf |
---|
203 | rs 1 SW+LW srf |
---|
204 | bils 1 Srf budget |
---|
205 | eod |
---|
206 | |
---|
207 | # ------------------- debut boucle sur les figures ---------------------------- |
---|
208 | for mask in $mask_figs ; do |
---|
209 | # ------------------- debut boucle sur les figures ---------------------------- |
---|
210 | |
---|
211 | case $mask in |
---|
212 | NAtla|circAa|etoa|etow|etows|oce|otrop) listevars="ts bils crehfls cres rs rss crest hfls tas cllcalipso clhcalipso " ;; |
---|
213 | interH|glob|ter|NAtl|circA|conv|weak|subs|PANET|CONMAR|OCEMAR) listevars="bils tas rt rlutcs crelt rsutcs crest cllcalipso clmcalipso clhcalipso pr" ;; |
---|
214 | Arct|Sibe|USA) listevars="tas rs rlds rsds crelt crest cllcalipso clmcalipso clhcalipso pr prw" ;; |
---|
215 | *) echo cas non prevu ; exit |
---|
216 | esac |
---|
217 | |
---|
218 | nvars=`echo $listevars | wc -w | awk ' { print $1 } '` |
---|
219 | case $mask in |
---|
220 | NAtl) yax="North Atlantic " ;; |
---|
221 | Arct) yax="Arctic ocean" ;; |
---|
222 | circA) yax="Circum Antartica " ;; |
---|
223 | Sibe) yax="Siberia " ;; |
---|
224 | USA) yax="US Gr. Plains " ;; |
---|
225 | glob) yax="Global " ;; |
---|
226 | ter) yax="Land " ;; |
---|
227 | oce) yax="Ocean " ;; |
---|
228 | otrop) yax="Tropical ocean " ;; |
---|
229 | interH) yax="Inter Hemispheric " ;; |
---|
230 | etoa) yax="ETOA " ;; |
---|
231 | etow) yax="ETO - Weak " ;; |
---|
232 | etows) yax="subs - Weak " ;; |
---|
233 | circAa) yax="Circum Antartic Anom. " ;; |
---|
234 | NAtla) yax="Nort Atlantic Anom. " ;; |
---|
235 | conv) yax="Convective regimes " ;; |
---|
236 | weak) yax="Weak convection " ;; |
---|
237 | subs) yax="Subsidences " ;; |
---|
238 | PANET) yax="Pacific Trop. NE" ;; |
---|
239 | CONMAR) yax="Terres Cont. Mar." ;; |
---|
240 | OCEMAR) yax="Ocean Cont. Mar." |
---|
241 | esac |
---|
242 | cat <<...eod>| tmp.param |
---|
243 | g0 type Chart |
---|
244 | world -0.5, -35, $nvars, 35 |
---|
245 | yaxis label "$yax Fluxes (W/m2) " |
---|
246 | xaxis ticklabel font 0 |
---|
247 | xaxis ticklabel color 1 |
---|
248 | xaxis tick place both |
---|
249 | xaxis tick spec type both |
---|
250 | xaxis tick spec 11 |
---|
251 | xaxis ticklabel char size 1.3 |
---|
252 | xaxis ticklabel angle 90 |
---|
253 | yaxis tick major 10 |
---|
254 | yaxis tick minor ticks 1 |
---|
255 | legend 1.20, 0.8 |
---|
256 | ...eod |
---|
257 | |
---|
258 | ii=0 |
---|
259 | for var in $listevars ; do |
---|
260 | fact=`grep "^$var " descr | awk ' { print $2 } '` |
---|
261 | titre=`grep "^$var " descr | sed -e 's/'$var'//' -e 's/'$fact'//'` |
---|
262 | cat <<......eod>> tmp.param |
---|
263 | xaxis tick major $ii, $ii |
---|
264 | xaxis ticklabel $ii, "$titre" |
---|
265 | ......eod |
---|
266 | (( ii = $ii + 1 )) |
---|
267 | done |
---|
268 | |
---|
269 | |
---|
270 | prev="" |
---|
271 | ip=0 |
---|
272 | listex="" |
---|
273 | echo LISTESIMSY $listsimsy |
---|
274 | for simy in $listsimsy ; do |
---|
275 | sim=`echo $simy | sed -e 's/_[0-9][0-9][0-9][0-9]_[0-9][0-9][0-9][0-9]//'` |
---|
276 | years=`echo $simy | sed -e s/${sim}//` |
---|
277 | echo $sim |
---|
278 | SIM_DIR=$CMOR_DIR/$sim$years/METRICS |
---|
279 | ls $SIM_DIR |
---|
280 | OBS_DIR=$CMOR_DIR/OBS/METRICS |
---|
281 | mkdir -p $WRK_D/$mask |
---|
282 | if [ "$sim" = "$prev" ] ; then # Cas ou on a plusieurs decennies de la meme simu |
---|
283 | (( ip = $ip + 1 )) |
---|
284 | xmgr=$WRK_D/$mask/$sim.$ip |
---|
285 | listex="$listex $sim.$ip" |
---|
286 | else |
---|
287 | xmgr=$WRK_D/$mask/$sim |
---|
288 | ip=0 ; prev=$sim |
---|
289 | listex="$listex $sim" |
---|
290 | fi |
---|
291 | rm -f $xmgr ; touch $xmgr |
---|
292 | for var in $listevars ; do |
---|
293 | echo var $var |
---|
294 | fact=`grep "^$var " descr | awk ' { print $2 } '` |
---|
295 | paste $OBS_DIR/$mask $SIM_DIR/$mask | grep "^$var " | awk ' { if ( $4 == 999999 ) print 0 ; else print '$fact' * ( $4 - $2 ) } ' >> $xmgr |
---|
296 | done |
---|
297 | done |
---|
298 | |
---|
299 | |
---|
300 | |
---|
301 | size=`echo $listsims | wc -w | awk ' { print 3. / $1 } '` |
---|
302 | for ii in 0 1 2 3 4 5 6 7 8 9 10 11 12 ; do |
---|
303 | echo "s$ii type bar" >> tmp.param |
---|
304 | echo "s$ii symbol fill pattern 1" >> tmp.param |
---|
305 | echo "s$ii symbol size $size" >> tmp.param |
---|
306 | echo "s$ii line linestyle 0" >> tmp.param |
---|
307 | done |
---|
308 | |
---|
309 | cd $WRK_D/$mask |
---|
310 | pwd ; echo xmgrace $listex -param ../../../tmp.param -legend load -hardcopy -hdevice EPS -printfile tmp.eps |
---|
311 | xmgrace $listex -param ../../../tmp.param -legend load -hardcopy -hdevice EPS -printfile tmp.eps |
---|
312 | epstopdf tmp.eps |
---|
313 | OUT_D=$COMP_D/METRICS/$season ; mkdir -p $OUT_D |
---|
314 | \mv -f tmp.pdf $OUT_D/$mask.pdf ; convert -density 144 $OUT_D/$mask.pdf $OUT_D/$mask.png |
---|
315 | cd ../../.. |
---|
316 | |
---|
317 | done |
---|
318 | |
---|
319 | cp mask*png $OUT_D |
---|
320 | done |
---|