[Dart-dev] [4158] DART/trunk/models/wrf/shell_scripts/advance_model.csh: Reworked by Josh Hacker, Ryan Torn, and Glen Romine to add function and

nancy at ucar.edu nancy at ucar.edu
Tue Nov 24 11:31:35 MST 2009


Revision: 4158
Author:   nancy
Date:     2009-11-24 11:31:35 -0700 (Tue, 24 Nov 2009)
Log Message:
-----------
Reworked by Josh Hacker, Ryan Torn, and Glen Romine to add function and
simplify the script.  It now supports a restart-file-per-member, simplifies
the time computations by using the advance_time executable, and handles
boundary files more cleanly.  Plus added many additional comments, and ways 
to select various options by setting shell variables at the top of the script.

Modified Paths:
--------------
    DART/trunk/models/wrf/shell_scripts/advance_model.csh

-------------- next part --------------
Modified: DART/trunk/models/wrf/shell_scripts/advance_model.csh
===================================================================
--- DART/trunk/models/wrf/shell_scripts/advance_model.csh	2009-11-23 23:25:24 UTC (rev 4157)
+++ DART/trunk/models/wrf/shell_scripts/advance_model.csh	2009-11-24 18:31:35 UTC (rev 4158)
@@ -1,4 +1,5 @@
 #!/bin/csh
+
 #
 # Data Assimilation Research Testbed -- DART
 # Copyright 2004-2007, Data Assimilation Research Section
@@ -11,21 +12,69 @@
 # $Revision$
 # $Date$
 
-# Standard script for use in assimilation applications
+# Shell script to run the WRF model from DART input.
 # where the model advance is executed as a separate process.
 
-# This script copies the necessary files into the temporary directory
-# for a model run. It assumes that there is ${CENTRALDIR}/WRF directory
-# where boundary conditions files reside.
+# This script performs the following:
+# 1.  Creates a temporary directory to run a WRF realization (see options)
+# 2.  Copies or links the necessary files into the temporary directory
+# 3.  Converts DART state vectors to wrf input
+# 4.  Updates LBCs (optionally draws perturbations from WRF-Var random covariances)
+# 5.  Writes a WRF namelist from a template
+# 6.  Runs WRF
+# 7.  Checks for incomplete runs
+# 8.  Converts wrf output to DART state vectors
 
-# If the ensemble mean assim_model_state_ic_mean is present in the CENTRALDIR,
-# it is converted to a WRF netCDF format.
-# It is then used in update_wrf_bc the calculate the deviation from the mean.
+# NOTES:
+# 1.  This version executes da_wrfvar.exe in serial (no mpirun)
+# 2.  If the ensemble mean assim_model_state_ic_mean is present in the 
+# $CENTRALDIR, it is converted to a WRF netCDF format.
+# It is then used in update_wrf_bc to calculate the deviation from the mean.
 # This deviation from the mean is then added at the end of the interval to
 # calculate new boundary tendencies. The magnitude of the perturbation added
 # at the end of the interval is controlled by infl. The purpose is to increase
 # time correlation at the lateral boundaries.
 
+# POSSIBLE TODO
+# 1.  modularization?  
+# 2.  error checking all over
+
+# this next section could be somewhere else in some docs.  If so
+# reference is needed ("for more information about how to run this, see ...")
+
+#-----snip--------------
+
+#-------------------------------------------------------
+# Dependencies (user responsibility)
+#-------------------------------------------------------
+# REQUIRED:
+# 1. advance_time (from DART), located in your $CENTRALDIR
+# 2. one of either (da_wrfvar.exe and pert_wrf_bc) or update_wrf_bc if you 
+# want to run real-data cases with specified LBCs.  Elaborated below.
+# 3. directory $CENTRALDIR/WRF_RUN_DATA containing all the WRF run-time files
+# (typically files with data for the physics: LANDUSE.TBL, RRTM_DATA, etc
+# but also anything else you want to link into the wrf-run directory.  If
+# using WRF-Var then be.dat should be in there too.
+# 4. wrf.exe, located in your $CENTRALDIR 
+# 5. A wrfinput_d01 file in your $CENTRALDIR.  
+# 6. namelist.input in your $CENTRALDIR for use as a template.  This file 
+# should include the WRF-Var namelists if you are using WRF-Var (v3.1++ required).
+#
+# OPTIONAL:
+# ####EITHER 1 or 2 is required for specified LBC runs
+# 1.  da_wrfvar.exe (version 3.1 or later) and pert_wrf_bc in your $CENTRALDIR.
+# In this case you also need be.dat (the be.dat.cv3 file from the WRF-Var 
+# distribution) in your $CENTRALDIR/WRF_RUN_DATA, and WRF-Var namelists in 
+# your $CENTRALDIR/namelist.input
+# 2.  update_wrf_bc in your $CENTRALDIR for using pre-existing LBC files. Pre-existing LBC files should live in $CENTRALDIR/WRF
+
+# File naming conventions:
+#  mean wrfinput - wrfinput_d0X_${gday}_${gsec}_mean
+#  mean wrfbdy - wrfbdy_d01_${gday}_${gsec}_mean
+#  wrfbdy members - wrfbdy_d01_${gday}_${gsec}_${member}
+
+#-----snip--------------
+
 # Arguments are the process number of caller, the number of state copies
 # belonging to that process, and the name of the filter_control_file for
 # that process
