Skip to content

Commit d1c9b22

Browse files
committed
#358 Handle the case where input iceberg files are empty
If input files have no icebergs, then use one of the empty input files as the output file. This will indicate that there are no icebergs, and the iceberg model can accept a restart file with no icebergs (per Alex Huth).
1 parent 346682f commit d1c9b22

File tree

1 file changed

+32
-10
lines changed

1 file changed

+32
-10
lines changed

src/iceberg-comb/iceberg_comb.sh.in

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -330,17 +330,39 @@ do
330330
has_icebergs $f && combine_files="$combine_files $f"
331331
done
332332

333-
# Run ncrcat on the files
334-
ncrcat_cmd="$ncrcat $combine_files $out_file"
335-
if [ $verbose -gt 0 ]
333+
# Normally, run ncrcat on the input files. However,
334+
# if all input files have no icebergs, then use one of the input files
335+
# as the output file, print a message, and exit normally.
336+
# This unambigously indicates that there are no icebergs,
337+
# and the iceberg model can read an iceberg restart with no icebergs.
338+
if [ -n "$combine_files" ]
336339
then
337-
echoerr "debug1: Running '$ncrcat_cmd'"
338-
fi
339-
eval $ncrcat_cmd
340-
if [ $? -ne 0 ]
341-
then
342-
echoerr "$script_name: Error during executing '$ncrcat_cmd'"
343-
exit $EXIT_FAILURE
340+
# Run ncrcat on the files
341+
ncrcat_cmd="$ncrcat $combine_files $out_file"
342+
if [ $verbose -gt 0 ]
343+
then
344+
echoerr "debug1: Running '$ncrcat_cmd'"
345+
fi
346+
eval $ncrcat_cmd
347+
if [ $? -ne 0 ]
348+
then
349+
echoerr "$script_name: Error during executing '$ncrcat_cmd'"
350+
exit $EXIT_FAILURE
351+
fi
352+
else
353+
# Copy first empty iceberg file to the output file
354+
echoerr "debug1: Input files contain no icebergs; this is fine"
355+
copy_cmd="cp ${in_files%% *} $out_file"
356+
if [ $verbose -gt 0 ]
357+
then
358+
echoerr "debug1: Running '$copy_cmd'"
359+
fi
360+
$copy_cmd
361+
if [ $? -ne 0 ]
362+
then
363+
echoerr "$script_name: Error during executing '$copy_cmd'"
364+
exit $EXIT_FAILURE
365+
fi
344366
fi
345367

346368
ncatted_cmd="$ncatted -a NumFilesInSet,global,d,, $out_file"

0 commit comments

Comments
 (0)