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