[Dart-dev] [6529] DART/trunk/models/cam/shell_scripts/CESM_DART_config: This is the consolidation of the DART-related changes to a CESM case.

nancy at ucar.edu nancy at ucar.edu
Fri Oct 18 15:24:33 MDT 2013


Revision: 6529
Author:   thoar
Date:     2013-10-18 15:24:33 -0600 (Fri, 18 Oct 2013)
Log Message:
-----------
This is the consolidation of the DART-related changes to a CESM case.
This script is copied into the CASEROOT directory and subsequently executed.
It is REQUIRED to use this script as it modifies the CASE.run script
with the bits to relink the latest cam initial files to the expected static
filenames.

Added Paths:
-----------
    DART/trunk/models/cam/shell_scripts/CESM_DART_config

-------------- next part --------------
Added: DART/trunk/models/cam/shell_scripts/CESM_DART_config
===================================================================
--- DART/trunk/models/cam/shell_scripts/CESM_DART_config	                        (rev 0)
+++ DART/trunk/models/cam/shell_scripts/CESM_DART_config	2013-10-18 21:24:33 UTC (rev 6529)
@@ -0,0 +1,410 @@
+#!/bin/csh
+#
+# DART software - Copyright 2004 - 2013 UCAR. This open source software is
+# provided by UCAR, "as is", without charge, subject to all terms of use at
+# http://www.image.ucar.edu/DAReS/DART/DART_download
+#
+# DART $Id: CESM_DART_config 6392 2013-08-12 16:10:09Z thoar $
+
+# ---------------------
+# Purpose
+# ---------------------
+#
+# This script integrates DART with a pre-existing CESM multi-instance case.
+# It must be run from a valid CASEROOT directory. If the case was created
+# using one of the DART scripts, this script should be staged in the
+# CASEROOT directory automatically, and DARTROOT is set at that time.
+#
+# CAM is the only active model component.
+# CESM starts and stops to allow for CAM to assimilate every 6 hours.
+#
+# This script will build the DART executables if they are not found.
+#
+# There are many CESM binary files in big-endian format, and DART reads
+# some of them, so you MUST compile DART accordingly e.g.,
+# ifort -convert big_endian
+# Contact dart at ucar.edu if you want to use another compiler.
+#
+# ---------------------
+# How to set up the script
+# ---------------------
+#
+# -- Ensure DARTROOT references a valid DART directory.
+# -- Examine the whole script to identify things to change for your experiments.
+# -- Provide any initial files needed by your run:
+#       inflation
+#       sampling error correction
+# -- Run this script.
+# -- Edit the DART input.nml that appears in the ${CASEROOT} directory.
+# -- Submit the job using ${CASEROOT}/${CASE}.submit
+#
+# ==============================================================================
+# Get the environment of the case - defines number of instances/ensemble size ...
+# Each model component has their own number of instances, but the 'coupled'
+# DART parts is going to use the number of instances of CAM.
+# ==============================================================================
+
+if ( ! -e ./Tools/ccsm_getenv ) then
+   echo "ERROR: $0 must be run from a CASEROOT directory".
+   exit -1
+endif
+
+source ./Tools/ccsm_getenv
+
+set num_instances = $NINST_ATM
+
+# DARTROOT is set by the DART CESM_configure scripts. Under certain
+# situations, you may need to set this manually. It should reference the
+# base portion of the DART code tree.
+
+setenv DARTROOT  BOGUS_DART_ROOT_STRING
+
+# ==============================================================================
+# Some
+# ==============================================================================
+
+set nonomatch       # suppress "rm" warnings if wildcard does not match anything
+
+# The FORCE options are not optional.
+# The VERBOSE options are useful for debugging though
+# some systems don't like the -v option to any of the following
+switch ("`hostname`")
+   case be*:
+      # NCAR "bluefire"
+      set   MOVE = '/usr/local/bin/mv -fv'
+      set   COPY = '/usr/local/bin/cp -fv --preserve=timestamps'
+      set   LINK = '/usr/local/bin/ln -fvs'
+      set REMOVE = '/usr/local/bin/rm -fr'
+
+   breaksw
+   default:
+      # NERSC "hopper", NWSC "yellowstone"
+      set   MOVE = '/bin/mv -fv'
+      set   COPY = '/bin/cp -fv --preserve=timestamps'
+      set   LINK = '/bin/ln -fvs'
+      set REMOVE = '/bin/rm -fr'
+
+   breaksw
+endsw
+
+echo ""
+
+# ==============================================================================
+# make sure the required directories exist
+# VAR is the shell variable name, DIR is the value
+# ==============================================================================
+
+foreach VAR ( CASEROOT DARTROOT )
+   set DIR = `eval echo \${$VAR}`
+   if ( ! -d $DIR ) then
+      echo "ERROR: directory '$DIR' not found"
+      echo "       In the setup script check the setting of: $VAR"
+      exit -1
+   endif
+end
+
+# ==============================================================================
+# Make sure the DART executables exist or build them if we can't find them.
+# The DART input.nml in the model directory IS IMPORTANT during this part
+# because it defines what observation types are supported.
+# ==============================================================================
+
+foreach MODEL ( cam )
+   set targetdir = $DARTROOT/models/$MODEL/work
+   if ( ! -x $targetdir/filter ) then
+      echo ""
+      echo "WARNING: executable file 'filter' not found."
+      echo "         Looking for: $targetdir/filter "
+      echo "         Trying to rebuild all executables for $MODEL now ..."
+      (cd $targetdir; ./quickbuild.csh -mpi)
+      if ( ! -x $targetdir/filter ) then
+         echo "ERROR: executable file 'filter' not found."
+         echo "       Unsuccessfully tried to rebuild: $targetdir/filter "
+         echo "       Required DART assimilation executables are not found."
+         echo "       Stopping prematurely."
+         exit -1
+      endif
+   endif
+end
+
+# ==============================================================================
+# Stage the required parts of DART in the CASEROOT directory.
+# ==============================================================================
+
+# The standard CESM short-term archiving script may need to be altered
+# to archive additional or subsets of things, or to reduce the amount of
+# data that is sent to the long-term archive.  Put a version of st_archive.sh
+# in  ${DARTROOT}/models/CESM/shell_scripts when/if necessary
+
+if (            ! -e           Tools/st_archive.sh.original ) then
+   ${COPY} Tools/st_archive.sh Tools/st_archive.sh.original
+else
+   echo "Tools/st_archive.sh backup copy already exists."
+   echo ""
+endif
+
+${COPY} ${DARTROOT}/models/cam/shell_scripts/st_archive.sh       Tools/
+${COPY} ${DARTROOT}/models/cam/shell_scripts/no_assimilate.csh   .
+${COPY} ${DARTROOT}/models/cam/shell_scripts/assimilate.csh      .
+${COPY} ${DARTROOT}/models/cam/shell_scripts/perfect_model.csh   .
+${COPY} ${DARTROOT}/shell_scripts/shell_exit.sh                  .
+
+# ==============================================================================
+# Stage the DART executables in the CESM execution root directory: EXEROOT
+# If you recompile the DART code (maybe to support more observation types)
+# we're making a script to make it easy to install new DART executables.
+# ==============================================================================
+
+cat << EndOfText >! refresh_dart_files
+#!/bin/sh
+
+# this script copies over the dart executables and namelists to the
+# proper directory.  if you have to update any dart code or namelists,
+# do it in the $DARTROOT directory and then rerun refresh_dart_files
+# this script was autogenerated by $0
+# using the variables set in that script
+
+if [[ -e input.nml ]]; then
+   if [[ -e input.nml.original ]]; then
+      echo "input.nml.original already exists - not making another"
+   else
+      ${COPY} input.nml input.nml.original
+   fi
+fi
+
+${COPY} ${DARTROOT}/models/cam/work/cam_to_dart       ${EXEROOT}/.
+${COPY} ${DARTROOT}/models/cam/work/dart_to_cam       ${EXEROOT}/.
+${COPY} ${DARTROOT}/models/cam/work/filter            ${EXEROOT}/.
+${COPY} ${DARTROOT}/models/cam/work/perfect_model_obs ${EXEROOT}/.
+${COPY} ${DARTROOT}/models/cam/work/input.nml         ${CASEROOT}/.
+
+# The first time this is executed, the update namelist script does not exist.
+
+if [[ -x update_dart_namelists ]]; then
+       ./update_dart_namelists
+fi
+
+exit 0
+
+EndOfText
+chmod 0755 refresh_dart_files
+
+./refresh_dart_files
+
+# ==============================================================================
+# Ensure the DART namelists are consistent with the ensemble size,
+# suggest settings for num members in the output diagnostics files, etc.
+# The user is free to update these after setup and before running.
+# ==============================================================================
+
+cat << EndOfText >! update_dart_namelists
+#!/bin/sh
+
+# this script makes certain namelist settings consistent with the number
+# of ensemble members built by the setup script.
+# this script was autogenerated by $0
+# using the variables set in that script
+
+# Ensure that the input.nml ensemble size matches the number of instances.
+# WARNING: the output files contain ALL ensemble members ==> BIG
+
+ex input.nml <<ex_end
+g;ens_size ;s;= .*;= ${NINST_ATM};
+g;num_output_state_members ;s;= .*;= ${NINST_ATM};
+g;num_output_obs_members ;s;= .*;= ${NINST_ATM};
+wq
+ex_end
+
+exit 0
+
+EndOfText
+chmod 0755 update_dart_namelists
+
+./update_dart_namelists
+
+#=========================================================================
+# Stage the files needed for SAMPLING ERROR CORRECTION - even if not
+# initially requested. The file is static, small, and may be needed later.
+#
+# If it is requested and is not present ... it is an error.
+#
+# The sampling error correction is a lookup table.  Each ensemble size
+# has its own (static) file.  It is only needed if any
+# input.nml:&assim_tools_nml:sampling_error_correction = .true.,
+#=========================================================================
+
+set SAMP_ERR_FILE = ${DARTROOT}/system_simulation/final_full_precomputed_tables/final_full.${num_instances}
+if (  -e   ${SAMP_ERR_FILE} ) then
+   ${COPY} ${SAMP_ERR_FILE} .
+else
+   echo ""
+   echo "WARNING: no final_full.xx file found for an ensemble size of ${num_instances}."
+   echo "         This file is NOT needed unless you want to turn on the"
+   echo "         sampling_error_correction feature in any of the models."
+   echo "         To use it, in addition to setting the namelist to .true., cd to:"
+   echo "         ${DARTROOT}/system_simulation"
+   echo "         and create a final_full.${num_instances} file"
+   echo "         one can be generated for any ensemble size; see docs."
+   echo "         Copy it into ${CASEROOT} before running."
+   echo ""
+endif
+
+foreach N ( input.nml )
+   set  MYSTRING = `grep sampling_error_correction $N`
+   set  MYSTRING = `echo $MYSTRING | sed -e "s#[=,'\.]# #g"`
+   set  MYSTRING = `echo $MYSTRING | sed -e 's#"# #g'`
+   set SECSTRING = `echo $MYSTRING[2] | tr '[:upper:]' '[:lower:]'`
+
+   if ( ${SECSTRING} == true ) then
+      if ( ! -e  ${SAMP_ERR_FILE} ) then
+         echo "ERROR: no sampling error correction file for this ensemble size."
+         echo "ERROR: looking for ${SAMP_ERR_FILE} in"
+         echo "ERROR: ${DARTROOT}/system_simulation/final_full_precomputed_tables"
+         echo "ERROR: one can be generated for any ensemble size; see docs."
+         exit -3
+      endif
+   endif
+end
+
+# ==============================================================================
+# Initial setup for the default inflation scenario.
+# ==============================================================================
+# CAM usually uses adaptive state-space prior inflation. The initial settings
+# are in the filter_nml and ... during an assimilation experiment, the output
+# from one assimilation is the input for the next. To facilitate this operationally,
+# it is useful to specify an initial file of inflation values for the first
+# assimilation step. However, I can think of no general way to do this. The
+# utility that creates the initial inflation values (fill_inflation_restart)
+# needs the model size from model_mod. To get that, CAM needs a 'cam_phis.nc'
+# file which we generally don't have at this stage of the game (it exists after
+# a model advance). So ... until I think of something better ... I am making a
+# cookie file that indicates this is the very first assimilation. If this
+# cookie file exists, the assimilate.csh script will make the inflation restart
+# file before it performs the assimilation. After the first assimilation takes
+# place, the cookie file must be 'eaten' so that subsequent assimilations do not
+# overwrite whatever _should_ be there.
+
+date >! ${RUNDIR}/cam_inflation_cookie
+
+# ==============================================================================
+# Creating the code to add to the *.run script to call DART.
+# If there is one instance ... we MUST be running a perfect_model experiment.
+# If there are many instances ... we MUST be assimilating.
+# The number of instances dictates what DART script will be used.
+# ==============================================================================
+
+cat << "EndOfText" >! temp.$$
+
+# -------------------------------------------------------------------------
+# START OF DART: if CESM finishes correctly (pirated from ccsm_postrun.csh);
+# perform an assimilation with DART.
+
+set CplLogFile = `ls -1t cpl.log* | head -n 1`
+if ($CplLogFile == "") then
+   echo 'ERROR: Model did not complete - no cpl.log file present - exiting.'
+   echo 'ERROR: DART will not be attempted.'
+   setenv LSB_PJL_TASK_GEOMETRY "{(0)}"
+   setenv EXITCODE -1
+   mpirun.lsf ${CASEROOT}/shell_exit.sh
+   exit -1
+endif
+
+grep 'SUCCESSFUL TERMINATION' $CplLogFile
+if ( $status == 0 ) then
+   ${CASEROOT}/DARTSCRIPTNAME
+
+   if ( $status == 0 ) then
+      echo "`date` -- DART HAS FINISHED"
+   else
+      echo "`date` -- DART ERROR - ABANDON HOPE"
+      setenv LSB_PJL_TASK_GEOMETRY "{(0)}"
+      setenv EXITCODE -3
+      mpirun.lsf ${CASEROOT}/shell_exit.sh
+      exit -3
+   endif
+else
+   echo 'ERROR: Model did not complete successfully - exiting.'
+   echo 'ERROR: DART will not be attempted.'
+   setenv LSB_PJL_TASK_GEOMETRY "{(0)}"
+   setenv EXITCODE -2
+   mpirun.lsf ${CASEROOT}/shell_exit.sh
+   exit -2
+endif
+
+# END OF DART BLOCK
+# -------------------------------------------------------------------------
+"EndOfText"
+
+# modify the "here" document to call the logical DART script.
+
+if ( $num_instances == 1 ) then
+   sed -e "s#DARTSCRIPTNAME#perfect_model.csh#" < temp.$$ >! add_to_run.txt
+else
+   sed -e "s#DARTSCRIPTNAME#no_assimilate.csh#" < temp.$$ >! add_to_run.txt
+endif
+
+# Now that the "here" document is created,
+# determine WHERE to insert it -- ONLY IF it is not already there.
+
+grep "ABANDON HOPE" ${CASE}.run > /dev/null
+set STATUSCHECK = $status
+
+if ( ${STATUSCHECK} == 0 ) then
+   echo "DART block already present in ${CASE}.run"
+   echo ""
+else if ( ${STATUSCHECK} == 1 ) then
+   echo "Adding DART block to ${CASE}.run"
+   echo ""
+
+   set MYSTRING = `grep --line-number "CSM EXECUTION HAS FINISHED" ${CASE}.run`
+   set MYSTRING = `echo $MYSTRING | sed -e "s#:# #g"`
+
+   @ origlen = `cat ${CASE}.run | wc -l`
+   @ keep = $MYSTRING[1]
+   @ lastlines = $origlen - $keep
+
+   head -n $keep      ${CASE}.run    >! temp.$$
+   cat                add_to_run.txt >> temp.$$
+   tail -n $lastlines ${CASE}.run    >> temp.$$
+
+   ${MOVE} temp.$$ ${CASE}.run
+   ${REMOVE} add_to_run.txt
+
+else
+   echo "ERROR in grep of ${CASE}.run: aborting"
+   echo "status was ${STATUSCHECK}"
+   exit -6
+endif
+
+chmod 0744 ${CASE}.run
+
+# ==============================================================================
+# What to do next
+# ==============================================================================
+
+echo "Time to check the DART configuration:"
+echo ""
+echo "1) Modify what you need to in the DART namelists. These are "
+echo "   ${CASEROOT}/input.nml"
+echo ""
+echo "2) If you have recompiled any part of the DART system, 'refresh_dart_files'"
+echo "   will copy them into the correct places."
+echo ""
+echo "3) Make sure the observation directory names in assimilate.csh match"
+echo "   those on your system, and submit the CESM job in the normal way."
+echo ""
+echo "4) Inflation files? Observation files for the time of interest?"
+echo ""
+echo "5) Make sure the ${CASE}.run script calls 'assimilate.csh' if you desire."
+echo "   The default behavior is to _not_ invoke DART and simply run CESM."
+echo ""
+echo "6) You can use ${CASEROOT}/stage_cesm_files"
+echo "    to stage files to restart a run." 
+
+exit 0
+
+# <next few lines under version control, do not edit>
+# $URL: https://subversion.ucar.edu/DAReS/DART/trunk/models/CESM/shell_scripts/CESM_DART_config $
+# $Revision: 6392 $
+# $Date: 2013-08-12 10:10:09 -0600 (Mon, 12 Aug 2013) $
+


More information about the Dart-dev mailing list