Skip to content

Instantly share code, notes, and snippets.

@j08lue
Created June 17, 2015 14:56
Show Gist options
  • Save j08lue/e95591e37f669b0ee801 to your computer and use it in GitHub Desktop.
Save j08lue/e95591e37f669b0ee801 to your computer and use it in GitHub Desktop.
CESM 1.2.2 data archiving scripts
#!/bin/bash
msls () {
rd=$1
ssh_loc=$2
scp_loc=$3
if [ "${ssh_loc}" != "" ] && [ "${scp_loc}" != "" ]; then
ssh -q ${ssh_loc} "ssh -q ${scp_loc} ls -l ${rd}"
fi
}
msmkdir () {
rd=$1
ssh_loc=$2
scp_loc=$3
if [ `which hsi | wc -w` == 1 ]; then
echo "msmkdir: hsi 'mkdir -p ${rd}'"
hsi -q "mkdir -p ${rd}"
if [ $? -eq 0 ]; then
return 0
else
echo "mksmkdir: error"
return $?
fi
else
echo "msmkdir: ssh -q ${ssh_loc} ssh -q ${scp_loc} mkdir -p ${rd} ":
ssh -q ${ssh_loc} "ssh -q ${scp_loc} mkdir -p ${rd}"
sleep 2
return 0
fi
}
msfsize() {
# function to get the size of a file
# from its long listing
if [ $# -lt 5 ]; then
echo "0"
else
echo $5
fi
}
msget () {
#------------------------------------------------------------------
# Copy files from the local mass store
# "Usage msget mssdir/file2 locdir/file1"
# rdf = remote dir/filename ldf = local dir/filename
# rd = remote dir rf = remote filename
# ld = local dir lf = local filename
# Split inputs into r(remote) and l(local) d(directories) and f(files)
# If the local filename is empty, set it to the remote filename
# If the local filename doesn't exist, exit
#------------------------------------------------------------------
rdf=$1; rd=`dirname ${rdf}`; rf=`basename ${rdf}`
ldf=$2; ld=`dirname ${ldf}`; lf=`basename ${ldf}`
if [ "${lf}" == '' ]; then
lf=${rf}
fi
if [ `which hsi | wc -w` == 1 ]; then
hsi -q "cd ${rd} ; get ${ldf} : ${rf}" >& /dev/null
return $?
fi
}
mscpdir () {
#------------------------------------------------------------------
# Copy entire directory to the local mass store
#------------------------------------------------------------------
ldr=$1
rdr=$2
ssh_loc=$3
scp_loc=$4
# ssh/scp to ssh_loc by first ssh to ssh_loc.
myld=`pwd`
if [ `ssh -q ${ssh_loc} "which bbscp" | wc -w` == 1 ]; then
echo "mscpdir: ssh -q ${ssh_loc} bbscp -z ${ldr} ${scp_loc}:${rdr}"
ssh -q ${ssh_loc} "bbscp -z ${ldr} ${scp_loc}:${rdr}"
else
echo "mscpdir: ssh -q ${ssh_loc} /usr/bin/scp -r -q ${ldr} ${scp_loc}:${rdr}"
ssh -q ${ssh_loc} "/usr/bin/scp -r -q ${ldr} ${scp_loc}:${rdr}"
fi
sleep 2
return 0
}
msput() {
#------------------------------------------------------------------
# Copy files to the local mass store
# rdf = remote dir/filename # ldf = local dir/filename
# rd = remote dir # rf = remote filename
# ld = local dir # lf = local filename
# Split inputs into r(remote) and l(local) d(directories) and f(files)
# If the remote file is empty, set it to the local filename
# Then execute site dependent mass store write
#------------------------------------------------------------------
ldf=$1; ld=`dirname ${ldf}`; lf=`basename ${ldf}`
rdf=$2; rd=`dirname ${rdf}`; rf=`basename ${rdf}`
ssh_loc=$3
scp_loc=$4
if [ "${rf}" == "" ]; then
rf=$lf
fi
if [ `which hsi | wc -w` == 1 ]; then
opts=" "
if ! [[ "$DOUT_L_HPSS_ACCNT" =~ "0000*" ]]; then
opts=" -a ${DOUT_L_HPSS_ACCNT} "
fi
# note that the -d flag will delete the local copy
echo "msput: hsi ${opts} 'cd ${rd} ; put -d ${ldf} : ${rf}'"
hsi ${opts} -q "cd ${rd} ; put -d ${ldf} : ${rf} ; chmod +r ${rf}"
return $?
fi
if [ "${ssh_loc}" != "" ] && [ "${scp_loc}" != "" ]; then
ssh -q ${ssh_loc} "scp -q ${ldf} ${scp_loc}:${rdf}"
sleep 2
fi
}
#***********************************************************************
# Long term archiving functionality
#***********************************************************************
# Assume that have access to the following environment variables
# $DOUT_S_ROOT, $DOUT_L_MSROOT, $DOUT_L_HPSS_ACCNT
# Above name for $MACH is there just for brief backwards compatibility
mode="unknown"
ssh_loc="unknown"
scp_loc="unknown"
arc_root="unknown"
while [ $# -gt 0 ]; do
case $1 in
-m|--mode )
mode=$2
echo " mode is $2"
shift
;;
--ssh_loc )
ssh_loc=$2
shift
;;
--scp_loc )
scp_loc=$2
shift
;;
--arc_root )
arc_root=$2
shift
;;
* )
esac
shift
done
found=0
for name in copy_files copy_dirs_hsi copy_dirs_sshscp copy_dirs_local ; do
if [ "$name" == "$mode" ] ; then
found=1
break
fi
done
if [ $found -ne 1 ] ; then
echo "$current value of mode $model not supported"
exit 1
fi
#----------------------------------------------------------------------
# If requested by user, save output on disk in $DOUT_S_SAVE_ROOT
#----------------------------------------------------------------------
if [ $DOUT_S_SAVE_ALL_ON_DISK == "TRUE" ] ; then
if [ ! -e $DOUT_S_SAVE_ROOT ]; then
mkdir -p $DOUT_S_SAVE_ROOT
if [ $? -ne 0 ] ; then
echo "Exit lt_archive.sh -- Cannot make save directory $DOUT_S_SAVE_ROOT"
exit
fi
fi
# ..Test that $DOUT_S_SAVE_ROOT is a valid directory
if [ ! -d $DOUT_S_SAVE_ROOT ]; then
if [ ! -h $DOUT_S_SAVE_ROOT ]; then
echo "Exit lt_archive.sh -- $DOUT_S_SAVE_ROOT is not a valid directory"
exit
else
if [ ! -d `readlink -f $DOUT_S_SAVE_ROOT` ] ; then
echo "Exit lt_archive.sh -- $DOUT_S_SAVE_ROOT is not a valid directory"
exit
fi
fi
fi
# ..Test that hard links are possible between $DOUT_S_ROOT and $DOUT_S_SAVE_ROOT
cd $DOUT_S_ROOT
echo 'TestHardLink' > TESTHARDLINK
cp -al TESTHARDLINK $DOUT_S_SAVE_ROOT
if [ $? -ne 0 ]; then
echo "Exit lt_archive.sh -- hard links not possible between $DOUT_S_ROOT and $DOUT_S_SAVE_ROOT"
rm -f TESTHARDLINK
exit
fi
rm -f TESTHARDLINK $DOUT_S_SAVE_ROOT/TESTHARDLINK
# ..Replicate directory trees (except rest) in $DOUT_S_SAVE_ROOT
dlist=`ls -1 | sed -e 's/rest//'`
cp -al $dlist $DOUT_S_SAVE_ROOT
fi
#----------------------------------------------------------------------
if [ "$mode" == "copy_dirs_hsi" ]; then
if_hsi=`which hsi | wc -w`
if [ $if_hsi != 1 ] ; then
echo "lt_archive: asked for copy_dirs_hsi - but hsi not found"
echo "lt_archive: check path"
exit -1
fi
# Long-term archiver for HPSS (Trey White, December 6, 2011)
date
if [ ! $?DOUT_L_HPSS_ACCNT ]; then
DOUT_L_HPSS_ACCNT=0
fi
# send files to HPSS and delete upon success
cd $DOUT_S_ROOT
if [ $DOUT_L_HPSS_ACCNT -gt 0 ]; then
hsi -a $DOUT_L_HPSS_ACCNT "mkdir -p $DOUT_L_MSROOT ; chmod +t $DOUT_L_MSROOT ; cd $DOUT_L_MSROOT ; put -dPR *"
else
hsi "mkdir -p $DOUT_L_MSROOT ; chmod +t $DOUT_L_MSROOT ; cd $DOUT_L_MSROOT ; put -dPR *"
fi
date
fi
#----------------------------------------------------------------------
if [ "$mode" == "copy_files" ]; then
#------------------------------------------------------------------
# Copy files and dir structure from short term archiving
# Assume there are up to two levels of dirs below $DOUT_S_ROOT
# $DOUT_S_ROOT/$dirl1/$dirl2
# dirl1 => normallly [atm,lnd,ocn,ice,cpl,glc,rof,wav,rest]
# dirl2 => normally [init,hist,logs,date(for rest)]
#------------------------------------------------------------------
cd $DOUT_S_ROOT
msmkdir $DOUT_L_MSROOT
for dirl1 in */ ; do
cd ${DOUT_S_ROOT}/${dirl1}
msmkdir ${DOUT_L_MSROOT}/${dirl1}
for dirl2 in */ ; do
cd ${DOUT_S_ROOT}/${dirl1}/${dirl2}
msmkdir ${DOUT_L_MSROOT}/${dirl1}/${dirl2}
for file in * ; do
if [ -f ${file} ]; then
# first remove any local file with name checkmssfile
if [ -e checkmssfile ]; then
rm -f checkmssfile
fi
# try to copy file from mass store into local checkmssfile
msget ${DOUT_L_MSROOT}/${dirl1}/${dirl2}/${file} checkmssfile
# compare local file and remote file, either remove local file
# OR write local file to mass store based on cmp return status
cmp -s ${file} checkmssfile
if [ $? == 0 ]; then
echo "l_archive.sh rm ${file}"
rm -f $file
else
echo "l_archive.sh: msput ${file} ${DOUT_L_MSROOT}/${dirl1}/${dirl2}/${file}"
msput ${file} ${DOUT_L_MSROOT}/${dirl1}/${dirl2}/${file}
fi
fi
done # for file
done # for dirl2
done # for dirl
fi # if copy_files
#----------------------------------------------------------------------
if [ "$mode" == "copy_dirs_sshscp" ]; then
echo "time : "`date`
cd $DOUT_S_ROOT
msmkdir ${DOUT_L_MSROOT} $ssh_loc $scp_loc
echo "time : "`date`
for dirl1 in */ ; do
cd $DOUT_S_ROOT/${dirl1}
mscpdir ${DOUT_S_ROOT}/${dirl1} ${DOUT_L_MSROOT} $ssh_loc $scp_loc
echo "time : "`date`
for dirl2 in */ ; do
cd ${DOUT_S_ROOT}/${dirl1}/${dirl2}
for file in `ls -1`; do
if [ -f ${file} ]; then
echo "local file: $file ... long-term archive file: ${DOUT_L_MSROOT}/${dirl1}/${dirl2}/${file}"
lta_listing=`msls ${DOUT_L_MSROOT}/${dirl1}/${dirl2}/${file} $ssh_loc $scp_loc`
echo "time : "`date`
loc_listing=`ls -l ${file}`
lta_size=`msfsize $lta_listing`
loc_size=`msfsize $loc_listing`
if [ $loc_size -gt 0 ] && [ $loc_size -eq $lta_size ]; then
echo "local file and long-term archive file are same size"
echo rm -f ${file}
rm -f ${file}
else
echo "local file and long-term archive file are NOT the same size... ${file} will remain on local disk"
#exit -1 #??? ask francis if this is right
# Not sure what to do here... maybe make the log entry and carry on...
fi
fi
done # for file
done # for dirl2
done # dirl1
fi # if copy_dirs
#----------------------------------------------------------------------
if [ "$mode" == "copy_dirs_local" ]; then
cd $DOUT_S_ROOT
mkdir -p ${arc_root}/${DOUT_L_MSROOT}
for dirl1 in */ ; do
cd $DOUT_S_ROOT/${dirl1}
cp -r ${DOUT_S_ROOT}/${dirl1} ${arc_root}/${DOUT_L_MSROOT}
for dirl2 in */ ; do
cd ${DOUT_S_ROOT}/${dirl1}/${dirl2}
for file in `ls -1`; do
if [ -f ${file} ]; then
echo "local file: $file ... long-term archive file: ${DOUT_L_MSROOT}/${dirl1}/${dirl2}/${file}"
lta_listing=`ls -l ${arc_root}/${DOUT_L_MSROOT}/${dirl1}/${dirl2}/${file}`
loc_listing=`ls -l ${file}`
lta_size=`msfsize $lta_listing`
loc_size=`msfsize $loc_listing`
if [ $loc_size -gt 0 ] && [ $loc_size -eq $lta_size ]; then
echo "local file and long-term archive file are same size"
echo rm -f ${file}
rm -f ${file}
else
echo "local file and long-term archive file are NOT the same size... ${file} will remain on local disk"
#exit -1 #??? ask francis if this is right
# Not sure what to do here... maybe make the log entry and carry on...
fi
fi
done # for file
done # for dirl2
done # dirl1
fi # if copy_dirs
#!/bin/sh
#short-term archive script - move model output out of run directory
#to free disc space for next invocation of model run
#must be executed from run directory
#function dispose:
#moves output files to specified area of st archive and will
#process interim files along the way:
#arg1 => interim files flag
#arg2 => destination
#remaining args => actual files to be processed
dispose() {
if [ "$1" == "ifiles_y" ] && [ "$DOUT_S_SAVE_INT_REST_FILES" != "TRUE" ]; then
shift
shift
rm $* 2> /dev/null
else
shift
dest=$1
mkdir -p $dest
shift
mv $* $dest 2> /dev/null
fi
}
#function get_inst_suffix:
#Gets a string corresponding to the current instance index of a given
#component, with a leading '.'; this can be appended to a file name.
#In the general case, the returned string is something like ".###",
#but if there is only a single instance of the given component, then
#the returned string is empty, because in that case the file names
#don't have any instance number (or the associated extra '_').
#
#arg1 => instance index for a given component
#arg2 => number of instances of this component
#
#result is returned in $inst_suffix
get_inst_suffix() {
# echo "get_inst_suffixa $1 $2 ${inst_suffix}"
if [ $2 -eq 1 ]; then # only one instance of this component
inst_suffix=""
else # multiple instances of this component
inst_suffix=`printf _%04d $1`
fi
# echo "get_inst_suffixb $1 $2 ${inst_suffix}"
}
echo ""
echo "st_archive.sh: start of short-term archiving"
#validate required env var settings
if [ -z "$DOUT_S_ROOT" ]; then
echo "st_archive.sh: error, environment variable DOUT_S_ROOT is required "
echo " for root location of short-term archive"
echo "st_archive.sh: exiting"
exit 1
fi
sta=${DOUT_S_ROOT}/.sta-$$-`date +%Y%m%d%H%M%S%N`
mkdir -p ${sta} 2> /dev/null
if [ $? -ne 0 ]; then
echo "st_archive.sh: error, unable to create short-term archive directory"
echo "st_archive.sh: exiting"
exit 1
fi
mv ${DOUT_S_ROOT}/* ${sta}
if [ -z "$DOUT_S_SAVE_INT_REST_FILES" ]; then
echo "st_archive.sh: warning, environment variable DOUT_S_SAVE_INT_REST_FILES is not "
echo " set - using "FALSE" as default for saving interim restart files"
export DOUT_S_SAVE_INT_REST_FILES=FALSE
fi
if [ "$DOUT_S_SAVE_INT_REST_FILES" == "FALSE" ]; then
echo "st_archive.sh: restart files from end of run will be saved, "
echo " interim restart files will be deleted"
fi
## Check component instance counts
if [ -z "$NINST_ATM" ]; then
echo "st_archive.sh: warning, NINST_ATM not set -- using 1 instance"
export NINST_ATM=1
fi
if [ -z "$NINST_LND" ]; then
echo "st_archive.sh: warning, NINST_LND not set -- using 1 instance"
export NINST_LND=1
fi
if [ -z "$NINST_ROF" ]; then
echo "st_archive.sh: warning, NINST_ROF not set -- using 1 instance"
export NINST_ROF=1
fi
if [ -z "$NINST_ICE" ]; then
echo "st_archive.sh: warning, NINST_ICE not set -- using 1 instance"
export NINST_ICE=1
fi
if [ -z "$NINST_OCN" ]; then
echo "st_archive.sh: warning, NINST_OCN not set -- using 1 instance"
export NINST_OCN=1
fi
if [ -z "$NINST_GLC" ]; then
echo "st_archive.sh: warning, NINST_GLC not set -- using 1 instance"
export NINST_GLC=1
fi
if [ -z "$NINST_WAV" ]; then
echo "st_archive.sh: warning, NINST_WAV not set -- using 1 instance"
export NINST_WAV=1
fi
#create directory for restart files
set ${CASE}.cpl.r.*
cplfile=`ls -rt $* 2> /dev/null | tail -1`
dname=`echo $cplfile | sed "s/\.nc//; s/^.*\.r\.//;"`
if [ -d ${sta}/rest/${dname} ]; then
rm -rf ${sta}/rest/${dname}
fi
mkdir -p ${sta}/rest/${dname}
if [ $? -ne 0 ]; then
echo "st_archive.sh: error, unable to create rest directory"
echo "st_archive.sh: exiting"
exit 1
fi
#populate temp directory with pointer files
set rpointer.*
if [ $# -le 0 ]; then
echo "st_archive.sh: error, script should be invoked from run directory..."
echo " expecting restart pointer files of the form 'rpointer.<component>'"
echo " but did not find any: $*"
echo "st_archive.sh: exiting"
exit 1
fi
mv $* ${sta}/rest/${dname}
set cpl.log.*; dispose ifiles_n ${sta}/cpl/logs $*
set cesm*.log.*; dispose ifiles_n ${sta}/cpl/logs $*
set ${CASE}.cpl.r.*; latest=`ls -rt $* 2> /dev/null | tail -1`; mv $latest ${sta}/rest/${dname} 2> /dev/null; dispose ifiles_y ${sta}/cpl/rest $*
set ${CASE}.cpl.h* ; dispose ifiles_n ${sta}/cpl/hist $*
# DART assimilation-related files
set dart_log.*; dispose ifiles_n ${sta}/dart/logs $*
set True_State.*.nc; dispose ifiles_n ${sta}/dart/hist $*
set Prior_Diag.*.nc; dispose ifiles_n ${sta}/dart/hist $*
set Posterior_Diag.*.nc; dispose ifiles_n ${sta}/dart/hist $*
set obs_seq.*.out; dispose ifiles_n ${sta}/dart/hist $*
set obs_seq.*.final; dispose ifiles_n ${sta}/dart/hist $*
set pr*inflate_restart*; latest=`ls -rt $* 2> /dev/null | tail -1`; mv $latest ${sta}/rest/${dname} 2> /dev/null; dispose ifiles_n ${sta}/dart/rest $*
set po*inflate_restart*; latest=`ls -rt $* 2> /dev/null | tail -1`; mv $latest ${sta}/rest/${dname} 2> /dev/null; dispose ifiles_n ${sta}/dart/rest $*
IDX=1
while [ $IDX -le $NINST_ATM ]
do
get_inst_suffix $IDX $NINST_ATM
set atm${inst_suffix}.log.*; dispose ifiles_n ${sta}/atm/logs $*
set ${CASE}.cam*${inst_suffix}.r.*; latest=`ls -rt $* 2> /dev/null | tail -1`; mv $latest ${sta}/rest/${dname} 2> /dev/null; dispose ifiles_y ${sta}/atm/rest $*
set ${CASE}.cam*${inst_suffix}.rs.*; latest=`ls -rt $* 2> /dev/null | tail -1`; mv $latest ${sta}/rest/${dname} 2> /dev/null; dispose ifiles_y ${sta}/atm/rest $*
set ${CASE}.cam*${inst_suffix}.ra.*; latest=`ls -rt $* 2> /dev/null | tail -1`; mv $latest ${sta}/rest/${dname} 2> /dev/null; dispose ifiles_y ${sta}/atm/rest $*
set ${CASE}.cam*${inst_suffix}.rh0.*; latest=`ls -rt $* 2> /dev/null | tail -1`; mv $latest ${sta}/rest/${dname} 2> /dev/null; dispose ifiles_y ${sta}/atm/rest $*
set ${CASE}.cam*${inst_suffix}.rh1.*; latest=`ls -rt $* 2> /dev/null | tail -1`; mv $latest ${sta}/rest/${dname} 2> /dev/null; dispose ifiles_y ${sta}/atm/rest $*
set ${CASE}.cam*${inst_suffix}.rh2.*; latest=`ls -rt $* 2> /dev/null | tail -1`; mv $latest ${sta}/rest/${dname} 2> /dev/null; dispose ifiles_y ${sta}/atm/rest $*
set ${CASE}.cam*${inst_suffix}.rh3.*; latest=`ls -rt $* 2> /dev/null | tail -1`; mv $latest ${sta}/rest/${dname} 2> /dev/null; dispose ifiles_y ${sta}/atm/rest $*
set ${CASE}.cam*${inst_suffix}.rh4.*; latest=`ls -rt $* 2> /dev/null | tail -1`; mv $latest ${sta}/rest/${dname} 2> /dev/null; dispose ifiles_y ${sta}/atm/rest $*
set ${CASE}.cam*${inst_suffix}.rh5.*; latest=`ls -rt $* 2> /dev/null | tail -1`; mv $latest ${sta}/rest/${dname} 2> /dev/null; dispose ifiles_y ${sta}/atm/rest $*
set ${CASE}.cam*${inst_suffix}.h0.*; latest=`ls -rt $* 2> /dev/null | tail -1`; cp $latest ${sta}/rest/${dname} 2> /dev/null; dispose ifiles_n ${sta}/atm/hist $*
set ${CASE}.cam*${inst_suffix}.h1.*; latest=`ls -rt $* 2> /dev/null | tail -1`; cp $latest ${sta}/rest/${dname} 2> /dev/null; dispose ifiles_n ${sta}/atm/hist $*
set ${CASE}.cam*${inst_suffix}.h2.*; latest=`ls -rt $* 2> /dev/null | tail -1`; cp $latest ${sta}/rest/${dname} 2> /dev/null; dispose ifiles_n ${sta}/atm/hist $*
set ${CASE}.cam*${inst_suffix}.h3.*; latest=`ls -rt $* 2> /dev/null | tail -1`; cp $latest ${sta}/rest/${dname} 2> /dev/null; dispose ifiles_n ${sta}/atm/hist $*
set ${CASE}.cam*${inst_suffix}.h4.*; latest=`ls -rt $* 2> /dev/null | tail -1`; cp $latest ${sta}/rest/${dname} 2> /dev/null; dispose ifiles_n ${sta}/atm/hist $*
set ${CASE}.cam*${inst_suffix}.h5.*; latest=`ls -rt $* 2> /dev/null | tail -1`; cp $latest ${sta}/rest/${dname} 2> /dev/null; dispose ifiles_n ${sta}/atm/hist $*
set ${CASE}.cam*${inst_suffix}.hs.*; latest=`ls -rt $* 2> /dev/null | tail -1`; cp $latest ${sta}/rest/${dname} 2> /dev/null; dispose ifiles_n ${sta}/atm/hist $*
set ${CASE}.cam*${inst_suffix}.i.*; latest=`ls -rt $* 2> /dev/null | tail -1`; mv $latest ${sta}/rest/${dname} 2> /dev/null; dispose ifiles_y ${sta}/atm/init $*
set ${CASE}.datm${inst_suffix}.r.* ; latest=`ls -rt $* 2> /dev/null | tail -1`; mv $latest ${sta}/rest/${dname} 2> /dev/null; dispose ifiles_y ${sta}/atm/rest $*
set ${CASE}.datm${inst_suffix}.rs* ; latest=`ls -rt $* 2> /dev/null | tail -1`; mv $latest ${sta}/rest/${dname} 2> /dev/null; dispose ifiles_y ${sta}/atm/rest $*
set ${CASE}.datm${inst_suffix}.h.* ; dispose ifiles_n ${sta}/atm/hist $*
set ${CASE}.wrf.r01.*; latest=`ls -rt $* 2> /dev/null | tail -1`; mv $latest ${sta}/rest/${dname} 2> /dev/null; dispose ifiles_y ${sta}/atm/rest $*
set ${CASE}.wrf.r02.*; latest=`ls -rt $* 2> /dev/null | tail -1`; mv $latest ${sta}/rest/${dname} 2> /dev/null; dispose ifiles_y ${sta}/atm/rest $*
set ${CASE}.wrf.r03.*; latest=`ls -rt $* 2> /dev/null | tail -1`; mv $latest ${sta}/rest/${dname} 2> /dev/null; dispose ifiles_y ${sta}/atm/rest $*
set ${CASE}.wrf.h01.*; dispose ifiles_n ${sta}/atm/hist $*
set ${CASE}.wrf.h02.*; dispose ifiles_n ${sta}/atm/hist $*
set ${CASE}.wrf.h03.*; dispose ifiles_n ${sta}/atm/hist $*
set ${CASE}.wrf.h1aux01.*; dispose ifiles_n ${sta}/atm/hist $*
set ${CASE}.wrf.h1aux02.*; dispose ifiles_n ${sta}/atm/hist $*
set ${CASE}.wrf.h1aux03.*; dispose ifiles_n ${sta}/atm/hist $*
set ${CASE}.wrf.h2aux01.*; dispose ifiles_n ${sta}/atm/hist $*
set ${CASE}.wrf.h2aux02.*; dispose ifiles_n ${sta}/atm/hist $*
set ${CASE}.wrf.h2aux03.*; dispose ifiles_n ${sta}/atm/hist $*
set ${CASE}.wrf.h3aux01.*; dispose ifiles_n ${sta}/atm/hist $*
set ${CASE}.wrf.h3aux02.*; dispose ifiles_n ${sta}/atm/hist $*
set ${CASE}.wrf.h3aux03.*; dispose ifiles_n ${sta}/atm/hist $*
IDX=`expr $IDX + 1`
done
IDX=1
while [ $IDX -le $NINST_LND ]
do
get_inst_suffix $IDX $NINST_LND
set lnd${inst_suffix}.log.*; dispose ifiles_n ${sta}/lnd/logs $*
set ${CASE}.clm?${inst_suffix}.r.*; latest=`ls -rt $* 2> /dev/null | tail -1`; mv $latest ${sta}/rest/${dname} 2> /dev/null; dispose ifiles_y ${sta}/lnd/rest $*
set ${CASE}.clm?${inst_suffix}.rh0.*; latest=`ls -rt $* 2> /dev/null | tail -1`; mv $latest ${sta}/rest/${dname} 2> /dev/null; dispose ifiles_y ${sta}/lnd/rest $*
set ${CASE}.clm?${inst_suffix}.rh1.*; latest=`ls -rt $* 2> /dev/null | tail -1`; mv $latest ${sta}/rest/${dname} 2> /dev/null; dispose ifiles_y ${sta}/lnd/rest $*
set ${CASE}.clm?${inst_suffix}.rh2.*; latest=`ls -rt $* 2> /dev/null | tail -1`; mv $latest ${sta}/rest/${dname} 2> /dev/null; dispose ifiles_y ${sta}/lnd/rest $*
set ${CASE}.clm?${inst_suffix}.rh3.*; latest=`ls -rt $* 2> /dev/null | tail -1`; mv $latest ${sta}/rest/${dname} 2> /dev/null; dispose ifiles_y ${sta}/lnd/rest $*
set ${CASE}.clm?${inst_suffix}.rh4.*; latest=`ls -rt $* 2> /dev/null | tail -1`; mv $latest ${sta}/rest/${dname} 2> /dev/null; dispose ifiles_y ${sta}/lnd/rest $*
set ${CASE}.clm?${inst_suffix}.rh5.*; latest=`ls -rt $* 2> /dev/null | tail -1`; mv $latest ${sta}/rest/${dname} 2> /dev/null; dispose ifiles_y ${sta}/lnd/rest $*
set ${CASE}.clm?${inst_suffix}.h0.*; latest=`ls -rt $* 2> /dev/null | tail -1`; cp $latest ${sta}/rest/${dname} 2> /dev/null; dispose ifiles_n ${sta}/lnd/hist $*
set ${CASE}.clm?${inst_suffix}.h1.*; latest=`ls -rt $* 2> /dev/null | tail -1`; cp $latest ${sta}/rest/${dname} 2> /dev/null; dispose ifiles_n ${sta}/lnd/hist $*
set ${CASE}.clm?${inst_suffix}.h2.*; latest=`ls -rt $* 2> /dev/null | tail -1`; cp $latest ${sta}/rest/${dname} 2> /dev/null; dispose ifiles_n ${sta}/lnd/hist $*
set ${CASE}.clm?${inst_suffix}.h3.*; latest=`ls -rt $* 2> /dev/null | tail -1`; cp $latest ${sta}/rest/${dname} 2> /dev/null; dispose ifiles_n ${sta}/lnd/hist $*
set ${CASE}.clm?${inst_suffix}.h4.*; latest=`ls -rt $* 2> /dev/null | tail -1`; cp $latest ${sta}/rest/${dname} 2> /dev/null; dispose ifiles_n ${sta}/lnd/hist $*
set ${CASE}.clm?${inst_suffix}.h5.*; latest=`ls -rt $* 2> /dev/null | tail -1`; cp $latest ${sta}/rest/${dname} 2> /dev/null; dispose ifiles_n ${sta}/lnd/hist $*
set ${CASE}.clm?${inst_suffix}.hv.*; latest=`ls -rt $* 2> /dev/null | tail -1`; cp $latest ${sta}/rest/${dname} 2> /dev/null; dispose ifiles_n ${sta}/lnd/hist $*
set ${CASE}.clm?${inst_suffix}.i.*; dispose ifiles_y ${sta}/lnd/init $*
set ${CASE}.dlnd${inst_suffix}.r.* ; latest=`ls -rt $* 2> /dev/null | tail -1`; mv $latest ${sta}/rest/${dname} 2> /dev/null; dispose ifiles_y ${sta}/lnd/rest $*
set ${CASE}.dlnd${inst_suffix}.rs* ; latest=`ls -rt $* 2> /dev/null | tail -1`; mv $latest ${sta}/rest/${dname} 2> /dev/null; dispose ifiles_y ${sta}/lnd/rest $*
set ${CASE}.dlnd${inst_suffix}.h.* ; dispose ifiles_n ${sta}/lnd/hist $*
IDX=`expr $IDX + 1`
done
IDX=1
while [ $IDX -le $NINST_ROF ]
do
get_inst_suffix $IDX $NINST_ROF
set rof${inst_suffix}.log.*; dispose ifiles_n ${sta}/rof/logs $*
set ${CASE}.rtm${inst_suffix}.r.*; latest=`ls -rt $* 2> /dev/null | tail -1`; mv $latest ${sta}/rest/${dname} 2> /dev/null; dispose ifiles_y ${sta}/rof/rest $*
set ${CASE}.rtm${inst_suffix}.rh0.*; latest=`ls -rt $* 2> /dev/null | tail -1`; mv $latest ${sta}/rest/${dname} 2> /dev/null; dispose ifiles_y ${sta}/rof/rest $*
set ${CASE}.rtm${inst_suffix}.rh1.*; latest=`ls -rt $* 2> /dev/null | tail -1`; mv $latest ${sta}/rest/${dname} 2> /dev/null; dispose ifiles_y ${sta}/rof/rest $*
set ${CASE}.rtm${inst_suffix}.rh2.*; latest=`ls -rt $* 2> /dev/null | tail -1`; mv $latest ${sta}/rest/${dname} 2> /dev/null; dispose ifiles_y ${sta}/rof/rest $*
set ${CASE}.rtm${inst_suffix}.rh3.*; latest=`ls -rt $* 2> /dev/null | tail -1`; mv $latest ${sta}/rest/${dname} 2> /dev/null; dispose ifiles_y ${sta}/rof/rest $*
set ${CASE}.rtm${inst_suffix}.h0.*; latest=`ls -rt $* 2> /dev/null | tail -1`; cp $latest ${sta}/rest/${dname} 2> /dev/null; dispose ifiles_n ${sta}/rof/hist $*
set ${CASE}.rtm${inst_suffix}.h1.*; latest=`ls -rt $* 2> /dev/null | tail -1`; cp $latest ${sta}/rest/${dname} 2> /dev/null; dispose ifiles_n ${sta}/rof/hist $*
set ${CASE}.rtm${inst_suffix}.h2.*; latest=`ls -rt $* 2> /dev/null | tail -1`; cp $latest ${sta}/rest/${dname} 2> /dev/null; dispose ifiles_n ${sta}/rof/hist $*
set ${CASE}.rtm${inst_suffix}.h3.*; latest=`ls -rt $* 2> /dev/null | tail -1`; cp $latest ${sta}/rest/${dname} 2> /dev/null; dispose ifiles_n ${sta}/rof/hist $*
IDX=`expr $IDX + 1`
done
IDX=1
while [ $IDX -le $NINST_ICE ]
do
get_inst_suffix $IDX $NINST_ICE
set ice${inst_suffix}.log.*; dispose ifiles_n ${sta}/ice/logs $*
set ${CASE}.cice${inst_suffix}.r.[0-9]*; latest=`ls -rt $* 2> /dev/null | tail -1`; mv $latest ${sta}/rest/${dname} 2> /dev/null; dispose ifiles_y ${sta}/ice/rest $*
set ${CASE}.cice${inst_suffix}.r.volpn*; latest=`ls -rt $* 2> /dev/null | tail -1`; mv $latest ${sta}/rest/${dname} 2> /dev/null; dispose ifiles_y ${sta}/ice/rest $*
set ${CASE}.cice${inst_suffix}.r.dEdd*; latest=`ls -rt $* 2> /dev/null | tail -1`; mv $latest ${sta}/rest/${dname} 2> /dev/null; dispose ifiles_y ${sta}/ice/rest $*
set ${CASE}.cice${inst_suffix}.r.age*; latest=`ls -rt $* 2> /dev/null | tail -1`; mv $latest ${sta}/rest/${dname} 2> /dev/null; dispose ifiles_y ${sta}/ice/rest $*
set ${CASE}.cice${inst_suffix}.r.aero*; latest=`ls -rt $* 2> /dev/null | tail -1`; mv $latest ${sta}/rest/${dname} 2> /dev/null; dispose ifiles_y ${sta}/ice/rest $*
set ${CASE}.cice${inst_suffix}.h*; dispose ifiles_n ${sta}/ice/hist $*
set ${CASE}.cice${inst_suffix}.i.*; dispose ifiles_y ${sta}/ice/init $*
set ${CASE}.dice${inst_suffix}.r.* ; latest=`ls -rt $* 2> /dev/null | tail -1`; mv $latest ${sta}/rest/${dname} 2> /dev/null; dispose ifiles_y ${sta}/ice/rest $*
set ${CASE}.dice${inst_suffix}.rs* ; latest=`ls -rt $* 2> /dev/null | tail -1`; mv $latest ${sta}/rest/${dname} 2> /dev/null; dispose ifiles_y ${sta}/ice/rest $*
set ${CASE}.dice${inst_suffix}.h.* ; dispose ifiles_n ${sta}/ice/hist $*
IDX=`expr $IDX + 1`
done
IDX=1
while [ $IDX -le $NINST_OCN ]
do
get_inst_suffix $IDX $NINST_OCN
set ocn${inst_suffix}.log.*; dispose ifiles_n ${sta}/ocn/logs $*
set ${CASE}.pop${inst_suffix}.r.*.hdr; latest=`ls -rt $* 2> /dev/null | tail -1`; mv $latest ${sta}/rest/${dname} 2> /dev/null; dispose ifiles_y ${sta}/ocn/rest $*
set ${CASE}.pop${inst_suffix}.r.*0000; latest=`ls -rt $* 2> /dev/null | tail -1`; mv $latest ${sta}/rest/${dname} 2> /dev/null; dispose ifiles_y ${sta}/ocn/rest $*
set ${CASE}.pop${inst_suffix}.r.*0000.nc; latest=`ls -rt $* 2> /dev/null | tail -1`; mv $latest ${sta}/rest/${dname} 2> /dev/null; dispose ifiles_y ${sta}/ocn/rest $*
set ${CASE}.pop${inst_suffix}.rh.ecosys.*.hdr; latest=`ls -rt $* 2> /dev/null | tail -1`; mv $latest ${sta}/rest/${dname} 2> /dev/null; dispose ifiles_y ${sta}/ocn/rest $*
set ${CASE}.pop${inst_suffix}.rh.ecosys.*0000; latest=`ls -rt $* 2> /dev/null | tail -1`; mv $latest ${sta}/rest/${dname} 2> /dev/null; dispose ifiles_y ${sta}/ocn/rest $*
set ${CASE}.pop${inst_suffix}.rh.ecosys.*0000.nc; latest=`ls -rt $* 2> /dev/null | tail -1`; mv $latest ${sta}/rest/${dname} 2> /dev/null; dispose ifiles_y ${sta}/ocn/rest $*
set ${CASE}.pop${inst_suffix}.rh.*.hdr; latest=`ls -rt $* 2> /dev/null | tail -1`; mv $latest ${sta}/rest/${dname} 2> /dev/null; dispose ifiles_y ${sta}/ocn/rest $*
set ${CASE}.pop${inst_suffix}.rh.*0000; latest=`ls -rt $* 2> /dev/null | tail -1`; mv $latest ${sta}/rest/${dname} 2> /dev/null; dispose ifiles_y ${sta}/ocn/rest $*
set ${CASE}.pop${inst_suffix}.rh.*0000.nc; latest=`ls -rt $* 2> /dev/null | tail -1`; mv $latest ${sta}/rest/${dname} 2> /dev/null; dispose ifiles_y ${sta}/ocn/rest $*
set ${CASE}.pop${inst_suffix}.ro.*; latest=`ls -rt $* 2> /dev/null | tail -1`; mv $latest ${sta}/rest/${dname} 2> /dev/null; dispose ifiles_y ${sta}/ocn/rest $*
set ${CASE}.pop${inst_suffix}.d?*; dispose ifiles_n ${sta}/ocn/hist $*
set ${CASE}.pop${inst_suffix}.h*; dispose ifiles_n ${sta}/ocn/hist $*
set ${CASE}.docn${inst_suffix}.r.* ; latest=`ls -rt $* 2> /dev/null | tail -1`; mv $latest ${sta}/rest/${dname} 2> /dev/null; dispose ifiles_y ${sta}/ocn/rest $*
set ${CASE}.docn${inst_suffix}.rs* ; latest=`ls -rt $* 2> /dev/null | tail -1`; mv $latest ${sta}/rest/${dname} 2> /dev/null; dispose ifiles_y ${sta}/ocn/rest $*
set ${CASE}.docn${inst_suffix}.h.* ; dispose ifiles_n ${sta}/ocn/hist $*
IDX=`expr $IDX + 1`
done
IDX=1
while [ $IDX -le $NINST_GLC ]
do
get_inst_suffix $IDX $NINST_GLC
set glc${inst_suffix}.log.*; dispose ifiles_n ${sta}/glc/logs $*
set ${CASE}.cism${inst_suffix}.r.[0-9]*; latest=`ls -rt $* 2> /dev/null | tail -1`; mv $latest ${sta}/rest/${dname} 2> /dev/null; dispose ifiles_y ${sta}/glc/rest $*
set ${CASE}.cism${inst_suffix}.r.volpn*; latest=`ls -rt $* 2> /dev/null | tail -1`; mv $latest ${sta}/rest/${dname} 2> /dev/null; dispose ifiles_y ${sta}/glc/rest $*
set ${CASE}.cism${inst_suffix}.r.dEdd*; latest=`ls -rt $* 2> /dev/null | tail -1`; mv $latest ${sta}/rest/${dname} 2> /dev/null; dispose ifiles_y ${sta}/glc/rest $*
set ${CASE}.cism${inst_suffix}.r.age*; latest=`ls -rt $* 2> /dev/null | tail -1`; mv $latest ${sta}/rest/${dname} 2> /dev/null; dispose ifiles_y ${sta}/glc/rest $*
set ${CASE}.cism${inst_suffix}.r.aero*; latest=`ls -rt $* 2> /dev/null | tail -1`; mv $latest ${sta}/rest/${dname} 2> /dev/null; dispose ifiles_y ${sta}/glc/rest $*
set ${CASE}.cism${inst_suffix}.h*; dispose ifiles_n ${sta}/glc/hist $*
set ${CASE}.cism${inst_suffix}.i.*; dispose ifiles_y ${sta}/glc/init $*
IDX=`expr $IDX + 1`
done
IDX=1
while [ $IDX -le $NINST_WAV ]
do
get_inst_suffix $IDX $NINST_WAV
set wav${inst_suffix}.log.*; dispose ifiles_n ${sta}/wav/logs $*
set ${CASE}.ww3${inst_suffix}.r.[0-9]*; latest=`ls -rt $* 2> /dev/null | tail -1`; mv $latest ${sta}/rest/${dname} 2> /dev/null; dispose ifiles_y ${sta}/wav/rest $*
set ${CASE}.ww3${inst_suffix}.h*; dispose ifiles_n ${sta}/wav/hist $*
set ${CASE}.ww3${inst_suffix}.i.*; dispose ifiles_y ${sta}/wav/init $*
set ${CASE}.dwav${inst_suffix}.r.* ; latest=`ls -rt $* 2> /dev/null | tail -1`; mv $latest ${sta}/rest/${dname} 2> /dev/null; dispose ifiles_y ${sta}/wav/rest $*
set ${CASE}.dwav${inst_suffix}.rs* ; latest=`ls -rt $* 2> /dev/null | tail -1`; mv $latest ${sta}/rest/${dname} 2> /dev/null; dispose ifiles_y ${sta}/wav/rest $*
set ${CASE}.dwav${inst_suffix}.h.* ; dispose ifiles_n ${sta}/wav/hist $*
IDX=`expr $IDX + 1`
done
#copy back the required files for next restart
cp ${sta}/rest/${dname}/* .
if mv ${sta}/* ${DOUT_S_ROOT}; then
rm -fr ${sta}
else
echo "st_archive.sh: error, final move command unsuccessful"
echo " some short-term archive data may be in ${sta}"
echo "st_archive.sh: exiting"
exit 1
fi
echo "st_archive.sh: short-term archiving completed successfully"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment