- Timestamp:
- Jun 18, 2016, 8:06:09 PM (8 years ago)
- Location:
- trunk/tools
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/model_graphics.bash
r868 r886 32 32 } 33 33 34 function is in_list() {34 function isInlist() { 35 35 # Function to check whether a value is in a list 36 36 list=$1 … … 60 60 exit 61 61 fi 62 } 63 64 function ferrmsgF() { 65 # Function to exit and write an error message and remove a file 66 # comdexit: code number exit from the last execution 67 # ref: script/reference from which error occurs 68 # msg: message to write ('!' for spaces, '#' for end of line) 69 # FileName: name of the file to remove in case of error 70 comdexit=$1 71 ref=$2 72 msg=$3 73 FileName=$4 74 75 if test ${comdexit} -ne 0; then 76 echo "ERROR -- error -- ERROR -- error" 77 echo " "${ref}": "$(echo ${msg} | tr '!' ' ' | tr '#' '\n')" !!" 78 rm ${FileName} >& /dev/null 79 exit 80 fi 81 } 82 83 function WRF_toCF() { 84 # Function to pass a WRF original file to CF-conventions 85 # wrff= WRF file 86 # wrfvl= WRF longitude var name (it might come from WPS!) 87 # wrfvL= WRF latitude var name (it might come from WPS!) 88 89 wrff=$1 90 wrfvl=$2 91 wrfvL=$3 92 93 fdims=`${pyHOME}/nc_var.py -o idims -f ${wrff} | grep alldims | tr '=' ' ' | \ 94 awk '{print $3}'` 95 96 CFdims='west_east@lon:south_north@lat:Time@time' 97 CFds=`echo ${CFdims} | tr ':' ' '` 98 99 pyout=`${pyHOME}/nc_var.py -o WRF_CFtime_creation -S 19491201000000,minutes \ 100 -f ${wrff} -v time` 101 pyn=$? 102 Spyout=`echo ${pyout} | tr '\n' '#' | tr ' ' '!'` 103 ferrmsgF ${pyn} ${fname} "python!'WRF_CFtime_creation'!failed"${Spyout} ${wrff} 104 105 pyout=`${pyHOME}/nc_var.py -o WRF_CFlonlat_creation -v ${wrfvl},${wrfvL} \ 106 -f ${wrff} -S lon,lat` 107 pyn=$? 108 Spyout=`echo ${pyout} | tr '\n' '#' | tr ' ' '!'` 109 ferrmsgF ${pyn} ${fname} "python!'WRF_CFlonlat_creation'!failed"${Spyout} ${wrff} 110 111 for CFd in ${CFds}; do 112 cd=`echo ${CFd} | tr '@' ' ' | awk '{print $2}'` 113 wd=`echo ${CFd} | tr '@' ' ' | awk '{print $1}'` 114 if $(isInlist ${fdims} ${wd}); then 115 pyout=`${pyHOME}/nc_var.py -o chdimname -f ${wrff} -S ${wd}':'${cd}` 116 pyn=$? 117 Spyout=`echo ${pyout} | tr '\n' '#' | tr ' ' '!'` 118 ferrmsgF ${pyn} ${fname} "python!'chdimname'!'"${wd}"'!failed#"${Spyout} ${wrff} 119 fi 120 done 121 62 122 } 63 123 … … 81 141 # [modvar]: variable to use from the file 82 142 # [diagvar]: variable computed from the diagnostics (diagnostic.py) 143 # mdim: name of the dimensions in the model 144 # mvdim: name of the vaariable-dimensions in the model 83 145 # scratch: whether is has to be done from the scratch or not 84 146 fname='compute_variable' … … 87 149 odir=$3 88 150 cvar=$4 89 scratch=$5 151 mdim=$5 152 mvdim=$6 153 scratch=$7 90 154 91 155 CFvarn=`echo ${cvar} | tr '|' ' ' | awk '{print $1}'` … … 98 162 awk '{print $2}' | tr '@' ' '` 99 163 164 # dimensions 165 dnx=`echo ${mdim} | tr ',' ' ' | awk '{print $1}'` 166 dny=`echo ${mdim} | tr ',' ' ' | awk '{print $2}'` 167 # var-dimensions 168 vdnx=`echo ${mvdim} | tr ',' ' ' | awk '{print $1}'` 169 vdny=`echo ${mvdim} | tr ',' ' ' | awk '{print $2}'` 170 100 171 cd ${odir} 101 172 … … 103 174 Ntotfiles=`echo ${cfiles} | wc -w | awk '{print $1}'` 104 175 ifile=1 176 105 177 for cf in ${cfiles}; do 106 178 ifS=`printf "%0${Ntotfiles}d" ${ifile}` 179 107 180 # Computing variable 108 181 filen=${odir}/${CFvarn}_${headerf}_${ifile}-${Ntotfiles}.nc 109 if ${scratch}; then rm ${filen}; fi 110 111 if test ! -f ${filen}; then 182 if ${scratch}; then 183 rm ${filen} 184 rm ${odir}/${CFvarn}_${headerf}.nc 185 fi 186 187 if test ! -f ${filen} && test ! -f ${odir}/${CFvarn}_${headerf}.nc; then 112 188 if test ! ${modvar} = 'None'; then 113 189 # model variable … … 116 192 pyout=`${pyHOME}/nc_var.py -f ${cf} -o DataSetSection_multivars -v ${vs} \ 117 193 -S ${values} | grep succesfull | awk '{print $6}' | tr '"' ' '` 118 ferrmsg $? ${fname} "python!'DataSetSection_multivars'!failed" 194 pyn=$? 195 Spyout=`echo ${pyout} | tr '\n' '#' | tr ' ' '!'` 196 ferrmsg ${pyn} ${fname} "python!'DataSetSection_multivars'!failed"${Spyout} 119 197 mv ${pyout} ${filen} 120 pyout=`${pyHOME}/nc_var.py -f ${filen} -o chvarname -v ${vs} -S ${CFvarn}` 121 ferrmsg $? ${fname} "python!'chvarname'!failed" 122 123 # adding CF lon,lat,time in WRF files 124 if test ${headerf:0:3} = 'wrf'; then 125 ${pyHOME}/nc_var.py -o WRF_CFtime_creation -S 19491201000000,minutes \ 126 -f ${filen} -v time 127 ${pyHOME}/nc_var.py -o WRF_CFlonlat_creation -v ${vdnx},${vdny} \ 128 -f ${filen} -S lon,lat 129 fi 198 199 pyout=`${pyHOME}/nc_var.py -f ${filen} -o chvarname -v ${modvar} -S ${CFvarn}` 200 pyn=$? 201 Spyout=`echo ${pyout} | tr '\n' '#' | tr ' ' '!'` 202 ferrmsgF ${pyn} ${fname} "python!'chvarname'!failed"${Spyout} ${filen} 130 203 else 131 204 # diagnostic variable … … 145 218 done 146 219 147 echo "python ${pyHOME}/diagnostics.py -f ${cf} -d ${dims} -v ${diagn}'|'${diagc}"148 220 pyout=`python ${pyHOME}/diagnostics.py -f ${cf} -d ${dims} -v ${diagn}'|'${diagc}` 149 ferrmsg $? ${fname} "python!'diagnostics'!failed" 221 pyn=$? 222 Spyout=`echo ${pyout} | tr '\n' '#' | tr ' ' '!'` 223 ferrmsg ${pyn} ${fname} "python!'diagnostics'!failed#"${Spyout} 150 224 mv diagnostics.nc ${filen} 151 152 # adding CF lon,lat,time in WRF files 153 if test ${headerf:0:3} = 'wrf'; then154 ${pyHOME}/nc_var.py -o WRF_CFtime_creation -S 19491201000000,minutes \155 -f ${filen} -v time156 ${pyHOME}/nc_var.py -o WRF_CFlonlat_creation -v ${vdnx},${vdny} \157 -f ${filen} -S lon,lat 158 fi 159 fi 225 fi 226 227 # adding CF lon,lat,time in WRF files 228 if test ${headerf:0:3} = 'wrf'; then 229 WRF_toCF ${filen} ${vdnx} ${vdny} 230 fi 231 232 LLUIS TO ADD ALL CF attributes!!!!!!! 233 160 234 fi 161 235 162 236 ifile=`expr ${ifile} + 1` 237 # End of files 163 238 done 164 239 240 # Joining variable files 241 filen=${odir}/${CFvarn}_${headerf}.nc 242 if ${scratch}; then rm ${filen}; fi 243 244 if test ! -f ${filen}; then 245 pyout=`python ${pyHOME}/nc_var.py -f ${CFvarn}_${headerf}_ \ 246 -o netcdf_fold_concatenation -S ./,time -v all` 247 pyn=$? 248 Spyout=`echo ${pyout} | tr '\n' '#' | tr ' ' '!'` 249 ferrmsg ${pyn} ${fname} "python!'netcdf_fold_concatenation'!failed#"${Spyout} 250 251 mv netcdf_fold_concatenated.nc ${filen} 252 if test -f ${filen}; then 253 rm ${CFvarn}_${headerf}_* 254 fi 255 fi 256 } 257 258 function compute_statistics(){ 259 # Function to compute different statistics 260 # idir: directory with the input files 261 # usefiles: ',' list of files to use [file1],...,[fileN] 262 # odir: directory to write the output files 263 # cvar: [CFvarn]|[varkind]|[headerf]|[varmod]|[vardiag] 264 # [CFvarn]: CF name of the variable 265 # [vark]: kind of variable: 266 # acc: temporal accumulated values 267 # diff: differences between models 268 # direct: no statistics 269 # Lmean: latitudinal mean values 270 # Lsec: latitudinal section (latitudinal value must be given, [var]@[lat]) 271 # lmean: longitudinal mean values 272 # lsec: longitudinal section (longitudinal value must be given, [var]@[lat]) 273 # tmean: temporal mean values 274 # xmean: x-axis mean values 275 # ymean: y-axis mean values 276 # zsum: vertical aggregated values 277 # [headerf]: header of the files to use 278 # [modvar]: variable to use from the file 279 # [diagvar]: variable computed from the diagnostics (diagnostic.py) 280 # mdim: name of the dimensions in the model 281 # mvdim: name of the vaariable-dimensions in the model 282 # scratch: whether is has to be done from the scratch or not 283 fname='compute_statistics' 284 285 idir=$1 286 usefiles=$2 287 odir=$3 288 cvar=$4 289 mdim=$5 290 mvdim=$6 291 scratch=$7 292 293 CFvarn=`echo ${cvar} | tr '|' ' ' | awk '{print $1}'` 294 vark=`echo ${cvar} | tr '|' ' ' | awk '{print $2}'` 295 headerf=`echo ${cvar} | tr '|' ' ' | awk '{print $3}'` 296 modvar=`echo ${cvar} | tr '|' ' ' | awk '{print $4}'` 297 diagvar=`echo ${cvar} | tr '|' ' ' | awk '{print $5}'` 298 299 cfiles=`echo ${usefiles} | tr ',' ' '` 300 301 # dimensions 302 dnx=`echo ${mdim} | tr ',' ' ' | awk '{print $1}'` 303 dny=`echo ${mdim} | tr ',' ' ' | awk '{print $2}'` 304 # var-dimensions 305 vdnx=`echo ${mvdim} | tr ',' ' ' | awk '{print $1}'` 306 vdny=`echo ${mvdim} | tr ',' ' ' | awk '{print $2}'` 307 308 cd ${odir} 309 310 filen=${CFvarn}_${headerf}_${vark}.nc 311 if ${scratch}; then rm ${filen} >& /dev/null; fi 312 313 if test ! -f ${filen}; then 314 # Computing stats 315 case ${vark} in 316 # temporal accumulated values 317 'acc') 318 echo " "${fname}": kind '"${vark}"' not ready !!" 319 exit 320 ;; 321 # differences between models 322 'diff') 323 echo " "${fname}": kind '"${vark}"' not ready !!" 324 exit 325 ;; 326 # no statistics 327 'direct') 328 cp ${cfiles} ${filen} 329 ;; 330 # latitudinal mean values 331 'Lmean') 332 echo " "${fname}": kind '"${vark}"' not ready !!" 333 exit 334 ;; 335 # latitudinal section (latitudinal value must be given, [var]@[lat]) 336 'Lsec') 337 echo " "${fname}": kind '"${vark}"' not ready !!" 338 exit 339 ;; 340 # longitudinal section (longitudinal value must be given, [var]@[lat]) 341 'lsec') 342 echo " "${fname}": kind '"${vark}"' not ready !!" 343 exit 344 ;; 345 # longitudinal mean values 346 'lmean') 347 echo " "${fname}": kind '"${vark}"' not ready !!" 348 exit 349 ;; 350 # temporal mean values 351 'tmean') 352 vals='time:-1,time,mean,lon:lat:'${vdnz}':time' 353 dims='time@time,'${dnz}'@'${vdnz}',lat@lat,lon@lon' 354 355 pyout=`python ${pyHOME}/nc_var.py -o file_oper_alongdims -S ${vals} \ 356 -f ${cfiles} -v ${CFvarn}` 357 pyn=$? 358 Spyout=`echo ${pyout} | tr '\n' '#' | tr ' ' '!'` 359 ferrmsg ${pyn} ${fname} "python!'file_oper_alongdims'!'tmean'!failed#"${Spyout} 360 mv file_oper_alongdims_mean.nc ${filen} 361 ;; 362 # x-axis mean values 363 'xmean') 364 vals='lon:-1,lon,mean,lon:lat:'${vdnz}':time' 365 dims='time@time,'${dnz}'@'${vdnz}',lat@lat,lon@lon' 366 echo "python ${pyHOME}/nc_var.py -o file_oper_alongdims -S ${vals} -f ${cfiles} -v ${CFvarn}" 367 368 pyout=`python ${pyHOME}/nc_var.py -o file_oper_alongdims -S ${vals} \ 369 -f ${cfiles} -v ${CFvarn}` 370 pyn=$? 371 Spyout=`echo ${pyout} | tr '\n' '#' | tr ' ' '!'` 372 ferrmsg ${pyn} ${fname} "python!'file_oper_alongdims'!'tmean'!failed#"${Spyout} 373 mv file_oper_alongdims_mean.nc ${filen} 374 ;; 375 # y-axis mean values 376 'ymean') 377 vals='lat:-1,lat,mean,lon:lat:'${vdnz}':time' 378 dims='time@time,'${dnz}'@'${vdnz}',lat@lat,lon@lon' 379 echo "python ${pyHOME}/nc_var.py -o file_oper_alongdims -S ${vals} -f ${cfiles} -v ${CFvarn}" 380 381 pyout=`python ${pyHOME}/nc_var.py -o file_oper_alongdims -S ${vals} \ 382 -f ${cfiles} -v ${CFvarn}` 383 pyn=$? 384 Spyout=`echo ${pyout} | tr '\n' '#' | tr ' ' '!'` 385 ferrmsg ${pyn} ${fname} "python!'file_oper_alongdims'!'tmean'!failed#"${Spyout} 386 mv file_oper_alongdims_mean.nc ${filen} 387 ;; 388 # vertical aggregated values 389 'zsum') 390 echo " "${fname}": kind '"${vark}"' not ready !!" 391 exit 392 ;; 393 *) 394 echo ${errmsg} 395 echo " "${fname}": kind '"${vark}"' not ready !!" 396 exit 397 ;; 398 esac 399 fi 400 # exit 165 401 # LLUIS 166 # exit167 402 } 168 403 … … 238 473 echo " dims: "${dnx}", "${dny}", "${dnz}", "${dnt} 239 474 echo " var dims: "${vdnx}", "${vdny}", "${vdnz}", "${vdnt} 475 moddims=${dnx}','${dny}','${dnz}','${dnt} 476 modvdims=${vdnx}','${vdny}','${vdnz}','${vdnt} 240 477 241 478 # Experiments loop … … 290 527 echo " "${vark}" ..." 291 528 case ${vark} in 292 ' varacc')529 'acc') 293 530 varvks=${varacc} 294 531 ;; 295 ' vardiff')532 'diff') 296 533 varvks=${vardiff} 297 534 ;; … … 299 536 varvks=${vardirect} 300 537 ;; 301 'varLsec') 538 'Lmean') 539 varvks=${varLmean} 540 ;; 541 'Lsec') 302 542 varvks=${varLsec} 303 543 ;; 304 'varlsec') 544 'lmean') 545 varvks=${varlmean} 546 ;; 547 'lsec') 305 548 varvks=${varlsec} 306 549 ;; 307 'varlmean') 308 varvks=${varlmean} 309 ;; 310 'vartmean') 550 'tmean') 311 551 varvks=${vartmean} 312 552 ;; 313 'varzsum') 553 'xmean') 554 varvks=${varxmean} 555 ;; 556 'ymean') 557 varvks=${varymean} 558 ;; 559 'zsum') 314 560 varvks=${varzsum} 315 561 ;; … … 408 654 cd $owdir 409 655 ic=1 656 isc=1 410 657 cvars=`echo ${varcompute} | tr ';' ' '` 411 658 for cvar in ${cvars}; do 412 659 CFv=`echo ${cvar} | tr '|' ' ' | awk '{print $1}'` 660 vark=`echo ${cvar} | tr '|' ' ' | awk '{print $2}'` 661 fileh=`echo ${cvar} | tr '|' ' ' | awk '{print $3}'` 413 662 modv=`echo ${cvar} | tr '|' ' ' | awk '{print $4}'` 414 663 diagv=`echo ${cvar} | tr '|' ' ' | awk '{print $5}'` … … 416 665 417 666 if test ! ${modv} = 'None' || test ! ${diagv} = 'None'; then 418 compute_variable ${iwdir} ${files} ${owdir} ${cvar} ${scratch} 667 compute_variable ${iwdir} ${files} ${owdir} ${cvar} ${moddims} ${modvdims} \ 668 ${scratch} 419 669 ic=`expr ${ic} + 1` 670 671 if test ! ${vark} = 'diff'; then 672 compute_statistics ${iwdir} ${CFv}_${fileh}.nc ${owdir} ${cvar} \ 673 ${moddims} ${modvdims} ${scratch} 674 isc=`expr ${isc} + 1` 675 else 676 echo " "${main}": differences will be calculated when all the " \ 677 "model/experiments will be done !" 678 fi 420 679 else 421 680 echo " not computing '"${CFv}"' for model '"${mod}"' !!" … … 425 684 # end of computing vars 426 685 done 427 echo " "${main}": has been "${ic}" variables computed" 686 echo " "${main}": "${ic}" variables has been computed" 687 echo " "${main}": "${isc}" statistics has been computed" 688 428 689 cd ${rootsh} 429 690 exit -
trunk/tools/model_graphics_template.dat
r868 r886 13 13 # - WRF outputs will have added 'WRFtime' variable 14 14 # 15 # NOTE: in this file all the values without '15 # NOTE: in this file all the values are ':' separated lists without ' 16 16 17 17 # python HOME … … 50 50 # diff: differences between models 51 51 # direct: no statistics 52 # Lmean: latitudinal mean values 52 53 # Lsec: latitudinal section (latitudinal value must be given, [var]@[lat]) 54 # lmean: longitudinal mean values 53 55 # lsec: longitudinal section (longitudinal value must be given, [var]@[lat]) 54 # lmean: longitudinal mean values55 56 # tmean: temporal mean values 57 # xmean: x-axis mean values 58 # ymean: y-axis mean values 56 59 # zsum: vertical aggregated values 57 varkinds = direct:tmean: lmean:diff60 varkinds = direct:tmean:xmean:diff 58 61 59 62 # variables (providing CF-name, script must provide equivalent variable for each model) … … 62 65 vardirect = tas:uas:vas:ps:pr:pracc:rsds:prw:evspsbl:hfss:hfls:hurs:huss:zmla:hufs:wakes:lwakeh:stherm:zmaxth:clt:cll:clm:clh:prc:prls:bils 63 66 vartmean = prc:prls:zmla:hfss:hfls:evspsbl:bils:uas:vas:tas:ps:clt:cll:clm:clh:prw:huss:pr:wakes:wakeh:stherm:zmaxth 64 var lmean = ta:ua:va:hur67 varxmean = ta:ua:va:hur 65 68 vardiff = ualmean:valmean:talmean:huslmean:uas:vas:ps:pr 66 69
Note: See TracChangeset
for help on using the changeset viewer.