Run specific Bash Scripts after every Autorun/Autopost

Questions and other topics related to UEMS 18.
Post Reply
User avatar
UwBeInt
Posts: 7
Joined: Sun Dec 09, 2018 10:38 am
Location: CH-5079 Zeihen
Contact:

Run specific Bash Scripts after every Autorun/Autopost

Post by UwBeInt » Fri Apr 10, 2020 12:04 pm

Hello

I use the UEMS Autorun for three Domains (Europe 12km, Switzerland 12km and Switzerland 4km).
The Cronjobs and Autorun will make a very good job for automatic 00, 06, 12 and 18Z Runs.

But, i want also let delete the older Images in the Directory and then Plot the new charts from Grads. For this i have written SH Scripts.

My Question is now: How i can tell uems_autorun, that it should be run a shell script after success autopost the Grads Files (emsupp) ?

Example:
Domain Europe 12km is downloading files, preparing and running. After UEMS will create Grib Files and of these a CTL File (Post GrADS).
If the process are success finished, then should be run two SH Scripts, before Autorun start's with the next Domain.

For Europe 12km, should be run sh_script_eu.sh, for Switzerland 12km run sh_script_ch and for Switzerland 4km the sh_script_ch4km.sh ...

Where can i put in this commands and how to find out which Domain is actually generated/postet?

Thank you.
System: Ubuntu 18.04.4 LTS - 40 x Intel(R) Xeon(R) CPU E5-2630 v4 @ 2.20GHz - 128GB RAM - 2.7TB HDD, 1TB SSD
www.uwbeinternational.org

User avatar
UwBeInt
Posts: 7
Joined: Sun Dec 09, 2018 10:38 am
Location: CH-5079 Zeihen
Contact:

Re: Run specific Bash Scripts after every Autorun/Autopost

Post by UwBeInt » Fri Apr 10, 2020 3:04 pm

I have now try anything with the $argv vars and add the following code in uems/strc/Ubin/uems_autoruns_wrapper.csh:

Code: Select all

    # Delete Old Images and Plot new GRADS
    set argv2 = `echo "$argv" | sed "s/ //g"`

    if ( `echo "$argv2" | /bin/grep "eu"` != "") then
    /home/uwbe/uems/clear_wrf_eu.sh ;
    /home/uwbe/uems/grads_scripts/plot_charts_eu.sh
    endif

    if ( `echo "$argv2" | /bin/grep "switzerland"` != "") then
    /home/uwbe/uems/clear_wrf_ch.sh ;
    /home/uwbe/uems/grads_scripts/plot_charts_ch.sh
    endif

    if ( `echo "$argv2" | /bin/grep "ch_4km"` != "") then
    /home/uwbe/uems/clear_wrf_ch4km.sh ;
    /home/uwbe/uems/grads_scripts/plot_charts_ch4km.sh
    endif
I hope it will work ^^
If do, then i will post all Codes also for your use :)
System: Ubuntu 18.04.4 LTS - 40 x Intel(R) Xeon(R) CPU E5-2630 v4 @ 2.20GHz - 128GB RAM - 2.7TB HDD, 1TB SSD
www.uwbeinternational.org

User avatar
UwBeInt
Posts: 7
Joined: Sun Dec 09, 2018 10:38 am
Location: CH-5079 Zeihen
Contact:

Re: Run specific Bash Scripts after every Autorun/Autopost

Post by UwBeInt » Fri Apr 10, 2020 6:09 pm

So, for me it work's fine.
Maybe you have a better Solution, then let me know.

Code: Select all

    #  Make sure the environment has been set correctly
    #
    if ( -e $EMS/etc/EMS.cshrc ) then
        source $EMS/etc/EMS.cshrc
    else
        echo ""
        echo "  ERROR: UEMS Environment variable not correct in $0."
        echo "         Fix it and try again."
        echo "" 
        exit
    endif


    #  Let's start the show
    #
    echo "  RUNNING: $EMS_STRC/Ubin/ems_autorun.pl $argv >& $EMS_LOGS/uems_autoruns.log"
    $EMS_STRC/Ubin/ems_autorun.pl $argv >& $EMS_LOGS/uems_autoruns.log ;

    # Delete Old Images and Plot new GRADS
    set argv2 = `echo "$argv" | sed "s/ //g"`

    if ( `echo "$argv2" | /bin/grep "eu"` != "") then
    sh /home/uwbe/uems/clear_wrf_eu.sh ;
    sh /home/uwbe/uems/grads_scripts/plot_charts_eu.sh
    endif

    if ( `echo "$argv2" | /bin/grep "switzerland"` != "") then
    sh /home/uwbe/uems/clear_wrf_ch.sh ;
    sh /home/uwbe/uems/grads_scripts/plot_charts_ch.sh
    endif

    if ( `echo "$argv2" | /bin/grep "ch_4km"` != "") then
    sh /home/uwbe/uems/clear_wrf_ch4km.sh ;
    sh /home/uwbe/uems/grads_scripts/plot_charts_ch4km.sh
    endif

   #if ( `echo "$argv2" | /bin/grep "eu_4km"` != "") then
   #/home/uwbe/uems/clear_wrf_eu4km.sh ;
   #/home/uwbe/uems/grads_scripts/plot_charts_eu4km.sh
   #endif

    set err = $?
    if ($err != 0) echo "  Your simulation appears not to have ended well ($err)\n\n"
