Skip to content

Commit

Permalink
some organization of drive-dates code in land spinup
Browse files Browse the repository at this point in the history
  • Loading branch information
zarzycki committed Mar 1, 2024
1 parent ca588ee commit 8f2c969
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 44 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ perturb.*.nl
nl.landspinup*
!nl.landspinup.pm-cpu
!nl.landspinup.derecho
nl_dd.*

## Model namelists
user_nl_cam
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,31 @@
#!/bin/bash

set -e
source ../utils.sh

### Set vars here for now
datesfile="dates.CHEY.VR28.NATL.REF.CAM5.4CLM5.0.dtime900.txt"
CASEDIR="/global/homes/c/czarzyck/I-runs/ne128pg2-spinup_19840101_0000"
path_to_rundir="/pscratch/sd/c/czarzyck/e3sm_scratch/pm-cpu/ne128pg2-spinup_19840101_0000/run"
CIMEsubstring=""
CIMEbatchargs=""
betacast="/global/homes/c/czarzyck/betacast"
WALLCLOCK="02:00:00"
RUNQUEUE="regular"
# Copy this last restart to a stash folder
DIRSTASH=/global/cfs/cdirs/m2637/E3SM_SCREAM_files/finidat/ne128pg2/CHEY.VR28.NATL.REF.CAM5.4CLM5.0.dtime900/

#--------

cd $betacast/land-spinup/

NAMELISTFILE=$1

source ../../utils.sh

# Read the namelist
read_bash_nl "${NAMELISTFILE}"

# Build relevant directories
CASEDIR=$CASESRC/$CASENAME
PATH_TO_RUNDIR=$BASERUN/$CASENAME/run/
SCRIPTDIR=$BETACAST/land-spinup/drive-dates/

echo $CASEDIR
echo $PATH_TO_RUNDIR
echo $SCRIPTDIR

## Set defaults
## Set these in your namelistfile if need to
if [ -z "${CIMEsubstring+x}" ]; then CIMEsubstring=""; fi
if [ -z "${CIMEbatchargs+x}" ]; then CIMEbatchargs=""; fi

## Get to this directory
cd $SCRIPTDIR

# Parse dates file
echo "Using dates in: "${datesfile}
longdate=$(get_top_line_from_dates "${datesfile}")
Expand All @@ -31,15 +39,15 @@ cd $CASEDIR
./xmlchange --force JOB_QUEUE=${RUNQUEUE}
./xmlchange REST_OPTION="end"
./xmlchange STOP_DATE="$yearstr$monthstr$daystr"
run_CIME2 "$path_to_rundir" "$CIMEsubstring" "$CIMEbatchargs" true
run_CIME2 "$PATH_TO_RUNDIR" "$CIMEsubstring" "$CIMEbatchargs" true

# Assuming run_CIME2 was successful, let's set CONTINUE_RUN to TRUE
# this is because for a cold start we want FALSE, but every other run is TRUE
# So there is no harm in doing this as long as the first run succeeds.
./xmlchange CONTINUE_RUN=TRUE

# Copy restart files to some directory for stashing purposes
cd $path_to_rundir
cd $PATH_TO_RUNDIR

# Assuming run was succesful, delete all other restarts except the last one
delete_except_last "*.clm2.r.*,*.elm.r.*,*.elm.rh0.*,*.elm.rh1.*"
Expand All @@ -48,32 +56,11 @@ delete_except_last "*.cpl.r.*"

echo "Done with delete_except_last"

## Make stash directories if they don't exist
if [ ! -d "$DIRSTASH" ]; then mkdir -v "$DIRSTASH"; fi
if [ ! -d "$DIRSTASH/logs/" ]; then mkdir -v "$DIRSTASH/logs/"; fi

function safe_cp2() {

local dest="$2"
# split on multiple input patterns if necessary
IFS=',' read -r -a patterns <<< "$1"

# Loop over all matching patterns
for pattern in "${patterns[@]}"; do

# Trim leading and trailing spaces from the pattern
pattern=$(echo "$pattern" | xargs)

# Collect all files matching the pattern, sorted
files=($(ls $pattern 2>/dev/null | sort))

if [ ${#files[@]} -eq 0 ]; then
echo "Error: ZERO files found matching pattern $pattern."
else
cp -v -- "${files[@]}" "$dest"
fi
done
}

## Copy relevant files over to dirstash, compress any uncompressed, and cleanup
safe_cp2 "*.clm2.r.*,*.elm.r.*" $DIRSTASH
safe_cp2 "*.mosart.r.*" $DIRSTASH
for file in $DIRSTASH/*.nc; do
Expand All @@ -84,8 +71,8 @@ mv -fv *tar.gz $DIRSTASH/logs/
rm -fv *.bin

# Return to the script dir to do things and resubmit
cd $betacast/land-spinup/
cd $SCRIPTDIR
remove_top_line_from_dates ${datesfile}

echo "*-*-*-* Automatically resubbing next date!"
exec ./drive-dates.sh
exec ./drive-dates.sh "$NAMELISTFILE"
8 changes: 8 additions & 0 deletions land-spinup/drive-dates/nl_dd.REF001.ne128pg2
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
datesfile="dates.REF001.ne128pg2.txt"
DIRSTASH="/global/cfs/cdirs/m2637/E3SM_SCREAM_files/finidat/ne128pg2/CHEY.VR28.NATL.REF.CAM5.4CLM5.0.dtime900/"
CASENAME="ne128pg2-spinup_19840101_0000"
CASESRC="/global/homes/c/czarzyck/I-runs/"
BASERUN="/pscratch/sd/c/czarzyck/e3sm_scratch/pm-cpu/"
BETACAST="/global/homes/c/czarzyck/betacast/"
WALLCLOCK="02:00:00"
RUNQUEUE="regular"
26 changes: 26 additions & 0 deletions utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,32 @@ function delete_except_last() {
}


# Copy files given a set of patterns
# Usage: safe_cp2 "*.clm2.r.*,*.elm.r.*" $DIRSTASH
function safe_cp2() {

local dest="$2"
# split on multiple input patterns if necessary
IFS=',' read -r -a patterns <<< "$1"

# Loop over all matching patterns
for pattern in "${patterns[@]}"; do

# Trim leading and trailing spaces from the pattern
pattern=$(echo "$pattern" | xargs)

# Collect all files matching the pattern, sorted
files=($(ls $pattern 2>/dev/null | sort))

if [ ${#files[@]} -eq 0 ]; then
echo "Error: ZERO files found matching pattern $pattern."
else
cp -v -- "${files[@]}" "$dest"
fi
done
}


# Usage:
# script_start=$(date +%s)
# script_end=$(date +%s)
Expand Down

0 comments on commit 8f2c969

Please sign in to comment.