source: lmdz_wrf/trunk/tools/model_graphics.bash @ 955

Last change on this file since 955 was 937, checked in by lfita, 9 years ago

Working verion with the 'shadconthovmsfc'

  • Property svn:executable set to *
File size: 76.2 KB
Line 
1#!/bin/bash
2# L. Fita, June 2016. Generic script to plot model outputs
3
4main='model_graphics.bash'
5
6# All purpouse
7######## ###### ##### #### ### ## #
8
9function uploadvars() {
10# Function to upload variables to the system from an ASCII file as:
11#   [varname] = [value]
12  fileval=$1
13  errormsg='ERROR -- error -- ERROR -- error'
14
15  if test ! -f ${fileval}; then
16    echo ${errormsg}
17    echo "  "${fname}": file '"${fileval}"' does not exist!!"
18    exit
19  fi
20
21  Nlin=`wc -l ${fileval} | awk '{print $1}'`
22
23  ilin=1
24  while test ${ilin} -le ${Nlin}; do
25    line=`head -n ${ilin} ${fileval} | tail -n 1`
26    varname=`echo ${line} | tr '=' ' ' | awk '{print $1}'`
27    value=`echo ${line} | tr '=' ' ' | awk '{print $2}'`
28    Lvarname=`expr length ${varname}'0'`
29
30    if test ${Lvarname} -gt 1 && test ! ${varname:0:1} = '#'; then
31      export ${varname}=${value}
32    fi
33    ilin=`expr ${ilin} + 1`
34  done
35}
36
37function isInlist() {
38# Function to check whether a value is in a list
39  list=$1
40  value=$2
41 
42  is=`echo ${list} | tr ':' '\n' | awk '{print "@"$1"@"}' | grep '@'${value}'@' | wc -w`
43  if test ${is} -eq 1
44  then
45    true
46  else
47    false
48  fi
49}
50
51function ferrmsg() {
52# Function to exit and write an error message
53#  comdexit: code number exit from the last execution
54#  ref: script/reference from which error occurs
55#  msg: message to write ('!' for spaces, '#' for end of line)
56  comdexit=$1
57  ref=$2
58  msg=$3
59
60  if test ${comdexit} -ne 0; then
61    echo "ERROR -- error -- ERROR -- error"
62    echo "  "${ref}": "$(echo ${msg} | tr '!' ' ' | tr '#' '\n')" !!"
63    exit
64  fi
65}
66
67function ferrmsgF() {
68# Function to exit and write an error message and remove a file
69#  comdexit: code number exit from the last execution
70#  ref: script/reference from which error occurs
71#  msg: message to write ('!' for spaces, '#' for end of line)
72#  FileName: name of the file to remove in case of error
73  comdexit=`expr $1 + 0`
74  ref=$2
75  msg=$3
76  FileName=$4
77
78  if test ${comdexit} -ne 0; then
79    echo "ERROR -- error -- ERROR -- error"
80    echo "  "${ref}": "$(echo ${msg} | tr '!' ' ' | tr '\#' '\n')" !!"
81    rm ${FileName} >& /dev/null
82    exit
83  fi
84}
85
86function list_add_label(){
87# Function to add the label to a list
88#   list= ':' separated list to wchich add a ticket
89#   label= label to add to the list
90#   ch= character to separate list values and new label
91#   pos= position of the label ('beg': beginning, 'end': ending)
92# $ list_add_label 1:2:3:4:5 abc # beg
93# abc#1:abc#2:abc#3:abc#4:abc#5
94
95  fname='list_add_label'
96
97  list=$1
98  label=$2
99  ch=$3
100  pos=$4
101
102  ival=1
103  lvs=`echo ${list} | tr ':' ' '`
104 
105  newlist=''
106  for listv in ${lvs}; do
107    if test ${pos} = 'beg'; then
108      nlv=${label}${ch}${listv}
109    else
110      nlv=${listv}${ch}${label}
111    fi
112    if test ${ival} -eq 1; then
113      newlist=${nlv}
114    else
115      newlist=${newlist}':'${nlv}
116    fi
117    ival=`expr ${ival} + 1`
118  done
119
120  echo ${newlist}
121}
122
123function stats_filename() {
124# Function to provide the name of a given statisitcs file
125#   CFvarn= CF variable name
126#   fkind= kind of the file
127#   headf= head of the file
128# $ stats_filename ta xmean wrfout
129# ta_wrfout_xmean.nc
130# $ stats_filename ta pinterp@last@xmean wrfout
131# ta_wrfout_pinterp_last_xmean.nc
132  fname='stats_filename'
133
134  CFvarn=$1
135  fkind=$2
136  headf=$3
137
138  # Number of operations in a combo file they are '@' separated
139  nopers=`echo ${fkind} | tr '@' ' ' | wc -w | awk '{print $1}'`
140
141  if test $(index_string ${fkind} pinterp) -ne -1; then
142    fhead=${headf}'p'
143  else
144    fhead=${headf}
145  fi
146
147  if test ${nopers} -eq 1; then
148    filename=${CFvarn}'_'${fhead}'_'${fkind}
149  else
150    opers=`echo ${fkind} | tr '@' ' '`
151    filename=${CFvarn}'_'${fhead}
152    for op in ${opers}; do
153      filename=${filename}'_'${op}
154    done
155  fi
156
157  echo ${filename}.nc
158}
159
160function index_string(){
161# Function to provide the index of a given word inside a string
162#   string= string to find in
163#   word= word to find
164#  $ index_string 123abc456ab789bca0 bca
165#  14
166  fname='index_string'
167  string=$1
168  word=$2
169
170  Lstring=`expr length ${string}`
171  Lword=`expr length ${word}`
172 
173  Lfinalstring=`expr ${Lstring} - ${Lword}`
174
175  iw=0
176  index=-1
177  while test ${iw} -le ${Lfinalstring}; do
178    if test ${string:${iw}:${Lword}} = ${word}; then
179      index=${iw}
180      break
181    fi
182    iw=`expr ${iw} + 1`
183  done
184
185  echo ${index}
186  return
187}
188
189function list_filter() {
190# Function to filter by a value a list
191#   list: list to filter
192#   value: value to filter with
193#  $ list_filter '1|i:2|ii:3|iii:4|iv:5|v:1|I:2|II:3|III:4|iv:5|v' 3
194#  3|iii:3|III
195  fname='list_filter'
196
197  list=$1
198  varn=$2
199
200  lvs=`echo ${list} | tr ':' ' '`
201
202  newlist=''
203  il=1
204  for lv in ${lvs}; do
205    if test $(index_string ${lv} ${varn}) -ne -1; then
206      if test ${il} -eq 1; then
207        newlist=${lv}
208      else
209        newlist=${newlist}':'${lv}
210      fi
211      il=`expr ${il} + 1`
212    fi
213  done
214
215  echo ${newlist}
216
217  return
218}
219
220function join_lists() {
221# Function to join lists without repeating values
222#   list1: first list to join
223#   list2: second list to join
224#  $ join_lists 1:2:3:4:5:6:7:8 a:b:3:c:5:6:7:9
225#  1:2:3:4:5:6:7:8:a:b:c:9
226
227  fname='join_lists'
228  list1=$1
229  list2=$2
230
231  ls1s=`echo ${list1} | tr ':' ' '`
232  ls2s=`echo ${list2} | tr ':' ' '`
233
234  newlist=${list1}
235  for ls2 in ${ls2s}; do
236    if ! $(isInlist ${list1} ${ls2}); then
237      newlist=${newlist}':'${ls2}
238    fi
239  done
240
241  echo ${newlist}
242}
243
244# Specific
245######## ###### ##### #### ### ## #
246
247function variable_compute(){
248# Function to retrieve the computation way of a given variable using a series of
249#   test files
250#   iwdir= directory with the test files
251#   var= name of the variable to test
252#   filtests= '@' separated list of '[head]|[file] test files
253  fname='variable_compute'
254
255  iwdir=$1
256  var=$2
257  filtests=$3
258
259  ftsts=`echo ${filtests} |tr '@' ' '`
260  cancompute=true
261
262  for ftest in ${ftsts}; do
263    headerf=`echo ${ftest} | tr '|' ' ' | awk '{print $1}'`
264    filen=`echo ${ftest} | tr '|' ' ' | awk '{print $2}'`
265    compute=`${pyHOME}/nc_var.py -o computevar_model -f ${iwdir}/${filen} -S ${var}`
266    ferrmsg $? ${main} "python!'computevar_model'!failed!#"$(echo ${compute} |       \
267      tr ' ' '!')
268    varmod=`echo ${compute} | tr ' ' '#' | tr '|' ' ' | awk '{print $2}' |           \
269      tr '@' ' ' | awk '{print $2}' | tr '=' ' ' | awk '{print $2}'`
270    vardiag=`echo ${compute} | tr ' ' '#' | tr '|' ' ' | awk '{print $2}' |          \
271      tr '@' ' ' | awk '{print $3}' | tr '=' ' ' | awk '{print $2}'`
272    echo "  "${var}" mod:"${varmod}" diag: "${vardiag}
273    if test ${varmod} = 'None' && test ${vardiag} = 'None'; then 
274      cancompute=false
275    else
276      cancompute=true
277    # Should be considered that variable can also be computed by both ways?
278      break
279    fi
280  done
281  if ! ${cancompute}; then
282    msg="there!is!no!way!to!compute!'"${var}"'!for!model!"${mod}
283# Too extrict!
284#    ferrmsg 1 ${main} ${msg}
285    echo ${warnmsg}
286    echo $(echo $msg | tr '!' ' ')
287  fi
288
289  # a ';' list 'varcompute' it is created for each variable giving:
290  #   [var]|[vark]|[headerf][varmod]|[vardiag]
291  # This list will be used to compute a new file for each variable
292  varcomp=${var}'|'${vark}'|'${headerf}'|'${varmod}'|'${vardiag}
293
294  echo "varcomp= "${varcomp}
295}
296
297function WRF_toCF() {
298# Function to pass a WRF original file to CF-conventions
299#   wrff= WRF file
300#   wrfvl= WRF longitude var name (it might come from WPS!)
301#   wrfvL= WRF latitude var name (it might come from WPS!)
302
303  wrff=$1
304  wrfvl=$2
305  wrfvL=$3
306
307  fdims=`${pyHOME}/nc_var.py -o idims -f ${wrff} | grep alldims | tr '=' ' ' |       \
308    awk '{print $3}'`
309
310  CFdims='west_east@lon:south_north@lat:Time@time'
311  CFds=`echo ${CFdims} | tr ':' ' '`
312 
313  pyout=`${pyHOME}/nc_var.py -o WRF_CFtime_creation -S 19491201000000,minutes        \
314    -f ${wrff} -v time`
315  pyn=$?
316  Spyout=`echo ${pyout} | tr '\n' '#' | tr ' ' '!'`
317  ferrmsgF ${pyn} ${fname} "python!'WRF_CFtime_creation'!failed"${Spyout} ${wrff}
318 
319  pyout=`${pyHOME}/nc_var.py -o WRF_CFlonlat_creation -v ${wrfvl},${wrfvL}           \
320    -f ${wrff} -S lon,lat`
321  pyn=$?
322  Spyout=`echo ${pyout} | tr '\n' '#' | tr ' ' '!'`
323  ferrmsgF ${pyn} ${fname} "python!'WRF_CFlonlat_creation'!failed"${Spyout} ${wrff}
324
325  for CFd in ${CFds}; do
326    cd=`echo ${CFd} | tr '@' ' ' | awk '{print $2}'`
327    wd=`echo ${CFd} | tr '@' ' ' | awk '{print $1}'`
328    if $(isInlist ${fdims} ${wd}); then
329      pyout=`${pyHOME}/nc_var.py -o chdimname -f ${wrff} -S ${wd}':'${cd}`
330      pyn=$?
331      Spyout=`echo ${pyout} | tr '\n' '#' | tr ' ' '!'`
332      ferrmsgF ${pyn} ${fname} "python!'chdimname'!'"${wd}"'!failed#"${Spyout} ${wrff}
333    fi
334  done
335
336  # CF attributes
337  dimvars='lon:lat:time:Times'
338
339  allfilevars=`python ${pyHOME}/nc_var.py -o ivars -f ${wrff} | grep allvars | awk '{print $3}'`
340  allvs=`echo ${allfilevars} | tr ':' ' '`
341  for vn in ${allvs}; do
342    if ! $(isInlist ${dimvars} ${vn}); then
343      varattrs=`python ${pyHOME}/generic.py -o variables_values -S ${vn}`
344      stn=`echo ${varattrs} | tr ':' ' ' | awk '{print $2}'`
345      lon=`echo ${varattrs} | tr ':' ' ' | awk '{print $5}' | tr '|' '!'`
346      un=`echo ${varattrs} | tr ':' ' ' | awk '{print $6}' | tr '|' '!'`
347
348      pyout=`python ${pyHOME}/nc_var.py -o varaddattr -f ${wrff} -S 'standard_name|'${stn} -v ${vn}`
349      pyn=$?
350      Spyout=`echo ${pyout} | tr '\n' '#' | tr ' ' '!'`
351      ferrmsgF ${pyn} ${fname} "python!'varaddattr'!'standard_name'!failed#"${Spyout} ${wrff}
352      pyout=`python ${pyHOME}/nc_var.py -o varaddattr -f ${wrff} -S 'long_name|'${lon} -v ${vn}`
353      pyn=$?
354      Spyout=`echo ${pyout} | tr '\n' '#' | tr ' ' '!'`
355      ferrmsgF ${pyn} ${fname} "python!'varaddattr'!'long_name'!failed#"${Spyout} ${wrff}
356      pyout=`python ${pyHOME}/nc_var.py -o varaddattr -f ${wrff} -S 'units|'${un} -v ${vn}`
357      pyn=$?
358      Spyout=`echo ${pyout} | tr '\n' '#' | tr ' ' '!'`
359      ferrmsgF ${pyn} ${fname} "python!'varaddattr'!'units'!failed#"${Spyout} ${wrff}
360    fi
361  done
362}
363
364function cleaning_varsfile() {
365# Function to keep only a list of variables from a file
366#   filen= file to clean
367#   keepvars= ':' separated list of variables to keep
368  fname='cleaning_varsfile'
369
370  filen=$1
371  keepvars=$2
372
373  fvars=`${pyHOME}/nc_var.py -o ivars -f ${filen} | grep allvars | tr '=' ' ' |      \
374    awk '{print $3}'`
375  fvs=`echo ${fvars} | tr ':' ' '`
376
377  for fv in ${fvs}; do
378    if ! $(isInlist ${keepvars} ${fv}); then
379      pyout=`python ${pyHOME}/nc_var.py -o varrm -v ${fv} -f ${filen}`
380      pyn=$?
381      Spyout=`echo ${pyout} | tr '\n' '#' | tr ' ' '!'`
382      ferrmsg ${pyn} ${fname} "python!'varrm'!'${fv}'!failed#"${Spyout}
383    fi
384  done
385}
386
387function compute_variable() {
388# Function to compute a variable
389#   idir: directory with the input files
390#   usefiles: ',' list of files as [headerf]@[file1]|...|[fileN]
391#   odir: directory to write the output files
392#   cvar: [CFvarn]|[varkind]|[headerf]|[varmod]|[vardiag]
393#     [CFvarn]: CF name of the variable
394#     [vark]: kind of variable:
395#        acc: temporal accumulated values
396#        diff: differences between models
397#        direct: no statistics
398#        last: last temporal value
399#        Lmean: latitudinal mean values
400#        Lsec: latitudinal section (latitudinal value must be given, [var]@[lat])
401#        lsec: longitudinal section (longitudinal value must be given, [var]@[lat])
402#        lmean: longitudinal mean values
403#        pinterp: pressure interpolation (to the given $plevels)
404#        tmean: temporal mean values
405#        tmean: temporal mean values
406#        xmean: x-axis mean values
407#        ymean: y-axis mean values
408#        zsum: vertical aggregated values
409#     [headerf]: header of the files to use
410#     [modvar]: variable to use from the file
411#     [diagvar]: variable computed from the diagnostics (diagnostic.py)
412#   mdim: name of the dimensions in the model
413#   mvdim: name of the vaariable-dimensions in the model
414#   scratch: whether is has to be done from the scratch or not
415  fname='compute_variable'
416  idir=$1
417  usefiles=$2
418  odir=$3
419  cvar=$4
420  mdim=$5
421  mvdim=$6
422  scratch=$7
423
424  CFvarn=`echo ${cvar} | tr '|' ' ' | awk '{print $1}'`
425  vark=`echo ${cvar} | tr '|' ' ' | awk '{print $2}'`
426  headerf=`echo ${cvar} | tr '|' ' ' | awk '{print $3}'`
427  modvar=`echo ${cvar} | tr '|' ' ' | awk '{print $4}'`
428  diagvar=`echo ${cvar} | tr '|' ' ' | awk '{print $5}'`
429
430  cfiles=`echo ${usefiles} | tr ',' '\n' | grep ${headerf} | tr '|' ' ' | \
431    awk '{print $2}' | tr '@' ' '`
432
433# dimensions
434  dnx=`echo ${mdim} | tr ',' ' ' | awk '{print $1}'`
435  dny=`echo ${mdim} | tr ',' ' ' | awk '{print $2}'`
436# var-dimensions
437  vdnx=`echo ${mvdim} | tr ',' ' ' | awk '{print $1}'`
438  vdny=`echo ${mvdim} | tr ',' ' ' | awk '{print $2}'`
439
440  cd ${odir}
441
442  # Computing separately and then joinging for all files
443  Ntotfiles=`echo ${cfiles} | wc -w | awk '{print $1}'`
444  ifile=1
445
446  for cf in ${cfiles}; do
447    ifS=`printf "%0${Ntotfiles}d" ${ifile}`
448
449# Computing variable
450    # Changing file head when it is a pressure-interpolated variable
451    if test ${vark} == 'pinterp'; then
452      fhead=${headerf}p
453    else
454      fhead=${headerf}
455    fi
456
457    filen=${odir}/${CFvarn}_${fhead}_${ifile}-${Ntotfiles}.nc
458    if ${scratch}; then 
459      rm ${filen} >& /dev/null
460      rm ${odir}/${CFvarn}_${fhead}.nc >& /dev/null
461    fi
462
463    if test ! -f ${filen} && test ! -f ${odir}/${CFvarn}_${fhead}.nc; then
464# Since model direct values are retrieved from `variables_valules.dat' which was initially coincived
465#   as a way to only give variable attributes, range and color bars, if a variable has a diagnostic
466#   way to be computed, the later one will be preferred
467
468      if test ! ${modvar} = 'None' && test ${diagvar} = 'None'; then
469        # model variable
470        values=${modvar}',0,-1,-1'
471        vs=${modvar},${vdnx},${vdny},${vdnz},${vdnt}
472        pyout=`${pyHOME}/nc_var.py -f ${cf} -o DataSetSection_multivars -v ${vs}     \
473          -S ${values} | grep succesfull | awk '{print $6}' | tr '"' ' '`
474        pyn=$?
475        Spyout=`echo ${pyout} | tr '\n' '#' | tr ' ' '!'`
476        ferrmsg ${pyn} ${fname} "python!'DataSetSection_multivars'!failed"${Spyout}
477        mv ${pyout} ${filen}
478
479        # Keeping the operations
480        pyins=${pyHOME}"/nc_var.py -f "${cf}" -o DataSetSection_multivars -v "${vs}
481        pyins=${pyins}" -S "${values}
482        echo " " >> ${odir}/all_computevars.inf
483        echo "# ${CFvarn}" "${modvar}" >> ${odir}/all_computevars.inf
484        echo ${pyins} >> ${odir}/all_computevars.inf
485
486        pyout=`${pyHOME}/nc_var.py -f ${filen} -o chvarname -v ${modvar} -S ${CFvarn}`
487        pyn=$?
488        Spyout=`echo ${pyout} | tr '\n' '#' | tr ' ' '!'`
489        ferrmsgF ${pyn} ${fname} "python!'chvarname'!failed"${Spyout} ${filen}
490      else
491        # diagnostic variable
492        dims=${dnt}@${vdnt},${dnz}@${vdnz},${dny}@${vdny},${dnx}@${vdnx}
493        diagn=`echo ${diagvar} | tr ':' '\n' | head -n 1`
494        Ndiagvars=`echo ${diagvar} | tr ':' ' ' | wc -w | awk '{print $1}'`
495        idiagv=2
496        diagc=''
497        while test ${idiagv} -le ${Ndiagvars}; do
498          diag1=`echo ${diagvar} | tr ':' '\n' | head -n ${idiagv} | tail -n 1`
499          if test ${idiagv} -eq 2; then
500            diagc=${diag1}
501          else
502            diagc=${diagc}'@'${diag1}
503          fi
504          idiagv=`expr ${idiagv} + 1`
505        done
506        pyout=`python ${pyHOME}/diagnostics.py -f ${cf} -d ${dims} -v ${diagn}'|'${diagc}`
507        pyn=$?
508        Spyout=`echo ${pyout} | tr '\n' '#' | tr ' ' '!'`
509        ferrmsg ${pyn} ${fname} "python!'diagnostics'!failed#"${Spyout}
510        mv diagnostics.nc ${filen}
511
512        # Keeping the operations
513        pyins=${pyHOME}"/diagnostics.py -f "${cf}" -d "${dims}" -v '"${diagn}"|"
514        pyins=${pyins}${diagc}"'"
515        echo " " >> ${odir}/all_computevars.inf
516        echo "# ${CFvarn}" "${diagvar}" >> ${odir}/all_computevars.inf
517        echo ${pyins} >> ${odir}/all_computevars.inf
518      fi
519
520      # adding CF lon,lat,time in WRF files
521      if test ${headerf:0:3} = 'wrf'; then
522        WRF_toCF ${filen} ${vdnx} ${vdny}
523      fi
524      # Attaching necessary variables for the pressure interpolation
525      if test ${vark} == 'pinterp'; then
526        requiredinterpvars='P:PB:PSFC:PH:PHB:HGT:T:QVAPOR:'
527        rqvs=`echo ${requiredinterpvars} | tr ':' ' '`
528        echo "  "${fname}": adding variables: "${rqvs}" to allow pressure interpolation"
529        for rqv in ${rqvs}; do
530          pyout=`${pyHOME}/nc_var.py -o fvaradd -S ${cf},${rqv} -f ${filen}`
531          pyn=$?
532          Spyout=`echo ${pyout} | tr '\n' '#' | tr ' ' '!'`
533          ferrmsgF ${pyn} ${fname} "python!'fvaradd'!failed#"${Spyout} ${filen}
534        done
535      fi
536    fi
537
538    ifile=`expr ${ifile} + 1`
539# End of files
540  done
541
542  # Joining variable files
543  filen=${odir}/${CFvarn}_${fhead}.nc
544  if ${scratch}; then rm ${filen} >& /dev/null; fi
545
546  if test ! -f ${filen}; then
547    pyout=`python ${pyHOME}/nc_var.py -f ${CFvarn}'_'${fhead}'_,-,.nc'               \
548      -o netcdf_fold_concatenation_HMT -S ./,time -v all`
549    pyn=$?
550    Spyout=`echo ${pyout} | tr '\n' '#' | tr ' ' '!'`
551    ferrmsg ${pyn} ${fname} "python!'netcdf_fold_concatenation_HMT'!failed#"${Spyout}
552    mv netcdf_fold_concatenated_HMT.nc ${filen}
553    if test -f ${filen}; then
554      rm ${CFvarn}_${fhead}_*-*.nc
555    fi
556  fi
557}
558
559function compute_statistics(){
560# Function to compute different statistics
561#   idir: directory with the input files
562#   usefiles: ',' list of files to use [file1],...,[fileN]
563#   odir: directory to write the output files
564#   cvar: [CFvarn]|[varkind]|[headerf]|[varmod]|[vardiag]
565#     [CFvarn]: CF name of the variable
566#     [vark]: kind of variable:
567#        acc: temporal accumulated values
568#        diff: differences between models
569#        direct: no statistics
570#        last: last temporal value
571#        Lmean: latitudinal mean values
572#        Lsec: latitudinal section (latitudinal value must be given, [var]@[lat])
573#        lmean: longitudinal mean values
574#        lsec: longitudinal section (longitudinal value must be given, [var]@[lat])
575#        pinterp: pressure interpolation (to the given $plevels)
576#        tmean: temporal mean values
577#        xmean: x-axis mean values
578#        ymean: y-axis mean values
579#        zsum: vertical aggregated values
580#     [headerf]: header of the files to use
581#     [modvar]: variable to use from the file
582#     [diagvar]: variable computed from the diagnostics (diagnostic.py)
583#   mdim: name of the dimensions in the model
584#   mvdim: name of the vaariable-dimensions in the model
585#   scratch: whether is has to be done from the scratch or not
586  fname='compute_statistics'
587
588  idir=$1
589  usefiles=$2
590  odir=$3
591  cvar=$4
592  mdim=$5
593  mvdim=$6
594  scratch=$7
595
596  # Getting a previous file name to continue with(for combinations)
597  if test $# -eq 8; then
598    echo ${warnmsg}
599    echo "  "${fname}": using a previous file '"$8"' to continue with!!"
600    prevfile=$8
601    usefiles=$8
602  fi
603
604  CFvarn=`echo ${cvar} | tr '|' ' ' | awk '{print $1}'`
605  vark=`echo ${cvar} | tr '|' ' ' | awk '{print $2}'`
606  headerf=`echo ${cvar} | tr '|' ' ' | awk '{print $3}'`
607  modvar=`echo ${cvar} | tr '|' ' ' | awk '{print $4}'`
608  diagvar=`echo ${cvar} | tr '|' ' ' | awk '{print $5}'`
609
610  cfiles=`echo ${usefiles} | tr ',' ' '`
611
612# dimensions
613  dnx=`echo ${mdim} | tr ',' ' ' | awk '{print $1}'`
614  dny=`echo ${mdim} | tr ',' ' ' | awk '{print $2}'`
615# var-dimensions
616  vdnx=`echo ${mvdim} | tr ',' ' ' | awk '{print $1}'`
617  vdny=`echo ${mvdim} | tr ',' ' ' | awk '{print $2}'`
618
619  cd ${odir}
620
621  if test $# -ne 8; then
622    if test ${vark} == 'pinterp'; then
623      fhead=${headerf}p
624    else
625      fhead=${headerf}
626    fi
627    filen=${CFvarn}_${fhead}_${vark}.nc
628  else
629    Lprevfile=`expr length ${prevfile}`
630    Lprevfile3=`expr ${Lprevfile} - 3`
631    filen=${prevfile:0:$Lprevfile3}_${vark}.nc
632  fi
633  if ${scratch}; then rm ${filen} >& /dev/null; fi
634
635  if test ! -f ${filen}; then
636    # Computing stats
637    case ${vark} in
638       # temporal accumulated values
639      'acc') 
640        echo "  "${fname}": kind '"${vark}"' not ready !!"
641        exit
642      ;;
643      # differences between models
644      'diff')
645        echo "  "${fname}": kind '"${vark}"' not ready !!"
646        exit
647      ;;
648      # no statistics
649      'direct')
650        cp ${cfiles} ${filen}
651      ;;
652      # last temporal value
653      'last')
654        Lcfiles=`expr length ${cfiles}`
655        Lcfiles3=`expr ${Lcfiles} - 3`
656        vals='time,-9,0,0'
657        pyout=`python ${pyHOME}/nc_var.py -o DataSetSection -S ${vals} -f ${cfiles}  \
658          -v ${CFvarn}`
659        pyn=$?
660        Spyout=`echo ${pyout} | tr '\n' '#' | tr ' ' '!'`
661        ferrmsg ${pyn} ${fname} "python!'DataSetSection'!'last'!failed#"${Spyout}
662        mv ${cfiles:0:${Lcfiles3}}_time_B-9-E0-I0.nc ${filen}
663
664        # Keeping the operations
665        pyins=${pyHOME}"/nc_var.py -o DataSetSection -S "${vals}" -f "${cfiles}
666        pyins=${pyins}"-v "${CFvarn}
667        echo " " >> ${odir}/all_statsvars.inf
668        echo "# ${CFvarn}" "${vark}" >> ${odir}/all_statsvars.inf
669        echo ${pyins} >> ${odir}/all_statsvars.inf
670      ;;
671      # latitudinal mean values
672      'Lmean')
673        echo "  "${fname}": kind '"${vark}"' not ready !!"
674        exit
675      ;;
676      # latitudinal section (latitudinal value must be given, [var]@[lat])
677      'Lsec')
678        echo "  "${fname}": kind '"${vark}"' not ready !!"
679        exit
680      ;;
681      # longitudinal section (longitudinal value must be given, [var]@[lat])
682      'lsec')
683        echo "  "${fname}": kind '"${vark}"' not ready !!"
684        exit
685      ;;
686      # longitudinal mean values
687      'lmean')
688        echo "  "${fname}": kind '"${vark}"' not ready !!"
689        exit
690      ;;
691      # pinterp: pressure interpolation (to the given $plevels)
692      'pinterp')
693        vals=${plevels}',1,1'
694        pyout=`python $pyHOME/nc_var.py -o pinterp -f ${cfiles} -S ${vals}           \
695          -v ${CFvarn}`
696        pyn=$?
697        Spyout=`echo ${pyout} | tr '\n' '#' | tr ' ' '!'`
698        ferrmsg ${pyn} ${fname} "python!'pinterp'!failed#"${Spyout}
699        cp pinterp.nc ${filen}
700
701        # Keeping the operations
702        pyins=${pyHOME}"/nc_var.py -o pinterp -S "${vals}" -f "${cfiles}
703        pyins=${pyins}"-v "${CFvarn}
704        echo " " >> ${odir}/all_statsvars.inf
705        echo "# ${CFvarn}" "${vark}" >> ${odir}/all_statsvars.inf
706        echo ${pyins} >> ${odir}/all_statsvars.inf
707
708        # adding CF lon,lat,time in WRF files
709        if test ${headerf:0:3} = 'wrf'; then
710          WRF_toCF ${filen} ${vdnx} ${vdny}
711        fi
712      ;;
713      # temporal mean values
714      'tmean')
715        vals='time|-1,time,mean,lon:lat:'${vdnz}':time'
716        dims='time@time,'${dnz}'@'${vdnz}',lat@lat,lon@lon'
717
718        pyout=`python ${pyHOME}/nc_var.py -o file_oper_alongdims -S ${vals}          \
719          -f ${cfiles} -v ${CFvarn}`
720        pyn=$?
721        Spyout=`echo ${pyout} | tr '\n' '#' | tr ' ' '!'`
722        ferrmsg ${pyn} ${fname} "python!'file_oper_alongdims'!'tmean'!failed#"${Spyout}
723        mv file_oper_alongdims_mean.nc ${filen}
724
725        # Keeping the operations
726        pyins=${pyHOME}"/nc_var.py -o file_oper_alongdims -S '"${vals}"' -f "${cfiles}
727        pyins=${pyins}" -v "${CFvarn}
728        echo " " >> ${odir}/all_statsvars.inf
729        echo "# ${CFvarn}" "${vark}" >> ${odir}/all_statsvars.inf
730        echo ${pyins} >> ${odir}/all_statsvars.inf
731
732        varkeep=':'${CFvarn}'mean:timestats'
733      ;;
734      # x-axis mean values
735      'xmean')
736        vals='lon|-1,lon,mean,lon:lat:'${vdnz}':time'
737        dims='time@time,'${dnz}'@'${vdnz}',lat@lat,lon@lon'
738
739        pyout=`python ${pyHOME}/nc_var.py -o file_oper_alongdims -S ${vals}         \
740          -f ${cfiles} -v ${CFvarn}`
741        pyn=$?
742        Spyout=`echo ${pyout} | tr '\n' '#' | tr ' ' '!'`
743        ferrmsg ${pyn} ${fname} "python!'file_oper_alongdims'!'tmean'!failed#"${Spyout}
744        mv file_oper_alongdims_mean.nc ${filen}
745
746        # Keeping the operations
747        pyins=${pyHOME}"/nc_var.py -o file_oper_alongdims -S '"${vals}"' -f "${cfiles}
748        pyins=${pyins}" -v "${CFvarn}
749        echo " " >> ${odir}/all_statsvars.inf
750        echo "# ${CFvarn}" "${vark}" >> ${odir}/all_statsvars.inf
751        echo ${pyins} >> ${odir}/all_statsvars.inf
752
753        varkeep=':'${CFvarn}'mean:lonstats'
754      ;;
755      # y-axis mean values
756      'ymean')
757        vals='lat|-1,lat,mean,lon:lat:'${vdnz}':time'
758        dims='time@time,'${dnz}'@'${vdnz}',lat@lat,lon@lon'
759
760        pyout=`python ${pyHOME}/nc_var.py -o file_oper_alongdims -S ${vals}         \
761          -f ${cfiles} -v ${CFvarn}`
762        pyn=$?
763        Spyout=`echo ${pyout} | tr '\n' '#' | tr ' ' '!'`
764        ferrmsg ${pyn} ${fname} "python!'file_oper_alongdims'!'tmean'!failed#"${Spyout}
765        mv file_oper_alongdims_mean.nc ${filen}
766
767        # Keeping the operations
768        pyins=${pyHOME}"/nc_var.py -o file_oper_alongdims -S '"${vals}"' -f "${cfiles}
769        pyins=${pyins}" -v "${CFvarn}
770        echo " " >> ${odir}/all_statsvars.inf
771        echo "# ${CFvarn}" "${vark}" >> ${odir}/all_statsvars.inf
772        echo ${pyins} >> ${odir}/all_statsvars.inf
773
774        varkeep=':'${CFvarn}'mean:latstats'
775      ;;
776      # vertical aggregated values
777      'zsum')
778        echo "  "${fname}": kind '"${vark}"' not ready !!"
779        exit
780      ;;
781      *)
782        echo ${errmsg}
783        echo "  "${fname}": kind '"${vark}"' not ready !!"
784        exit
785      ;;
786    esac
787    cleaning_varsfile ${filen} ${CFvarn}':lon:lat:pres:time'${varkeep}
788  fi
789
790}
791
792function draw_plot(){
793# Function to carry out the drawing of the plots
794#   plot= [kplot]+[varn1]|[kind1]#[varn2]|[kind2]#....
795#     diffmap2Dsfc: 2D map of surface differences values of 1 variable
796#     diffmap2Dz: 2D map of 3D differences values of 1 variable
797#     shadconthovmsfc: Hovmoeller diagrams of 2 variable at the surface in shadow and the other in contourn
798#     map2Dsfc: 2D map of surface values of 1 variable
799#     map3D: 2D map of 3D values of 1 variable
800#     shadcont2Dsfc: 2D map of shadow (1st variable) and countour (2nd variable) [stvar1]#[stvar2]
801#
802#     ':' separated list of statitsics variable values are given as: [var]|[kind(including combo values)]
803#     in figures with more than 1 variable, use '#' to separate them
804#   odir= working directory
805#   headf= head of the file
806  fname='draw_plot'
807
808  set -x
809
810  plot=$1
811  odir=$2
812  headf=$3
813  scratch=$4
814
815  cd ${odir}
816
817  kplot=`echo ${plot} | tr '+' ' ' | awk '{print $1}'`
818  plotvals=`echo ${plot} | tr '+' ' ' | awk '{print $2}'`
819
820  # Assuming that multiple variables will be separated by '#'
821  nvars=`echo ${plotvals} | tr '#' ' ' | wc -w | awk '{print $1}'`
822
823  # Model and experiment
824  mod=`echo ${odir} | tr '/' '\n' | tail -n 2 | head -n 1`
825  exp=`echo ${odir} | tr '/' '\n' | tail -n 1`
826
827  figfiles=''
828  varinfilen=''
829  CFvars=''
830  figvarparam=''
831  varkinds=''
832  vardims=''
833  if test ${nvars} -ge 1; then
834    figname=${kplot}_${headf}
835    iv=1
836    while test $iv -le ${nvars}; do
837      varkind=`echo ${plotvals} | tr '#' '\n' | head -n ${iv} | tail -n 1`
838      varn=`echo ${varkind} | tr '|' ' ' | awk '{print $1}'`
839      kind=`echo ${varkind} | tr '|' ' ' | awk '{print $2}'`
840      # Do we have processed the given variable?
841      nfiles=`ls -1 ${odir}/${varn}_${headf}*.nc | wc -l | awk '{print $1}'`
842      if test ${nfiles} -eq 0; then
843        echo "  "${fname}": there are no files for variable '"${varn}"' skiping it !!"
844        return
845      fi
846
847      if $(isInlist ${varmeanname} ${kind}); then 
848        vn=${varn}'mean'
849      else
850        vn=${varn}
851      fi
852      filen=`stats_filename ${varn} ${kind} ${headf}`
853      dims=`python ${pyHOME}/nc_var.py -o idims -f ${filen} | grep alldims |         \
854        awk '{print $3}'`
855
856      if test ${iv} -eq 1; then
857        varkinds=${varkind}
858        CFvars=${varn}
859        varinfilen=${vn}
860        figfiles=${filen}
861        vardims=${dims}
862        if $(isInlist ${dims} 'time'); then
863          tunits=`python ${pyHOME}/nc_var.py -o ivattrs -f ${filen} -v time |        \
864            grep units | grep -v '#' | awk '{print $3}'`
865        fi
866      else
867        varkinds=${varkinds}':'${varkind}
868        CFvars=${CFvars}':'${varn}
869        varinfilen=${varinfilen}':'${vn}
870        figfiles=${figfiles}':'${filen}
871        vardims=${vardims}':'${dims}
872      fi
873
874      figname=${figname}'_'${vn}'-'${kind}
875
876      # Getting plot variable configuration
877      specific=false
878      if $(isInlist ${specificvarplot} ${varn}); then
879        vals=`listfilter ${specificvarplot} ${varn}`
880        kvals=`listfilter ${specificvarplot} ${kind}`
881        Lkvals=`expr length ${kvals}'0'`
882        if test ${Lkvals} -gt 1; then
883          fkvals=`listfilter ${kvals} ${kplot}`
884          Lfkvals=`expr length ${fkvals}'0'`
885          if test ${Lfkvals} -gt 1; then
886            specific=true
887            minval=`echo ${fkvals} | tr '|' ' ' | awk '{print $4}'`
888            maxval=`echo ${fkvals} | tr '|' ' ' | awk '{print $5}'`
889            colorbar=`echo ${fkvals} | tr '|' ' ' | awk '{print $6}'`
890            cntformat=`echo ${fkvals} | tr '|' ' ' | awk '{print $7}'`
891            colorcnt=`echo ${fkvals} | tr '|' ' ' | awk '{print $8}'`
892          fi
893        fi
894      fi
895      if ! ${specific}; then
896        allvals=`python ${pyHOME}/drawing.py -o variable_values -S ${varn} |         \
897          grep all_values | awk '{print $3}'`
898        pyn=$?
899        ferrmsg ${pyn} ${fname} "python!'variable_values'!'${varn}'!failed#"
900        minval=`echo ${allvals} | tr ',' ' ' | awk '{print $3}'`
901        maxval=`echo ${allvals} | tr ',' ' ' | awk '{print $4}'`
902        colorbar=`echo ${allvals} | tr ',' ' ' | awk '{print $7}'`
903        cntformat='%g'
904        colorcnt='black'
905      fi
906
907      # Graphical paramters for each variable in the plot
908      if test ${iv} -eq 1; then
909        figvarparam=${minval}'|'${maxval}'|'${colorbar}'|'${cntformat}'|'${colorcnt}
910      else
911        figvarparam=${figvarparam}':'${minval}'|'${maxval}'|'${colorbar}'|'
912        figvarparam=${figvarparam}${cntformat}'|'${colorcnt}
913      fi
914
915      iv=`expr ${iv} + 1`
916    # End of number of variables of the plot
917    done
918  fi
919  figname=${figname}.${kindfig}
920
921  if ${scratch}; then rm ${figname} >& /dev/null; fi
922  if test ! -f ${figname}; then
923    case ${kplot} in
924      'diffmap2Dsfc')
925        echo "  "${fname}": kind of plot '"${kplot}"' not ready !!"
926        exit
927      ;;
928      'diffmap2Dz')
929        echo "  "${fname}": kind of plot '"${kplot}"' not ready !!"
930        exit
931      ;;
932      'map2Dsfc')
933        echo "  "${fname}": kind of plot '"${kplot}"' not ready !!"
934        exit
935      ;;
936      'map3D')
937        echo "  "${fname}": kind of plot '"${kplot}"' not ready !!"
938        exit
939      ;;
940      'shadcont2Dsfc')
941        figtit=${mod}'|'${exp}'|'$(echo ${varkinds} | tr ':' '|')
942        shdstdn=`echo ${CFvars} | tr ':' ' ' | awk '{print $1}'`
943        cntstdn=`echo ${CFvars} | tr ':' ' ' | awk '{print $2}'`
944        figfs=`echo ${figfiles} | tr ':' ','`
945        srange=`echo ${figvarparam} | tr ':' ' ' | awk '{print $1}' | tr '|' ' ' |   \
946          awk '{print $1","$2}'`
947        cbar=`echo ${figvarparam} | tr ':' ' ' | awk '{print $1}' | tr '|' ' ' |     \
948          awk '{print $3}'`
949        crange=`echo ${figvarparam} | tr ':' ' ' | awk '{print $2}' | tr '|' ' ' |   \
950          awk '{print $1","$2}'`
951        cline=`echo ${figvarparam} | tr ':' ' ' | awk '{print $2}' | tr '|' ' ' |    \
952          awk '{print $5}'`
953        cfmt=`echo ${figvarparam} | tr ':' ' ' | awk '{print $2}' | tr '|' ' ' |     \
954          awk '{print $4}'`
955
956        graphvals=$(echo ${CFvars} | tr ':' ',')
957        graphvals=${graphvals}':lon|-1,lat|-1:lon|-1,lat|-1:lon:lat:'${cbar}':fixc,'
958        graphvals=${graphvals}${cline}':'${cfmt}':'${srange}':'${crange}',9:'
959        graphvals=${graphvals}${figtit}':'${kindfig}':False:'${mapval}
960 
961        pyout=`python ${pyHOME}/drawing.py -f ${figfs} -o draw_2D_shad_cont          \
962          -S ${graphvals} -v $(echo ${varinfilen} | tr ':' ',')`
963        pyn=$?
964        Spyout=`echo ${pyout} | tr '\n' '#' | tr ' ' '!'`
965        ferrmsg ${pyn} ${fname} "python!'draw_2D_shad_cont'!failed#"${Spyout}
966        mv 2Dfields_shadow-contour.${kindfig} ${figname}
967
968        # keeping all figures
969        plotins="python "${pyHOME}"/drawing.py -f "${figfs}" -o draw_2D_shad_cont "
970        plotins=${plotins}"-S '"${graphvals}"' -v "$(echo ${varinfileb} | tr ':' ',')
971        echo " " >> ${odir}/all_figures.inf
972        echo "#"$(echo $f{igtit} | tr '|' ' ') >> ${odir}/all_figures.inf
973        echo ${plotins} >> ${odir}/all_figures.inf
974
975#        exit
976      ;;
977      'shadconthovmsfc')
978        shdstdn=`echo ${CFvars} | tr ':' ' ' | awk '{print $1}'`
979        cntstdn=`echo ${CFvars} | tr ':' ' ' | awk '{print $2}'`
980
981        # It is assumed that if the space variable is 'lon': is desired a (lon, time) plot
982        #   it it is 'lat': then (time, lat) plot
983        dimspace='xxx' 
984        if $( isInlist ${vardims} 'lon'); then
985          spacedim='lon'
986          figtit=${mod}'|'${exp}'|mean|longitudinal|evolution|of|'${shdstdn}'|&|'
987          figtit=${figtit}${cntstdn}
988          reverse='None'
989          dims=${spacedim}'|-1,time|-1;'${spacedim}'|-1,time|-1;'${spacedim}';time'
990        else
991          spacedim='lat'
992          figtit=${mod}'|'${exp}'|mean|meridional|evolution|of|'${shdstdn}'|&|'
993          figtit=${figtit}${cntstdn}
994          reverse='None'
995          dims=${spacedim}'|-1,time|-1;'${spacedim}'|-1,time|-1;time;'${spacedim}
996        fi
997
998        figfs=`echo ${figfiles} | tr ':' ','`
999        srange=`echo ${figvarparam} | tr ':' ' ' | awk '{print $1}' | tr '|' ' ' |   \
1000          awk '{print $1","$2}'`
1001        cbar=`echo ${figvarparam} | tr ':' ' ' | awk '{print $1}' | tr '|' ' ' |     \
1002          awk '{print $3}'`
1003        crange=`echo ${figvarparam} | tr ':' ' ' | awk '{print $2}' | tr '|' ' ' |   \
1004          awk '{print $1","$2}'`
1005        cline=`echo ${figvarparam} | tr ':' ' ' | awk '{print $2}' | tr '|' ' ' |    \
1006          awk '{print $5}'`
1007        cfmt=`echo ${figvarparam} | tr ':' ' ' | awk '{print $2}' | tr '|' ' ' |     \
1008          awk '{print $4}'`
1009
1010#        if test ${spacedim} = 'lon'; then
1011#          dims='lon|-1,time|-1:lon|-1,time|-1:time:lon'
1012#        else
1013#          dims='lat|-1,time|-1:lat|-1,time|-1:time:lat'
1014#        fi
1015
1016        graphvals=$(echo ${CFvars} | tr ':' ',')
1017        graphvals=${shdstdn}','${cntstdn}';'${dims}';'
1018        graphvals=${graphvals}${cbar}';fixsigc,'${cline}';'${cfmt}';'${srange}';'
1019        graphvals=${graphvals}${crange}',9;'${figtit}';'${kindfig}';'${reverse}';'
1020        graphvals=${graphvals}'time|'${tunits}'|'${timekind}'|'${timefmt}'|'
1021        graphvals=${graphvals}${timelabel}
1022
1023        python ${pyHOME}/drawing.py -f ${figfs} -o draw_2D_shad_cont_time            \
1024         -S ${graphvals} -v $(echo ${varinfilen} | tr ':' ',')
1025        mv 2Dfields_shadow-contour.${kindfig} ${figname}
1026
1027        # keeping all figures
1028        plotins="python "${pyHOME}"/drawing.py -f "${figfs}" -o draw_2D_shad_cont_time"
1029        plotins=${plotins}" -S ${graphvals} -v "$(echo ${varinfilen} | tr ':' ',')
1030        echo " " >> ${odir}/all_figures.inf
1031        echo "#"$(echo $f{igtit} | tr '|' ' ') >> ${odir}/all_figures.inf
1032        echo ${plotins} >> ${odir}/all_figures.inf
1033
1034#        exit
1035      ;;
1036      *)
1037        echo ${errormsg}
1038        echo "  "${fname}": plot kind '"${kplot}"' not ready !!"
1039        exit
1040      ;;
1041    esac
1042  fi
1043
1044#LLUIS
1045
1046}
1047
1048#######    #######
1049## MAIN
1050    #######
1051rootsh=`pwd`
1052
1053# Uploading environment
1054uploadvars model_graphics.dat
1055
1056if test ${scratch} = 'true'; then
1057  scratch=true
1058  echo ${warnmsg}
1059  echo "  "${main}": starting from the SCRATCH !!"
1060  echo "    10 seconds left!!"
1061  filescratch=true
1062  figscratch=true
1063  sleep 10
1064else
1065  scratch=false
1066  if test ${filescratch} = 'true'; then
1067    filescratch=true
1068    echo ${warnmsg}
1069    echo "  "${main}": files starting from the SCRATCH !!"
1070    echo "    5 seconds left!!"
1071    sleep 5
1072  else
1073    filescratch=false
1074  fi
1075  if test ${figscratch} = 'true'; then
1076    figscratch=true
1077    echo ${warnmsg}
1078    echo "  "${main}": figures starting from the SCRATCH !!"
1079    echo "    5 seconds left!!"
1080    sleep 5
1081  else
1082    figscratch=false
1083  fi
1084fi
1085
1086if test ${addfiles} = 'true'; then
1087  addfiles=true
1088else
1089  addfiles=false
1090fi
1091
1092if test ${addfigures} = 'true'; then
1093  addfigures=true
1094else
1095  addfigures=false
1096fi
1097
1098if test ${debug} = 'true'; then
1099  dbg=true
1100else
1101  dbg=false
1102fi
1103
1104timeval='tstep'
1105zval='null'
1106dimval='lon,lat,pressure,time'
1107
1108compute=0
1109computetlon=false
1110plot=false
1111single2Dplot=false
1112lonZsec=false
1113differences=true
1114
1115combosfile=${HOMEpy}/diagnostics.inf
1116
1117####### ###### ##### #### ### ## #
1118
1119mods=`echo ${models} | tr ':' ' '`
1120varks=`echo ${varkinds} | tr ':' ' '`
1121
1122# Models loop
1123##
1124for mod in ${mods}; do
1125  case ${mod} in
1126    'WRF')
1127      exps=`echo ${WRFexps} | tr ':' ' '`
1128      fheaders=`echo ${WRFheaders} | tr ':' ' '`
1129    ;;
1130    'LMDZ')
1131      exps=`echo ${LMDZexps} | tr ':' ' '`
1132      fheaders=`echo ${LMDZheaders} | tr ':' ' '`
1133    ;;
1134    'WRF_LMDZ')
1135      exps=`echo ${WRF_LMDZexps} | tr ':' ' '`
1136      fheaders=`echo ${WRF_LMDZheaders} | tr ':' ' '`
1137    ;;
1138    '*')
1139      echo ${errmsg}
1140      echo "  "${main}": model '"${mod}"' not ready!!"
1141      exit
1142    ;;
1143  esac 
1144
1145  modinf=`$pyHOME/nc_var.py -o model_characteristics -f None -S ${mod} | \
1146    grep singleline | awk '{print $2}'`
1147  ferrmsg $? $main "python!'model_characteristics'!failed"
1148  dnx=`echo ${modinf} | tr ';' '\n' | grep dimxn | tr '=' ' ' | awk '{print $2}'`
1149  dny=`echo ${modinf} | tr ';' '\n' | grep dimyn | tr '=' ' ' | awk '{print $2}'`
1150  dnz=`echo ${modinf} | tr ';' '\n' | grep dimzn | tr '=' ' ' | awk '{print $2}'`
1151  dnt=`echo ${modinf} | tr ';' '\n' | grep dimtn | tr '=' ' ' | awk '{print $2}'`
1152  vdnx=`echo ${modinf} | tr ';' '\n' | grep vardxn | tr '=' ' ' | awk '{print $2}'`
1153  vdny=`echo ${modinf} | tr ';' '\n' | grep vardyn | tr '=' ' ' | awk '{print $2}'`
1154  vdnz=`echo ${modinf} | tr ';' '\n' | grep vardzn | tr '=' ' ' | awk '{print $2}'`
1155  vdnt=`echo ${modinf} | tr ';' '\n' | grep vardtn | tr '=' ' ' | awk '{print $2}'`
1156  echo ${mod}
1157  echo "  dims: "${dnx}", "${dny}", "${dnz}", "${dnt}
1158  echo "  var dims: "${vdnx}", "${vdny}", "${vdnz}", "${vdnt}
1159  moddims=${dnx}','${dny}','${dnz}','${dnt}
1160  modvdims=${vdnx}','${vdny}','${vdnz}','${vdnt}
1161
1162# Experiments loop
1163##
1164  for exp in ${exps}; do
1165    echo "  "${exp}"..."
1166    iwdir=${ifold}/${mod}/${exp}
1167
1168    # Does input folder exist?
1169    if test ! -d ${iwdir}; then
1170      echo ${errmsg}
1171      echo "  "${main}": folder '"${iwdir}"' does not exist !!"
1172      exit
1173    fi
1174
1175    owdir=${ofold}/${mod}/${exp}
1176    mkdir -p ${owdir}
1177
1178    # Need to pass to analyze all the data?
1179    if ${filescratch}; then 
1180      rm ${owdir}/varcompute.inf >& /dev/null
1181      rm ${owdir}/all_computevars.inf >& /dev/null
1182      rm ${owdir}/all_statsvars.inf >& /dev/null
1183
1184      echo "## Computation of variables " > ${owdir}/all_computevars.inf
1185      echo "## Computation of statistics " > ${owdir}/all_statsvars.inf
1186    fi
1187
1188
1189    if test ! -f ${owdir}/varcompute.inf; then
1190
1191      # Does input folder has header files?
1192      cd ${iwdir}
1193      files=''
1194      testfiles=''
1195      ih=1
1196      for fh in ${fheaders}; do
1197        if ${filescratch}; then rm ${owdir}/*_${fh}*.nc >& /dev/null; fi
1198
1199        files1h=`ls -1 ${fh}* | tr '\n' '@'`
1200        Lfiles1h=`expr length ${files1h}'0'`
1201        if test ${Lfiles1h} -lt 2; then
1202          ferrmsg 1 $main "folder!:!"${iwdir}"!does!not!contain!files!"${fh}"*"
1203        fi
1204        testfiles1h=`ls -1 ${fh}* | head -n 1`
1205        if test ${ih} -eq 1; then
1206          files=${fh}'|'${files1h}
1207          testfiles=${fh}'|'${testfiles1h}
1208        else
1209          files=${files}','${fh}'|'${files1h}
1210          testfiles=${testfiles}'@'${fh}'|'${testfiles1h}
1211        fi
1212        ih=`expr ${ih} + 1`
1213      done
1214      testfs=`echo ${testfiles} | tr '@' ' '`
1215      cd ${rootsh}
1216
1217# Kind variables loop
1218##
1219      combo=false
1220      ik=1
1221      itotv=1
1222      for vark in ${varks}; do
1223        echo "    "${vark}" ..."
1224        case ${vark} in
1225          'acc')
1226            varvks=${varacc}
1227          ;;
1228          'combo')
1229            combo=true
1230            varvcombo=${varcombo}
1231            varcos=`echo ${varvcombo} | tr ':' ' '`
1232            varvks=''
1233            ivco=1
1234            for vco in ${varcos}; do
1235              vn=`echo ${vco} | tr '@' ' ' | awk '{print $1}'`
1236              if test ${ivco} -eq 1; then
1237                varvks=${vco}
1238              else
1239                varvks=${varvks}':'${vco}
1240              fi
1241              ivco=`expr ${ivco} + 1`
1242            done
1243          ;;
1244          'diff')
1245            varvks=${vardiff}
1246          ;;
1247          'direct')
1248            varvks=${vardirect}
1249          ;;
1250          'last')
1251            varvks=${varlast}
1252          ;;
1253          'Lmean')
1254            varvks=${varLmean}
1255          ;;
1256          'Lsec')
1257            varvks=${varLsec}
1258          ;;
1259          'lmean')
1260            varvks=${varlmean}
1261          ;;
1262          'lsec')
1263            varvks=${varlsec}
1264          ;;
1265          'pinterp')
1266            varvks=${varpinterp}
1267          ;;
1268          'tmean')
1269            varvks=${vartmean}
1270          ;;
1271          'xmean')
1272            varvks=${varxmean}
1273          ;;
1274          'ymean')
1275            varvks=${varymean}
1276          ;;
1277          'zsum')
1278            varvks=${varzsum}
1279          ;;
1280          '*')
1281            echo ${errmsg}
1282            echo "  "${main}": variable kind '"${vark}"' not ready!!"
1283            exit
1284          ;;
1285        esac
1286
1287# Do we have variables for this kind?
1288        Lvarvks=`expr length ${varvks}'0'`
1289        if test ${Lvarvks} -lt 2; then
1290          ferrmsg 1 ${main} "variable!kind!"${vark}"!without!variables"
1291        fi
1292        if test ${ik} -eq 1; then
1293          allvars=${varvks}
1294        else
1295          allvars=${allvars}':'${varvks}
1296        fi
1297        ik=`expr ${ik} + 1`
1298        vars=`echo ${varvks} | tr ':' ' '`
1299
1300# Variables loop
1301##
1302        iv=1
1303        for var in ${vars}; do
1304          echo "      "${var}
1305          # How to compute it?
1306          varcomp=`variable_compute ${iwdir} ${var} ${testfiles} | grep varcomp |    \
1307            awk '{print $2}'`
1308
1309          if test ${itotv} -eq 1; then
1310            varcompute=${varcomp}
1311          else
1312            varcompute=${varcompute}';'${varcomp}
1313          fi
1314
1315          iv=`expr ${iv} + 1`
1316          itotv=`expr ${itotv} + 1`
1317
1318# end loop of variables
1319        done
1320# end of kind of variables
1321      done
1322
1323      # Outwritting the varcompute to avoid next time (if it is not filescratch!)
1324      cat << EOF > ${owdir}/varcompute.inf
1325files: ${files}
1326varcompute: ${varcompute}
1327itotv: ${itotv}
1328testfs: ${testfiles}
1329EOF
1330    else
1331      echo $warnmsg
1332      echo "  "${main}": getting already data information from the experiment!"
1333      files=`cat ${owdir}/varcompute.inf | grep files | awk '{print $2}'`
1334      varcompute=`cat ${owdir}/varcompute.inf | grep varcompute | awk '{print $2}'`
1335      itotv=`cat ${owdir}/varcompute.inf | grep itotv | awk '{print $2}'`
1336      testfiles=`cat ${owdir}/varcompute.inf | grep testfs | awk '{print $2}'`
1337# End of avoiding to repeat all the experiment search
1338    fi
1339
1340    echo "  For experiment '"${exp}"' is required to compute: "${itotv}" variables"
1341# Computing files for each variable
1342##
1343    echo "      Computing all variables ..."
1344    cd $owdir
1345    ic=1
1346    isc=1
1347    cvars=`echo ${varcompute} | tr ';' ' '`
1348    for cvar in ${cvars}; do
1349      CFv=`echo ${cvar} | tr '|' ' ' | awk '{print $1}'`
1350      vark=`echo ${cvar} | tr '|' ' ' | awk '{print $2}'`
1351      fileh=`echo ${cvar} | tr '|' ' ' | awk '{print $3}'`
1352      modv=`echo ${cvar} | tr '|' ' ' | awk '{print $4}'`
1353      diagv=`echo ${cvar} | tr '|' ' ' | awk '{print $5}'`
1354      if ${dbg}; then echo "        "${CFv}"; "${modv}" "${diagv}; fi
1355
1356      if test ! ${modv} = 'None' || test ! ${diagv} = 'None'; then
1357        compute_variable ${iwdir} ${files} ${owdir} ${cvar} ${moddims} ${modvdims}   \
1358          ${filescratch}
1359        ic=`expr ${ic} + 1`
1360
1361        if test ! ${vark} = 'diff' && test ! ${vark} = 'combo'; then
1362          if test ${vark} = 'pinterp'; then
1363            fhead=${fileh}'p'
1364          else
1365            fhead=${fileh}
1366          fi
1367          compute_statistics ${iwdir} ${CFv}_${fhead}.nc ${owdir} ${cvar}            \
1368            ${moddims} ${modvdims} ${filescratch}
1369          isc=`expr ${isc} + 1`
1370        else
1371          if test ${vark} = 'diff'; then
1372            echo "  "${main}": differences will be calculated when all the "         \
1373              "model/experiments will be done !"
1374          elif test ${vark} = 'diff'; then
1375            echo "  "${main}": combos will be calculated later when all the "        \
1376              "variables will be done !"
1377          fi
1378        fi
1379      else
1380        if ${dbg}; then echo "        not '"${CFv}"' for model '"${mod}"' !!"; fi
1381      fi
1382
1383      # exit
1384# end of computing vars
1385    done
1386
1387    # Computing combos
1388    if ${combo}; then
1389      echo "      Computing combos: "${varcombo}
1390      varcos=`echo ${varcombo} | tr ':' ' '`
1391      for vco in ${varcos}; do
1392        echo "        "${vco}
1393        CFvarn=`echo ${vco} | tr ';' ' ' | awk '{print $1}'`
1394        cvar=`variable_compute ${iwdir} ${CFvarn} ${testfiles} | grep varcomp |      \
1395          awk '{print $2}'`
1396        CFv=`echo ${cvar} | tr '|' ' ' | awk '{print $1}'`
1397        vark=`echo ${cvar} | tr '|' ' ' | awk '{print $2}'`
1398        fileh=`echo ${cvar} | tr '|' ' ' | awk '{print $3}'`
1399        modv=`echo ${cvar} | tr '|' ' ' | awk '{print $4}'`
1400        diagv=`echo ${cvar} | tr '|' ' ' | awk '{print $5}'`
1401
1402        combs=`echo ${vco} | tr ';' ' ' | awk '{print $2}' | tr '@' ' '`
1403        ifile=${CFv}_${fhead}
1404        for comb in ${combs}; do
1405          combcvar=${CFv}'|'${comb}'|'${fileh}'|'${modv}'|'${diagv}
1406          compute_statistics ${iwdir} ${ifile}.nc ${owdir} ${combcvar} ${moddims}    \
1407            ${modvdims} ${filescratch} ${ifile}.nc
1408          ifile=${ifile}_${comb}
1409          isc=`expr ${isc} + 1`
1410        # End of combo
1411        done
1412      # End of combo variables
1413      done
1414    fi
1415
1416    echo "  "${main}": "${ic}" variables has been computed"
1417    echo "  "${main}": "${isc}" statistics has been computed"
1418
1419# Direct plotting
1420##
1421    echo "  "${main}": Plotting direct figures ..."
1422    if ${figscratch}; then rm directplotsdraw.inf; fi
1423    if test ! -f directplotsdraw.inf; then
1424      drwplts=`echo ${drawplots} | tr ':' ' '`
1425      ikp=1
1426      plots=''
1427      for drw in ${drwplts}; do
1428        if $(isInlist ${directplots} ${drw}); then
1429          case ${drw} in
1430            'map2Dsfc')
1431              plts=${pltmap2Dsfc}
1432            ;;
1433            'map3D')
1434              plts=${pltmap3D}
1435            ;;
1436            'shadcont2Dsfc')
1437              plts=${pltshadcont2Dsfc}
1438            ;;
1439            'shadconthovmsfc')
1440              plts=${pltshadconthovmsfc}
1441            ;;
1442            *)
1443              echo ${errmsg}
1444              echo "  "${main}": plot kind '"${drw}"' not ready !!"
1445              exit
1446          esac
1447          # Do we have plots for this kind?
1448          Lkplots=`expr length ${plts}'0'`
1449          if test ${Lkplots} -lt 2; then
1450            ferrmsg 1 ${main} "plot!kind!"${drw}"!without!variables"
1451          fi
1452          kplots=`list_add_label ${plts} ${drw} + beg`
1453          if test ${ikp} -eq 1; then
1454            plots=${kplots}
1455          else
1456            plots=${plots}':'${kplots}
1457          fi
1458          ikp=`expr ${ikp} + 1`
1459        fi
1460# End of coincident direct plots
1461      done
1462      cat << EOF > directplotsdraw.inf
1463Nkinds= ${ikp}
1464plots= ${plots}
1465EOF
1466    else
1467      echo ${warnmsg}
1468      echo "  "${main}": retrieving direct plots from existing file 'directplotsdraw.inf' !!"
1469      Nkinds=`cat directplotsdraw.inf | grep Nkinds | awk '{print $2}'`
1470      plots=`cat directplotsdraw.inf | grep plots | awk '{print $2}'`
1471    fi
1472
1473    if ${figscratch}; then rm ${owdir}/all_figures.inf; fi
1474    if test ! -f ${owdir}/all_figures.inf; then
1475      echo "###### List of all figures" > ${owdir}/all_figures.inf
1476    fi
1477
1478    pts=`echo ${plots} | tr ':' ' '`
1479    idp=1
1480    for pt in ${pts}; do
1481      echo "        "${pt}
1482      draw_plot ${pt} ${owdir} ${fileh} ${figscratch}
1483      idp=`expr ${idp} + 1`
1484    done
1485
1486    echo "  "${main}": "${idp}" direct plots hav been computed"
1487# LLUIS
1488    cd ${rootsh}
1489    exit
1490# end of experiments
1491  done
1492# end of models
1493done
1494
1495exit
1496
1497istep=0
1498
1499if test ${compute} -eq 1; then
1500  for exp in ${exps}; do
1501    echo "exp: "${exp}
1502    if test ${exp} == 'AR40'; then
1503      var2Dtmeans=${var2Dtmeans_AR40}
1504    else
1505      var2Dtmeans=${var2Dtmeans_NPv31}
1506    fi
1507    for vark in ${varks}; do
1508      echo "  vark: "${vark}
1509
1510      if test ${vark} = 'mean'; then
1511        fileorig=${ifoldmean}/${exp}/${filenmean}
1512        if test ! -f ${fileorig}; then
1513          fileworig=${filensfc}
1514          dvals='T:Time,Z:bottom_top,Y:south_north,X:west_east'
1515          dimnames='T:Time,Z:bottom_top,Y:south_north,X:west_east'
1516          python ${HOMEpy}/vertical_interpolation.py                            \
1517            -f ${ofold}/${exp}/${filensfc} -o WRFp -i ${plevels} -k 'lin'            \
1518            -v WRFt,U,V,WRFrh,WRFght -d ${dimnames} -D T:Times,Z:ZNU,Y:XLAT,X:XLONG
1519          if test $? -ne 0; then
1520            echo ${errormsg}
1521            echo "  python failed!"
1522            echo "  python ${HOMEpy}/vertical_interpolation.py"                            \
1523            "-f ${ofold}/${exp}/${filensfc} -o WRFp -i ${plevels} -k 'lin'"            \
1524            "-v WRFt,U,V,WRFrh,WRFght -d ${dimnames} -D T:Times,Z:ZNU,Y:XLAT,X:XLONG"
1525            rm ${ofold}/${exp}/vertical_interpolation_WRFp.nc >& /dev/null
1526            exit
1527          fi
1528          mv vertical_interpolation_WRFp.nc ${ofold}/${exp}
1529        fi
1530        vars=`echo ${mean_variables} | tr ':' ' '`
1531        ofile='mean_variables'
1532      elif test ${vark} = 'sfc'; then
1533        fileorig=${ifoldsfc}/${exp}/${filensfc}
1534        if test ! -f ${fileorig}; then
1535          fileworig=${filensfc}
1536          cp ${ifoldsfc}/${exp}/${fileworig} ${ifoldsfc}/${exp}/${filensfc}
1537          python ${HOMEpy}/nc_var.py -o WRF_CFxtime_creation -f ${ifoldsfc}/${exp}/${filensfc} \
1538            -S 19491201000000,hours -v time
1539          python ${HOMEpy}/nc_var.py -o WRF_CFlonlat_creation -f ${ifoldsfc}/${exp}/${filensfc}\
1540            -S longitude,latitude -v XLONG,XLAT
1541        fi
1542        if test ${exp} = 'AR40'; then
1543          vars=`echo ${sfc_variables_AR40} | tr ':' ' '`
1544        else
1545          vars=`echo ${sfc_variables_NPv31} | tr ':' ' '`
1546        fi
1547        ofile='sfc_variables'
1548      elif test ${vark} = 'diag'; then
1549        fileorig=${ifolddiag}/${exp}/${filendiag}
1550        vars=`echo ${diag_variables} | tr ':' ' '`
1551        if test ! -f ${fileorig}; then
1552          values='Time@XTIME,bottom_top@ZNU,south_north@XLAT,west_east@XLONG'
1553          ivar=0
1554          varcombos=''
1555          for var in ${vars}; do
1556            echo "    var:"${var}
1557            varn=`echo ${var} | tr '_' ' ' | awk '{print $2}'`
1558            combo=`python ${HOMEpy}/diagnostics.py -f ${combosfile} -d variable_combo -v ${varn}\
1559              | grep COMBO | awk '{print $2}'`
1560            if test ${combo} = 'ERROR'; then
1561              echo ${errormsg}
1562              echo "  No variable '"${varn}"' in '"${combosfile}"' !!"
1563              exit
1564            fi
1565            if test ${ivar} -eq 0; then
1566              varcombos=${varn}'|'${combo}
1567            else
1568              varcombos=${varcombos}','${varn}'|'${combo}
1569            fi
1570            ivar=`expr ${ivar} + 1`
1571          done
1572          python ${HOMEpy}/diagnostics.py -d ${values} -f ${ifoldsfc}/${exp}/${filensfc} -v \
1573            ${varcombos}
1574          if test $? -ne 0; then
1575            echo ${errormsg}
1576            echo "  python failed!!"
1577            echo python ${HOMEpy}/diagnostics.py -d ${values} -f ${ifoldsfc}/${exp}/${filensfc}\
1578              -v ${varcombos}
1579            exit
1580          fi
1581          python ${HOMEpy}/nc_var.py -o WRF_CFxtime_creation -f diagnostics.nc                 \
1582            -S 19491201000000,hours -v time
1583           python ${HOMEpy}/nc_var.py -o WRF_CFlonlat_creation -f diagnostics.nc               \
1584            -S longitude,latitude -v XLONG,XLAT
1585          mv diagnostics.nc ${ifolddiag}/${exp}
1586        fi
1587        ofile='diag_variables'
1588      elif test ${vark} = 'z'; then
1589        fileorig=${ifoldmean}/${exp}/${filenmean}
1590        vars=`echo ${z_variables} | tr ':' ' '`
1591        ofile='z_variables'
1592      fi
1593
1594# Averaging
1595##
1596      echo "  averaging..."
1597      ivar=0
1598      for varn in ${vars}; do
1599        file=${fileorig}
1600        echo "    var: "${varn}
1601        var=`echo ${varn} | tr '|' ' ' | awk '{print $2}'`
1602        varval=`python ${HOMEpy}/drawing.py -o variable_values -S ${var} | grep all_values | awk '{print $3}'`
1603        varname=`echo ${varval} | tr ',' ' ' | awk '{print $1}'`
1604
1605        echo "      std name: "${varname}
1606        varhead=`echo ${varname} | tr '_' ' ' | awk '{print $1}'`
1607        vartail=`echo ${varname} | tr '_' ' ' | awk '{print $2}'`
1608
1609        if test ${vark} = 'mean'; then
1610          vals='time:-1|z:-1|y:-1|x:-1,time:x,mean,pressure:lat'
1611          python ${HOMEpy}/nc_var.py -o file_oper_alongdims -S ${vals} -f ${file} -v ${var}
1612          pyexec=$?
1613          if test ${pyexec} -ne 0; then
1614            echo ${errormsg}
1615            echo "  "${main}": python fai1ls!"
1616            echo "python ${HOMEpy}/nc_var.py -o file_oper_alongdims -S ${vals} -f ${file} -v ${var}"
1617            exit
1618          else
1619            oper=`echo ${vals} | tr ',' ' ' | awk '{print $3}'`
1620            mv file_oper_alongdims_mean.nc ${ofold}/${exp}/${varname}${oper}.nc
1621          fi
1622        elif test ${vark} = 'z'; then
1623          vals='time:-1|z:-1|y:-1|x:-1,time:x,mean,pressure:lat'
1624          echo "NOT FINISHED!!!!"
1625          exit
1626        else
1627          vals='Time:-1|south_north:-1|west_east:-1,west_east,mean,time:XLAT'
1628          if test ${var} = 'ACRAINTOT'; then
1629            files='add|'${file}'|RAINC,add|'${file}'|RAINNC'
1630            python ${HOMEpy}/nc_var.py -S 'time|XLAT|XLONG@'${files} -o compute_opersvarsfiles \
1631              -v ${var}
1632            mv opersvarsfiles_${var}.nc ${ofold}/${exp}
1633            file=${ofold}/${exp}/opersvarsfiles_${var}.nc
1634          elif test ${var} = 'RAINTOT'; then
1635            dims='Time@time,bottom_top@ZNU,south_north@XLAT,west_east@XLONG'
1636            python ${HOMEpy}/diagnostics.py -d ${dims} -v 'RAINTOT|RAINC@RAINNC@time' -f ${file}
1637            mv diagnostics.nc ${ofold}/${exp}/diagnostics_${varname}.nc
1638            file=${ofold}/${exp}/diagnostics_${varname}.nc
1639            var='pr'
1640          elif test ${var} = 'cllmh'; then
1641            dims='Time@time,bottom_top@ZNU,south_north@XLAT,west_east@XLONG'
1642            clouds='cll:clm:clh'
1643            cls=`echo ${clouds} | tr ':' ' '`
1644            for cl in ${cls}; do
1645              file=${ofold}/${exp}/diagnostics.nc
1646              var=${cl}
1647              echo "    var: "${var}
1648              python ${HOMEpy}/nc_var.py -o file_oper_alongdims -S ${vals} -f ${file} -v ${cl}
1649              pyexec=$?
1650              if test ${pyexec} -ne 0; then
1651                echo ${errormsg}
1652                echo "  "${main}": python fails!"
1653                echo python ${HOMEpy}/nc_var.py -o file_oper_alongdims -S ${vals} -f ${file} -v ${cl}
1654                exit
1655              fi
1656              mv file_oper_alongdims_mean.nc ${ofold}/${exp}/${cl}${oper}.nc
1657              vals='Time:-1|south_north:-1|west_east:-1,Time,mean,XLONG:XLAT'
1658              dims='Time@time,bottom_top@ZNU,south_north@XLAT,west_east@XLONG'
1659              python ${HOMEpy}/nc_var.py -o file_oper_alongdims -S ${vals} -f ${file} -v ${cl}
1660              pyexec=$?
1661              if test ${pyexec} -ne 0; then
1662                echo ${errormsg}
1663                echo "  "${main}": python fails!"
1664                exit
1665              else
1666                oper=`echo ${vals} | tr ',' ' ' | awk '{print $3}'`
1667                mv file_oper_alongdims_mean.nc ${ofold}/${exp}/${cl}t${oper}.nc
1668              fi
1669            done
1670#            break
1671          elif test ${var} = 'WRFbils' && test ! -f ${ofold}/${exp}/diagnostics_${varname}.nc; then
1672            dims='Time@time,south_north@XLAT,west_east@XLONG'
1673            python ${HOMEpy}/diagnostics.py -d ${dims} -v 'WRFbils|HFX@LH' -f ${file}
1674            mv diagnostics.nc ${ofold}/${exp}/diagnostics_${varname}.nc
1675            file=${ofold}/${exp}/diagnostics_${varname}.nc
1676            var='bils'
1677          elif test ${var} = 'WRFprw' && test ! -f ${ofold}/${exp}/diagnostics_${varname}.nc; then
1678            dims='Time@time,bottom_top@ZNU,south_north@XLAT,west_east@XLONG'
1679            python ${HOMEpy}/diagnostics.py -d ${dims} -v 'WRFprw|WRFdens@QVAPOR' -f ${file}
1680            mv diagnostics.nc ${ofold}/${exp}/diagnostics_${varname}.nc
1681            file=${ofold}/${exp}/diagnostics_${varname}.nc
1682            var='prw'
1683          elif test ${var} = 'WRFrhs' && test ! -f ${ofold}/${exp}/diagnostics_${varname}.nc; then
1684            dims='Time@time,bottom_top@ZNU,south_north@XLAT,west_east@XLONG'
1685            python ${HOMEpy}/diagnostics.py -d ${dims} -v 'WRFrhs|PSFC@T2@Q2' -f ${file}
1686            mv diagnostics.nc ${ofold}/${exp}/diagnostics_${varname}.nc
1687            file=${ofold}/${exp}/diagnostics_${varname}.nc
1688            var='huss'
1689          elif test ${var} = 'WRFprc'; then
1690            vals='Time:-1|south_north:-1|west_east:-1,west_east,mean,time:XLAT'
1691            dims='Time@time,bottom_top@ZNU,south_north@XLAT,west_east@XLONG'
1692            var='prc'
1693          elif test ${var} = 'WRFprls'; then
1694            vals='Time:-1|south_north:-1|west_east:-1,west_east,mean,time:XLAT'
1695            dims='Time@time,bottom_top@ZNU,south_north@XLAT,west_east@XLONG'
1696            var='prls'
1697          fi
1698          if test ! -f ${ofold}/${exp}/${varname}${oper}.nc; then
1699            python ${HOMEpy}/nc_var.py -o file_oper_alongdims -S ${vals} -f ${file} -v ${var}
1700            pyexec=$?
1701            if test ${pyexec} -ne 0; then
1702              echo ${errormsg}
1703              echo "  "${main}": python fails!"
1704              exit
1705            else
1706              mv file_oper_alongdims_mean.nc ${ofold}/${exp}/${varname}${oper}.nc
1707            fi
1708          fi
1709        fi
1710
1711# Time means
1712        if $(isin_list ${var2Dtmeans} ${var}); then 
1713          echo "Computing time means!!"
1714          if test ${var} = 'cllmh'; then
1715            clouds='cll:clm:clh'
1716            clds=`echo ${clouds} | tr ':' ' '`
1717            for cld in ${clds}; do
1718              vals='Time:-1|south_north:-1|west_east:-1,Time,mean,XLONG:XLAT'
1719              dims='Time@time,bottom_top@ZNU,south_north@XLAT,west_east@XLONG'
1720              python ${HOMEpy}/nc_var.py -o file_oper_alongdims -S ${vals} -f ${file} -v ${cld}
1721              pyexec=$?
1722              if test ${pyexec} -ne 0; then
1723                echo ${errormsg}
1724                echo "  "${main}": python fails!"
1725                exit
1726              else
1727                oper=`echo ${vals} | tr ',' ' ' | awk '{print $3}'`
1728                mv file_oper_alongdims_mean.nc ${ofold}/${exp}/${cld}t${oper}.nc
1729              fi
1730            done
1731          else
1732            vals='Time:-1|south_north:-1|west_east:-1,Time,mean,XLONG:XLAT'
1733            dims='Time@time,bottom_top@ZNU,south_north@XLAT,west_east@XLONG'
1734            python ${HOMEpy}/nc_var.py -o file_oper_alongdims -S ${vals} -f ${file} -v ${var}
1735            pyexec=$?
1736            if test ${pyexec} -ne 0; then
1737              echo ${errormsg}
1738              echo "  "${main}": python fails!"
1739              exit
1740            else
1741              oper=`echo ${vals} | tr ',' ' ' | awk '{print $3}'`
1742              mv file_oper_alongdims_mean.nc ${ofold}/${exp}/${varname}t${oper}.nc
1743            fi
1744          fi
1745        fi
1746        if test ${var} = 'cllmh'; then exit; fi
1747        ivar=`expr ${ivar} + 1`
1748#        exit
1749# end of vars
1750      done
1751
1752# end of kind vars
1753    done
1754
1755  done
1756# end of compute
1757fi
1758# Longitudinal means of tmeans
1759##
1760if ${computetlon}; then
1761  echo "Computing Longitudinal means of temporal means..."
1762  for exp in ${exps}; do
1763    echo "  exp:"${exp}
1764    for tmean in ${ofold}/${exp}/*tmean.nc; do
1765      fname=`basename ${tmean}`
1766      var=`ncdump -h ${tmean} | grep float | grep mean | tr '(' ' ' | awk '{print $2}'`
1767      vals='south_north:-1|west_east:-1,west_east,mean,XLAT'
1768      dims='bottom_top@bottom_top,south_north@south_north,west_east@west_east'
1769      if test ! -f ${ofold}/${exp}/${var}t-lonmean.nc; then
1770        python ${HOMEpy}/nc_var.py -o file_oper_alongdims -S ${vals} -f ${tmean} -v ${var}
1771        pyexec=$?
1772        if test ${pyexec} -ne 0; then
1773          echo ${errormsg}
1774          echo "  "${main}": python fails!"
1775          exit
1776        else
1777          mv file_oper_alongdims_mean.nc ${ofold}/${exp}/${var}t-lonmean.nc
1778        fi
1779#      exit
1780      fi
1781    done
1782
1783  done
1784fi
1785
1786if ${plot}; then
1787# Plots
1788##
1789
1790for exp in ${exps}; do
1791  echo "exp: "${exp}
1792  for vark in ${varks}; do
1793    echo "  vark: "${vark}
1794    if test ${vark} = 'mean'; then
1795      gcoups=`echo ${graph_couples_mean} | tr ':' ' '`
1796    elif test ${vark} = 'sfc'; then
1797      if test ${exp} = 'AR40'; then
1798        gcoups=`echo ${graph_couples_sfc_AR40} | tr ':' ' '`
1799      else
1800        gcoups=`echo ${graph_couples_sfc_NPv31} | tr ':' ' '`
1801      fi
1802    elif test ${vark} = 'diag'; then
1803      gcoups=`echo ${graph_couples_diag} | tr ':' ' '`
1804    fi
1805
1806    for gpair in ${gcoups}; do
1807      shdvar=`echo ${gpair} | tr '@' ' ' | awk '{print $1}'`
1808      cntvar=`echo ${gpair} | tr '@' ' ' | awk '{print $2}'`
1809      echo "  couple: "${shdvar}'-'${cntvar}
1810      shdvals=`python ${HOMEpy}/drawing.py -o variable_values -S ${shdvar} | grep all_values | awk '{print $3}'`
1811      cntvals=`python ${HOMEpy}/drawing.py -o variable_values -S ${cntvar} | grep all_values | awk '{print $3}'`
1812      files=${ofold}'/'${exp}'/'${shdvar}'mean.nc,'${ofold}'/'${exp}'/'${cntvar}'mean.nc'
1813
1814      Lshdvals=`expr length ${shdvals}0`
1815      if test ${Lshdvals} -lt 2; then
1816        echo ${errormsg}
1817        echo "  Error in drawing_tools.py 'variables_values'!!"
1818        echo "    variable '"${shdvar}"' NOT found!"
1819        exit
1820      fi
1821
1822      Lcntvals=`expr length ${cntvals}0`
1823      if test ${Lcntvals} -lt 2; then
1824        echo ${errormsg}
1825        echo "  Error in drawing_tools.py 'variables_values'!!"
1826        echo "    variable '"${cntvar}"' NOT found!"
1827        exit
1828      fi
1829
1830      shdstdn=`echo ${shdvals} | tr ',' ' ' | awk '{print $1}'`
1831      shdcbar=`echo ${shdvals} | tr ',' ' ' | awk '{print $7}'`
1832      shdmin=`echo ${shdvals} | tr ',' ' ' | awk '{print $3}'`
1833      shdmax=`echo ${shdvals} | tr ',' ' ' | awk '{print $4}'`
1834
1835      cntstdn=`echo ${cntvals} | tr ',' ' ' | awk '{print $1}'`
1836      cntmin=`echo ${cntvals} | tr ',' ' ' | awk '{print $3}'`
1837      cntmax=`echo ${cntvals} | tr ',' ' ' | awk '{print $4}'`
1838
1839      if test ${shdstdn} = 'ERROR' || test ${cntstdn} = 'ERROR'; then
1840        echo ${errmsg}
1841        echo "  "${main}": wrong variable names!!!"
1842        echo "    shdvals: "${shdvals}
1843        echo "    cntvals: "${cntvals}
1844        echo "    shdvar: "${shdvar}" cntvar: "${cntvar}
1845        exit
1846      fi
1847
1848      cntcolor='black'
1849      cntfmt='%g'
1850
1851      if test ${gpair} = 'va@ua'; then
1852        shdmin=`echo ${shdmin} | awk '{print $1/4.}'`
1853        shdmax=`echo ${shdmax} | awk '{print $1/4.}'`
1854        cntmin=`echo ${cntmin} | awk '{print $1/3.}'`
1855        cntmax=`echo ${cntmax} | awk '{print $1 + 20.}'`
1856      elif test ${gpair} = 'tas@ps'; then
1857        shdmin=`echo ${shdmin} | awk '{print $1 + 50.}'`
1858        shdmax=`echo ${shdmax} | awk '{print $1 - 15.}'`
1859        cntmin=`echo ${cntmin} | awk '{print $1 + 15000.}'`
1860        cntmax=`echo ${cntmax} | awk '{print $1 - 2000.}'`
1861      elif test ${gpair} = 'uas@vas'; then
1862        cntmin=`echo ${cntmin} | awk '{print $1 * 0.1}'`
1863        cntmax=`echo ${cntmax} | awk '{print $1 * 0.1}'`
1864      elif test ${gpair} = 'pr@rsds'; then
1865#        shdmax=`echo ${shdmax} | awk '{print $1 / 20.}'`
1866        cntmax=`echo ${cntmax} | awk '{print $1 / 3.}'`
1867      elif test ${gpair} = 'clt@cll' || test ${gpair} = 'clh@clm'; then
1868        cntcolor='red'
1869        cntfmt='%.1g'
1870      elif test ${gpair} = 'clh@clm'; then
1871        cntmax=`echo ${cntmax} | awk '{print $1}'`
1872      elif test ${gpair} = 'prw@huss'; then
1873        shdmax=`echo ${shdmax} | awk '{print $1*4}'`
1874      elif test ${gpair} = 'prls@prc'; then
1875        shdmax=`echo ${shdmax} | awk '{print $1/1.}'`
1876        cntmax=`echo ${cntmax} | awk '{print $1 * 0.5}'`
1877      elif test ${gpair} = 'hfls@hfss'; then
1878        cntmin='-50.'
1879        cntmax='50.'
1880      fi
1881 
1882      if test ${vark} = 'mean'; then
1883        graphvals=${shdstdn}','${cntstdn}':z|-1,y|-1:z|-1,y|-1:lat:pressure:'
1884        graphvals=${graphvals}${shdcbar}':fixsigc,'${cntcolor}':'${cntfmt}':'${shdmin}','
1885        graphvals=${graphvals}${shdmax}':'${cntmin}','${cntmax}',9:LMDZ+WRF|'${exp}
1886        graphvals=${graphvals}'|meridional|monthly|average|of|'${shdstdn}'|&|'
1887        graphvals=${graphvals}${cntstdn}':pdf:flip@y:None'
1888      else
1889        graphvals=${shdstdn}','${cntstdn}':y|-1,time|-1:y|-1,time|-1:time:XLAT:'
1890        graphvals=${graphvals}${shdcbar}':fixsigc,'${cntcolor}':'${cntfmt}':'${shdmin}','
1891        graphvals=${graphvals}${shdmax}':'${cntmin}','${cntmax}',9:WRF+LMDZ|'${exp}
1892        graphvals=${graphvals}'|mean|meridional|evolution|of|'${shdstdn}'|&|'
1893        graphvals=${graphvals}${cntstdn}':pdf:None:time|hours!since!1949-12-01|'
1894        graphvals=${graphvals}'exct,5,d|%d|date!([DD]):None'
1895      fi
1896
1897      echo ${files}
1898      echo ${graphvals}
1899      echo ${shdstdn}'mean,'${cntstdn}'mean'
1900
1901      if test ${vark} = 'sfc' || test ${vark} = 'diag' && 
1902       ! $(isin_list ${coup2D} ${gpair}); then
1903        python ${HOMEpy}/drawing.py -f ${files} -o draw_2D_shad_cont_time -S ${graphvals} -v   \
1904          ${shdstdn}'mean,'${cntstdn}'mean'
1905        pyexc=$?
1906      else
1907        python ${HOMEpy}/drawing.py -f ${files} -o draw_2D_shad_cont -S ${graphvals} -v        \
1908          ${shdstdn}'mean,'${cntstdn}'mean'
1909        pyexc=$?
1910      fi
1911      if test ${pyexc} -ne 0; then
1912        echo ${errormsg}
1913        echo "  "${main}": drawing.py fails!"
1914        exit
1915      else
1916        mv 2Dfields_shadow-contour.pdf ${ofold}/${exp}/${shdvar}mean_${cntvar}mean.pdf
1917        evince ${ofold}/${exp}/${shdvar}mean_${cntvar}mean.pdf &
1918      fi
1919
1920      if $(isin_list ${coup2D} ${gpair}); then
1921        graphvals=${shdstdn}','${cntstdn}':south_north|-1,west_east|-1:'
1922        graphvals=${graphvals}'south_north|-1,west_east|-1:longitude:latitude:'
1923        graphvals=${graphvals}${shdcbar}':fixsigc,'${cntcolor}':'${cntfmt}':'${shdmin}','
1924        graphvals=${graphvals}${shdmax}':'${cntmin}','${cntmax}',9:LMDZ+WRF|'${exp}
1925        graphvals=${graphvals}'|monthly|average|of|'${shdstdn}'|&|'
1926        graphvals=${graphvals}${cntstdn}':pdf:flip@y:None'
1927        echo '  '${shdstdn}'mean,'${cntstdn}'mean'
1928
1929        python ${HOMEpy}/drawing.py -f ${files} -o draw_2D_shad_cont -S ${graphvals} -v        \
1930          ${shdstdn}'mean,'${cntstdn}'mean'
1931        pyexc=$?
1932        if test ${pyexc} -ne 0; then
1933          echo ${errormsg}
1934          echo "  "${main}": drawing.py fails!"
1935          exit
1936        else
1937          mv 2Dfields_shadow-contour.pdf ${ofold}/${exp}/${shdvar}tmean_${cntvar}tmean.pdf
1938          evince ${ofold}/${exp}/${shdvar}tmean_${cntvar}tmean.pdf &
1939        fi
1940      fi
1941#      exit
1942
1943# end of couples
1944    done
1945# end of kinds
1946  done
1947
1948done
1949fi
1950
1951# 2D single plots
1952##
1953if ${single2Dplot}; then
1954  echo "2D single plots"
1955  for exp in ${exps}; do
1956    echo "  exp:"${exp}
1957    for tmean in ${ofold}/${exp}/*tmean.nc ;do
1958      fname=`basename ${tmean}`
1959      var=`ncdump -h ${tmean} | grep float | grep mean | tr '(' ' ' | awk '{print $2}'`
1960      if test ! ${var} = 'cltmean'; then
1961        shdvals=`python ${HOMEpy}/drawing.py -o variable_values -S ${var} |          \
1962          grep all_values | awk '{print $3}'`
1963        cbar=`echo ${shdvals} | tr ',' ' ' | awk '{print $7}'`
1964        min=`echo ${shdvals} | tr ',' ' ' | awk '{print $3}'`
1965        max=`echo ${shdvals} | tr ',' ' ' | awk '{print $4}'`
1966
1967        if test ${var} = 'prlsmean'; then xtrms='0,0.00015';
1968        elif test ${var} = 'prwmean'; then xtrms='0,40';
1969        elif test ${var} = 'psmean'; then xtrms='99000,102500';
1970        elif test ${var} = 'r2mean'; then xtrms='0,0.025';
1971        elif test ${var} = 'tasmean'; then xtrms='275,310';
1972        elif test ${var} = 'tmlamean'; then xtrms='260,310';
1973        elif test ${var} = 'uasmean'; then xtrms='-20,20';
1974        elif test ${var} = 'vasmean'; then xtrms='-20,20';
1975        else xtrms=${min}','${max}; fi
1976
1977#        vals=${var}':XLONG|-1,XLAT|-1:XLONG:XLAT:'${cbar}':'${xtrms}':monthly|mean:pdf:'
1978#        vals=${vals}'None:None:true'
1979#        dims='south_north@XLAT,west_east@XLONG'
1980        python ${HOMEpy}/nc_var.py -o WRF_CFlonlat_creation -S longitude,latitude    \
1981          -f ${tmean} -v XLONG,XLAT
1982        vals=${var}':longitude|-1,latitude|-1:longitude:latitude:'${cbar}':'${xtrms}':monthly|mean:pdf:'
1983        vals=${vals}'None:None:true'
1984        dims='south_north@latitude,west_east@longitude'
1985        python ${HOMEpy}/drawing.py -o draw_2D_shad -S ${vals} -f ${tmean} -v ${var}
1986        pyexec=$?
1987        if test ${pyexec} -ne 0; then
1988          echo ${errormsg}
1989          echo "  "${main}": python fails!"
1990          exit
1991        else
1992          mv 2Dfields_shadow.pdf ${ofold}/${exp}/${var}tmean.pdf
1993#          evince ${ofold}/${exp}/${var}tmean.pdf &
1994#          exit
1995        fi
1996      fi
1997    done
1998  done
1999fi
2000
2001# lon 2 vertical section
2002##
2003echo "lon 2 vertical section ..."
2004vars=`echo ${lon2DZsecvars} | tr ':' ' '`
2005pts=`echo ${lon2DZsecpts} | tr ':' ' '`
2006
2007if ${lonZsec}; then
2008  for exp in ${exps}; do
2009    file=${ofold}/${exp}/vertical_interpolation_WRFp.nc
2010#    python ${HOMEpy}/nc_var.py -o WRF_CFlonlat_creation -S longitude,latitude        \
2011#     -f ${file} -v lon,lat
2012## ALREADY done!
2013#    python ${HOMEpy}/nc_var.py -o valmod -S lowthres@oper,0.,sumc,360. -f ${file}    \
2014#       -v lon
2015    if test ${exp} = 'AR40'; then labexp='wlmdza'
2016    else labexp='wlmdzb'; fi
2017
2018    for pt in ${pts}; do
2019      echo "  pt: "${pt}
2020      vals='x:15|y:'${pt}'|time:23'
2021      lonval=`python ${HOMEpy}/nc_var.py -o varout -f ${file} -S ${vals} -v lon |    \
2022        awk '{print $2}'`
2023      latval=`python ${HOMEpy}/nc_var.py -o varout -f ${file} -S ${vals} -v lat |    \
2024        awk '{print $2}'`
2025      tval=`python ${HOMEpy}/nc_var.py -o varout -f ${file} -S ${vals} -v time |     \
2026        awk '{print $2}'`
2027      for var in ${vars}; do
2028        echo "    var: "${var}
2029
2030        shdvals=`python ${HOMEpy}/drawing.py -o variable_values -S ${var} |          \
2031          grep all_values | awk '{print $3}'`
2032        cbar=`echo ${shdvals} | tr ',' ' ' | awk '{print $7}'`
2033        min=`echo ${shdvals} | tr ',' ' ' | awk '{print $3}'`
2034        max=`echo ${shdvals} | tr ',' ' ' | awk '{print $4}'`
2035
2036# WRFt,U,V,WRFrh,WRFght
2037        if test ${var} = 'WRFght'; then xtrms='0,40000';
2038        elif test ${var} = 'WRFt'; then xtrms='200,300';
2039        elif test ${var} = 'U'; then xtrms='-40,40';
2040        elif test ${var} = 'V'; then xtrms='-20,20';
2041        else xtrms=${min}','${max}; fi
2042
2043# Plotting
2044        vals=${var}':x|-1,y|'${pt}',z|-1,time|24:lon:pressure:'${cbar}':'
2045        vals=${vals}${xtrms}':'${labexp}'|vertical|longitudinal|section|('${latval}
2046        vals=${vals}'$^{\circ}$):pdf:flip@y:None:true'
2047        python ${HOMEpy}/drawing.py -o draw_2D_shad -S ${vals} -f ${file} -v ${var}
2048        pyexec=$?
2049        if test ${pyexec} -ne 0; then
2050          echo ${errormsg}
2051          echo "  "${main}": python fails!"
2052          exit
2053        else
2054          mv 2Dfields_shadow.pdf ${ofold}/${exp}/${var}_lonZsec_${pt}pt.pdf
2055          evince ${ofold}/${exp}/${var}_lonZsec_${pt}pt.pdf &
2056        fi
2057
2058        cntcolor='black'
2059        cntfmt='%g'
2060
2061        if test ${var} = 'WRFght'; then cxtrms='0,40000';
2062        elif test ${var} = 'WRFt'; then cxtrms='200,300';
2063        elif test ${var} = 'U'; then cxtrms='-40,40';
2064        elif test ${var} = 'V'; then cxtrms='-20,20';
2065        else cxtrms=${min}','${max}; fi
2066
2067        graphvals=${var}','${var}':x|-1,y|'${pt}',z|-1,time|24:'
2068        graphvals=${graphvals}'x|-1,y|'${pt}',z|-1,time|24:lon:pressure:'
2069        graphvals=${graphvals}${cbar}':fixsigc,'${cntcolor}':'${cntfmt}':'${xtrms}':'
2070        graphvals=${graphvals}${cxtrms}',15:'${labexp}
2071        graphvals=${graphvals}'|vertical|zonal|section|('${latval}'$^{\circ}$):pdf:'
2072        graphvals=${graphvals}'flip@y:None'
2073
2074        python ${HOMEpy}/drawing.py -o draw_2D_shad_cont -S ${graphvals}             \
2075          -f ${file},${file} -v ${var},${var}
2076        pyexec=$?
2077        if test ${pyexec} -ne 0; then
2078          echo ${errormsg}
2079          echo "  "${main}": python fails!"
2080          exit
2081        else
2082          mv 2Dfields_shadow-contour.pdf ${ofold}/${exp}/${var}_lonZsec-cnt_${pt}pt.pdf
2083          evince ${ofold}/${exp}/${var}_lonZsec-cnt_${pt}pt.pdf &
2084        fi
2085
2086#        exit
2087      done
2088    done
2089  done
2090fi
2091
2092echo "Computing differences"
2093exp1=`echo ${experiments} | tr ':' ' ' | awk '{print $1}'`
2094exp2=`echo ${experiments} | tr ':' ' ' | awk '{print $2}'`
2095
2096diffks=`echo ${diffkinds} | tr ':' ' '`
2097
2098if test ${differences}; then
2099  for kind in ${diffks}; do
2100    echo ${kind}
2101    case ${kind} in
2102      'diffZ')
2103        vars=`echo ${diffZvars} | tr ':' ' '`
2104        fileorigd='mean.nc'
2105      ;;
2106      'diffH')
2107        vars=`echo ${diffHvars} | tr ':' ' '`
2108        fileorigd='tmean.nc'
2109      ;;
2110    esac
2111
2112    echo "  "${var}
2113    for var in ${vars}; do
2114      if test ! -f ${ofold}/${var}_diff.nc; then
2115#        cdo sub ${ofold}/${exp1}/${var}${fileorigd} ${ofold}/${exp2}/${var}${fileorigd} ${ofold}/${var}_diff.nc
2116        if test ${kind} = 'diffZ'; then
2117          values='pressure|lat@add|'${ofold}'/'${exp1}'/'${var}${fileorigd}'|'${var}'mean,'
2118          values=${values}'sub|'${ofold}'/'${exp2}'/'${var}${fileorigd}'|'${var}'mean'
2119          python ${HOMEpy}/nc_var.py -o compute_opersvarsfiles -S ${values} -v ${var}
2120          pyexec=$?
2121          if test ${pyexec} -ne 0; then
2122            echo ${errormsg}
2123            echo "  "${main}": python fails!"
2124            exit
2125          fi
2126          mv opersvarsfiles_${var}.nc ${ofold}/${var}_diff.nc
2127        else
2128          values='longitude|latitude@add|'${ofold}'/'${exp1}'/'${var}${fileorigd}'|'${var}'mean,'
2129          values=${values}'sub|'${ofold}'/'${exp2}'/'${var}${fileorigd}'|'${var}'mean'
2130          python ${HOMEpy}/nc_var.py -o compute_opersvarsfiles -S ${values} -v ${var}
2131          pyexec=$?
2132          if test ${pyexec} -ne 0; then
2133            echo ${errormsg}
2134            echo "  "${main}": python fails!"
2135            exit
2136          fi
2137          mv opersvarsfiles_${var}.nc ${ofold}/${var}_diff.nc
2138        fi
2139      fi
2140    done
2141
2142    if test ${kind} = 'diffZ'; then
2143      coups=`echo ${graph_couples_mean} | tr ':' ' '`
2144      for coup in ${coups}; do
2145        shdvar=`echo ${coup} | tr '@' ' ' | awk '{print $1}'`
2146        cntvar=`echo ${coup} | tr '@' ' ' | awk '{print $2}'`
2147
2148        echo "  couple: "${shdvar}'-'${cntvar}
2149
2150        shdvals=`python ${HOMEpy}/drawing.py -o variable_values -S ${shdvar} | grep all_values | awk '{print $3}'`
2151        cntvals=`python ${HOMEpy}/drawing.py -o variable_values -S ${cntvar} | grep all_values | awk '{print $3}'`
2152        files=${ofold}'/'${shdvar}'_diff.nc,'${ofold}'/'${cntvar}'_diff.nc'
2153
2154        shdstdn=`echo ${shdvals} | tr ',' ' ' | awk '{print $1}'`
2155        shdcbar=`echo ${shdvals} | tr ',' ' ' | awk '{print $7}'`
2156        shdmin=`echo ${shdvals} | tr ',' ' ' | awk '{print $3}'`
2157        shdmax=`echo ${shdvals} | tr ',' ' ' | awk '{print $4}'`
2158
2159        cntstdn=`echo ${cntvals} | tr ',' ' ' | awk '{print $1}'`
2160        cntmin=`echo ${cntvals} | tr ',' ' ' | awk '{print $3}'`
2161        cntmax=`echo ${cntvals} | tr ',' ' ' | awk '{print $4}'`
2162
2163        shdcbar='seismic'
2164        if test ${coup} = 'va@ua'; then
2165          shdmin=-4.
2166          shdmax=4.
2167          cntmin=-10.
2168          cntmax=10.
2169        elif test ${coup} = 'hus@ta'; then 
2170          shdmin=-0.2
2171          shdmax=0.2
2172          cntmin=-2.
2173          cntmax=2.
2174        fi
2175
2176        cntcolor='black'
2177        cntfmt='%g'
2178
2179        graphvals=${shdstdn}','${cntstdn}':x|-1,y|-1,x_2|-1:x|-1,y|-1,x_2|-1:lat:'
2180        graphvals=${graphvals}'pressure:'${shdcbar}':fixsigc,'${cntcolor}':'${cntfmt}':'
2181        graphvals=${graphvals}${shdmin}','${shdmax}':'${cntmin}','${cntmax}',9:'
2182        graphvals=${graphvals}${exp1}'-'${exp2}'|meridional|monthly|average|differences|of|'
2183        graphvals=${graphvals}${shdstdn}'|&|'${cntstdn}':pdf:flip@y:None'
2184
2185        python ${HOMEpy}/drawing.py -o draw_2D_shad_cont -S ${graphvals}             \
2186          -f ${files} -v ${shdvar},${cntvar}
2187        pyexec=$?
2188        if test ${pyexec} -ne 0; then
2189          echo ${errormsg}
2190          echo "  "${main}": python fails!"
2191          exit
2192        else
2193          mv 2Dfields_shadow-contour.pdf ${ofold}/${shdvar}-${cntvar}_diff.pdf
2194          evince ${ofold}/${shdvar}-${cntvar}_diff.pdf &
2195        fi
2196      done
2197#      exit
2198    else
2199      for var in ${vars}; do
2200        echo "  "${var}
2201        vals=`python ${HOMEpy}/drawing.py -o variable_values -S ${var} | grep all_values | awk '{print $3}'`
2202        file=${ofold}/${var}_diff.nc
2203
2204        stdn=`echo ${vals} | tr ',' ' ' | awk '{print $1}'`
2205        cbar='seismic'
2206
2207        if test ${var} = 'uas'; then xtrms='-10.,10.';
2208        elif test ${var} = 'vas'; then xtrms='-5,5';
2209        elif test ${var} = 'ps'; then xtrms='-500,500';
2210        elif test ${var} = 'pr'; then xtrms='-0.001,0.001';
2211        else xtrms=${min}','${max}; fi
2212
2213        vals=${var}':x|-1,y|-1:longitude:latitude:'${cbar}':'
2214        vals=${vals}${xtrms}':'${exp1}'-'${exp2}'|meridional|monthly|average|differences:'
2215        vals=${vals}'pdf:None:None:true'
2216        python ${HOMEpy}/drawing.py -o draw_2D_shad -S ${vals} -f ${file} -v ${var}
2217        pyexec=$?
2218        if test ${pyexec} -ne 0; then
2219          echo ${errormsg}
2220          echo "  "${main}": python fails!"
2221          exit
2222        else
2223          mv 2Dfields_shadow.pdf ${ofold}/${var}_diff.pdf
2224          evince ${ofold}/${var}_diff.pdf &
2225        fi
2226#        exit
2227      done
2228    fi
2229  done
2230fi
Note: See TracBrowser for help on using the repository browser.