#!/bin/bash set -x ###################################################################################### #Define variables used for the call of the MARS retrieval scripts ###################################################################################### START_YEAR=2015 # Start year of your simulation START_MONTH=01 # Start month of your simulation START_DAY=01 # Start day of your simulation START_HOUR=00 # Start hour of your simulation FORECAST_LENGTH="30" # Length of the forcast cycle in hours, e.g. 30 hours LAST_YEAR=2015 # Final end year of your simulation LAST_MONTH=01 # Final end month of your simulation LAST_DAY=31 # Final end day of your simulation FIRST_DATE=${START_YEAR}${START_MONTH}${START_DAY} # Start of the loop (first day simulation, usually you do not need to change this) LOOP_START_DAY=01 #Calculation of the end loop (calculates total number of days that will be simulated) LOOP_END_DAY=` expr $"(( $(date --date="$LAST_YEAR$LAST_MONTH$LAST_DAY" +%s) - $(date --date="$START_YEAR$START_MONTH$START_DAY" +%s) ))/(60*60*24) + 1"|bc ` ######################################################################################## # # create start and stop dates for the WRF NWP simulation # ###################################################################################### ## Now loop over days to automatise the work## while [ ${LOOP_START_DAY} -le ${LOOP_END_DAY} ] do INITIAL_DATE=${START_YEAR}${START_MONTH}${START_DAY} # Necessary afterward for organizing and naming folders for your outputs INITIAL_HOUR=${START_HOUR} # Necessary afterward for organizing and naming folders for your outputs # Calculate STOP time (STOP_YEAR, STOP_DAY, STOP_MONTH, STOP_HOUR) after running one cycle (e.g. 30 hours) # if you have e.g. 30 forecast length, then STOP DATE will be the following day and STOP HOUR will be 6 UTC INITIAL_DATE=${START_YEAR}${START_MONTH} # Initial date necessary for organising folders where you will put your outputs MONTH_DAYS=` cal $START_MONTH $START_YEAR | xargs | awk '{print $NF}' ` #Calculates number of days per selected month STOP_HOUR=0`expr $FORECAST_LENGTH - 24` #Calculates the hour at which the forecast stops after one forecast cycle if [ ${START_DAY} -lt ${MONTH_DAYS} ] #If a day is within a month then STOP_DAY=`expr $START_DAY + 1` STOP_MONTH=$START_MONTH STOP_YEAR=$START_YEAR elif [ ${START_MONTH} -eq 12 ] && [ ${START_DAY} -eq ${MONTH_DAYS} ] #If a day is the last day in a year then STOP_DAY=1 STOP_MONTH=01 STOP_YEAR=`expr $START_YEAR + 1` elif [ ${START_DAY} -eq ${MONTH_DAYS} ] #If a day is the last day in a month then STOP_DAY=1 STOP_MONTH=0`expr $START_MONTH + 1` STOP_YEAR=$START_YEAR fi #Adding zero before number if [ ${STOP_DAY} -lt 10 ] then STOP_DAY=0${STOP_DAY} fi ##################################################################################### # Define variables used to fill the namelist file "namelist.input" # # ***************** READ THIS CAREFULLY BEFORE YOU START!!!!!********************* # ##################################################################################### MAX_DOM=1 # Number of WRF model domains ################################################################################ #The entries were calculated above for the namelist.input ################################################################################ S_YEAR="${START_YEAR}, ${START_YEAR}" # This is an example for 2 domains. If you have S_MONTH="${START_MONTH}, ${START_MONTH}" # more domains, you have to adjust this: S_DAY="${START_DAY}, ${START_DAY}" # Insert comma separated list for the different S_HOUR="${START_HOUR}, ${START_HOUR}" # domains. The variables has to be replaced E_YEAR="${STOP_YEAR}, ${STOP_YEAR}" # by numbers when start and stop shall be E_MONTH="${STOP_MONTH}, ${STOP_MONTH}" # different for the different domains. E_DAY="${STOP_DAY}, ${STOP_DAY}" # E_HOUR="${STOP_HOUR}, ${STOP_HOUR}" # ################################################################################ # Create data directory and working directory ################################################################################ WRKDIR=/lustre/cray/ws7/ws/ipmspa-SABLE-0/NWP_MODE_WRF371/ # Your working directory (usually it is WRFV3/run where you run WRF) DATADIR=/lustre/cray/ws7/ws/ipmspa-SABLE-0/MET_EM_NWP_MODE/ # Directory where you have MET_EM files OUTPUT=/lustre/cray/ws7/ws/ipmspa-SABLE-0/NWP_MODE_WRF371/${INITIAL_DATE}${INITIAL_HOUR} # Directory where you want to put your output files # Test whether the directories exist. Create if not the case. This will be changed in # a way, that an existing directory is automatically deleted and recreated when # everything is working. #test -d ${WRKDIR} || mkdir ${WRKDIR} #test -d ${DATADIR} || mkdir ${DATADIR} test -d ${OUTPUT} || mkdir ${OUTPUT} ############################################################################# ## Create namelist ## Adjust the namelist as you want ############################################################################# cd ${WRKDIR} # Enter the working directory cat > namelist.input < mail_message # If failed message sent to your email /usr/bin/mail -s "NWP MODE REAL failed" j.milovac@uni-hohenheim.de < mail_message # Send an info to your mail exit 1 fi # Change SOIL data in the WRF input file to keep it continuous if [ ${INITIAL_DATE} -ne ${FIRST_DATE} ] # If it is not the first date with which you intialise the NWP simulation then ncl change_wrfinput.ncl mv wrfout_wrfinput_d01 ${OUTPUT} mv wrfout_wrfinput_d02 ${OUTPUT} fi # remove old files rm -f rsl.* ####################################### ## run WRF.EXE once at the beginning ####################################### cd ${WRKDIR} # Starting real using start_real.sh script that you need to create for HRLS WRF_job_pid_orig=`qsub start_wrf.sh` WRF_job_pid=${WRF_job_pid_orig%.hornet-batch.hww.de} #check if the job is still running echo "Job WRF ID= " $WRF_job_pid sleep 60 while [ 1 = 1 ] do sleep 30 qout=`qstat | grep $WRF_job_pid` || break echo $qout | grep -q " C " && break done # Checking if the job is finished with success or not if grep "SUCCESS COMPLETE WRF" rsl.error.0000 then echo "wrf final ok" # If the job finished successfully, rename wrfout file at 00 UTC next day to wrfout_date_wrfinput_d0x necessary for keeping the soil vailables continuous! # Notice, the number of these files corresponds to the number of domains!!! cp wrfout_d01_${STOP_YEAR}-${STOP_MONTH}-${STOP_DAY}_00_00_00 wrfout_wrfinput_d01 cp wrfout_d02_${STOP_YEAR}-${STOP_MONTH}-${STOP_DAY}_00_00_00 wrfout_wrfinput_d02 else echo "RUN_WRF_EXE failed, exiting" echo "RUN_WRF_EXE failed" > mail_message /usr/bin/mail -s "MYNN WRF.EXE failed for "${START_YEAR}${START_MONTH}${START_DAY} jmilovac@uni-hohenheim.de < mail_message exit 1 fi # Moving all necessary files to your OUTPUT folder and removing the nonnecessary ones mv wrfout_d0* ${OUTPUT} mv wrfinput_d0* ${OUTPUT} mv wrflowinp_d0* ${OUTPUT} mv wrfbdy_d0* ${OUTPUT} mv wrfrst_d0* ${OUTPUT} rm -f rsl.* rm -f met_em* ########################################## # Change to the next day ########################################## LOOP_START_DAY=`expr $LOOP_START_DAY + 1 ` if [ ${START_DAY} -lt ${MONTH_DAYS} ] #If a day is within a month then START_DAY=`expr $START_DAY + 1` START_MONTH=$START_MONTH START_YEAR=$START_YEAR elif [ ${START_MONTH} -eq 12 ] && [ ${START_DAY} -eq ${MONTH_DAYS} ] #If a day is the last day in a year then START_DAY=1 START_MONTH=01 START_YEAR=`expr $START_YEAR + 1` elif [ ${START_DAY} -eq ${MONTH_DAYS} ] #If a day is the last day in a month then START_DAY=1 START_MONTH=0`expr $START_MONTH + 1` START_YEAR=$START_YEAR fi if [ ${START_DAY} -lt 10 ] then START_DAY=0${START_DAY} fi done