@@ -33,26 +82,81 @@
 set num_states = $2
 set control_file = $3
 
-set      myname = $0
-set  CENTRALDIR = ..
+# Setting to 1 saves output files from the ensemble mean only, while setting to
+# larger numbers will save all member output files <= to this value
+set save_ensemble_member = 0
+set delete_temp_dir = true
 
-# Get unique name for temporary working directory for this process's stuff
-set temp_dir = 'advance_temp'${process}
+# set this to true if you want to maintain complete individual wrfinput/output
+# for each member (to carry through non-updated fields)
+set individual_members = false
 
-set days_in_month = ( 31 28 31 30 31 30 31 31 30 31 30 31 )
-   
-set REMOVE = '/bin/rm -rf'
-set   COPY = 'cp -p'
-set   MOVE = 'mv -f'
-   
+# next line ensures that the last cycle leaves everything in the temp dirs
+if ( $individual_members == true ) set delete_temp_dir = false
+
+set  myname = $0
+set  CENTRALDIR = `pwd`
+set  WRFOUTDIR  = ${CENTRALDIR}/WRFOUT
+set  REMOVE = '/bin/rm -rf'
+set    COPY = '/bin/cp -p'
+set    MOVE = '/bin/mv -f'
+set      LN = '/bin/ln -sf'
+unalias cd
+unalias ls
+
+# if process 0 go ahead and check for dependencies here
+if ( $process == 0 ) then
+
+   if ( ! -x ${CENTRALDIR}/advance_time ) then
+     echo ABORT\: advance_model.csh could not find required executable dependency ${CENTRALDIR}/advance_time
+     exit 1
+   endif
+
+   if ( ! -d WRF_RUN_DATA ) then
+      echo ABORT\: advance_model.csh could not find required data directory ${CENTRALDIR}/WRF_RUN_DATA, which contains all the WRF run-time input files
+      exit 1
+   endif
+
+   if ( ! -x ${CENTRALDIR}/da_wrfvar.exe ) then
+     echo
+     echo WARNING\: advance_model.csh could not find optional executable dependency ${CENTRALDIR}/da_wrfvar.exe
+     echo
+     if ( ! -x update_wrf_bc ) then
+        echo ABORT\: advance_model.csh could not find required executable dependency ${CENTRALDIR}/update_wrf_bc
+        exit 1
+     endif
+
+   else
+
+     echo
+     echo WARNING\: da_wrfvar.exe found, using it to update LBCs on the fly
+     echo
+     if ( ! -x pert_wrf_bc ) then
+        echo ABORT\: advance_model.csh could not find required executable dependency ${CENTRALDIR}/pert_wrf_bc
+        exit 1
+     endif
+     if ( ! -r ${CENTRALDIR}/WRF_RUN_DATA/be.dat ) then
+        echo ABORT\: advance_model.csh could not find required readable dependency ${CENTRALDIR}/WRF_RUN_DATA/be.dat
+        exit 1
+     endif
+     if ( ! -e ${CENTRALDIR}/bc_pert_scale ) then
+        echo WARNING\:  using default VAR covariance scales
+     endif
+
+   endif
+
+endif # process 0 dependency checking
+
+# set this flag here for all processes so we don't have to keep checking
+if ( -x ${CENTRALDIR}/da_wrfvar.exe ) then
+   set USE_WRFVAR = 1
+else
+   set USE_WRFVAR = 0
+endif
+
 # give the filesystem time to collect itself
 sleep 5
 
-# Create a clean temporary directory and go there
-\rm -rf  $temp_dir
-mkdir -p $temp_dir
-cd       $temp_dir
-
 # Each parallel task may need to advance more than one ensemble member.
 # This control file has the actual ensemble number, the input filename,
 # and the output filename for each advance.  Be prepared to loop and
@@ -61,150 +165,111 @@
 set ensemble_member_line = 1
 set input_file_line = 2
 set output_file_line = 3
+
 while($state_copy <= $num_states)
 
-   set ensemble_member = `head -$ensemble_member_line ../$control_file | tail -1`
-   set input_file      = `head -$input_file_line      ../$control_file | tail -1`
-   set output_file     = `head -$output_file_line     ../$control_file | tail -1`
+   set ensemble_member = `head -$ensemble_member_line ${CENTRALDIR}/${control_file} | tail -1`
+   set input_file      = `head -$input_file_line      ${CENTRALDIR}/${control_file} | tail -1`
+   set output_file     = `head -$output_file_line     ${CENTRALDIR}/${control_file} | tail -1`
 
+   set infl = 0.0
 
