2018-08-13 13:01:08 +08:00
|
|
|
#!/bin/sh
|
2017-11-17 04:03:35 +08:00
|
|
|
# This shell script tests ncdump for netcdf-4
|
2017-12-19 05:26:33 +08:00
|
|
|
# Ed Hartnett, Dennis Heimbigner, Ward Fisher
|
2017-03-09 08:01:10 +08:00
|
|
|
|
2017-12-13 00:44:22 +08:00
|
|
|
if test "x$srcdir" = x ; then srcdir=`pwd`; fi
|
2017-03-09 08:01:10 +08:00
|
|
|
. ../test_common.sh
|
|
|
|
|
2010-06-03 21:24:43 +08:00
|
|
|
set -e
|
2012-05-12 04:26:11 +08:00
|
|
|
|
2018-08-26 11:44:41 +08:00
|
|
|
# Remove the version information from _NCProperties
|
|
|
|
cleanncprops() {
|
|
|
|
src="$1"
|
|
|
|
dst="$2"
|
|
|
|
rm -f $dst
|
|
|
|
cat $src \
|
|
|
|
| sed -e 's/_SuperblockVersion = 1/_SuperblockVersion = 0/' \
|
|
|
|
| sed -e 's/\(netcdflibversion\|netcdf\)=.*|/\1=NNNN|/' \
|
|
|
|
| sed -e 's/\(hdf5libversion\|hdf5\)=.*"/\1=HHHH"/' \
|
2018-09-07 05:53:25 +08:00
|
|
|
| grep -v '_NCProperties' \
|
2018-08-26 11:44:41 +08:00
|
|
|
| cat >$dst
|
|
|
|
}
|
|
|
|
|
2018-08-13 14:01:53 +08:00
|
|
|
ERR() {
|
2017-12-19 05:26:33 +08:00
|
|
|
RES=$?
|
|
|
|
if [ $RES -ne 0 ]; then
|
|
|
|
echo "Error found: $RES"
|
|
|
|
exit $RES
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2010-06-03 21:24:43 +08:00
|
|
|
echo ""
|
2017-11-25 19:31:58 +08:00
|
|
|
echo "*** Testing ncgen and ncdump for netCDF-4 format."
|
2017-12-19 05:26:33 +08:00
|
|
|
${NCGEN} -k nc4 -b -o tst_netcdf4_c0_4.nc ${ncgenc04} ;ERR
|
|
|
|
${NCDUMP} -n c1 tst_netcdf4_c0_4.nc | sed 's/e+0/e+/g' > tst_netcdf4_c1_4.cdl ; ERR
|
|
|
|
diff -b tst_netcdf4_c1_4.cdl $srcdir/ref_ctest1_nc4.cdl ; ERR
|
2010-06-03 21:24:43 +08:00
|
|
|
|
2017-11-25 20:19:11 +08:00
|
|
|
echo "*** Creating test output tst_netcdf4_c0.nc."
|
2017-12-19 05:26:33 +08:00
|
|
|
${NCGEN} -k nc7 -b -o tst_netcdf4_c0.nc ${ncgenc0} ; ERR
|
2014-09-19 08:26:06 +08:00
|
|
|
|
2017-11-25 20:19:11 +08:00
|
|
|
echo "*** Testing that program tst_h_rdc0 can read tst_netcdf4_c0.nc."
|
2017-12-19 05:26:33 +08:00
|
|
|
${execdir}/tst_h_rdc0 ; ERR
|
2017-11-17 04:03:35 +08:00
|
|
|
|
|
|
|
echo "*** Running tst_create_files.c to create test files."
|
2017-12-19 05:26:33 +08:00
|
|
|
${execdir}/tst_create_files ; ERR
|
2017-11-17 04:03:35 +08:00
|
|
|
echo "*** Testing tst_create_files output for netCDF-4 features."
|
2017-12-19 05:26:33 +08:00
|
|
|
${NCDUMP} tst_solar_1.nc | sed 's/e+0/e+/g' > tst_solar_1.cdl ; ERR
|
|
|
|
diff -b tst_solar_1.cdl $srcdir/ref_tst_solar_1.cdl ; ERR
|
|
|
|
${NCDUMP} tst_solar_2.nc | sed 's/e+0/e+/g' > tst_solar_2.cdl ; ERR
|
|
|
|
diff -b tst_solar_2.cdl $srcdir/ref_tst_solar_2.cdl ; ERR
|
2017-11-17 04:03:35 +08:00
|
|
|
|
|
|
|
echo "*** Running tst_group_data.c to create test files."
|
2017-12-19 05:26:33 +08:00
|
|
|
${execdir}/tst_group_data ; ERR
|
|
|
|
${NCDUMP} tst_group_data.nc | sed 's/e+0/e+/g' > tst_group_data.cdl ; ERR
|
|
|
|
diff -b tst_group_data.cdl $srcdir/ref_tst_group_data.cdl ; ERR
|
2012-05-12 04:26:11 +08:00
|
|
|
|
2012-06-13 05:50:02 +08:00
|
|
|
echo "*** Testing -v option with absolute name and groups..."
|
2017-12-19 05:26:33 +08:00
|
|
|
${NCDUMP} -v g2/g3/var tst_group_data.nc | sed 's/e+0/e+/g' > tst_group_data.cdl ; ERR
|
|
|
|
diff -b tst_group_data.cdl $srcdir/ref_tst_group_data_v23.cdl ; ERR
|
2012-05-12 04:26:11 +08:00
|
|
|
|
2012-06-13 05:50:02 +08:00
|
|
|
echo "*** Testing -v option with relative name and groups..."
|
2017-12-19 05:26:33 +08:00
|
|
|
${NCDUMP} -v var,var2 tst_group_data.nc | sed 's/e+0/e+/g' > tst_group_data.cdl ; ERR
|
|
|
|
diff -b tst_group_data.cdl $srcdir/ref_tst_group_data.cdl ; ERR
|
2017-11-17 04:03:35 +08:00
|
|
|
|
|
|
|
echo "*** Running tst_enum_data.c to create test files."
|
2017-12-19 05:26:33 +08:00
|
|
|
${execdir}/tst_enum_data ; ERR
|
|
|
|
${NCDUMP} tst_enum_data.nc | sed 's/e+0/e+/g' > tst_enum_data.cdl ; ERR
|
|
|
|
diff -b tst_enum_data.cdl $srcdir/ref_tst_enum_data.cdl ; ERR
|
2017-11-17 04:03:35 +08:00
|
|
|
|
|
|
|
echo "*** Running tst_opaque_data.c to create test files."
|
2017-12-19 05:26:33 +08:00
|
|
|
${execdir}/tst_opaque_data ; ERR
|
|
|
|
${NCDUMP} tst_opaque_data.nc | sed 's/e+0/e+/g' > tst_opaque_data.cdl ; ERR
|
|
|
|
diff -b tst_opaque_data.cdl $srcdir/ref_tst_opaque_data.cdl ; ERR
|
2017-11-17 04:03:35 +08:00
|
|
|
|
|
|
|
echo "*** Running tst_vlen_data.c to create test files."
|
2017-12-19 05:26:33 +08:00
|
|
|
${execdir}/tst_vlen_data ; ERR
|
|
|
|
${NCDUMP} tst_vlen_data.nc | sed 's/e+0/e+/g' > tst_vlen_data.cdl ; ERR
|
|
|
|
diff -b tst_vlen_data.cdl $srcdir/ref_tst_vlen_data.cdl ; ERR
|
2017-11-17 04:03:35 +08:00
|
|
|
|
|
|
|
echo "*** Running tst_comp.c to create test files."
|
2017-12-19 05:26:33 +08:00
|
|
|
${execdir}/tst_comp ; ERR
|
|
|
|
${NCDUMP} tst_comp.nc | sed 's/e+0/e+/g' > tst_comp.cdl ; ERR
|
|
|
|
diff -b tst_comp.cdl $srcdir/ref_tst_comp.cdl ; ERR
|
2017-11-17 04:03:35 +08:00
|
|
|
|
|
|
|
echo "*** Running tst_nans.c to create test files."
|
2017-12-19 05:26:33 +08:00
|
|
|
${execdir}/tst_nans ; ERR
|
|
|
|
${NCDUMP} tst_nans.nc | sed 's/e+0/e+/g' > tst_nans.cdl ; ERR
|
|
|
|
diff -b tst_nans.cdl $srcdir/ref_tst_nans.cdl ; ERR
|
2017-11-17 04:03:35 +08:00
|
|
|
|
2010-06-03 21:24:43 +08:00
|
|
|
# Do unicode test only if it exists => BUILD_UTF8 is true
|
|
|
|
if test -f ./tst_unicode -o -f ./tst_unicode.exe ; then
|
|
|
|
echo "*** dumping tst_unicode.nc to tst_unicode.cdl..."
|
2017-12-19 05:26:33 +08:00
|
|
|
${execdir}/tst_unicode ; ERR
|
|
|
|
${NCDUMP} tst_unicode.nc | sed 's/e+0/e+/g' > tst_unicode.cdl ; ERR
|
2010-06-03 21:24:43 +08:00
|
|
|
#echo "*** comparing tst_unicode.cdl with ref_tst_unicode.cdl..."
|
2012-05-09 03:36:27 +08:00
|
|
|
#diff -b tst_unicode.cdl $srcdir/ref_tst_unicode.cdl
|
2010-06-03 21:24:43 +08:00
|
|
|
fi
|
2017-11-17 04:03:35 +08:00
|
|
|
|
|
|
|
echo "*** Running tst_special_atts.c to create test files."
|
2017-12-19 05:26:33 +08:00
|
|
|
${execdir}/tst_special_atts ; ERR
|
2018-08-26 11:44:41 +08:00
|
|
|
${NCDUMP} -c -s tst_special_atts.nc > tst_special_atts.cdl ; ERR
|
|
|
|
cleanncprops tst_special_atts.cdl tst_special_atts.tmp
|
|
|
|
cleanncprops $srcdir/ref_tst_special_atts.cdl ref_tst_special_atts.tmp
|
2010-06-03 21:24:43 +08:00
|
|
|
echo "*** comparing tst_special_atts.cdl with ref_tst_special_atts.cdl..."
|
2018-08-26 11:44:41 +08:00
|
|
|
diff -b tst_special_atts.tmp ref_tst_special_atts.tmp ; ERR
|
2017-12-19 05:26:33 +08:00
|
|
|
|
|
|
|
#echo ""
|
|
|
|
#echo "*** Testing ncdump on file with corrupted header "
|
|
|
|
#rm -f ./ignore_tst_netcdf4
|
|
|
|
#if ${NCDUMP} ${srcdir}/ref_test_corrupt_magic.nc > ./ignore_tst_netcdf4 2>&1 ; then
|
|
|
|
#echo "***Fail: ncdump should have failed on ref_test_corrupt_magic.nc"
|
|
|
|
#else
|
|
|
|
#echo "***XFail: ncdump properly failed on ref_test_corrupt_magic.nc"
|
|
|
|
#fi
|
|
|
|
#rm -fr ./ignore_tst_netcdf4
|
re e-support UBS-599337
re pull request https://github.com/Unidata/netcdf-c/pull/405
re pull request https://github.com/Unidata/netcdf-c/pull/446
Notes:
1. This branch is a cleanup of the magic.dmh branch.
2. magic.dmh was originally merged, but caused problems with parallel IO.
It was re-issued as pull request https://github.com/Unidata/netcdf-c/pull/446.
3. This branch + pull request replace any previous pull requests and magic.dmh branch.
Given an otherwise valid netCDF file that has a corrupted header,
the netcdf library currently crashes. Instead, it should return
NC_ENOTNC.
Additionally, the NC_check_file_type code does not do the
forward search required by hdf5 files. It currently only looks
at file position 0 instead of 512, 1024, 2048,... Also, it turns
out that the HDF4 magic number is assumed to always be at the
beginning of the file (unlike HDF5).
The change is localized to libdispatch/dfile.c See
https://support.hdfgroup.org/release4/doc/DSpec_html/DS.pdf
Also, it turns out that the code in NC_check_file_type is duplicated
(mostly) in the function libsrc4/nc4file.c#nc_check_for_hdf.
This branch does the following.
1. Make NC_check_file_type return NC_ENOTNC instead of crashing.
2. Remove nc_check_for_hdf and centralize all file format checking
NC_check_file_type.
3. Add proper forward search for HDF5 files (but not HDF4 files)
to look for the magic number at offsets of 0, 512, 1024...
4. Add test tst_hdf5_offset.sh. This tests that hdf5 files with
an offset are properly recognized. It does so by prefixing
a legal file with some number of zero bytes: 512, 1024, etc.
5. Off-topic: Added -N flag to ncdump to force a specific output dataset name.
2017-10-25 06:25:09 +08:00
|
|
|
|
2018-05-15 22:24:27 +08:00
|
|
|
# This should work, but does not. See github issue 982.
|
|
|
|
#echo "*** creating tst_output_irish_rover.cdl from ref_tst_irish_rover.nc..."
|
2018-05-15 22:13:25 +08:00
|
|
|
#${NCDUMP} ref_tst_irish_rover.nc > tst_output_irish_rover.cdl
|
|
|
|
|
2018-08-26 11:44:41 +08:00
|
|
|
rm -f *.tmp
|
2010-06-03 21:24:43 +08:00
|
|
|
echo "*** All ncgen and ncdump test output for netCDF-4 format passed!"
|
|
|
|
exit 0
|