mirror of
https://github.com/Unidata/netcdf-c.git
synced 2025-02-05 16:20:10 +08:00
The netcdf-c code has to deal with a variety of platforms: Windows, OSX, Linux, Cygwin, MSYS, etc. These platforms differ significantly in the kind of file paths that they accept. So in order to handle this, I have created a set of replacements for the most common file system operations such as _open_ or _fopen_ or _access_ to manage the file path differences correctly. A more limited version of this idea was already implemented via the ncwinpath.h and dwinpath.c code. So this can be viewed as a replacement for that code. And in path in many cases, the only change that was required was to replace '#include <ncwinpath.h>' with '#include <ncpathmgt.h>' and then replace file operation calls with the NCxxx equivalent from ncpathmgr.h Note that recently, the ncwinpath.h was renamed ncpathmgmt.h, so this pull request should not require dealing with winpath. The heart of the change is include/ncpathmgmt.h, which provides alternate operations such as NCfopen or NCaccess and which properly parse and rebuild path arguments to work for the platform on which the code is executing. This mostly matters for Windows because of the way that it uses backslash and drive letters, as compared to *nix*. One important feature is that the user can do string manipulations on a file path without having to worry too much about the platform because the path management code will properly handle most mixed cases. So one can for example concatenate a path suffix that uses forward slashes to a Windows path and have it work correctly. The conversion code is in libdispatch/dpathmgr.c, and the important function there is NCpathcvt which does the proper conversions to the local path format. As a rule, most code should just replace their file operations with the corresponding NCxxx ones defined in include/ncpathmgmt.h. These NCxxx functions all call NCpathcvt on their path arguments before executing the actual file operation. In some rare cases, the client may need to directly use NCpathcvt, but this should be avoided as much as possible. If there is a need for supporting a new file operation not already in ncpathmgmt.h, then use the code in dpathmgr.c as a template. Also please notify Unidata so we can include it as a formal part or our supported operations. Also, if you see an operation in the library that is not using the NCxxx form, then please submit an issue so we can fix it. Misc. Changes: * Clean up the utf8 testing code; it is impossible to get some tests to work under windows using shell scripts; the args do not pass as utf8 but as some other encoding. * Added an extra utf8 test case: test_unicode_path.sh * Add a true test for HDF5 1.10.6 or later because as noted in PR https://github.com/Unidata/netcdf-c/pull/1794, HDF5 changed its Windows file path handling.
80 lines
2.8 KiB
Bash
Executable File
80 lines
2.8 KiB
Bash
Executable File
#!/bin/sh
|
|
# This shell script runs extra tests ncdump for netcdf-4
|
|
# Dennis Heimbigner, Ward Fisher
|
|
|
|
if test "x$srcdir" = x ; then srcdir=`pwd`; fi
|
|
. ../test_common.sh
|
|
|
|
set -e
|
|
|
|
# Remove the version information from _NCProperties
|
|
cleanncprops() {
|
|
src="$1"
|
|
dst="$2"
|
|
rm -f $dst
|
|
cat $src \
|
|
| sed -e '/:_Endianness/d' \
|
|
| sed -e 's/_SuperblockVersion = 1/_SuperblockVersion = 0/' \
|
|
| sed -e 's/\(netcdflibversion\|netcdf\)=.*|/\1=NNNN|/' \
|
|
| sed -e 's/\(hdf5libversion\|hdf5\)=.*"/\1=HHHH"/' \
|
|
| grep -v '_NCProperties' \
|
|
| cat >$dst
|
|
}
|
|
|
|
echo ""
|
|
echo "*** Running extra netcdf-4 tests."
|
|
|
|
#
|
|
# In windows, these tests fail because srcdir is prepended.
|
|
# e.g., Instead of 'ncdump ref_tst_compounds2' the file would
|
|
# contain:
|
|
# 'ncdump ./ref_tst_compounds2'. This causes the test to fail.
|
|
# But, 'srcdir' is necessary for make distcheck.
|
|
#
|
|
# Short term solution, use sed when on windows/MSYS to
|
|
# remove the './','../../ncdump'.
|
|
#
|
|
# I am undoing this because libdispatch/dwinpath.c
|
|
# should be taking care of this. If not, then that is
|
|
# what we need to fix. Alternatively, we can use top_srcdir,
|
|
# which is an absolute path
|
|
|
|
echo "*** running tst_string_data to create test files..."
|
|
${execdir}/tst_string_data
|
|
|
|
echo "*** dumping tst_string_data.nc to tst_string_data.cdl..."
|
|
${NCDUMP} tst_string_data.nc > tst_string_data.cdl
|
|
cleanncprops tst_string_data.cdl tst_string_data.tmp
|
|
cleanncprops ${srcdir}/ref_tst_string_data.cdl ref_tst_string_data.tmp
|
|
echo "*** comparing tst_string_data.cdl with ref_tst_string_data.cdl..."
|
|
diff -b tst_string_data.tmp ref_tst_string_data.tmp
|
|
|
|
#echo '*** testing non-coordinate variable of same name as dimension...'
|
|
#${NCGEN} -v4 -b -o tst_noncoord.nc ${top_srcdir}/ncdump/ref_tst_noncoord.cdl
|
|
|
|
echo '*** testing reference file ref_tst_compounds2.nc...'
|
|
${NCDUMP} ${top_srcdir}/ncdump/ref_tst_compounds2.nc > tst_compounds2.cdl
|
|
diff -b tst_compounds2.cdl ${top_srcdir}/ncdump/ref_tst_compounds2.cdl
|
|
|
|
echo '*** testing reference file ref_tst_compounds3.nc...'
|
|
${NCDUMP} ${top_srcdir}/ncdump/ref_tst_compounds3.nc > tst_compounds3.cdl
|
|
diff -b tst_compounds3.cdl ${top_srcdir}/ncdump/ref_tst_compounds3.cdl
|
|
|
|
echo '*** testing reference file ref_tst_compounds4.nc...'
|
|
${NCDUMP} ${top_srcdir}/ncdump/ref_tst_compounds4.nc > tst_compounds4.cdl
|
|
diff -b tst_compounds4.cdl ${top_srcdir}/ncdump/ref_tst_compounds4.cdl
|
|
|
|
# Exercise Jira NCF-213 bug fix
|
|
# rm -f tst_ncf213.cdl tst_ncf213.nc
|
|
# Remove specific _NCProperties values
|
|
${NCGEN} -b -o tst_ncf213.nc $srcdir/ref_tst_ncf213.cdl
|
|
${NCDUMP} -s -h tst_ncf213.nc > tst_ncf213.cdl
|
|
cleanncprops tst_ncf213.cdl tst_ncf213.tmp
|
|
cleanncprops ${srcdir}/ref_tst_ncf213.cdl ref_tst_ncf213.tmp
|
|
# Now compare
|
|
diff -b tst_ncf213.tmp ref_tst_ncf213.tmp
|
|
|
|
echo "*** All ncgen and ncdump extra test output for netCDF-4 format passed!"
|
|
exit 0
|
|
|