-   set element = $ensemble_member
-   
-   set infl = 0.0
-   
-   # Shell script to run the WRF model from DART input.
-   # where the model advance is executed as a separate process.
-   
-   echo "starting ${myname} for ens member $element at "`date`
-   echo "CENTRALDIR is ${CENTRALDIR}"
-   echo "temp_dir is ${temp_dir}"
-   
-   
-   # Copy or link the required files to the temp directory
-   
-   ln -sf ${CENTRALDIR}/input.nml .
- 
-   ln -sf ${CENTRALDIR}/CAM_ABS_DATA .
-   ln -sf ${CENTRALDIR}/CAM_AEROPT_DATA .
-   ln -sf ${CENTRALDIR}/ETAMPNEW_DATA .
-   ln -sf ${CENTRALDIR}/ETAMPNEW_DATA_DBL .
-   ln -sf ${CENTRALDIR}/GENPARM.TBL .
-   ln -sf ${CENTRALDIR}/grib2map.tbl .
-   ln -sf ${CENTRALDIR}/gribmap.txt .
-   ln -sf ${CENTRALDIR}/LANDUSE.TBL .
-   ln -sf ${CENTRALDIR}/ozone.formatted .
-   ln -sf ${CENTRALDIR}/ozone_lat.formatted .
-   ln -sf ${CENTRALDIR}/ozone_plev.formatted .
-   ln -sf ${CENTRALDIR}/RRTM_DATA .
-   ln -sf ${CENTRALDIR}/RRTM_DATA_DBL .
-   ln -sf ${CENTRALDIR}/SOILPARM.TBL .
-   ln -sf ${CENTRALDIR}/tr49t67 .
-   ln -sf ${CENTRALDIR}/tr49t85 .
-   ln -sf ${CENTRALDIR}/tr67t85 .
-   # WRF versions before and including V3.0.1.1 use urban_param.tbl,    
-   # V3.1 uses URBPARM.TBL - link to either that are found.)
-   if ( -e ${CENTRALDIR}/urban_param.tbl ) then
-      ln -sf ${CENTRALDIR}/urban_param.tbl .
+   #  create a new temp directory for each member unless requested to keep and it exists already
+   set temp_dir = "advance_temp${ensemble_member}"
+
+   if ( ( -d $temp_dir ) & ( $individual_members == "true" ) ) then
+
+      cd $temp_dir
+      set rmlist = ( `ls | grep -v wrfinput_d0?` )
+      ${REMOVE} $rmlist
+
+   else
+
+      ${REMOVE} $temp_dir >& /dev/null
+      mkdir -p $temp_dir
+      cd $temp_dir
+
+      ${COPY} ${CENTRALDIR}/wrfinput_d0? .
+
    endif
