#!/bin/bash # run this after a new inner nest is made. # new_domanin DOMAINNAME # usage new_domain DOMAINNAME # This script will create all needed directories for DOMAINNAME and DOMAINNAME-WINDOW and populate them with the correct files to run RASP # You will be left to edit the rasp.run.parameters.DOMAINNAME.TEMPLATE to have it run as you want it to. # The purpose is to create a domain without a window in wrf_tools and then let the script do everything else. # If no argument is given, the script relies on the most recently created domain in $BASEDIR/WRF/wrfsi/domains/ # being the one you want to work on. # # The script checks for a correctly set up environment including trustit=1 #controls whether there are opportunities to abort. set to 0 for pauses if [[ -z $BASEDIR || -z $EXT_DATAROOT || -z $SOURCE_ROOT || -z $INSTALLROOT || -z $GEOG_DATAROOT || -z $DATAROOT || -z $NCARG_ROOT || -z $NETCDF || -z $NCL_COMMAND ]] then echo "BASEDIR=$BASEDIR" echo "EXT_DATAROOT=$EXT_DATAROOT" echo "SOURCE_ROOT=$SOURCE_ROOT" echo "INSTALLROOT=$INSTALLROOT" echo "GEOG_DATAROOT=$GEOG_DATAROOT" echo "DATAROOT=$DATAROOT" echo "NCARG_ROOT=$NCARG_ROOT" echo "NETCDF=$NETCDF" echo "NCL_COMMAND=$NCL_COMMAND" echo " " echo "You need to set all the above variables in your environment" echo "To make it always available put lines like 'export BASEDIR=/home/myaccount/DRJACK' into your .bashrc file." echo " " echo "Run this script immediately after creating a new domain and localizing it using the wrf_tools program." echo " " exit fi if [ -d $BASEDIR/WRF/wrfsi/domains/$1 ] then NEWDOMAIN=$1 else if [ -z $BASEDIR ] then echo "You need to set BASEDIR in your environment" echo "To make it always available but the line 'export BASEDIR=/home/myaccount/DRJACK' into your .bashrc file." echo "Run this script immediately after creating a new domain and localizing it using the wrf_tools program." exit fi fi if [ ! -z $1 ] then NEWDOMAIN=$1 else NEWDOMAIN="" fi cd $BASEDIR/WRF/wrfsi echo "$BASEDIR is the BASEDIR being used for this setup." echo "$1 is the domain --> $newdomain being acted on." # you can hardcode your favorite editor here if [ ! -z $(grep "^.*TIME_STEP.*6f.*WINDOW" $BASEDIR/RASP/RUN/rasp.pl) ] then echo "You appear to have an older version fo the rasp.pl script. Please download a new one to save us all headaches." echo "You could just edit it according to the directions on the RASP wiki..." exit fi if [ -z $EDITOR ] then echo "You don't have any EDITOR in you environment. Please set EDITOR to your favorite editor" exit fi myeditor=$EDITOR ## actually run the qui tool as part of new domain cd $BASEDIR/WRF/wrfsi echo "$NEWDOMAIN is the domain that will be worked on now before wrf_tools." ## make sure the environment is set if not use these defaults (edit to suit) # this assumes the environment contains the needed variables. # wrf_tools ## this makes the new directory if they didn't already. #use tail to find it after running wrftools echo "$NEWDOMAIN is the domain that will be worked on now after wrf_tools." # if no newdomain passed, find the name of the one most recently created if [[ -z $NEWDOMAIN ]] then NEWDOMAIN=$(ls -rt domains |tail -1) fi echo "You should have just run the GUI for $NEWDOMAIN" echo " If that is not correct, type control-C now" echo " " if [ -z $NEWDOMAIN ] then echo " You must edit wrf.nl and wrfsi.nl to make them" echo " consistent with the RASP scripts." echo " run this script with the name of your favorite editor as a parameter" exit fi echo $NEWDOMAIN pwd #echo "Files will be edited using $myeditor" if [[ $trustit -ne 1 ]]; then echo "sleeping still OK?";sleep 10s;fi cd $BASEDIR/WRF/wrfsi/domains/$NEWDOMAIN/static/ ## these are the typical edits needed. Just brute force replace them. ## FIRST IN THE DOMAIN pwd if [[ $trustit -ne 1 ]]; then echo "sleeping still OK?";sleep 5s;fi if [ ! -e wrfsi.nl.original ] then cp wrfsi.nl wrfsi.nl.original; fi if [ ! -e wrf.nl.original ] then cp wrf.nl wrf.nl.original fi echo "wrf.nl and wrfsi.nl as created by gui preserved with extension .original" if [[ $trustit -ne 1 ]]; then echo "sleeping still OK?";sleep 3s;fi ## make moad_delta's 3 decimal places #|sed -e 's#\(MOAD_DELTA_X = \)\([0-9][1-9]\)\(000\)#\1\2\3.000#g' cat wrfsi.nl |sed \ -e 's#\(MOAD_DELTA_X = \)\([0-9][1-9]\)\(000\)#\1\2\3.000#g'\ -e 's#\(MOAD_DELTA_Y = \)\([0-9][1-9]\)\(000\)#\1\2\3.000#g' \ -e '/MOAD_DELTA_X/,/MOAD_DELTA_Y/ s#\(\.000\.000\),#\.000,#g' \ -e 's/NUM_DOMAINS = 3/NUM_DOMAINS = 2/' >wrfsi.tmp # sed -e '/MOAD_DELTA_X/,/MOAD_DELTA_Y/ s#\([0-9]000\),#\1.000,#g' -e 's#000.,#000.000,#g' \ cat wrfsi.tmp |sed -e 's/NUM_ACTIVE_SUBNESTS = .*,/NUM_ACTIVE_SUBNESTS = 1,/g' >wrfsi.nl grep -i moad wrfsi.nl if [[ $trustit -ne 1 ]]; then echo "sleeping still OK?";sleep 5s;fi #wrf.nl max_dom dy dx assume they are starting with 18 12 6 using ratio of three so get either 0, .3 or .7 cat wrf.nl| sed -e '/dx/,/dy/ s#33.3,#33.333,#g' \ -e '/dx/,/dy/ s#\([0-9]00\),#\1.000,#g' \ -e '/dx/,/dy/ s#\(\.000\.000\),#\.000,#g' \ -e ' /dx/,/dy/ s#66.7,#66.667,#g' >wrf.tmp cat wrf.tmp |sed -e 's/max_dom = .*$/max_dom = 2/g' \ -e 's/NUM_DOMAINS = 3/NUM_DOMAINS = 2/'\ -e 's/SPECIFIED =.*$/SPECIFIED = .true.,.false.,.false.,/' >wrf.nl # possible but not mandatory TJ uses it near Mt Baker WA glacier problems. sed -i.bak 's/IFSNOW.*$/IFSNOW = 0,/' wrf.nl echo "just fixed $NEWDOMAIN wrf.nl and wrfsi.nl" if [[ $trustit -ne 1 ]]; then echo "sleeping still OK?";sleep 3s;fi #echo "make sure that the initial versions of the namelist file, wrf.nl has proper parameters" #echo "SPECIFIED should be = .true.,.false.,.false.," #echo "delta and MOAD_DELTA should be the same precision (highest)in the files wrf.nl and wrfsi.nl " #grep -i moad_delta $BASEDIR/WRF/wrfsi/domains/$1/static/wrfsi.nl #egrep -i 'max_dom | ACTIVE |dx| dy |SPECIFIED |' $BASEDIR/WRF/wrfsi/domains/$NEWDOMAIN/static/wrf.nl #echo " Opening editor on wrf.nl so you can fix it." #if [[ $trustit -ne 1 ]]; then echo "sleeping still OK?";sleep 3s;fi #$myeditor wrf.nl #echo " now edit wrfsi.nl to match what you just edited" #if [[ $trustit -ne 1 ]]; then echo "sleeping still OK?";sleep 3s;fi #$myeditor wrfsi.nl echo "Create $NEWDOMAIN output directories under $BASEDIR/WRF/WRFV2/RASP/ .. . ignore file exists errors" mkdir $BASEDIR/WRF/WRFV2/RASP/$NEWDOMAIN cp -dp $BASEDIR/WRF/WRFV2/RASP/em_real_linksonly/* $BASEDIR/WRF/WRFV2/RASP/$NEWDOMAIN echo "Creating new directories for $NEWDOMAIN OUTPUT images" mkdir $BASEDIR/RASP/HTML/$NEWDOMAIN echo "Created $BASEDIR/RASP/HTML/$NEWDOMAIN" mkdir $BASEDIR/RASP/HTML/$NEWDOMAIN/FCST echo "Created $BASEDIR/RASP/HTML/$NEWDOMAIN/FCST" mkdir $BASEDIR/RASP/RUN/OUT/$NEWDOMAIN mkdir $BASEDIR/RASP/RUN/OUT/$NEWDOMAIN-WINDOW echo "Created $BASEDIR/RASP/RUN/OUT/$NEWDOMAIN and $NEWDOMAIN-WINDOW" echo " " echo " " if [[ $trustit -ne 1 ]]; then echo "sleeping still OK?";sleep 3s;fi # copy the MOAD wrf.nl as namelist.template ##cp $BASEDIR/WRF/wrfsi/domains/$NEWDOMAIN/static/wrf.nl $BASEDIR/WRF/WRFV2/RASP/$NEWDOMAIN/namelist.template # create windows cd $BASEDIR/WRF/wrfsi/domains/$NEWDOMAIN ## THEN IN THE WINDOW pwd echo "Now going to creat WINDOW for wrfsi/domains/$NEWDOMAIN" if [[ $trustit -ne 1 ]]; then echo "sleeping still OK?";sleep 5s;fi echo " " echo " " echo "running $BASEDIR/WRF/UTIL/create_directory.wrfsi_window.pl" $BASEDIR/WRF/UTIL/create_directory.wrfsi_window.pl if [[ $trustit -ne 1 ]]; then echo "sleeping still OK?";sleep 3s;fi echo " " echo " " cd $BASEDIR/WRF/wrfsi/domains/$NEWDOMAIN-WINDOW/static pwd echo "fixing MOAD_DELTA_X MOAD_DELTA_Y in $BASEDIR/WRF/wrfsi/domains/$NEWDOMAIN-WINDOW/static/wrfsi.nl" if [[ $trustit -ne 1 ]]; then echo "sleeping still OK?";sleep 2s;fi cat wrfsi.nl |sed -e 's#\(MOAD_DELTA_X = \)\([0-9][1-9]\)\(000\)#\1\2\3.000#g'\ -e 's#\(MOAD_DELTA_Y = \)\([0-9][1-9]\)\(000\)#\1\2\3.000#g' \ -e 's/NUM_DOMAINS = 3/NUM_DOMAINS = 2/' >wrfsi.tmp # sed -e '/MOAD_DELTA_X/,/MOAD_DELTA_Y/ s#\([0-9]000\),#\1.000,#g' -e 's#000.,#000.000,#g' \ cat wrfsi.tmp |sed -e 's/NUM_ACTIVE_SUBNESTS = .*,/NUM_ACTIVE_SUBNESTS = 1,/g' >wrfsi.nl echo " MOAD_DELTA_X MOAD_DELTA_Y in $BASEDIR/WRF/wrfsi/domains/$NEWDOMAIN-WINDOW/static/wrfsi.nl are now:" grep -i moad wrfsi.nl #wrf.nl max_dom dy dx assume they are using ratio of three so get either 0, .3 or .7 #cat wrf.nl| sed -e '/dx/,/dy/ s#33.3,#33.333,#g' -e 's#\([0-9]000\),#\1.000,#g' -e 's#000.,#000.000,#g' -e 's#6.7,#6.667,#g' >wrf.tmp #cat wrf.tmp |sed -e 's/max_dom = .*$/max_dom = 2/g' >wrf.nl #sed -i.bak 's/SPECIFIED =.*$/SPECIFIED = .true., .false.,.false.,/' wrf.nl # possible but not mandatory TJ uses it near Mt Baker WA glacier problems. #sed -i.bak 's/IFSNOW.*$/IFSNOW = 0,/ wrf.nl' cp $BASEDIR/WRF/wrfsi/domains/$NEWDOMAIN/static/wrf.nl $BASEDIR/WRF/WRFV2/RASP/$NEWDOMAIN/namelist.template echo "Now going to creat WINDOW for output $BASEDIR/WRF/WRFV2/RASP/$NEWDOMAIN" cd $BASEDIR/WRF/WRFV2/RASP/$NEWDOMAIN $BASEDIR/WRF/UTIL/create_directory.wrf_window.pl echo "namelist.template files have been installed as follows" find $BASEDIR -wholename "*$NEWDOMAIN*namelist.template" if [[ $trustit -ne 1 ]]; then echo "sleeping still OK?";sleep 2s;fi echo "*********************************Starting Checks on problem parameters **********************************" echo "max_dom in wrf.nl should equal NUM_DOMAINS in wrfsi.nl and should be only 2, not 3 for a windowed run." echo " " grep -i max_dom $BASEDIR/WRF/wrfsi/domains/$NEWDOMAIN/static/wrf.nl grep -i NUM_DOMAINS $BASEDIR/WRF/wrfsi/domains/$NEWDOMAIN/static/wrfsi.nl echo " " echo " " echo " NUM_ACTIVE_SUBNETS Must be 1 \(even for a windowed run\)" echo " " grep -i NUM_ACTIVE_SUBNESTS $BASEDIR/WRF/wrfsi/domains/$NEWDOMAIN/static/wrfsi.nl echo " " echo "deltas should be the same precision in both files and in both namelist.template files" grep -i moad_delta $BASEDIR/WRF/wrfsi/domains/$NEWDOMAIN/static/wrfsi.nl echo "in $BASEDIR/WRF/wrfsi/domains/$NEWDOMAIN/static/wrfsi.nl" egrep -i 'dx| dy ' $BASEDIR/WRF/wrfsi/domains/$NEWDOMAIN/static/wrf.nl echo "in $BASEDIR/WRF/wrfsi/domains/$NEWDOMAIN/static/wrf.nl " egrep -i 'dx| dy ' $BASEDIR/WRF/WRFV2/RASP/$NEWDOMAIN/namelist.template echo "in $BASEDIR/WRF/WRFV2/RASP/$NEWDOMAIN-WINDOW/namelist.template " egrep -i 'dx| dy ' $BASEDIR/WRF/WRFV2/RASP/$NEWDOMAIN-WINDOW/namelist.template echo "RUN_HOURS should be = 0" grep RUN_HOURS $BASEDIR/WRF/wrfsi/domains/$NEWDOMAIN/static/wrf.nl grep RUN_HOURS $BASEDIR/WRF/WRFV2/RASP/$NEWDOMAIN/namelist.template grep RUN_HOURS $BASEDIR/WRF/WRFV2/RASP/$NEWDOMAIN-WINDOW/namelist.template echo " " echo " " echo "SPECIFIED should be = .true.,.false.,.false.," grep SPECIFIED $BASEDIR/WRF/wrfsi/domains/$NEWDOMAIN/static/wrf.nl grep SPECIFIED $BASEDIR/WRF/WRFV2/RASP/$NEWDOMAIN/namelist.template grep SPECIFIED $BASEDIR/WRF/WRFV2/RASP/$NEWDOMAIN-WINDOW/namelist.template echo " " echo " If you are in an area where snow lingers at higher elevations into the spring you may want to set IFSNOW=0 in the namelist.templates." echo " There should be 52 levels, that seems to be OK these days. " echo " " echo " If the above didn't check out, run postwindownewchecks after fixing the offending parts by manually editing the non-matched files " #pushd $BASEDIR/RASP/RUN echo "now in $(pwd)" echo "copying the rasp.run.parameters.PANOCHE.TEMPLATE as rasp.run.parameters.$NEWDOMAIN.TEMPLATE with PANOCHE replaced by $NEWDOMAIN cat rasp.run.parameters.PANOCHE.TEMPLATE |sed -e "s#PANOCHE#$NEWDOMAIN#g" > rasp.run.parameters.$NEWDOMAIN.TEMPLATE #echo " Now run the following command in this directory" #echo " cp rasp.run.parameters.PANOCHE rasp.run.parameters.$NEWDOMAIN" echo " You should edit rasp.run.parameters.$NEWDOMAIN to make any desired changes." #echo " Globally replace PANOCHE with $NEWDOMAIN in the file rasp.run.parameters.$NEWDOMAIN " echo " Be careful with the timing of runs and with the time step variable. " #edit $BASEDIR/RASP/RUN/rasp.run.parameters.$NEWDOMAIN.TEMPLATE #popd echo "You are now set up with the following environment variables." echo "BASEDIR=$BASEDIR" echo "EXT_DATAROOT=$EXT_DATAROOT" echo "SOURCE_ROOT=$SOURCE_ROOT" echo "INSTALLROOT=$INSTALLROOT" echo "GEOG_DATAROOT=$GEOG_DATAROOT" echo "DATAROOT=$DATAROOT" echo "NCARG_ROOT=$NCARG_ROOT" echo "NETCDF=$NETCDF" echo "NCL_COMMAND=$NCL_COMMAND" echo "" echo "EDITOR= $EDITOR" echo "MAIL= $MAIL" echo "HOME= $HOME" echo "COLORTERM= $COLORTERM" echo " " echo "To run the model for $NEWDOMAIN, the domain you just created" echo "cd to $BASEDIR/RASP/RUN " echo "cp rasp.run.parameters.$NEWDOMAIN.TEMPLATE rasp.run.parameters.$NEWDOMAIN " echo " " echo " edit rasp.run.parameters.$NEWDOMAIN to set your desired times and parameters" echo " " echo " then issue the command# run.rasp $NEWDOMAIN & echo " wait patiently. Or watch the printout with # tail -f rasp.$(echo $NEWDOMAIN | tr "[A-Z]" "[a-z]").printout " echo " note: control-c exits tail."