source: lmdz_wrf/trunk/tools/obs-sim_Comparison.bash @ 2011

Last change on this file since 2011 was 2009, checked in by lfita, 7 years ago

Fixing creation of new dimension in `netcdf_fold_concatenated_HMT.nc'

  • Property svn:executable set to *
File size: 55.5 KB
Line 
1#!/bin/bash -x
2# Shell script to compare observations with simulations using PyNCplot
3#
4#   observations: different files from create_OBSnetcdf.py and/or UWyoming_snd_nc.py
5#   simulations: multiple outputs from different models and runs
6#
7
8# Name of the file with the configuration
9if test $1 = '-h'; then
10  echo "************************************************"
11  echo "***            Script to compare             ***"
12  echo "*** sounding and single-station observations ***"
13  echo "***         with multiple simulations        ***"
14  echo "************************************************"
15  echo "obs-sim_Comparison [ConfFile](configuration file)"
16else
17  rootsh=`pwd`
18
19  configfname=$1
20
21####### ###### ##### #### ### ## #
22
23function uploadvars() {
24# Function to upload variables to the system from an ASCII file as:
25#   [varname] = [value]
26  fileval=$1
27  errormsg='ERROR -- error -- ERROR -- error'
28
29  if test ! -f ${fileval}; then
30    echo ${errormsg}
31    echo "  "${fname}": file '"${fileval}"' does not exist!!"
32    exit
33  fi
34
35  Nlin=`wc -l ${fileval} | awk '{print $1}'`
36
37  ilin=1
38  while test ${ilin} -le ${Nlin}; do
39    line=`head -n ${ilin} ${fileval} | tail -n 1`
40    varname=`echo ${line} | tr '=' ' ' | awk '{print $1}'`
41    value=`echo ${line} | tr '=' ' ' | awk '{print $2}'`
42    Lvarname=`expr length ${varname}'0'`
43
44    if test ${Lvarname} -gt 1 && test ! ${varname:0:1} = '#'; then
45      export ${varname}=${value}
46    fi
47    ilin=`expr ${ilin} + 1`
48  done 
49}
50
51uploadvars ${configfname}
52echo "END upload -- end UPLOAD -- END upload -- end UPLOAD"
53
54# files from scratch
55if test; then ${fscratch} = 'true'; fscratch=true
56else fscratch=false; fi
57
58# figures from scratch
59if test; then ${gscratch} = 'true'; gscratch=true
60else gscratch=false; fi
61
62function num_hex(){
63# Fucntion to transform a number to a hexagonal basis
64#   num: number to transform
65  fname='num_hex'
66  num=$1
67
68  if test ${num} -gt 255; then
69    echo ${errormsg}
70    echo "  "${fname}": value "${num}" too large !!"
71    exit
72  fi
73  if test ${num} -gt 16; then
74    xviA=`expr ${num} / 16`
75    numA=`expr ${xviA} '*' 16`
76    xviB=`expr ${num} - ${numA}`
77  else
78    xviA=0
79    xviB=${num}
80  fi
81
82  if test ${xviA} -gt 9; then
83    case ${xviA} in
84      10)
85        hexA='A'
86      ;;
87      11)
88        hexA='B'
89      ;;
90      12)
91        hexA='C'
92      ;;
93      13)
94        hexA='D'
95      ;;
96      14)
97        hexA='E'
98      ;;
99      15)
100        hexA='F'
101      ;;
102    esac
103  else
104    hexA=${xviA}
105  fi
106
107  if test ${xviB} -gt 9; then
108    case ${xviB} in
109      10)
110        hexB='A'
111      ;;
112      11)
113        hexB='B'
114      ;;
115      12)
116        hexB='C'
117      ;;
118      13)
119        hexB='D'
120      ;;
121      14)
122        hexB='E'
123      ;;
124      15)
125        hexB='F'
126      ;;
127    esac
128  else
129    hexB=${xviB}
130  fi
131
132  echo ${hexA}${hexB}
133}
134
135function isin_list() {
136# Function to check whether a value is in a list
137  list=$1
138  value=$2
139 
140  is=`echo ${list} | tr ':' '\n' | awk '{print "@"$1"@"}' | grep '@'${value}'@' | wc -w`
141  if test ${is} -eq 1
142  then
143    true
144  else
145    false
146  fi
147}
148
149function get_WRFsounding_data(){
150# Function to get the data to compute analysis in a sounding point
151#   stlon= longitude value of the station
152#   stlat= latitude value of the station
153#   filen= name of the file
154#   lonvarn= name of the longitude variable
155#   latvarn= name of the latitude variable
156#   snddiagnames= diagnostics to compute (as ':' separated list)
157#   snddiagd= name of the dimensions and dimension variables to use for diagnostics
158
159  funcvals=$1
160
161  stlon=`echo ${funcvals} | tr '#' ' ' | awk '{print $1}'`
162  stlat=`echo ${funcvals} | tr '#' ' ' | awk '{print $2}'`
163  filen=`echo ${funcvals} | tr '#' ' ' | awk '{print $3}'`
164  lonvarn=`echo ${funcvals} | tr '#' ' ' | awk '{print $4}'`
165  latvarn=`echo ${funcvals} | tr '#' ' ' | awk '{print $5}'`
166  snddiagnames=`echo ${funcvals} | tr '#' ' ' | awk '{print $6}'`
167  snddiagd=`echo ${funcvals} | tr '#' ' ' | awk '{print $7}'`
168
169  vals=${lonvarn}':'${latvarn}':Time|0'
170  gridsndv=`python ${pyHOME}/nc_var.py -o get_point -f ${filen} -S ${vals}           \
171    -v ${stlon},${stlat} | tr ' ' '!'`
172  echo "* get grid point: "${stlon}", "${stlat} >> ${ofileins}
173  echo python ${pyHOME}/nc_var.py -o get_point -f ${filen} -S "'"${vals}"'"          \
174    -v ${stlon},${stlat} >> ${ofileins}
175  echo " " >> ${ofileins}
176
177  xsnd=`echo ${gridsndv} | tr '!' ' ' | awk '{print $1}' | tr ',' ' ' |              \
178   awk '{print $1}'`
179  ysnd=`echo ${gridsndv} | tr '!' ' ' | awk '{print $1}' | tr ',' ' ' |              \
180  awk '{print $2}'`
181  dsnd=`echo ${gridsndv} | tr '!' ' ' | awk '{print $2}'`
182
183  xsnd1=`expr ${xsnd} + 1`
184  ysnd1=`expr ${ysnd} + 1`
185
186  # Getting values
187  if ${fscratch}; then rm ${simsndptf} >& /dev/null; fi
188  if test ! -f ${simsndptf}; then
189    values='Time,0,-1,1@bottom_top,0,-1,1@south_north,'${ysnd}','${ysnd}',1@'
190    values=${values}'west_east,'${xsnd}','${xsnd}',1@south_north_stag,'${ysnd}','
191    values=${values}${ysnd1}',1@west_east_stag,'${xsnd}','${xsnd1}',1:False'
192    python ${pyHOME}/nc_var.py -o DataSetSection_multidims -f ${filen}               \
193      -S ${values} -v all
194    if test $? -ne 0; then
195      echo ${errmsg}
196      echo "  python failed!!"
197      echo python ${pyHOME}/nc_var.py -o DataSetSection_multidims -f ${filen}        \
198        -S "'"${values}"'" -v all
199      exit
200    fi
201    echo "* get values at snd point: "${stlon}", "${stlat} >> ${ofileins}
202    echo python ${pyHOME}/nc_var.py -o DataSetSection_multidims -f ${filen}          \
203      -S "'"${values}"'" -v all >> ${ofileins}
204    echo " " >> ${ofileins}
205
206    yslc='south_north_B'${ysnd}'-E'${ysnd}'-I1'
207    ystslc='south_north_stag_B'${ysnd}'-E'${ysnd1}'-I1'
208    xslc='west_east_B'${xsnd}'-E'${xsnd}'-I1'
209    xstslc='west_east_stag_B'${xsnd}'-E'${xsnd1}'-I1'
210
211    Hfilen=`basename ${filen}`
212    Dfilen=`dirname ${filen}`
213    Hhfilen=`echo ${Hfilen} | tr '.' ' ' | awk '{print $1}'`
214
215    ofilen='newfile_multidims.nc'
216    mv ${ofilen} ${simsndptf}
217  fi
218   
219  # Computing sounding diagnostics
220  diagns=`echo ${snddiagnames} | tr ':' ' '`
221
222  idiag=1
223  for diagn in ${diagns}; do
224    diagv=`cat $pyHOME/diagnostics.inf | grep ${diagn}',' | tr ',' ' ' |             \
225      awk '{print $2"|"$3}'`
226    if test ${idiag} -eq 1; then
227      snddiagvals=${diagv}
228    else
229      snddiagvals=${snddiagvals}','${diagv}
230    fi
231    idiag=`expr ${idiag} + 1`
232  done
233
234  if ${fscratch}; then rm ${simsnddiagsf}; fi
235  if test ! -f ${simsnddiagsf}; then
236    python ${pyHOME}/diagnostics.py -f ${simsndptf} -d ${snddiagd} -v ${snddiagvals}
237    if test $? -ne 0; then
238      echo ${errmsg}
239      echo "  python failed!!"
240      echo python ${pyHOME}/diagnostics.py -f ${simsndptf} -d "'"${snddiagd}"'" -v   \
241        "'"${snddiagvals}"'"
242      exit
243    fi
244    echo "* computing diagnostics at snd point: "${stlon}", "${stlat} >> ${ofileins}
245    echo python ${pyHOME}/diagnostics.py -f "'"${simsndptf}"'" -d "'"${snddiagd}"'"  \
246      -v "'"${snddiagvals}"'" >> ${ofileins}
247    echo " " >> ${ofileins}
248
249    mv diagnostics.nc ${simsnddiagsf}
250    if $(isin_list ${snddiagnames} WRFt); then
251      #To deg
252      python ${pyHOME}/nc_var.py -o valmod -S subc,273.15 -f ${simsnddiagsf} -v ta
253    fi
254    if $(isin_list ${snddiagnames} WRFp); then
255      #To Pa
256      python ${pyHOME}/nc_var.py -o valmod -S divc,100. -f ${simsnddiagsf} -v pres
257    fi
258  fi
259}
260
261function get_WRFsurface_data(){
262# Function to get the data to compute analysis in a surface point
263#   stlon= longitude value of the station
264#   stlat= latitude value of the station
265#   filen= name of the file
266#   lonvarn= name of the longitude variable
267#   latvarn= name of the latitude variable
268#   sfcdiagnames= diagnostics to compute (as ':' separated list)
269#   nondiagvs= ':' list of variables which are not from a diagnostics ('None' for
270#     without)
271#   sfcdiagd= name of the dimensions and dimension variables to use for diagnostics
272
273  funcvals=$1
274
275  stlon=`echo ${funcvals} | tr '#' ' ' | awk '{print $1}'`
276  stlat=`echo ${funcvals} | tr '#' ' ' | awk '{print $2}'`
277  filen=`echo ${funcvals} | tr '#' ' ' | awk '{print $3}'`
278  lonvarn=`echo ${funcvals} | tr '#' ' ' | awk '{print $4}'`
279  latvarn=`echo ${funcvals} | tr '#' ' ' | awk '{print $5}'`
280  sfcdiagnames=`echo ${funcvals} | tr '#' ' ' | awk '{print $6}'`
281  nondiagvs=`echo ${funcvals} | tr '#' ' ' | awk '{print $7}'`
282  sfcdiagd=`echo ${funcvals} | tr '#' ' ' | awk '{print $8}'`
283
284  vals=${lonvarn}':'${latvarn}':Time|0'
285  gridsndv=`python ${pyHOME}/nc_var.py -o get_point -f ${filen} -S ${vals}           \
286    -v ${stlon},${stlat} | tr ' ' '!'`
287  echo "* get grid point: "${stlon}", "${stlat} >> ${ofileins}
288  echo python ${pyHOME}/nc_var.py -o get_point -f ${filen} -S "'"${vals}"'"          \
289    -v ${stlon},${stlat} >> ${ofileins}
290  echo " " >> ${ofileins}
291  xsnd=`echo ${gridsndv} | tr '!' ' ' | awk '{print $1}' | tr ',' ' ' |              \
292   awk '{print $1}'`
293  ysnd=`echo ${gridsndv} | tr '!' ' ' | awk '{print $1}' | tr ',' ' ' |              \
294  awk '{print $2}'`
295  dsnd=`echo ${gridsndv} | tr '!' ' ' | awk '{print $2}'`
296
297  xsnd1=`expr ${xsnd} + 1`
298  ysnd1=`expr ${ysnd} + 1`
299
300  # Getting values
301  if ${fscratch}; then rm ${simsfcptf} >& /dev/null; fi
302  if test ! -f ${simsfcptf}; then
303    values='Time,0,-1,1@south_north,'${ysnd}','${ysnd}',1@'
304    values=${values}'west_east,'${xsnd}','${xsnd}',1@south_north_stag,'${ysnd}','
305    values=${values}${ysnd1}',1@west_east_stag,'${xsnd}','${xsnd1}',1:False'
306    python ${pyHOME}/nc_var.py -o DataSetSection_multidims -f ${filen}               \
307      -S ${values} -v all
308    if test $? -ne 0; then
309      echo ${errmsg}
310      echo "  python failed!!"
311      echo python ${pyHOME}/nc_var.py -o DataSetSection_multidims -f ${filen}        \
312        -S "'"${values}"'" -v all
313      exit
314    fi
315  echo "* get values at sfc point: "${stlon}", "${stlat} >> ${ofileins}
316  echo python ${pyHOME}/nc_var.py -o DataSetSection_multidims -f ${filen}            \
317      -S "'"${values}"'" -v all >> ${ofileins}
318  echo " " >> ${ofileins}
319    yslc='south_north_B'${ysnd}'-E'${ysnd}'-I1'
320    ystslc='south_north_stag_B'${ysnd}'-E'${ysnd1}'-I1'
321    xslc='west_east_B'${xsnd}'-E'${xsnd}'-I1'
322    xstslc='west_east_stag_B'${xsnd}'-E'${xsnd1}'-I1'
323
324    ofilen='newfile_multidims.nc'
325    mv ${ofilen} ${simsfcptf}
326  fi
327   
328  # Computing sfc diagnostics
329  diagns=`echo ${sfcdiagnames} | tr ':' ' '`
330
331  idiag=1
332  for diagn in ${diagns}; do
333    diagv=`cat $pyHOME/diagnostics.inf | grep WRF | grep ${diagn}',' | tr ',' ' ' |  \
334      awk '{print $2"|"$3}'`
335    if test ${idiag} -eq 1; then
336      sfcdiagvals=${diagv}
337    else
338      sfcdiagvals=${sfcdiagvals}','${diagv}
339    fi
340    idiag=`expr ${idiag} + 1`
341  done
342
343  if ${fscratch}; then rm ${simsfcdiagsf}; fi
344  if test ! -f ${simsfcdiagsf}; then
345    python ${pyHOME}/diagnostics.py -f ${simsfcptf} -d ${sfcdiagd} -v ${sfcdiagvals}
346    if test $? -ne 0; then
347      echo ${errmsg}
348      echo "  python failed!!"
349      echo python ${pyHOME}/diagnostics.py -f ${simsfcptf} -d "'"${sfcdiagd}"'"      \
350        -v "'"${sfcdiagvals}"'"
351      exit
352    fi
353    echo "* diagnostics at sfc point: "${stlon}", "${stlat} >> ${ofileins}
354    echo python ${pyHOME}/diagnostics.py -f ${simsfcptf} -d "'"${sfcdiagd}"'"        \
355      -v "'"${sfcdiagvals}"'" >> ${ofileins}
356    echo " " >> ${ofileins}
357    mv diagnostics.nc ${simsfcdiagsf}
358    if $(isin_list ${sfcdiagnames} wds); then
359      #To rad
360      python ${pyHOME}/nc_var.py -o valmod -S mulc,0.0174532925199 -f ${simsfcdiagsf}\
361        -v wds
362      python ${pyHOME}/nc_var.py -o varaddattr -S 'units|rad' -f ${simsfcdiagsf} -v wds
363    fi
364  fi
365
366  #Adding non-diagnostic variables
367  if test ! ${nondiagvs} = 'None'; then
368    varsadd=`echo ${nondiagvs} | tr ':' ' '`
369    for vadd in ${varsadd}; do
370      python ${pyHOME}/nc_var.py -o fvaradd -S ${simsfcptf},${vadd} -f ${simsfcdiagsf}
371      if test $? -ne 0; then
372        echo ${errmsg}
373        echo "  python failed!!"
374        echo python ${pyHOME}/nc_var.py -o fvaradd -S "'"${simsfcptf},${vadd}"'"     \
375          -f ${simsfcdiagsf}
376        exit
377        rm ${simsfcdiagsf}
378      fi
379      echo "* adding variable '"${vadd}"' at sfc point: "${stlon}", "${stlat} >> ${ofileins}
380      echo python ${pyHOME}/nc_var.py -o fvaradd -S "'"${simsfcptf},${vadd}"'"       \
381        -f ${simsfcdiagsf} >> ${ofileins}
382      echo " " >> ${ofileins}
383      # CF varname
384      CFvarn=`python $pyHOME/generic.py -o variables_values -S ${vadd} | tr ':' ' ' |\
385        awk '{print $1}'`
386      if test $? -ne 0; then
387        echo ${errmsg}
388        echo "  python failed!!"
389        echo python $pyHOME/generic.py -o variables_values -S ${vadd}
390        exit
391        rm ${simsfcdiagsf}
392      fi
393      python $pyHOME/nc_var.py -o chvarname -S ${CFvarn} -f ${simsfcdiagsf} -v ${vadd}
394      if test $? -ne 0; then
395        echo ${errmsg}
396        echo "  python failed!!"
397        echo python ${pyHOME}/nc_var.py -o chvarname -S ${CFvarn} -f ${simsfcdiagsf} \
398          -v ${vadd}
399        exit
400        rm ${simsfcdiagsf}
401      fi
402    done
403  fi
404}
405
406function WindRose_plot() {
407# Function to plot a Wind rose
408#   it: time-step to use from the file
409#   sndstid: id of the sounding station
410#   sndstn: name of the sounding station to appear in plot ('!' for spaces)
411#   timeS: String with the format of the actual time ('!' for spaces)
412#   ofigdir: folder for the output of the figure
413#   timefS: date of the plot to be used for the figure name
414#   filen: file to use
415#   figheader: header of the figure's file name
416
417    valuesfig=$1
418
419    it=`echo ${valuesfig} | tr '#' ' ' | awk '{print $1}'`
420    sndstid=`echo ${valuesfig} | tr '#' ' ' | awk '{print $2}'`
421    sndstn=`echo ${valuesfig} | tr '#' ' ' | awk '{print $3}'`
422    timeS=`echo ${valuesfig} | tr '#' ' ' | awk '{print $4}'`
423    ofigdir=`echo ${valuesfig} | tr '#' ' ' | awk '{print $5}'`
424    timefS=`echo ${valuesfig} | tr '#' ' ' | awk '{print $6}'`
425    filen=`echo ${valuesfig} | tr '#' ' ' | awk '{print $7}'`
426    figheader=`echo ${valuesfig} | tr '#' ' ' | awk '{print $8}'`
427
428    values='pres|-1;time|'${it}':linepoint;multicol;pres;auto;auto;rainbow;auto:'
429    values=${values}${sndstn}'!sounding!WindRose!on!'${timeS}'!local!time:'${kfig}
430    values=${values}':cardinals:False:WindRose:True'
431    ofign=${ofigdir}'/'${figheader}'_'${sndstid}'_'${timefS}'.'${kfig}
432    if ${gscratch}; then rm ${ofign} >& /dev/null; fi
433    if test ! -f ${ofign}; then
434      echo "  Wind Rose on: "${timeS}
435      python ${pyHOME}/drawing.py -o draw_WindRose -S ${values} -v ua,va -f ${filen} >& /dev/null
436      if test $? -ne 0; then
437        echo ${errmsg}
438        echo "  python failed!!"
439        echo python ${pyHOME}/drawing.py -o draw_WindRose -S "'"${values}"'" -v ua,va -f ${filen}
440        exit
441      fi
442      convert -trim WindRose.png ${ofign}
443      echo "* "${ofign} >> ${ofilefigs}
444      echo python ${pyHOME}/drawing.py -o draw_WindRose -S "'"${values}"'" -v ua,va -f "'"${filen}"'" >> ${ofilefigs}
445      echo " " >> ${ofilefigs}
446    fi
447}
448
449function SkewT_logP_plot() {
450# Function to plot a SkewT_logP plot
451#   it: time step to use from file
452#   sndstid: id of the sounding station
453#   sndstn: name of the sounding station to appear in plot ('!' for spaces)
454#   timeS: String with the format of the actual time ('!' for spaces)
455#   ofigdir: folder for the output of the figure
456#   timefS: date of the plot to be used for the figure name
457#   filen: file to use
458#   figheader: header of the figure's file name
459
460    valuesfig=$1
461
462    it=`echo ${valuesfig} | tr '#' ' ' | awk '{print $1}'`
463    sndstid=`echo ${valuesfig} | tr '#' ' ' | awk '{print $2}'`
464    sndstn=`echo ${valuesfig} | tr '#' ' ' | awk '{print $3}'`
465    timeS=`echo ${valuesfig} | tr '#' ' ' | awk '{print $4}'`
466    ofigdir=`echo ${valuesfig} | tr '#' ' ' | awk '{print $5}'`
467    timefS=`echo ${valuesfig} | tr '#' ' ' | awk '{print $6}'`
468    filen=`echo ${valuesfig} | tr '#' ' ' | awk '{print $7}'`
469    figheader=`echo ${valuesfig} | tr '#' ' ' | awk '{print $8}'`
470 
471    values='time|'${it}',pres|-1:auto:auto:'${sndstn}'!sounding!on!'${timeS}'!local!'
472    values=${values}'time:'${kfig}':True'
473    ofign=${ofigdir}'/'${figheader}'_'${sndstid}'_'${timefS}'.'${kfig}
474    if ${gscratch}; then rm ${ofign} >& /dev/null; fi
475    if test ! -f ${ofign}; then
476      echo "  Sounding on: "$(echo ${timeS} | tr '!' ' ')
477      python ${pyHOME}/drawing.py -o draw_SkewT -S ${values} -v ta,tda,pres -f ${filen} >& /dev/null
478      if test $? -ne 0; then
479        echo ${errmsg}
480        echo "  python failed!!"
481        echo python ${pyHOME}/drawing.py -o draw_SkewT -S "'"${values}"'" -v ta,tda,pres -f ${filen}
482        exit
483      fi
484      convert -trim SkewT.png ${ofign}
485      echo "* "${ofign} >> ${ofilefigs}
486      echo python ${pyHOME}/drawing.py -o draw_SkewT -S "'"${values}"'" -v ta,tda,pres -f "'"${filen}"'" >> ${ofilefigs}
487      echo " " >> ${ofilefigs}
488    fi
489}
490
491function multi_soundings_plot() {
492# Function to plot a multi_sounding figure
493#   sndstid: id of the sounding station
494#   sndstn: name of the sounding station to appear in plot ('!' for spaces)
495#   tatda_evol_labs: labels for the figure
496#   tatda_evol_cols: colors of the lines for the figure
497#   timeS3: date in the figure
498#   ofigdir: folder for the output figure
499#   figheader: header of the figure's file name
500
501  valuesfig=$1
502
503  sndstid=`echo ${valuesfig} | tr '@' ' ' | awk '{print $1}'`
504  sndstn=`echo ${valuesfig} | tr '@' ' ' | awk '{print $2}'`
505  tatda_evol_labs=`echo ${valuesfig} | tr '@' ' ' | awk '{print $3}'`
506  tatda_evol_cols=`echo ${valuesfig} | tr '@' ' ' | awk '{print $4}'`
507  tatda_evol_files=`echo ${valuesfig} | tr '@' ' ' | awk '{print $5}'`
508  timeS3=`echo ${valuesfig} | tr '@' ' ' | awk '{print $6}'`
509  ofigdir=`echo ${valuesfig} | tr '@' ' ' | awk '{print $7}'`
510  figheader=`echo ${valuesfig} | tr '@' ' ' | awk '{print $8}'`
511
512  tatda_evol_values='auto:auto:multilines!'${tatda_evol_labs}'!'${tatda_evol_cols}'!'
513  tatda_evol_values=${tatda_evol_values}'-!,!2:0,auto:'${sndstn}'!sounding!evolution!on!'
514  tatda_evol_values=${tatda_evol_values}${timeS3}'!local!time:'${kfig}':True'
515
516  ofign=${ofigdir}'/'${figheader}'_'${stid}'.'${kfig}
517  if ${gscratch}; then rm ${ofign} >& /dev/null; fi
518  if test ! -f ${ofign}; then
519    echo "  Sounding on: "$(echo ${timeS} | tr '!' ' ')
520    python ${pyHOME}/drawing.py -o draw_multi_SkewT -S ${tatda_evol_values} -f ${tatda_evol_files} >& /dev/null
521    if test $? -ne 0; then
522      echo ${errmsg}
523      echo "  python failed!!"
524      echo python ${pyHOME}/drawing.py -o draw_multi_SkewT -S "'"${tatda_evol_values}"'" -f "'"${tatda_evol_files}"'"
525      exit
526    fi
527    convert -trim multi_SkewT.png ${ofign}
528    echo "* "${ofign} >> ${ofilefigs}
529    echo python ${pyHOME}/drawing.py -o draw_multi_SkewT -S "'"${tatda_evol_values}"'" -f "'"${tatda_evol_files}"'" >> ${ofilefigs}
530    echo " " >> ${ofilefigs}
531  fi
532}
533
534function multi_SkewT_logP_plot() {
535# Function to plot a multi_SkewT_logP plot with multiple lines
536#   sndstid: id of the sounding station
537#   sndstn: name of the sounding station to appear in plot ('!' for spaces)
538#   complabs: labels for the plot
539#   compcols: colors for the plot
540#   complines: type of lines for the plot
541#   compfiles: files to use for the plot
542#   dateS: String with the format of the actual time ('!' for spaces)
543#   ofigdir: folder for the output of the figure
544#   datefS: date of the plot to be used for the figure name
545#   figheader: header of the figure's file name
546
547    valuesfig=$1
548    sndstid=`echo ${valuesfig} | tr '@' ' ' | awk '{print $1}'`
549    sndstn=`echo ${valuesfig} | tr '@' ' ' | awk '{print $2}'`
550    complabs=`echo ${valuesfig} | tr '@' ' ' | awk '{print $3}'`
551    compcols=`echo ${valuesfig} | tr '@' ' ' | awk '{print $4}'`
552    complines=`echo ${valuesfig} | tr '@' ' ' | awk '{print $5}'`
553    compfiles=`echo ${valuesfig} | tr '@' ' ' | awk '{print $6}'`
554    dateS=`echo ${valuesfig} | tr '@' ' ' | awk '{print $7}'`
555    ofigdir=`echo ${valuesfig} | tr '@' ' ' | awk '{print $8}'`
556    datefS=`echo ${valuesfig} | tr '@' ' ' | awk '{print $9}'`
557    figheader=`echo ${valuesfig} | tr '@' ' ' | awk '{print $10}'`
558
559    values='auto:auto:multilines!'${complabs}'!'${compcols}'!'
560    values=${values}${complines}'!,!2:0,auto:'${ststn}'!sounding!obs!,!sim!'
561    values=${values}'comparison!on!'${dateS}'!UTC:png:True'
562
563    ofign=${ofigdir}'/'${figheader}'_'${sndstid}'_'${datefS}'.'${kfig}
564    if ${gscratch}; then rm ${ofign} >& /dev/null; fi
565    if test ! -f ${ofign}; then
566      echo "  Sounding on: "$(echo ${dateS} | tr '!' ' ')
567      python ${pyHOME}/drawing.py -o draw_multi_SkewT -S ${values} -f ${compfiles} >& /dev/null
568      if test $? -ne 0; then
569        echo ${errmsg}
570        echo "  python failed!!"
571        echo python ${pyHOME}/drawing.py -o draw_multi_SkewT -S "'"${values}"'" -f "'"${compfiles}"'"
572        exit
573      fi
574      convert -trim multi_SkewT.png ${ofign}
575      echo "* "${ofign} >> ${ofilefigs}
576      echo python ${pyHOME}/drawing.py -o draw_multi_SkewT -S "'"${values}"'" -f "'"${compfiles}"'" >> ${ofilefigs}
577      echo " " >> ${ofilefigs}
578    fi
579}
580
581function Homoeller_SkewT_map_plot() {
582# Function to plot a Hovmoeller SkewT_map
583#   sndstid: id of the sounding station
584#   sndstn: name of the sounding station to appear in plot ('!' for spaces)
585#   sndv: variable to plot
586#   ofigdir: folder for the output of the figure
587#   datefS: date of the plot to be used for the figure name
588#   timevals: values to use for the time-axis in the plot
589#   simfilen: name of the simulation file at the given point
590#   sndfilen: name of the sounding file
591#   expl: label of the experiment
592#   expn: name of the experiment
593#   cbar: color bar
594#   figheader: header of the figure's file name
595
596  valuesfig=$1
597  sndstid=`echo ${valuesfig} | tr '#' ' ' | awk '{print $1}'`
598  sndstn=`echo ${valuesfig} | tr '#' ' ' | awk '{print $2}'`
599  sndv=`echo ${valuesfig} | tr '#' ' ' | awk '{print $3}'`
600  ofigdir=`echo ${valuesfig} | tr '#' ' ' | awk '{print $4}'`
601  datefS=`echo ${valuesfig} | tr '#' ' ' | awk '{print $5}'`
602  timevals=`echo ${valuesfig} | tr '#' ' ' | awk '{print $6}'`
603  simfilen=`echo ${valuesfig} | tr '#' ' ' | awk '{print $7}'`
604  sndfilen=`echo ${valuesfig} | tr '#' ' ' | awk '{print $8}'`
605  expl=`echo ${valuesfig} | tr '#' ' ' | awk '{print $9}'`
606  expn=`echo ${valuesfig} | tr '#' ' ' | awk '{print $10}'`
607  cbar=`echo ${valuesfig} | tr '#' ' ' | awk '{print $11}'`
608  figheader=`echo ${valuesfig} | tr '#' ' ' | awk '{print $12}'`
609
610  cfiles=${simfilen}';'${sndv}';time;pres;time|-1,pres|-1@'
611  cfiles=${cfiles}${sndfilen}';'${sndv}';time;pres;time|-1,pres|-1'
612  cvalues=${sndv}';y;auto|'${timevals}';Vfix,auto,50.,auto'
613  cvalues=${cvalues}';'${cbar}',auto,auto;Srange,Srange;auto;obs!,!'${expn}'!'
614  cvalues=${cvalues}${sndstn}'!sounding;'${kfig}';flip@y;None;yes'
615
616  ofign=${ofigdir}'/'${figheader}'_'${expl}'_'${sndstid}'_'${sndv}'.'${kfig}
617  if ${gscratch}; then rm ${ofign} >& /dev/null; fi
618  if test ! -f ${ofign}; then
619    python ${pyHOME}/drawing.py -o draw_2D_shad_contdisc_time -f ${cfiles} -S ${cvalues}
620    if test $? -ne 0; then
621      echo ${errmsg}
622      echo "  python failed!!"
623      echo python ${pyHOME}/drawing.py -o draw_2D_shad_contdisc_time -f "'"${cfiles}"'" -S "'"${cvalues}"'"
624      exit
625    fi
626    convert -trim 2Dshad_obs-sim_comparison_time.png ${ofign}
627    echo "* "${ofign} >> ${ofilefigs}
628    echo python ${pyHOME}/drawing.py -o draw_2D_shad_contdisc_time -f "'"${cfiles}"'" -S "'"${cvalues}"'" >> ${ofilefigs}
629    echo " " >> ${ofilefigs}
630  fi
631}
632
633function multiple_time_series_plot(){
634# Function to plot multiple time-series
635#   sti: id of the surface station
636#   stn: name of the surface station to appear in plot ('!' for spaces)
637#   sfcv: name of variable to plot
638#   ofigdir: folder for the output of the figure
639#   timevals: values of the time-axis to use
640#   files: files to use
641#   labs: labels of the legend
642#   lcol: color of lines to use
643#   nsfc: minimum value to plot
644#   xsfc: maximum value to plot
645#   figheader: header of the figure's file name
646
647    valuesfig=$1
648    stid=`echo ${valuesfig} | tr '@' ' ' | awk '{print $1}'`
649    stn=`echo ${valuesfig} | tr '@' ' ' | awk '{print $2}'`
650    sfcv=`echo ${valuesfig} | tr '@' ' ' | awk '{print $3}'`
651    ofigdir=`echo ${valuesfig} | tr '@' ' ' | awk '{print $4}'`
652    timevals=`echo ${valuesfig} | tr '@' ' ' | awk '{print $5}'`
653    files=`echo ${valuesfig} | tr '@' ' ' | awk '{print $6}'`
654    labs=`echo ${valuesfig} | tr '@' ' ' | awk '{print $7}'`
655    lcol=`echo ${valuesfig} | tr '@' ' ' | awk '{print $8}'`
656    nsfc=`echo ${valuesfig} | tr '@' ' ' | awk '{print $9}'`
657    xsfc=`echo ${valuesfig} | tr '@' ' ' | awk '{print $10}'`
658    figheader=`echo ${valuesfig} | tr '@' ' ' | awk '{print $11}'`
659
660    timen=`echo ${timevals} | tr '|' ' ' | awk '{print $3}'`
661    fmtT=`echo ${timevals} | tr '|' ' ' | awk '{print $1"|"$2}'`
662
663    values='ststimes,time;y;'${timen}';auto;'${labs}';'${sfcv}';'${sfcv}
664    values=${values}'|evolution|at|'$(echo ${stn} | tr '!' '|')';'${nsfc}','${xsfc}';'
665    values=${values}'time|'${fmtT}';0|12;'
666    values=${values}${kfig}';-;'${lcol}';.;2.;2.;all;-1;True'
667
668    ofign=${ofigdir}'/'${figheader}'_'${sfcv}_${sti}'.'${kfig}
669    if ${gscratch}; then rm ${ofign} >& /dev/null; fi
670    if test ! -f ${ofign}; then
671      python ${pyHOME}/drawing.py -o draw_lines_time -f ${files} -S ${values} -v ${sfcv}
672      if test $? -ne 0; then
673        echo ${errmsg}
674        echo "  python failed!!"
675        echo python ${pyHOME}/drawing.py -o draw_lines_time -f "'"${files}"'" -S "'"${values}"'" -v ${sfcv}
676        exit
677      fi
678      convert -trim lines_time.${kfig} ${ofign}
679      echo "* "${ofign} >> ${ofilefigs}
680      echo python ${pyHOME}/drawing.py -o draw_lines_time -f "'"${files}"'" -S "'"${values}"'" -v ${sfcv} >> ${ofilefigs}
681      echo " "${ofign} >> ${ofilefigs}
682    fi
683}
684
685function shad_contdisc_map_plot(){
686# Function to plot a map of a continuos and a discontinuos variable
687#   expl: label of the experiment
688#   expn: name of the experiment in the title of the plot
689#   sfcv: name of variable to plot
690#   ofigdir: folder for the output of the figure
691#   obsfiles: observtional file to use
692#   simfile: simulation file to use
693#   it: time-step from simulation
694#   oit: time-step from observations
695#   timeS: format of time to appear in the title
696#   timefS: format of time to be used for the file name
697#   nsfc: minimum value to plot
698#   xsfc: maximum value to plot
699#   mapv: map values
700#   mapcover: cover of the map
701#   figheader: header of the figure's file name
702
703    valuesfig=$1
704
705    expl=`echo ${valuesfig} | tr '#' ' ' | awk '{print $1}'`
706    expn=`echo ${valuesfig} | tr '#' ' ' | awk '{print $2}'`
707    sfcv=`echo ${valuesfig} | tr '#' ' ' | awk '{print $3}'`
708    ofigdir=`echo ${valuesfig} | tr '#' ' ' | awk '{print $4}'`
709    obsfile=`echo ${valuesfig} | tr '#' ' ' | awk '{print $5}'`
710    simfile=`echo ${valuesfig} | tr '#' ' ' | awk '{print $6}'`
711    it=`echo ${valuesfig} | tr '#' ' ' | awk '{print $7}'`
712    oit=`echo ${valuesfig} | tr '#' ' ' | awk '{print $8}'`
713    timeS=`echo ${valuesfig} | tr '#' ' ' | awk '{print $9}'`
714    timefS=`echo ${valuesfig} | tr '#' ' ' | awk '{print $10}'`
715    nsfc=`echo ${valuesfig} | tr '#' ' ' | awk '{print $11}'`
716    xsfc=`echo ${valuesfig} | tr '#' ' ' | awk '{print $12}'`
717    mapv=`echo ${valuesfig} | tr '#' ' ' | awk '{print $13}'`
718    mapcover=`echo ${valuesfig} | tr '#' ' ' | awk '{print $14}'`
719    figheader=`echo ${valuesfig} | tr '#' ' ' | awk '{print $15}'`
720
721    CFvarvals=`python $pyHOME/generic.py -o variables_values -S ${sfcv}`
722    cbar=`echo ${CFvarvals} | tr ':' ' ' | awk '{print $7}'`
723
724    cfiles=${simfile}';'${sfcv}';XLONG;XLAT;Time|'${it}',time|'${it}','
725    cfiles=${cfiles}'west_east|-1,south_north|-1@'${obsfile}';'${sfcv}
726    cfiles=${cfiles}';stslon;stslat;time|'${oit}',lon|-1,lat|-1'
727    cvalues=${sfcv}':west_east,south_north:auto:'${cbar}',auto,auto:'${nsfc}','
728    cvalues=${cvalues}${xsfc}':''auto:obs!,!'${expn}'!'${sfcv}'!on!'${timeS}'!UTC:'
729    cvalues=${cvalues}${kfig}':None:'${mapv}':'${mapcover}':yes'
730
731    ofign=${ofigdir}'/'${figheader}'_'${timefS}'_'${sfcv}'_'${expl}'.'${kfig}
732    if ${gscratch}; then rm ${ofign} >& /dev/null; fi
733    if test ! -f ${ofign}; then
734      python ${pyHOME}/drawing.py -o draw_2D_shad_contdisc -f ${cfiles} -S ${cvalues}
735      if test $? -ne 0; then
736        echo ${errmsg}
737        echo "  python failed!!"
738        echo python ${pyHOME}/drawing.py -o draw_2D_shad_contdisc -f "'"${cfiles}"'" -S "'"${cvalues}"'"
739      fi
740      convert -trim 2Dshad_obs-sim_comparison.png ${ofign} 
741      echo "* "${ofign} >> ${ofilefigs}
742      echo python ${pyHOME}/drawing.py -o draw_2D_shad_contdisc -f "'"${cfiles}"'" -S "'"${cvalues}"'" >> ${ofilefigs}
743      echo " " >> ${ofilefigs}
744    fi
745}
746
747#######    #######
748## MAIN
749    #######
750
751mkdir -p ${odir}
752ofileins=${wdir}/allins_functions.inf
753ofilefigs=${wdir}/allins_figures.inf
754if ${fscratch}; then 
755  echo "*** Instruction from all functions _______" > ${ofileins}
756  echo " " >> ${ofileins}
757  echo "*** Instruction from all figures _______" > ${ofilefigs}
758  echo " " >> ${ofilefigs}
759fi
760
761# Files in sounding folder (from UWyoming_netcdf.py)
762if test ! ${sndHf} = 'None'; then
763  sndfs=`ls -1 ${snddir}/${sndHf}* | tr '\n' ':'`
764  echo "Soundings files _______"
765  echo ${sndfs} | tr ':' '\n'
766  sndfiles=`echo ${sndfs} | tr ':' ' '`
767else
768  sndfiles='None'
769fi
770
771# Files in sounding folder (from UWyoming_netcdf.py)
772if test ! ${sfcHf} = 'None'; then
773  sfcfs=`ls -1 ${sfcdir}/${sfcHf}** | tr '\n' ':'`
774  echo "Surface files _______"
775  echo ${sfcfs} | tr ':' '\n'
776  sfcfiles=`echo ${sfcfs} | tr ':' ' '`
777else
778  sfcfiles='None'
779fi
780
781exps=`echo ${sims} | tr ':' ' '`
782simH=`echo ${simHMT} | tr ',' ' ' | awk '{print $1}'`
783simM=`echo ${simHMT} | tr ',' ' ' | awk '{print $2}'`
784simT=`echo ${simHMT} | tr ',' ' ' | awk '{print $3}'`
785
786###
787## Preparing simulations
788###
789
790# sounding data
791isnd=1
792for sndf in ${sndfiles}; do
793  stid=`python $pyHOME/nc_var.py -o grattr -f ${sndf} -S Station_number`
794  sndlon=`ncdump -h ${sndf} | grep Station_longitude | awk '{print $3}'`
795  sndlat=`ncdump -h ${sndf} | grep Station_latitude | awk '{print $3}'`
796  sndheight=`ncdump -h ${sndf} | grep Station_elevation | awk '{print $3}'`
797
798  if test ${isnd} -eq 1; then 
799    sndstids=${stid}'@'${sndf}
800    echo "snd,"${stid}","${sndlon}","${sndlat}","${sndheight} > ${wdir}/stations.inf
801  else 
802    sndstids=${sndstids}':'${stid}'@'${sndf}
803    echo "snd,"${stid}","${sndlon}","${sndlat}","${sndheight} >> ${wdir}/stations.inf
804  fi
805
806  iexp=1
807  for exp in ${exps}; do
808    expf=`echo ${exp} | tr ',' ' ' | awk '{print $1}'`
809    expl=`echo ${exp} | tr ',' ' ' | awk '{print $2}'`
810    expn=`echo ${exp} | tr ',' ' ' | awk '{print $3}'`
811    expc=`echo ${exp} | tr ',' ' ' | awk '{print $4}'`
812
813    simfiles=`ls -1 ${simdir}/${expf}/${simH}*${simM}*${simT}`
814
815    for simf in ${simfiles}; do
816      simfn=`basename ${simf}`
817      fdate=`echo ${simfn} | tr '.' ' ' | awk '{print $1}' | tr '_' ' ' |            \
818        awk '{print $3"_"$4}'`
819
820      simsndptf=${odir}'/simout_vars_sndpt_'${stid}'_'${expl}'_'${fdate}'.nc'
821      simsnddiagsf=${odir}'/simout_snddiags_'${stid}'_'${expl}'_'${fdate}'.nc'
822
823      fvals=${sndlon}'#'${sndlat}'#'${simf}'#XLONG#XLAT#'${wrfsnddiags}'#'
824      fvals=${fvals}${simsnddiagd}
825      get_WRFsounding_data ${fvals}
826
827    # end of files
828    done
829
830    # Concatenating files
831    ofile=${odir}/simout_sndvars_${stid}_${expn}.nc
832    if ${fscratch}; then rm ${ofile} >& /dev/null; fi
833    if test ! -f ${ofile}; then
834      Nconfc=`ls -1 ${odir}/simout_snddiags_*${stid}*nc | wc -l | awk '{print $1}'`
835      if test ${Nconfc} -gt 1; then 
836        values=${odir}',Time,time'
837        HMT='simout_snddiags_,'${stid}'_'${expn},'nc'
838        python ${pyHOME}/nc_var.py -o netcdf_fold_concatenation_HMT -S ${values}      \
839         -f ${HMT} -v all
840        if test $? -ne 0; then
841          echo ${errmsg}
842          echo "  python failed!!"
843          echo python ${pyHOME}/nc_var.py -o netcdf_fold_concatenation_HMT -S ${values}\
844          -f ${HMT} -v all
845          exit
846        fi
847        echo " * Concatenating sounding data at point: "${sndlon}", "${sndlat} >> ${ofileins}
848        echo python  ${pyHOME}/nc_var.py -o netcdf_fold_concatenation_HMT -S \
849          "'"${values}"'" -f ${HMT} -v all >> ${ofileins}
850        echo " " >> ${ofileins}
851        mv netcdf_fold_concatenated_HMT.nc ${ofile}
852      else
853        ffilen=`ls -1 ${odir}/simout_snddiags_*${stid}*nc`
854        cp ${ffilen} ${ofile}
855      fi
856    fi
857    iexp=`expr ${iexp} + 1`
858  # end of experiments
859  done
860
861  isnd=`expr ${isnd} + 1`
862done
863exit
864
865diagns=`echo ${wrfsnddiags} | tr ':' ' '`
866snddiagd='time@time,bottom_top@P,south_north@XLAT,west_east@XLONG'
867snddiagvals=''
868idiag=1
869for diagn in ${diagns}; do
870  diagv=`cat $pyHOME/diagnostics.inf | grep ${diagn}',' | tr ',' ' ' |               \
871    awk '{print $2"|"$3}'`
872  if test ${idiag} -eq 1; then
873    snddiagvals=${diagv}
874  else
875    snddiagvals=${snddiagvals}','${diagv}
876  fi
877  idiag=`expr ${idiag} + 1`
878done
879
880if test ${sfcvars} != 'None'; then
881# surface diags
882diagns=`echo ${wrfsfcdiags} | tr ':' ' '`
883sfcdiagd='time@time,south_north@XLAT,west_east@XLONG'
884sfcdiagvals=''
885idiag=1
886iadv=1
887for diagn in ${diagns}; do
888  diagv=`cat $pyHOME/diagnostics.inf | grep WRF | grep ${diagn}',' | tr ',' ' ' |    \
889    awk '{print $2"|"$3}'`
890  Ldiagv=`expr length $(echo ${diagv} | tr ' ' '@')0`
891  if test ${Ldiagv} -lt 2; then
892    echo ${errmsg}
893    echo "  diagnostic '"${diagn}"' (for WRF) does not exist !!"
894    if test ${iadv} -eq 1; then advs=${diagn}; iadv=`expr ${iadv} + 1`
895    else advs=${adv}','${diagn}; fi
896  else
897    if test ${idiag} -eq 1; then
898      sfcdiagvals=${diagv}
899      idiag=`expr ${idiag} + 1`
900    else
901      sfcdiagvals=${sfcdiagvals}','${diagv}
902    fi
903  fi
904done
905fi
906
907exps=`echo ${sims} | tr ':' ' '`
908
909iexp=1
910for exp in ${exps}; do
911  expf=`echo ${exp} | tr ',' ' ' | awk '{print $1}'`
912  expl=`echo ${exp} | tr ',' ' ' | awk '{print $2}'`
913  expn=`echo ${exp} | tr ',' ' ' | awk '{print $3}'`
914  expc=`echo ${exp} | tr ',' ' ' | awk '{print $4}'`
915
916  # Joining files
917  simjoinselvars=${odir}'/simout_vars_'${expl}'.nc'
918  if ${fscratch}; then rm ${simjoinselvars}; fi
919  if test ! -f ${simjoinselvars}; then
920    values=${simdir}'/'${expf}','${simtimedimn}','${simtimevarn}
921    HMT=${simHMT}
922    python ${pyHOME}/nc_var.py -o netcdf_fold_concatenation_HMT -S ${values}         \
923     -f ${HMT} -v ${simvars}
924    if test $? -ne 0; then
925      echo ${errmsg}
926      echo "  python failed!!"
927      echo python ${pyHOME}/nc_var.py -o netcdf_fold_concatenation_HMT -S "'"${values}"'"  \
928        -f "'"${HMT}"'" -v "'"${simvars}"'"
929      exit
930    fi
931    mv netcdf_fold_concatenated_HMT.nc ${simjoinselvars}
932  fi
933
934  # Computing sounding diagnostics
935  simdiagsf=${odir}'/simout_snddiags_'${expl}'.nc'
936  if ${fscratch}; then rm ${simdiagsf}; fi
937  if test ! -f ${simdiagsf}; then
938    python ${pyHOME}/diagnostics.py -f ${simjoinselvars} -d ${snddiagd} -v ${snddiagvals}
939    if test $? -ne 0; then
940      echo ${errmsg}
941      echo "  python failed!!"
942      echo python ${pyHOME}/diagnostics.py -f ${simjoinselvars} -d "'"${snddiagd}"'" -v "'"${snddiagvals}"'"
943      exit
944    fi
945    mv diagnostics.nc ${simdiagsf}
946    #To deg
947    python ${pyHOME}/nc_var.py -o valmod -S subc,273.15 -f ${simdiagsf} -v ta
948    #To Pa
949    python ${pyHOME}/nc_var.py -o valmod -S divc,100. -f ${simdiagsf} -v pres
950  fi
951
952  if test ${sfcvars} != 'None'; then
953  # Computing surface diagnostics
954  simsfcdiagf=${odir}'/simout_sfcdiags_'${expl}'.nc'
955  if ${fscratch}; then rm ${simsfcdiagf}; fi
956  if test ! -f ${simsfcdiagf}; then
957    python ${pyHOME}/diagnostics.py -f ${simjoinselvars} -d ${sfcdiagd} -v ${sfcdiagvals}
958    if test $? -ne 0; then
959      echo ${errmsg}
960      echo "  python failed!!"
961      echo python ${pyHOME}/diagnostics.py -f ${simjoinselvars} -d "'"${sfcdiagd}"'" -v ${sfcdiagvals}
962      exit
963    fi
964    mv diagnostics.nc ${simsfcdiagf}
965    #To rad
966    python ${pyHOME}/nc_var.py -o valmod -S mulc,0.0174532925199 -f ${simsfcdiagf} -v wds
967    python ${pyHOME}/nc_var.py -o varaddattr -S 'units|rad' -f ${simsfcdiagf} -v wds
968  fi
969
970  #Adding non-diagnostic variables
971  if test ${iadv} -ne 1; then
972    varsadd=`echo ${advs} | tr ',' ' '`
973    for vadd in ${varsadd}; do
974      python ${pyHOME}/nc_var.py -o fvaradd -S ${simjoinselvars},${vadd} -f ${simsfcdiagf}
975      if test $? -ne 0; then
976        echo ${errmsg}
977        echo "  python failed!!"
978        echo python ${pyHOME}/nc_var.py -o fvaradd -S "'"${simjoinselvars},${vadd}"'" -f ${simsfcdiagf}
979        exit
980        rm ${simsfcdiagf}
981      fi
982      # CF varname
983      CFvarn=`python $pyHOME/generic.py -o variables_values -S ${vadd} | tr ':' ' ' |  \
984        awk '{print $1}'`
985      if test $? -ne 0; then
986        echo ${errmsg}
987        echo "  python failed!!"
988        echo python $pyHOME/generic.py -o variables_values -S ${vadd}
989        exit
990        rm ${simsfcdiagf}
991      fi
992      python $pyHOME/nc_var.py -o chvarname -S ${CFvarn} -f ${simsfcdiagf} -v ${vadd}
993      if test $? -ne 0; then
994        echo ${errmsg}
995        echo "  python failed!!"
996        echo python ${pyHOME}/nc_var.py -o chvarname -S ${CFvarn} -f ${simsfcdiagf} -v ${vadd}
997        exit
998        rm ${simsfcdiagf}
999      fi
1000    done
1001  fi
1002  fi
1003
1004  iexp=`expr ${iexp} + 1`
1005
1006# End experiments
1007done
1008
1009mkdir -p ${ofigdir}
1010
1011###
1012## Soundings figures
1013###
1014
1015isnd=1
1016for sndf in ${sndfiles}; do
1017  stid=`python $pyHOME/nc_var.py -o grattr -f ${sndf} -S Station_number`
1018
1019  # Getting wind components
1020  ouavasndf=${odir}'/sounding_uava_'${stid}'.nc'
1021  if ${fscratch}; then rm ${ouavasndf}; fi
1022  if test ! -f ${ouavasndf}; then
1023    python ${pyHOME}/diagnostics.py -f ${sndf} -d 'time@time,pres@pres' -v 'uavaFROMwswd|ws@wd'
1024    if test $? -ne 0; then
1025      echo ${errmsg}
1026      echo "  python failed!!"
1027      echo python ${pyHOME}/diagnostics.py -f ${sndf} -d 'time@time,pres@pres' -v 'uavaFROMwswd|ws@wd'
1028      exit
1029    fi 
1030    mv diagnostics.nc ${ouavasndf}
1031  fi
1032done
1033
1034sndids=`echo ${sndstids} | tr ':' ' '`
1035
1036for stidf in ${sndids}; do
1037  stid=`echo ${stidf} | tr '@' ' ' | awk '{print $1}'`
1038  sndorigfn=`echo ${stidf} | tr '@' ' ' | awk '{print $2}'`
1039  echo ${stid}" ..."
1040  it=0
1041  tatda_evol_values=''
1042  tatda_evol_files=''
1043  sndtimes=''
1044  snddates=''
1045  sndFdates=''
1046  snddimt=`python ${pyHOME}/nc_var.py -o itime -S CFtime -f ${sndorigfn} -v time | \
1047     grep 'dimt:' | awk '{print $2-1}'`
1048
1049  # Time characteristics
1050  tunits=`python ${pyHOME}/nc_var.py -o ivattrs -v time -f ${sndorigfn} | \
1051    grep -v allvattrs | grep units | awk '{print $3}'`
1052  Tu=`echo ${tunits} | tr '!' ' ' | awk '{print $1}'`
1053  Dref0=`echo ${tunits} | tr '!' ' ' | awk '{print $3}'`
1054  Dref=${Dref0:0:4}${Dref0:5:2}${Dref0:8:2}
1055
1056  # Getting values for evolution plot
1057  col=`echo ${icolta} | tr ':' ' ' | awk '{print $1}'`
1058  col2=`echo ${icolta} | tr ':' ' ' | awk '{print $2}'`
1059  while test ${it} -le ${snddimt}; do
1060    timev=`python $pyHOME/nc_var.py -o varout -S time:${it} -f ${sndorigfn} -v time | \
1061      grep NC | awk '{printf ("%d", $2)}'`
1062    timeS=`date +${figsndTfmt} -d"${Dref} ${timev} ${Tu}"`
1063    timeS2=`date +%d"$^{"%H"}$" -d"${Dref} ${timev} ${Tu}"`
1064    timeS3=`date +%Y"-"%b -d"${Dref} ${timev} ${Tu}"`
1065    timeS4=`date +%Y -d"${Dref} ${timev} ${Tu}"`
1066    echo "  "${it}" "${timev}" "${Dref}" '"${timev}"' "${Tu}" "$(echo ${timeS} | tr '!' ' ')
1067    timefS=`date +%Y%m%d%H%M%S -d"${Dref} ${timev} ${Tu}"`
1068
1069    # for now...
1070    sndstn=${stid}
1071
1072    fivals=${it}'#'${stid}'#'${sndstn}'#'${timeS}'#'${ofigdir}'#'${timefS}'#'
1073    fivals=${fivals}${ouavasndf}'#WindRose'
1074    WindRose_plot ${fivals}
1075
1076    fivals=${it}'#'${stid}'#'${sndstn}'#'${timeS}'#'${ofigdir}'#'${timefS}'#'
1077    fivals=${fivals}${sndorigfn}'#SkewT-logP_obs_ta-tda'
1078    SkewT_logP_plot ${fivals}
1079
1080    colH=`num_hex ${col}`
1081    colH2=`num_hex ${col2}`
1082    if test ${it} -eq 0; then
1083      sndtimes=${timev}
1084      snddates=${timeS}
1085      sndFdates=${timefS}
1086      tatda_evol_files=${sndorigfn}':pres|-1,time|'${it}':ta,pres;'
1087      tatda_evol_files=${tatda_evol_files}${sndorigfn}':pres|-1,time|'${it}':tda,pres'
1088      tatda_evol_labs='ta_'${timeS2}',tda'
1089      tatda_evol_cols='#'${colH}${colH2}${colH2}',#'${colH2}${colH2}${colH}
1090    else
1091      sndtimes=${sndtimes}','${timev}
1092      snddates=${snddates}','${timeS}
1093      sndFdates=${sndFdates}','${timefS}
1094      tatda_evol_files=${tatda_evol_files}';'${sndorigfn}':pres|-1,time|'${it}':ta,pres'
1095      tatda_evol_files=${tatda_evol_files}';'${sndorigfn}':pres|-1,time|'${it}':tda,pres'
1096      if test $(expr ${it} % 2) -eq 0; then 
1097        tatda_evol_labs=${tatda_evol_labs}','${timeS2}',None'
1098      else 
1099        tatda_evol_labs=${tatda_evol_labs}',None,None'
1100      fi
1101      tatda_evol_cols=${tatda_evol_cols}',#'${colH}${colH2}${colH2}',#'${colH2}${colH2}${colH}
1102    fi
1103    col=`expr ${col} - ${ddcol}`
1104    col2=`expr ${col2} - ${ddcol}`
1105
1106    #exit
1107    it=`expr ${it} + 1`
1108  done
1109
1110  fivals=${stid}'@'${sndstn}'@'${tatda_evol_labs}'@'${tatda_evol_cols}'@'
1111  fivals=${fivals}${tatda_evol_files}'@'${timeS3}'@'${ofigdir}'@SkewT-logP_obs_evol'
1112  multi_soundings_plot ${fivals}
1113
1114# End of soundings
1115done
1116
1117# snd-sims comparison
1118
1119for stidf in ${sndids}; do
1120  stid=`echo ${stidf} | tr '@' ' ' | awk '{print $1}'`
1121  sndorigfn=`echo ${stidf} | tr '@' ' ' | awk '{print $2}'`
1122  echo "snd: "${stid}
1123
1124  sndlon=`ncdump -h ${sndorigfn} | grep Station_longitude | awk '{print $3}'`
1125  sndlat=`ncdump -h ${sndorigfn} | grep Station_latitude | awk '{print $3}'`
1126  sndts=`echo ${sndtimes} | tr ',' ' '`
1127
1128  # for now...
1129  sndstn=${stid}
1130
1131  # Time characteristics
1132  tunits=`python ${pyHOME}/nc_var.py -o ivattrs -v time -f ${sndorigfn} |            \
1133    grep -v allvattrs | grep units | awk '{print $3}'`
1134  Tu=`echo ${tunits} | tr '!' ' ' | awk '{print $1}'`
1135  Dref0=`echo ${tunits} | tr '!' ' ' | awk '{print $3}'`
1136  Dref=${Dref0:0:4}${Dref0:5:2}${Dref0:8:2}
1137
1138  obsdimt=`python ${pyHOME}/nc_var.py -o itime -S CFtime, -v time -f ${sndorigfn} |  \
1139    grep dimt | awk '{print $2-1}'`
1140
1141  # Plotting
1142  it=0
1143  while test ${it} -le ${obsdimt}; do
1144
1145    otimev=`python $pyHOME/nc_var.py -o varout -S time:${it} -f ${sndorigfn} -v time |\
1146      grep NC | awk '{printf ("%d", $2)}'`
1147    dateS=`date +${figsndTfmt} -d"${Dref} ${otimev} ${Tu}"`
1148    timeS2=`date +%d"$^{"%H"}$" -d"${Dref} ${otimev} ${Tu}"`
1149    timeS3=`date +%Y"-"%b -d"${Dref} ${otimev} ${Tu}"`
1150    timeS4=`date +%Y -d"${Dref} ${otimev} ${Tu}"`
1151    datefS=`date +%Y%m%d%H%M%S -d"${Dref} ${otimev} ${Tu}"`
1152
1153    iexp=1
1154    for exp in ${exps}; do
1155      expf=`echo ${exp} | tr ',' ' ' | awk '{print $1}'`
1156      expl=`echo ${exp} | tr ',' ' ' | awk '{print $2}'`
1157      expn=`echo ${exp} | tr ',' ' ' | awk '{print $3}'`
1158      expc=`echo ${exp} | tr ',' ' ' | awk '{print $4}'`
1159
1160      simjoinselvars=${odir}'/simout_vars_'${expl}'.nc'
1161      simdiagsf=${odir}'/simout_snddiags_'${expl}'.nc'
1162
1163      gridsndv=`python ${pyHOME}/nc_var.py -o get_point -f ${simjoinselvars}         \
1164        -S 'XLONG:XLAT:Time|0' -v ${sndlon}','${sndlat} | tr ' ' '!'`
1165      xsnd=`echo ${gridsndv} | tr '!' ' ' | awk '{print $1}' | tr ',' ' ' |          \
1166        awk '{print $1}'`
1167      ysnd=`echo ${gridsndv} | tr '!' ' ' | awk '{print $1}' | tr ',' ' ' |          \
1168        awk '{print $2}'`
1169      dsnd=`echo ${gridsndv} | tr '!' ' ' | awk '{print $2}'`
1170      if test ${it} -eq 0 && test ${iexp} -eq 1; then
1171        echo "    Equivalent simulated sounding grid point: "${gridsnd}" distance: "\
1172          ${dsnd}
1173      fi
1174
1175      # Getting values at the sounding point
1176      simsndptf=${odir}'/simout_vars_sndpt_'${stid}'_'${expl}'.nc'
1177      if ${fscratch}; then rm ${simsndptf} >& /dev/null; fi
1178      if test ! -f ${simsndptf}; then
1179        values='time,0,-1,1@bottom_top,0,-1,1@south_north,'${ysnd}','${ysnd}',1@'
1180        values=${values}'west_east,'${xsnd}','${xsnd}',1'
1181        python ${pyHOME}/nc_var.py -o DataSetSection_multidims -f ${simdiagsf}       \
1182          -S ${values} -v all
1183        if test $? -ne 0; then
1184          echo ${errmsg}
1185          echo "  python failed!!"
1186          echo python ${pyHOME}/nc_var.py -o DataSetSection_multidims -f ${simdiagsf}\
1187            -S "'"${values}"'" -v all
1188          exit
1189        fi
1190        ofilen=`ls -rt1 ${odir} | tail -n 1`
1191        mv ${odir}/${ofilen} ${simsndptf}
1192      fi
1193
1194      # Time information from simulation
1195      simdimt=`python ${pyHOME}/nc_var.py -o itime -S CFtime, -v time                \
1196        -f ${simdiagsf} | grep dimt | awk '{print $2}'`
1197      simtunits=`python ${pyHOME}/nc_var.py -o ivattrs -v time -f ${simdiagsf} |     \
1198        grep -v allvattrs | grep units | awk '{print $3}'`
1199      simTu=`echo ${tunits} | tr '!' ' ' | awk '{print $1}'`
1200      simDref0=`echo ${tunits} | tr '!' ' ' | awk '{print $3}'`
1201      simDref=${simDref0:0:4}${simDref0:5:2}${simDref0:8:2}
1202
1203      # Time step from simulated file
1204      timestepv=`python ${pyHOME}/nc_var.py -o get_time -f ${simsndptf}               \
1205        -S ${otimev}';'${tunits} -v time | tr ' ' '@'`
1206      timestep=`echo ${timestepv} | tr '@' ' ' | awk '{print $1}'`
1207      if test $? -ne 0; then
1208        echo ${errmsg}
1209        echo "  python failed!!"
1210        echo python ${pyHOME}/nc_var.py -o get_time -f ${simsndptf}                  \
1211          -S ${otimev}';'${tunits} -v time
1212        exit
1213      fi
1214
1215      if test ${iexp} -eq 1; then
1216        echo "     "${it}": it="${timestep}" "$(echo ${dateS} | tr '!' ' ')" "${datefS}
1217        tacomplabs='$ta^{obs}$,$ta^{'${expn}'}$'
1218        tdacomplabs='$tda^{obs}$,$tda^{'${expn}'}$'
1219        tacompcols='#FF6464,'${expc}
1220        tdacompcols='#6464FF,'${expc}
1221        tacompltyp='-,-'
1222        tdacompltyp='-,-.'
1223        tacompfiles=${sndorigfn}':pres|-1,time|'${it}':ta,pres;'
1224        tacompfiles=${tacompfiles}${simsndptf}':bottom_top|-1,time|'${timestep}':'
1225        tacompfiles=${tacompfiles}'ta,pres'
1226        tdacompfiles=${sndorigfn}':pres|-1,time|'${it}':tda,pres;'
1227        tdacompfiles=${tdacompfiles}${simsndptf}':bottom_top|-1,time|'${timestep}':'
1228        tdacompfiles=${tdacompfiles}'tda,pres'
1229      else
1230        tacomplabs=${tacomplabs}',$ta^{'${expn}'}$'
1231        tdacomplabs=${tdacomplabs}',$tda^{'${expn}'}$'
1232        tacompcols=${tacompcols}','${expc}
1233        tdacompcols=${tdacompcols}','${expc}
1234        tacompltyp=${tacompltyp}',-'
1235        tdacompltyp=${tdacompltyp}',-.'
1236        tacompfiles=${tacompfiles}';'${simsndptf}':bottom_top|-1,time|'${timestep}':'
1237        tacompfiles=${tacompfiles}'ta,pres'
1238        tdacompfiles=${tdacompfiles}';'${simsndptf}':bottom_top|-1,time|'${timestep}
1239        tdacompfiles=${tdacompfiles}':tda,pres'
1240      fi
1241
1242      # Hovmoeller maps
1243      sndvs=`echo ${sndvars} | tr ':' ' '`
1244      for sndv in ${sndvs}; do
1245
1246        CFvarvals=`python $pyHOME/generic.py -o variables_values -S ${sndv}`
1247        cbar=`echo ${CFvarvals} | tr ':' ' ' | awk '{print $7}'`
1248
1249        fivals=${stid}'#'${sndstn}'#'${sndv}'#'${ofigdir}'#'${datefS}'#'${fmtTts}
1250        fivals=${fivals}'#'${simsndptf}'#'${sndorigfn}'#'${expl}'#'${expn}'#'${cbar}
1251        fivals=${fivals}'#SkewT-logP_obs-sim_evol'
1252
1253        Homoeller_SkewT_map_plot ${fivals}
1254
1255      # end sounding vars
1256      done
1257
1258      iexp=`expr ${iexp} + 1`
1259    # End experiments
1260    done
1261
1262    complabs=${tacomplabs}','${tdacomplabs}
1263    compcols=${tacompcols}','${tdacompcols}
1264    compltyp=${tacompltyp}','${tdacompltyp}
1265    compfiles=${tacompfiles}';'${tdacompfiles}
1266
1267    fivals=${stid}'@'${sndstn}'@'${complabs}'@'${compcols}'@'${compltyp}'@'
1268    fivals=${fivals}${compfiles}'@'${dateS}'@'${ofigdir}'@'${datefS}'@'${ofigdir}'@'
1269    fivals=${fivals}'SkewT-logP_obs-sim_step'
1270
1271    multi_SkewT_logP_plot ${fivals}
1272
1273    # Wind Rose comparison
1274    fivals=${it}'#'${stid}'#'${sndstn}'#'${timeS}'#'${ofigdir}'#'${timefS}'#'
1275    fivals=${fivals}${ouavasndf}'#WindRose_obs-sim_'
1276    multi_WindRose_plot ${fivals}
1277
1278    it=`expr ${it} + 1`
1279  # End sounding time-steps
1280  done
1281
1282# End of soundings stations
1283done
1284
1285###
1286## SFC figures
1287###
1288
1289# Joining all observations
1290obssfcfile=${odir}'/all_single-stations.nc'
1291if test ! -f ${wdir}/${sfcdir}/${obssfcfile}; then
1292  python ${pyHOME}/nc_var.py -o join_singlestation_obsfiles -S                       \
1293    ${sfcdir}':OBSnetcdf' -v all
1294  if test $? -ne 0; then
1295    echo ${errmsg}
1296    echo "  python failed!!"
1297    echo  python ${pyHOME}/nc_var.py -o join_singlestation_obsfiles \
1298      -S ${sfcdir}':OBSnetcdf' -v all
1299  fi
1300  mv joined_singlestations.nc ${obssfcfile}
1301fi
1302
1303# getting min,max values
1304if test ${sfcvars} != 'None'; then
1305fcs=`echo ${sfcvars} | tr ':' ' '`
1306
1307iv=1
1308for sfcpv in ${sfcs}; do
1309  sfcv=`echo ${sfcpv} | tr '@' ' ' | awk '{print $1}'`
1310  nsfc=`echo ${sfcpv} | tr '@' ' ' | awk '{print $2}'`
1311  xsfc=`echo ${sfcpv} | tr '@' ' ' | awk '{print $3}'`
1312  if test ${nsfc} = 'FROMobs'; then
1313    fstats=`python $pyHOME/nc_var.py -o field_stats -S full,1.e+20,None              \
1314      -f ${obssfcfile} -v ${sfcv} | grep MAT | grep ${sfcv}`
1315    nsfc=`echo ${fstats} | awk '{print $3}'`
1316  elif test ${nsfc} = 'FROMsims'; then
1317    iexp=1
1318    for exp in ${exps}; do
1319      expl=`echo ${exp} | tr ',' ' ' | awk '{print $2}'`
1320      simsfcdiagf=${odir}'/simout_sfcdiags_'${expl}'.nc'
1321   
1322      fstats=`python $pyHOME/nc_var.py -o field_stats -S full,1.e+20,None            \
1323        -f ${simsfcdiagf} -v ${sfcv} | grep MAT | grep ${sfcv}`
1324      if test ${iexp} -eq 1; then
1325        nsfc=`echo ${fstats} | awk '{print $3}'`
1326      else
1327        nsfc2=`echo ${fstats} | awk '{print $3}'`
1328        nsfcf=`echo ${nsfc}" "${nsfc2} | awk '{if ($1 < $2) {print $1;} else {print $2;}}'`
1329      fi
1330    done
1331  elif test ${nsfc} = 'FROMobssims'; then
1332    fstats=`python $pyHOME/nc_var.py -o field_stats -S full,1.e+20,None              \
1333      -f ${obssfcfile} -v ${sfcv} | grep MAT | grep ${sfcv}`
1334    nsfc=`echo ${fstats} | awk '{print $3}'`
1335    for exp in ${exps}; do
1336      expl=`echo ${exp} | tr ',' ' ' | awk '{print $2}'`
1337      simsfcdiagf=${odir}'/simout_sfcdiags_'${expl}'.nc'
1338   
1339      fstats=`python $pyHOME/nc_var.py -o field_stats -S full,1.e+20,None            \
1340        -f ${simsfcdiagf} -v ${sfcv} | grep MAT | grep ${sfcv}`
1341      nsfc2=`echo ${fstats} | awk '{print $3}'`
1342      nsfc=`echo ${nsfc}" "${nsfc2} | awk '{if ($1 < $2) {print $1;} else {print $2;}}'`
1343    done
1344  fi
1345  if test ${xsfc} = 'FROMobs'; then
1346    fstats=`python $pyHOME/nc_var.py -o field_stats -S full,1.e+20,None              \
1347      -f ${obssfcfile} -v ${sfcv} | grep MAT | grep ${sfcv}`
1348    xsfc=`echo ${fstats} | awk '{print $4}'`
1349  elif test ${xsfc} = 'FROMsims'; then
1350    iexp=1
1351    for exp in ${exps}; do
1352      expl=`echo ${exp} | tr ',' ' ' | awk '{print $2}'`
1353      simsfcdiagf=${odir}'/simout_sfcdiags_'${expl}'.nc'
1354   
1355      fstats=`python $pyHOME/nc_var.py -o field_stats -S full,1.e+20,None            \
1356        -f ${simsfcdiagf} -v ${sfcv} | grep MAT | grep ${sfcv}`
1357      if test ${iexp} -eq 1; then
1358        xsfc=`echo ${fstats} | awk '{print $4}'`
1359      else
1360        xsfc2=`echo ${fstats} | awk '{print $4}'`
1361        xsfcf=`echo ${xsfc}" "${xsfc2} | awk '{if ($1 > $2) {print $1;} else {print $2;}}'`
1362      fi
1363    done
1364  elif test ${nsfc} = 'FROMobssims'; then
1365    fstats=`python $pyHOME/nc_var.py -o field_stats -S full,1.e+20,None              \
1366      -f ${obssfcfile} -v ${sfcv} | grep MAT | grep ${sfcv}`
1367    xsfc=`echo ${fstats} | awk '{print $4}'`
1368    iexp=1
1369    for exp in ${exps}; do
1370      expl=`echo ${exp} | tr ',' ' ' | awk '{print $2}'`
1371      simsfcdiagf=${odir}'/simout_sfcdiags_'${expl}'.nc'
1372   
1373      fstats=`python $pyHOME/nc_var.py -o field_stats -S full,1.e+20,None            \
1374        -f ${simsfcdiagf} -v ${sfcv} | grep MAT | grep ${sfcv}`
1375      xsfc2=`echo ${fstats} | awk '{print $4}'`
1376      xsfcf=`echo ${xsfc}" "${xsfc2} | awk '{if ($1 > $2) {print $1;} else {print $2;}}'`
1377    done
1378  fi
1379  if test $iv -eq 1; then
1380    newsfcvars=${sfcv}'@'${nsfc}'@'${xsfc}
1381  else
1382    newsfcvars=${newsfcvars}':'${sfcv}'@'${nsfc}'@'${xsfc}
1383  fi
1384  iv=`expr ${iv} + 1`
1385done
1386sfcs=`echo ${newsfcvars} | tr ':' ' '`
1387echo "new sfc variables: "${sfcs}
1388
1389# Time-series
1390
1391# stations
1392# FROM: https://stackoverflow.com/questions/2961635/using-awk-to-print-all-columns-from-the-nth-to-the-last
1393stsids=`python ${pyHOME}/nc_var.py -o varout -v id -f \
1394  ${obssfcfile} -S 'Nstations:-1|time:0' | awk '{$1=""; printf("%d:",substr($0,2))}'`
1395stsnames=`python ${pyHOME}/nc_var.py -o varout -v stsname -f \
1396  ${obssfcfile} -S Nstations:-1 | awk '{$1=""; print substr($0,2)}' | tr '\n' ':' | \
1397  tr ' ' '!'`
1398stslons=`python ${pyHOME}/nc_var.py -o varout -v stslon -f \
1399  ${obssfcfile} -S Nstations:-1 | awk '{$1=""; print substr($0,2)}' | tr '\n' ':'`
1400stslats=`python ${pyHOME}/nc_var.py -o varout -v stslat -f \
1401  ${obssfcfile} -S Nstations:-1 | awk '{$1=""; print substr($0,2)}' | tr '\n' ':'`
1402
1403Nsts=`echo ${stsnames} | tr ':' ' ' | wc -w | awk '{print $1}'`
1404ist=1
1405while test ${ist} -le ${Nsts}; do
1406  sti=`echo ${stsids} | tr ':' '\n' | head -n ${ist} | tail -n 1`
1407  stn=`echo ${stsnames} | tr ':' '\n' | head -n ${ist} | tail -n 1`
1408  stl=`echo ${stslons} | tr ':' '\n' | head -n ${ist} | tail -n 1`
1409  stL=`echo ${stslats} | tr ':' '\n' | head -n ${ist} | tail -n 1`
1410  ist_1=`expr ${ist} - 1`
1411
1412  sfccompfiles=${obssfcfile}'%time|-1;Nstations|'${ist_1}
1413  sfccomplabs='obs'
1414  sfccompcols='#000000'
1415
1416  iexp=1
1417  for exp in ${exps}; do
1418    expl=`echo ${exp} | tr ',' ' ' | awk '{print $2}'`
1419    expn=`echo ${exp} | tr ',' ' ' | awk '{print $3}'`
1420    expc=`echo ${exp} | tr ',' ' ' | awk '{print $4}'`
1421
1422    simsfcdiagf=${odir}'/simout_sfcdiags_'${expl}'.nc'
1423
1424    gridsfcv=`python ${pyHOME}/nc_var.py -o get_point -f ${simsfcdiagf}              \
1425      -S 'XLONG:XLAT:Time|0' -v ${stl}','${stL} | tr ' ' '!'`
1426    xgrid=`echo ${gridsfcv} | tr '!' ' ' | awk '{print $1}' | tr ',' ' ' |           \
1427      awk '{print $1}'`
1428    ygrid=`echo ${gridsfcv} | tr '!' ' ' | awk '{print $1}' | tr ',' ' ' |           \
1429      awk '{print $2}'`
1430    distgrid=`echo ${gridsfcv} | tr '!' ' ' | awk '{print $2}'`
1431
1432    sfcstats=${sti}'@'${stn}'@'${stl}'@'${stL}'@'${gridsfc}
1433
1434    sfccompfiles=${sfccompfiles}','${simsfcdiagf}'%time|-1;south_north|'${ygrid}';west_east|'
1435    sfccompfiles=${sfccompfiles}${xgrid}
1436    sfccomplabs=${sfccomplabs}','${expn}
1437    sfccompcols=${sfccompcols}','${expc}
1438  done
1439  # end experiments
1440
1441  for sfcpv in ${sfcs}; do
1442    sfcv=`echo ${sfcpv} | tr '@' ' ' | awk '{print $1}'`
1443    nsfc=`echo ${sfcpv} | tr '@' ' ' | awk '{print $2}'`
1444    xsfc=`echo ${sfcpv} | tr '@' ' ' | awk '{print $3}'`
1445
1446    fivals=${sti}'@'${stn}'@'${sfcv}'@'${ofigdir}'@'${fmtTts}'@'${sfccompfiles}'@'
1447    fivals=${fivals}${sfccomplabs}'@'${sfccompcols}'@'${nsfc}'@'${xsfc}
1448    fivals=${fivals}'@obs-sim_evol_ts'
1449
1450    multiple_time_series_plot ${fivals}
1451
1452  done
1453  # end observations
1454
1455  ist=`expr $ist + 1`
1456done
1457# end sfc statinos
1458
1459# Cont-disc comparison
1460iexp=1
1461for exp in ${exps}; do
1462  expl=`echo ${exp} | tr ',' ' ' | awk '{print $2}'`
1463  expn=`echo ${exp} | tr ',' ' ' | awk '{print $3}'`
1464  expc=`echo ${exp} | tr ',' ' ' | awk '{print $4}'`
1465
1466  simsfcdiagf=${odir}'/simout_sfcdiags_'${expl}'.nc'
1467
1468  # Time information from simulation
1469  simdimt=`python ${pyHOME}/nc_var.py -o itime -S CFtime, -v time -f ${simsfcdiagf}  \
1470    | grep dimt | awk '{print $2-1}'`
1471  simtunits=`python ${pyHOME}/nc_var.py -o ivattrs -v time -f ${simsfcdiagf} |       \
1472    grep -v allvattrs | grep units | awk '{print $3}'`
1473  simTu=`echo ${tunits} | tr '!' ' ' | awk '{print $1}'`
1474  simDref0=`echo ${tunits} | tr '!' ' ' | awk '{print $3}'`
1475  simDref=${simDref0:0:4}${simDref0:5:2}${simDref0:8:2}
1476
1477  it=0
1478  while test ${it} -le ${simdimt}; do
1479    simtstep=`python ${pyHOME}/nc_var.py -o varout -f ${simsfcdiagf} -S              \
1480      'time:'${it} -v time | grep NC | awk '{printf ("%d",$2)}'`
1481    if test $? -ne 0; then
1482      echo ${errmsg}
1483      echo "  python failed!!"
1484      echo python ${pyHOME}/nc_var.py -o varout -f ${simsfcdiagf} -S 'time:'${it} -v time
1485      exit
1486    fi
1487
1488    timeS=`date +${figsndTfmt} -d"${simDref} ${simtstep} ${simTu}"`
1489    echo ${it}" "${simtstep}" "${simDref}" "${simTu}" "$(echo ${timeS} | tr '!' ' ')
1490    timefS=`date +%Y%m%d%H%M%S -d"${simDref} ${simtstep} ${simTu}"`
1491
1492    # Looking for obs time
1493    oitv=`python ${pyHOME}/nc_var.py -o get_time -f ${obssfcfile}                    \
1494      -S ${simtstep}';'${tunits} -v ststimes | grep -v differ | tr ' ' '@'`
1495    oit=`echo ${oitv} | tr '@' ' ' | awk '{print $1}'`
1496
1497    for sfcnxv in ${sfcs}; do
1498      sfcv=`echo ${sfcnxv} | tr '@' ' ' | awk '{print $1}'`
1499      nsfc=`echo ${sfcnxv} | tr '@' ' ' | awk '{print $2}'`
1500      xsfc=`echo ${sfcnxv} | tr '@' ' ' | awk '{print $3}'`
1501
1502      fivals=${expl}'#'${expn}'#'${sfcv}'#'${ofigdir}'#'${obssfcfile}'#'${simsfcdiagf}
1503      fivals=${fivals}'#'${it}'#'${oit}'#'${timeS}'#'${timefS}'#'${nsfc}'#'${xsfc}'#'
1504      fivals=${fivals}${mapv}'#'${mapcover}'#map_obs-sim'
1505
1506      shad_contdisc_map_plot ${fivals}
1507
1508    # end of variables
1509    done
1510
1511  it=`expr ${it} + 1`
1512  # end of time-steps
1513  done
1514
1515# end of simulations
1516done
1517fi
1518
1519fi
Note: See TracBrowser for help on using the repository browser.