-   if ( -e ${CENTRALDIR}/URBPARM.TBL ) then
-      ln -sf ${CENTRALDIR}/URBPARM.TBL .
-   endif
-   ln -sf ${CENTRALDIR}/VEGPARM.TBL .
-   ln -sf ${CENTRALDIR}/wrf.exe .
-   
-   # nfile is required when using mpi to run wrf.exe
-   # nfile is machine specific; ideally, it should be
-   # constructed by the script advance_ens.csh
-   
+
+   # link WRF-runtime files (required) and be.dat (if using WRF-Var)
+   ${LN} ${CENTRALDIR}/WRF_RUN_DATA/*  .
+
+   # link DART namelist
+   ${LN} ${CENTRALDIR}/input.nml       .
+
+   # link WRF executable
+   ${LN} ${CENTRALDIR}/wrf.exe         .
+
+   # nfile is required when using MPICH to run wrf.exe
+   # nfile is machine specific.  Not needed on all platforms
+
    hostname >! nfile
    hostname >>! nfile
-   ###ln -s  ${CENTRALDIR}/nfile$element nfile
-   ${COPY} ${CENTRALDIR}/wrfinput_d0? .
-                      # Provides auxilliary info not avail. from DART state vector
-   
-   if (  -e ${CENTRALDIR}/assim_model_state_ic_mean ) then
-      ln -sf ${CENTRALDIR}/assim_model_state_ic_mean dart_wrf_vector
+
+   # if a mean state ic file exists convert it to a wrfinput_mean netcdf file
+   if ( -e ${CENTRALDIR}/assim_model_state_ic_mean ) then
+      ${LN} ${CENTRALDIR}/assim_model_state_ic_mean dart_wrf_vector
       ${CENTRALDIR}/dart_to_wrf >&! out.dart_to_wrf_mean
       ${COPY} wrfinput_d01 wrfinput_mean
+      ${REMOVE} wrf.info dart_wrf_vector
    endif
-   
-   ${MOVE} ${CENTRALDIR}/$input_file dart_wrf_vector # ICs for run
-   
-   # Convert DART to wrfinput
-   
+
+   # ICs for this wrf run; Convert DART file to wrfinput netcdf file
+   ${MOVE} ${CENTRALDIR}/${input_file} dart_wrf_vector 
    ${CENTRALDIR}/dart_to_wrf >&! out.dart_to_wrf
-   
    ${REMOVE} dart_wrf_vector
-   
+
    # The program dart_to_wrf has created the file wrf.info.
    # Time information is extracted from wrf.info.
-   
+   # (bc in the following few lines is the calculator program,
+   # not boundary conditions.)
+
    set secday = `head -1 wrf.info`
    set targsecs = $secday[1]
    set targdays = $secday[2]
    set targkey = `echo "$targdays * 86400 + $targsecs" | bc`
-   
+
    set secday = `head -2 wrf.info | tail -1`
    set wrfsecs = $secday[1]
    set wrfdays = $secday[2]
    set wrfkey = `echo "$wrfdays * 86400 + $wrfsecs" | bc`
-   
-   # If model blew up in the previous cycle, the member is now likely an outlier.
-   # Set infl = 0. to avoid further deterioration of the ensemble member.
-   
-   if ( -e ${CENTRALDIR}/blown_${wrfdays}_${wrfsecs}.out ) then
-      set MBLOWN = `cat ${CENTRALDIR}/blown_${wrfdays}_${wrfsecs}.out`
-      set NBLOWN = `cat ${CENTRALDIR}/blown_${wrfdays}_${wrfsecs}.out | wc -l`
-      set BLOWN = 0
-      set imem = 1
-      while ( $imem <= $NBLOWN )
-         if ( $MBLOWN[$imem] == $element ) then
-            set BLOWN = `expr $BLOWN \+ 1`
-         endif
-         set imem = `expr $imem \+ 1`
-      end
-      if ( $BLOWN > 0 ) then
-         set infl = 0.0
-      endif
-   endif
-   
+
    # Find all BC's file available and sort them with "keys".
    # NOTE: this needs a fix for the idealized wrf case in which there are no
    # boundary files (also same for global wrf).  right now some of the
    # commands below give errors, which are ok to ignore in the idealized case
    # but it is not good form to generate spurious error messages.
-   
-   #--1st, check if LBCs are "specified" (in which case wrfbdy files are req'd)
-   set SPEC_BC = `grep specified ${CENTRALDIR}/namelist.input | grep true | cat | wc -l`
-   
-   if ($SPEC_BC > 0) then
-      ls ${CENTRALDIR}/WRF/wrfbdy_*_$element >! bdy.list
-   else
-      echo ${CENTRALDIR}/WRF/wrfbdy_${targdays}_${targsecs}_$element >! bdy.list
+
+   # check if LBCs are "specified" (in which case wrfbdy files are req'd)
+   # and we need to set up a key list to manage target times
+   set SPEC_BC = `grep specified ${CENTRALDIR}/namelist.input | grep true | wc -l`
+
+   if ( $SPEC_BC > 0 ) then
+
+      if ( $USE_WRFVAR ) then
+         set bdyfiles = `ls ${CENTRALDIR}/WRF/wrfbdy_d01_*_mean`
+      else
+         set bdyfiles = `ls ${CENTRALDIR}/WRF/wrfbdy_d01_*_${ensemble_member} | grep -v mean`
+      endif
+
+      set keylist = ()
+      foreach f ( $bdyfiles )
+	 set day = `echo $f | awk -F_ '{print $(NF-2)}'`
+	 set sec = `echo $f | awk -F_ '{print $(NF-1)}'`
+         set key = `echo "$day * 86400 + $sec" | bc`
+         set keylist = ( $keylist $key )
+      end
+
+      set keys = `echo $keylist | sort`
+
+   else  #  idealized WRF with non-specified BCs
+
+      set keys = ( $targkey )
+
    endif
-   
-   echo ${CENTRALDIR}/WRF/wrfbdy_ >! str.name
-   sed 's/\//\\\//g' < str.name >! str.name2
-   set STRNAME = `cat str.name2`
-   set COMMAND = s/`echo ${STRNAME}`//
-   
-   sed $COMMAND < bdy.list >! bdy.list2
-   sed 's/_/ /g' < bdy.list2 >! bdy.list
-   set num_files = `cat bdy.list | wc -l`
-   set items = `cat bdy.list`
-   set ifile = 1
-   set iday = 1
-   set isec = 2
-   if ( -e keys ) ${REMOVE} keys
-   while ( $ifile <= $num_files )
-      set key = `echo "$items[$iday] * 86400 + $items[$isec]" | bc`
-      echo $key >>! keys
-      set ifile = `expr $ifile \+ 1`
-      set iday = `expr $iday \+ 3`
-      set isec = `expr $isec \+ 3`
-   end
-   set keys = `sort keys`
-   
+
    set cal_date    = `head -3 wrf.info | tail -1`
    set START_YEAR  = $cal_date[1]
    set START_MONTH = $cal_date[2]
@@ -212,236 +277,266 @@
    set START_HOUR  = $cal_date[4]
    set START_MIN   = $cal_date[5]
    set START_SEC   = $cal_date[6]
-   
-   set END_YEAR    = $cal_date[1]
-   set END_MONTH   = $cal_date[2]
-   set END_DAY     = $cal_date[3]
-   set END_HOUR    = $cal_date[4]
-   set END_MIN     = $cal_date[5]
-   set END_SEC     = $cal_date[6]
-   
+
+   set START_STRING = ${START_YEAR}-${START_MONTH}-${START_DAY}_${START_HOUR}:${START_MIN}:${START_SEC}
+
    set MY_NUM_DOMAINS    = `head -4 wrf.info | tail -1`
    set ADV_MOD_COMMAND   = `head -5 wrf.info | tail -1`
-   
-   if ( `expr $END_YEAR \% 4` == 0 ) then
-      set days_in_month[2] = 29
-   endif
-   if ( `expr $END_YEAR \% 100` == 0 ) then
-      if ( `expr $END_YEAR \% 400` == 0 ) then
-         set days_in_month[2] = 29
-      else
-         set days_in_month[2] = 28
-      endif
-   endif
-   
-   set ifile = 1
+
    # Find the next BC's file available.
-   
+
+   @ ifile = 1
    while ( $keys[${ifile}] <= $wrfkey )
-      if ($ifile < $num_files ) then
-         set ifile = `expr $ifile \+ 1`
+      if ( $ifile < $#bdyfiles ) then
+         @ ifile ++
       else
          echo No boundary file available to move beyond
-         echo ${START_YEAR}-${START_MONTH}-${START_DAY}_${START_HOUR}:${START_MIN}:${START_SEC}
-         exit
+         echo $START_STRING
+         exit 1
       endif
    end
-   
+
    ###############################################################
    # Advance the model with new BC until target time is reached. #
    ###############################################################
-   
+
    while ( $wrfkey < $targkey )
-   
+
       set iday = `echo "$keys[$ifile] / 86400" | bc`
       set isec = `echo "$keys[$ifile] % 86400" | bc`
-   
-      # Copy the boundary condition file to the temp directory.
-   
-      ${COPY} ${CENTRALDIR}/WRF/wrfbdy_${iday}_${isec}_$element wrfbdy_d01
-   
-      #${COPY} ${CENTRALDIR}/WRF/wrflowinp_d01_${iday}_${isec} wrflowinp_d01
-   
+
+      # Copy the boundary condition file to the temp directory if needed.
+      if ( $SPEC_BC > 0 ) then
+
+         if ( $USE_WRFVAR ) then
+            ${COPY} ${CENTRALDIR}/WRF/wrfbdy_d01_${iday}_${isec}_mean               wrfbdy_d01
+         else
+            ${COPY} ${CENTRALDIR}/WRF/wrfbdy_d01_${iday}_${isec}_${ensemble_member} wrfbdy_d01
+         endif
+
+      endif
+
       if ( $targkey > $keys[$ifile] ) then
          set INTERVAL_SS = `echo "$keys[$ifile] - $wrfkey" | bc`
       else
          set INTERVAL_SS = `echo "$targkey - $wrfkey" | bc`
       endif
-      set RUN_HOURS   = `expr $INTERVAL_SS \/ 3600`
-      set REMAIN      = `expr $INTERVAL_SS \% 3600`
-      set RUN_MINUTES = `expr $REMAIN \/ 60`
-      set RUN_SECONDS = `expr $REMAIN \% 60`
+
       set INTERVAL_MIN = `expr $INTERVAL_SS \/ 60`
-   
-      set END_SEC = `expr $END_SEC \+ $INTERVAL_SS`
-      while ( `expr $END_SEC - 60` >= 0 )
-         set END_SEC = `expr $END_SEC \- 60`
-         set END_MIN = `expr $END_MIN \+ 1`
-         if ( `expr $END_MIN - 60` >= 0 ) then
-            set END_MIN = `expr $END_MIN \- 60`
-            set END_HOUR = `expr $END_HOUR \+ 1`
+
+      set END_STRING = `echo ${START_STRING} ${INTERVAL_SS}s -w | ${CENTRALDIR}/advance_time`
+      set END_YEAR  = `echo $END_STRING | cut -c1-4`
+      set END_MONTH = `echo $END_STRING | cut -c6-7`
+      set END_DAY   = `echo $END_STRING | cut -c9-10`
+      set END_HOUR  = `echo $END_STRING | cut -c12-13`
+      set END_MIN   = `echo $END_STRING | cut -c15-16`
+      set END_SEC   = `echo $END_STRING | cut -c18-19`
+
+      # Update boundary conditions.
+      # WARNING: da_wrfvar.exe will only work correctly if running WRF V3.1 or later!
+      # If it is found in the central dir, use it to regnerate perturbed boundary files
+      # Otherwise, do the original call to update_wrf_bc
+      if ( $USE_WRFVAR ) then
+
+         #  Set the covariance perturbation scales using file or default values
+         if ( -e ${CENTRALDIR}/bc_pert_scale ) then
+            set pscale = `head -1 ${CENTRALDIR}/bc_pert_scale | tail -1`
+            set hscale = `head -2 ${CENTRALDIR}/bc_pert_scale | tail -1`
+            set vscale = `head -3 ${CENTRALDIR}/bc_pert_scale | tail -1`
+            set autoc  = `head -4 ${CENTRALDIR}/bc_pert_scale | tail -1`
+         else
+            set pscale = 0.25
+            set hscale = 1.0
+            set vscale = 1.5
+            set autoc = 0.0
          endif
-         if ( `expr $END_HOUR - 24` >= 0 ) then
-            set END_HOUR = `expr $END_HOUR \- 24`
-            set END_DAY  = `expr $END_DAY \+ 1`
+         @ iseed2 = $ensemble_member * 10000
+
+         ${REMOVE} script.sed
+         cat >! script.sed << EOF
+            /analysis_date/c\
+            analysis_date = \'${END_STRING}.0000\',
+            /as1/c\
+            as1 = ${pscale}, ${hscale}, ${vscale},
+            /as2/c\
+            as2 = ${pscale}, ${hscale}, ${vscale},
+            /as3/c\
+            as3 = ${pscale}, ${hscale}, ${vscale},
+            /as4/c\
+            as4 = ${pscale}, ${hscale}, ${vscale},
+            /as5/c\
+            as5 = ${pscale}, ${hscale}, ${vscale},
+            /seed_array1/c\
+            seed_array1 = ${END_YEAR}${END_MONTH}${END_DAY}${END_HOUR},
+            /seed_array2/c\
+            seed_array2 = $iseed2,
+            /start_year/c\
+            start_year = ${END_YEAR},
+            /start_month/c\
+            start_month = ${END_MONTH},
+            /start_day/c\
+            start_day = ${END_DAY},
+            /start_hour/c\
+            start_hour = ${END_HOUR},
+            /start_minute/c\
+            start_minute = ${END_MIN},
+            /start_second/c\
+            start_second = ${END_SEC},
+            /end_year/c\
+            end_year = ${END_YEAR},
+            /end_month/c\
+            end_month = ${END_MONTH},
+            /end_day/c\
+            end_day = ${END_DAY},
+            /end_hour/c\
+            end_hour = ${END_HOUR},
+            /end_minute/c\
+            end_minute = ${END_MIN},
+            /end_second/c\
+            end_second = ${END_SEC},
+EOF
+# The EOF on the line above MUST REMAIN in column 1.
+
+         sed -f script.sed ${CENTRALDIR}/namelist.input >! namelist.input
+         ${LN} ${CENTRALDIR}/WRF/wrfinput_d01_${targdays}_${targsecs}_mean ./fg
+         ${CENTRALDIR}/da_wrfvar.exe >>&! out.wrfvar
+         if ( -e rsl.out.0000 ) cat rsl.out.0000 >> out.wrfvar
+
+         ${MOVE} wrfvar_output wrfinput_next
+         ${LN} wrfinput_d01 wrfinput_this
+         ${LN} wrfbdy_d01 wrfbdy_this
+
+         # if wrfinput_mean file found, rename it
+         if ( -e wrfinput_mean ) then
+            ${MOVE} wrfinput_mean   wrfinput_this_mean
+            ${MOVE} fg              wrfinput_next_mean
          endif
-         if ( `expr $END_DAY - $days_in_month[$END_MONTH]` > 0 ) then
-            set END_DAY = 1
-            set END_MONTH = `expr $END_MONTH \+ 1`
-         endif
-         if ( `expr $END_MONTH - 12` > 0 ) then
-            set END_MONTH = 1
-            set END_YEAR  = `expr $END_YEAR \+ 1`
-   
-            if ( `expr $END_YEAR \% 4` == 0 ) then
-               set days_in_month[2] = 29
-            endif
-            if ( `expr $END_YEAR \% 100` == 0 ) then
-               if ( `expr $END_YEAR \% 400` == 0 ) then
-                  set days_in_month[2] = 29
-               else
-                  set days_in_month[2] = 28
-               endif
-            endif
-   
-         endif
-      end
-   
-      set END_SEC = `expr $END_SEC \+ 100`
-      set END_SEC = `echo $END_SEC | cut -c2-3`
-      set END_MIN = `expr $END_MIN \+ 100`
-      set END_MIN = `echo $END_MIN | cut -c2-3`
-      set END_HOUR = `expr $END_HOUR \+ 100`
-      set END_HOUR = `echo $END_HOUR | cut -c2-3`
-      set END_DAY = `expr $END_DAY \+ 100`
-      set END_DAY = `echo $END_DAY | cut -c2-3`
-      set END_MONTH = `expr $END_MONTH \+ 100`
-      set END_MONTH = `echo $END_MONTH | cut -c2-3`
-   
-   #-----------------------------------------------------------------------
-   # Update time control entries in the WRF namelist.input:
-   #-----------------------------------------------------------------------
-   
-   ${REMOVE} script.sed
-   cat >! script.sed << EOF
-    /run_hours/c\
-    run_hours                  = ${RUN_HOURS}
-    /run_minutes/c\
-    run_minutes                = ${RUN_MINUTES}
-    /run_seconds/c\
-    run_seconds                = ${RUN_SECONDS}
-    /start_year/c\
-    start_year                 = ${START_YEAR}, ${START_YEAR}, ${START_YEAR}
-    /start_month/c\
-    start_month                = ${START_MONTH}, ${START_MONTH}, ${START_MONTH}
-    /start_day/c\
-    start_day                  = ${START_DAY}, ${START_DAY}, ${START_DAY}
-    /start_hour/c\
-    start_hour                 = ${START_HOUR}, ${START_HOUR}, ${START_HOUR}
-    /start_minute/c\
-    start_minute               = ${START_MIN}, ${START_MIN}, ${START_MIN}
-    /start_second/c\
-    start_second               = ${START_SEC}, ${START_SEC}, ${START_SEC}
-    /end_year/c\
-    end_year                   = ${END_YEAR}, ${END_YEAR}, ${END_YEAR}
-    /end_month/c\
-    end_month                  = ${END_MONTH}, ${END_MONTH}, ${END_MONTH}
-    /end_day/c\
-    end_day                    = ${END_DAY}, ${END_DAY}, ${END_DAY}
-    /end_hour/c\
-    end_hour                   = ${END_HOUR}, ${END_HOUR}, ${END_HOUR}
-    /end_minute/c\
-    end_minute                 = ${END_MIN}, ${END_MIN}, ${END_MIN}
-    /end_second/c\
-    end_second                 = ${END_SEC}, ${END_SEC}, ${END_SEC}
-# set history interval equal to run interval to make sure you have
-# a wrfoutput file at the end of the run interval
- /history_interval/c\
- history_interval           = ${INTERVAL_MIN}, ${INTERVAL_MIN}, ${INTERVAL_MIN}
-#  dart_to_wrf is expecting only a single time per file
- /frames_per_outfile/c\
- frames_per_outfile         = 1, 1, 1,
+
+         echo $autoc | ${CENTRALDIR}/pert_wrf_bc >&! out.pert_wrf_bc
+         ${REMOVE} wrfinput_this wrfinput_next wrfbdy_this
+         if ( -e wrfinput_this_mean ) ${REMOVE} wrfinput_this_mean wrfinput_next_mean
+
+      else  # Update boundary conditions from existing wrfbdy files
+
+         echo $infl | ${CENTRALDIR}/update_wrf_bc >&! out.update_wrf_bc
+
+      endif
+
+      ${REMOVE} script.sed namelist.input
+      cat >! script.sed << EOF
+         /run_hours/c\
+         run_hours                  = 0,
+         /run_minutes/c\
+         run_minutes                = 0,
+         /run_seconds/c\
+         run_seconds                = ${INTERVAL_SS},
+         /start_year/c\
+         start_year                 = ${MY_NUM_DOMAINS}*${START_YEAR},
+         /start_month/c\
+         start_month                = ${MY_NUM_DOMAINS}*${START_MONTH},
+         /start_day/c\
+         start_day                  = ${MY_NUM_DOMAINS}*${START_DAY},
+         /start_hour/c\
+         start_hour                 = ${MY_NUM_DOMAINS}*${START_HOUR},
+         /start_minute/c\
+         start_minute               = ${MY_NUM_DOMAINS}*${START_MIN},
+         /start_second/c\
+         start_second               = ${MY_NUM_DOMAINS}*${START_SEC},
+         /end_year/c\
+         end_year                   = ${MY_NUM_DOMAINS}*${END_YEAR},
+         /end_month/c\
+         end_month                  = ${MY_NUM_DOMAINS}*${END_MONTH},
+         /end_day/c\
+         end_day                    = ${MY_NUM_DOMAINS}*${END_DAY},
+         /end_hour/c\
+         end_hour                   = ${MY_NUM_DOMAINS}*${END_HOUR},
+         /end_minute/c\
+         end_minute                 = ${MY_NUM_DOMAINS}*${END_MIN},
+         /end_second/c\
+         end_second                 = ${MY_NUM_DOMAINS}*${END_SEC},
+         /history_interval/c\
+         history_interval           = ${MY_NUM_DOMAINS}*${INTERVAL_MIN},
+         /frames_per_outfile/c\
+         frames_per_outfile         = ${MY_NUM_DOMAINS}*1,
+         /max_dom/c\
+         max_dom                    = ${MY_NUM_DOMAINS},
 EOF
-   
-    sed -f script.sed \
-       ${CENTRALDIR}/namelist.input >! namelist.input
-   
-   # Update boundary conditions
-   
-      echo $infl | ${CENTRALDIR}/update_wrf_bc >&! out.update_wrf_bc
-   
-      if ( -e rsl.out.integration ) then
-         ${REMOVE} rsl.*
-      endif
-   
+# The EOF on the line above MUST REMAIN in column 1.
+
+      sed -f script.sed ${CENTRALDIR}/namelist.input >! namelist.input
+
+      #-------------------------------------------------------------
+      #
+      # HERE IS A GOOD PLACE TO GRAB FIELDS FROM OTHER SOURCES
+      # AND STUFF THEM INTO YOUR wrfinput_d0? FILES
+      #
+      #------------------------------------------------------------
+
+      # clean out any old rsl files
+      if ( -e rsl.out.integration )  ${REMOVE} rsl.*
+
       # run WRF here
       ${ADV_MOD_COMMAND} >>&! rsl.out.integration
-      ${COPY} rsl.out.integration ${CENTRALDIR}/wrf.out_${targdays}_${targsecs}_${element}  
-      sleep 1
-   
-      set SUCCESS = `grep "wrf: SUCCESS COMPLETE WRF" rsl.* | cat | wc -l`
+
+      if ( -e rsl.out.0000 ) cat rsl.out.0000 >> rsl.out.integration
+      ${COPY} rsl.out.integration ${WRFOUTDIR}/wrf.out_${targdays}_${targsecs}_${ensemble_member}
+#      sleep 1
+
+      set SUCCESS = `grep "wrf: SUCCESS COMPLETE WRF" rsl.out.integration | cat | wc -l`
       if ($SUCCESS == 0) then
-         echo $element >>! ${CENTRALDIR}/blown_${targdays}_${targsecs}.out
+         echo $ensemble_member >>! ${CENTRALDIR}/blown_${targdays}_${targsecs}.out
          echo "Model failure! Check file " ${CENTRALDIR}/blown_${targdays}_${targsecs}.out
-         echo "for a list of failed elements, and check here for the individual output files:"
-         echo " ${CENTRALDIR}/wrf.out_${targdays}_${targsecs}_elementnumber  "
+         echo "for a list of failed ensemble_members, and check here for the individual output files:"
+         echo " ${CENTRALDIR}/wrf.out_${targdays}_${targsecs}_${ensemble_member}  "
          exit -1
       endif
 
-      if ( -e ${CENTRALDIR}/extract ) then
-         if ( $element == 1 ) then
-            ls wrfout_d0${MY_NUM_DOMAINS}_* >! wrfout.list
-            if ( -e ${CENTRALDIR}/psfc.nc ) then
-               ${COPY} ${CENTRALDIR}/psfc.nc .
-            endif
-            echo `cat wrfout.list | wc -l` | ${CENTRALDIR}/extract
-            ${MOVE} psfc.nc ${CENTRALDIR}/.
-         endif
-      endif
-   
       set dn = 1
       while ( $dn <= $MY_NUM_DOMAINS )
-         ${MOVE} wrfout_d0${dn}_${END_YEAR}-${END_MONTH}-${END_DAY}_${END_HOUR}:${END_MIN}:${END_SEC} wrfinput_d0${dn}
-         set dn = `expr $dn \+ 1`
+         if ( $ensemble_member <= $save_ensemble_member ) ${COPY} wrfout_d0${dn}_${END_STRING} ${WRFOUTDIR}/wrfout_d0${dn}_${END_STRING}_${ensemble_member}
+         ${MOVE} wrfout_d0${dn}_${END_STRING} wrfinput_d0${dn}
+         @ dn ++
       end
-   
+
       ${REMOVE} wrfout*
-   
+
       set START_YEAR  = $END_YEAR
       set START_MONTH = $END_MONTH
       set START_DAY   = $END_DAY
       set START_HOUR  = $END_HOUR
       set START_MIN   = $END_MIN
       set START_SEC   = $END_SEC
-      set wrfkey = $keys[$ifile]
-      set ifile = `expr $ifile \+ 1`
-   
+      set wrfkey      = $keys[$ifile]
+      @ ifile ++
+
    end
-   
+
    ##############################################
    # At this point, the target time is reached. #
    ##############################################
-   
+
    # create new input to DART (taken from "wrfinput")
    ${CENTRALDIR}/wrf_to_dart >&! out.wrf_to_dart
-   
-   ${MOVE} dart_wrf_vector ${CENTRALDIR}/$output_file
+   ${MOVE} dart_wrf_vector ${CENTRALDIR}/${output_file}
 
-   set state_copy = `expr $state_copy \+ 1`
-   set ensemble_member_line = `expr $ensemble_member_line \+ 3`
-   set input_file_line = `expr $input_file_line \+ 3`
-   set output_file_line = `expr $output_file_line \+ 3`
-end
+   cd $CENTRALDIR
 
+   #  delete the temp directory for each member if desired
+   if ( $delete_temp_dir == 'true' )  ${REMOVE} ${temp_dir}
+   echo "Ensemble Member $ensemble_member completed"
 
+   # and now repeat the entire process for any other ensemble member that
+   # needs to be advanced by this task.
+   @ state_copy ++
+   @ ensemble_member_line += 3
+   @ input_file_line += 3
+   @ output_file_line += 3
 
-# Change back to working directory and get rid of temporary directory
-cd ${CENTRALDIR}
-echo ${REMOVE} ${temp_dir}
-${REMOVE} ${temp_dir}
+end
 
-# Remove the filter_control file to signal completeion
+# Remove the filter_control file to signal completion
 # Is there a need for any sleeps to avoid trouble on completing moves here?
-\rm -rf $control_file
+${REMOVE} $control_file
 
+exit 0
 


More information about the Dart-dev mailing list