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

Last change on this file since 2012 was 2012, checked in by lfita, 6 years ago

Working version with the generic definition of output file (preventing generalization...)

  • Property svn:executable set to *
File size: 55.6 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
791iost=1
792obstype='sounding'
793prn='snd'
794listfiles=${sndfiles}
795wrfdiags=${wrfsnddiags}
796simdiagd=${simsnddiagd}
797for ostf in ${listfiles}; do
798  stid=`python $pyHOME/nc_var.py -o grattr -f ${ostf} -S Station_number`
799  ostlon=`ncdump -h ${ostf} | grep Station_longitude | awk '{print $3}'`
800  ostlat=`ncdump -h ${ostf} | grep Station_latitude | awk '{print $3}'`
801  ostheight=`ncdump -h ${ostf} | grep Station_elevation | awk '{print $3}'`
802
803  if test ${iost} -eq 1; then 
804    oststids=${stid}'@'${ostf}
805    echo ${prn}","${stid}","${ostlon}","${ostlat}","${ostheight} > ${wdir}/stations.inf
806  else 
807    oststids=${oststids}':'${stid}'@'${ostf}
808    echo ${prn}","${stid}","${ostlon}","${ostlat}","${ostheight} >> ${wdir}/stations.inf
809  fi
810
811  iexp=1
812  for exp in ${exps}; do
813    expf=`echo ${exp} | tr ',' ' ' | awk '{print $1}'`
814    expl=`echo ${exp} | tr ',' ' ' | awk '{print $2}'`
815    expn=`echo ${exp} | tr ',' ' ' | awk '{print $3}'`
816    expc=`echo ${exp} | tr ',' ' ' | awk '{print $4}'`
817
818    simfiles=`ls -1 ${simdir}/${expf}/${simH}*${simM}*${simT}`
819
820    for simf in ${simfiles}; do
821      simfn=`basename ${simf}`
822      fdate=`echo ${simfn} | tr '.' ' ' | awk '{print $1}' | tr '_' ' ' |            \
823        awk '{print $3"_"$4}'`
824
825      simostptf=${odir}'/simout_vars_'${prn}'pt_'${stid}'_'${expl}'_'${fdate}'.nc'
826      simostdiagsf=${odir}'/simout_'${prn}'diags_'${stid}'_'${expl}'_'${fdate}'.nc'
827
828      fvals=${ostlon}'#'${ostlat}'#'${simf}'#XLONG#XLAT#'${wrfdiags}'#'
829      fvals=${fvals}${simdiagd}
830      get_WRFsounding_data ${fvals}
831
832    # end of files
833    done
834
835    # Concatenating files
836    ofile=${odir}/simout_${prn}vars_${stid}_${expl}.nc
837    if ${fscratch}; then rm ${ofile} >& /dev/null; fi
838    if test ! -f ${ofile}; then
839      Nconfc=`ls -1 ${odir}/simout_${prn}diags_*${stid}*${expl}*.nc | wc -l | awk '{print $1}'`
840      if test ${Nconfc} -gt 1; then 
841        values=${odir}',Time,time'
842        HMT='simout_'${prn}'diags_,'${stid}'_'${expn},'nc'
843        python ${pyHOME}/nc_var.py -o netcdf_fold_concatenation_HMT -S ${values}      \
844         -f ${HMT} -v all
845        if test $? -ne 0; then
846          echo ${errmsg}
847          echo "  python failed!!"
848          echo python ${pyHOME}/nc_var.py -o netcdf_fold_concatenation_HMT -S ${values}\
849          -f ${HMT} -v all
850          exit
851        fi
852        echo " * Concatenating "${obstype}" data at point: "${ostlon}", "${ostlat} >> ${ofileins}
853        echo python  ${pyHOME}/nc_var.py -o netcdf_fold_concatenation_HMT -S \
854          "'"${values}"'" -f ${HMT} -v all >> ${ofileins}
855        echo " " >> ${ofileins}
856        mv netcdf_fold_concatenated_HMT.nc ${ofile}
857      else
858        ffilen=`ls -1 ${odir}/simout_${prn}diags_*${stid}*${expl}*.nc`
859        cp ${ffilen} ${ofile}
860      fi
861    fi
862    iexp=`expr ${iexp} + 1`
863  # end of experiments
864  done
865
866  iost=`expr ${iost} + 1`
867done
868exit
869
870diagns=`echo ${wrfsnddiags} | tr ':' ' '`
871snddiagd='time@time,bottom_top@P,south_north@XLAT,west_east@XLONG'
872snddiagvals=''
873idiag=1
874for diagn in ${diagns}; do
875  diagv=`cat $pyHOME/diagnostics.inf | grep ${diagn}',' | tr ',' ' ' |               \
876    awk '{print $2"|"$3}'`
877  if test ${idiag} -eq 1; then
878    snddiagvals=${diagv}
879  else
880    snddiagvals=${snddiagvals}','${diagv}
881  fi
882  idiag=`expr ${idiag} + 1`
883done
884
885if test ${sfcvars} != 'None'; then
886# surface diags
887diagns=`echo ${wrfsfcdiags} | tr ':' ' '`
888sfcdiagd='time@time,south_north@XLAT,west_east@XLONG'
889sfcdiagvals=''
890idiag=1
891iadv=1
892for diagn in ${diagns}; do
893  diagv=`cat $pyHOME/diagnostics.inf | grep WRF | grep ${diagn}',' | tr ',' ' ' |    \
894    awk '{print $2"|"$3}'`
895  Ldiagv=`expr length $(echo ${diagv} | tr ' ' '@')0`
896  if test ${Ldiagv} -lt 2; then
897    echo ${errmsg}
898    echo "  diagnostic '"${diagn}"' (for WRF) does not exist !!"
899    if test ${iadv} -eq 1; then advs=${diagn}; iadv=`expr ${iadv} + 1`
900    else advs=${adv}','${diagn}; fi
901  else
902    if test ${idiag} -eq 1; then
903      sfcdiagvals=${diagv}
904      idiag=`expr ${idiag} + 1`
905    else
906      sfcdiagvals=${sfcdiagvals}','${diagv}
907    fi
908  fi
909done
910fi
911
912exps=`echo ${sims} | tr ':' ' '`
913
914iexp=1
915for exp in ${exps}; do
916  expf=`echo ${exp} | tr ',' ' ' | awk '{print $1}'`
917  expl=`echo ${exp} | tr ',' ' ' | awk '{print $2}'`
918  expn=`echo ${exp} | tr ',' ' ' | awk '{print $3}'`
919  expc=`echo ${exp} | tr ',' ' ' | awk '{print $4}'`
920
921  # Joining files
922  simjoinselvars=${odir}'/simout_vars_'${expl}'.nc'
923  if ${fscratch}; then rm ${simjoinselvars}; fi
924  if test ! -f ${simjoinselvars}; then
925    values=${simdir}'/'${expf}','${simtimedimn}','${simtimevarn}
926    HMT=${simHMT}
927    python ${pyHOME}/nc_var.py -o netcdf_fold_concatenation_HMT -S ${values}         \
928     -f ${HMT} -v ${simvars}
929    if test $? -ne 0; then
930      echo ${errmsg}
931      echo "  python failed!!"
932      echo python ${pyHOME}/nc_var.py -o netcdf_fold_concatenation_HMT -S "'"${values}"'"  \
933        -f "'"${HMT}"'" -v "'"${simvars}"'"
934      exit
935    fi
936    mv netcdf_fold_concatenated_HMT.nc ${simjoinselvars}
937  fi
938
939  # Computing sounding diagnostics
940  simdiagsf=${odir}'/simout_snddiags_'${expl}'.nc'
941  if ${fscratch}; then rm ${simdiagsf}; fi
942  if test ! -f ${simdiagsf}; then
943    python ${pyHOME}/diagnostics.py -f ${simjoinselvars} -d ${snddiagd} -v ${snddiagvals}
944    if test $? -ne 0; then
945      echo ${errmsg}
946      echo "  python failed!!"
947      echo python ${pyHOME}/diagnostics.py -f ${simjoinselvars} -d "'"${snddiagd}"'" -v "'"${snddiagvals}"'"
948      exit
949    fi
950    mv diagnostics.nc ${simdiagsf}
951    #To deg
952    python ${pyHOME}/nc_var.py -o valmod -S subc,273.15 -f ${simdiagsf} -v ta
953    #To Pa
954    python ${pyHOME}/nc_var.py -o valmod -S divc,100. -f ${simdiagsf} -v pres
955  fi
956
957  if test ${sfcvars} != 'None'; then
958  # Computing surface diagnostics
959  simsfcdiagf=${odir}'/simout_sfcdiags_'${expl}'.nc'
960  if ${fscratch}; then rm ${simsfcdiagf}; fi
961  if test ! -f ${simsfcdiagf}; then
962    python ${pyHOME}/diagnostics.py -f ${simjoinselvars} -d ${sfcdiagd} -v ${sfcdiagvals}
963    if test $? -ne 0; then
964      echo ${errmsg}
965      echo "  python failed!!"
966      echo python ${pyHOME}/diagnostics.py -f ${simjoinselvars} -d "'"${sfcdiagd}"'" -v ${sfcdiagvals}
967      exit
968    fi
969    mv diagnostics.nc ${simsfcdiagf}
970    #To rad
971    python ${pyHOME}/nc_var.py -o valmod -S mulc,0.0174532925199 -f ${simsfcdiagf} -v wds
972    python ${pyHOME}/nc_var.py -o varaddattr -S 'units|rad' -f ${simsfcdiagf} -v wds
973  fi
974
975  #Adding non-diagnostic variables
976  if test ${iadv} -ne 1; then
977    varsadd=`echo ${advs} | tr ',' ' '`
978    for vadd in ${varsadd}; do
979      python ${pyHOME}/nc_var.py -o fvaradd -S ${simjoinselvars},${vadd} -f ${simsfcdiagf}
980      if test $? -ne 0; then
981        echo ${errmsg}
982        echo "  python failed!!"
983        echo python ${pyHOME}/nc_var.py -o fvaradd -S "'"${simjoinselvars},${vadd}"'" -f ${simsfcdiagf}
984        exit
985        rm ${simsfcdiagf}
986      fi
987      # CF varname
988      CFvarn=`python $pyHOME/generic.py -o variables_values -S ${vadd} | tr ':' ' ' |  \
989        awk '{print $1}'`
990      if test $? -ne 0; then
991        echo ${errmsg}
992        echo "  python failed!!"
993        echo python $pyHOME/generic.py -o variables_values -S ${vadd}
994        exit
995        rm ${simsfcdiagf}
996      fi
997      python $pyHOME/nc_var.py -o chvarname -S ${CFvarn} -f ${simsfcdiagf} -v ${vadd}
998      if test $? -ne 0; then
999        echo ${errmsg}
1000        echo "  python failed!!"
1001        echo python ${pyHOME}/nc_var.py -o chvarname -S ${CFvarn} -f ${simsfcdiagf} -v ${vadd}
1002        exit
1003        rm ${simsfcdiagf}
1004      fi
1005    done
1006  fi
1007  fi
1008
1009  iexp=`expr ${iexp} + 1`
1010
1011# End experiments
1012done
1013
1014mkdir -p ${ofigdir}
1015
1016###
1017## Soundings figures
1018###
1019
1020isnd=1
1021for sndf in ${sndfiles}; do
1022  stid=`python $pyHOME/nc_var.py -o grattr -f ${sndf} -S Station_number`
1023
1024  # Getting wind components
1025  ouavasndf=${odir}'/sounding_uava_'${stid}'.nc'
1026  if ${fscratch}; then rm ${ouavasndf}; fi
1027  if test ! -f ${ouavasndf}; then
1028    python ${pyHOME}/diagnostics.py -f ${sndf} -d 'time@time,pres@pres' -v 'uavaFROMwswd|ws@wd'
1029    if test $? -ne 0; then
1030      echo ${errmsg}
1031      echo "  python failed!!"
1032      echo python ${pyHOME}/diagnostics.py -f ${sndf} -d 'time@time,pres@pres' -v 'uavaFROMwswd|ws@wd'
1033      exit
1034    fi 
1035    mv diagnostics.nc ${ouavasndf}
1036  fi
1037done
1038
1039sndids=`echo ${sndstids} | tr ':' ' '`
1040
1041for stidf in ${sndids}; do
1042  stid=`echo ${stidf} | tr '@' ' ' | awk '{print $1}'`
1043  sndorigfn=`echo ${stidf} | tr '@' ' ' | awk '{print $2}'`
1044  echo ${stid}" ..."
1045  it=0
1046  tatda_evol_values=''
1047  tatda_evol_files=''
1048  sndtimes=''
1049  snddates=''
1050  sndFdates=''
1051  snddimt=`python ${pyHOME}/nc_var.py -o itime -S CFtime -f ${sndorigfn} -v time | \
1052     grep 'dimt:' | awk '{print $2-1}'`
1053
1054  # Time characteristics
1055  tunits=`python ${pyHOME}/nc_var.py -o ivattrs -v time -f ${sndorigfn} | \
1056    grep -v allvattrs | grep units | awk '{print $3}'`
1057  Tu=`echo ${tunits} | tr '!' ' ' | awk '{print $1}'`
1058  Dref0=`echo ${tunits} | tr '!' ' ' | awk '{print $3}'`
1059  Dref=${Dref0:0:4}${Dref0:5:2}${Dref0:8:2}
1060
1061  # Getting values for evolution plot
1062  col=`echo ${icolta} | tr ':' ' ' | awk '{print $1}'`
1063  col2=`echo ${icolta} | tr ':' ' ' | awk '{print $2}'`
1064  while test ${it} -le ${snddimt}; do
1065    timev=`python $pyHOME/nc_var.py -o varout -S time:${it} -f ${sndorigfn} -v time | \
1066      grep NC | awk '{printf ("%d", $2)}'`
1067    timeS=`date +${figsndTfmt} -d"${Dref} ${timev} ${Tu}"`
1068    timeS2=`date +%d"$^{"%H"}$" -d"${Dref} ${timev} ${Tu}"`
1069    timeS3=`date +%Y"-"%b -d"${Dref} ${timev} ${Tu}"`
1070    timeS4=`date +%Y -d"${Dref} ${timev} ${Tu}"`
1071    echo "  "${it}" "${timev}" "${Dref}" '"${timev}"' "${Tu}" "$(echo ${timeS} | tr '!' ' ')
1072    timefS=`date +%Y%m%d%H%M%S -d"${Dref} ${timev} ${Tu}"`
1073
1074    # for now...
1075    sndstn=${stid}
1076
1077    fivals=${it}'#'${stid}'#'${sndstn}'#'${timeS}'#'${ofigdir}'#'${timefS}'#'
1078    fivals=${fivals}${ouavasndf}'#WindRose'
1079    WindRose_plot ${fivals}
1080
1081    fivals=${it}'#'${stid}'#'${sndstn}'#'${timeS}'#'${ofigdir}'#'${timefS}'#'
1082    fivals=${fivals}${sndorigfn}'#SkewT-logP_obs_ta-tda'
1083    SkewT_logP_plot ${fivals}
1084
1085    colH=`num_hex ${col}`
1086    colH2=`num_hex ${col2}`
1087    if test ${it} -eq 0; then
1088      sndtimes=${timev}
1089      snddates=${timeS}
1090      sndFdates=${timefS}
1091      tatda_evol_files=${sndorigfn}':pres|-1,time|'${it}':ta,pres;'
1092      tatda_evol_files=${tatda_evol_files}${sndorigfn}':pres|-1,time|'${it}':tda,pres'
1093      tatda_evol_labs='ta_'${timeS2}',tda'
1094      tatda_evol_cols='#'${colH}${colH2}${colH2}',#'${colH2}${colH2}${colH}
1095    else
1096      sndtimes=${sndtimes}','${timev}
1097      snddates=${snddates}','${timeS}
1098      sndFdates=${sndFdates}','${timefS}
1099      tatda_evol_files=${tatda_evol_files}';'${sndorigfn}':pres|-1,time|'${it}':ta,pres'
1100      tatda_evol_files=${tatda_evol_files}';'${sndorigfn}':pres|-1,time|'${it}':tda,pres'
1101      if test $(expr ${it} % 2) -eq 0; then 
1102        tatda_evol_labs=${tatda_evol_labs}','${timeS2}',None'
1103      else 
1104        tatda_evol_labs=${tatda_evol_labs}',None,None'
1105      fi
1106      tatda_evol_cols=${tatda_evol_cols}',#'${colH}${colH2}${colH2}',#'${colH2}${colH2}${colH}
1107    fi
1108    col=`expr ${col} - ${ddcol}`
1109    col2=`expr ${col2} - ${ddcol}`
1110
1111    #exit
1112    it=`expr ${it} + 1`
1113  done
1114
1115  fivals=${stid}'@'${sndstn}'@'${tatda_evol_labs}'@'${tatda_evol_cols}'@'
1116  fivals=${fivals}${tatda_evol_files}'@'${timeS3}'@'${ofigdir}'@SkewT-logP_obs_evol'
1117  multi_soundings_plot ${fivals}
1118
1119# End of soundings
1120done
1121
1122# snd-sims comparison
1123
1124for stidf in ${sndids}; do
1125  stid=`echo ${stidf} | tr '@' ' ' | awk '{print $1}'`
1126  sndorigfn=`echo ${stidf} | tr '@' ' ' | awk '{print $2}'`
1127  echo "snd: "${stid}
1128
1129  sndlon=`ncdump -h ${sndorigfn} | grep Station_longitude | awk '{print $3}'`
1130  sndlat=`ncdump -h ${sndorigfn} | grep Station_latitude | awk '{print $3}'`
1131  sndts=`echo ${sndtimes} | tr ',' ' '`
1132
1133  # for now...
1134  sndstn=${stid}
1135
1136  # Time characteristics
1137  tunits=`python ${pyHOME}/nc_var.py -o ivattrs -v time -f ${sndorigfn} |            \
1138    grep -v allvattrs | grep units | awk '{print $3}'`
1139  Tu=`echo ${tunits} | tr '!' ' ' | awk '{print $1}'`
1140  Dref0=`echo ${tunits} | tr '!' ' ' | awk '{print $3}'`
1141  Dref=${Dref0:0:4}${Dref0:5:2}${Dref0:8:2}
1142
1143  obsdimt=`python ${pyHOME}/nc_var.py -o itime -S CFtime, -v time -f ${sndorigfn} |  \
1144    grep dimt | awk '{print $2-1}'`
1145
1146  # Plotting
1147  it=0
1148  while test ${it} -le ${obsdimt}; do
1149
1150    otimev=`python $pyHOME/nc_var.py -o varout -S time:${it} -f ${sndorigfn} -v time |\
1151      grep NC | awk '{printf ("%d", $2)}'`
1152    dateS=`date +${figsndTfmt} -d"${Dref} ${otimev} ${Tu}"`
1153    timeS2=`date +%d"$^{"%H"}$" -d"${Dref} ${otimev} ${Tu}"`
1154    timeS3=`date +%Y"-"%b -d"${Dref} ${otimev} ${Tu}"`
1155    timeS4=`date +%Y -d"${Dref} ${otimev} ${Tu}"`
1156    datefS=`date +%Y%m%d%H%M%S -d"${Dref} ${otimev} ${Tu}"`
1157
1158    iexp=1
1159    for exp in ${exps}; do
1160      expf=`echo ${exp} | tr ',' ' ' | awk '{print $1}'`
1161      expl=`echo ${exp} | tr ',' ' ' | awk '{print $2}'`
1162      expn=`echo ${exp} | tr ',' ' ' | awk '{print $3}'`
1163      expc=`echo ${exp} | tr ',' ' ' | awk '{print $4}'`
1164
1165      simjoinselvars=${odir}'/simout_vars_'${expl}'.nc'
1166      simdiagsf=${odir}'/simout_snddiags_'${expl}'.nc'
1167
1168      gridsndv=`python ${pyHOME}/nc_var.py -o get_point -f ${simjoinselvars}         \
1169        -S 'XLONG:XLAT:Time|0' -v ${sndlon}','${sndlat} | tr ' ' '!'`
1170      xsnd=`echo ${gridsndv} | tr '!' ' ' | awk '{print $1}' | tr ',' ' ' |          \
1171        awk '{print $1}'`
1172      ysnd=`echo ${gridsndv} | tr '!' ' ' | awk '{print $1}' | tr ',' ' ' |          \
1173        awk '{print $2}'`
1174      dsnd=`echo ${gridsndv} | tr '!' ' ' | awk '{print $2}'`
1175      if test ${it} -eq 0 && test ${iexp} -eq 1; then
1176        echo "    Equivalent simulated sounding grid point: "${gridsnd}" distance: "\
1177          ${dsnd}
1178      fi
1179
1180      # Getting values at the sounding point
1181      simsndptf=${odir}'/simout_vars_sndpt_'${stid}'_'${expl}'.nc'
1182      if ${fscratch}; then rm ${simsndptf} >& /dev/null; fi
1183      if test ! -f ${simsndptf}; then
1184        values='time,0,-1,1@bottom_top,0,-1,1@south_north,'${ysnd}','${ysnd}',1@'
1185        values=${values}'west_east,'${xsnd}','${xsnd}',1'
1186        python ${pyHOME}/nc_var.py -o DataSetSection_multidims -f ${simdiagsf}       \
1187          -S ${values} -v all
1188        if test $? -ne 0; then
1189          echo ${errmsg}
1190          echo "  python failed!!"
1191          echo python ${pyHOME}/nc_var.py -o DataSetSection_multidims -f ${simdiagsf}\
1192            -S "'"${values}"'" -v all
1193          exit
1194        fi
1195        ofilen=`ls -rt1 ${odir} | tail -n 1`
1196        mv ${odir}/${ofilen} ${simsndptf}
1197      fi
1198
1199      # Time information from simulation
1200      simdimt=`python ${pyHOME}/nc_var.py -o itime -S CFtime, -v time                \
1201        -f ${simdiagsf} | grep dimt | awk '{print $2}'`
1202      simtunits=`python ${pyHOME}/nc_var.py -o ivattrs -v time -f ${simdiagsf} |     \
1203        grep -v allvattrs | grep units | awk '{print $3}'`
1204      simTu=`echo ${tunits} | tr '!' ' ' | awk '{print $1}'`
1205      simDref0=`echo ${tunits} | tr '!' ' ' | awk '{print $3}'`
1206      simDref=${simDref0:0:4}${simDref0:5:2}${simDref0:8:2}
1207
1208      # Time step from simulated file
1209      timestepv=`python ${pyHOME}/nc_var.py -o get_time -f ${simsndptf}               \
1210        -S ${otimev}';'${tunits} -v time | tr ' ' '@'`
1211      timestep=`echo ${timestepv} | tr '@' ' ' | awk '{print $1}'`
1212      if test $? -ne 0; then
1213        echo ${errmsg}
1214        echo "  python failed!!"
1215        echo python ${pyHOME}/nc_var.py -o get_time -f ${simsndptf}                  \
1216          -S ${otimev}';'${tunits} -v time
1217        exit
1218      fi
1219
1220      if test ${iexp} -eq 1; then
1221        echo "     "${it}": it="${timestep}" "$(echo ${dateS} | tr '!' ' ')" "${datefS}
1222        tacomplabs='$ta^{obs}$,$ta^{'${expn}'}$'
1223        tdacomplabs='$tda^{obs}$,$tda^{'${expn}'}$'
1224        tacompcols='#FF6464,'${expc}
1225        tdacompcols='#6464FF,'${expc}
1226        tacompltyp='-,-'
1227        tdacompltyp='-,-.'
1228        tacompfiles=${sndorigfn}':pres|-1,time|'${it}':ta,pres;'
1229        tacompfiles=${tacompfiles}${simsndptf}':bottom_top|-1,time|'${timestep}':'
1230        tacompfiles=${tacompfiles}'ta,pres'
1231        tdacompfiles=${sndorigfn}':pres|-1,time|'${it}':tda,pres;'
1232        tdacompfiles=${tdacompfiles}${simsndptf}':bottom_top|-1,time|'${timestep}':'
1233        tdacompfiles=${tdacompfiles}'tda,pres'
1234      else
1235        tacomplabs=${tacomplabs}',$ta^{'${expn}'}$'
1236        tdacomplabs=${tdacomplabs}',$tda^{'${expn}'}$'
1237        tacompcols=${tacompcols}','${expc}
1238        tdacompcols=${tdacompcols}','${expc}
1239        tacompltyp=${tacompltyp}',-'
1240        tdacompltyp=${tdacompltyp}',-.'
1241        tacompfiles=${tacompfiles}';'${simsndptf}':bottom_top|-1,time|'${timestep}':'
1242        tacompfiles=${tacompfiles}'ta,pres'
1243        tdacompfiles=${tdacompfiles}';'${simsndptf}':bottom_top|-1,time|'${timestep}
1244        tdacompfiles=${tdacompfiles}':tda,pres'
1245      fi
1246
1247      # Hovmoeller maps
1248      sndvs=`echo ${sndvars} | tr ':' ' '`
1249      for sndv in ${sndvs}; do
1250
1251        CFvarvals=`python $pyHOME/generic.py -o variables_values -S ${sndv}`
1252        cbar=`echo ${CFvarvals} | tr ':' ' ' | awk '{print $7}'`
1253
1254        fivals=${stid}'#'${sndstn}'#'${sndv}'#'${ofigdir}'#'${datefS}'#'${fmtTts}
1255        fivals=${fivals}'#'${simsndptf}'#'${sndorigfn}'#'${expl}'#'${expn}'#'${cbar}
1256        fivals=${fivals}'#SkewT-logP_obs-sim_evol'
1257
1258        Homoeller_SkewT_map_plot ${fivals}
1259
1260      # end sounding vars
1261      done
1262
1263      iexp=`expr ${iexp} + 1`
1264    # End experiments
1265    done
1266
1267    complabs=${tacomplabs}','${tdacomplabs}
1268    compcols=${tacompcols}','${tdacompcols}
1269    compltyp=${tacompltyp}','${tdacompltyp}
1270    compfiles=${tacompfiles}';'${tdacompfiles}
1271
1272    fivals=${stid}'@'${sndstn}'@'${complabs}'@'${compcols}'@'${compltyp}'@'
1273    fivals=${fivals}${compfiles}'@'${dateS}'@'${ofigdir}'@'${datefS}'@'${ofigdir}'@'
1274    fivals=${fivals}'SkewT-logP_obs-sim_step'
1275
1276    multi_SkewT_logP_plot ${fivals}
1277
1278    # Wind Rose comparison
1279    fivals=${it}'#'${stid}'#'${sndstn}'#'${timeS}'#'${ofigdir}'#'${timefS}'#'
1280    fivals=${fivals}${ouavasndf}'#WindRose_obs-sim_'
1281    multi_WindRose_plot ${fivals}
1282
1283    it=`expr ${it} + 1`
1284  # End sounding time-steps
1285  done
1286
1287# End of soundings stations
1288done
1289
1290###
1291## SFC figures
1292###
1293
1294# Joining all observations
1295obssfcfile=${odir}'/all_single-stations.nc'
1296if test ! -f ${wdir}/${sfcdir}/${obssfcfile}; then
1297  python ${pyHOME}/nc_var.py -o join_singlestation_obsfiles -S                       \
1298    ${sfcdir}':OBSnetcdf' -v all
1299  if test $? -ne 0; then
1300    echo ${errmsg}
1301    echo "  python failed!!"
1302    echo  python ${pyHOME}/nc_var.py -o join_singlestation_obsfiles \
1303      -S ${sfcdir}':OBSnetcdf' -v all
1304  fi
1305  mv joined_singlestations.nc ${obssfcfile}
1306fi
1307
1308# getting min,max values
1309if test ${sfcvars} != 'None'; then
1310fcs=`echo ${sfcvars} | tr ':' ' '`
1311
1312iv=1
1313for sfcpv in ${sfcs}; do
1314  sfcv=`echo ${sfcpv} | tr '@' ' ' | awk '{print $1}'`
1315  nsfc=`echo ${sfcpv} | tr '@' ' ' | awk '{print $2}'`
1316  xsfc=`echo ${sfcpv} | tr '@' ' ' | awk '{print $3}'`
1317  if test ${nsfc} = 'FROMobs'; then
1318    fstats=`python $pyHOME/nc_var.py -o field_stats -S full,1.e+20,None              \
1319      -f ${obssfcfile} -v ${sfcv} | grep MAT | grep ${sfcv}`
1320    nsfc=`echo ${fstats} | awk '{print $3}'`
1321  elif test ${nsfc} = 'FROMsims'; then
1322    iexp=1
1323    for exp in ${exps}; do
1324      expl=`echo ${exp} | tr ',' ' ' | awk '{print $2}'`
1325      simsfcdiagf=${odir}'/simout_sfcdiags_'${expl}'.nc'
1326   
1327      fstats=`python $pyHOME/nc_var.py -o field_stats -S full,1.e+20,None            \
1328        -f ${simsfcdiagf} -v ${sfcv} | grep MAT | grep ${sfcv}`
1329      if test ${iexp} -eq 1; then
1330        nsfc=`echo ${fstats} | awk '{print $3}'`
1331      else
1332        nsfc2=`echo ${fstats} | awk '{print $3}'`
1333        nsfcf=`echo ${nsfc}" "${nsfc2} | awk '{if ($1 < $2) {print $1;} else {print $2;}}'`
1334      fi
1335    done
1336  elif test ${nsfc} = 'FROMobssims'; then
1337    fstats=`python $pyHOME/nc_var.py -o field_stats -S full,1.e+20,None              \
1338      -f ${obssfcfile} -v ${sfcv} | grep MAT | grep ${sfcv}`
1339    nsfc=`echo ${fstats} | awk '{print $3}'`
1340    for exp in ${exps}; do
1341      expl=`echo ${exp} | tr ',' ' ' | awk '{print $2}'`
1342      simsfcdiagf=${odir}'/simout_sfcdiags_'${expl}'.nc'
1343   
1344      fstats=`python $pyHOME/nc_var.py -o field_stats -S full,1.e+20,None            \
1345        -f ${simsfcdiagf} -v ${sfcv} | grep MAT | grep ${sfcv}`
1346      nsfc2=`echo ${fstats} | awk '{print $3}'`
1347      nsfc=`echo ${nsfc}" "${nsfc2} | awk '{if ($1 < $2) {print $1;} else {print $2;}}'`
1348    done
1349  fi
1350  if test ${xsfc} = 'FROMobs'; then
1351    fstats=`python $pyHOME/nc_var.py -o field_stats -S full,1.e+20,None              \
1352      -f ${obssfcfile} -v ${sfcv} | grep MAT | grep ${sfcv}`
1353    xsfc=`echo ${fstats} | awk '{print $4}'`
1354  elif test ${xsfc} = 'FROMsims'; then
1355    iexp=1
1356    for exp in ${exps}; do
1357      expl=`echo ${exp} | tr ',' ' ' | awk '{print $2}'`
1358      simsfcdiagf=${odir}'/simout_sfcdiags_'${expl}'.nc'
1359   
1360      fstats=`python $pyHOME/nc_var.py -o field_stats -S full,1.e+20,None            \
1361        -f ${simsfcdiagf} -v ${sfcv} | grep MAT | grep ${sfcv}`
1362      if test ${iexp} -eq 1; then
1363        xsfc=`echo ${fstats} | awk '{print $4}'`
1364      else
1365        xsfc2=`echo ${fstats} | awk '{print $4}'`
1366        xsfcf=`echo ${xsfc}" "${xsfc2} | awk '{if ($1 > $2) {print $1;} else {print $2;}}'`
1367      fi
1368    done
1369  elif test ${nsfc} = 'FROMobssims'; then
1370    fstats=`python $pyHOME/nc_var.py -o field_stats -S full,1.e+20,None              \
1371      -f ${obssfcfile} -v ${sfcv} | grep MAT | grep ${sfcv}`
1372    xsfc=`echo ${fstats} | awk '{print $4}'`
1373    iexp=1
1374    for exp in ${exps}; do
1375      expl=`echo ${exp} | tr ',' ' ' | awk '{print $2}'`
1376      simsfcdiagf=${odir}'/simout_sfcdiags_'${expl}'.nc'
1377   
1378      fstats=`python $pyHOME/nc_var.py -o field_stats -S full,1.e+20,None            \
1379        -f ${simsfcdiagf} -v ${sfcv} | grep MAT | grep ${sfcv}`
1380      xsfc2=`echo ${fstats} | awk '{print $4}'`
1381      xsfcf=`echo ${xsfc}" "${xsfc2} | awk '{if ($1 > $2) {print $1;} else {print $2;}}'`
1382    done
1383  fi
1384  if test $iv -eq 1; then
1385    newsfcvars=${sfcv}'@'${nsfc}'@'${xsfc}
1386  else
1387    newsfcvars=${newsfcvars}':'${sfcv}'@'${nsfc}'@'${xsfc}
1388  fi
1389  iv=`expr ${iv} + 1`
1390done
1391sfcs=`echo ${newsfcvars} | tr ':' ' '`
1392echo "new sfc variables: "${sfcs}
1393
1394# Time-series
1395
1396# stations
1397# FROM: https://stackoverflow.com/questions/2961635/using-awk-to-print-all-columns-from-the-nth-to-the-last
1398stsids=`python ${pyHOME}/nc_var.py -o varout -v id -f \
1399  ${obssfcfile} -S 'Nstations:-1|time:0' | awk '{$1=""; printf("%d:",substr($0,2))}'`
1400stsnames=`python ${pyHOME}/nc_var.py -o varout -v stsname -f \
1401  ${obssfcfile} -S Nstations:-1 | awk '{$1=""; print substr($0,2)}' | tr '\n' ':' | \
1402  tr ' ' '!'`
1403stslons=`python ${pyHOME}/nc_var.py -o varout -v stslon -f \
1404  ${obssfcfile} -S Nstations:-1 | awk '{$1=""; print substr($0,2)}' | tr '\n' ':'`
1405stslats=`python ${pyHOME}/nc_var.py -o varout -v stslat -f \
1406  ${obssfcfile} -S Nstations:-1 | awk '{$1=""; print substr($0,2)}' | tr '\n' ':'`
1407
1408Nsts=`echo ${stsnames} | tr ':' ' ' | wc -w | awk '{print $1}'`
1409ist=1
1410while test ${ist} -le ${Nsts}; do
1411  sti=`echo ${stsids} | tr ':' '\n' | head -n ${ist} | tail -n 1`
1412  stn=`echo ${stsnames} | tr ':' '\n' | head -n ${ist} | tail -n 1`
1413  stl=`echo ${stslons} | tr ':' '\n' | head -n ${ist} | tail -n 1`
1414  stL=`echo ${stslats} | tr ':' '\n' | head -n ${ist} | tail -n 1`
1415  ist_1=`expr ${ist} - 1`
1416
1417  sfccompfiles=${obssfcfile}'%time|-1;Nstations|'${ist_1}
1418  sfccomplabs='obs'
1419  sfccompcols='#000000'
1420
1421  iexp=1
1422  for exp in ${exps}; do
1423    expl=`echo ${exp} | tr ',' ' ' | awk '{print $2}'`
1424    expn=`echo ${exp} | tr ',' ' ' | awk '{print $3}'`
1425    expc=`echo ${exp} | tr ',' ' ' | awk '{print $4}'`
1426
1427    simsfcdiagf=${odir}'/simout_sfcdiags_'${expl}'.nc'
1428
1429    gridsfcv=`python ${pyHOME}/nc_var.py -o get_point -f ${simsfcdiagf}              \
1430      -S 'XLONG:XLAT:Time|0' -v ${stl}','${stL} | tr ' ' '!'`
1431    xgrid=`echo ${gridsfcv} | tr '!' ' ' | awk '{print $1}' | tr ',' ' ' |           \
1432      awk '{print $1}'`
1433    ygrid=`echo ${gridsfcv} | tr '!' ' ' | awk '{print $1}' | tr ',' ' ' |           \
1434      awk '{print $2}'`
1435    distgrid=`echo ${gridsfcv} | tr '!' ' ' | awk '{print $2}'`
1436
1437    sfcstats=${sti}'@'${stn}'@'${stl}'@'${stL}'@'${gridsfc}
1438
1439    sfccompfiles=${sfccompfiles}','${simsfcdiagf}'%time|-1;south_north|'${ygrid}';west_east|'
1440    sfccompfiles=${sfccompfiles}${xgrid}
1441    sfccomplabs=${sfccomplabs}','${expn}
1442    sfccompcols=${sfccompcols}','${expc}
1443  done
1444  # end experiments
1445
1446  for sfcpv in ${sfcs}; do
1447    sfcv=`echo ${sfcpv} | tr '@' ' ' | awk '{print $1}'`
1448    nsfc=`echo ${sfcpv} | tr '@' ' ' | awk '{print $2}'`
1449    xsfc=`echo ${sfcpv} | tr '@' ' ' | awk '{print $3}'`
1450
1451    fivals=${sti}'@'${stn}'@'${sfcv}'@'${ofigdir}'@'${fmtTts}'@'${sfccompfiles}'@'
1452    fivals=${fivals}${sfccomplabs}'@'${sfccompcols}'@'${nsfc}'@'${xsfc}
1453    fivals=${fivals}'@obs-sim_evol_ts'
1454
1455    multiple_time_series_plot ${fivals}
1456
1457  done
1458  # end observations
1459
1460  ist=`expr $ist + 1`
1461done
1462# end sfc statinos
1463
1464# Cont-disc comparison
1465iexp=1
1466for exp in ${exps}; do
1467  expl=`echo ${exp} | tr ',' ' ' | awk '{print $2}'`
1468  expn=`echo ${exp} | tr ',' ' ' | awk '{print $3}'`
1469  expc=`echo ${exp} | tr ',' ' ' | awk '{print $4}'`
1470
1471  simsfcdiagf=${odir}'/simout_sfcdiags_'${expl}'.nc'
1472
1473  # Time information from simulation
1474  simdimt=`python ${pyHOME}/nc_var.py -o itime -S CFtime, -v time -f ${simsfcdiagf}  \
1475    | grep dimt | awk '{print $2-1}'`
1476  simtunits=`python ${pyHOME}/nc_var.py -o ivattrs -v time -f ${simsfcdiagf} |       \
1477    grep -v allvattrs | grep units | awk '{print $3}'`
1478  simTu=`echo ${tunits} | tr '!' ' ' | awk '{print $1}'`
1479  simDref0=`echo ${tunits} | tr '!' ' ' | awk '{print $3}'`
1480  simDref=${simDref0:0:4}${simDref0:5:2}${simDref0:8:2}
1481
1482  it=0
1483  while test ${it} -le ${simdimt}; do
1484    simtstep=`python ${pyHOME}/nc_var.py -o varout -f ${simsfcdiagf} -S              \
1485      'time:'${it} -v time | grep NC | awk '{printf ("%d",$2)}'`
1486    if test $? -ne 0; then
1487      echo ${errmsg}
1488      echo "  python failed!!"
1489      echo python ${pyHOME}/nc_var.py -o varout -f ${simsfcdiagf} -S 'time:'${it} -v time
1490      exit
1491    fi
1492
1493    timeS=`date +${figsndTfmt} -d"${simDref} ${simtstep} ${simTu}"`
1494    echo ${it}" "${simtstep}" "${simDref}" "${simTu}" "$(echo ${timeS} | tr '!' ' ')
1495    timefS=`date +%Y%m%d%H%M%S -d"${simDref} ${simtstep} ${simTu}"`
1496
1497    # Looking for obs time
1498    oitv=`python ${pyHOME}/nc_var.py -o get_time -f ${obssfcfile}                    \
1499      -S ${simtstep}';'${tunits} -v ststimes | grep -v differ | tr ' ' '@'`
1500    oit=`echo ${oitv} | tr '@' ' ' | awk '{print $1}'`
1501
1502    for sfcnxv in ${sfcs}; do
1503      sfcv=`echo ${sfcnxv} | tr '@' ' ' | awk '{print $1}'`
1504      nsfc=`echo ${sfcnxv} | tr '@' ' ' | awk '{print $2}'`
1505      xsfc=`echo ${sfcnxv} | tr '@' ' ' | awk '{print $3}'`
1506
1507      fivals=${expl}'#'${expn}'#'${sfcv}'#'${ofigdir}'#'${obssfcfile}'#'${simsfcdiagf}
1508      fivals=${fivals}'#'${it}'#'${oit}'#'${timeS}'#'${timefS}'#'${nsfc}'#'${xsfc}'#'
1509      fivals=${fivals}${mapv}'#'${mapcover}'#map_obs-sim'
1510
1511      shad_contdisc_map_plot ${fivals}
1512
1513    # end of variables
1514    done
1515
1516  it=`expr ${it} + 1`
1517  # end of time-steps
1518  done
1519
1520# end of simulations
1521done
1522fi
1523
1524fi
Note: See TracBrowser for help on using the repository browser.