My "plot_charts"-Bash Script's are written for every Domain. These Scripts check if an actual CTL-File is in the WRF Out Directory /emsprd/grads and then will run a lot of Grads-Scripts for plotting Maps. I have written the GrADS with $args, so that i can run every Script for any Domain, any Time and any length.

The clear_wrf_XX.sh Script will delete all older Maps/Images in the wrf_out Directory.

Example, here the plot_charts_eu.sh - Script: (The length-Variable is your lenght what you have choose or give by ems_prep).

Code: Select all

#!bin/csh
length=182

find_eu=$(find /home/uwbe/uems/runs/eu/emsprd/grads -name "*.ctl" -type f -printf "%f\n")
openfile_eu=${find_eu%%_*}
plot_temp2m_eu='grads -h GD -bpcx "run /home/uwbe/uems/grads_scripts/plot_temp2m.gs eu ${openfile_eu} ${length}"'
plot_capesfc_eu='grads -h GD -bpcx "run /home/uwbe/uems/grads_scripts/plot_capesfc.gs eu ${openfile_eu} ${length}"'
plot_lindex_eu='grads -h GD -blcx "run /home/uwbe/uems/grads_scripts/plot_lindex.gs eu ${openfile_eu} ${length}"'
plot_compradarref_eu='grads -h GD -blcx "run /home/uwbe/uems/grads_scripts/plot_compradarref.gs eu ${openfile_eu} ${length}"'
plot_vv50_eu='grads -h GD -blcx "run /home/uwbe/uems/grads_scripts/plot_vvel.gs 50 eu ${openfile_eu} ${length}"'
plot_vv250_eu='grads -h GD -blcx "run /home/uwbe/uems/grads_scripts/plot_vvel.gs 250 eu ${openfile_eu} ${length}"'
plot_vv625_eu='grads -h GD -blcx "run /home/uwbe/uems/grads_scripts/plot_vvel.gs 625 eu ${openfile_eu} ${length}"'
plot_vv750_eu='grads -h GD -blcx "run /home/uwbe/uems/grads_scripts/plot_vvel.gs 750 eu ${openfile_eu} ${length}"'
plot_vv850_eu='grads -h GD -blcx "run /home/uwbe/uems/grads_scripts/plot_vvel.gs 850 eu ${openfile_eu} ${length}"'
plot_vv925_eu='grads -h GD -blcx "run /home/uwbe/uems/grads_scripts/plot_vvel.gs 925 eu ${openfile_eu} ${length}"'
plot_vv950_eu='grads -h GD -blcx "run /home/uwbe/uems/grads_scripts/plot_vvel.gs 950 eu ${openfile_eu} ${length}"'
plot_vv975_eu='grads -h GD -blcx "run /home/uwbe/uems/grads_scripts/plot_vvel.gs 975 eu ${openfile_eu} ${length}"'
plot_vv1000_eu='grads -h GD -blcx "run /home/uwbe/uems/grads_scripts/plot_vvel.gs 1000 eu ${openfile_eu} ${length}"'
plot_10mwind_eu='grads -h GD -bpcx "run /home/uwbe/uems/grads_scripts/plot_10mwind.gs eu ${openfile_eu} ${length}"'

echo "Starte GrADS Script's - EU 12km Modell-Plot-Prozess"

eval $plot_temp2m_eu > /dev/null ; 
eval $plot_capesfc_eu > /dev/null ; 
eval $plot_lindex_eu > /dev/null ; 
eval $plot_compradarref_eu > /dev/null ; 
eval $plot_vv50_eu > /dev/null ; 
eval $plot_vv250_eu > /dev/null ; 
eval $plot_vv625_eu > /dev/null ; 
eval $plot_vv750_eu > /dev/null ;
eval $plot_vv850_eu > /dev/null ; 
eval $plot_vv925_eu > /dev/null ; 
eval $plot_vv950_eu > /dev/null ; 
eval $plot_vv975_eu > /dev/null ; 
eval $plot_vv1000_eu > /dev/null ;
eval $plot_10mwind_eu > /dev/null ;

echo "Modelle wurden \033[32merfolgreich\033[0m geplottet."
And here you can see a Example GrADS-Script (10mWind):

Code: Select all

