source: lmdz_wrf/trunk/tools/get_data_snd-sfc_validation.bash @ 2828

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

Removing test!

  • Property svn:executable set to *
File size: 12.9 KB
Line 
1#!/bin/bash -x
2### Script to get sounding and surface points for validation purposes
3
4#   soundings: different lon,lat locations of soundings stations
5#   surface: different lon,lat locations of surface stations
6#   simulations: multiple outputs from different models and runs
7#   outputs: multiple different type of file outputs from model runs
8#
9
10# Name of the file with the configuration
11if test $1 = '-h'; then
12  echo "******************************************"
13  echo "***     Script to get WRF data at     ***"
14  echo "*** sounding and surface observations ***"
15  echo "***     from multiple simulations     ***"
16  echo "*****************************************"
17  echo "get_data_snd-sfc_validation [ConfFile](configuration file)"
18else
19  rootsh=`pwd`
20
21  configfname=$1
22
23####### ###### ##### #### ### ## #
24
25function uploadvars() {
26# Function to upload variables to the system from an ASCII file as:
27#   [varname] = [value]
28  fileval=$1
29  errormsg='ERROR -- error -- ERROR -- error'
30
31  if test ! -f ${fileval}; then
32    echo ${errormsg}
33    echo "  "${fname}": file '"${fileval}"' does not exist!!"
34    exit
35  fi
36
37  Nlin=`wc -l ${fileval} | awk '{print $1}'`
38
39  ilin=1
40  while test ${ilin} -le ${Nlin}; do
41    line=`head -n ${ilin} ${fileval} | tail -n 1`
42    varname=`echo ${line} | tr '=' ' ' | awk '{print $1}'`
43    Nwords=`echo ${line} | tr '=' ' ' | wc -w | awk '{print $1}'`
44    if test ${Nwords} -gt 2; then
45      value=`echo ${line} | tr '=' ' ' | awk '{for (i=2; i<=NF; i++) printf("%s!",$i)}'`
46    else
47      value=`echo ${line} | tr '=' ' ' | awk '{print $2}'`
48    fi
49    Lvarname=`expr length ${varname}'0'`
50
51    if test ${Lvarname} -gt 1 && test ! ${varname:0:1} = '#'; then
52      val=`echo ${value} | tr '!' ' '`
53      Lval=`expr length "${val}"`
54      Lval1=`expr ${Lval} - 1`
55      if test "${val:${Lval1}:2}" = ' '; then 
56        val=${val:0:${Lval1}}; fi
57      export ${varname}="${val}"
58    fi
59    ilin=`expr ${ilin} + 1`
60  done 
61}
62
63#######    #######
64## MAIN
65    #######
66uploadvars ${configfname}
67echo "END upload -- end UPLOAD -- END upload -- end UPLOAD"
68
69errmsg='ERROR -- error -- ERROR -- error'
70pyBINS=`echo ${pyBIN} | tr ' ' '!'`
71
72# from scratch
73if test ${scratch} = 'true'; then scratch=true
74else scratch=false; fi
75
76# Modules
77if test ! ${LOADmods} = 'None'; then
78  lmods=`echo ${LOADmods} | tr ':' ' '`
79  for lmod in ${lmods}; do
80    module load ${lmod}
81  done
82fi
83
84insoutf='allins_functions.inf'
85
86exps=`echo ${experiments} | tr ':' ' '`
87sndsts=`echo ${sndstations} | tr ':' ' '`
88sfcsts=`echo ${sfcstations} | tr ':' ' '`
89
90for expn in ${exps}; do
91  ifold=${infolder}/${expn}/wrfout
92  ofold=${ofolder}/${expn}
93
94  mkdir -p ${ofold}
95
96  if test ! ${sndstations} = 'None'; then
97  for sndvn in ${sndsts}; do
98    sndid=`echo ${sndvn} | tr ',' ' ' | awk '{print $1}'`
99    sndlon=`echo ${sndvn} | tr ',' ' ' | awk '{print $2}'`
100    sndlat=`echo ${sndvn} | tr ',' ' ' | awk '{print $3}'`
101
102    kout='snd'
103    filek='_vars_'${kout}'pt _'${kout}'diags'
104    # Sounding values
105    if test ! ${snddiags} = 'None'; then
106      fHEADn='simout'
107      files=`ls -1 ${infolder}/${expn}/wrfout/wrfout_d${domn}*`
108      ofile=${ofold}/${fHEADn}_${kout}diags_${sndid}_${expn}.nc
109      if test ${scratch} = 'true'; then rm ${ofile} >& /dev/null; fi
110      if test ! -f ${ofile}; then
111        for filen in ${files}; do
112          $pyHOME/get_WRFsounding-surface_data.bash ${scratch} ${ofold} ${expn}      \
113            ${sndvn} None ${filen} ${snddiags},None,None,None,None ${pyBINS}
114        # end of files
115        done
116
117        # Concatenating files
118        for fk in ${filek}; do
119          whichk=`expr ${fk} : ."diags"`
120          if ! grep -q diags <<< ${fk}; then values=${ofold}',Time,WRFtime'
121          else values=${ofold}',Time,time'; fi
122
123          ofile=${ofold}/${fHEADn}${fk}_${sndid}_${expn}.nc
124          HMT=${fHEADn}${fk}'_,'${sndid}'_'${expn},'nc'
125          Nfiles=`ls -1 ${ofold}/${fHEADn}${fk}_*${sndid}_${expn}_*.nc | wc -l`
126          if test ${Nfiles} -gt 1; then
127            ${pyBIN} ${pyHOME}/nc_var.py -o netcdf_fold_concatenation_HMT            \
128              -S ${values} -f ${HMT} -v all
129            if test $? -ne 0; then
130              echo ${errmsg}
131              echo "  python failed!!"
132              echo ${pyBIN} ${pyHOME}/nc_var.py -o netcdf_fold_concatenation_HMT     \
133              -S ${values} -f ${HMT} -v all
134              exit
135            fi
136            echo " * Concatenating sounding data '"${fk}"' at point: "${sndid} >>    \
137              ${insoutf}
138            echo ${pyBIN}  ${pyHOME}/nc_var.py -o netcdf_fold_concatenation_HMT      \
139             -S "'"${values}"'" -f ${HMT} -v all >> ${insoutf}
140            echo " " >> ${insoutf}
141            mv netcdf_fold_concatenated_HMT.nc ${ofile}
142          else
143            file1=`ls -1 ${ofold}/${fHEADn}${fk}_*${sndid}_${expn}*.nc`
144            mv ${file1} ${ofile}
145          fi
146        done
147        rm ${ofold}/${fHEADn}*${kout}*_${sndid}_${expn}_????-??-??_??:??:??.nc >& /dev/null
148      fi
149     fi
150
151    # cordex values
152    if test ! ${cdxdiags} = 'None' || test ! ${cdxnondiags} = 'None'; then
153      fHEADn='simcdx'
154      files=`ls -1 ${infolder}/${expn}/wrfout/wrfcdx_d${domn}*`
155      ofile=${ofold}/${fHEADn}_${kout}diags_${sndid}_${expn}.nc
156      if test ${scratch} = 'true'; then rm ${ofile} >& /dev/null; fi
157      if test ! -f ${ofile}; then
158        for filen in ${files}; do
159          $pyHOME/get_WRFsounding-surface_data.bash ${scratch} ${ofold} ${expn}      \
160            ${sndvn} None ${filen} None,None,None,${cdxdiags},${cdxnondiags} ${pyBINS}
161        # end of files
162        done
163
164        # Concatenating files
165        for fk in ${filek}; do
166          whichk=`expr ${fk} : ."diags"`
167          if ! grep -q diags <<< ${fk}; then values=${ofold}',Time,WRFtime'
168          else values=${ofold}',Time,time'; fi
169
170          ofile=${ofold}/${fHEADn}${fk}_${sndid}_${expn}.nc
171          HMT=${fHEADn}${fk}'_,'${sndid}'_'${expn},'nc'
172          Nfiles=`ls -1 ${ofold}/${fHEADn}${fk}_*${sndid}_${expn}_*.nc | wc -l`
173          if test ${Nfiles} -gt 1; then
174            ${pyBIN} ${pyHOME}/nc_var.py -o netcdf_fold_concatenation_HMT            \
175              -S ${values} -f ${HMT} -v all
176            if test $? -ne 0; then
177              echo ${errmsg}
178              echo "  python failed!!"
179              echo ${pyBIN} ${pyHOME}/nc_var.py -o netcdf_fold_concatenation_HMT     \
180                -S ${values} -f ${HMT} -v all
181              exit
182            fi
183            echo " * Concatenating cdx sounding data at point: "${sndlon}", "        \
184              ${sndlat} >> ${insoutf}
185            echo ${pyBIN}  ${pyHOME}/nc_var.py -o netcdf_fold_concatenation_HMT      \
186             -S "'"${values}"'" -f ${HMT} -v all >> ${insoutf}
187            echo " " >> ${insoutf}
188            mv netcdf_fold_concatenated_HMT.nc ${ofile}
189          else
190            file1=`ls -1 ${ofold}/${fHEADn}${fk}_*${sndid}_${expn}*.nc`
191            mv ${file1} ${ofile}
192          fi
193        done
194        rm ${ofold}/${fHEADn}*${kout}*_${sndid}_${expn}_????-??-??_??:??:??.nc >& /dev/null
195      fi
196     fi
197  # end of sounding stations
198  done
199  fi
200
201  # Surface stations
202  if test ! ${sfcstations} = 'None'; then
203  for sfcvn in ${sfcsts}; do
204    sfcid=`echo ${sfcvn} | tr ',' ' ' | awk '{print $1}'`
205    sfclon=`echo ${sfcvn} | tr ',' ' ' | awk '{print $2}'`
206    sfclat=`echo ${sfcvn} | tr ',' ' ' | awk '{print $3}'`
207
208    kout='sfc'
209    filek='_vars_'${kout}'pt _'${kout}'diags'
210    # out sfc pt
211    if test ! ${sfcdiags} = 'None' || test ! ${sfcnondiags} = 'None'; then
212      fHEADn='simout'
213      files=`ls -1 ${infolder}/${expn}/wrfout/wrfout_d${domn}*`
214      ofile=${ofold}/${fHEADn}_${kout}diags_${sfcid}_${expn}.nc
215      if test ${scratch} = 'true'; then rm ${ofile} >& /dev/null; fi
216      if test ! -f ${ofile}; then
217        for filen in ${files}; do
218          $pyHOME/get_WRFsounding-surface_data.bash ${scratch} ${ofold} ${expn} None \
219            ${sfcvn} ${filen} None,${sfcdiags},${sfcnondiags},None,None ${pyBINS}
220        # end of files
221        done
222
223        # Concatenating files
224        for fk in ${filek}; do
225          whichk=`expr ${fk} : ."diags"`
226          if ! grep -q diags <<< ${fk}; then values=${ofold}',Time,WRFtime'
227          else values=${ofold}',Time,time'; fi
228
229          ofile=${ofold}/${fHEADn}${fk}_${sfcid}_${expn}.nc
230          HMT=${fHEADn}${fk}'_,'${sfcid}'_'${expn},'nc'
231          Nfiles=`ls -1 ${ofold}/${fHEADn}${fk}_*${sfcid}_${expn}_*.nc | wc -l`
232          if test ${Nfiles} -gt 0; then
233            ${pyBIN} ${pyHOME}/nc_var.py -o netcdf_fold_concatenation_HMT            \
234              -S ${values} -f ${HMT} -v all
235            if test $? -ne 0; then
236              echo ${errmsg}
237              echo "  python failed!!"
238              echo ${pyBIN} ${pyHOME}/nc_var.py -o netcdf_fold_concatenation_HMT     \
239                -S ${values} -f ${HMT} -v all
240              exit
241            fi
242            echo " * Concatenating surface data '"${fk}"' at point: "${sfcid} >>     \
243              ${insoutf}
244            echo ${pyBIN}  ${pyHOME}/nc_var.py -o netcdf_fold_concatenation_HMT      \
245             -S "'"${values}"'" -f ${HMT} -v all >> ${insoutf}
246            echo " " >> ${insoutf}
247            mv netcdf_fold_concatenated_HMT.nc ${ofile}
248          else
249            file1=`ls -1 ${ofold}/${fHEADn}${fk}_*${sfcid}_${expn}*.nc`
250            mv ${file1} ${ofile}
251          fi
252        done
253        rm ${ofold}/${fHEADn}*${kout}*_${sfcid}_${expn}_????-??-??_??:??:??.nc >& /dev/null
254      fi
255    fi
256
257    # cdx sfc pt
258    if test ! ${cdxdiags} = 'None' || test ! ${cdxnondiags} = 'None'; then
259      fHEADn='simcdx'
260      files=`ls -1 ${infolder}/${expn}/wrfout/wrfcdx_d${domn}*`
261      ofile=${ofold}/${fHEADn}_${kout}diags_${sfcid}_${expn}.nc
262      if test ${scratch} = 'true'; then rm ${ofile} >& /dev/null; fi
263      if test ! -f ${ofile}; then
264        for filen in ${files}; do
265          $pyHOME/get_WRFsounding-surface_data.bash ${scratch} ${ofold} ${expn} None \
266            ${sfcvn} ${filen} None,None,None,${cdxdiags},${cdxnondiags} ${pyBINS}
267        # end of files
268        done
269
270        # Concatenating files
271        for fk in ${filek}; do
272          whichk=`expr ${fk} : ."diags"`
273          if ! grep -q diags <<< ${fk}; then values=${ofold}',Time,WRFtime'
274          else values=${ofold}',Time,time'; fi
275
276          ofile=${ofold}/${fHEADn}${fk}_${sfcid}_${expn}.nc
277          HMT=${fHEADn}${fk}'_,'${sfcid}'_'${expn},'nc'
278          Nfiles=`ls -1 ${ofold}/${fHEADn}${fk}_*${sfcid}_${expn}_*.nc | wc -l`
279          if test ${Nfiles} -gt 0; then
280            ${pyBIN} ${pyHOME}/nc_var.py -o netcdf_fold_concatenation_HMT            \
281              -S ${values} -f ${HMT} -v all
282            if test $? -ne 0; then
283              echo ${errmsg}
284              echo "  python failed!!"
285              echo ${pyBIN} ${pyHOME}/nc_var.py -o netcdf_fold_concatenation_HMT     \
286                -S ${values} -f ${HMT} -v all
287              exit
288            fi
289            echo " * Concatenating cdx surface data at point: "${sfcid} >> ${insoutf}
290            echo ${pyBIN}  ${pyHOME}/nc_var.py -o netcdf_fold_concatenation_HMT      \
291             -S "'"${values}"'" -f ${HMT} -v all >> ${insoutf}
292            echo " " >> ${insoutf}
293            mv netcdf_fold_concatenated_HMT.nc ${ofile}
294          else
295            file1=`ls -1 ${ofold}/${fHEADn}${fk}_*${sfcid}_${expn}*.nc`
296            mv ${file1} ${ofile}
297          fi
298        done
299        rm ${ofold}/${fHEADn}*${kout}*_${sfcid}_${expn}_????-??-??_??:??:??.nc >& /dev/null
300      fi
301      #exit
302    fi
303
304  # end of surfaces
305  done
306  fi
307
308  # 2D maps
309  kout='sfcmap'
310  filek='_vars_'${kout}' _'${kout}'diags'
311  okind='out cdx' 
312  for ik in ${okind}; do
313    fHEADn='sim'${ik}
314    for fk in ${filek}; do
315      whichk=`expr ${fk} : ."diags"`
316      if ! grep -q diags <<< ${fk}; then values=${ofold}',Time,WRFtime'
317      else values=${ofold}',Time,time'; fi
318
319      ofile=${ofold}/${fHEADn}${fk}_${expn}.nc
320      if test ${scratch} = 'true'; then rm ${ofile} >& /dev/null; fi
321      if test ! -f ${ofile}; then
322        # Concatenating files
323        values=${ofold}',Time,WRFtime'
324        HMT=${fHEADn}${fk}'_,'${expn},'nc'
325        Nfiles=`ls -1 ${ofold}/${fHEADn}${fk}_*${expn}_*.nc | wc -l`
326        if test ${Nfiles} -gt 0; then
327          ${pyBIN} ${pyHOME}/nc_var.py -o netcdf_fold_concatenation_HMT -S ${values} \
328           -f ${HMT} -v all
329          if test $? -ne 0; then
330            echo ${errmsg}
331            echo "  python failed!!"
332            echo ${pyBIN} ${pyHOME}/nc_var.py -o netcdf_fold_concatenation_HMT       \
333              -S ${values} -f ${HMT} -v all
334            exit
335          fi
336          echo " * Concatenating '${ik}' surface map data: " >> ${insoutf}
337          echo ${pyBIN}  ${pyHOME}/nc_var.py -o netcdf_fold_concatenation_HMT        \
338           -S "'"${values}"'" -f ${HMT} -v all >> ${insoutf}
339          echo " " >> ${insoutf}
340          mv netcdf_fold_concatenated_HMT.nc ${ofile}
341        else
342          file1=`ls -1 ${ofold}/${fHEADn}${fk}_*${expn}*.nc`
343          mv ${file1} ${ofile}
344        fi
345      fi
346    done
347    rm ${ofold}/${fHEADn}*${kout}*_${expn}_????-??-??_??:??:??.nc >& /dev/null
348  done
349
350# End of experiments
351done
352
353fi
Note: See TracBrowser for help on using the repository browser.