1 | #!/bin/bash |
---|
2 | # L. Fita, June 2016. Generic script to plot model outputs |
---|
3 | |
---|
4 | main='model_graphics.bash' |
---|
5 | |
---|
6 | function uploadvars() { |
---|
7 | # Function to upload variables to the system from an ASCII file as: |
---|
8 | # [varname] = [value] |
---|
9 | fileval=$1 |
---|
10 | errormsg='ERROR -- error -- ERROR -- error' |
---|
11 | |
---|
12 | if test ! -f ${fileval}; then |
---|
13 | echo ${errormsg} |
---|
14 | echo " "${fname}": file '"${fileval}"' does not exist!!" |
---|
15 | exit |
---|
16 | fi |
---|
17 | |
---|
18 | Nlin=`wc -l ${fileval} | awk '{print $1}'` |
---|
19 | |
---|
20 | ilin=1 |
---|
21 | while test ${ilin} -le ${Nlin}; do |
---|
22 | line=`head -n ${ilin} ${fileval} | tail -n 1` |
---|
23 | varname=`echo ${line} | tr '=' ' ' | awk '{print $1}'` |
---|
24 | value=`echo ${line} | tr '=' ' ' | awk '{print $2}'` |
---|
25 | Lvarname=`expr length ${varname}'0'` |
---|
26 | |
---|
27 | if test ${Lvarname} -gt 1 && test ! ${varname:0:1} = '#'; then |
---|
28 | export ${varname}=${value} |
---|
29 | fi |
---|
30 | ilin=`expr ${ilin} + 1` |
---|
31 | done |
---|
32 | } |
---|
33 | |
---|
34 | function isInlist() { |
---|
35 | # Function to check whether a value is in a list |
---|
36 | list=$1 |
---|
37 | value=$2 |
---|
38 | |
---|
39 | is=`echo ${list} | tr ':' '\n' | awk '{print "@"$1"@"}' | grep '@'${value}'@' | wc -w` |
---|
40 | if test ${is} -eq 1 |
---|
41 | then |
---|
42 | true |
---|
43 | else |
---|
44 | false |
---|
45 | fi |
---|
46 | } |
---|
47 | |
---|
48 | function ferrmsg() { |
---|
49 | # Function to exit and write an error message |
---|
50 | # comdexit: code number exit from the last execution |
---|
51 | # ref: script/reference from which error occurs |
---|
52 | # msg: message to write ('!' for spaces, '#' for end of line) |
---|
53 | comdexit=$1 |
---|
54 | ref=$2 |
---|
55 | msg=$3 |
---|
56 | |
---|
57 | if test ${comdexit} -ne 0; then |
---|
58 | echo "ERROR -- error -- ERROR -- error" |
---|
59 | echo " "${ref}": "$(echo ${msg} | tr '!' ' ' | tr '#' '\n')" !!" |
---|
60 | exit |
---|
61 | fi |
---|
62 | } |
---|
63 | |
---|
64 | function ferrmsgF() { |
---|
65 | # Function to exit and write an error message and remove a file |
---|
66 | # comdexit: code number exit from the last execution |
---|
67 | # ref: script/reference from which error occurs |
---|
68 | # msg: message to write ('!' for spaces, '#' for end of line) |
---|
69 | # FileName: name of the file to remove in case of error |
---|
70 | comdexit=`expr $1 + 0` |
---|
71 | ref=$2 |
---|
72 | msg=$3 |
---|
73 | FileName=$4 |
---|
74 | |
---|
75 | if test ${comdexit} -ne 0; then |
---|
76 | echo "ERROR -- error -- ERROR -- error" |
---|
77 | echo " "${ref}": "$(echo ${msg} | tr '!' ' ' | tr '\#' '\n')" !!" |
---|
78 | rm ${FileName} >& /dev/null |
---|
79 | exit |
---|
80 | fi |
---|
81 | } |
---|
82 | |
---|
83 | function WRF_toCF() { |
---|
84 | # Function to pass a WRF original file to CF-conventions |
---|
85 | # wrff= WRF file |
---|
86 | # wrfvl= WRF longitude var name (it might come from WPS!) |
---|
87 | # wrfvL= WRF latitude var name (it might come from WPS!) |
---|
88 | |
---|
89 | wrff=$1 |
---|
90 | wrfvl=$2 |
---|
91 | wrfvL=$3 |
---|
92 | |
---|
93 | fdims=`${pyHOME}/nc_var.py -o idims -f ${wrff} | grep alldims | tr '=' ' ' | \ |
---|
94 | awk '{print $3}'` |
---|
95 | |
---|
96 | CFdims='west_east@lon:south_north@lat:Time@time' |
---|
97 | CFds=`echo ${CFdims} | tr ':' ' '` |
---|
98 | |
---|
99 | pyout=`${pyHOME}/nc_var.py -o WRF_CFtime_creation -S 19491201000000,minutes \ |
---|
100 | -f ${wrff} -v time` |
---|
101 | pyn=$? |
---|
102 | Spyout=`echo ${pyout} | tr '\n' '#' | tr ' ' '!'` |
---|
103 | ferrmsgF ${pyn} ${fname} "python!'WRF_CFtime_creation'!failed"${Spyout} ${wrff} |
---|
104 | |
---|
105 | pyout=`${pyHOME}/nc_var.py -o WRF_CFlonlat_creation -v ${wrfvl},${wrfvL} \ |
---|
106 | -f ${wrff} -S lon,lat` |
---|
107 | pyn=$? |
---|
108 | Spyout=`echo ${pyout} | tr '\n' '#' | tr ' ' '!'` |
---|
109 | ferrmsgF ${pyn} ${fname} "python!'WRF_CFlonlat_creation'!failed"${Spyout} ${wrff} |
---|
110 | |
---|
111 | for CFd in ${CFds}; do |
---|
112 | cd=`echo ${CFd} | tr '@' ' ' | awk '{print $2}'` |
---|
113 | wd=`echo ${CFd} | tr '@' ' ' | awk '{print $1}'` |
---|
114 | if $(isInlist ${fdims} ${wd}); then |
---|
115 | pyout=`${pyHOME}/nc_var.py -o chdimname -f ${wrff} -S ${wd}':'${cd}` |
---|
116 | pyn=$? |
---|
117 | Spyout=`echo ${pyout} | tr '\n' '#' | tr ' ' '!'` |
---|
118 | ferrmsgF ${pyn} ${fname} "python!'chdimname'!'"${wd}"'!failed#"${Spyout} ${wrff} |
---|
119 | fi |
---|
120 | done |
---|
121 | |
---|
122 | # CF attributes |
---|
123 | dimvars='lon:lat:time:Times' |
---|
124 | |
---|
125 | allfilevars=`python ${pyHOME}/nc_var.py -o ivars -f ${wrff} | grep allvars | awk '{print $3}'` |
---|
126 | allvs=`echo ${allfilevars} | tr ':' ' '` |
---|
127 | for vn in ${allvs}; do |
---|
128 | if ! $(isInlist ${dimvars} ${vn}); then |
---|
129 | varattrs=`python ${pyHOME}/generic.py -o variables_values -S ${vn}` |
---|
130 | stn=`echo ${varattrs} | tr ':' ' ' | awk '{print $2}'` |
---|
131 | lon=`echo ${varattrs} | tr ':' ' ' | awk '{print $5}' | tr '|' '!'` |
---|
132 | un=`echo ${varattrs} | tr ':' ' ' | awk '{print $6}' | tr '|' '!'` |
---|
133 | |
---|
134 | pyout=`python ${pyHOME}/nc_var.py -o varaddattr -f ${wrff} -S 'standard_name|'${stn} -v ${vn}` |
---|
135 | pyn=$? |
---|
136 | Spyout=`echo ${pyout} | tr '\n' '#' | tr ' ' '!'` |
---|
137 | ferrmsgF ${pyn} ${fname} "python!'varaddattr'!'standard_name'!failed#"${Spyout} ${wrff} |
---|
138 | pyout=`python ${pyHOME}/nc_var.py -o varaddattr -f ${wrff} -S 'long_name|'${lon} -v ${vn}` |
---|
139 | pyn=$? |
---|
140 | Spyout=`echo ${pyout} | tr '\n' '#' | tr ' ' '!'` |
---|
141 | ferrmsgF ${pyn} ${fname} "python!'varaddattr'!'long_name'!failed#"${Spyout} ${wrff} |
---|
142 | pyout=`python ${pyHOME}/nc_var.py -o varaddattr -f ${wrff} -S 'units|'${un} -v ${vn}` |
---|
143 | pyn=$? |
---|
144 | Spyout=`echo ${pyout} | tr '\n' '#' | tr ' ' '!'` |
---|
145 | ferrmsgF ${pyn} ${fname} "python!'varaddattr'!'units'!failed#"${Spyout} ${wrff} |
---|
146 | fi |
---|
147 | done |
---|
148 | } |
---|
149 | |
---|
150 | function compute_variable() { |
---|
151 | # Function to compute a variable |
---|
152 | # idir: directory with the input files |
---|
153 | # usefiles: ',' list of files as [headerf]@[file1]|...|[fileN] |
---|
154 | # odir: directory to write the output files |
---|
155 | # cvar: [CFvarn]|[varkind]|[headerf]|[varmod]|[vardiag] |
---|
156 | # [CFvarn]: CF name of the variable |
---|
157 | # [vark]: kind of variable: |
---|
158 | # acc: temporal accumulated values |
---|
159 | # diff: differences between models |
---|
160 | # direct: no statistics |
---|
161 | # Lsec: latitudinal section (latitudinal value must be given, [var]@[lat]) |
---|
162 | # lsec: longitudinal section (longitudinal value must be given, [var]@[lat]) |
---|
163 | # lmean: longitudinal mean values |
---|
164 | # pinterp: pressure interpolation (to the given $plevels) |
---|
165 | # tmean: temporal mean values |
---|
166 | # zsum: vertical aggregated values |
---|
167 | # [headerf]: header of the files to use |
---|
168 | # [modvar]: variable to use from the file |
---|
169 | # [diagvar]: variable computed from the diagnostics (diagnostic.py) |
---|
170 | # mdim: name of the dimensions in the model |
---|
171 | # mvdim: name of the vaariable-dimensions in the model |
---|
172 | # scratch: whether is has to be done from the scratch or not |
---|
173 | fname='compute_variable' |
---|
174 | idir=$1 |
---|
175 | usefiles=$2 |
---|
176 | odir=$3 |
---|
177 | cvar=$4 |
---|
178 | mdim=$5 |
---|
179 | mvdim=$6 |
---|
180 | scratch=$7 |
---|
181 | |
---|
182 | CFvarn=`echo ${cvar} | tr '|' ' ' | awk '{print $1}'` |
---|
183 | vark=`echo ${cvar} | tr '|' ' ' | awk '{print $2}'` |
---|
184 | headerf=`echo ${cvar} | tr '|' ' ' | awk '{print $3}'` |
---|
185 | modvar=`echo ${cvar} | tr '|' ' ' | awk '{print $4}'` |
---|
186 | diagvar=`echo ${cvar} | tr '|' ' ' | awk '{print $5}'` |
---|
187 | |
---|
188 | cfiles=`echo ${usefiles} | tr ',' '\n' | grep ${headerf} | tr '|' ' ' | \ |
---|
189 | awk '{print $2}' | tr '@' ' '` |
---|
190 | |
---|
191 | # dimensions |
---|
192 | dnx=`echo ${mdim} | tr ',' ' ' | awk '{print $1}'` |
---|
193 | dny=`echo ${mdim} | tr ',' ' ' | awk '{print $2}'` |
---|
194 | # var-dimensions |
---|
195 | vdnx=`echo ${mvdim} | tr ',' ' ' | awk '{print $1}'` |
---|
196 | vdny=`echo ${mvdim} | tr ',' ' ' | awk '{print $2}'` |
---|
197 | |
---|
198 | cd ${odir} |
---|
199 | |
---|
200 | # Computing separately and then joinging for all files |
---|
201 | Ntotfiles=`echo ${cfiles} | wc -w | awk '{print $1}'` |
---|
202 | ifile=1 |
---|
203 | |
---|
204 | for cf in ${cfiles}; do |
---|
205 | ifS=`printf "%0${Ntotfiles}d" ${ifile}` |
---|
206 | |
---|
207 | # Computing variable |
---|
208 | # Changing file head when it is a pressure-interpolated variable |
---|
209 | if test ${vark} == 'pinterp'; then |
---|
210 | fhead=${headerf}p |
---|
211 | else |
---|
212 | fhead=${headerf} |
---|
213 | fi |
---|
214 | |
---|
215 | filen=${odir}/${CFvarn}_${fhead}_${ifile}-${Ntotfiles}.nc |
---|
216 | if ${scratch}; then |
---|
217 | rm ${filen} >& /dev/null |
---|
218 | rm ${odir}/${CFvarn}_${fhead}.nc >& /dev/null |
---|
219 | fi |
---|
220 | |
---|
221 | if test ! -f ${filen} && test ! -f ${odir}/${CFvarn}_${fhead}.nc; then |
---|
222 | if test ! ${modvar} = 'None'; then |
---|
223 | # model variable |
---|
224 | values=${modvar}',0,-1,-1' |
---|
225 | vs=${modvar},${vdnx},${vdny},${vdnz},${vdnt} |
---|
226 | pyout=`${pyHOME}/nc_var.py -f ${cf} -o DataSetSection_multivars -v ${vs} \ |
---|
227 | -S ${values} | grep succesfull | awk '{print $6}' | tr '"' ' '` |
---|
228 | pyn=$? |
---|
229 | Spyout=`echo ${pyout} | tr '\n' '#' | tr ' ' '!'` |
---|
230 | ferrmsg ${pyn} ${fname} "python!'DataSetSection_multivars'!failed"${Spyout} |
---|
231 | mv ${pyout} ${filen} |
---|
232 | |
---|
233 | pyout=`${pyHOME}/nc_var.py -f ${filen} -o chvarname -v ${modvar} -S ${CFvarn}` |
---|
234 | pyn=$? |
---|
235 | Spyout=`echo ${pyout} | tr '\n' '#' | tr ' ' '!'` |
---|
236 | ferrmsgF ${pyn} ${fname} "python!'chvarname'!failed"${Spyout} ${filen} |
---|
237 | else |
---|
238 | # diagnostic variable |
---|
239 | dims=${dnt}@${vdnt},${dnz}@${vdnz},${dny}@${vdny},${dnx}@${vdnx} |
---|
240 | diagn=`echo ${diagvar} | tr ':' '\n' | head -n 1` |
---|
241 | Ndiagvars=`echo ${diagvar} | tr ':' ' ' | wc -w | awk '{print $1}'` |
---|
242 | idiagv=2 |
---|
243 | diagc='' |
---|
244 | while test ${idiagv} -le ${Ndiagvars}; do |
---|
245 | diag1=`echo ${diagvar} | tr ':' '\n' | head -n ${idiagv} | tail -n 1` |
---|
246 | if test ${idiagv} -eq 2; then |
---|
247 | diagc=${diag1} |
---|
248 | else |
---|
249 | diagc=${diagc}'@'${diag1} |
---|
250 | fi |
---|
251 | idiagv=`expr ${idiagv} + 1` |
---|
252 | done |
---|
253 | |
---|
254 | pyout=`python ${pyHOME}/diagnostics.py -f ${cf} -d ${dims} -v ${diagn}'|'${diagc}` |
---|
255 | pyn=$? |
---|
256 | Spyout=`echo ${pyout} | tr '\n' '#' | tr ' ' '!'` |
---|
257 | ferrmsg ${pyn} ${fname} "python!'diagnostics'!failed#"${Spyout} |
---|
258 | mv diagnostics.nc ${filen} |
---|
259 | fi |
---|
260 | |
---|
261 | # adding CF lon,lat,time in WRF files |
---|
262 | if test ${headerf:0:3} = 'wrf'; then |
---|
263 | WRF_toCF ${filen} ${vdnx} ${vdny} |
---|
264 | fi |
---|
265 | # Attaching necessary variables for the pressure interpolation |
---|
266 | if test ${vark} == 'pinterp'; then |
---|
267 | requiredinterpvars='P:PB:PSFC:PH:PHB:HGT:T:QVAPOR:' |
---|
268 | rqvs=`echo ${requiredinterpvars} | tr ':' ' '` |
---|
269 | echo " "${fname}": adding variables: "${rqvs}" to allow pressure interpolation" |
---|
270 | for rqv in ${rqvs}; do |
---|
271 | pyout=`${pyHOME}/nc_var.py -o fvaradd -S ${cf},${rqv} -f ${filen}` |
---|
272 | pyn=$? |
---|
273 | Spyout=`echo ${pyout} | tr '\n' '#' | tr ' ' '!'` |
---|
274 | ferrmsgF ${pyn} ${fname} "python!'fvaradd'!failed#"${Spyout} ${filen} |
---|
275 | done |
---|
276 | fi |
---|
277 | fi |
---|
278 | |
---|
279 | |
---|
280 | ifile=`expr ${ifile} + 1` |
---|
281 | # End of files |
---|
282 | done |
---|
283 | |
---|
284 | # Joining variable files |
---|
285 | filen=${odir}/${CFvarn}_${fhead}.nc |
---|
286 | if ${scratch}; then rm ${filen} >& /dev/null; fi |
---|
287 | |
---|
288 | if test ! -f ${filen}; then |
---|
289 | pyout=`python ${pyHOME}/nc_var.py -f ${CFvarn}'_'${fhead}'_,-,.nc' \ |
---|
290 | -o netcdf_fold_concatenation_HMT -S ./,time -v all` |
---|
291 | pyn=$? |
---|
292 | Spyout=`echo ${pyout} | tr '\n' '#' | tr ' ' '!'` |
---|
293 | ferrmsg ${pyn} ${fname} "python!'netcdf_fold_concatenation_HMT'!failed#"${Spyout} |
---|
294 | mv netcdf_fold_concatenated_HMT.nc ${filen} |
---|
295 | if test -f ${filen}; then |
---|
296 | rm ${CFvarn}_${fhead}_*-*.nc |
---|
297 | fi |
---|
298 | fi |
---|
299 | } |
---|
300 | |
---|
301 | function compute_statistics(){ |
---|
302 | # Function to compute different statistics |
---|
303 | # idir: directory with the input files |
---|
304 | # usefiles: ',' list of files to use [file1],...,[fileN] |
---|
305 | # odir: directory to write the output files |
---|
306 | # cvar: [CFvarn]|[varkind]|[headerf]|[varmod]|[vardiag] |
---|
307 | # [CFvarn]: CF name of the variable |
---|
308 | # [vark]: kind of variable: |
---|
309 | # acc: temporal accumulated values |
---|
310 | # diff: differences between models |
---|
311 | # direct: no statistics |
---|
312 | # Lmean: latitudinal mean values |
---|
313 | # Lsec: latitudinal section (latitudinal value must be given, [var]@[lat]) |
---|
314 | # lmean: longitudinal mean values |
---|
315 | # lsec: longitudinal section (longitudinal value must be given, [var]@[lat]) |
---|
316 | # pinterp: pressure interpolation (to the given $plevels) |
---|
317 | # tmean: temporal mean values |
---|
318 | # xmean: x-axis mean values |
---|
319 | # ymean: y-axis mean values |
---|
320 | # zsum: vertical aggregated values |
---|
321 | # [headerf]: header of the files to use |
---|
322 | # [modvar]: variable to use from the file |
---|
323 | # [diagvar]: variable computed from the diagnostics (diagnostic.py) |
---|
324 | # mdim: name of the dimensions in the model |
---|
325 | # mvdim: name of the vaariable-dimensions in the model |
---|
326 | # scratch: whether is has to be done from the scratch or not |
---|
327 | fname='compute_statistics' |
---|
328 | |
---|
329 | idir=$1 |
---|
330 | usefiles=$2 |
---|
331 | odir=$3 |
---|
332 | cvar=$4 |
---|
333 | mdim=$5 |
---|
334 | mvdim=$6 |
---|
335 | scratch=$7 |
---|
336 | |
---|
337 | CFvarn=`echo ${cvar} | tr '|' ' ' | awk '{print $1}'` |
---|
338 | vark=`echo ${cvar} | tr '|' ' ' | awk '{print $2}'` |
---|
339 | headerf=`echo ${cvar} | tr '|' ' ' | awk '{print $3}'` |
---|
340 | modvar=`echo ${cvar} | tr '|' ' ' | awk '{print $4}'` |
---|
341 | diagvar=`echo ${cvar} | tr '|' ' ' | awk '{print $5}'` |
---|
342 | |
---|
343 | cfiles=`echo ${usefiles} | tr ',' ' '` |
---|
344 | |
---|
345 | # dimensions |
---|
346 | dnx=`echo ${mdim} | tr ',' ' ' | awk '{print $1}'` |
---|
347 | dny=`echo ${mdim} | tr ',' ' ' | awk '{print $2}'` |
---|
348 | # var-dimensions |
---|
349 | vdnx=`echo ${mvdim} | tr ',' ' ' | awk '{print $1}'` |
---|
350 | vdny=`echo ${mvdim} | tr ',' ' ' | awk '{print $2}'` |
---|
351 | |
---|
352 | cd ${odir} |
---|
353 | |
---|
354 | if test ${vark} == 'pinterp'; then |
---|
355 | fhead=${headerf}p |
---|
356 | else |
---|
357 | fhead=${headerf} |
---|
358 | fi |
---|
359 | filen=${CFvarn}_${fhead}_${vark}.nc |
---|
360 | if ${scratch}; then rm ${filen} >& /dev/null; fi |
---|
361 | |
---|
362 | if test ! -f ${filen}; then |
---|
363 | # Computing stats |
---|
364 | case ${vark} in |
---|
365 | # temporal accumulated values |
---|
366 | 'acc') |
---|
367 | echo " "${fname}": kind '"${vark}"' not ready !!" |
---|
368 | exit |
---|
369 | ;; |
---|
370 | # differences between models |
---|
371 | 'diff') |
---|
372 | echo " "${fname}": kind '"${vark}"' not ready !!" |
---|
373 | exit |
---|
374 | ;; |
---|
375 | # no statistics |
---|
376 | 'direct') |
---|
377 | cp ${cfiles} ${filen} |
---|
378 | ;; |
---|
379 | # latitudinal mean values |
---|
380 | 'Lmean') |
---|
381 | echo " "${fname}": kind '"${vark}"' not ready !!" |
---|
382 | exit |
---|
383 | ;; |
---|
384 | # latitudinal section (latitudinal value must be given, [var]@[lat]) |
---|
385 | 'Lsec') |
---|
386 | echo " "${fname}": kind '"${vark}"' not ready !!" |
---|
387 | exit |
---|
388 | ;; |
---|
389 | # longitudinal section (longitudinal value must be given, [var]@[lat]) |
---|
390 | 'lsec') |
---|
391 | echo " "${fname}": kind '"${vark}"' not ready !!" |
---|
392 | exit |
---|
393 | ;; |
---|
394 | # longitudinal mean values |
---|
395 | 'lmean') |
---|
396 | echo " "${fname}": kind '"${vark}"' not ready !!" |
---|
397 | exit |
---|
398 | ;; |
---|
399 | # pinterp: pressure interpolation (to the given $plevels) |
---|
400 | 'pinterp') |
---|
401 | vals=${plevels}',1,1' |
---|
402 | echo "python $pyHOME/nc_var.py -o pinterp -f ${cfiles} -S ${vals} -v ${CFvarn}" |
---|
403 | pyout=`python $pyHOME/nc_var.py -o pinterp -f ${cfiles} -S ${vals} \ |
---|
404 | -v ${CFvarn}` |
---|
405 | pyn=$? |
---|
406 | Spyout=`echo ${pyout} | tr '\n' '#' | tr ' ' '!'` |
---|
407 | ferrmsg ${pyn} ${fname} "python!'pinterp'!failed#"${Spyout} |
---|
408 | cp pinterp.nc ${filen} |
---|
409 | |
---|
410 | # adding CF lon,lat,time in WRF files |
---|
411 | if test ${headerf:0:3} = 'wrf'; then |
---|
412 | WRF_toCF ${filen} ${vdnx} ${vdny} |
---|
413 | fi |
---|
414 | ;; |
---|
415 | # temporal mean values |
---|
416 | 'tmean') |
---|
417 | vals='time|-1,time,mean,lon:lat:'${vdnz}':time' |
---|
418 | dims='time@time,'${dnz}'@'${vdnz}',lat@lat,lon@lon' |
---|
419 | |
---|
420 | pyout=`python ${pyHOME}/nc_var.py -o file_oper_alongdims -S ${vals} \ |
---|
421 | -f ${cfiles} -v ${CFvarn}` |
---|
422 | pyn=$? |
---|
423 | Spyout=`echo ${pyout} | tr '\n' '#' | tr ' ' '!'` |
---|
424 | ferrmsg ${pyn} ${fname} "python!'file_oper_alongdims'!'tmean'!failed#"${Spyout} |
---|
425 | mv file_oper_alongdims_mean.nc ${filen} |
---|
426 | ;; |
---|
427 | # x-axis mean values |
---|
428 | 'xmean') |
---|
429 | vals='lon|-1,lon,mean,lon:lat:'${vdnz}':time' |
---|
430 | dims='time@time,'${dnz}'@'${vdnz}',lat@lat,lon@lon' |
---|
431 | echo "python ${pyHOME}/nc_var.py -o file_oper_alongdims -S ${vals} -f ${cfiles} -v ${CFvarn}" |
---|
432 | |
---|
433 | pyout=`python ${pyHOME}/nc_var.py -o file_oper_alongdims -S ${vals} \ |
---|
434 | -f ${cfiles} -v ${CFvarn}` |
---|
435 | pyn=$? |
---|
436 | Spyout=`echo ${pyout} | tr '\n' '#' | tr ' ' '!'` |
---|
437 | ferrmsg ${pyn} ${fname} "python!'file_oper_alongdims'!'tmean'!failed#"${Spyout} |
---|
438 | mv file_oper_alongdims_mean.nc ${filen} |
---|
439 | ;; |
---|
440 | # y-axis mean values |
---|
441 | 'ymean') |
---|
442 | vals='lat|-1,lat,mean,lon:lat:'${vdnz}':time' |
---|
443 | dims='time@time,'${dnz}'@'${vdnz}',lat@lat,lon@lon' |
---|
444 | echo "python ${pyHOME}/nc_var.py -o file_oper_alongdims -S ${vals} -f ${cfiles} -v ${CFvarn}" |
---|
445 | |
---|
446 | pyout=`python ${pyHOME}/nc_var.py -o file_oper_alongdims -S ${vals} \ |
---|
447 | -f ${cfiles} -v ${CFvarn}` |
---|
448 | pyn=$? |
---|
449 | Spyout=`echo ${pyout} | tr '\n' '#' | tr ' ' '!'` |
---|
450 | ferrmsg ${pyn} ${fname} "python!'file_oper_alongdims'!'tmean'!failed#"${Spyout} |
---|
451 | mv file_oper_alongdims_mean.nc ${filen} |
---|
452 | ;; |
---|
453 | # vertical aggregated values |
---|
454 | 'zsum') |
---|
455 | echo " "${fname}": kind '"${vark}"' not ready !!" |
---|
456 | exit |
---|
457 | ;; |
---|
458 | *) |
---|
459 | echo ${errmsg} |
---|
460 | echo " "${fname}": kind '"${vark}"' not ready !!" |
---|
461 | exit |
---|
462 | ;; |
---|
463 | esac |
---|
464 | fi |
---|
465 | # exit |
---|
466 | # LLUIS |
---|
467 | } |
---|
468 | |
---|
469 | ####### ####### |
---|
470 | ## MAIN |
---|
471 | ####### |
---|
472 | rootsh=`pwd` |
---|
473 | |
---|
474 | # Uploading environment |
---|
475 | uploadvars model_graphics.dat |
---|
476 | |
---|
477 | if test ${scratch} = 'true'; then |
---|
478 | scratch=true |
---|
479 | echo ${warnmsg} |
---|
480 | echo " "${main}": starting from the SCRATCH !!" |
---|
481 | echo " 10 seconds left!!" |
---|
482 | sleep 10 |
---|
483 | else |
---|
484 | scratch=false |
---|
485 | fi |
---|
486 | |
---|
487 | if test ${debug} = 'true'; then |
---|
488 | dbg=true |
---|
489 | else |
---|
490 | dbg=false |
---|
491 | fi |
---|
492 | |
---|
493 | timeval='tstep' |
---|
494 | zval='null' |
---|
495 | dimval='lon,lat,pressure,time' |
---|
496 | |
---|
497 | compute=0 |
---|
498 | computetlon=false |
---|
499 | plot=false |
---|
500 | single2Dplot=false |
---|
501 | lonZsec=false |
---|
502 | differences=true |
---|
503 | |
---|
504 | combosfile=${HOMEpy}/diagnostics.inf |
---|
505 | |
---|
506 | ####### ###### ##### #### ### ## # |
---|
507 | |
---|
508 | mods=`echo ${models} | tr ':' ' '` |
---|
509 | varks=`echo ${varkinds} | tr ':' ' '` |
---|
510 | |
---|
511 | # Models loop |
---|
512 | ## |
---|
513 | for mod in ${mods}; do |
---|
514 | case ${mod} in |
---|
515 | 'WRF') |
---|
516 | exps=`echo ${WRFexps} | tr ':' ' '` |
---|
517 | fheaders=`echo ${WRFheaders} | tr ':' ' '` |
---|
518 | ;; |
---|
519 | 'LMDZ') |
---|
520 | exps=`echo ${LMDZexps} | tr ':' ' '` |
---|
521 | fheaders=`echo ${LMDZheaders} | tr ':' ' '` |
---|
522 | ;; |
---|
523 | 'WRF_LMDZ') |
---|
524 | exps=`echo ${WRF_LMDZexps} | tr ':' ' '` |
---|
525 | fheaders=`echo ${WRF_LMDZheaders} | tr ':' ' '` |
---|
526 | ;; |
---|
527 | '*') |
---|
528 | echo ${errmsg} |
---|
529 | echo " "${main}": model '"${mod}"' not ready!!" |
---|
530 | exit |
---|
531 | ;; |
---|
532 | esac |
---|
533 | |
---|
534 | modinf=`$pyHOME/nc_var.py -o model_characteristics -f None -S ${mod} | \ |
---|
535 | grep singleline | awk '{print $2}'` |
---|
536 | ferrmsg $? $main "python!'model_characteristics'!failed" |
---|
537 | dnx=`echo ${modinf} | tr ';' '\n' | grep dimxn | tr '=' ' ' | awk '{print $2}'` |
---|
538 | dny=`echo ${modinf} | tr ';' '\n' | grep dimyn | tr '=' ' ' | awk '{print $2}'` |
---|
539 | dnz=`echo ${modinf} | tr ';' '\n' | grep dimzn | tr '=' ' ' | awk '{print $2}'` |
---|
540 | dnt=`echo ${modinf} | tr ';' '\n' | grep dimtn | tr '=' ' ' | awk '{print $2}'` |
---|
541 | vdnx=`echo ${modinf} | tr ';' '\n' | grep vardxn | tr '=' ' ' | awk '{print $2}'` |
---|
542 | vdny=`echo ${modinf} | tr ';' '\n' | grep vardyn | tr '=' ' ' | awk '{print $2}'` |
---|
543 | vdnz=`echo ${modinf} | tr ';' '\n' | grep vardzn | tr '=' ' ' | awk '{print $2}'` |
---|
544 | vdnt=`echo ${modinf} | tr ';' '\n' | grep vardtn | tr '=' ' ' | awk '{print $2}'` |
---|
545 | echo ${mod} |
---|
546 | echo " dims: "${dnx}", "${dny}", "${dnz}", "${dnt} |
---|
547 | echo " var dims: "${vdnx}", "${vdny}", "${vdnz}", "${vdnt} |
---|
548 | moddims=${dnx}','${dny}','${dnz}','${dnt} |
---|
549 | modvdims=${vdnx}','${vdny}','${vdnz}','${vdnt} |
---|
550 | |
---|
551 | # Experiments loop |
---|
552 | ## |
---|
553 | for exp in ${exps}; do |
---|
554 | echo " "${exp}"..." |
---|
555 | iwdir=${ifold}/${mod}/${exp} |
---|
556 | |
---|
557 | # Does input folder exist? |
---|
558 | if test ! -d ${iwdir}; then |
---|
559 | echo ${errmsg} |
---|
560 | echo " "${main}": folder '"${iwdir}"' does not exist !!" |
---|
561 | exit |
---|
562 | fi |
---|
563 | |
---|
564 | owdir=${ofold}/${mod}/${exp} |
---|
565 | mkdir -p ${owdir} |
---|
566 | |
---|
567 | # Need to pass to analyze all the data? |
---|
568 | if ${scratch}; then rm ${owdir}/varcompute.inf >& /dev/null; fi |
---|
569 | if test ! -f ${owdir}/varcompute.inf; then |
---|
570 | |
---|
571 | # Does input folder has header files? |
---|
572 | cd ${iwdir} |
---|
573 | files='' |
---|
574 | testfiles='' |
---|
575 | ih=1 |
---|
576 | for fh in ${fheaders}; do |
---|
577 | if ${scratch}; then rm ${owdir}/*_${fh}*.nc >& /dev/null; fi |
---|
578 | |
---|
579 | files1h=`ls -1 ${fh}* | tr '\n' '@'` |
---|
580 | Lfiles1h=`expr length ${files1h}'0'` |
---|
581 | if test ${Lfiles1h} -lt 2; then |
---|
582 | ferrmsg 1 $main "folder!:!"${iwdir}"!does!not!contain!files!"${fh}"*" |
---|
583 | fi |
---|
584 | testfiles1h=`ls -1 ${fh}* | head -n 1` |
---|
585 | if test ${ih} -eq 1; then |
---|
586 | files=${fh}'|'${files1h} |
---|
587 | testfiles=${fh}'|'${testfiles1h} |
---|
588 | else |
---|
589 | files=${files}','${fh}'|'${files1h} |
---|
590 | testfiles=${testfiles}'@'${fh}'|'${testfiles1h} |
---|
591 | fi |
---|
592 | ih=`expr ${ih} + 1` |
---|
593 | done |
---|
594 | testfs=`echo ${testfiles} | tr '@' ' '` |
---|
595 | cd ${rootsh} |
---|
596 | |
---|
597 | # Kind variables loop |
---|
598 | ## |
---|
599 | ik=1 |
---|
600 | itotv=1 |
---|
601 | for vark in ${varks}; do |
---|
602 | echo " "${vark}" ..." |
---|
603 | case ${vark} in |
---|
604 | 'acc') |
---|
605 | varvks=${varacc} |
---|
606 | ;; |
---|
607 | 'diff') |
---|
608 | varvks=${vardiff} |
---|
609 | ;; |
---|
610 | 'direct') |
---|
611 | varvks=${vardirect} |
---|
612 | ;; |
---|
613 | 'Lmean') |
---|
614 | varvks=${varLmean} |
---|
615 | ;; |
---|
616 | 'Lsec') |
---|
617 | varvks=${varLsec} |
---|
618 | ;; |
---|
619 | 'lmean') |
---|
620 | varvks=${varlmean} |
---|
621 | ;; |
---|
622 | 'lsec') |
---|
623 | varvks=${varlsec} |
---|
624 | ;; |
---|
625 | 'pinterp') |
---|
626 | varvks=${varpinterp} |
---|
627 | ;; |
---|
628 | 'tmean') |
---|
629 | varvks=${vartmean} |
---|
630 | ;; |
---|
631 | 'xmean') |
---|
632 | varvks=${varxmean} |
---|
633 | ;; |
---|
634 | 'ymean') |
---|
635 | varvks=${varymean} |
---|
636 | ;; |
---|
637 | 'zsum') |
---|
638 | varvks=${varzsum} |
---|
639 | ;; |
---|
640 | '*') |
---|
641 | echo ${errmsg} |
---|
642 | echo " "${main}": variable kind '"${vark}"' not ready!!" |
---|
643 | exit |
---|
644 | ;; |
---|
645 | esac |
---|
646 | |
---|
647 | # Do we have variables for this kind? |
---|
648 | Lvarvks=`expr length ${varvks}'0'` |
---|
649 | if test ${Lvarvks} -lt 2; then |
---|
650 | ferrmsg 1 ${main} "variable!kind!"${vark}"!without!variables" |
---|
651 | fi |
---|
652 | if test ${ik} -eq 1; then |
---|
653 | allvars=${varvks} |
---|
654 | else |
---|
655 | allvars=${allvars}':'${varvks} |
---|
656 | fi |
---|
657 | ik=`expr ${ik} + 1` |
---|
658 | vars=`echo ${varvks} | tr ':' ' '` |
---|
659 | |
---|
660 | # Variables loop |
---|
661 | ## |
---|
662 | iv=1 |
---|
663 | for var in ${vars}; do |
---|
664 | echo " "${var} |
---|
665 | # How to copmute it? |
---|
666 | cancompute=true |
---|
667 | for ftest in ${testfs}; do |
---|
668 | headerf=`echo ${ftest} | tr '|' ' ' | awk '{print $1}'` |
---|
669 | filen=`echo ${ftest} | tr '|' ' ' | awk '{print $2}'` |
---|
670 | compute=`${pyHOME}/nc_var.py -o computevar_model -f ${iwdir}/${filen} \ |
---|
671 | -S ${var}` |
---|
672 | ferrmsg $? ${main} "python!'computevar_model'!failed!#"$(echo ${compute} | \ |
---|
673 | tr ' ' '!') |
---|
674 | varmod=`echo ${compute} | tr ' ' '#' | tr '|' ' ' | awk '{print $2}' | \ |
---|
675 | tr '@' ' ' | awk '{print $2}' | tr '=' ' ' | awk '{print $2}'` |
---|
676 | vardiag=`echo ${compute} | tr ' ' '#' | tr '|' ' ' | awk '{print $2}' | \ |
---|
677 | tr '@' ' ' | awk '{print $3}' | tr '=' ' ' | awk '{print $2}'` |
---|
678 | echo " "${var}" mod:"${varmod}" diag: "${vardiag} |
---|
679 | if test ${varmod} = 'None' && test ${vardiag} = 'None'; then |
---|
680 | cancompute=false |
---|
681 | else |
---|
682 | cancompute=true |
---|
683 | # Should be considered that variable can also be computed by both ways? |
---|
684 | break |
---|
685 | fi |
---|
686 | done |
---|
687 | if ! ${cancompute}; then |
---|
688 | msg="there!is!no!way!to!compute!'"${var}"'!for!model!"${mod} |
---|
689 | # Too extrict! |
---|
690 | # ferrmsg 1 ${main} ${msg} |
---|
691 | echo ${warnmsg} |
---|
692 | echo $(echo $msg | tr '!' ' ') |
---|
693 | fi |
---|
694 | |
---|
695 | # A ';' list 'varcompute' it is created for each variable giving: |
---|
696 | # [var]|[vark]|[headerf][varmod]|[vardiag] |
---|
697 | # This list will be used to compute a new file for each variable |
---|
698 | varcomp=${var}'|'${vark}'|'${headerf}'|'${varmod}'|'${vardiag} |
---|
699 | if test ${itotv} -eq 1; then |
---|
700 | varcompute=${varcomp} |
---|
701 | else |
---|
702 | varcompute=${varcompute}';'${varcomp} |
---|
703 | fi |
---|
704 | |
---|
705 | iv=`expr ${iv} + 1` |
---|
706 | itotv=`expr ${itotv} + 1` |
---|
707 | |
---|
708 | # end loop of variables |
---|
709 | done |
---|
710 | # end of kind of variables |
---|
711 | done |
---|
712 | |
---|
713 | # Outwritting the varcompute to avoid next time (if it is not scratch!) |
---|
714 | cat << EOF > ${owdir}/varcompute.inf |
---|
715 | files: ${files} |
---|
716 | varcompute: ${varcompute} |
---|
717 | itotv: ${itotv} |
---|
718 | EOF |
---|
719 | else |
---|
720 | echo $warnmsg |
---|
721 | echo " "${main}": getting already data information from the experiment!" |
---|
722 | files=`cat ${owdir}/varcompute.inf | grep files | awk '{print $2}'` |
---|
723 | varcompute=`cat ${owdir}/varcompute.inf | grep varcompute | awk '{print $2}'` |
---|
724 | itotv=`cat ${owdir}/varcompute.inf | grep itotv | awk '{print $2}'` |
---|
725 | # End of avoiding to repeat all the experiment search |
---|
726 | fi |
---|
727 | |
---|
728 | echo " For experiment '"${exp}"' is required to compute: "${itotv}" variables" |
---|
729 | # Computing files for each variable |
---|
730 | ## |
---|
731 | echo " Computing all variables ..." |
---|
732 | cd $owdir |
---|
733 | ic=1 |
---|
734 | isc=1 |
---|
735 | cvars=`echo ${varcompute} | tr ';' ' '` |
---|
736 | for cvar in ${cvars}; do |
---|
737 | CFv=`echo ${cvar} | tr '|' ' ' | awk '{print $1}'` |
---|
738 | vark=`echo ${cvar} | tr '|' ' ' | awk '{print $2}'` |
---|
739 | fileh=`echo ${cvar} | tr '|' ' ' | awk '{print $3}'` |
---|
740 | modv=`echo ${cvar} | tr '|' ' ' | awk '{print $4}'` |
---|
741 | diagv=`echo ${cvar} | tr '|' ' ' | awk '{print $5}'` |
---|
742 | if ${dbg}; then echo " "${CFv}"; "${modv}" "${diagv}; fi |
---|
743 | |
---|
744 | if test ! ${modv} = 'None' || test ! ${diagv} = 'None'; then |
---|
745 | compute_variable ${iwdir} ${files} ${owdir} ${cvar} ${moddims} ${modvdims} \ |
---|
746 | ${scratch} |
---|
747 | ic=`expr ${ic} + 1` |
---|
748 | |
---|
749 | if test ! ${vark} = 'diff'; then |
---|
750 | if test ${vark} = 'pinterp'; then |
---|
751 | fhead=${fileh}'p' |
---|
752 | else |
---|
753 | fhead=${fileh} |
---|
754 | fi |
---|
755 | compute_statistics ${iwdir} ${CFv}_${fhead}.nc ${owdir} ${cvar} \ |
---|
756 | ${moddims} ${modvdims} ${scratch} |
---|
757 | isc=`expr ${isc} + 1` |
---|
758 | else |
---|
759 | echo " "${main}": differences will be calculated when all the " \ |
---|
760 | "model/experiments will be done !" |
---|
761 | fi |
---|
762 | else |
---|
763 | if ${dbg}; then echo " not '"${CFv}"' for model '"${mod}"' !!"; fi |
---|
764 | fi |
---|
765 | |
---|
766 | # exit |
---|
767 | # end of computing vars |
---|
768 | done |
---|
769 | echo " "${main}": "${ic}" variables has been computed" |
---|
770 | echo " "${main}": "${isc}" statistics has been computed" |
---|
771 | |
---|
772 | cd ${rootsh} |
---|
773 | exit |
---|
774 | # end of experiments |
---|
775 | done |
---|
776 | # end of models |
---|
777 | done |
---|
778 | |
---|
779 | exit |
---|
780 | |
---|
781 | istep=0 |
---|
782 | |
---|
783 | if test ${compute} -eq 1; then |
---|
784 | for exp in ${exps}; do |
---|
785 | echo "exp: "${exp} |
---|
786 | if test ${exp} == 'AR40'; then |
---|
787 | var2Dtmeans=${var2Dtmeans_AR40} |
---|
788 | else |
---|
789 | var2Dtmeans=${var2Dtmeans_NPv31} |
---|
790 | fi |
---|
791 | for vark in ${varks}; do |
---|
792 | echo " vark: "${vark} |
---|
793 | |
---|
794 | if test ${vark} = 'mean'; then |
---|
795 | fileorig=${ifoldmean}/${exp}/${filenmean} |
---|
796 | if test ! -f ${fileorig}; then |
---|
797 | fileworig=${filensfc} |
---|
798 | dvals='T:Time,Z:bottom_top,Y:south_north,X:west_east' |
---|
799 | dimnames='T:Time,Z:bottom_top,Y:south_north,X:west_east' |
---|
800 | python ${HOMEpy}/vertical_interpolation.py \ |
---|
801 | -f ${ofold}/${exp}/${filensfc} -o WRFp -i ${plevels} -k 'lin' \ |
---|
802 | -v WRFt,U,V,WRFrh,WRFght -d ${dimnames} -D T:Times,Z:ZNU,Y:XLAT,X:XLONG |
---|
803 | if test $? -ne 0; then |
---|
804 | echo ${errormsg} |
---|
805 | echo " python failed!" |
---|
806 | echo " python ${HOMEpy}/vertical_interpolation.py" \ |
---|
807 | "-f ${ofold}/${exp}/${filensfc} -o WRFp -i ${plevels} -k 'lin'" \ |
---|
808 | "-v WRFt,U,V,WRFrh,WRFght -d ${dimnames} -D T:Times,Z:ZNU,Y:XLAT,X:XLONG" |
---|
809 | rm ${ofold}/${exp}/vertical_interpolation_WRFp.nc >& /dev/null |
---|
810 | exit |
---|
811 | fi |
---|
812 | mv vertical_interpolation_WRFp.nc ${ofold}/${exp} |
---|
813 | fi |
---|
814 | vars=`echo ${mean_variables} | tr ':' ' '` |
---|
815 | ofile='mean_variables' |
---|
816 | elif test ${vark} = 'sfc'; then |
---|
817 | fileorig=${ifoldsfc}/${exp}/${filensfc} |
---|
818 | if test ! -f ${fileorig}; then |
---|
819 | fileworig=${filensfc} |
---|
820 | cp ${ifoldsfc}/${exp}/${fileworig} ${ifoldsfc}/${exp}/${filensfc} |
---|
821 | python ${HOMEpy}/nc_var.py -o WRF_CFxtime_creation -f ${ifoldsfc}/${exp}/${filensfc} \ |
---|
822 | -S 19491201000000,hours -v time |
---|
823 | python ${HOMEpy}/nc_var.py -o WRF_CFlonlat_creation -f ${ifoldsfc}/${exp}/${filensfc}\ |
---|
824 | -S longitude,latitude -v XLONG,XLAT |
---|
825 | fi |
---|
826 | if test ${exp} = 'AR40'; then |
---|
827 | vars=`echo ${sfc_variables_AR40} | tr ':' ' '` |
---|
828 | else |
---|
829 | vars=`echo ${sfc_variables_NPv31} | tr ':' ' '` |
---|
830 | fi |
---|
831 | ofile='sfc_variables' |
---|
832 | elif test ${vark} = 'diag'; then |
---|
833 | fileorig=${ifolddiag}/${exp}/${filendiag} |
---|
834 | vars=`echo ${diag_variables} | tr ':' ' '` |
---|
835 | if test ! -f ${fileorig}; then |
---|
836 | values='Time@XTIME,bottom_top@ZNU,south_north@XLAT,west_east@XLONG' |
---|
837 | ivar=0 |
---|
838 | varcombos='' |
---|
839 | for var in ${vars}; do |
---|
840 | echo " var:"${var} |
---|
841 | varn=`echo ${var} | tr '_' ' ' | awk '{print $2}'` |
---|
842 | combo=`python ${HOMEpy}/diagnostics.py -f ${combosfile} -d variable_combo -v ${varn}\ |
---|
843 | | grep COMBO | awk '{print $2}'` |
---|
844 | if test ${combo} = 'ERROR'; then |
---|
845 | echo ${errormsg} |
---|
846 | echo " No variable '"${varn}"' in '"${combosfile}"' !!" |
---|
847 | exit |
---|
848 | fi |
---|
849 | if test ${ivar} -eq 0; then |
---|
850 | varcombos=${varn}'|'${combo} |
---|
851 | else |
---|
852 | varcombos=${varcombos}','${varn}'|'${combo} |
---|
853 | fi |
---|
854 | ivar=`expr ${ivar} + 1` |
---|
855 | done |
---|
856 | python ${HOMEpy}/diagnostics.py -d ${values} -f ${ifoldsfc}/${exp}/${filensfc} -v \ |
---|
857 | ${varcombos} |
---|
858 | if test $? -ne 0; then |
---|
859 | echo ${errormsg} |
---|
860 | echo " python failed!!" |
---|
861 | echo python ${HOMEpy}/diagnostics.py -d ${values} -f ${ifoldsfc}/${exp}/${filensfc}\ |
---|
862 | -v ${varcombos} |
---|
863 | exit |
---|
864 | fi |
---|
865 | python ${HOMEpy}/nc_var.py -o WRF_CFxtime_creation -f diagnostics.nc \ |
---|
866 | -S 19491201000000,hours -v time |
---|
867 | python ${HOMEpy}/nc_var.py -o WRF_CFlonlat_creation -f diagnostics.nc \ |
---|
868 | -S longitude,latitude -v XLONG,XLAT |
---|
869 | mv diagnostics.nc ${ifolddiag}/${exp} |
---|
870 | fi |
---|
871 | ofile='diag_variables' |
---|
872 | elif test ${vark} = 'z'; then |
---|
873 | fileorig=${ifoldmean}/${exp}/${filenmean} |
---|
874 | vars=`echo ${z_variables} | tr ':' ' '` |
---|
875 | ofile='z_variables' |
---|
876 | fi |
---|
877 | |
---|
878 | # Averaging |
---|
879 | ## |
---|
880 | echo " averaging..." |
---|
881 | ivar=0 |
---|
882 | for varn in ${vars}; do |
---|
883 | file=${fileorig} |
---|
884 | echo " var: "${varn} |
---|
885 | var=`echo ${varn} | tr '|' ' ' | awk '{print $2}'` |
---|
886 | varval=`python ${HOMEpy}/drawing.py -o variable_values -S ${var} | grep all_values | awk '{print $3}'` |
---|
887 | varname=`echo ${varval} | tr ',' ' ' | awk '{print $1}'` |
---|
888 | |
---|
889 | echo " std name: "${varname} |
---|
890 | varhead=`echo ${varname} | tr '_' ' ' | awk '{print $1}'` |
---|
891 | vartail=`echo ${varname} | tr '_' ' ' | awk '{print $2}'` |
---|
892 | |
---|
893 | if test ${vark} = 'mean'; then |
---|
894 | vals='time:-1|z:-1|y:-1|x:-1,time:x,mean,pressure:lat' |
---|
895 | python ${HOMEpy}/nc_var.py -o file_oper_alongdims -S ${vals} -f ${file} -v ${var} |
---|
896 | pyexec=$? |
---|
897 | if test ${pyexec} -ne 0; then |
---|
898 | echo ${errormsg} |
---|
899 | echo " "${main}": python fai1ls!" |
---|
900 | echo "python ${HOMEpy}/nc_var.py -o file_oper_alongdims -S ${vals} -f ${file} -v ${var}" |
---|
901 | exit |
---|
902 | else |
---|
903 | oper=`echo ${vals} | tr ',' ' ' | awk '{print $3}'` |
---|
904 | mv file_oper_alongdims_mean.nc ${ofold}/${exp}/${varname}${oper}.nc |
---|
905 | fi |
---|
906 | elif test ${vark} = 'z'; then |
---|
907 | vals='time:-1|z:-1|y:-1|x:-1,time:x,mean,pressure:lat' |
---|
908 | echo "NOT FINISHED!!!!" |
---|
909 | exit |
---|
910 | else |
---|
911 | vals='Time:-1|south_north:-1|west_east:-1,west_east,mean,time:XLAT' |
---|
912 | if test ${var} = 'ACRAINTOT'; then |
---|
913 | files='add|'${file}'|RAINC,add|'${file}'|RAINNC' |
---|
914 | python ${HOMEpy}/nc_var.py -S 'time|XLAT|XLONG@'${files} -o compute_opersvarsfiles \ |
---|
915 | -v ${var} |
---|
916 | mv opersvarsfiles_${var}.nc ${ofold}/${exp} |
---|
917 | file=${ofold}/${exp}/opersvarsfiles_${var}.nc |
---|
918 | elif test ${var} = 'RAINTOT'; then |
---|
919 | dims='Time@time,bottom_top@ZNU,south_north@XLAT,west_east@XLONG' |
---|
920 | python ${HOMEpy}/diagnostics.py -d ${dims} -v 'RAINTOT|RAINC@RAINNC@time' -f ${file} |
---|
921 | mv diagnostics.nc ${ofold}/${exp}/diagnostics_${varname}.nc |
---|
922 | file=${ofold}/${exp}/diagnostics_${varname}.nc |
---|
923 | var='pr' |
---|
924 | elif test ${var} = 'cllmh'; then |
---|
925 | dims='Time@time,bottom_top@ZNU,south_north@XLAT,west_east@XLONG' |
---|
926 | clouds='cll:clm:clh' |
---|
927 | cls=`echo ${clouds} | tr ':' ' '` |
---|
928 | for cl in ${cls}; do |
---|
929 | file=${ofold}/${exp}/diagnostics.nc |
---|
930 | var=${cl} |
---|
931 | echo " var: "${var} |
---|
932 | python ${HOMEpy}/nc_var.py -o file_oper_alongdims -S ${vals} -f ${file} -v ${cl} |
---|
933 | pyexec=$? |
---|
934 | if test ${pyexec} -ne 0; then |
---|
935 | echo ${errormsg} |
---|
936 | echo " "${main}": python fails!" |
---|
937 | echo python ${HOMEpy}/nc_var.py -o file_oper_alongdims -S ${vals} -f ${file} -v ${cl} |
---|
938 | exit |
---|
939 | fi |
---|
940 | mv file_oper_alongdims_mean.nc ${ofold}/${exp}/${cl}${oper}.nc |
---|
941 | vals='Time:-1|south_north:-1|west_east:-1,Time,mean,XLONG:XLAT' |
---|
942 | dims='Time@time,bottom_top@ZNU,south_north@XLAT,west_east@XLONG' |
---|
943 | python ${HOMEpy}/nc_var.py -o file_oper_alongdims -S ${vals} -f ${file} -v ${cl} |
---|
944 | pyexec=$? |
---|
945 | if test ${pyexec} -ne 0; then |
---|
946 | echo ${errormsg} |
---|
947 | echo " "${main}": python fails!" |
---|
948 | exit |
---|
949 | else |
---|
950 | oper=`echo ${vals} | tr ',' ' ' | awk '{print $3}'` |
---|
951 | mv file_oper_alongdims_mean.nc ${ofold}/${exp}/${cl}t${oper}.nc |
---|
952 | fi |
---|
953 | done |
---|
954 | # break |
---|
955 | elif test ${var} = 'WRFbils' && test ! -f ${ofold}/${exp}/diagnostics_${varname}.nc; then |
---|
956 | dims='Time@time,south_north@XLAT,west_east@XLONG' |
---|
957 | python ${HOMEpy}/diagnostics.py -d ${dims} -v 'WRFbils|HFX@LH' -f ${file} |
---|
958 | mv diagnostics.nc ${ofold}/${exp}/diagnostics_${varname}.nc |
---|
959 | file=${ofold}/${exp}/diagnostics_${varname}.nc |
---|
960 | var='bils' |
---|
961 | elif test ${var} = 'WRFprw' && test ! -f ${ofold}/${exp}/diagnostics_${varname}.nc; then |
---|
962 | dims='Time@time,bottom_top@ZNU,south_north@XLAT,west_east@XLONG' |
---|
963 | python ${HOMEpy}/diagnostics.py -d ${dims} -v 'WRFprw|WRFdens@QVAPOR' -f ${file} |
---|
964 | mv diagnostics.nc ${ofold}/${exp}/diagnostics_${varname}.nc |
---|
965 | file=${ofold}/${exp}/diagnostics_${varname}.nc |
---|
966 | var='prw' |
---|
967 | elif test ${var} = 'WRFrhs' && test ! -f ${ofold}/${exp}/diagnostics_${varname}.nc; then |
---|
968 | dims='Time@time,bottom_top@ZNU,south_north@XLAT,west_east@XLONG' |
---|
969 | python ${HOMEpy}/diagnostics.py -d ${dims} -v 'WRFrhs|PSFC@T2@Q2' -f ${file} |
---|
970 | mv diagnostics.nc ${ofold}/${exp}/diagnostics_${varname}.nc |
---|
971 | file=${ofold}/${exp}/diagnostics_${varname}.nc |
---|
972 | var='huss' |
---|
973 | elif test ${var} = 'WRFprc'; then |
---|
974 | vals='Time:-1|south_north:-1|west_east:-1,west_east,mean,time:XLAT' |
---|
975 | dims='Time@time,bottom_top@ZNU,south_north@XLAT,west_east@XLONG' |
---|
976 | var='prc' |
---|
977 | elif test ${var} = 'WRFprls'; then |
---|
978 | vals='Time:-1|south_north:-1|west_east:-1,west_east,mean,time:XLAT' |
---|
979 | dims='Time@time,bottom_top@ZNU,south_north@XLAT,west_east@XLONG' |
---|
980 | var='prls' |
---|
981 | fi |
---|
982 | if test ! -f ${ofold}/${exp}/${varname}${oper}.nc; then |
---|
983 | python ${HOMEpy}/nc_var.py -o file_oper_alongdims -S ${vals} -f ${file} -v ${var} |
---|
984 | pyexec=$? |
---|
985 | if test ${pyexec} -ne 0; then |
---|
986 | echo ${errormsg} |
---|
987 | echo " "${main}": python fails!" |
---|
988 | exit |
---|
989 | else |
---|
990 | mv file_oper_alongdims_mean.nc ${ofold}/${exp}/${varname}${oper}.nc |
---|
991 | fi |
---|
992 | fi |
---|
993 | fi |
---|
994 | echo "HereLluis"${var} |
---|
995 | # Time means |
---|
996 | if $(isin_list ${var2Dtmeans} ${var}); then |
---|
997 | echo "Computing time means!!" |
---|
998 | if test ${var} = 'cllmh'; then |
---|
999 | clouds='cll:clm:clh' |
---|
1000 | clds=`echo ${clouds} | tr ':' ' '` |
---|
1001 | for cld in ${clds}; do |
---|
1002 | vals='Time:-1|south_north:-1|west_east:-1,Time,mean,XLONG:XLAT' |
---|
1003 | dims='Time@time,bottom_top@ZNU,south_north@XLAT,west_east@XLONG' |
---|
1004 | python ${HOMEpy}/nc_var.py -o file_oper_alongdims -S ${vals} -f ${file} -v ${cld} |
---|
1005 | pyexec=$? |
---|
1006 | if test ${pyexec} -ne 0; then |
---|
1007 | echo ${errormsg} |
---|
1008 | echo " "${main}": python fails!" |
---|
1009 | exit |
---|
1010 | else |
---|
1011 | oper=`echo ${vals} | tr ',' ' ' | awk '{print $3}'` |
---|
1012 | mv file_oper_alongdims_mean.nc ${ofold}/${exp}/${cld}t${oper}.nc |
---|
1013 | fi |
---|
1014 | done |
---|
1015 | else |
---|
1016 | vals='Time:-1|south_north:-1|west_east:-1,Time,mean,XLONG:XLAT' |
---|
1017 | dims='Time@time,bottom_top@ZNU,south_north@XLAT,west_east@XLONG' |
---|
1018 | python ${HOMEpy}/nc_var.py -o file_oper_alongdims -S ${vals} -f ${file} -v ${var} |
---|
1019 | pyexec=$? |
---|
1020 | if test ${pyexec} -ne 0; then |
---|
1021 | echo ${errormsg} |
---|
1022 | echo " "${main}": python fails!" |
---|
1023 | exit |
---|
1024 | else |
---|
1025 | oper=`echo ${vals} | tr ',' ' ' | awk '{print $3}'` |
---|
1026 | mv file_oper_alongdims_mean.nc ${ofold}/${exp}/${varname}t${oper}.nc |
---|
1027 | fi |
---|
1028 | fi |
---|
1029 | fi |
---|
1030 | if test ${var} = 'cllmh'; then exit; fi |
---|
1031 | ivar=`expr ${ivar} + 1` |
---|
1032 | # exit |
---|
1033 | # end of vars |
---|
1034 | done |
---|
1035 | |
---|
1036 | # end of kind vars |
---|
1037 | done |
---|
1038 | |
---|
1039 | done |
---|
1040 | # end of compute |
---|
1041 | fi |
---|
1042 | # Longitudinal means of tmeans |
---|
1043 | ## |
---|
1044 | if ${computetlon}; then |
---|
1045 | echo "Computing Longitudinal means of temporal means..." |
---|
1046 | for exp in ${exps}; do |
---|
1047 | echo " exp:"${exp} |
---|
1048 | for tmean in ${ofold}/${exp}/*tmean.nc; do |
---|
1049 | fname=`basename ${tmean}` |
---|
1050 | var=`ncdump -h ${tmean} | grep float | grep mean | tr '(' ' ' | awk '{print $2}'` |
---|
1051 | vals='south_north:-1|west_east:-1,west_east,mean,XLAT' |
---|
1052 | dims='bottom_top@bottom_top,south_north@south_north,west_east@west_east' |
---|
1053 | if test ! -f ${ofold}/${exp}/${var}t-lonmean.nc; then |
---|
1054 | python ${HOMEpy}/nc_var.py -o file_oper_alongdims -S ${vals} -f ${tmean} -v ${var} |
---|
1055 | pyexec=$? |
---|
1056 | if test ${pyexec} -ne 0; then |
---|
1057 | echo ${errormsg} |
---|
1058 | echo " "${main}": python fails!" |
---|
1059 | exit |
---|
1060 | else |
---|
1061 | mv file_oper_alongdims_mean.nc ${ofold}/${exp}/${var}t-lonmean.nc |
---|
1062 | fi |
---|
1063 | # exit |
---|
1064 | fi |
---|
1065 | done |
---|
1066 | |
---|
1067 | done |
---|
1068 | fi |
---|
1069 | |
---|
1070 | if ${plot}; then |
---|
1071 | # Plots |
---|
1072 | ## |
---|
1073 | |
---|
1074 | for exp in ${exps}; do |
---|
1075 | echo "exp: "${exp} |
---|
1076 | for vark in ${varks}; do |
---|
1077 | echo " vark: "${vark} |
---|
1078 | if test ${vark} = 'mean'; then |
---|
1079 | gcoups=`echo ${graph_couples_mean} | tr ':' ' '` |
---|
1080 | elif test ${vark} = 'sfc'; then |
---|
1081 | if test ${exp} = 'AR40'; then |
---|
1082 | gcoups=`echo ${graph_couples_sfc_AR40} | tr ':' ' '` |
---|
1083 | else |
---|
1084 | gcoups=`echo ${graph_couples_sfc_NPv31} | tr ':' ' '` |
---|
1085 | fi |
---|
1086 | elif test ${vark} = 'diag'; then |
---|
1087 | gcoups=`echo ${graph_couples_diag} | tr ':' ' '` |
---|
1088 | fi |
---|
1089 | |
---|
1090 | for gpair in ${gcoups}; do |
---|
1091 | shdvar=`echo ${gpair} | tr '@' ' ' | awk '{print $1}'` |
---|
1092 | cntvar=`echo ${gpair} | tr '@' ' ' | awk '{print $2}'` |
---|
1093 | echo " couple: "${shdvar}'-'${cntvar} |
---|
1094 | shdvals=`python ${HOMEpy}/drawing.py -o variable_values -S ${shdvar} | grep all_values | awk '{print $3}'` |
---|
1095 | cntvals=`python ${HOMEpy}/drawing.py -o variable_values -S ${cntvar} | grep all_values | awk '{print $3}'` |
---|
1096 | files=${ofold}'/'${exp}'/'${shdvar}'mean.nc,'${ofold}'/'${exp}'/'${cntvar}'mean.nc' |
---|
1097 | |
---|
1098 | Lshdvals=`expr length ${shdvals}0` |
---|
1099 | if test ${Lshdvals} -lt 2; then |
---|
1100 | echo ${errormsg} |
---|
1101 | echo " Error in drawing_tools.py 'variables_values'!!" |
---|
1102 | echo " variable '"${shdvar}"' NOT found!" |
---|
1103 | exit |
---|
1104 | fi |
---|
1105 | |
---|
1106 | Lcntvals=`expr length ${cntvals}0` |
---|
1107 | if test ${Lcntvals} -lt 2; then |
---|
1108 | echo ${errormsg} |
---|
1109 | echo " Error in drawing_tools.py 'variables_values'!!" |
---|
1110 | echo " variable '"${cntvar}"' NOT found!" |
---|
1111 | exit |
---|
1112 | fi |
---|
1113 | |
---|
1114 | shdstdn=`echo ${shdvals} | tr ',' ' ' | awk '{print $1}'` |
---|
1115 | shdcbar=`echo ${shdvals} | tr ',' ' ' | awk '{print $7}'` |
---|
1116 | shdmin=`echo ${shdvals} | tr ',' ' ' | awk '{print $3}'` |
---|
1117 | shdmax=`echo ${shdvals} | tr ',' ' ' | awk '{print $4}'` |
---|
1118 | |
---|
1119 | cntstdn=`echo ${cntvals} | tr ',' ' ' | awk '{print $1}'` |
---|
1120 | cntmin=`echo ${cntvals} | tr ',' ' ' | awk '{print $3}'` |
---|
1121 | cntmax=`echo ${cntvals} | tr ',' ' ' | awk '{print $4}'` |
---|
1122 | |
---|
1123 | if test ${shdstdn} = 'ERROR' || test ${cntstdn} = 'ERROR'; then |
---|
1124 | echo ${errmsg} |
---|
1125 | echo " "${main}": wrong variable names!!!" |
---|
1126 | echo " shdvals: "${shdvals} |
---|
1127 | echo " cntvals: "${cntvals} |
---|
1128 | echo " shdvar: "${shdvar}" cntvar: "${cntvar} |
---|
1129 | exit |
---|
1130 | fi |
---|
1131 | |
---|
1132 | cntcolor='black' |
---|
1133 | cntfmt='%g' |
---|
1134 | |
---|
1135 | if test ${gpair} = 'va@ua'; then |
---|
1136 | shdmin=`echo ${shdmin} | awk '{print $1/4.}'` |
---|
1137 | shdmax=`echo ${shdmax} | awk '{print $1/4.}'` |
---|
1138 | cntmin=`echo ${cntmin} | awk '{print $1/3.}'` |
---|
1139 | cntmax=`echo ${cntmax} | awk '{print $1 + 20.}'` |
---|
1140 | elif test ${gpair} = 'tas@ps'; then |
---|
1141 | shdmin=`echo ${shdmin} | awk '{print $1 + 50.}'` |
---|
1142 | shdmax=`echo ${shdmax} | awk '{print $1 - 15.}'` |
---|
1143 | cntmin=`echo ${cntmin} | awk '{print $1 + 15000.}'` |
---|
1144 | cntmax=`echo ${cntmax} | awk '{print $1 - 2000.}'` |
---|
1145 | elif test ${gpair} = 'uas@vas'; then |
---|
1146 | cntmin=`echo ${cntmin} | awk '{print $1 * 0.1}'` |
---|
1147 | cntmax=`echo ${cntmax} | awk '{print $1 * 0.1}'` |
---|
1148 | elif test ${gpair} = 'pr@rsds'; then |
---|
1149 | # shdmax=`echo ${shdmax} | awk '{print $1 / 20.}'` |
---|
1150 | cntmax=`echo ${cntmax} | awk '{print $1 / 3.}'` |
---|
1151 | elif test ${gpair} = 'clt@cll' || test ${gpair} = 'clh@clm'; then |
---|
1152 | cntcolor='red' |
---|
1153 | cntfmt='%.1g' |
---|
1154 | elif test ${gpair} = 'clh@clm'; then |
---|
1155 | cntmax=`echo ${cntmax} | awk '{print $1}'` |
---|
1156 | elif test ${gpair} = 'prw@huss'; then |
---|
1157 | shdmax=`echo ${shdmax} | awk '{print $1*4}'` |
---|
1158 | elif test ${gpair} = 'prls@prc'; then |
---|
1159 | shdmax=`echo ${shdmax} | awk '{print $1/1.}'` |
---|
1160 | cntmax=`echo ${cntmax} | awk '{print $1 * 0.5}'` |
---|
1161 | elif test ${gpair} = 'hfls@hfss'; then |
---|
1162 | cntmin='-50.' |
---|
1163 | cntmax='50.' |
---|
1164 | fi |
---|
1165 | |
---|
1166 | if test ${vark} = 'mean'; then |
---|
1167 | graphvals=${shdstdn}','${cntstdn}':z|-1,y|-1:z|-1,y|-1:lat:pressure:' |
---|
1168 | graphvals=${graphvals}${shdcbar}':fixsigc,'${cntcolor}':'${cntfmt}':'${shdmin}',' |
---|
1169 | graphvals=${graphvals}${shdmax}':'${cntmin}','${cntmax}',9:LMDZ+WRF|'${exp} |
---|
1170 | graphvals=${graphvals}'|meridional|monthly|average|of|'${shdstdn}'|&|' |
---|
1171 | graphvals=${graphvals}${cntstdn}':pdf:flip@y:None' |
---|
1172 | else |
---|
1173 | graphvals=${shdstdn}','${cntstdn}':y|-1,time|-1:y|-1,time|-1:time:XLAT:' |
---|
1174 | graphvals=${graphvals}${shdcbar}':fixsigc,'${cntcolor}':'${cntfmt}':'${shdmin}',' |
---|
1175 | graphvals=${graphvals}${shdmax}':'${cntmin}','${cntmax}',9:WRF+LMDZ|'${exp} |
---|
1176 | graphvals=${graphvals}'|mean|meridional|evolution|of|'${shdstdn}'|&|' |
---|
1177 | graphvals=${graphvals}${cntstdn}':pdf:None:time|hours!since!1949-12-01|' |
---|
1178 | graphvals=${graphvals}'exct,5,d|%d|date!([DD]):None' |
---|
1179 | fi |
---|
1180 | |
---|
1181 | echo ${files} |
---|
1182 | echo ${graphvals} |
---|
1183 | echo ${shdstdn}'mean,'${cntstdn}'mean' |
---|
1184 | |
---|
1185 | if test ${vark} = 'sfc' || test ${vark} = 'diag' && |
---|
1186 | ! $(isin_list ${coup2D} ${gpair}); then |
---|
1187 | python ${HOMEpy}/drawing.py -f ${files} -o draw_2D_shad_cont_time -S ${graphvals} -v \ |
---|
1188 | ${shdstdn}'mean,'${cntstdn}'mean' |
---|
1189 | pyexc=$? |
---|
1190 | else |
---|
1191 | python ${HOMEpy}/drawing.py -f ${files} -o draw_2D_shad_cont -S ${graphvals} -v \ |
---|
1192 | ${shdstdn}'mean,'${cntstdn}'mean' |
---|
1193 | pyexc=$? |
---|
1194 | fi |
---|
1195 | if test ${pyexc} -ne 0; then |
---|
1196 | echo ${errormsg} |
---|
1197 | echo " "${main}": drawing.py fails!" |
---|
1198 | exit |
---|
1199 | else |
---|
1200 | mv 2Dfields_shadow-contour.pdf ${ofold}/${exp}/${shdvar}mean_${cntvar}mean.pdf |
---|
1201 | evince ${ofold}/${exp}/${shdvar}mean_${cntvar}mean.pdf & |
---|
1202 | fi |
---|
1203 | |
---|
1204 | if $(isin_list ${coup2D} ${gpair}); then |
---|
1205 | graphvals=${shdstdn}','${cntstdn}':south_north|-1,west_east|-1:' |
---|
1206 | graphvals=${graphvals}'south_north|-1,west_east|-1:longitude:latitude:' |
---|
1207 | graphvals=${graphvals}${shdcbar}':fixsigc,'${cntcolor}':'${cntfmt}':'${shdmin}',' |
---|
1208 | graphvals=${graphvals}${shdmax}':'${cntmin}','${cntmax}',9:LMDZ+WRF|'${exp} |
---|
1209 | graphvals=${graphvals}'|monthly|average|of|'${shdstdn}'|&|' |
---|
1210 | graphvals=${graphvals}${cntstdn}':pdf:flip@y:None' |
---|
1211 | echo ' '${shdstdn}'mean,'${cntstdn}'mean' |
---|
1212 | |
---|
1213 | python ${HOMEpy}/drawing.py -f ${files} -o draw_2D_shad_cont -S ${graphvals} -v \ |
---|
1214 | ${shdstdn}'mean,'${cntstdn}'mean' |
---|
1215 | pyexc=$? |
---|
1216 | if test ${pyexc} -ne 0; then |
---|
1217 | echo ${errormsg} |
---|
1218 | echo " "${main}": drawing.py fails!" |
---|
1219 | exit |
---|
1220 | else |
---|
1221 | mv 2Dfields_shadow-contour.pdf ${ofold}/${exp}/${shdvar}tmean_${cntvar}tmean.pdf |
---|
1222 | evince ${ofold}/${exp}/${shdvar}tmean_${cntvar}tmean.pdf & |
---|
1223 | fi |
---|
1224 | fi |
---|
1225 | # exit |
---|
1226 | |
---|
1227 | # end of couples |
---|
1228 | done |
---|
1229 | # end of kinds |
---|
1230 | done |
---|
1231 | |
---|
1232 | done |
---|
1233 | fi |
---|
1234 | |
---|
1235 | # 2D single plots |
---|
1236 | ## |
---|
1237 | if ${single2Dplot}; then |
---|
1238 | echo "2D single plots" |
---|
1239 | for exp in ${exps}; do |
---|
1240 | echo " exp:"${exp} |
---|
1241 | for tmean in ${ofold}/${exp}/*tmean.nc ;do |
---|
1242 | fname=`basename ${tmean}` |
---|
1243 | var=`ncdump -h ${tmean} | grep float | grep mean | tr '(' ' ' | awk '{print $2}'` |
---|
1244 | if test ! ${var} = 'cltmean'; then |
---|
1245 | shdvals=`python ${HOMEpy}/drawing.py -o variable_values -S ${var} | \ |
---|
1246 | grep all_values | awk '{print $3}'` |
---|
1247 | cbar=`echo ${shdvals} | tr ',' ' ' | awk '{print $7}'` |
---|
1248 | min=`echo ${shdvals} | tr ',' ' ' | awk '{print $3}'` |
---|
1249 | max=`echo ${shdvals} | tr ',' ' ' | awk '{print $4}'` |
---|
1250 | |
---|
1251 | if test ${var} = 'prlsmean'; then xtrms='0,0.00015'; |
---|
1252 | elif test ${var} = 'prwmean'; then xtrms='0,40'; |
---|
1253 | elif test ${var} = 'psmean'; then xtrms='99000,102500'; |
---|
1254 | elif test ${var} = 'r2mean'; then xtrms='0,0.025'; |
---|
1255 | elif test ${var} = 'tasmean'; then xtrms='275,310'; |
---|
1256 | elif test ${var} = 'tmlamean'; then xtrms='260,310'; |
---|
1257 | elif test ${var} = 'uasmean'; then xtrms='-20,20'; |
---|
1258 | elif test ${var} = 'vasmean'; then xtrms='-20,20'; |
---|
1259 | else xtrms=${min}','${max}; fi |
---|
1260 | |
---|
1261 | # vals=${var}':XLONG|-1,XLAT|-1:XLONG:XLAT:'${cbar}':'${xtrms}':monthly|mean:pdf:' |
---|
1262 | # vals=${vals}'None:None:true' |
---|
1263 | # dims='south_north@XLAT,west_east@XLONG' |
---|
1264 | python ${HOMEpy}/nc_var.py -o WRF_CFlonlat_creation -S longitude,latitude \ |
---|
1265 | -f ${tmean} -v XLONG,XLAT |
---|
1266 | vals=${var}':longitude|-1,latitude|-1:longitude:latitude:'${cbar}':'${xtrms}':monthly|mean:pdf:' |
---|
1267 | vals=${vals}'None:None:true' |
---|
1268 | dims='south_north@latitude,west_east@longitude' |
---|
1269 | python ${HOMEpy}/drawing.py -o draw_2D_shad -S ${vals} -f ${tmean} -v ${var} |
---|
1270 | pyexec=$? |
---|
1271 | if test ${pyexec} -ne 0; then |
---|
1272 | echo ${errormsg} |
---|
1273 | echo " "${main}": python fails!" |
---|
1274 | exit |
---|
1275 | else |
---|
1276 | mv 2Dfields_shadow.pdf ${ofold}/${exp}/${var}tmean.pdf |
---|
1277 | # evince ${ofold}/${exp}/${var}tmean.pdf & |
---|
1278 | # exit |
---|
1279 | fi |
---|
1280 | fi |
---|
1281 | done |
---|
1282 | done |
---|
1283 | fi |
---|
1284 | |
---|
1285 | # lon 2 vertical section |
---|
1286 | ## |
---|
1287 | echo "lon 2 vertical section ..." |
---|
1288 | vars=`echo ${lon2DZsecvars} | tr ':' ' '` |
---|
1289 | pts=`echo ${lon2DZsecpts} | tr ':' ' '` |
---|
1290 | |
---|
1291 | if ${lonZsec}; then |
---|
1292 | for exp in ${exps}; do |
---|
1293 | file=${ofold}/${exp}/vertical_interpolation_WRFp.nc |
---|
1294 | # python ${HOMEpy}/nc_var.py -o WRF_CFlonlat_creation -S longitude,latitude \ |
---|
1295 | # -f ${file} -v lon,lat |
---|
1296 | ## ALREADY done! |
---|
1297 | # python ${HOMEpy}/nc_var.py -o valmod -S lowthres@oper,0.,sumc,360. -f ${file} \ |
---|
1298 | # -v lon |
---|
1299 | if test ${exp} = 'AR40'; then labexp='wlmdza' |
---|
1300 | else labexp='wlmdzb'; fi |
---|
1301 | |
---|
1302 | for pt in ${pts}; do |
---|
1303 | echo " pt: "${pt} |
---|
1304 | vals='x:15|y:'${pt}'|time:23' |
---|
1305 | lonval=`python ${HOMEpy}/nc_var.py -o varout -f ${file} -S ${vals} -v lon | \ |
---|
1306 | awk '{print $2}'` |
---|
1307 | latval=`python ${HOMEpy}/nc_var.py -o varout -f ${file} -S ${vals} -v lat | \ |
---|
1308 | awk '{print $2}'` |
---|
1309 | tval=`python ${HOMEpy}/nc_var.py -o varout -f ${file} -S ${vals} -v time | \ |
---|
1310 | awk '{print $2}'` |
---|
1311 | for var in ${vars}; do |
---|
1312 | echo " var: "${var} |
---|
1313 | |
---|
1314 | shdvals=`python ${HOMEpy}/drawing.py -o variable_values -S ${var} | \ |
---|
1315 | grep all_values | awk '{print $3}'` |
---|
1316 | cbar=`echo ${shdvals} | tr ',' ' ' | awk '{print $7}'` |
---|
1317 | min=`echo ${shdvals} | tr ',' ' ' | awk '{print $3}'` |
---|
1318 | max=`echo ${shdvals} | tr ',' ' ' | awk '{print $4}'` |
---|
1319 | |
---|
1320 | # WRFt,U,V,WRFrh,WRFght |
---|
1321 | if test ${var} = 'WRFght'; then xtrms='0,40000'; |
---|
1322 | elif test ${var} = 'WRFt'; then xtrms='200,300'; |
---|
1323 | elif test ${var} = 'U'; then xtrms='-40,40'; |
---|
1324 | elif test ${var} = 'V'; then xtrms='-20,20'; |
---|
1325 | else xtrms=${min}','${max}; fi |
---|
1326 | |
---|
1327 | # Plotting |
---|
1328 | vals=${var}':x|-1,y|'${pt}',z|-1,time|24:lon:pressure:'${cbar}':' |
---|
1329 | vals=${vals}${xtrms}':'${labexp}'|vertical|longitudinal|section|('${latval} |
---|
1330 | vals=${vals}'$^{\circ}$):pdf:flip@y:None:true' |
---|
1331 | python ${HOMEpy}/drawing.py -o draw_2D_shad -S ${vals} -f ${file} -v ${var} |
---|
1332 | pyexec=$? |
---|
1333 | if test ${pyexec} -ne 0; then |
---|
1334 | echo ${errormsg} |
---|
1335 | echo " "${main}": python fails!" |
---|
1336 | exit |
---|
1337 | else |
---|
1338 | mv 2Dfields_shadow.pdf ${ofold}/${exp}/${var}_lonZsec_${pt}pt.pdf |
---|
1339 | evince ${ofold}/${exp}/${var}_lonZsec_${pt}pt.pdf & |
---|
1340 | fi |
---|
1341 | |
---|
1342 | cntcolor='black' |
---|
1343 | cntfmt='%g' |
---|
1344 | |
---|
1345 | if test ${var} = 'WRFght'; then cxtrms='0,40000'; |
---|
1346 | elif test ${var} = 'WRFt'; then cxtrms='200,300'; |
---|
1347 | elif test ${var} = 'U'; then cxtrms='-40,40'; |
---|
1348 | elif test ${var} = 'V'; then cxtrms='-20,20'; |
---|
1349 | else cxtrms=${min}','${max}; fi |
---|
1350 | |
---|
1351 | graphvals=${var}','${var}':x|-1,y|'${pt}',z|-1,time|24:' |
---|
1352 | graphvals=${graphvals}'x|-1,y|'${pt}',z|-1,time|24:lon:pressure:' |
---|
1353 | graphvals=${graphvals}${cbar}':fixsigc,'${cntcolor}':'${cntfmt}':'${xtrms}':' |
---|
1354 | graphvals=${graphvals}${cxtrms}',15:'${labexp} |
---|
1355 | graphvals=${graphvals}'|vertical|zonal|section|('${latval}'$^{\circ}$):pdf:' |
---|
1356 | graphvals=${graphvals}'flip@y:None' |
---|
1357 | |
---|
1358 | python ${HOMEpy}/drawing.py -o draw_2D_shad_cont -S ${graphvals} \ |
---|
1359 | -f ${file},${file} -v ${var},${var} |
---|
1360 | pyexec=$? |
---|
1361 | if test ${pyexec} -ne 0; then |
---|
1362 | echo ${errormsg} |
---|
1363 | echo " "${main}": python fails!" |
---|
1364 | exit |
---|
1365 | else |
---|
1366 | mv 2Dfields_shadow-contour.pdf ${ofold}/${exp}/${var}_lonZsec-cnt_${pt}pt.pdf |
---|
1367 | evince ${ofold}/${exp}/${var}_lonZsec-cnt_${pt}pt.pdf & |
---|
1368 | fi |
---|
1369 | |
---|
1370 | # exit |
---|
1371 | done |
---|
1372 | done |
---|
1373 | done |
---|
1374 | fi |
---|
1375 | |
---|
1376 | echo "Computing differences" |
---|
1377 | exp1=`echo ${experiments} | tr ':' ' ' | awk '{print $1}'` |
---|
1378 | exp2=`echo ${experiments} | tr ':' ' ' | awk '{print $2}'` |
---|
1379 | |
---|
1380 | diffks=`echo ${diffkinds} | tr ':' ' '` |
---|
1381 | |
---|
1382 | if test ${differences}; then |
---|
1383 | for kind in ${diffks}; do |
---|
1384 | echo ${kind} |
---|
1385 | case ${kind} in |
---|
1386 | 'diffZ') |
---|
1387 | vars=`echo ${diffZvars} | tr ':' ' '` |
---|
1388 | fileorigd='mean.nc' |
---|
1389 | ;; |
---|
1390 | 'diffH') |
---|
1391 | vars=`echo ${diffHvars} | tr ':' ' '` |
---|
1392 | fileorigd='tmean.nc' |
---|
1393 | ;; |
---|
1394 | esac |
---|
1395 | |
---|
1396 | echo " "${var} |
---|
1397 | for var in ${vars}; do |
---|
1398 | if test ! -f ${ofold}/${var}_diff.nc; then |
---|
1399 | # cdo sub ${ofold}/${exp1}/${var}${fileorigd} ${ofold}/${exp2}/${var}${fileorigd} ${ofold}/${var}_diff.nc |
---|
1400 | if test ${kind} = 'diffZ'; then |
---|
1401 | values='pressure|lat@add|'${ofold}'/'${exp1}'/'${var}${fileorigd}'|'${var}'mean,' |
---|
1402 | values=${values}'sub|'${ofold}'/'${exp2}'/'${var}${fileorigd}'|'${var}'mean' |
---|
1403 | python ${HOMEpy}/nc_var.py -o compute_opersvarsfiles -S ${values} -v ${var} |
---|
1404 | pyexec=$? |
---|
1405 | if test ${pyexec} -ne 0; then |
---|
1406 | echo ${errormsg} |
---|
1407 | echo " "${main}": python fails!" |
---|
1408 | exit |
---|
1409 | fi |
---|
1410 | mv opersvarsfiles_${var}.nc ${ofold}/${var}_diff.nc |
---|
1411 | else |
---|
1412 | values='longitude|latitude@add|'${ofold}'/'${exp1}'/'${var}${fileorigd}'|'${var}'mean,' |
---|
1413 | values=${values}'sub|'${ofold}'/'${exp2}'/'${var}${fileorigd}'|'${var}'mean' |
---|
1414 | python ${HOMEpy}/nc_var.py -o compute_opersvarsfiles -S ${values} -v ${var} |
---|
1415 | pyexec=$? |
---|
1416 | if test ${pyexec} -ne 0; then |
---|
1417 | echo ${errormsg} |
---|
1418 | echo " "${main}": python fails!" |
---|
1419 | exit |
---|
1420 | fi |
---|
1421 | mv opersvarsfiles_${var}.nc ${ofold}/${var}_diff.nc |
---|
1422 | fi |
---|
1423 | fi |
---|
1424 | done |
---|
1425 | |
---|
1426 | if test ${kind} = 'diffZ'; then |
---|
1427 | coups=`echo ${graph_couples_mean} | tr ':' ' '` |
---|
1428 | for coup in ${coups}; do |
---|
1429 | shdvar=`echo ${coup} | tr '@' ' ' | awk '{print $1}'` |
---|
1430 | cntvar=`echo ${coup} | tr '@' ' ' | awk '{print $2}'` |
---|
1431 | |
---|
1432 | echo " couple: "${shdvar}'-'${cntvar} |
---|
1433 | |
---|
1434 | shdvals=`python ${HOMEpy}/drawing.py -o variable_values -S ${shdvar} | grep all_values | awk '{print $3}'` |
---|
1435 | cntvals=`python ${HOMEpy}/drawing.py -o variable_values -S ${cntvar} | grep all_values | awk '{print $3}'` |
---|
1436 | files=${ofold}'/'${shdvar}'_diff.nc,'${ofold}'/'${cntvar}'_diff.nc' |
---|
1437 | |
---|
1438 | shdstdn=`echo ${shdvals} | tr ',' ' ' | awk '{print $1}'` |
---|
1439 | shdcbar=`echo ${shdvals} | tr ',' ' ' | awk '{print $7}'` |
---|
1440 | shdmin=`echo ${shdvals} | tr ',' ' ' | awk '{print $3}'` |
---|
1441 | shdmax=`echo ${shdvals} | tr ',' ' ' | awk '{print $4}'` |
---|
1442 | |
---|
1443 | cntstdn=`echo ${cntvals} | tr ',' ' ' | awk '{print $1}'` |
---|
1444 | cntmin=`echo ${cntvals} | tr ',' ' ' | awk '{print $3}'` |
---|
1445 | cntmax=`echo ${cntvals} | tr ',' ' ' | awk '{print $4}'` |
---|
1446 | |
---|
1447 | shdcbar='seismic' |
---|
1448 | if test ${coup} = 'va@ua'; then |
---|
1449 | shdmin=-4. |
---|
1450 | shdmax=4. |
---|
1451 | cntmin=-10. |
---|
1452 | cntmax=10. |
---|
1453 | elif test ${coup} = 'hus@ta'; then |
---|
1454 | shdmin=-0.2 |
---|
1455 | shdmax=0.2 |
---|
1456 | cntmin=-2. |
---|
1457 | cntmax=2. |
---|
1458 | fi |
---|
1459 | |
---|
1460 | cntcolor='black' |
---|
1461 | cntfmt='%g' |
---|
1462 | |
---|
1463 | graphvals=${shdstdn}','${cntstdn}':x|-1,y|-1,x_2|-1:x|-1,y|-1,x_2|-1:lat:' |
---|
1464 | graphvals=${graphvals}'pressure:'${shdcbar}':fixsigc,'${cntcolor}':'${cntfmt}':' |
---|
1465 | graphvals=${graphvals}${shdmin}','${shdmax}':'${cntmin}','${cntmax}',9:' |
---|
1466 | graphvals=${graphvals}${exp1}'-'${exp2}'|meridional|monthly|average|differences|of|' |
---|
1467 | graphvals=${graphvals}${shdstdn}'|&|'${cntstdn}':pdf:flip@y:None' |
---|
1468 | |
---|
1469 | python ${HOMEpy}/drawing.py -o draw_2D_shad_cont -S ${graphvals} \ |
---|
1470 | -f ${files} -v ${shdvar},${cntvar} |
---|
1471 | pyexec=$? |
---|
1472 | if test ${pyexec} -ne 0; then |
---|
1473 | echo ${errormsg} |
---|
1474 | echo " "${main}": python fails!" |
---|
1475 | exit |
---|
1476 | else |
---|
1477 | mv 2Dfields_shadow-contour.pdf ${ofold}/${shdvar}-${cntvar}_diff.pdf |
---|
1478 | evince ${ofold}/${shdvar}-${cntvar}_diff.pdf & |
---|
1479 | fi |
---|
1480 | done |
---|
1481 | # exit |
---|
1482 | else |
---|
1483 | for var in ${vars}; do |
---|
1484 | echo " "${var} |
---|
1485 | vals=`python ${HOMEpy}/drawing.py -o variable_values -S ${var} | grep all_values | awk '{print $3}'` |
---|
1486 | file=${ofold}/${var}_diff.nc |
---|
1487 | |
---|
1488 | stdn=`echo ${vals} | tr ',' ' ' | awk '{print $1}'` |
---|
1489 | cbar='seismic' |
---|
1490 | |
---|
1491 | if test ${var} = 'uas'; then xtrms='-10.,10.'; |
---|
1492 | elif test ${var} = 'vas'; then xtrms='-5,5'; |
---|
1493 | elif test ${var} = 'ps'; then xtrms='-500,500'; |
---|
1494 | elif test ${var} = 'pr'; then xtrms='-0.001,0.001'; |
---|
1495 | else xtrms=${min}','${max}; fi |
---|
1496 | |
---|
1497 | vals=${var}':x|-1,y|-1:longitude:latitude:'${cbar}':' |
---|
1498 | vals=${vals}${xtrms}':'${exp1}'-'${exp2}'|meridional|monthly|average|differences:' |
---|
1499 | vals=${vals}'pdf:None:None:true' |
---|
1500 | python ${HOMEpy}/drawing.py -o draw_2D_shad -S ${vals} -f ${file} -v ${var} |
---|
1501 | pyexec=$? |
---|
1502 | if test ${pyexec} -ne 0; then |
---|
1503 | echo ${errormsg} |
---|
1504 | echo " "${main}": python fails!" |
---|
1505 | exit |
---|
1506 | else |
---|
1507 | mv 2Dfields_shadow.pdf ${ofold}/${var}_diff.pdf |
---|
1508 | evince ${ofold}/${var}_diff.pdf & |
---|
1509 | fi |
---|
1510 | # exit |
---|
1511 | done |
---|
1512 | fi |
---|
1513 | done |
---|
1514 | fi |
---|