[2000] | 1 | #!/bin/bash |
---|
| 2 | #### Script to get data from a given specific sounding and surface stations from WRF |
---|
| 3 | ## |
---|
| 4 | ## e.g. # get_WRFsounding-surface_data.bash true ./ control 87576,-58.52,-34.81 87576,-58.52,-34.81 /home/lluis/PY/wrfout_d01_1995-01-01_00:00:00 WRFt:WRFtda:WRFp:WRFua:WRFva:ws:WRFwd wds:wss:WRFtdas T2 |
---|
| 5 | if test $1 = '-h'; then |
---|
| 6 | echo "************************************" |
---|
| 7 | echo "*** Script to get snd & sfc data ***" |
---|
| 8 | echo "*** from WRF output ***" |
---|
| 9 | echo "************************************" |
---|
| 10 | echo "get_WRFsounding-surface_data.bash [scratch] [odir] [expl] \ |
---|
| 11 | [sndid],[sndlon],[sndlat] [sfcid],[sfclon],[sfclat] [infilen] [wrfsnddiags] \ |
---|
| 12 | [wrfsfcdiags] [wrfsfcnodiags]" |
---|
| 13 | else |
---|
| 14 | |
---|
| 15 | if test $1 = 'true'; then fscratch=true |
---|
| 16 | else fscratch=false; fi |
---|
| 17 | |
---|
| 18 | odir=$2 |
---|
| 19 | expl=$3 |
---|
[2002] | 20 | if test ! $4 = 'None'; then |
---|
[2001] | 21 | sndid=`echo $4 | tr ',' ' ' | awk '{print $1}'` |
---|
| 22 | sndlon=`echo $4 | tr ',' ' ' | awk '{print $2}'` |
---|
| 23 | sndlat=`echo $4 | tr ',' ' ' | awk '{print $3}'` |
---|
| 24 | else |
---|
| 25 | sndid='None' |
---|
| 26 | fi |
---|
[2000] | 27 | |
---|
[2002] | 28 | if test ! $5 = 'None'; then |
---|
[2001] | 29 | sfcid=`echo $5 | tr ',' ' ' | awk '{print $1}'` |
---|
| 30 | sfclon=`echo $5 | tr ',' ' ' | awk '{print $2}'` |
---|
| 31 | sfclat=`echo $5 | tr ',' ' ' | awk '{print $3}'` |
---|
| 32 | else |
---|
| 33 | sfcid='None' |
---|
| 34 | fi |
---|
[2000] | 35 | |
---|
| 36 | infilen=$6 |
---|
| 37 | wrfsnddiags=$7 |
---|
| 38 | wrfsfcdiags=$8 |
---|
| 39 | wrfsfcnodiags=$9 |
---|
| 40 | |
---|
| 41 | function isin_list() { |
---|
| 42 | # Function to check whether a value is in a list |
---|
| 43 | list=$1 |
---|
| 44 | value=$2 |
---|
| 45 | |
---|
| 46 | is=`echo ${list} | tr ':' '\n' | awk '{print "@"$1"@"}' | grep '@'${value}'@' | wc -w` |
---|
| 47 | if test ${is} -eq 1 |
---|
| 48 | then |
---|
| 49 | true |
---|
| 50 | else |
---|
| 51 | false |
---|
| 52 | fi |
---|
| 53 | } |
---|
| 54 | |
---|
| 55 | function get_WRFsounding_data(){ |
---|
| 56 | # Function to get the data to compute analysis in a sounding point |
---|
| 57 | # stlon= longitude value of the station |
---|
| 58 | # stlat= latitude value of the station |
---|
| 59 | # filen= name of the file |
---|
| 60 | # lonvarn= name of the longitude variable |
---|
| 61 | # latvarn= name of the latitude variable |
---|
| 62 | # snddiagnames= diagnostics to compute (as ':' separated list) |
---|
| 63 | |
---|
| 64 | funcvals=$1 |
---|
| 65 | |
---|
| 66 | stlon=`echo ${funcvals} | tr '#' ' ' | awk '{print $1}'` |
---|
| 67 | stlat=`echo ${funcvals} | tr '#' ' ' | awk '{print $2}'` |
---|
| 68 | filen=`echo ${funcvals} | tr '#' ' ' | awk '{print $3}'` |
---|
| 69 | lonvarn=`echo ${funcvals} | tr '#' ' ' | awk '{print $4}'` |
---|
| 70 | latvarn=`echo ${funcvals} | tr '#' ' ' | awk '{print $5}'` |
---|
| 71 | snddiagnames=`echo ${funcvals} | tr '#' ' ' | awk '{print $6}'` |
---|
| 72 | |
---|
| 73 | vals=${lonvarn}':'${latvarn}':Time|0' |
---|
| 74 | gridsndv=`python ${pyHOME}/nc_var.py -o get_point -f ${filen} -S ${vals} \ |
---|
| 75 | -v ${stlon},${stlat} | tr ' ' '!'` |
---|
| 76 | echo "* get grid point: "${stlon}", "${stlat} >> ${ofileins} |
---|
| 77 | echo python ${pyHOME}/nc_var.py -o get_point -f ${filen} -S "'"${vals}"'" \ |
---|
| 78 | -v ${stlon},${stlat} >> ${ofileins} |
---|
| 79 | echo " " >> ${ofileins} |
---|
| 80 | |
---|
| 81 | xsnd=`echo ${gridsndv} | tr '!' ' ' | awk '{print $1}' | tr ',' ' ' | \ |
---|
| 82 | awk '{print $1}'` |
---|
| 83 | ysnd=`echo ${gridsndv} | tr '!' ' ' | awk '{print $1}' | tr ',' ' ' | \ |
---|
| 84 | awk '{print $2}'` |
---|
| 85 | dsnd=`echo ${gridsndv} | tr '!' ' ' | awk '{print $2}'` |
---|
| 86 | |
---|
| 87 | xsnd1=`expr ${xsnd} + 1` |
---|
| 88 | ysnd1=`expr ${ysnd} + 1` |
---|
| 89 | |
---|
| 90 | # Getting values |
---|
| 91 | if ${fscratch}; then rm ${simsndptf} >& /dev/null; fi |
---|
| 92 | if test ! -f ${simsndptf}; then |
---|
| 93 | values='Time,0,-1,1@bottom_top,0,-1,1@south_north,'${ysnd}','${ysnd}',1@' |
---|
| 94 | values=${values}'west_east,'${xsnd}','${xsnd}',1@south_north_stag,'${ysnd}',' |
---|
| 95 | values=${values}${ysnd1}',1@west_east_stag,'${xsnd}','${xsnd1}',1' |
---|
| 96 | python ${pyHOME}/nc_var.py -o DataSetSection_multidims -f ${filen} \ |
---|
| 97 | -S ${values} -v all |
---|
| 98 | if test $? -ne 0; then |
---|
| 99 | echo ${errmsg} |
---|
| 100 | echo " python failed!!" |
---|
| 101 | echo python ${pyHOME}/nc_var.py -o DataSetSection_multidims -f ${filen} \ |
---|
| 102 | -S "'"${values}"'" -v all |
---|
| 103 | exit |
---|
| 104 | fi |
---|
| 105 | echo "* get values at snd point: "${stlon}", "${stlat} >> ${ofileins} |
---|
| 106 | echo python ${pyHOME}/nc_var.py -o DataSetSection_multidims -f ${filen} \ |
---|
| 107 | -S "'"${values}"'" -v all >> ${ofileins} |
---|
| 108 | echo " " >> ${ofileins} |
---|
| 109 | |
---|
| 110 | yslc='south_north_B'${ysnd}'-E'${ysnd}'-I1' |
---|
| 111 | ystslc='south_north_stag_B'${ysnd}'-E'${ysnd1}'-I1' |
---|
| 112 | xslc='west_east_B'${xsnd}'-E'${xsnd}'-I1' |
---|
| 113 | xstslc='west_east_stag_B'${xsnd}'-E'${xsnd1}'-I1' |
---|
| 114 | |
---|
| 115 | ofilen=${filen}'_Time_B0-E-1-I1_bottom_top_B0-E-1-I1_'${yslc}'_'${xslc}'_' |
---|
| 116 | ofilen=${ofilen}${ystslc}'_'${xstslc}'.nc' |
---|
| 117 | mv ${ofilen} ${simsndptf} |
---|
| 118 | fi |
---|
| 119 | |
---|
| 120 | # Computing sounding diagnostics |
---|
| 121 | snddiagd='Time@WRFtime,bottom_top@P' |
---|
| 122 | diagns=`echo ${snddiagnames} | tr ':' ' '` |
---|
| 123 | |
---|
| 124 | idiag=1 |
---|
| 125 | for diagn in ${diagns}; do |
---|
| 126 | diagv=`cat $pyHOME/diagnostics.inf | grep ${diagn}',' | tr ',' ' ' | \ |
---|
| 127 | awk '{print $2"|"$3}'` |
---|
| 128 | if test ${idiag} -eq 1; then |
---|
| 129 | snddiagvals=${diagv} |
---|
| 130 | else |
---|
| 131 | snddiagvals=${snddiagvals}','${diagv} |
---|
| 132 | fi |
---|
| 133 | idiag=`expr ${idiag} + 1` |
---|
| 134 | done |
---|
| 135 | |
---|
| 136 | if ${fscratch}; then rm ${simsnddiagsf}; fi |
---|
| 137 | if test ! -f ${simsnddiagsf}; then |
---|
| 138 | python ${pyHOME}/diagnostics.py -f ${simsndptf} -d ${snddiagd} -v ${snddiagvals} |
---|
| 139 | if test $? -ne 0; then |
---|
| 140 | echo ${errmsg} |
---|
| 141 | echo " python failed!!" |
---|
| 142 | echo python ${pyHOME}/diagnostics.py -f ${simsndptf} -d "'"${snddiagd}"'" -v \ |
---|
| 143 | "'"${snddiagvals}"'" |
---|
| 144 | exit |
---|
| 145 | fi |
---|
| 146 | echo "* computing diagnostics at snd point: "${stlon}", "${stlat} >> ${ofileins} |
---|
| 147 | echo python ${pyHOME}/diagnostics.py -f "'"${simsndptf}"'" -d "'"${snddiagd}"'" \ |
---|
| 148 | -v "'"${snddiagvals}"'" >> ${ofileins} |
---|
| 149 | echo " " >> ${ofileins} |
---|
| 150 | |
---|
| 151 | mv diagnostics.nc ${simsnddiagsf} |
---|
| 152 | if $(isin_list ${snddiagnames} WRFt); then |
---|
| 153 | #To deg |
---|
| 154 | python ${pyHOME}/nc_var.py -o valmod -S subc,273.15 -f ${simsnddiagsf} -v ta |
---|
| 155 | fi |
---|
| 156 | if $(isin_list ${snddiagnames} WRFp); then |
---|
| 157 | #To Pa |
---|
| 158 | python ${pyHOME}/nc_var.py -o valmod -S divc,100. -f ${simsnddiagsf} -v pres |
---|
| 159 | fi |
---|
| 160 | fi |
---|
| 161 | } |
---|
| 162 | |
---|
| 163 | function get_WRFsurface_data(){ |
---|
| 164 | # Function to get the data to compute analysis in a surface point |
---|
| 165 | # stlon= longitude value of the station |
---|
| 166 | # stlat= latitude value of the station |
---|
| 167 | # filen= name of the file |
---|
| 168 | # lonvarn= name of the longitude variable |
---|
| 169 | # latvarn= name of the latitude variable |
---|
| 170 | # sfcdiagnames= diagnostics to compute (as ':' separated list) |
---|
| 171 | # nondiagvs= ':' list of variables which are not from a diagnostics ('None' for |
---|
| 172 | # without) |
---|
| 173 | |
---|
| 174 | funcvals=$1 |
---|
| 175 | |
---|
| 176 | stlon=`echo ${funcvals} | tr '#' ' ' | awk '{print $1}'` |
---|
| 177 | stlat=`echo ${funcvals} | tr '#' ' ' | awk '{print $2}'` |
---|
| 178 | filen=`echo ${funcvals} | tr '#' ' ' | awk '{print $3}'` |
---|
| 179 | lonvarn=`echo ${funcvals} | tr '#' ' ' | awk '{print $4}'` |
---|
| 180 | latvarn=`echo ${funcvals} | tr '#' ' ' | awk '{print $5}'` |
---|
| 181 | sfcdiagnames=`echo ${funcvals} | tr '#' ' ' | awk '{print $6}'` |
---|
| 182 | nondiagvs=`echo ${funcvals} | tr '#' ' ' | awk '{print $7}'` |
---|
| 183 | |
---|
| 184 | vals=${lonvarn}':'${latvarn}':Time|0' |
---|
| 185 | gridsndv=`python ${pyHOME}/nc_var.py -o get_point -f ${filen} -S ${vals} \ |
---|
| 186 | -v ${stlon},${stlat} | tr ' ' '!'` |
---|
| 187 | echo "* get grid point: "${stlon}", "${stlat} >> ${ofileins} |
---|
| 188 | echo python ${pyHOME}/nc_var.py -o get_point -f ${filen} -S "'"${vals}"'" \ |
---|
| 189 | -v ${stlon},${stlat} >> ${ofileins} |
---|
| 190 | echo " " >> ${ofileins} |
---|
| 191 | xsnd=`echo ${gridsndv} | tr '!' ' ' | awk '{print $1}' | tr ',' ' ' | \ |
---|
| 192 | awk '{print $1}'` |
---|
| 193 | ysnd=`echo ${gridsndv} | tr '!' ' ' | awk '{print $1}' | tr ',' ' ' | \ |
---|
| 194 | awk '{print $2}'` |
---|
| 195 | dsnd=`echo ${gridsndv} | tr '!' ' ' | awk '{print $2}'` |
---|
| 196 | |
---|
| 197 | xsnd1=`expr ${xsnd} + 1` |
---|
| 198 | ysnd1=`expr ${ysnd} + 1` |
---|
| 199 | |
---|
| 200 | # Getting values |
---|
| 201 | if ${fscratch}; then rm ${simsfcptf} >& /dev/null; fi |
---|
| 202 | if test ! -f ${simsfcptf}; then |
---|
| 203 | values='Time,0,-1,1@south_north,'${ysnd}','${ysnd}',1@' |
---|
| 204 | values=${values}'west_east,'${xsnd}','${xsnd}',1@south_north_stag,'${ysnd}',' |
---|
| 205 | values=${values}${ysnd1}',1@west_east_stag,'${xsnd}','${xsnd1}',1' |
---|
| 206 | python ${pyHOME}/nc_var.py -o DataSetSection_multidims -f ${filen} \ |
---|
| 207 | -S ${values} -v all |
---|
| 208 | if test $? -ne 0; then |
---|
| 209 | echo ${errmsg} |
---|
| 210 | echo " python failed!!" |
---|
| 211 | echo python ${pyHOME}/nc_var.py -o DataSetSection_multidims -f ${filen} \ |
---|
| 212 | -S "'"${values}"'" -v all |
---|
| 213 | exit |
---|
| 214 | fi |
---|
| 215 | echo "* get values at sfc point: "${stlon}", "${stlat} >> ${ofileins} |
---|
| 216 | echo python ${pyHOME}/nc_var.py -o DataSetSection_multidims -f ${filen} \ |
---|
| 217 | -S "'"${values}"'" -v all >> ${ofileins} |
---|
| 218 | echo " " >> ${ofileins} |
---|
| 219 | yslc='south_north_B'${ysnd}'-E'${ysnd}'-I1' |
---|
| 220 | ystslc='south_north_stag_B'${ysnd}'-E'${ysnd1}'-I1' |
---|
| 221 | xslc='west_east_B'${xsnd}'-E'${xsnd}'-I1' |
---|
| 222 | xstslc='west_east_stag_B'${xsnd}'-E'${xsnd1}'-I1' |
---|
| 223 | |
---|
| 224 | ofilen=${filen}'_Time_B0-E-1-I1_'${yslc}'_'${xslc}'_'${ystslc}'_'${xstslc}'.nc' |
---|
| 225 | mv ${ofilen} ${simsfcptf} |
---|
| 226 | fi |
---|
| 227 | |
---|
| 228 | # Computing sfc diagnostics |
---|
| 229 | sfcdiagd='Time@WRFtime' |
---|
| 230 | diagns=`echo ${sfcdiagnames} | tr ':' ' '` |
---|
| 231 | |
---|
| 232 | idiag=1 |
---|
| 233 | for diagn in ${diagns}; do |
---|
| 234 | diagv=`cat $pyHOME/diagnostics.inf | grep WRF | grep ${diagn}',' | tr ',' ' ' | \ |
---|
| 235 | awk '{print $2"|"$3}'` |
---|
| 236 | if test ${idiag} -eq 1; then |
---|
| 237 | sfcdiagvals=${diagv} |
---|
| 238 | else |
---|
| 239 | sfcdiagvals=${sfcdiagvals}','${diagv} |
---|
| 240 | fi |
---|
| 241 | idiag=`expr ${idiag} + 1` |
---|
| 242 | done |
---|
| 243 | |
---|
| 244 | if ${fscratch}; then rm ${simsfcdiagsf}; fi |
---|
| 245 | if test ! -f ${simsfcdiagsf}; then |
---|
| 246 | python ${pyHOME}/diagnostics.py -f ${simsfcptf} -d ${sfcdiagd} -v ${sfcdiagvals} |
---|
| 247 | if test $? -ne 0; then |
---|
| 248 | echo ${errmsg} |
---|
| 249 | echo " python failed!!" |
---|
| 250 | echo python ${pyHOME}/diagnostics.py -f ${simsfcptf} -d "'"${sfcdiagd}"'" \ |
---|
| 251 | -v "'"${sfcdiagvals}"'" |
---|
| 252 | exit |
---|
| 253 | fi |
---|
| 254 | echo "* diagnostics at sfc point: "${stlon}", "${stlat} >> ${ofileins} |
---|
| 255 | echo python ${pyHOME}/diagnostics.py -f ${simsfcptf} -d "'"${sfcdiagd}"'" \ |
---|
| 256 | -v "'"${sfcdiagvals}"'" >> ${ofileins} |
---|
| 257 | echo " " >> ${ofileins} |
---|
| 258 | mv diagnostics.nc ${simsfcdiagsf} |
---|
| 259 | if $(isin_list ${sfcdiagnames} wds); then |
---|
| 260 | #To rad |
---|
| 261 | python ${pyHOME}/nc_var.py -o valmod -S mulc,0.0174532925199 -f ${simsfcdiagsf}\ |
---|
| 262 | -v wds |
---|
| 263 | python ${pyHOME}/nc_var.py -o varaddattr -S 'units|rad' -f ${simsfcdiagsf} -v wds |
---|
| 264 | fi |
---|
| 265 | fi |
---|
| 266 | |
---|
| 267 | #Adding non-diagnostic variables |
---|
| 268 | if test ! ${nondiagvs} = 'None'; then |
---|
| 269 | varsadd=`echo ${nondiagvs} | tr ':' ' '` |
---|
| 270 | for vadd in ${varsadd}; do |
---|
| 271 | python ${pyHOME}/nc_var.py -o fvaradd -S ${simsfcptf},${vadd} -f ${simsfcdiagsf} |
---|
| 272 | if test $? -ne 0; then |
---|
| 273 | echo ${errmsg} |
---|
| 274 | echo " python failed!!" |
---|
| 275 | echo python ${pyHOME}/nc_var.py -o fvaradd -S "'"${simsfcptf},${vadd}"'" \ |
---|
| 276 | -f ${simsfcdiagsf} |
---|
| 277 | exit |
---|
| 278 | rm ${simsfcdiagsf} |
---|
| 279 | fi |
---|
| 280 | echo "* adding variable '"${vadd}"' at sfc point: "${stlon}", "${stlat} >> ${ofileins} |
---|
| 281 | echo python ${pyHOME}/nc_var.py -o fvaradd -S "'"${simsfcptf},${vadd}"'" \ |
---|
| 282 | -f ${simsfcdiagsf} >> ${ofileins} |
---|
| 283 | echo " " >> ${ofileins} |
---|
| 284 | # CF varname |
---|
| 285 | CFvarn=`python $pyHOME/generic.py -o variables_values -S ${vadd} | tr ':' ' ' |\ |
---|
| 286 | awk '{print $1}'` |
---|
| 287 | if test $? -ne 0; then |
---|
| 288 | echo ${errmsg} |
---|
| 289 | echo " python failed!!" |
---|
| 290 | echo python $pyHOME/generic.py -o variables_values -S ${vadd} |
---|
| 291 | exit |
---|
| 292 | rm ${simsfcdiagsf} |
---|
| 293 | fi |
---|
| 294 | python $pyHOME/nc_var.py -o chvarname -S ${CFvarn} -f ${simsfcdiagsf} -v ${vadd} |
---|
| 295 | if test $? -ne 0; then |
---|
| 296 | echo ${errmsg} |
---|
| 297 | echo " python failed!!" |
---|
| 298 | echo python ${pyHOME}/nc_var.py -o chvarname -S ${CFvarn} -f ${simsfcdiagsf} \ |
---|
| 299 | -v ${vadd} |
---|
| 300 | exit |
---|
| 301 | rm ${simsfcdiagsf} |
---|
| 302 | fi |
---|
| 303 | done |
---|
| 304 | fi |
---|
| 305 | } |
---|
[2001] | 306 | ####### ####### |
---|
| 307 | ## MAIN |
---|
| 308 | ####### |
---|
[2000] | 309 | |
---|
[2001] | 310 | rootsh=`pwd` |
---|
[2000] | 311 | |
---|
[2001] | 312 | ofileins=${rootsh}'/allins_functions.inf' |
---|
[2000] | 313 | |
---|
[2001] | 314 | if ${fscratch}; then |
---|
| 315 | echo "All instructions _______ " > ${ofileins} |
---|
| 316 | echo "******* ****** ***** **** *** ** *" >> ${ofileins} |
---|
| 317 | echo " " >> ${ofileins} |
---|
| 318 | fi |
---|
[2000] | 319 | |
---|
[2001] | 320 | fdate=`echo ${infilen} | tr '_' ' ' | awk '{print $3"_"$4}'` |
---|
[2000] | 321 | |
---|
[2001] | 322 | # Sounding |
---|
| 323 | if test ! ${sndid} = 'None'; then |
---|
| 324 | stid=${sndid} |
---|
| 325 | simsndptf=${odir}'/simout_vars_sndpt_'${stid}'_'${expl}'_'${fdate}'.nc' |
---|
| 326 | simsnddiagsf=${odir}'/simout_snddiags_'${stid}'_'${expl}'_'${fdate}'.nc' |
---|
[2000] | 327 | |
---|
[2001] | 328 | fvals=${sndlon}'#'${sndlat}'#'${infilen}'#XLONG#XLAT#'${wrfsnddiags} |
---|
| 329 | get_WRFsounding_data ${fvals} |
---|
| 330 | fi |
---|
[2000] | 331 | |
---|
[2001] | 332 | # Surface |
---|
| 333 | if test ! ${sfcid} = 'None'; then |
---|
| 334 | stid=${sfcid} |
---|
| 335 | simsfcptf=${odir}'/simout_vars_sfcpt_'${stid}'_'${expl}'_'${fdate}'.nc' |
---|
| 336 | simsfcdiagsf=${odir}'/simout_sfcdiags_'${stid}'_'${expl}'_'${fdate}'.nc' |
---|
| 337 | |
---|
| 338 | fvals=${sfclon}'#'${sfclat}'#'${infilen}'#XLONG#XLAT#'${wrfsfcdiags}'#'${wrfsfcnodiags} |
---|
| 339 | get_WRFsurface_data ${fvals} |
---|
| 340 | fi |
---|
| 341 | |
---|
[2000] | 342 | fi |
---|