source: lmdz_wrf/trunk/tools/obs-sim_Comparison_ONLYfigures.bash @ 2831

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

Working on it, but not followed.... no time! GEWEX-CPC

  • Property svn:executable set to *
File size: 46.5 KB
Line 
1#!/bin/bash
2# Shell script to compare observations with simulations using PyNCplot figures 'ONLY'
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
54fscratch=false
55
56# figures from scratch
57if test ${gscratch} = 'true'; then gscratch=true
58else gscratch=false; fi
59
60function num_hex(){
61# Fucntion to transform a number to a hexagonal basis
62#   num: number to transform
63  fname='num_hex'
64  num=$1
65
66  if test ${num} -gt 255; then
67    echo ${errormsg}
68    echo "  "${fname}": value "${num}" too large !!"
69    exit
70  fi
71  if test ${num} -gt 16; then
72    xviA=`expr ${num} / 16`
73    numA=`expr ${xviA} '*' 16`
74    xviB=`expr ${num} - ${numA}`
75  else
76    xviA=0
77    xviB=${num}
78  fi
79
80  if test ${xviA} -gt 9; then
81    case ${xviA} in
82      10)
83        hexA='A'
84      ;;
85      11)
86        hexA='B'
87      ;;
88      12)
89        hexA='C'
90      ;;
91      13)
92        hexA='D'
93      ;;
94      14)
95        hexA='E'
96      ;;
97      15)
98        hexA='F'
99      ;;
100    esac
101  else
102    hexA=${xviA}
103  fi
104
105  if test ${xviB} -gt 9; then
106    case ${xviB} in
107      10)
108        hexB='A'
109      ;;
110      11)
111        hexB='B'
112      ;;
113      12)
114        hexB='C'
115      ;;
116      13)
117        hexB='D'
118      ;;
119      14)
120        hexB='E'
121      ;;
122      15)
123        hexB='F'
124      ;;
125    esac
126  else
127    hexB=${xviB}
128  fi
129
130  echo ${hexA}${hexB}
131}
132
133function isin_list() {
134# Function to check whether a value is in a list
135  list=$1
136  value=$2
137 
138  is=`echo ${list} | tr ':' '\n' | awk '{print "@"$1"@"}' | grep '@'${value}'@' | wc -w`
139  if test ${is} -eq 1
140  then
141    true
142  else
143    false
144  fi
145}
146
147function WindRose_plot() {
148# Function to plot a Wind rose
149#   it: time-step to use from the file
150#   sndstid: id of the sounding station
151#   sndstn: name of the sounding station to appear in plot ('!' for spaces)
152#   timeS: String with the format of the actual time ('!' for spaces)
153#   ofigdir: folder for the output of the figure
154#   timefS: date of the plot to be used for the figure name
155#   filen: file to use
156#   figheader: header of the figure's file name
157
158    valuesfig=$1
159
160    it=`echo ${valuesfig} | tr '#' ' ' | awk '{print $1}'`
161    sndstid=`echo ${valuesfig} | tr '#' ' ' | awk '{print $2}'`
162    sndstn=`echo ${valuesfig} | tr '#' ' ' | awk '{print $3}'`
163    timeS=`echo ${valuesfig} | tr '#' ' ' | awk '{print $4}'`
164    ofigdir=`echo ${valuesfig} | tr '#' ' ' | awk '{print $5}'`
165    timefS=`echo ${valuesfig} | tr '#' ' ' | awk '{print $6}'`
166    filen=`echo ${valuesfig} | tr '#' ' ' | awk '{print $7}'`
167    figheader=`echo ${valuesfig} | tr '#' ' ' | awk '{print $8}'`
168
169    values='pres|-1;time|'${it}':linepoint;multicol;pres;auto;auto;rainbow;auto:'
170    values=${values}${sndstn}'!sounding!WindRose!on!'${timeS}'!local!time:'${kfig}
171    values=${values}':cardinals:False:WindRose:True'
172    ofign=${ofigdir}'/'${figheader}'_'${sndstid}'_'${timefS}'.'${kfig}
173    if ${gscratch}; then rm ${ofign} >& /dev/null; fi
174    if test ! -f ${ofign}; then
175      echo "    Wind Rose on: "$(echo ${timeS} | tr '!' ' ')
176      python ${pyHOME}/drawing.py -o draw_WindRose -S ${values} -v ua,va -f ${filen} >& /dev/null
177      if test $? -ne 0; then
178        echo ${errmsg}
179        echo "  python failed!!"
180        echo python ${pyHOME}/drawing.py -o draw_WindRose -S "'"${values}"'" -v ua,va -f ${filen}
181        exit
182      fi
183      convert -trim WindRose.png ${ofign}
184      echo "* "${ofign} >> ${ofilefigs}
185      echo python ${pyHOME}/drawing.py -o draw_WindRose -S "'"${values}"'" -v ua,va -f "'"${filen}"'" >> ${ofilefigs}
186      echo " " >> ${ofilefigs}
187    fi
188}
189
190function SkewT_logP_plot() {
191# Function to plot a SkewT_logP plot
192#   it: time step to use from file
193#   sndstid: id of the sounding station
194#   sndstn: name of the sounding station to appear in plot ('!' for spaces)
195#   timeS: String with the format of the actual time ('!' for spaces)
196#   ofigdir: folder for the output of the figure
197#   timefS: date of the plot to be used for the figure name
198#   filen: file to use
199#   figheader: header of the figure's file name
200
201    valuesfig=$1
202
203    it=`echo ${valuesfig} | tr '#' ' ' | awk '{print $1}'`
204    sndstid=`echo ${valuesfig} | tr '#' ' ' | awk '{print $2}'`
205    sndstn=`echo ${valuesfig} | tr '#' ' ' | awk '{print $3}'`
206    timeS=`echo ${valuesfig} | tr '#' ' ' | awk '{print $4}'`
207    ofigdir=`echo ${valuesfig} | tr '#' ' ' | awk '{print $5}'`
208    timefS=`echo ${valuesfig} | tr '#' ' ' | awk '{print $6}'`
209    filen=`echo ${valuesfig} | tr '#' ' ' | awk '{print $7}'`
210    figheader=`echo ${valuesfig} | tr '#' ' ' | awk '{print $8}'`
211 
212    values='time|'${it}',pres|-1:auto:auto:'${sndstn}'!sounding!on!'${timeS}'!local!'
213    values=${values}'time:'${kfig}':True'
214    ofign=${ofigdir}'/'${figheader}'_'${sndstid}'_'${timefS}'.'${kfig}
215    if ${gscratch}; then rm ${ofign} >& /dev/null; fi
216    if test ! -f ${ofign}; then
217      echo "    Sounding on: "$(echo ${timeS} | tr '!' ' ')
218      python ${pyHOME}/drawing.py -o draw_SkewT -S ${values} -v ta,tda,pres -f ${filen} >& /dev/null
219      if test $? -ne 0; then
220        echo ${errmsg}
221        echo "  python failed!!"
222        echo python ${pyHOME}/drawing.py -o draw_SkewT -S "'"${values}"'" -v ta,tda,pres -f ${filen}
223        exit
224      fi
225      convert -trim SkewT.png ${ofign}
226      echo "* "${ofign} >> ${ofilefigs}
227      echo python ${pyHOME}/drawing.py -o draw_SkewT -S "'"${values}"'" -v ta,tda,pres -f "'"${filen}"'" >> ${ofilefigs}
228      echo " " >> ${ofilefigs}
229    fi
230}
231
232function multi_soundings_plot() {
233# Function to plot a multi_sounding figure
234#   sndstid: id of the sounding station
235#   sndstn: name of the sounding station to appear in plot ('!' for spaces)
236#   tatda_evol_labs: labels for the figure
237#   tatda_evol_cols: colors of the lines for the figure
238#   timeS3: date in the figure
239#   ofigdir: folder for the output figure
240#   figheader: header of the figure's file name
241
242  valuesfig=$1
243
244  sndstid=`echo ${valuesfig} | tr '@' ' ' | awk '{print $1}'`
245  sndstn=`echo ${valuesfig} | tr '@' ' ' | awk '{print $2}'`
246  tatda_evol_labs=`echo ${valuesfig} | tr '@' ' ' | awk '{print $3}'`
247  tatda_evol_cols=`echo ${valuesfig} | tr '@' ' ' | awk '{print $4}'`
248  tatda_evol_files=`echo ${valuesfig} | tr '@' ' ' | awk '{print $5}'`
249  timeS3=`echo ${valuesfig} | tr '@' ' ' | awk '{print $6}'`
250  ofigdir=`echo ${valuesfig} | tr '@' ' ' | awk '{print $7}'`
251  figheader=`echo ${valuesfig} | tr '@' ' ' | awk '{print $8}'`
252
253  tatda_evol_values='auto:auto:multilines!'${tatda_evol_labs}'!'${tatda_evol_cols}'!'
254  tatda_evol_values=${tatda_evol_values}'-!,!2:0,auto:'${sndstn}'!sounding!evolution!on!'
255  tatda_evol_values=${tatda_evol_values}${timeS3}'!local!time:'${kfig}':True'
256
257  ofign=${ofigdir}'/'${figheader}'_'${stid}'.'${kfig}
258  if ${gscratch}; then rm ${ofign} >& /dev/null; fi
259  if test ! -f ${ofign}; then
260    echo "    Sounding on: "$(echo ${timeS} | tr '!' ' ')
261    python ${pyHOME}/drawing.py -o draw_multi_SkewT -S ${tatda_evol_values} -f ${tatda_evol_files} >& /dev/null
262    if test $? -ne 0; then
263      echo ${errmsg}
264      echo "  python failed!!"
265      echo python ${pyHOME}/drawing.py -o draw_multi_SkewT -S "'"${tatda_evol_values}"'" -f "'"${tatda_evol_files}"'"
266      exit
267    fi
268    convert -trim multi_SkewT.png ${ofign}
269    echo "* "${ofign} >> ${ofilefigs}
270    echo python ${pyHOME}/drawing.py -o draw_multi_SkewT -S "'"${tatda_evol_values}"'" -f "'"${tatda_evol_files}"'" >> ${ofilefigs}
271    echo " " >> ${ofilefigs}
272  fi
273}
274
275function multi_SkewT_logP_plot() {
276# Function to plot a multi_SkewT_logP plot with multiple lines
277#   sndstid: id of the sounding station
278#   sndstn: name of the sounding station to appear in plot ('!' for spaces)
279#   complabs: labels for the plot
280#   compcols: colors for the plot
281#   complines: type of lines for the plot
282#   compfiles: files to use for the plot
283#   dateS: String with the format of the actual time ('!' for spaces)
284#   ofigdir: folder for the output of the figure
285#   datefS: date of the plot to be used for the figure name
286#   figheader: header of the figure's file name
287
288    valuesfig=$1
289    sndstid=`echo ${valuesfig} | tr '@' ' ' | awk '{print $1}'`
290    sndstn=`echo ${valuesfig} | tr '@' ' ' | awk '{print $2}'`
291    complabs=`echo ${valuesfig} | tr '@' ' ' | awk '{print $3}'`
292    compcols=`echo ${valuesfig} | tr '@' ' ' | awk '{print $4}'`
293    complines=`echo ${valuesfig} | tr '@' ' ' | awk '{print $5}'`
294    compfiles=`echo ${valuesfig} | tr '@' ' ' | awk '{print $6}'`
295    dateS=`echo ${valuesfig} | tr '@' ' ' | awk '{print $7}'`
296    ofigdir=`echo ${valuesfig} | tr '@' ' ' | awk '{print $8}'`
297    datefS=`echo ${valuesfig} | tr '@' ' ' | awk '{print $9}'`
298    figheader=`echo ${valuesfig} | tr '@' ' ' | awk '{print $10}'`
299
300    values='auto:auto:multilines!'${complabs}'!'${compcols}'!'
301    values=${values}${complines}'!,!2:0,auto:'${ststn}'!sounding!obs!,!sim!'
302    values=${values}'comparison!on!'${dateS}'!UTC:png:True'
303
304    ofign=${ofigdir}'/'${figheader}'_'${sndstid}'_'${datefS}'.'${kfig}
305    if ${gscratch}; then rm ${ofign} >& /dev/null; fi
306    if test ! -f ${ofign}; then
307      echo "    Sounding on: "$(echo ${dateS} | tr '!' ' ')
308      python ${pyHOME}/drawing.py -o draw_multi_SkewT -S ${values} -f ${compfiles} >& /dev/null
309      if test $? -ne 0; then
310        echo ${errmsg}
311        echo "  python failed!!"
312        echo python ${pyHOME}/drawing.py -o draw_multi_SkewT -S "'"${values}"'" -f "'"${compfiles}"'"
313        exit
314      fi
315      convert -trim multi_SkewT.png ${ofign}
316      echo "* "${ofign} >> ${ofilefigs}
317      echo python ${pyHOME}/drawing.py -o draw_multi_SkewT -S "'"${values}"'" -f "'"${compfiles}"'" >> ${ofilefigs}
318      echo " " >> ${ofilefigs}
319    fi
320}
321
322function Hovmoeller_SkewT_map_plot() {
323# Function to plot a Hovmoeller SkewT_map
324#   sndstid: id of the sounding station
325#   sndstn: name of the sounding station to appear in plot ('!' for spaces)
326#   sndv: variable to plot
327#   ofigdir: folder for the output of the figure
328#   datefS: date of the plot to be used for the figure name
329#   timevals: values to use for the time-axis in the plot
330#   simfilen: name of the simulation file at the given point
331#   sndfilen: name of the sounding file
332#   expl: label of the experiment
333#   expn: name of the experiment
334#   cbar: color bar
335#   figheader: header of the figure's file name
336
337  valuesfig=$1
338  sndstid=`echo ${valuesfig} | tr '#' ' ' | awk '{print $1}'`
339  sndstn=`echo ${valuesfig} | tr '#' ' ' | awk '{print $2}'`
340  sndv=`echo ${valuesfig} | tr '#' ' ' | awk '{print $3}'`
341  ofigdir=`echo ${valuesfig} | tr '#' ' ' | awk '{print $4}'`
342  datefS=`echo ${valuesfig} | tr '#' ' ' | awk '{print $5}'`
343  timevals=`echo ${valuesfig} | tr '#' ' ' | awk '{print $6}'`
344  simfilen=`echo ${valuesfig} | tr '#' ' ' | awk '{print $7}'`
345  sndfilen=`echo ${valuesfig} | tr '#' ' ' | awk '{print $8}'`
346  expl=`echo ${valuesfig} | tr '#' ' ' | awk '{print $9}'`
347  expn=`echo ${valuesfig} | tr '#' ' ' | awk '{print $10}'`
348  cbar=`echo ${valuesfig} | tr '#' ' ' | awk '{print $11}'`
349  figheader=`echo ${valuesfig} | tr '#' ' ' | awk '{print $12}'`
350
351  cfiles=${simfilen}';'${sndv}';time;pres;time|-1,pres|-1@'
352  cfiles=${cfiles}${sndfilen}';'${sndv}';time;pres;time|-1,pres|-1'
353  cvalues=${sndv}';y;auto|'${timevals}';Vfix,auto,50.,auto'
354  cvalues=${cvalues}';'${cbar}',auto,auto;Srange,Srange;auto;obs!,!'${expn}'!'
355  cvalues=${cvalues}${sndstn}'!sounding;'${kfig}';flip@y;None;yes'
356
357  ofign=${ofigdir}'/'${figheader}'_'${expl}'_'${sndstid}'_'${sndv}'.'${kfig}
358  if ${gscratch}; then rm ${ofign} >& /dev/null; fi
359  if test ! -f ${ofign}; then
360    echo "    Sounding comparison on : "${sndstid}" by "${expl}
361    python ${pyHOME}/drawing.py -o draw_2D_shad_contdisc_time -f ${cfiles} -S ${cvalues}
362    if test $? -ne 0; then
363      echo ${errmsg}
364      echo "  python failed!!"
365      echo python ${pyHOME}/drawing.py -o draw_2D_shad_contdisc_time -f "'"${cfiles}"'" -S "'"${cvalues}"'"
366      exit
367    fi
368    convert -trim 2Dshad_obs-sim_comparison_time.png ${ofign}
369    echo "* "${ofign} >> ${ofilefigs}
370    echo python ${pyHOME}/drawing.py -o draw_2D_shad_contdisc_time -f "'"${cfiles}"'" -S "'"${cvalues}"'" >> ${ofilefigs}
371    echo " " >> ${ofilefigs}
372  fi
373}
374
375function multiple_time_series_plot(){
376# Function to plot multiple time-series
377#   sti: id of the surface station
378#   stn: name of the surface station to appear in plot ('!' for spaces)
379#   sfcv: name of variable to plot
380#   ofigdir: folder for the output of the figure
381#   timevals: values of the time-axis to use
382#   files: files to use
383#   labs: labels of the legend
384#   lcol: color of lines to use
385#   nsfc: minimum value to plot
386#   xsfc: maximum value to plot
387#   figheader: header of the figure's file name
388
389    valuesfig=$1
390    stid=`echo ${valuesfig} | tr '@' ' ' | awk '{print $1}'`
391    stn=`echo ${valuesfig} | tr '@' ' ' | awk '{print $2}'`
392    sfcv=`echo ${valuesfig} | tr '@' ' ' | awk '{print $3}'`
393    ofigdir=`echo ${valuesfig} | tr '@' ' ' | awk '{print $4}'`
394    timevals=`echo ${valuesfig} | tr '@' ' ' | awk '{print $5}'`
395    files=`echo ${valuesfig} | tr '@' ' ' | awk '{print $6}'`
396    labs=`echo ${valuesfig} | tr '@' ' ' | awk '{print $7}'`
397    lcol=`echo ${valuesfig} | tr '@' ' ' | awk '{print $8}'`
398    nsfc=`echo ${valuesfig} | tr '@' ' ' | awk '{print $9}'`
399    xsfc=`echo ${valuesfig} | tr '@' ' ' | awk '{print $10}'`
400    figheader=`echo ${valuesfig} | tr '@' ' ' | awk '{print $11}'`
401
402    timen=`echo ${timevals} | tr '|' ' ' | awk '{print $3}'`
403    fmtT=`echo ${timevals} | tr '|' ' ' | awk '{print $1"|"$2}'`
404
405    values='ststimes,time;y;'${timen}';auto;'${labs}';'${sfcv}';'${sfcv}
406    values=${values}'|evolution|at|'$(echo ${stn} | tr '!' '|')';'${nsfc}','${xsfc}';'
407    values=${values}'time|'${fmtT}';0|12;'
408    values=${values}${kfig}';-;'${lcol}';.;2.;2.;all;-1;True'
409
410    ofign=${ofigdir}'/'${figheader}'_'${sfcv}_${sti}'.'${kfig}
411    if ${gscratch}; then rm ${ofign} >& /dev/null; fi
412    if test ! -f ${ofign}; then
413      echo "    Time-Series comparison on : "${sti}" for "${sfcv}
414      python ${pyHOME}/drawing.py -o draw_lines_time -f ${files} -S ${values} -v ${sfcv}
415      if test $? -ne 0; then
416        echo ${errmsg}
417        echo "  python failed!!"
418        echo python ${pyHOME}/drawing.py -o draw_lines_time -f "'"${files}"'" -S "'"${values}"'" -v ${sfcv}
419        exit
420      fi
421      convert -trim lines_time.${kfig} ${ofign}
422      echo "* "${ofign} >> ${ofilefigs}
423      echo python ${pyHOME}/drawing.py -o draw_lines_time -f "'"${files}"'" -S "'"${values}"'" -v ${sfcv} >> ${ofilefigs}
424      echo " "${ofign} >> ${ofilefigs}
425    fi
426}
427
428function shad_contdisc_map_plot(){
429# Function to plot a map of a continuos and a discontinuos variable
430#   expl: label of the experiment
431#   expn: name of the experiment in the title of the plot
432#   sfcv: name of variable to plot
433#   ofigdir: folder for the output of the figure
434#   obsfiles: observtional file to use
435#   simfile: simulation file to use
436#   it: time-step from simulation
437#   oit: time-step from observations
438#   timeS: format of time to appear in the title
439#   timefS: format of time to be used for the file name
440#   nsfc: minimum value to plot
441#   xsfc: maximum value to plot
442#   mapv: map values
443#   mapcover: cover of the map
444#   figheader: header of the figure's file name
445
446    valuesfig=$1
447
448    expl=`echo ${valuesfig} | tr '#' ' ' | awk '{print $1}'`
449    expn=`echo ${valuesfig} | tr '#' ' ' | awk '{print $2}'`
450    sfcv=`echo ${valuesfig} | tr '#' ' ' | awk '{print $3}'`
451    ofigdir=`echo ${valuesfig} | tr '#' ' ' | awk '{print $4}'`
452    obsfile=`echo ${valuesfig} | tr '#' ' ' | awk '{print $5}'`
453    simfile=`echo ${valuesfig} | tr '#' ' ' | awk '{print $6}'`
454    it=`echo ${valuesfig} | tr '#' ' ' | awk '{print $7}'`
455    oit=`echo ${valuesfig} | tr '#' ' ' | awk '{print $8}'`
456    timeS=`echo ${valuesfig} | tr '#' ' ' | awk '{print $9}'`
457    timefS=`echo ${valuesfig} | tr '#' ' ' | awk '{print $10}'`
458    nsfc=`echo ${valuesfig} | tr '#' ' ' | awk '{print $11}'`
459    xsfc=`echo ${valuesfig} | tr '#' ' ' | awk '{print $12}'`
460    mapv=`echo ${valuesfig} | tr '#' ' ' | awk '{print $13}'`
461    mapcover=`echo ${valuesfig} | tr '#' ' ' | awk '{print $14}'`
462    figheader=`echo ${valuesfig} | tr '#' ' ' | awk '{print $15}'`
463
464    CFvarvals=`python $pyHOME/generic.py -o variables_values -S ${sfcv}`
465    cbar=`echo ${CFvarvals} | tr ':' ' ' | awk '{print $7}'`
466
467    cfiles=${simfile}';'${sfcv}';XLONG;XLAT;Time|'${it}',time|'${it}','
468    cfiles=${cfiles}'west_east|-1,south_north|-1@'${obsfile}';'${sfcv}
469    cfiles=${cfiles}';stslon;stslat;time|'${oit}',lon|-1,lat|-1'
470    cvalues=${sfcv}':west_east,south_north:auto:'${cbar}',auto,auto:'${nsfc}','
471    cvalues=${cvalues}${xsfc}':''auto:obs!,!'${expn}'!'${sfcv}'!on!'${timeS}'!UTC:'
472    cvalues=${cvalues}${kfig}':None:'${mapv}':'${mapcover}':yes'
473
474    ofign=${ofigdir}'/'${figheader}'_'${timefS}'_'${sfcv}'_'${expl}'.'${kfig}
475    if ${gscratch}; then rm ${ofign} >& /dev/null; fi
476    if test ! -f ${ofign}; then
477      echo "    Map comparison on : "$(echo ${timeS} | tr '!' ' ')" by "${expl}" for "${sfcv}
478      python ${pyHOME}/drawing.py -o draw_2D_shad_contdisc -f ${cfiles} -S ${cvalues}
479      if test $? -ne 0; then
480        echo ${errmsg}
481        echo "  python failed!!"
482        echo python ${pyHOME}/drawing.py -o draw_2D_shad_contdisc -f "'"${cfiles}"'" -S "'"${cvalues}"'"
483      fi
484      convert -trim 2Dshad_obs-sim_comparison.png ${ofign} 
485      echo "* "${ofign} >> ${ofilefigs}
486      echo python ${pyHOME}/drawing.py -o draw_2D_shad_contdisc -f "'"${cfiles}"'" -S "'"${cvalues}"'" >> ${ofilefigs}
487      echo " " >> ${ofilefigs}
488    fi
489}
490
491function multi_WindRose_plot(){
492# Function to plot a WindRose with data from multiple soundings
493#   sti: id of the sounding station
494#   stn: name of the sounding station to appear in plot ('!' for spaces)
495#   ofigdir: folder for the output of the figure
496#   files: files to use
497#   labs: labels of the legend
498#   lmark: marker of lines to use
499#   timeS: time of the plot as it should appear in the figure ('!' for spaces)
500#   timefS: time of the plot as it should appear in the figure's file
501#   figheader: header of the figure's file name
502
503    valuesfig=$1
504
505    stid=`echo ${valuesfig} | tr '%' ' ' | awk '{print $1}'`
506    stn=`echo ${valuesfig} | tr '%' ' ' | awk '{print $2}'`
507    ofigdir=`echo ${valuesfig} | tr '%' ' ' | awk '{print $3}'`
508    files=`echo ${valuesfig} | tr '%' ' ' | awk '{print $4}'`
509    labs=`echo ${valuesfig} | tr '%' ' ' | awk '{print $5}'`
510    lmark=`echo ${valuesfig} | tr '%' ' ' | awk '{print $6}'`
511    timeS=`echo ${valuesfig} | tr '%' ' ' | awk '{print $7}'`
512    timefS=`echo ${valuesfig} | tr '%' ' ' | awk '{print $8}'`
513    figheader=`echo ${valuesfig} | tr '%' ' ' | awk '{print $9}'`
514
515    Nfiles=`echo ${labs} | tr ',' ' ' | wc -w | awk '{print $1-1}'`
516    frqm='1'
517    iff=1
518    while test ${iff} -le ${Nfiles}; do frqm=${frqm}'@10'; iff=`expr ${iff} + 1`; done
519
520    values='linepoint;multicol;pres;-;'${lmark}';'${frqm}';spectral;auto:'${labs}':'
521    values=${values}'WindRose!obs!,!sim!comparison!at!'${stid}'!on!'${timeS}'!UTC:'
522    values=${values}${kfig}':auto:''True'
523
524    ofign=${ofigdir}'/'${figheader}'_'${stid}'_'${timefS}'.'${kfig}
525    if ${gscratch}; then rm ${ofign} >& /dev/null; fi
526    if test ! -f ${ofign}; then
527      echo "    WindRose comparison at: "${stid}" on "$(echo ${timeS} | tr '!' ' ')
528      python ${pyHOME}/drawing.py -o draw_multiWindRose -f ${files} -S ${values}
529      if test $? -ne 0; then
530        echo ${errmsg}
531        echo "  python failed!!"
532        echo python ${pyHOME}/drawing.py -o draw_multiWindRose -f "'"${files}"'"     \
533         -S "'"${values}"'"
534        exit
535      fi
536      convert -trim multi_WindRose.${kfig} ${ofign}
537      echo "* "${ofign} >> ${ofilefigs}
538      echo python ${pyHOME}/drawing.py -o draw_multiWindRose -f "'"${files}"'"       \
539        -S "'"${values}"'" >> ${ofilefigs}
540      echo " " >> ${ofilefigs}
541    fi
542}
543
544#######    #######
545## MAIN
546    #######
547
548mkdir -p ${odir}
549ofileins=${wdir}/allins_functions.inf
550ofilefigs=${wdir}/allins_figures.inf
551if ${fscratch}; then 
552  echo "*** Instruction from all functions _______" > ${ofileins}
553  echo " " >> ${ofileins}
554fi
555if ${gscratch}; then 
556  echo "*** Instruction from all figures _______" > ${ofilefigs}
557  echo " " >> ${ofilefigs}
558fi
559
560# Files in sounding folder (from UWyoming_netcdf.py)
561if test ! ${sndHf} = 'None'; then
562  sndfs=`ls -1 ${snddir}/${sndHf}* | tr '\n' ':'`
563  echo "Soundings files _______"
564  echo ${sndfs} | tr ':' '\n'
565  sndfiles=`echo ${sndfs} | tr ':' ' '`
566else
567  sndfiles='None'
568fi
569
570# Files in sounding folder (from UWyoming_netcdf.py)
571if test ! ${sfcHf} = 'None'; then
572  sfcfs=`ls -1 ${sfcdir}/${sfcHf}** | tr '\n' ':'`
573  echo "Surface files _______"
574  echo ${sfcfs} | tr ':' '\n'
575  sfcfiles=`echo ${sfcfs} | tr ':' ' '`
576else
577  sfcfiles='None'
578fi
579
580exps=`echo ${sims} | tr ':' ' '`
581simH=`echo ${simHMT} | tr ',' ' ' | awk '{print $1}'`
582simM=`echo ${simHMT} | tr ',' ' ' | awk '{print $2}'`
583simT=`echo ${simHMT} | tr ',' ' ' | awk '{print $3}'`
584
585###
586## Preparing stations data
587###
588
589# sounding data
590iost=1
591obstype='sounding'
592prn='snd'
593if test ! ${sndHf} = 'None'; then 
594  listfiles=${sndfiles}
595else
596  listfiles=' '
597fi
598wrfdiags=${wrfsnddiags}
599simdiagd=${simsnddiagd}
600for ostf in ${listfiles}; do
601  stid=`python $pyHOME/nc_var.py -o grattr -f ${ostf} -S Station_number`
602  ostlon=`ncdump -h ${ostf} | grep Station_longitude | awk '{print $3}'`
603  ostlat=`ncdump -h ${ostf} | grep Station_latitude | awk '{print $3}'`
604  ostheight=`ncdump -h ${ostf} | grep Station_elevation | awk '{print $3}'`
605
606  if test ${iost} -eq 1; then 
607    oststids=${stid}'@'${ostf}
608    echo ${prn}","${stid}","${ostlon}","${ostlat}","${ostheight} > ${wdir}/stations.inf
609  else 
610    oststids=${oststids}':'${stid}'@'${ostf}
611    echo ${prn}","${stid}","${ostlon}","${ostlat}","${ostheight} >> ${wdir}/stations.inf
612  fi
613
614  iost=`expr ${iost} + 1`
615done
616if test ! ${sndHf} = 'None'; then sndstids=${oststids}; fi
617
618# surface data at station
619iost=1
620obstype='surface'
621prn='sfc'
622if test ! ${sfcHf} = 'None'; then 
623  listfiles=${sndfiles}
624else
625  listfiles=' '
626fi
627wrfdiags=${wrfsfcdiags}
628simdiagd=${simsfcdiagd}
629for ostf in ${listfiles}; do
630  stid=`python $pyHOME/nc_var.py -o varout -f ${ostf} -S 'time:0' -v id | grep NC \
631    | awk '{printf("%d",$2)}'`
632  ostlon=`python $pyHOME/nc_var.py -o varout -f ${ostf} -S 'time:0' -v lon | grep NC \
633    | awk '{print $2}'`
634  ostlat=`python $pyHOME/nc_var.py -o varout -f ${ostf} -S 'time:0' -v lat | grep NC \
635    | awk '{print $2}'`
636  ostheight=`python $pyHOME/nc_var.py -o varout -f ${ostf} -S 'time:0' -v height |   \
637    grep NC | awk '{print $2}'`
638
639  if test ! ${wdir}/stations.inf; then 
640    oststids=${stid}'@'${ostf}
641    echo ${prn}","${stid}","${ostlon}","${ostlat}","${ostheight} > ${wdir}/stations.inf
642  else 
643    oststids=${oststids}':'${stid}'@'${ostf}
644    echo ${prn}","${stid}","${ostlon}","${ostlat}","${ostheight} >> ${wdir}/stations.inf
645  fi
646
647  iost=`expr ${iost} + 1`
648done
649if test ! ${sfcHf} = 'None'; then sfcstids=${oststids}; fi
650
651###
652##
653# Figures
654##
655###
656
657mkdir -p ${ofigdir}
658
659##
660# Stations maps
661##
662ofig=${ofigdir}/stations.png
663if ${gscratch}; then rm ${ofig} >& /dev/null; fi
664if test ! -f ${ofig}; then
665  fivals=${mapstchar}':'${mapv}':lonlatxtrms:'${figexperimentname}'!stations:'
666  fivals=${fivals}${kfig}':true'
667  python ${pyHOME}/drawing.py -o draw_stations_map -f ${wdir}/stations.inf           \
668    -S ${fivals}
669  if test $? -ne 0; then
670    echo ${errmsg}
671    echo "  python failed!!"
672    echo python ${pyHOME}/drawing.py -o draw_stations_map -f ${wdir}/stations.inf    \
673      -S "'"${fivals}"'"
674    exit
675  fi
676  echo " * Map of the stations: " >> ${ofilefigs}
677  echo python ${pyHOME}/drawing.py -o draw_stations_map -f ${wdir}/stations.inf      \
678    -S "'"${fivals}"'" >> ${ofilefigs}
679  echo " " >> ${ofilefigs}
680  convert -trim stations_map.${kfig} ${ofig}
681fi
682
683###
684## Soundings figures
685###
686
687isnd=1
688for sndf in ${sndfiles}; do
689  stid=`python $pyHOME/nc_var.py -o grattr -f ${sndf} -S Station_number`
690
691  # Getting wind components
692  ouavasndf=${odir}'/sounding_uava_'${stid}'.nc'
693  if ${fscratch}; then rm ${ouavasndf}; fi
694  if test ! -f ${ouavasndf}; then
695    python ${pyHOME}/diagnostics.py -f ${sndf} -d 'time@time,pres@pres'              \
696      -v 'uavaFROMobswswd|ws@wd'
697    if test $? -ne 0; then
698      echo ${errmsg}
699      echo "  python failed!!"
700      echo python ${pyHOME}/diagnostics.py -f ${sndf} -d 'time@time,pres@pres'       \
701        -v 'uavaFROMobswswd|ws@wd'
702      exit
703    fi
704    echo " * Getting ua,va winds from station "${stid}": " >> ${ofileins}
705    echo python ${pyHOME}/diagnostics.py -f ${sndf} -d "'"time@time,pres@pres"'"     \
706      -v "'"uavaFROMobswswd|ws@wd"'" >> ${ofileins}
707    echo " " >> ${ofileins}   
708    mv diagnostics.nc ${ouavasndf}
709  fi
710done
711
712sndids=`echo ${sndstids} | tr ':' ' '`
713
714for stidf in ${sndids}; do
715  stid=`echo ${stidf} | tr '@' ' ' | awk '{print $1}'`
716  sndorigfn=`echo ${stidf} | tr '@' ' ' | awk '{print $2}'`
717  echo ${stid}" ..."
718  it=0
719  tatda_evol_values=''
720  tatda_evol_files=''
721  sndtimes=''
722  snddates=''
723  sndFdates=''
724  snddimt=`python ${pyHOME}/nc_var.py -o itime -S CFtime -f ${sndorigfn} -v time | \
725     grep 'dimt:' | awk '{print $2-1}'`
726
727  # Time characteristics
728  tunits=`python ${pyHOME}/nc_var.py -o ivattrs -v time -f ${sndorigfn} | \
729    grep -v allvattrs | grep units | awk '{print $3}'`
730  Tu=`echo ${tunits} | tr '!' ' ' | awk '{print $1}'`
731  Dref0=`echo ${tunits} | tr '!' ' ' | awk '{print $3}'`
732  Dref=${Dref0:0:4}${Dref0:5:2}${Dref0:8:2}
733
734  # Getting values for evolution plot
735  col=`echo ${icolta} | tr ':' ' ' | awk '{print $1}'`
736  col2=`echo ${icolta} | tr ':' ' ' | awk '{print $2}'`
737  while test ${it} -le ${snddimt}; do
738    timev=`python $pyHOME/nc_var.py -o varout -S time:${it} -f ${sndorigfn} -v time | \
739      grep NC | awk '{printf ("%d", $2)}'`
740    timeS=`date +${figsndTfmt} -d"${Dref} ${timev} ${Tu}"`
741    timeS2=`date +%d"$^{"%H"}$" -d"${Dref} ${timev} ${Tu}"`
742    timeS3=`date +%Y"-"%b -d"${Dref} ${timev} ${Tu}"`
743    timeS4=`date +%Y -d"${Dref} ${timev} ${Tu}"`
744    echo "  "${it}" "${timev}" "${Dref}" '"${timev}"' "${Tu}" "$(echo ${timeS} | tr '!' ' ')
745    timefS=`date +%Y%m%d%H%M%S -d"${Dref} ${timev} ${Tu}"`
746
747    sndstn=`python $pyHOME/nc_var.py -o grattr -f ${sndorigfn} -S Station_name |     \
748      tr ' ' '!'`
749
750    fivals=${it}'#'${stid}'#'${sndstn}'#'${timeS}'#'${ofigdir}'#'${timefS}'#'
751    fivals=${fivals}${ouavasndf}'#WindRose_obs'
752    WindRose_plot ${fivals}
753
754    fivals=${it}'#'${stid}'#'${sndstn}'#'${timeS}'#'${ofigdir}'#'${timefS}'#'
755    fivals=${fivals}${sndorigfn}'#SkewT-logP_obs_ta-tda'
756    SkewT_logP_plot ${fivals}
757
758    colH=`num_hex ${col}`
759    colH2=`num_hex ${col2}`
760    if test ${it} -eq 0; then
761      sndtimes=${timev}
762      snddates=${timeS}
763      sndFdates=${timefS}
764      tatda_evol_files=${sndorigfn}':pres|-1,time|'${it}':ta,pres;'
765      tatda_evol_files=${tatda_evol_files}${sndorigfn}':pres|-1,time|'${it}':tda,pres'
766      tatda_evol_labs='ta_'${timeS2}',tda'
767      tatda_evol_cols='#'${colH}${colH2}${colH2}',#'${colH2}${colH2}${colH}
768    else
769      sndtimes=${sndtimes}','${timev}
770      snddates=${snddates}','${timeS}
771      sndFdates=${sndFdates}','${timefS}
772      tatda_evol_files=${tatda_evol_files}';'${sndorigfn}':pres|-1,time|'${it}':ta,pres'
773      tatda_evol_files=${tatda_evol_files}';'${sndorigfn}':pres|-1,time|'${it}':tda,pres'
774      if test $(expr ${it} % 2) -eq 0; then 
775        tatda_evol_labs=${tatda_evol_labs}','${timeS2}',None'
776      else 
777        tatda_evol_labs=${tatda_evol_labs}',None,None'
778      fi
779      tatda_evol_cols=${tatda_evol_cols}',#'${colH}${colH2}${colH2}',#'${colH2}${colH2}${colH}
780    fi
781    col=`expr ${col} - ${ddcol}`
782    col2=`expr ${col2} - ${ddcol}`
783
784    it=`expr ${it} + 1`
785  done
786
787  fivals=${stid}'@'${sndstn}'@'${tatda_evol_labs}'@'${tatda_evol_cols}'@'
788  fivals=${fivals}${tatda_evol_files}'@'${timeS3}'@'${ofigdir}'@SkewT-logP_obs_evol'
789  multi_soundings_plot ${fivals}
790
791# End of soundings
792done
793
794# snd-sims comparison
795
796for stidf in ${sndids}; do
797  stid=`echo ${stidf} | tr '@' ' ' | awk '{print $1}'`
798  sndorigfn=`echo ${stidf} | tr '@' ' ' | awk '{print $2}'`
799  echo "snd: "${stid}
800
801  sndlon=`ncdump -h ${sndorigfn} | grep Station_longitude | awk '{print $3}'`
802  sndlat=`ncdump -h ${sndorigfn} | grep Station_latitude | awk '{print $3}'`
803  sndts=`echo ${sndtimes} | tr ',' ' '`
804  sndstn=`python $pyHOME/nc_var.py -o grattr -f ${sndorigfn} -S Station_name |       \
805    tr ' ' '!'`
806
807  # Time characteristics
808  tunits=`python ${pyHOME}/nc_var.py -o ivattrs -v time -f ${sndorigfn} |            \
809    grep -v allvattrs | grep units | awk '{print $3}'`
810  Tu=`echo ${tunits} | tr '!' ' ' | awk '{print $1}'`
811  Dref0=`echo ${tunits} | tr '!' ' ' | awk '{print $3}'`
812  Dref=${Dref0:0:4}${Dref0:5:2}${Dref0:8:2}
813
814  obsdimt=`python ${pyHOME}/nc_var.py -o itime -S CFtime, -v time -f ${sndorigfn} |  \
815    grep dimt | awk '{print $2-1}'`
816
817  # Plotting
818  it=0
819  while test ${it} -le ${obsdimt}; do
820
821    otimev=`python $pyHOME/nc_var.py -o varout -S time:${it} -f ${sndorigfn} -v time |\
822      grep NC | awk '{printf ("%d", $2)}'`
823    dateS=`date +${figsndTfmt} -d"${Dref} ${otimev} ${Tu}"`
824    timeS2=`date +%d"$^{"%H"}$" -d"${Dref} ${otimev} ${Tu}"`
825    timeS3=`date +%Y"-"%b -d"${Dref} ${otimev} ${Tu}"`
826    timeS4=`date +%Y -d"${Dref} ${otimev} ${Tu}"`
827    datefS=`date +%Y%m%d%H%M%S -d"${Dref} ${otimev} ${Tu}"`
828
829    iexp=1
830    for exp in ${exps}; do
831      expf=`echo ${exp} | tr ',' ' ' | awk '{print $1}'`
832      expl=`echo ${exp} | tr ',' ' ' | awk '{print $2}'`
833      expn=`echo ${exp} | tr ',' ' ' | awk '{print $3}'`
834      expc=`echo ${exp} | tr ',' ' ' | awk '{print $4}'`
835      expm=`echo ${exp} | tr ',' ' ' | awk '{print $5}'`
836
837      #simjoinselvars=${odir}'/simout_vars_'${expl}'.nc'
838      #simdiagsf=${odir}'/simout_snddiags_'${expl}'.nc'
839      #simfiles=`ls -1 ${simdir}/${expf}/${simH}*${simM}*${simT}`
840      simjoinselvars=`ls -1 ${simdir}/${expf}/${simH}*${simM}*${simT} | head -n 1`
841      simdiagsf=${odir}'/simout_sndvars_'${stid}'_'${expl}'.nc'
842      simsndptf=${odir}'/simout_sndvars_'${stid}'_'${expl}'.nc'
843
844      gridsndv=`python ${pyHOME}/nc_var.py -o get_point -f ${simjoinselvars}         \
845        -S 'XLONG:XLAT:Time|0' -v ${sndlon}','${sndlat} | tr ' ' '!'`
846      xsnd=`echo ${gridsndv} | tr '!' ' ' | awk '{print $1}' | tr ',' ' ' |          \
847        awk '{print $1}'`
848      ysnd=`echo ${gridsndv} | tr '!' ' ' | awk '{print $1}' | tr ',' ' ' |          \
849        awk '{print $2}'`
850      dsnd=`echo ${gridsndv} | tr '!' ' ' | awk '{print $2}'`
851      if test ${it} -eq 0 && test ${iexp} -eq 1; then
852        echo "    Equivalent simulated sounding grid point: "${gridsnd}" distance: "\
853          ${dsnd}
854      fi
855
856      # Time information from simulation
857      simdimt=`python ${pyHOME}/nc_var.py -o itime -S CFtime, -v time                \
858        -f ${simdiagsf} | grep dimt | awk '{print $2}'`
859      simtunits=`python ${pyHOME}/nc_var.py -o ivattrs -v time -f ${simdiagsf} |     \
860        grep -v allvattrs | grep units | awk '{print $3}'`
861      simTu=`echo ${tunits} | tr '!' ' ' | awk '{print $1}'`
862      simDref0=`echo ${tunits} | tr '!' ' ' | awk '{print $3}'`
863      simDref=${simDref0:0:4}${simDref0:5:2}${simDref0:8:2}
864
865      # Time step from simulated file
866      timestepv=`python ${pyHOME}/nc_var.py -o get_time -f ${simsndptf}               \
867        -S ${otimev}';'${tunits} -v time | tr ' ' '@'`
868      timestep=`echo ${timestepv} | tr '@' ' ' | awk '{print $1}'`
869      timestepdiff=`echo ${timestepv} | tr '@' ' ' | awk '{print $2}'`
870      if test $? -ne 0; then
871        echo ${errmsg}
872        echo "  python failed!!"
873        echo python ${pyHOME}/nc_var.py -o get_time -f ${simsndptf}                  \
874          -S ${otimev}';'${tunits} -v time
875        exit
876      fi
877
878      if test ${iexp} -eq 1; then
879        echo "     "${it}": it="${timestep}" "$(echo ${dateS} | tr '!' ' ')" "${datefS}
880        tacomplabs='$ta^{obs}$,$ta^{'${expn}'}$'
881        tdacomplabs='$tda^{obs}$,$tda^{'${expn}'}$'
882        tacompcols='#FF6464,'${expc}
883        tdacompcols='#6464FF,'${expc}
884        tacompltyp='-,-'
885        tdacompltyp='-,-.'
886        tacompfiles=${sndorigfn}':pres|-1,time|'${it}':ta,pres;'
887        tacompfiles=${tacompfiles}${simsndptf}':bottom_top|-1,Time|'${timestep}':'
888        tacompfiles=${tacompfiles}'ta,pres'
889        tdacompfiles=${sndorigfn}':pres|-1,time|'${it}':tda,pres;'
890        tdacompfiles=${tdacompfiles}${simsndptf}':bottom_top|-1,Time|'${timestep}':'
891        tdacompfiles=${tdacompfiles}'tda,pres'
892
893        # multi Wind-Rose
894        # Getting pressure level from observations to plot
895        if test ${it} -eq 0; then
896          fstats=`python $pyHOME/nc_var.py -o field_stats -S full,1.e+20,None        \
897            -f ${simsndptf} -v pres | grep MAT | grep pres`
898          nsimpres=`echo ${fstats} | awk '{printf ("%d",$3)}'`
899        fi
900
901        obsuavaf=${odir}/sounding_uava_${stid}.nc
902        obspres=`python $pyHOME/nc_var.py -o varout -f ${obsuavaf} -S time:${it}     \
903          -v pres | awk '{print $2}' | tr '\n' ':'`
904        Lobspres1=`expr length ${obspres} | awk '{print $1-1}'`
905        vals=${obspres:0:${Lobspres1}}',threshold,:,'${nsimpres}
906        kobs=`python ${pyHOME}/generic.py -o inf_operSlist -S ${vals}`
907        if test $? -ne 0; then
908            echo ${errormsg}
909            echo "  python failed !!"
910            echo python ${pyHOME}/generic.py -o inf_operSlist -S ${vals}
911            exit
912        fi
913        vals=${obspres:0:${Lobspres1}}',getvalue,:,'${kobs}
914        onpres=`python ${pyHOME}/generic.py -o inf_operSlist -S ${vals}`
915        echo "      obs level of sim npres "${nsimpres}": "${kobs}" "${onpres}
916
917        mWRcomplabs='obs,'${expn}
918        mWRcompfiles=${odir}'/sounding_uava_'${stid}'.nc@pres|1,'${kobs}',1;time|'
919        mWRcompfiles=${mWRcompfiles}${it}'@ua,va#'${simsndptf}'@bottom_top|-1;Time|'
920        mWRcompfiles=${mWRcompfiles}${timestep}'@ua,va'
921        mWRmarks='.@'${expm}
922      else
923        tacomplabs=${tacomplabs}',$ta^{'${expn}'}$'
924        tdacomplabs=${tdacomplabs}',$tda^{'${expn}'}$'
925        tacompcols=${tacompcols}','${expc}
926        tdacompcols=${tdacompcols}','${expc}
927        tacompltyp=${tacompltyp}',-'
928        tdacompltyp=${tdacompltyp}',-.'
929        tacompfiles=${tacompfiles}';'${simsndptf}':bottom_top|-1,Time|'${timestep}':'
930        tacompfiles=${tacompfiles}'ta,pres'
931        tdacompfiles=${tdacompfiles}';'${simsndptf}':bottom_top|-1,Time|'${timestep}
932        tdacompfiles=${tdacompfiles}':tda,pres'
933        # multi Wind-Rose
934        mWRcomplabs=${mWRcomplabs}','${expn}
935        mWRcompfiles=${mWRcompfiles}'#'${simsndptf}'@bottom_top|-1;Time|'${timestep}
936        mWRcompfiles=${mWRcompfiles}'@ua,va'
937        mWRmarks=${mWRmarks}'@'${expm}
938      fi
939
940      if test ${it} -eq 0; then
941        # Hovmoeller maps
942        sndvs=`echo ${sndvars} | tr ':' ' '`
943        for sndv in ${sndvs}; do
944 
945          CFvarvals=`python $pyHOME/generic.py -o variables_values -S ${sndv}`
946          cbar=`echo ${CFvarvals} | tr ':' ' ' | awk '{print $7}'`
947
948          fivals=${stid}'#'${sndstn}'#'${sndv}'#'${ofigdir}'#'${datefS}'#'${fmtTts}
949          fivals=${fivals}'#'${simsndptf}'#'${sndorigfn}'#'${expl}'#'${expn}'#'${cbar}
950          fivals=${fivals}'#SkewT-logP_obs-sim_evol'
951
952          Hovmoeller_SkewT_map_plot ${fivals}
953
954        # end sounding vars
955        done
956      fi
957
958      iexp=`expr ${iexp} + 1`
959    # End experiments
960    done
961
962    complabs=${tacomplabs}','${tdacomplabs}
963    compcols=${tacompcols}','${tdacompcols}
964    compltyp=${tacompltyp}','${tdacompltyp}
965    compfiles=${tacompfiles}';'${tdacompfiles}
966
967    fivals=${stid}'@'${sndstn}'@'${complabs}'@'${compcols}'@'${compltyp}'@'
968    fivals=${fivals}${compfiles}'@'${dateS}'@'${ofigdir}'@'${datefS}'@'
969    fivals=${fivals}'SkewT-logP_obs-sim_step'
970    multi_SkewT_logP_plot ${fivals}
971
972    # Wind Rose comparison
973    fivals=${stid}'%'${sndstn}'%'${ofigdir}'%'${mWRcompfiles}'%'${mWRcomplabs}'%'
974    fivals=${fivals}${mWRmarks}'%'${dateS}'%'${datefS}'%WindRose_obs-sim_step'
975
976    multi_WindRose_plot ${fivals}
977
978    it=`expr ${it} + 1`
979  # End sounding time-steps
980  done
981
982# End of soundings stations
983done
984
985# Joining sounding 1D variables
986obssnd1Dfile=${odir}'/all_sounding_1D.nc'
987if test ! -f ${obssnd1Dfile}; then
988  python ${pyHOME}/nc_var.py -o join_sounding_obsfiles -S ${snddir}':UWyoming_snd'   \
989    -v all
990  if test $? -ne 0; then
991    echo ${errmsg}
992    echo "  python failed!!"
993    echo python ${pyHOME}/nc_var.py -o join_sounding_obsfiles                        \
994      -S ${snddir}':UWyoming_snd' -v all
995  fi
996  echo " * Joining all 1D variables from all sounding station files : " >> ${ofileins}
997  echo python ${pyHOME}/nc_var.py -o join_sounding_obsfiles                          \
998      -S ${snddir}':UWyoming_snd' -v all >> ${ofileins}   
999  echo " " >> ${ofileins}   
1000  mv joined_soundingstations.nc ${obssnd1Dfile}
1001fi
1002
1003exit
1004
1005###
1006## SFC figures
1007###
1008
1009# Joining all observations
1010obssfcfile=${odir}'/all_single-stations.nc'
1011if test ! -f ${obssfcfile}; then
1012  python ${pyHOME}/nc_var.py -o join_singlestation_obsfiles -S                       \
1013    ${sfcdir}':OBSnetcdf' -v all
1014  if test $? -ne 0; then
1015    echo ${errmsg}
1016    echo "  python failed!!"
1017    echo  python ${pyHOME}/nc_var.py -o join_singlestation_obsfiles \
1018      -S ${sfcdir}':OBSnetcdf' -v all
1019  fi
1020  echo " * Joining all surface station files : " >> ${ofileins}
1021  echo python ${pyHOME}/nc_var.py -o join_singlestation_obsfiles -S                  \
1022    ${sfcdir}':OBSnetcdf' -v all >> ${ofileins}   
1023  echo " " >> ${ofileins}   
1024  mv joined_singlestations.nc ${obssfcfile}
1025fi
1026
1027# getting min,max values
1028if test ${sfcvars} != 'None'; then
1029fcs=`echo ${sfcvars} | tr ':' ' '`
1030
1031iv=1
1032for sfcpv in ${sfcs}; do
1033  sfcv=`echo ${sfcpv} | tr '@' ' ' | awk '{print $1}'`
1034  nsfc=`echo ${sfcpv} | tr '@' ' ' | awk '{print $2}'`
1035  xsfc=`echo ${sfcpv} | tr '@' ' ' | awk '{print $3}'`
1036  if test ${nsfc} = 'FROMobs'; then
1037    fstats=`python $pyHOME/nc_var.py -o field_stats -S full,1.e+20,None              \
1038      -f ${obssfcfile} -v ${sfcv} | grep MAT | grep ${sfcv}`
1039    nsfc=`echo ${fstats} | awk '{print $3}'`
1040  elif test ${nsfc} = 'FROMsims'; then
1041    iexp=1
1042    for exp in ${exps}; do
1043      expl=`echo ${exp} | tr ',' ' ' | awk '{print $2}'`
1044      for stidf in ${sndids}; do
1045        stid=`echo ${stidf} | tr '@' ' ' | awk '{print $1}'`
1046        simsfcdiagf=${odir}'/simout_sfcvars_'${stdi}'_'${expl}'.nc'
1047        fstats=`python $pyHOME/nc_var.py -o field_stats -S full,1.e+20,None            \
1048          -f ${simsfcdiagf} -v ${sfcv} | grep MAT | grep ${sfcv}`
1049        if test ${iexp} -eq 1; then
1050          nsfc=`echo ${fstats} | awk '{print $3}'`
1051        else
1052          nsfc2=`echo ${fstats} | awk '{print $3}'`
1053          nsfcf=`echo ${nsfc}" "${nsfc2} | awk '{if ($1 < $2) {print $1;} else {print $2;}}'`
1054        fi
1055        iexp=`expr ${iexp} + 1`
1056      done
1057    done
1058  elif test ${nsfc} = 'FROMobssims'; then
1059    fstats=`python $pyHOME/nc_var.py -o field_stats -S full,1.e+20,None              \
1060      -f ${obssfcfile} -v ${sfcv} | grep MAT | grep ${sfcv}`
1061    nsfc=`echo ${fstats} | awk '{print $3}'`
1062    for exp in ${exps}; do
1063      expl=`echo ${exp} | tr ',' ' ' | awk '{print $2}'`
1064      for stidf in ${sndids}; do
1065        stid=`echo ${stidf} | tr '@' ' ' | awk '{print $1}'`
1066        simsfcdiagf=${odir}'/simout_sfcvars_'${stdi}'_'${expl}'.nc'   
1067        fstats=`python $pyHOME/nc_var.py -o field_stats -S full,1.e+20,None          \
1068          -f ${simsfcdiagf} -v ${sfcv} | grep MAT | grep ${sfcv}`
1069        nsfc2=`echo ${fstats} | awk '{print $3}'`
1070        nsfc=`echo ${nsfc}" "${nsfc2} | awk '{if ($1 < $2) {print $1;} else {print $2;}}'`
1071      done
1072    done
1073  fi
1074  if test ${xsfc} = 'FROMobs'; then
1075    fstats=`python $pyHOME/nc_var.py -o field_stats -S full,1.e+20,None              \
1076      -f ${obssfcfile} -v ${sfcv} | grep MAT | grep ${sfcv}`
1077    xsfc=`echo ${fstats} | awk '{print $4}'`
1078  elif test ${xsfc} = 'FROMsims'; then
1079    iexp=1
1080    for exp in ${exps}; do
1081      expl=`echo ${exp} | tr ',' ' ' | awk '{print $2}'`     
1082      for stidf in ${sndids}; do
1083        stid=`echo ${stidf} | tr '@' ' ' | awk '{print $1}'`
1084        simsfcdiagf=${odir}'/simout_sfcvars_'${stdi}'_'${expl}'.nc'
1085   
1086        fstats=`python $pyHOME/nc_var.py -o field_stats -S full,1.e+20,None            \
1087          -f ${simsfcdiagf} -v ${sfcv} | grep MAT | grep ${sfcv}`
1088        if test ${iexp} -eq 1; then
1089          xsfc=`echo ${fstats} | awk '{print $4}'`
1090        else
1091          xsfc2=`echo ${fstats} | awk '{print $4}'`
1092          xsfcf=`echo ${xsfc}" "${xsfc2} | awk '{if ($1 > $2) {print $1;} else {print $2;}}'`
1093        fi
1094        iexp=`expr ${iexp} + 1`
1095      done
1096    done
1097  elif test ${nsfc} = 'FROMobssims'; then
1098    fstats=`python $pyHOME/nc_var.py -o field_stats -S full,1.e+20,None              \
1099      -f ${obssfcfile} -v ${sfcv} | grep MAT | grep ${sfcv}`
1100    xsfc=`echo ${fstats} | awk '{print $4}'`
1101    iexp=1
1102    for exp in ${exps}; do
1103      expl=`echo ${exp} | tr ',' ' ' | awk '{print $2}'`
1104      for stidf in ${sndids}; do
1105        stid=`echo ${stidf} | tr '@' ' ' | awk '{print $1}'`
1106        simsfcdiagf=${odir}'/simout_sfcvars_'${stdi}'_'${expl}'.nc'
1107   
1108        fstats=`python $pyHOME/nc_var.py -o field_stats -S full,1.e+20,None            \
1109          -f ${simsfcdiagf} -v ${sfcv} | grep MAT | grep ${sfcv}`
1110        xsfc2=`echo ${fstats} | awk '{print $4}'`
1111        xsfcf=`echo ${xsfc}" "${xsfc2} | awk '{if ($1 > $2) {print $1;} else {print $2;}}'`
1112      done
1113    done
1114  fi
1115  if test $iv -eq 1; then
1116    newsfcvars=${sfcv}'@'${nsfc}'@'${xsfc}
1117  else
1118    newsfcvars=${newsfcvars}':'${sfcv}'@'${nsfc}'@'${xsfc}
1119  fi
1120  iv=`expr ${iv} + 1`
1121done
1122sfcs=`echo ${newsfcvars} | tr ':' ' '`
1123echo "new sfc variables: "${sfcs}
1124
1125# Time-series
1126
1127# stations
1128# FROM: https://stackoverflow.com/questions/2961635/using-awk-to-print-all-columns-from-the-nth-to-the-last
1129stsids=`python ${pyHOME}/nc_var.py -o varout -v id -f \
1130  ${obssfcfile} -S 'Nstations:-1|time:0' | awk '{$1=""; printf("%d:",substr($0,2))}'`
1131stsnames=`python ${pyHOME}/nc_var.py -o varout -v stsname -f \
1132  ${obssfcfile} -S Nstations:-1 | awk '{$1=""; print substr($0,2)}' | tr '\n' ':' | \
1133  tr ' ' '!'`
1134stslons=`python ${pyHOME}/nc_var.py -o varout -v stslon -f \
1135  ${obssfcfile} -S Nstations:-1 | awk '{$1=""; print substr($0,2)}' | tr '\n' ':'`
1136stslats=`python ${pyHOME}/nc_var.py -o varout -v stslat -f \
1137  ${obssfcfile} -S Nstations:-1 | awk '{$1=""; print substr($0,2)}' | tr '\n' ':'`
1138
1139Nsts=`echo ${stsnames} | tr ':' ' ' | wc -w | awk '{print $1}'`
1140ist=1
1141while test ${ist} -le ${Nsts}; do
1142  sti=`echo ${stsids} | tr ':' '\n' | head -n ${ist} | tail -n 1`
1143  stn=`echo ${stsnames} | tr ':' '\n' | head -n ${ist} | tail -n 1`
1144  stl=`echo ${stslons} | tr ':' '\n' | head -n ${ist} | tail -n 1`
1145  stL=`echo ${stslats} | tr ':' '\n' | head -n ${ist} | tail -n 1`
1146  ist_1=`expr ${ist} - 1`
1147
1148  sfccompfiles=${obssfcfile}'%time|-1;Nstations|'${ist_1}
1149  sfccomplabs='obs'
1150  sfccompcols='#000000'
1151
1152  iexp=1
1153  for exp in ${exps}; do
1154    expl=`echo ${exp} | tr ',' ' ' | awk '{print $2}'`
1155    expn=`echo ${exp} | tr ',' ' ' | awk '{print $3}'`
1156    expc=`echo ${exp} | tr ',' ' ' | awk '{print $4}'`
1157    expm=`echo ${exp} | tr ',' ' ' | awk '{print $5}'`
1158
1159    simsfcdiagf=${odir}'/simout_sfcvars_'${stdi}'_'${expl}'.nc'
1160
1161    sfcstats=${sti}'@'${stn}'@'${stl}'@'${stL}'@'${gridsfc}
1162
1163    sfccompfiles=${sfccompfiles}','${simsfcdiagf}'%time|-1'
1164    sfccomplabs=${sfccomplabs}','${expn}
1165    sfccompcols=${sfccompcols}','${expc}
1166  done
1167  # end experiments
1168
1169  for sfcpv in ${sfcs}; do
1170    sfcv=`echo ${sfcpv} | tr '@' ' ' | awk '{print $1}'`
1171    nsfc=`echo ${sfcpv} | tr '@' ' ' | awk '{print $2}'`
1172    xsfc=`echo ${sfcpv} | tr '@' ' ' | awk '{print $3}'`
1173
1174    fivals=${sti}'@'${stn}'@'${sfcv}'@'${ofigdir}'@'${fmtTts}'@'${sfccompfiles}'@'
1175    fivals=${fivals}${sfccomplabs}'@'${sfccompcols}'@'${nsfc}'@'${xsfc}
1176    fivals=${fivals}'@obs-sim_evol_ts'
1177
1178    multiple_time_series_plot ${fivals}
1179    exit
1180
1181  done
1182  # end observations
1183
1184  ist=`expr $ist + 1`
1185done
1186# end sfc statinos
1187
1188# Cont-disc comparison
1189iexp=1
1190for exp in ${exps}; do
1191  expl=`echo ${exp} | tr ',' ' ' | awk '{print $2}'`
1192  expn=`echo ${exp} | tr ',' ' ' | awk '{print $3}'`
1193  expc=`echo ${exp} | tr ',' ' ' | awk '{print $4}'`
1194  expm=`echo ${exp} | tr ',' ' ' | awk '{print $5}'`
1195
1196  simsfcdiagf=${odir}'/simout_sfcmapdiags_'${expl}'.nc'
1197
1198  # Time information from simulation
1199  simdimt=`python ${pyHOME}/nc_var.py -o itime -S CFtime, -v time -f ${simsfcdiagf}  \
1200    | grep dimt | awk '{print $2-1}'`
1201  simtunits=`python ${pyHOME}/nc_var.py -o ivattrs -v time -f ${simsfcdiagf} |       \
1202    grep -v allvattrs | grep units | awk '{print $3}'`
1203  simTu=`echo ${tunits} | tr '!' ' ' | awk '{print $1}'`
1204  simDref0=`echo ${tunits} | tr '!' ' ' | awk '{print $3}'`
1205  simDref=${simDref0:0:4}${simDref0:5:2}${simDref0:8:2}
1206
1207  it=0
1208  while test ${it} -le ${simdimt}; do
1209    simtstep=`python ${pyHOME}/nc_var.py -o varout -f ${simsfcdiagf} -S              \
1210      'time:'${it} -v time | grep NC | awk '{printf ("%d",$2)}'`
1211    if test $? -ne 0; then
1212      echo ${errmsg}
1213      echo "  python failed!!"
1214      echo python ${pyHOME}/nc_var.py -o varout -f ${simsfcdiagf} -S 'time:'${it} -v time
1215      exit
1216    fi
1217
1218    timeS=`date +${figsndTfmt} -d"${simDref} ${simtstep} ${simTu}"`
1219    echo ${it}" "${simtstep}" "${simDref}" "${simTu}" "$(echo ${timeS} | tr '!' ' ')
1220    timefS=`date +%Y%m%d%H%M%S -d"${simDref} ${simtstep} ${simTu}"`
1221
1222    # Looking for obs time
1223    oitv=`python ${pyHOME}/nc_var.py -o get_time -f ${obssfcfile}                    \
1224      -S ${simtstep}';'${tunits} -v ststimes | grep -v differ | tr ' ' '@'`
1225    oit=`echo ${oitv} | tr '@' ' ' | awk '{print $1}'`
1226
1227    for sfcnxv in ${sfcs}; do
1228      sfcv=`echo ${sfcnxv} | tr '@' ' ' | awk '{print $1}'`
1229      nsfc=`echo ${sfcnxv} | tr '@' ' ' | awk '{print $2}'`
1230      xsfc=`echo ${sfcnxv} | tr '@' ' ' | awk '{print $3}'`
1231
1232      fivals=${expl}'#'${expn}'#'${sfcv}'#'${ofigdir}'#'${obssfcfile}'#'${simsfcdiagf}
1233      fivals=${fivals}'#'${it}'#'${oit}'#'${timeS}'#'${timefS}'#'${nsfc}'#'${xsfc}'#'
1234      fivals=${fivals}${mapv}'#'${mapcover}'#map_obs-sim'
1235
1236      shad_contdisc_map_plot ${fivals}
1237
1238    # end of variables
1239    done
1240
1241  it=`expr ${it} + 1`
1242  # end of time-steps
1243  done
1244
1245# end of simulations
1246done
1247fi
1248
1249fi
Note: See TracBrowser for help on using the repository browser.