The usage is as follows:
./test_output.sh
However, this would normally be run within a serial batch script to avoid using excessive resources on the login nodes.
Source for test_output.sh
##
## Copyright (c) The University of Edinburgh 2009. All Rights Reserved.
##
#!/bin/bash
#
# Script to test the NEMO output against the vanilla output to ensure that
# changes have not damaged the numerical output
#
# This script will generally be run via the serial queues as it could
# potentially take a number of minutes.
export PATH=$PATH:~/scripts
# Give list of files to be processed/created:
filelist="votemper vozocrtx vomecrty vovecrtz isssalin"
# VANILLA_OUTPUT_DIR = directory containing original NEMO 3.0 output
# created with netCDF 3.6.2 in Classic mode.
export VANILLA_OUTPUT_DIR=/work/n01/n01/fionanem/NEMO_V3.0/ORCA025/EXP_V3.0_005
# TEST_OUTPUT_DIR = directory containing test dataset
export TEST_OUTPUT_DIR=/work/n01/n01/fionanem/NEMO_V3.0/ORCA025/EXP_V3.0_015
# Check whether vanilla output exists and if not create it - we need one
# condition per file as different input data are involved for each test
cd $VANILLA_OUTPUT_DIR
for file in $filelist
do
if [ ! -e ${file}_ncdf3.nc ]
then
echo "Creating file ${file}_ncdf3.nc"
if [ $file = "votemper" ]
then
# echo "RUNNING get_parameters.sh O25-V3_CU30_19580101_19580101_grid_T_0000.nc 3 votemper"
get_parameters.sh O25-V3_CU30_19580101_19580101_grid_T_0000.nc 3 votemper
fi
if [ $file = "vozocrtx" ]
then
echo "Running..."
# echo "RUNNING get_parameters.sh O25-V3_CU30_19580101_19580101_grid_U_0000.nc 3 vozocrtx"
get_parameters.sh O25-V3_CU30_19580101_19580101_grid_U_0000.nc 3 vozocrtx
fi
if [ $file = "vomecrty" ]
then
echo "Running..."
# echo "RUNNING get_parameters.sh O25-V3_CU30_19580101_19580101_grid_V_0000.nc 3 vomecrty"
get_parameters.sh O25-V3_CU30_19580101_19580101_grid_V_0000.nc 3 vomecrty
fi
if [ $file = "vovecrtz" ]
then
echo "Running..."
# echo "RUNNING get_parameters.sh O25-V3_CU30_19580101_19580101_grid_W_0000.nc 3 vovecrtz"
get_parameters.sh O25-V3_CU30_19580101_19580101_grid_W_0000.nc 3 vovecrtz
fi
if [ $file = "isssalin" ]
then
echo "Running..."
# echo "RUNNING get_parameters.sh O25-V3_CU30_19580101_19580101_icemod_0000.nc 3 isssalin"
get_parameters.sh O25-V3_CU30_19580101_19580101_icemod_0000.nc 3 isssalin
fi
else
echo "The file ${file}_ncdf3.nc already exists"
fi
done
# Combine .nc files and create test datasets:
cd $TEST_OUTPUT_DIR
for file in $filelist
do
echo "About to remove file ${file}_ncdf4.nc before new run"
# Uncomment when running in batch/new tests
# rm ${file}_ncdf4.nc
done
# Uncomment for new run. All 5 files need to be created for each new test
get_parameters.sh O25-V3_CU30_19580101_19580101_grid_T_0000.nc 4 votemper
get_parameters.sh O25-V3_CU30_19580101_19580101_grid_U_0000.nc 4 vozocrtx
get_parameters.sh O25-V3_CU30_19580101_19580101_grid_V_0000.nc 4 vomecrty
get_parameters.sh O25-V3_CU30_19580101_19580101_grid_W_0000.nc 4 vovecrtz
get_parameters.sh O25-V3_CU30_19580101_19580101_icemod_0000.nc 4 isssalin
# Now we've extracted a dataset from each type of output file need to compare with
# The corresponding vanilla output and ensure the numerical values match up.
testoutputfile="test.output" # Contains output from the comparison
rm $TEST_OUTPUT_DIR/$testoutputfile # Remove old file before comparison
for file in $filelist
do
rm tmpfile # Ensure the tmpfile is removed prior to any comparison of the output
echo "Testing file = ${file}_ncdf3.txt" >> $testoutputfile
diff $VANILLA_OUTPUT_DIR/${file}_ncdf3.txt $TEST_OUTPUT_DIR/${file}_ncdf4.txt >> $testoutputfile
diff $VANILLA_OUTPUT_DIR/${file}_ncdf3.txt $TEST_OUTPUT_DIR/${file}_ncdf4.txt >> tmpfile
if [ -s tmpfile ]
then
echo "There is a difference between the test files" >> $testoutputfile
else
echo "No differences" >> $testoutputfile
fi
echo " " >> $testoutputfile
done
echo "*** All tests completed ***" >> $testoutputfile
# Tidy up - could remove tmpfile here to ensure it doesn't exist between tests.
# rm tmpfile
Source for get_parameters.sh
##
## Copyright (c) The University of Edinburgh 2009. All Rights Reserved.
##
#!/bin/bash
#
# Script to extract parameters from NEMO netCDF output so that
# output can be verified and compared etc
#
# $1 = name of the file series to be combined and tested
# e.g. ORCA025-N200_5d_19580101_19580101_grid_T_0000.nc
EXPECTED_ARGS=3
if [ $# -ne $EXPECTED_ARGS ]
then
echo " "
echo "Script for extracting parameters from NEMO netCDF output"
echo "so that output can be compared between runs"
echo " "
echo "Usage: `basename $0` {filename.nc netCDF_version(3 or 4), variable (e.g. votemper)}"
exit $E_BADARGS
fi
if [ $2 -ne 3 -a $2 -ne 4 ]
then
echo "You must specify whether the file is netCDF3 of netCDF4 format"
exit
fi
# Set paths to different versions of nocscombine/cdftools - need different
# versions for Classic and netCDF4 files - control selection with input $2
if [ $2 -eq 3 ]
then
export NOCSCOMB_EXE=/home/n01/n01/fionanem/NOCSCOMBINE/nocscombine
export CDFTOOLS_DIR=/home/n01/n01/fionanem/CDFTOOLS/bin
else
export NOCSCOMB_EXE=/home/n01/n01/fionanem/NOCSCOMBINE/nocscombine4_release_nozlib
export CDFTOOLS_DIR=/home/n01/n01/fionanem/CDFTOOLS/bin_nc4_release
fi
# Give the output netCDF file a name - name is based on variable being
# extracted $MYVAR and netCDF version (3 or 4)
export MYVAR=$3
export OUTFILE_NC=${MYVAR}_ncdf${2}.nc
export OUTFILE_TXT=${MYVAR}_ncdf${2}.txt
# Run NOCSCOMBINE to create large .nc file
echo "Running NOCSCOMBINE on $1 with $NOCSCOMB_EXE"
echo "DEBUG: RUNNING: $NOCSCOMB_EXE -f $1 -d $MYVAR -o $OUTFILE_NC"
$NOCSCOMB_EXE -f $1 -d $MYVAR -o $OUTFILE_NC
# Extract mean of variable using cdfmeanvar
echo "Running cdfmeanvar on $OUTFILE_NC, creating output $OUTFILE_TXT"
echo "DEBUG: RUNNING: $CDFTOOLS_DIR/cdfmeanvar $OUTFILE_NC $MYVAR T > $OUTFILE_TXT"
$CDFTOOLS_DIR/cdfmeanvar $OUTFILE_NC $MYVAR T > $OUTFILE_TXT