source: lmdz_wrf/trunk/tools/concatenate.bash @ 1401

Last change on this file since 1401 was 223, checked in by lfita, 10 years ago

Adding bash script to genreate analaysis concatenating multiple outputs

  • Property svn:executable set to *
File size: 12.6 KB
Line 
1#!/bin/bash
2## e.g. # concatenate.bash hydrostatic -1:14:2:25
3if test $1 = '-h'; then
4  echo "*******************************"
5  echo "*** Files WRF concatenation ***" 
6  echo "*******************************"
7  echo "concatenate.bash [fold](fodler to use) [point](as Time:z:y:x, -1 last value)"
8else
9function isin_list() {
10# Function to check whether a value is in a list
11  list=$1
12  value=$2
13 
14  is=`echo ${list} | tr ':' '\n' | awk '{print "@"$1"@"}' | grep '@'${value}'@' | wc -w`
15  if test ${is} -eq 1
16  then
17    true
18  else
19    false
20  fi
21}
22
23####### ###### ##### #### ### ## #
24  allvars='XLONG,XLAT,Times,LDQAJS,LDTAJS,LDQCON,LDTCON,LDUCON,LDVCON,LDQDYN,LDTDYN,LDUDYN,LDVDYN,LDQEVA,LDTEVA,LDQLSCST,LDTLSCST,LDQLSCTH,LDTLSCTH,LDQLSC,LDTLSC,LDQPHY,LDTPHY,LDQTHE,LDTTHE,LDQVDF,LDTVDF,LDUVDF,LDVVDF,LDQWAK,LDTWAK,QVAPOR,QCLOUD,LGEOP,LTEMP,LPRES,LVITU,LVITV,LVITW,LVPRECIP,LRHUM,LH2O,LPR_CON_I,LPR_CON_L,LIWCON,LPTCONV,LSNOW,LEVAP,LPRECIP,LPLUC,LPLUL,LRH2M,T2,U10,V10,LCLDL,LCLDM,LCLDH,PSFC'
25
26# Variables to be printed centered at zero
27  ZEROcenteredvars='LDQAJS:LDTAJS:LDQCON:LDTCON:LDUCON:LDVCON:LDQDYN:LDTDYN:LDUDYN:LDVDYN:LDQEVA:LDTEVA:LDQLSCST:LDTLSCST:LDQLSCTH:LDTLSCTH:LDQLSC:LDTLSC:LDQPHY:LDTPHY:LDQTHE:LDTTHE:LDQVDF:LDTVDF:LDUVDF:LDVVDF:LDQWAK:LDTWAK:LVITU:LVITV:LVITW:U10:V10'
28
29# Variables printed following min/max or quantiles
30  MINMAXvars='QVAPOR:QCLOUD:LGEOP:LTEMP:LPRES:LVPRECIP:LRHUM:LH2O:LPR_CON_I:LPR_CON_L:LIWCON:LPTCONV:LSNOW:LEVAP:LPRECIP:LPLUC:LPLUL:LRH2M:T2:LCLDL:LCLDM:LCLDH:PSFC'
31
32# 1D variables
33  OneDvars='LSNOW:LEVAP:LPRECIP:LPLUC:LPLUL:LRH2M:T2:U10:V10:LCLDL:LCLDM:LCLDH:PSFC'
34
35  NOdraw='XLONG:XLAT:Times:longitude:latitude:time:intTime:varDIMbottom_top'
36
37# File creation
38  file=0
39
40# Cutting file
41  cut=0
42
43# Drawing
44  draw=0
45
46# Graphic visualization
47  vis=0
48
49  hovzvarns='dqajs:dtajs:dqcon:dtcon:ducon:dvcon:dqdyn:dtdyn:dudyn:dvdyn:dqeva:dteva:dqlscst:dtlscst:dqlscth:dtlscth:dqlsc:dtlsc:dqphy:dtphy:dqthe:dtthe:dqvdf:dtvdf:duvdf:dvvdf:dqwak:dtwak:r:c:zg:ta:pres:ua:va:wap:prprof:hus:h2o:prci:prcl:ri:cpt'
50
51  dh2varns='dqajs:dtajs:dqcon:dtcon:ducon:dvcon:dqdyn:dtdyn:dudyn:dvdyn:dqeva:dteva:dqlscst:dtlscst:dqlscth:dtlscth:dqlsc:dtlsc:dqphy:dtphy:dqthe:dtthe:dqvdf:dtvdf:duvdf:dvvdf:dqwak:dtwak:r:c:zg:ta:pres:ua:va:wap:prprof:hus:h2o:prci:prcl:ri:cpt:prsn:evspsbl:pr:prc:prls:huss:tas:uas:vas:cll:clm:clh:ps'
52
53  tevolvarns='dqajs:dtajs:dqcon:dtcon:ducon:dvcon:dqdyn:dtdyn:dudyn:dvdyn:dqeva:dteva:dqlscst:dtlscst:dqlscth:dtlscth:dqlsc:dtlsc:dqphy:dtphy:dqthe:dtthe:dqvdf:dtvdf:duvdf:dvvdf:dqwak:dtwak:r:c:zg:ta:pres:ua:va:wap:prprof:hus:h2o:prci:prcl:ri:cpt:prsn:evspsbl:pr:prc:prls:huss:tas:uas:vas:cll:clm:clh:ps'
54
55# Tex
56  tex=1
57  Ncoldraw=5
58 
59  graphkinds='hor:Hovmoller:TimeSeries' 
60
61  kvalues='2dh:hovz:tevol'
62
63#######    #######
64## MAIN
65    #######
66  rootsh=`pwd`
67  PYhome=${HOME}/PY
68  main='concatenation.bash'
69  errormsg='ERROR -- error -- ERROR -- error'
70  infold=`pwd`
71  fold=$1
72  point=$2
73
74  ofold=${fold}
75
76  tval=`echo ${point} | tr ':' ' ' | awk '{print $1}'`
77  zval=`echo ${point} | tr ':' ' ' | awk '{print $2}'`
78  yval=`echo ${point} | tr ':' ' ' | awk '{print $3}'`
79  xval=`echo ${point} | tr ':' ' ' | awk '{print $4}'`
80
81  kvals=`echo ${kvalues} | tr ':' ' '`
82  graphks=`echo ${graphkinds} | tr ':' ' '`
83
84  if test ${file} -eq 1; then
85    python ${PYhome}/nc_var.py -o netcdf_fold_concatenation -f wrfout_d01 -S ${infold}/${fold},Time -v ${allvars}
86
87    if test $? -ne 0; then
88      echo ${errormsg}
89      echo "  "${main}"python has failed!!"
90      echo "    python ${PYhome}/nc_var.py -o netcdf_fold_concatenation -f wrfout_d01\
91      -S ${infold}/${fold},Time -v ${allvars}"
92      exit
93    fi
94    mv netcdf_fold_concatenated.nc ${infold}/${fold}/wrfout_d01_check.nc
95  fi
96
97  if test ${cut} -eq 1; then
98    infile=${infold}/${fold}/wrfout_d01_check.nc
99    for kvn in ${kvals}; do
100      echo "  kind of values: "${kvn}
101      case $kvn in
102        '2dh')
103          pyvls='Time,'${tval}','${tval}',1@bottom_top,'${zval}','${zval}',1'
104        ;;
105        'hovz')
106          pyvls='south_north,'${yval}','${yval}',1@west_east,'${xval}','${xval}',1'
107        ;;
108        'tevol')
109          pyvls='bottom_top,'${zval}','${zval}',1@south_north,'${yval}','${yval}
110          pyvls=${pyvls}',1@west_east,'${xval}','${xval}',1'
111        ;;
112      esac
113      ofile=`python ${PYhome}/nc_var.py -o DataSetSection_multidims -f ${infile}     \
114        -S ${pyvls} | grep succesfull | awk '{print $6}' | tr '"' ' '`
115      if test $? -ne 0; then
116        echo ${errmsg}
117        echo "  "${main}": python failed!"
118        echo "    python "${PYhome}/nc_var.py -o DataSetSection_multidims              \
119          -f ${infile} -S ${pyvls}
120        exit
121      fi
122      case $kvn in
123        '2dh')
124# Adding CF longitudes and latitudes
125          python ${PYhome}/nc_var.py -f ${ofile} -o WRF_CFlonlat_creation            \
126            -S longitude,latitude -v XLONG,XLAT
127        ;;
128        'tevol')
129# Adding CF time
130          python ${PYhome}/nc_var.py -f ${ofile} -o WRF_CFtime_creation              \
131            -S 19491201000000,hours -v time
132        ;;
133        'hovz')
134# Adding CF time
135          python ${PYhome}/nc_var.py -f ${ofile} -o WRF_CFtime_creation              \
136            -S 19491201000000,hours -v time
137# Adding variable dimension from 'bottom_top'
138          python ${PYhome}/nc_var.py -f ${ofile} -o dimVar_creation -S bottom_top
139        ;;
140      esac
141    done
142  fi
143
144  if test $draw -eq 1; then
145  echo "Drawing..."
146  mkdir -p ${ofold}/figs
147  infile=${fold}'/wrfout_d01_check'
148
149  for kvn in ${kvals}; do
150    case $kvn in
151      '2dh')
152        filetail='Time_B'${tval}'-E'${tval}'-I1_bottom_top_B'${zval}
153        filetail=${filetail}'-E'${zval}'-I1'
154        dh2varns=''
155      ;;
156      'hovz')
157        filetail='south_north_B'${yval}'-E'${yval}'-I1_west_east_B'${xval}
158        filetail=${filetail}'-E'${xval}'-I1'
159        hovzvarns=''
160      ;;
161      'tevol')
162        filetail='bottom_top_B'${zval}'-E'${zval}'-I1_south_north_B'${yval}'-E'
163        filetail=${filetail}${yval}'-I1_west_east_B'${xval}'-E'${xval}'-I1'
164        tevolvarns=''
165      ;;
166    esac
167    drwfile=${infile}_${filetail}.nc
168    var0s=`python ~/PY/nc_var.py -o ivars -f ${drwfile} | grep allvars | awk '{print $3}'`
169    vars=`echo ${var0s} | tr ':' ' '`
170    echo ${vars}
171    for var in ${vars}; do
172      if ! $(isin_list ${NOdraw} ${var}); then
173      echo "  var: "${var}
174      varvals=`python ${PYhome}/drawing.py -o variable_values -S ${var} | grep all_values`
175      if test $? -ne 0; then
176        echo "  "${main}": Variable '"${var}"' not defined !!!!"
177        exit
178      fi
179      stdn=`echo ${varvals} | tr ',' ' ' | awk '{print $3}'`
180      cbar=`echo ${varvals} | tr ',' ' ' | awk '{print $9}'`
181      min=`echo ${varvals} | tr ',' ' ' | awk '{print $5}'`
182      max=`echo ${varvals} | tr ',' ' ' | awk '{print $6}'`
183
184      if test ${kvn} = 'hovz' && ! $(isin_list ${OneDvars} ${var}); then
185# Shadded vertical Hovmoller diagrams
186##
187      hovzvarns=${hovzvarns}':'${stdn}
188# Let's make it easy
189      if $(isin_list ${ZEROcenteredvars} ${var}); then
190        min='Spercentile@1'
191        max='Spercentile@1'
192        cbar='seismic'
193      else
194        min='Saroundminmax@0.8'
195        max='Saroundminmax@0.8'
196      fi 
197
198      if test ${var} = 'LDQEVA'; then
199        cbar='Reds'
200      fi
201
202      echo "    min: "${min}" max: "${max}
203
204      values=${stdn}':Time|-1,bottom_top|-1:varDIMbottom_top:time:'${cbar}':'
205      values=${values}${min}','${max}':vertical|temporal|evolution|:pdf:'
206      values=${values}'transpose:time|hours!since!1949-12-01|exct,12,h|'
207      values=${values}'$%d^{%H}$|date!($[DD]^{[HH]}$)|x:True'
208
209      python ${PYhome}/drawing.py -o draw_2D_shad_time -f ${infile}_${filetail}.nc   \
210        -S ${values} -v ${var},time
211      if test $? -ne 0; then
212        echo ${errormsg}
213        echo "  "${main}": drawing.py fails!"
214        echo python ${PYhome}/drawing.py -o draw_2D_shad_time \
215          -f ${infile}_${filetail}.nc -S ${values} -v ${var},time
216        exit
217      else
218        mv 2Dfields_shadow_time.pdf ${ofold}/figs/${stdn}_Hovmoller.pdf
219        if test $vis -eq 1; then evince ${ofold}/figs/${stdn}_Hovmoller.pdf & fi
220      fi
221     
222      elif test ${kvn} = 'tevol'; then
223# Point evolution
224      tevolvarns=${tevolvarns}':'${stdn}
225
226      values=${stdn}':time|($[DD]^{[HH]}$):exct,12,h:$%d^{%H}$:time|evolution|at'
227      values=${values}'|(x='${xval}',y='${yval}',z='${zval}'):1:pdf'
228      python ${PYhome}/drawing.py -o draw_timeSeries -f ${infile}_${filetail}.nc     \
229        -S ${values} -v ${var},time
230      if test $? -ne 0; then
231        echo ${errormsg}
232        echo "  "${main}": drawing.py fails!"
233        echo python ${PYhome}/drawing.py -o draw_timeSeries \
234          -f ${infile}_${filetail}.nc -S ${values} -v ${var},time
235        exit
236      else
237        mv TimeSeries_${stdn}.pdf ${ofold}/figs/${stdn}_TimeSeries.pdf
238        if test $vis -eq 1; then evince ${ofold}/figs/${stdn}_TimeSeries.pdf & fi
239      fi
240
241      elif test ${kvn} = '2dh'; then
242# Horizontal plot
243      dh2varns=${dh2varns}':'${stdn}
244      mapv='None'
245
246      min=`echo ${varvals} | tr ',' ' ' | awk '{print $5}'`
247      max=`echo ${varvals} | tr ',' ' ' | awk '{print $6}'`
248
249      if $(isin_list ${ZEROcenteredvars} ${var}); then
250        min='Spercentile@1'
251        max='Spercentile@1'
252        cbar='seismic'
253      else
254        min='Saroundminmax@0.97'
255        max='Saroundminmax@0.97'
256      fi 
257
258      if test ${var} = 'LRH2M'; then
259        max='100.'
260      elif test ${var} = 'T2'; then
261        min='270'
262        max='300.'
263      fi
264
265      echo "    min: "${min}" max: "${max}
266
267      values=${stdn}':south_north|-1,west_east|-1:longitude:latitude:'${cbar}':'
268      values=${values}${min}','${max}':horizontal|section|at|(t='${tval}
269      values=${values}',z='${zval}'):pdf:None:'${mapv}':True'
270
271      python ${PYhome}/drawing.py -o draw_2D_shad -f ${infile}_${filetail}.nc        \
272        -S ${values} -v ${var}
273      if test $? -ne 0; then
274        echo ${errormsg}
275        echo "  "${main}": drawing.py fails!"
276        echo python ${PYhome}/drawing.py -o draw_2D_shad \
277          -f ${infile}_${filetail}.nc -S ${values} -v ${var}
278        exit
279      else
280        mv 2Dfields_shadow.pdf ${ofold}/figs/${stdn}_hor.pdf
281        if test $vis -eq 1; then evince ${ofold}/figs/${stdn}_hor.pdf & fi
282      fi
283
284#      exit
285      fi
286      fi
287    done
288  done
289  fi
290
291  if test ${tex} -eq 1; then
292# Tex generation
293    echo "  TeX file generation...."
294
295    otex='concatenate.tex'
296
297    icol=1
298    while test ${icol} -le ${Ncoldraw}; do
299      NcolS=${NcolS}'c'
300      icol=`expr ${icol} + 1`
301    done
302
303    colfrac=`echo "1 "${Ncoldraw} | awk '{print $1/$2}'`
304    maxlinegraph=`echo "2 "${Ncoldraw} | awk '{printf("%d",$2*sqrt($1))}'`
305    echo "%concatenate LaTeX output" > ${otex}
306
307    for graphk in ${graphks}; do
308      cat << EOF >> ${otex}
309
310\\begin{figure}
311\\begin{center}
312\\begin{tabular}{${NcolS}}
313EOF
314      echo "  graphk: "${graphk}
315
316      case ${graphk} in
317        'hor')
318          vardrwns=${dh2varns}
319          GraphName='Horizontal section at time='${tval}', zlev='${zval}
320        ;;
321        'TimeSeries')
322          vardrwns=${tevolvarns}
323          GraphName='Punctual temporal evolution at zlev='${zval}', ypt= '${yval}', xpt= '${xval}
324        ;;
325        'Hovmoller')
326          vardrwns=${hovzvarns}
327          GraphName='Hovmoeller vertical section evolution at ypt= '${yval}', xpt= '${xval}
328        ;;
329      esac
330      echo "    vardrwns: "${vardrwns}
331      vardns=`echo ${vardrwns} | tr ':' ' '`
332
333      Ngraph=1
334      Nline=1
335      Ngraphk=1
336      varsgraph=''
337      for graph in ${vardns}; do
338        varvals=`python ${PYhome}/drawing.py -o variable_values -S ${var} | grep all_values`
339        stdn=`echo ${varvals} | tr ',' ' ' | awk '{print $3}'`
340
341        graphn=${ofold}'/'figs'/'${graph}'_'${graphk}'.png'
342        echo "\includegraphics[width="${colfrac}"\textwidth]{"${graphn}"}" >> ${otex}
343        modNgraph=`expr ${Ngraph} % ${Ncoldraw}`
344        if test ${modNgraph} -eq 0; then
345          echo "\\\\" >> ${otex}
346          Nline=`expr ${Nline} + 1`
347          if test ${Nline} -gt ${maxlinegraph}; then
348            Nline=1
349            varsgraph=${varsgraph}', '${graph}
350            cat << EOF >> ${otex}
351\\end{tabular}
352\\end{center}
353\\caption{${GraphName} graphics from top left to bottom right of ${varsgraph}}
354\\label{fig:${graphk}_${Ngraphk}}
355\\end{figure}
356\\clearpage
357
358\\begin{figure}
359\\begin{center}
360\\begin{tabular}{${NcolS}}
361EOF
362
363           Ngraphk=`expr ${Ngraphk} + 1`
364           varsgraph=''
365          fi
366        else
367          echo "&" >> ${otex}
368          varsgraph=${varsgraph}', '${graph}
369        fi
370        Ngraph=`expr ${Ngraph} + 1`
371      done
372      cat << EOF >> ${otex}
373\\end{tabular}
374\\end{center}
375\\caption{${GraphName} graphics from top left to bottom right of ${varsgraph}}
376\\label{fig:${graphk}_${Ngraphk}}
377\\end{figure}
378\\clearpage
379
380EOF
381
382    done
383  fi
384
385fi
Note: See TracBrowser for help on using the repository browser.