source: lmdz_wrf/trunk/tools/lmdz_check.bash @ 199

Last change on this file since 199 was 191, checked in by lfita, 11 years ago

Script to check LMDZ+WRF runs at a given grid point when it crashes

  • Property svn:executable set to *
File size: 17.5 KB
Line 
1#!/bin/bash
2## g.e. # lmdz_check.bash -1:6:3:26 wrfout_d01_1979-12-01_00:00:00 /home/lluis/PY /home/lluis/etudes/WRF_LMDZ/WaquaL/LaTeX/NPv31_hgardfou/figs 0 None 0
3if test $1 = '-h'; then
4  echo "**********************************"
5  echo "***   Shell script to analyze  ***"
6  echo "*** LMDZ runs at a given point ***"
7  echo "**********************************"
8  echo "lmdz_check.bash [point](as Time:z:y:x, -1 last value) [infile] [pyhome] \
9    (place with pthon scripts) [ofold](output folder) [getvals](0, no; 1: yes, \
10    whether to compute intermediary files) [mapv](None, no; map characteristics:[proj],[res])"
11  echo "  [point]: as Time:z:y:x, (-1 for last value, python style (0 based))"
12  echo "  [infile]: file to use"
13  echo "  [pyhome]: place with pthon scripts"
14  echo "  [ofold]: output folder"
15  echo "  [getvals]: 0, no; 1: yes, whether to compute intermediary files"
16  echo "  [mapv]: None, no; map characteristics:[proj],[res]"
17  echo "  [visualize]: 0, no; 1: yes, whether to visualize results"
18else
19  rootsh=`pwd`
20  errmsg='ERROR -- error -- ERROR -- error'
21  main='lmdz_check.bash'
22
23  point=$1
24  infile=$2
25  PYHOME=$3
26  ofold=$4
27  getvals=$5
28  mapv=$6
29  vis=$7
30
31# To paint figures
32  draw=1
33
34# To generate Hovmoller graph
35  dohov=1
36
37# To generate point graph
38  dopt=1
39
40# To generate horizontal graph
41  dohor=1
42
43# To generate neighbourghood evol graph
44  doneig=1
45
46# To generate LaTeX
47  dolatex=1
48
49  vartypes='dt:st:sfc'
50
51  dtvariables='AJS:CON:DYN:EVA:LSCST:LSCTH:LSC:PHY:THE:VDF:WAK'
52  stvariables='QVAPOR:QCLOUD:LGEOP:LTEMP:LVITU:LVITV:LVITW:LRHUM:LH2O'
53  sfcvariables='LSNOW:LEVAP:LPRECIP:LPLUC:LPLUL:LRH2M:T2:U10:V10:LCLDL:LCLDM:LCLDH:PSFC'
54
55  kvalues='2dh:hovz:tevol'
56
57  otex='lmdz_check.tex'
58####### ###### ##### #### ### ## #
59# Levels to interpolate
60  plevels='100000.,97500.,95000.,92500.,90000.,85000.,80000.,75000.,70000.,'
61  plevels=${plevels}'65000.,60000.,55000.,50000.,45000.,40000.,35000.,30000.,'
62  plevels=${plevels}'25000.,20000.,15000.,10000.,5000.,2500.,1000.,'
63  plevels=${plevels}'500.,250.'
64
65  tval=`echo ${point} | tr ':' ' ' | awk '{print $1}'`
66  zval=`echo ${point} | tr ':' ' ' | awk '{print $2}'`
67  yval=`echo ${point} | tr ':' ' ' | awk '{print $3}'`
68  xval=`echo ${point} | tr ':' ' ' | awk '{print $4}'`
69
70#######    #######
71## MAIN
72    #######
73
74  vtypes=`echo ${vartypes} | tr ':' ' '`
75  kvals=`echo ${kvalues} | tr ':' ' '`
76
77# All variables
78  allvars0=''
79
80  for vt in ${vtypes}; do
81    case $vt in
82      'dt' )
83        var0s=`echo ${dtvariables} | tr ':' ' '`
84        for var0 in $var0s; do
85          allvars0=${allvars0}'LDQ'${var0}',LDT'${var0}','
86        done
87      ;;
88      'sfc' )
89        var0s=`echo ${sfcvariables} | tr ':' ' '`
90        for var0 in $var0s; do
91          allvars0=${allvars0}${var0}','
92        done
93      ;;
94      'st' )
95        var0s=`echo ${stvariables} | tr ':' ' '`
96        for var0 in $var0s; do
97          allvars0=${allvars0}${var0}','
98        done
99      ;;
100    esac
101  done
102  Lallvars0=`expr length ${allvars0}`
103  Lallvars01=`expr ${Lallvars0} - 1`
104  allvars=${allvars0:0:${Lallvars01}}
105  echo "all vars: '"${allvars}"'"
106
107  if test ${getvals} -eq 1; then
108    for kvn in ${kvals}; do
109      echo "  kind of values: "${kvn}
110      case $kvn in
111        '2dh')
112          pyvls='Time,'${tval}','${tval}',1@bottom_top,'${zval}','${zval}',1'
113        ;;
114        'hovz')
115          pyvls='south_north,'${yval}','${yval}',1@west_east,'${xval}','${xval}',1'
116        ;;
117        'tevol')
118          pyvls='bottom_top,'${zval}','${zval}',1@south_north,'${yval}','${yval}
119          pyvls=${pyvls}',1@west_east,'${xval}','${xval}',1'
120        ;;
121      esac
122      ofile=`python ${PYHOME}/nc_var.py -o DataSetSection_multidims -f ${infile}     \
123        -S ${pyvls} | grep succesfull | awk '{print $6}' | tr '"' ' '`
124      if test $? -ne 0; then
125        echo ${errmsg}
126        echo "  "${main}": python failed!"
127        echo "    python "${HOME}/nc_var.py -o DataSetSection_multidims              \
128          -f ${infile} -S ${pyvls}
129        exit
130      fi
131      case $kvn in
132        '2dh')
133# Adding CF longitudes and latitudes
134          python ${PYHOME}/nc_var.py -f ${ofile} -o WRF_CFlonlat_creation            \
135            -S longitude,latitude -v XLONG,XLAT
136        ;;
137        'tevol')
138# Adding CF time
139          python ${PYHOME}/nc_var.py -f ${ofile} -o WRF_CFtime_creation              \
140            -S 19491201000000,hours -v time
141        ;;
142        'hovz')
143# Adding CF time
144          python ${PYHOME}/nc_var.py -f ${ofile} -o WRF_CFtime_creation              \
145            -S 19491201000000,hours -v time
146# Adding variable dimension from 'bottom_top'
147          python ${PYHOME}/nc_var.py -f ${ofile} -o dimVar_creation -S bottom_top
148# Vertical interpolation
149#          dvals='T:Time,Z:bottom_top,Y:south_north,X:west_east'
150#          python ${PYHOME}/vertical_interpolation.py -f ${ofile} -o WRFp             \
151#            -i ${plevels} -k 'lin' -v ${allvars} -d ${dvals}                         \
152#            -D T:Times,Z:ZNU,Y:XLAT,X:XLONG
153#          if test $? -ne 0; then
154#            echo ${errormsg}
155#            echo "  "${main}": drawing.py fails!"
156#            echo python ${PYHOME}/vertical_interpolation.py -f ${ofile} -o WRFp \
157#             -i ${plevels} -k 'lin' -v ${allvars} -d ${dvals} \
158#             -D T:Times,Z:ZNU,Y:XLAT,X:XLONG
159#            exit
160#          fi
161#          ofilen0=`echo ${ofile} | tr '.' ' ' | awk '{print $1}'`
162#          mv vertical_interpolation_WRFp.nc ${ofilen0}_WRFp.nc
163        ;;
164      esac
165    done
166  fi
167
168#exit
169  if test $draw -eq 1; then
170  echo "Drawing..."
171  for vt in ${vtypes}; do
172    echo "variable type: "${vt}
173    case $vt in
174      'dt' )
175        var0s=`echo ${dtvariables} | tr ':' ' '`
176        vars=''
177        for var0 in $var0s; do
178          vars=${vars}'LDQ'${var0}' LDT'${var0}' '
179        done
180      ;;
181      'sfc' )
182        vars=`echo ${sfcvariables} | tr ':' ' '`
183      ;;
184      'st' )
185        vars=`echo ${stvariables} | tr ':' ' '`
186      ;;
187    esac
188    for var in ${vars}; do
189      echo "  var:"${var}
190      varvals=`python ${PYHOME}/drawing.py -o variable_values -S ${var} | grep all_values`
191      if test $? -ne 0; then
192        echo "  "${main}": Variable '"${var}"' not defined !!!!"
193        exit
194      fi
195      stdn=`echo ${varvals} | tr ',' ' ' | awk '{print $3}'`
196      cbar=`echo ${varvals} | tr ',' ' ' | awk '{print $9}'`
197      min=`echo ${varvals} | tr ',' ' ' | awk '{print $5}'`
198      max=`echo ${varvals} | tr ',' ' ' | awk '{print $6}'`
199
200      if test $dohov -eq 1 && ! test ${vt} = 'sfc'; then
201# Shadded vertical Hovmoller diagrams
202      filetail='south_north_B'${yval}'-E'${yval}'-I1_west_east_B'${xval}
203      filetail=${filetail}'-E'${xval}'-I1'
204
205# Let's make it easy
206      if test ${vt} = 'st';then
207        min='Saroundminmax@0.97'
208        max='Saroundminmax@0.97'
209      else
210        min='Spercentile@1'
211        max='Spercentile@1'
212      fi
213
214      if test ${var} = 'LDQEVA' || test ${var} = 'LDTEVA' || test ${var} = 'LH2O';then
215        min='Saroundminmax@0.75'
216        max='Saroundminmax@0.75'
217        if test ${var} = 'LDQEVA'; then
218          cbar='Reds'
219        else
220          cbar='Blues'
221        fi
222      fi
223
224      echo "    min: "${min}" max: "${max}
225
226      values=${stdn}':Time|-1,bottom_top|-1:varDIMbottom_top:time:'${cbar}':'
227      values=${values}${min}','${max}':vertical|temporal|evolution|:pdf:'
228      values=${values}'transpose:time|hours!since!1949-12-01|exct,12,h|'
229      values=${values}'$%d^{%H}$|date!($[DD]^{[HH]}$)|x:True'
230
231      python ${PYHOME}/drawing.py -o draw_2D_shad_time -f ${infile}_${filetail}.nc   \
232        -S ${values} -v ${var},time
233      if test $? -ne 0; then
234        echo ${errormsg}
235        echo "  "${main}": drawing.py fails!"
236        echo python ${PYHOME}/drawing.py -o draw_2D_shad_time \
237          -f ${infile}_${filetail}.nc -S ${values} -v ${var},time
238        exit
239      else
240        mv 2Dfields_shadow_time.pdf ${ofold}/${stdn}_Hovmoller.pdf
241        if test $vis -eq 1; then evince ${ofold}/${stdn}_Hovmoller.pdf & fi
242      fi
243      fi
244     
245      if test $dopt -eq 1; then
246# Point evolution
247      filetail='bottom_top_B'${zval}'-E'${zval}'-I1_south_north_B'${yval}'-E'
248      filetail=${filetail}${yval}'-I1_west_east_B'${xval}'-E'${xval}'-I1'
249
250      values=${stdn}':time|($[DD]^{[HH]}$):exct,12,h:$%d^{%H}$:time|evolution|at'
251      values=${values}'|(x='${xval}',y='${yval}',z='${zval}'):1:pdf'
252      python ${PYHOME}/drawing.py -o draw_timeSeries -f ${infile}_${filetail}.nc     \
253        -S ${values} -v ${var},time
254      if test $? -ne 0; then
255        echo ${errormsg}
256        echo "  "${main}": drawing.py fails!"
257        echo python ${PYHOME}/drawing.py -o draw_timeSeries \
258          -f ${infile}_${filetail}.nc -S ${values} -v ${var},time
259        exit
260      else
261        mv TimeSeries_${stdn}.pdf ${ofold}/${stdn}_TimeSeries.pdf
262        if test $vis -eq 1; then evince ${ofold}/${stdn}_TimeSeries.pdf & fi
263      fi
264      fi
265
266      if test $dohor -eq 1; then
267# Horizontal plot
268      filetail='Time_B'${tval}'-E'${tval}'-I1_bottom_top_B'${zval}
269      filetail=${filetail}'-E'${zval}'-I1'
270
271      min=`echo ${varvals} | tr ',' ' ' | awk '{print $5}'`
272      max=`echo ${varvals} | tr ',' ' ' | awk '{print $6}'`
273
274      if test ${vt} = 'dt'; then
275        min='Spercentile@1'
276        max='Spercentile@1'
277      elif test ${vt} = 'st'; then
278        min='Saroundminmax@0.97'
279        max='Saroundminmax@0.97'
280      fi
281
282      if test ${var} = 'LRH2M'; then
283        max='100.'
284      elif test ${var} = 'T2'; then
285        min='270'
286        max='300.'
287      fi
288
289      echo "    min: "${min}" max: "${max}
290
291      values=${stdn}':south_north|-1,west_east|-1:longitude:latitude:'${cbar}':'
292      values=${values}${min}','${max}':horizontal|section|at|(t='${tval}
293      values=${values}',z='${zval}'):pdf:None:'${mapv}':True'
294
295      python ${PYHOME}/drawing.py -o draw_2D_shad -f ${infile}_${filetail}.nc        \
296        -S ${values} -v ${var}
297      if test $? -ne 0; then
298        echo ${errormsg}
299        echo "  "${main}": drawing.py fails!"
300        echo python ${PYHOME}/drawing.py -o draw_2D_shad \
301          -f ${infile}_${filetail}.nc -S ${values} -v ${var}
302        exit
303      else
304        mv 2Dfields_shadow.pdf ${ofold}/${stdn}_hor.pdf
305        if test $vis -eq 1; then evince ${ofold}/${stdn}_hor.pdf & fi
306      fi
307      fi
308
309      if test $doneig -eq 1; then
310# Neighbourghood plot
311      filetail=''
312
313      min=`echo ${varvals} | tr ',' ' ' | awk '{print $5}'`
314      max=`echo ${varvals} | tr ',' ' ' | awk '{print $6}'`
315
316      if test ${vt} = 'dt'; then
317        min='Spercentile@1'
318        max='Spercentile@1'
319      elif test ${vt} = 'st'; then
320        min='Saroundminmax@0.97'
321        max='Saroundminmax@0.97'
322      fi
323
324      if test ${var} = 'LRH2M'; then
325        max='100.'
326      elif test ${var} = 'T2'; then
327        min='270'
328        max='300.'
329      fi
330
331      echo "    min: "${min}" max: "${max}
332
333      values=${stdn}':Time|-1|Times,bottom_top|'${zval}'|ZNU,south_north|'${yval}
334      values=${values}'|XLAT,west_east|'${xval}'|XLONG:south_north,west_east:5:auto:'
335      values=${values}'time|($[DD]^{[HH]}$),time|($[DD]^{[HH]}$):exct,2,h|exct,1,d:'
336      values=${values}'$%d^{%H}$,$%d^{%H}$:5|pts|neighbourghood|temporal|evolution:'
337      values=${values}${min}','${max}':'${cbar}':pdf:False'
338
339      python ${PYHOME}/drawing.py -o draw_Neighbourghood_evol -f ${infile}           \
340        -S ${values} -v ${var}
341      if test $? -ne 0; then
342        echo ${errormsg}
343        echo "  "${main}": drawing.py fails!"
344        echo python ${PYHOME}/drawing.py -o draw_Neighbourghood_evol \
345          -f ${infile} -S ${values} -v ${var}
346        exit
347      else
348        mv Neighbourghood_evol.pdf ${ofold}/${stdn}_Neighbourghood_evol.pdf
349        if test $vis -eq 1; then evince ${ofold}/${stdn}_Neighbourghood_evol.pdf & fi
350      fi
351      fi
352
353#      exit
354    done
355  done
356  fi
357
358# LaTeX file generation
359##
360#
361  if test $dolatex -eq 1; then
362  echo "  LaTeX file '"${otex}"' generation..."
363  if test ${tval} -eq -1; then tvalS='last'; fi
364
365  cat << EOF > ${otex}
366\\documentclass{article}
367\\usepackage{graphicx}
368
369\\textwidth=18cm
370\\textheight=23cm
371\\oddsidemargin=-1cm
372\\evensidemargin=-1cm
373\\topmargin=-1cm
374
375\\begin{document}
376
377\\title{checking LMDZ at time=${tval}, z=${zval}, y=${yval}, x=${xval}}
378\\author{}
379
380\\maketitle
381EOF
382  for vt in ${vtypes}; do
383    echo "variable type: "${vt}
384    case $vt in
385      'dt' )
386        vars=`echo ${dtvariables} | tr ':' ' '`
387        ivar=1
388        for var in ${vars}; do
389          varvals=`python ${PYHOME}/drawing.py -o variable_values -S LDQ${var} \
390            | grep all_values`
391#          varn=`echo ${varvals} | tr ',' ' ' | awk '{print $3}'`
392          varn=`echo ${var} | tr '[:upper:]' '[:lower:]'`
393          ln=`echo ${varvals} | tr ',' ' ' | awk '{print $7}'`
394          echo "    var: "${varn}
395
396          cat << EOF >> ${otex}
397% d[q/t]_${varn}
398%%
399
400\\begin{figure}
401\\begin{center}
402\\begin{tabular}{cc}
403\\includegraphics[height=0.2\\textheight]{${ofold}/dq${varn}_hor}
404&
405\\includegraphics[height=0.2\\textheight]{${ofold}/dt${varn}_hor}
406\\\\
407\\includegraphics[height=0.2\\textheight]{${ofold}/dq${varn}_Hovmoller}
408&
409\\includegraphics[height=0.2\\textheight]{${ofold}/dt${varn}_Hovmoller}
410\\\\
411\\includegraphics[height=0.2\\textheight]{${ofold}/dq${varn}_TimeSeries}
412&
413\\includegraphics[height=0.2\\textheight]{${ofold}/dt${varn}_TimeSeries}
414\\\\
415\\includegraphics[height=0.2\\textheight]{${ofold}/dq${varn}_Neighbourghood_evol}
416&
417\\includegraphics[height=0.2\\textheight]{${ofold}/dt${varn}_Neighbourghood_evol}
418\\end{tabular}
419EOF
420          if test ${ivar} -eq 1; then
421            firstvar=${varn}
422            caption='\caption{Instantaneaous value at time='${tvalS}', z='${zval}
423            caption=${caption}' level of humidity tendency due to '${varn}' (top left)'
424            caption=${caption}', thermal tendency (top right), temporal evolution of '
425            caption=${caption}'the vertical profile at yval='${yval}', xval='${xval}
426            caption=${caption}'humidity tendency (2nd row left), thermal tendency '
427            caption=${caption}'(2nd row right), temporal evolution at the given point'
428            caption=${caption}' (3rd row), evolution of a box of 5x5 centered on the '
429            caption=${caption}'point (bottom)}'
430          else
431            caption='\caption{As in figure \ref{fig:d_qt_'${firstvar}'}, but for '
432            caption=${caption}${varn}'}'
433          fi
434          cat << EOF >> ${otex}
435${caption}
436\\label{fig:d_qt_${varn}}
437\\end{center}
438\\end{figure}
439EOF
440          ivar=`expr ${ivar} + 1`
441        done
442cat << EOF >> ${otex}
443\\clearpage
444EOF
445      ;;
446      'sfc' )
447        vars=`echo ${sfcvariables} | tr ':' ' '`
448        ivar=1
449        for var in ${vars}; do
450          varvals=`python ${PYHOME}/drawing.py -o variable_values -S ${var} \
451            | grep all_values`         
452          varn=`echo ${varvals} | tr ',' ' ' | awk '{print $3}'`
453          ln=`echo ${varvals} | tr ',' ' ' | awk '{print $7}'`
454          cat << EOF >> ${otex}
455% ${varn}
456%%
457
458\\begin{figure}
459\\begin{center}
460\\begin{tabular}{ccc}
461\\includegraphics[width=0.33\\textwidth]{${ofold}/${varn}_hor}
462&
463\\includegraphics[width=0.33\\textwidth]{${ofold}/${varn}_TimeSeries}
464&
465\\includegraphics[width=0.33\\textwidth]{${ofold}/${varn}_Neighbourghood_evol}
466\\end{tabular}
467EOF
468          if test ${ivar} -eq 1; then
469            firstvar=${varn}
470            caption='\caption{Instantaneaous value at time='${tvalS}' of '${varn}
471            caption=${caption}' (left), temporal evolution at the given point'
472            caption=${caption}' (middle), evolution of a box of 5x5 centered on the '
473            caption=${caption}'point (right)}'
474          else
475             caption='\caption{As in figure \ref{fig:state_'${firstvar}'}, but for '
476             caption=${caption}${varn}'}'
477          fi
478          cat << EOF >> ${otex}
479${caption}
480\\label{fig:state_${varn}}
481\\end{center}
482\\end{figure}
483EOF
484          ivar=`expr ${ivar} + 1`
485        done
486cat << EOF >> ${otex}
487\\clearpage
488EOF
489      ;;
490      'st' )
491        vars=`echo ${stvariables} | tr ':' ' '`
492        ivar=1
493        for var in ${vars}; do
494          varvals=`python ${PYHOME}/drawing.py -o variable_values -S ${var} \
495            | grep all_values`         
496          varn=`echo ${varvals} | tr ',' ' ' | awk '{print $3}'`
497          ln=`echo ${varvals} | tr ',' ' ' | awk '{print $7}'`
498          cat << EOF >> ${otex}
499% ${varn}
500%%
501
502\\begin{figure}
503\\begin{center}
504\\begin{tabular}{cc}
505\\includegraphics[width=0.5\\textwidth]{${ofold}/${varn}_hor}
506&
507\\includegraphics[width=0.5\\textwidth]{${ofold}/${varn}_Hovmoller}
508\\\\
509\\includegraphics[width=0.5\\textwidth]{${ofold}/${varn}_TimeSeries}
510&
511\\includegraphics[width=0.5\\textwidth]{${ofold}/${varn}_Neighbourghood_evol}
512\\end{tabular}
513EOF
514          if test ${ivar} -eq 1; then
515            firstvar=${varn}
516            caption='\caption{Instantaneaous value at time='${tvalS}', z='${zval}
517            caption=${caption}' level of '${varn}' (top left), temporal evolution of the'
518            caption=${caption}' vertical profile at yval='${yval}', xval='${xval}
519            caption=${caption}' (top right), temporal evolution at the given point '
520            caption=${caption}' (bottom left), evolution of a box of 5x5 centered on the '
521            caption=${caption}'point (bottom right)}'
522          else
523             caption='\caption{As in figure \ref{fig:state_'${firstvar}'}, but for '
524             caption=${caption}${varn}'}'
525          fi
526          cat << EOF >> ${otex}
527${caption}
528\\label{fig:state_${varn}}
529\\end{center}
530\\end{figure}
531EOF
532          ivar=`expr ${ivar} + 1`
533        done
534cat << EOF >> ${otex}
535\\clearpage
536EOF
537      ;;
538    esac
539  done
540  cat << EOF >> ${otex}
541\\end{document}
542EOF
543  otexn=`echo ${otex} | tr '.' ' ' | awk '{print $1}'`
544  pdflatex ${otexn}
545  pdflatex ${otexn}
546  evince ${otexn}.pdf &
547  fi
548fi
549
Note: See TracBrowser for help on using the repository browser.