Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 85 additions & 0 deletions CIME/Tools/noresm2netcdf4.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#!/bin/bash -fvx
# zip restart files?
set -e
ZIPRES=1

# remove log files?
RMLOGS=0

# Set script name
sn=noresm2netcdf4

# archive path of case
ABASE=$1

if [ ! -d $ABASE ]; then
echo "${sn}: ${ABASE} is not a directory." >&2
exit 1
fi
cd $ABASE

# Set arguments
nthreads=4

# Set various variables
ncdump=`which ncdump`
nccopy=`which nccopy`
complevel=5 # 1-9
lid="`date +%y%m%d-%H%M%S`"

# Functions

convert_cmd () {
echo convert $ncfile
rm -f ${ncfile}_tmp
set -e
ncks -a -h -O -4 -L $complevel $ncfile ${ncfile}_tmp
mv ${ncfile}_tmp ${ncfile}
chmod go+r ${ncfile}
}

compress_cmd () {
if [ $ZIPRES -eq 1 ] ; then
echo zip $ncfile
gzip $ncfile
chmod go+r ${ncfile}.gz
fi
}

convert_loop () {
set -e
# loop over cases
for ncfile in `find . -wholename '*/hist/*.nc' -print`; do
if [[ "`$ncdump -k $ncfile`" != 'netCDF-4' && "`$ncdump -k $ncfile`" != 'netCDF-4 classic model' ]] ; then
while :; do
if [ `jobs -p|wc -l` -lt $nthreads ]; then
convert_cmd &
break
fi
sleep 0.1s
done
fi
done
for ncfile in `find . -wholename '*/rest/*.nc' -print`; do
while :; do
if [ `jobs -p|wc -l` -lt $nthreads ]; then
compress_cmd &
break
fi
sleep 0.1s
done
done
for logfile in `find . -wholename '*/logs/*' -print`; do
if [ $RMLOGS -eq 1 ] ; then
rm -f $logfile
fi
done

wait
echo "${sn}: conversion completed."
}

# Execute the convert loop as a backgroud process
echo `date` > $ABASE/archive.log.$lid
convert_loop >> $ABASE/archive.log.$lid
echo `date` >> $ABASE/archive.log.$lid
1 change: 1 addition & 0 deletions CIME/case/case.py
Original file line number Diff line number Diff line change
Expand Up @@ -1671,6 +1671,7 @@ def _create_caseroot_tools(self):
os.path.join(toolsdir, "xmlchange"),
os.path.join(toolsdir, "xmlquery"),
os.path.join(toolsdir, "pelayout"),
os.path.join(toolsdir, "noresm2netcdf4.sh"),
)
try:
for exefile in exefiles:
Expand Down
14 changes: 14 additions & 0 deletions CIME/case/case_st_archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -1077,6 +1077,20 @@ def case_st_archive(
)
else:
self.submit(resubmit=True)
if self.get_value('COMPRESS_ARCHIVE_FILES'):
archiveroot = self.get_value('DOUT_S_ROOT')
convert='/noresm2netcdf4.sh'
cmd_convert=caseroot+convert
cmd="%s %s" %(cmd_convert,archiveroot)
logger.info("cmd={}".format(cmd))
run_cmd_no_fail(cmd)

if self.get_value('COPY_CASE_FOLDER'):
archiveroot = self.get_value('DOUT_S_ROOT')
sync='rsync -avh'
cmd="%s %s %s %s" %(sync,caseroot, archiveroot+'/case','>'+archiveroot+'/case.log')
logger.info("cmd={}".format(cmd))
run_cmd_no_fail(cmd)

return True

Expand Down