*Run Script without Display with follow command:
*Command: grads -h GD -bpcx "plot_10mwind.gs DOMAIN YYMMDDHHMM LENGTH"
*Example for Use this Script: grads -h GD -bpcx "plot_10mwind.gs switzerland 2004021800 180"
*Script by Dominic Kurz, UwBe International
*research@uwbeinternational.org

function main(args)

 'reinit'

domain=subwrd(args,1)
openfile=subwrd(args,2)
hours=subwrd(args,3)

if (domain = 'eu') ; dom="eu" ; endif
if (domain = 'eu_4km') ; dom="eu_4km" ; endif
if (domain = 'switzerland') ; dom="ch" ; endif
if (domain = 'ch_4km') ; dom="ch_4km" ; endif

file='/home/uwbe/uems/runs/'domain'/emsprd/grads/'openfile'_wrfout_arw_d01.ctl'

'open 'file

i = 1
while (i < hours)
   say 'i = 'i
   if (domain = 'eu')
      'set lon -5.5 19.5'
      'set lat 35 56'
       endif
   if (domain = 'eu_4km')
      'set lon -3 17.5'
      'set lat 38.5 52'
       endif
   if (domain = 'switzerland')
      'set lon 2 14'
      'set lat 42 52'
       endif
   if (domain = 'ch_4km')
      'set lon 6 11'
      'set lat 45 48.5'
      endif
   'set mpdset hires'
   'set map 1 1 7'
   'set t 'i
   'q time'
   if (i = 1)
  runwrd=subwrd(result,3)
  cyc=substr(runwrd,1,2)
  say 'cyc = 'cyc
  rundate=substr(runwrd,4,2)
  runmo=substr(runwrd,6,3)
  runyear=substr(runwrd,9,4)
  'q files'
  runlin=sublin(result,1)
  say 'runlin = 'runlin
  runwrd=subwrd(runlin,4)
  runfile=substr(runwrd,1,10)
   endif
   'q time'
   fwrd=subwrd(result,3)
   fhr=substr(fwrd,1,2)
   fdate=substr(fwrd,4,2)
   fmo=substr(fwrd,6,3)
   fyear=substr(fwrd,9,4)
'set gxout shaded'
'set grads off'
'set rgb 31 230 255 225'
'set rgb 33 180 250 170'
'set rgb 35 120 245 115'
'set rgb 43 150 210 250'
'set rgb 46 60 150 245'
'set rgb 48 30 110 235'
'set rgb 49 238 39 17'
'set rgb 26 255 50 0'
'set rgb 28 192 0 0'
'set rgb 93 211 0 211'
'set rbcols 31 33 35 43 46 48 49 26 28 93'
   'd skip(UGRDmwl,1,2);VGRDmwl;mag(UGRDmwl,VGRDmwl)'
   'draw map'
   '/home/uwbe/uems/grads_scripts/xcbar -direction horizontal -edge triangle'
   '/home/uwbe/uems/grads_scripts/plot_cities_'dom
   ghr = i - 1
   'draw title \ 10m Wind (m/s) - WRF-EMS 'rundate' 'runmo' 'runyear'_'cyc' UTC \\ Valid: 'fdate' 'fmo' 'fyear'_'fhr' UTC'
   'set string 1 bl 2'
   'set strsiz 0.12 0.12'
    if (domain = 'eu') ; gtx="Europe 12km Grid" ; endif
    if (domain = 'eu_4km') ; gtx="Europe 4km Grid" ; endif
    if (domain = 'switzerland') ; gtx="Switzerland 12km Grid" ; endif
    if (domain = 'ch_4km') ; gtx="Switzerland 4km Grid" ; endif
   'draw string 0.4 0.25 'gtx
   'draw string 0.4 0.12 www.uwbeinternational.org - UwBe International Severe Weather Research'
   'set string -90 c 2'
   'set strsiz 0.12 0.12'
   'draw string 4 5.8 Copyright by UwBe International'
if (domain = 'ch_4km') ; imgsiz="x936 y1300" ; endif
if (domain = 'switzerland') ; imgsiz="x936 y1300" ; endif
if (domain = 'eu'); imgsiz="x936 y1300" ; endif
if (domain = 'eu_4km') ; imgsiz="x936 y1300" ; endif
if (ghr < 10)
   'printim /home/uwbe/uems/runs/'domain'/wrf_out/wind_10m/wind_10m_'runfile'f0'ghr'.png 'imgsiz' png white'
   else
   'printim /home/uwbe/uems/runs/'domain'/wrf_out/wind_10m/wind_10m_'runfile'f'ghr'.png 'imgsiz' png white'
   endif
   'clear'
   i = i + 1
endwhile
Maybe this Codes will help :)
System: Ubuntu 18.04.4 LTS - 40 x Intel(R) Xeon(R) CPU E5-2630 v4 @ 2.20GHz - 128GB RAM - 2.7TB HDD, 1TB SSD
www.uwbeinternational.org

Post Reply