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

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

Adding right concatenation variable

  • Property svn:executable set to *
File size: 12.3 KB
Line 
1#!/bin/bash
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    value=`echo ${line} | tr '=' ' ' | awk '{print $2}'`
44    Lvarname=`expr length ${varname}'0'`
45
46    if test ${Lvarname} -gt 1 && test ! ${varname:0:1} = '#'; then
47      export ${varname}=${value}
48    fi
49    ilin=`expr ${ilin} + 1`
50  done 
51}
52
53#######    #######
54## MAIN
55    #######
56uploadvars ${configfname}
57echo "END upload -- end UPLOAD -- END upload -- end UPLOAD"
58
59errmsg='ERROR -- error -- ERROR -- error'
60
61# from scratch
62if test ${scratch} = 'true'; then scratch=true
63else scratch=false; fi
64
65# Modules
66if test ! ${LOADmods} = 'None'; then
67  lmods=`echo ${LOADmods} | tr ':' ' '`
68  for lmod in ${lmods}; do
69    module load ${lmod}
70  done
71fi
72
73insoutf='allins_functions.inf'
74
75exps=`echo ${experiments} | tr ':' ' '`
76sndsts=`echo ${sndstations} | tr ':' ' '`
77sfcsts=`echo ${sfcstations} | tr ':' ' '`
78
79for expn in ${exps}; do
80  ifold=${infolder}/${expn}/wrfout
81  ofold=${ofolder}/${expn}
82
83  mkdir -p ${ofold}
84
85  if test ! ${sndstations} = 'None'; then
86  for sndvn in ${sndsts}; do
87    sndid=`echo ${sndvn} | tr ',' ' ' | awk '{print $1}'`
88    sndlon=`echo ${sndvn} | tr ',' ' ' | awk '{print $2}'`
89    sndlat=`echo ${sndvn} | tr ',' ' ' | awk '{print $3}'`
90
91    kout='snd'
92    filek='_vars_'${kout}'pt _'${kout}'diags'
93    # Sounding values
94    if test ! ${snddiags} = 'None'; then
95      fHEADn='simout'
96      files=`ls -1 ${infolder}/${expn}/wrfout/wrfout_d${domn}*`
97      ofile=${ofold}/${fHEADn}_${kout}diags_${sndid}_${expn}.nc
98      if test ${scratch} = 'true'; then rm ${ofile} >& /dev/null; fi
99      if test ! -f ${ofile}; then
100        for filen in ${files}; do
101          $pyHOME/get_WRFsounding-surface_data.bash ${scratch} ${ofold} ${expn}      \
102            ${sndvn} None ${filen} ${snddiags},None,None,None,None
103        # end of files
104        done
105
106        # Concatenating files
107        for fk in ${filek}; do
108          whichk=`expr ${fk} : ."diags"`
109          if test ${whichk} -eq 0; then values=${ofold}',Time,Times'
110          else values=${ofold}',Time,time'; fi
111
112          ofile=${ofold}/${fHEADn}${fk}_${sndid}_${expn}.nc
113          HMT=${fHEADn}${fk}'_,'${sndid}'_'${expn},'nc'
114          Nfiles=`ls -1 ${ofold}/${fHEADn}${fk}_*${sndid}_${expn}*.nc | wc -l`
115          if test ${Nfiles} -gt 1; then
116            python ${pyHOME}/nc_var.py -o netcdf_fold_concatenation_HMT -S ${values} \
117             -f ${HMT} -v all
118            if test $? -ne 0; then
119              echo ${errmsg}
120              echo "  python failed!!"
121              echo python ${pyHOME}/nc_var.py -o netcdf_fold_concatenation_HMT           \
122              -S ${values} -f ${HMT} -v all
123              exit
124            fi
125            echo " * Concatenating sounding data '"${fk}"' at point: "${sndid} >> ${insoutf}
126            echo python  ${pyHOME}/nc_var.py -o netcdf_fold_concatenation_HMT            \
127             -S "'"${values}"'" -f ${HMT} -v all >> ${insoutf}
128            echo " " >> ${insoutf}
129            mv netcdf_fold_concatenated_HMT.nc ${ofile}
130            rm ${ofold}/${fHEADn}${fk}_${sndid}_${expn}_????-??-??_??:??:??.nc >& /dev/null
131          else
132            file1=`ls -1 ${ofold}/${fHEADn}${fk}_*${sndid}_${expn}*.nc`
133            mv ${file1} ${ofile}
134          fi
135        done
136      fi
137     fi
138
139    # cordex values
140    if test ! ${cdxdiags} = 'None' || test ! ${cdxnondiags} = 'None'; then
141      fHEADn='simcdx'
142      files=`ls -1 ${infolder}/${expn}/wrfout/wrfcdx_d${domn}*`
143      ofile=${ofold}/${fHEADn}_${kout}diags_${sndid}_${expn}.nc
144      if test ${scratch} = 'true'; then rm ${ofile} >& /dev/null; fi
145      if test ! -f ${ofile}; then
146        for filen in ${files}; do
147          $pyHOME/get_WRFsounding-surface_data.bash ${scratch} ${ofold} ${expn}      \
148            ${sndvn} None ${filen} None,None,None,${cdxdiags},${cdxnondiags}
149        # end of files
150        done
151
152        # Concatenating files
153        for fk in ${filek}; do
154          whichk=`expr ${fk} : ."diags"`
155          if test ${whichk} -eq 0; then values=${ofold}',Time,Times'
156          else values=${ofold}',Time,time'; fi
157
158          ofile=${ofold}/${fHEADn}${fk}_${sndid}_${expn}.nc
159          HMT=${fHEADn}${fk}'_,'${sndid}'_'${expn},'nc'
160          Nfiles=`ls -1 ${ofold}/${fHEADn}${fk}_*${sndid}_${expn}*.nc | wc -l`
161          if test ${Nfiles} -gt 1; then
162            python ${pyHOME}/nc_var.py -o netcdf_fold_concatenation_HMT -S ${values}   \
163             -f ${HMT} -v all
164            if test $? -ne 0; then
165              echo ${errmsg}
166              echo "  python failed!!"
167              echo python ${pyHOME}/nc_var.py -o netcdf_fold_concatenation_HMT         \
168                -S ${values} -f ${HMT} -v all
169              exit
170            fi
171            echo " * Concatenating cdx sounding data at point: "${sndlon}", "${sndlat} >>\
172              ${insoutf}
173            echo python  ${pyHOME}/nc_var.py -o netcdf_fold_concatenation_HMT          \
174             -S "'"${values}"'" -f ${HMT} -v all >> ${insoutf}
175            echo " " >> ${insoutf}
176            mv netcdf_fold_concatenated_HMT.nc ${ofile}
177            rm ${ofold}/${fHEADn}${fk}_${sndid}_${expn}_????-??-??_??:??:??.nc >& /dev/null
178          else
179            file1=`ls -1 ${ofold}/${fHEADn}${fk}_*${sndid}_${expn}*.nc`
180            mv ${file1} ${ofile}
181          fi
182        done
183      fi
184     fi
185  # end of sounding stations
186  done
187  fi
188
189  # Surface stations
190  if test ! ${sfcstations} = 'None'; then
191  for sfcvn in ${sfcsts}; do
192    sfcid=`echo ${sfcvn} | tr ',' ' ' | awk '{print $1}'`
193    sfclon=`echo ${sfcvn} | tr ',' ' ' | awk '{print $2}'`
194    sfclat=`echo ${sfcvn} | tr ',' ' ' | awk '{print $3}'`
195
196    kout='sfc'
197    filek='_vars_'${kout}'pt _'${kout}'diags'
198    # out sfc pt
199    if test ! ${sfcdiags} = 'None' || test ! ${sfcnondiags} = 'None'; then
200      fHEADn='simout'
201      files=`ls -1 ${infolder}/${expn}/wrfout/wrfout_d${domn}*`
202      ofile=${ofold}/${fHEADn}_${kout}diags_${sfcid}_${expn}.nc
203      if test ${scratch} = 'true'; then rm ${ofile} >& /dev/null; fi
204      if test ! -f ${ofile}; then
205        for filen in ${files}; do
206          $pyHOME/get_WRFsounding-surface_data.bash ${scratch} ${ofold} ${expn} None \
207            ${sfcvn} ${filen} None,${sfcdiags},${sfcnondiags},None,None
208        # end of files
209        done
210
211        # Concatenating files
212        for fk in ${filek}; do
213          whichk=`expr ${fk} : ."diags"`
214          if test ${whichk} -eq 0; then values=${ofold}',Time,Times'
215          else values=${ofold}',Time,time'; fi
216
217          ofile=${ofold}/${fHEADn}${fk}_${sfcid}_${expn}.nc
218          HMT=${fHEADn}${fk}'_,'${sfcid}'_'${expn},'nc'
219          Nfiles=`ls -1 ${ofold}/${fHEADn}${fk}_*${sfcid}_${expn}*.nc | wc -l`
220          if test ${Nfiles} -gt 0; then
221            python ${pyHOME}/nc_var.py -o netcdf_fold_concatenation_HMT -S ${values}   \
222             -f ${HMT} -v all
223            if test $? -ne 0; then
224              echo ${errmsg}
225              echo "  python failed!!"
226              echo python ${pyHOME}/nc_var.py -o netcdf_fold_concatenation_HMT         \
227                -S ${values} -f ${HMT} -v all
228              exit
229            fi
230            echo " * Concatenating surface data '"${fk}"' at point: "${sfcid} >> ${insoutf}
231            echo python  ${pyHOME}/nc_var.py -o netcdf_fold_concatenation_HMT          \
232             -S "'"${values}"'" -f ${HMT} -v all >> ${insoutf}
233            echo " " >> ${insoutf}
234            mv netcdf_fold_concatenated_HMT.nc ${ofile}
235            rm ${ofold}/${fHEADn}${fk}_${sfcid}_${expn}_????-??-??_??:??:??.nc >& /dev/null
236          else
237            file1=`ls -1 ${ofold}/${fHEADn}${fk}_*${sfcid}_${expn}*.nc`
238            mv ${file1} ${ofile}
239          fi
240        done
241      fi
242    fi
243
244    # cdx sfc pt
245    if test ! ${cdxdiags} = 'None' || test ! ${cdxnondiags} = 'None'; then
246      fHEADn='simcdx'
247      files=`ls -1 ${infolder}/${expn}/wrfout/wrfcdx_d${domn}*`
248      ofile=${ofold}/${fHEADn}_${kout}diags_${sfcid}_${expn}.nc
249      if test ${scratch} = 'true'; then rm ${ofile} >& /dev/null; fi
250      if test ! -f ${ofile}; then
251        for filen in ${files}; do
252          $pyHOME/get_WRFsounding-surface_data.bash ${scratch} ${ofold} ${expn} None \
253            ${sfcvn} ${filen} None,None,None,${cdxdiags},${cdxnondiags}
254        # end of files
255        done
256
257        # Concatenating files
258        for fk in ${filek}; do
259          whichk=`expr ${fk} : ."diags"`
260          if test ${whichk} -eq 0; then values=${ofold}',Time,Times'
261          else values=${ofold}',Time,time'; fi
262
263          ofile=${ofold}/${fHEADn}${fk}_${sfcid}_${expn}.nc
264          HMT=${fHEADn}${fk}'_,'${sfcid}'_'${expn},'nc'
265          Nfiles=`ls -1 ${ofold}/${fHEADn}${fk}_*${sfcid}_${expn}*.nc | wc -l`
266          if test ${Nfiles} -gt 0; then
267            python ${pyHOME}/nc_var.py -o netcdf_fold_concatenation_HMT -S ${values}   \
268             -f ${HMT} -v all
269            if test $? -ne 0; then
270              echo ${errmsg}
271              echo "  python failed!!"
272              echo python ${pyHOME}/nc_var.py -o netcdf_fold_concatenation_HMT         \
273                -S ${values} -f ${HMT} -v all
274              exit
275            fi
276            echo " * Concatenating cdx surface data at point: "${sfcid} >> ${insoutf}
277            echo python  ${pyHOME}/nc_var.py -o netcdf_fold_concatenation_HMT          \
278             -S "'"${values}"'" -f ${HMT} -v all >> ${insoutf}
279            echo " " >> ${insoutf}
280            mv netcdf_fold_concatenated_HMT.nc ${ofile}
281            rm ${ofold}/${fHEADn}${fk}_${sfcid}_${expn}_????-??-??_??:??:??.nc >& /dev/null
282          else
283            file1=`ls -1 ${ofold}/${fHEADn}${fk}_*${sfcid}_${expn}*.nc`
284            mv ${file1} ${ofile}
285          fi
286        done
287      fi
288      #exit
289    fi
290
291  # end of surfaces
292  done
293  fi
294
295  # 2D maps
296  kout='sfcmap'
297  filek='_vars_'${kout}' _'${kout}'diags'
298  okind='out cdx' 
299  for ik in ${okind}; do
300    fHEADn='sim'${ik}
301    for fk in ${filek}; do
302      whichk=`expr ${fk} : ."diags"`
303      if test ${whichk} -eq 0; then values=${ofold}',Time,Times'
304      else values=${ofold}',Time,time'; fi
305
306      ofile=${ofold}/${fHEADn}${fk}_${expn}.nc
307      if test ${scratch} = 'true'; then rm ${ofile} >& /dev/null; fi
308      if test ! -f ${ofile}; then
309        # Concatenating files
310        values=${ofold}',Time,time'
311        HMT=${fHEADn}${fk}'_,'${expn},'nc'
312        Nfiles=`ls -1 ${ofold}/${fHEADn}${fk}_*${expn}*.nc | wc -l`
313        if test ${Nfiles} -gt 0; then
314          python ${pyHOME}/nc_var.py -o netcdf_fold_concatenation_HMT -S ${values}     \
315           -f ${HMT} -v all
316          if test $? -ne 0; then
317            echo ${errmsg}
318            echo "  python failed!!"
319            echo python ${pyHOME}/nc_var.py -o netcdf_fold_concatenation_HMT           \
320              -S ${values} -f ${HMT} -v all
321            exit
322          fi
323          echo " * Concatenating '${ik}' surface map data: " >> ${insoutf}
324          echo python  ${pyHOME}/nc_var.py -o netcdf_fold_concatenation_HMT            \
325           -S "'"${values}"'" -f ${HMT} -v all >> ${insoutf}
326          echo " " >> ${insoutf}
327          mv netcdf_fold_concatenated_HMT.nc ${ofile}
328          rm ${ofold}/${fHEADn}${fk}_${expn}_????-??-??_??:??:??.nc >& /dev/null
329        else
330          file1=`ls -1 ${ofold}/${fHEADn}${fk}_*${expn}*.nc`
331          mv ${file1} ${ofile}
332        fi
333      fi
334    done
335  done
336
337# End of experiments
338done
339
340fi
Note: See TracBrowser for help on using the repository browser.