mirror of
https://github.com/Unidata/netcdf-c.git
synced 2025-03-25 17:40:27 +08:00
minor refactor of the build system to work better for cross-compiling
This commit is contained in:
parent
99aeb5d720
commit
965a3aac70
35
Makefile.am
35
Makefile.am
@ -12,7 +12,7 @@ ACLOCAL_AMFLAGS = -I m4
|
||||
|
||||
# These files get added to the distribution.
|
||||
EXTRA_DIST = README COPYRIGHT RELEASE_NOTES INSTALL test_prog.c \
|
||||
test_prog.F test_prog.f90
|
||||
test_prog.F test_prog.f90 lib_flags.am
|
||||
|
||||
pkgconfigdir=$(libdir)/pkgconfig
|
||||
pkgconfig_DATA = netcdf.pc
|
||||
@ -61,6 +61,7 @@ endif
|
||||
|
||||
# Is the user building netCDF-4?
|
||||
if USE_NETCDF4
|
||||
H5_TEST_DIR = h5_test
|
||||
LIBSRC4_DIR = libsrc4
|
||||
NC_TEST4 = nc_test4
|
||||
endif
|
||||
@ -105,8 +106,6 @@ if BUILD_CDMREMOTE
|
||||
LIBCDMR=libcdmr
|
||||
endif
|
||||
|
||||
#WIN32=win32
|
||||
|
||||
# This is the list of subdirs for which Makefiles will be constructed
|
||||
# and run. ncgen must come before ncdump and cxx, because their tests
|
||||
# depend on it. nf_test depends upon ncgen as well.
|
||||
@ -115,17 +114,17 @@ endif
|
||||
# built right before LIBSRC4_DIR.
|
||||
# If using dispatch, then the order is different
|
||||
if BUILD_SEPARATE_FORTRAN
|
||||
SUBDIRS = include $(UDUNITS) $(DISPATCHDIR) $(OCLIB) $(F90_DIR) \
|
||||
$(F77_DIR) $(LIBSRC_DIR) $(LIBSRC4_DIR) $(NCDAP3) $(NCDAP4) $(LIBCDMR) \
|
||||
${ASSEMBLEDIR} $(V2_TEST) $(NCGEN3) $(NCGEN) $(NCDUMP) $(F77_TEST) \
|
||||
${CXX_DIR} $(CXX4) $(NC_TEST_DIR) $(NC_TEST4) $(NCDAPTESTDIR) man4 \
|
||||
$(EXAMPLES) $(WIN32) $(LIBCF)
|
||||
SUBDIRS = include $(UDUNITS) $(H5_TEST_DIR) $(DISPATCHDIR) $(OCLIB) \
|
||||
$(F90_DIR) $(F77_DIR) $(LIBSRC_DIR) $(LIBSRC4_DIR) $(NCDAP3) $(NCDAP4) \
|
||||
$(LIBCDMR) ${ASSEMBLEDIR} $(V2_TEST) $(NCGEN3) $(NCGEN) $(NCDUMP) \
|
||||
$(F77_TEST) ${CXX_DIR} $(CXX4) $(NC_TEST4) $(NC_TEST_DIR) \
|
||||
$(NCDAPTESTDIR) man4 $(EXAMPLES) $(LIBCF)
|
||||
else
|
||||
SUBDIRS = include $(UDUNITS) $(DISPATCHDIR) $(OCLIB) $(F90_DIR) \
|
||||
$(F77_DIR) $(LIBSRC_DIR) $(LIBSRC4_DIR) $(NCDAP3) $(NCDAP4) $(LIBCDMR) \
|
||||
${ASSEMBLEDIR} $(V2_TEST) $(NCGEN3) $(NCGEN) $(NCDUMP) $(F77_TEST) \
|
||||
${CXX_DIR} $(CXX4) $(NC_TEST_DIR) $(NC_TEST4) $(NCDAPTESTDIR) man4 \
|
||||
$(EXAMPLES) $(WIN32) $(LIBCF)
|
||||
SUBDIRS = include $(UDUNITS) $(H5_TEST_DIR) $(DISPATCHDIR) $(OCLIB) \
|
||||
$(F90_DIR) $(F77_DIR) $(LIBSRC_DIR) $(LIBSRC4_DIR) $(NCDAP3) $(NCDAP4) \
|
||||
$(LIBCDMR) ${ASSEMBLEDIR} $(V2_TEST) $(NCGEN3) $(NCGEN) $(NCDUMP) \
|
||||
$(F77_TEST) ${CXX_DIR} $(CXX4) $(NC_TEST4) $(NC_TEST_DIR) \
|
||||
$(NCDAPTESTDIR) man4 $(EXAMPLES) $(LIBCF)
|
||||
endif
|
||||
|
||||
# Remove these generated files, for a distclean.
|
||||
@ -165,6 +164,14 @@ if BUILD_CXX
|
||||
BINFILES += include/netcdf.hh include/ncvalues.h include/netcdfcpp.h lib/libnetcdf_c++.a
|
||||
endif
|
||||
|
||||
if BUILD_DLL
|
||||
BINFILES += liblib/.libs/cygnetcdf-7.dll liblib/.libs/libnetcdf.dll.a \
|
||||
liblib/.libs/libnetcdf.a liblib/.libs/libnetcdf.la
|
||||
if BUILD_F77
|
||||
BINFILES +=
|
||||
endif # BUILD_F77
|
||||
endif # BUILD_DLL
|
||||
|
||||
# At Unidata, package up binaries.
|
||||
ftpbin: install
|
||||
echo "Getting binaries from ${prefix}"
|
||||
@ -174,7 +181,7 @@ ftpbin: install
|
||||
echo "CFLAGS=$(CFLAGS) CXXFLAGS=$(CXXFLAGS)" >> ${prefix}/README_BINARIES.txt
|
||||
echo "FCFLAGS=$(FCFLAGS) F77FLAGS=$(F77FLAGS) $F90FLAGS=$(F90FLAGS)" >> ${prefix}/README_BINARIES.txt
|
||||
which tar
|
||||
echo "PATH: $PATH"
|
||||
echo "PATH: $(PATH)"
|
||||
tar cf @BINFILE_NAME@ -C ${prefix} ${BINFILES}
|
||||
gzip -f @BINFILE_NAME@
|
||||
|
||||
|
98
configure.ac
98
configure.ac
@ -1170,118 +1170,78 @@ if test ! "x$PNETCDFDIR" = x; then
|
||||
CPPFLAGS="${CPPFLAGS} -I${PNETCDFDIR}/include"
|
||||
fi
|
||||
|
||||
# Check for the header.
|
||||
AC_CHECK_HEADERS([hdf5.h], [], [nc_hdf5_h_missing=yes])
|
||||
|
||||
# If HDF5 is not found, error out if the user specifically asked for
|
||||
# netcdf-4, otherwise just turn netCDF-4 off.
|
||||
if test "x$nc_hdf5_h_missing" = xyes; then
|
||||
# I think this should only check the
|
||||
# enable_netcdf4 flag
|
||||
# if test "x$enable_netcdf_4" = xyes -o "x$HDF5DIR" != x; then
|
||||
if test "x$enable_netcdf_4" = xyes ; then
|
||||
AC_MSG_ERROR([NetCDF-4 requires HDF5, but hdf5.h cannot be found. Try using \
|
||||
the --with-hdf5 option to specify location of HDF5.])
|
||||
else
|
||||
enable_netcdf_4=no
|
||||
fi
|
||||
else
|
||||
if test ! "x$enable_netcdf_4" = xno; then
|
||||
enable_netcdf_4=yes
|
||||
fi
|
||||
# If the user specified a HDF5 directory, assume they want netcdf-4
|
||||
# turned on.
|
||||
if test "x$HDF5DIR" != x; then
|
||||
enable_netcdf_4=yes
|
||||
fi
|
||||
|
||||
AC_MSG_CHECKING([whether we should try to build netCDF-4])
|
||||
AC_MSG_RESULT([$enable_netcdf_4])
|
||||
|
||||
if test "x$enable_netcdf_4" = xyes || test "x$enable_dap" = xyes; then
|
||||
AC_CHECK_LIB([z], [deflate], [], [nc_z_lib_missing=yes])
|
||||
if test "x$nc_z_lib_missing" = xyes; then
|
||||
AC_MSG_ERROR([Can't find or link to the z library. Configure with --with-zlib, or turn off netCDF-4 and \
|
||||
opendap with --disable-netcdf-4 --disable-dap, or see config.log for errors.])
|
||||
fi
|
||||
AC_CHECK_LIB([z], [deflate], [], [
|
||||
AC_MSG_ERROR([Can't find or link to the z library. Configure with --with-zlib, or turn off netCDF-4 and \
|
||||
opendap with --disable-netcdf-4 --disable-dap, or see config.log for errors.])])
|
||||
fi
|
||||
|
||||
|
||||
if test "x$enable_netcdf_4" = xyes; then
|
||||
AC_DEFINE([USE_NETCDF4], [1], [if true, build netCDF-4])
|
||||
AC_DEFINE([H5_USE_16_API], [1], [use HDF5 1.6 API])
|
||||
|
||||
# Check for the main hdf5 library.
|
||||
AC_CHECK_LIB([hdf5], [H5Fflush], [], [nc_hdf5_lib_missing=yes])
|
||||
if test "x$nc_hdf5_h_missing" = xyes || test "x$nc_hdf5_lib_missing" = xyes; then
|
||||
AC_MSG_ERROR([Can't find or link to the hdf5 library. Configure with --with-hdf5, or use \
|
||||
--disable-netcdf-4, or see config.log for errors.])
|
||||
fi
|
||||
AC_CHECK_LIB([hdf5], [H5Fflush], [], [AC_MSG_ERROR([Can't find or link to the hdf5 library. Configure with --with-hdf5, or use \
|
||||
--disable-netcdf-4, or see config.log for errors.])])
|
||||
|
||||
# We also require the HDF5 High Level library.
|
||||
AC_CHECK_LIB([hdf5_hl], [H5DSis_scale], [], [nc_hdf5_hl_lib_missing=yes])
|
||||
if test "x$nc_hdf5_hl_lib_missing" = xyes; then
|
||||
AC_MSG_ERROR([Can't find or link to the hdf5 high-level. Configure with --with-hdf5, or use \
|
||||
--disable-netcdf-4, or see config.log for errors.])
|
||||
fi
|
||||
|
||||
AC_CHECK_LIB([hdf5_hl], [H5DSis_scale], [], [AC_MSG_ERROR([Can't find or link to the hdf5 high-level. Configure with --with-hdf5, or use \
|
||||
--disable-netcdf-4, or see config.log for errors.])])
|
||||
|
||||
AC_CHECK_HEADERS([hdf5.h], [], [AC_MSG_ERROR([NetCDF-4 requires HDF5, but hdf5.h cannot be found. Try using \
|
||||
the --with-hdf5 option to specify location of HDF5.])])
|
||||
AC_CHECK_FUNCS([H5Pget_fapl_mpiposix H5Pget_fapl_mpio H5Pset_deflate H5Z_can_apply_szip])
|
||||
|
||||
# The user may have parallel HDF5 based on MPI POSIX.
|
||||
AC_CHECK_LIB([hdf5], [H5Pget_fapl_mpiposix], [enable_parallel_posix=yes], [])
|
||||
if test "x$enable_parallel_posix" = xyes; then
|
||||
if test "x$ac_cv_func_H5Pget_fapl_mpiposix" = xyes; then
|
||||
AC_DEFINE([USE_PARALLEL_POSIX], [1], [if true, compile in parallel netCDF-4 based on MPI/POSIX])
|
||||
fi
|
||||
|
||||
# The user may have parallel HDF5 based on MPI mumble mumble.
|
||||
AC_CHECK_LIB([hdf5], [H5Pget_fapl_mpio], [enable_parallel_mpio=yes], [])
|
||||
if test "x$enable_parallel_mpio" = xyes; then
|
||||
if test "x$ac_cv_func_H5Pget_fapl_mpio" = xyes; then
|
||||
AC_DEFINE([USE_PARALLEL_MPIO], [1], [if true, compile in parallel netCDF-4 based on MPI/IO])
|
||||
fi
|
||||
|
||||
# If parallel is in use, enable it in the C code. Also add some stuff to netcdf.h.
|
||||
enable_parallel=no
|
||||
# AC_MSG_CHECKING([how to modify netcdf.h to deal with parallel I/O])
|
||||
if test "x$enable_parallel_mpio" = xyes -o "x$enable_parallel_posix" = xyes; then
|
||||
if test "x$ac_cv_func_H5Pget_fapl_mpio" = xyes -o "x$ac_cv_func_H5Pget_fapl_mpiposix" = xyes; then
|
||||
enable_parallel=yes
|
||||
AC_DEFINE([USE_PARALLEL], [1], [if true, parallel netCDF-4 is in use])
|
||||
# Modify netcdf.h to include parallel stuff.
|
||||
# When doing distcheck, this cmd will fail because of
|
||||
# the permissions set on $top_builddir.
|
||||
# So, we forcibly reset the permissions
|
||||
#chmod u+w libsrc4/netcdf.h
|
||||
# sed '/#include <errno.h>/{G;s/$/\/* mpi.h included by configure. *\//;G;s/$/#include <mpi.h>/;}' libsrc4/netcdf_base.h > libsrc4/netcdf.h
|
||||
|
||||
# Using pnetcdf for classic parallel I/O?
|
||||
if test "x$enable_pnetcdf" = xyes; then
|
||||
AC_CHECK_LIB([pnetcdf], [ncmpi_create], [nc4_have_pnetcdf_lib=yes])
|
||||
if test "x$nc4_have_pnetcdf_lib" != xyes; then
|
||||
AC_MSG_ERROR([Cannot link to pnetcdf library, yet --enable-pnetcdf was used.])
|
||||
fi
|
||||
AC_CHECK_LIB([pnetcdf], [ncmpi_create], [],
|
||||
[AC_MSG_ERROR([Cannot link to pnetcdf library, yet --enable-pnetcdf was used.])])
|
||||
|
||||
dnl AC_CHECK_HEADERS([pnetcdf.h], [], [nc4_pnetcdf_h_missing=yes)
|
||||
dnl if test ! "x$HAVE_PNETCDF" = x1; then
|
||||
dnl AC_MSG_ERROR([Cannot find pnetcdf header, yet --enable-pnetcdf was used.])
|
||||
dnl fi
|
||||
AC_DEFINE([USE_PNETCDF], [1], [if true, parallel netCDF is used])
|
||||
fi
|
||||
# AC_MSG_RESULT([with parallel])
|
||||
# else
|
||||
# AC_MSG_RESULT([without parallel])
|
||||
# Modify netcdf.h to include defs for missing parallel stuff.
|
||||
# WARNING: the similar defs in libdispatch/ncdispatch.h must match this
|
||||
# When doing distcheck, this cmd will fail because of
|
||||
# the permissions set on $top_builddir.
|
||||
# So, we forcibly reset the permissions
|
||||
#chmod u+w libsrc4/netcdf.h
|
||||
# sed '/#include <errno.h>/{G;s/$/\/* These defs added by netCDF configure because parallel HDF5 is not present. *\//;G;s/$/#ifndef MPI_INCLUDED/;G;s/$/#define MPI_Comm int/;G;s/$/#define MPI_Info int/;G;s/$/#define MPI_COMM_WORLD 0/;G;s/$/#define MPI_INFO_NULL 0/;G;s/$/#endif/;}' libsrc4/netcdf_base.h > libsrc4/netcdf.h
|
||||
fi
|
||||
|
||||
AC_MSG_CHECKING([whether parallel I/O features are to be included])
|
||||
AC_MSG_RESULT([$enable_parallel])
|
||||
|
||||
# The user must have build HDF5 with the ZLIB library.
|
||||
AC_CHECK_LIB([hdf5], [H5Pset_deflate], [enable_zlib=yes], [])
|
||||
if test "x$enable_zlib" = xyes; then
|
||||
#AC_CHECK_LIB([hdf5], [H5Pset_deflate], [enable_zlib=yes], [])
|
||||
if test "x$ac_cv_func_H5Pset_deflate" = xyes; then
|
||||
AC_DEFINE([USE_ZLIB], [1], [if true, compile in zlib compression in netCDF-4 variables])
|
||||
fi
|
||||
|
||||
# The user must have build HDF5 with the ZLIB library.
|
||||
AC_CHECK_LIB([hdf5], [H5Z_can_apply_szip], [enable_szip=yes], [])
|
||||
if test "x$enable_szip" = xyes; then
|
||||
# AC_CHECK_LIB([hdf5], [H5Z_can_apply_szip], [enable_szip=yes], [])
|
||||
if test "x$ac_cv_func_H5Z_can_apply_szip" = xyes; then
|
||||
AC_DEFINE([USE_SZIP], [1], [if true, compile in szip compression in netCDF-4 variables])
|
||||
fi
|
||||
|
||||
@ -1294,11 +1254,6 @@ dnl fi
|
||||
AC_CHECK_LIB([mfhdf], [SDcreate], [], [])
|
||||
AC_DEFINE([USE_HDF4], [1], [if true, use HDF4 too])
|
||||
fi
|
||||
else
|
||||
# !netcdf-4
|
||||
# Modify netcdf.h to include defs for missing parallel stuff.
|
||||
#sed '/#include <errno.h>/{G;s/$/\/* These defs added by netCDF configure because parallel HDF5 is not present. *\//;G;s/$/#ifndef MPI_INCLUDED/;G;s/$/#define MPI_Comm int/;G;s/$/#define MPI_Info int/;G;s/$/#define MPI_COMM_WORLD 0/;G;s/$/#define MPI_INFO_NULL 0/;G;s/$/#endif/;}' libsrc4/netcdf_base.h > libsrc4/netcdf.h
|
||||
ignore=1;
|
||||
fi
|
||||
|
||||
# Restore LDFLAGS to it's old value.
|
||||
@ -1583,6 +1538,7 @@ AC_CONFIG_FILES([Makefile
|
||||
nc-config
|
||||
netcdf.pc
|
||||
include/Makefile
|
||||
h5_test/Makefile
|
||||
man4/Makefile
|
||||
fortran/Makefile
|
||||
libsrc/Makefile
|
||||
|
@ -6,39 +6,35 @@
|
||||
# $Id: Makefile.am,v 1.18 2010/05/29 00:20:16 dmh Exp $
|
||||
|
||||
# Point pre-preprocessor to netcdf-4 directory (libsrc4).
|
||||
AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/libsrc4
|
||||
AM_LDFLAGS =
|
||||
LDADD =
|
||||
|
||||
AM_CPPFLAGS += -I${top_srcdir}/liblib
|
||||
AM_LDFLAGS += ${top_builddir}/liblib/libnetcdf.la @EXTERN_LDFLAGS@
|
||||
LDADD += $(top_builddir)/cxx4/libnetcdf_c++4.la
|
||||
|
||||
# See comments in libsrc/Makefile.am about the version number.
|
||||
libnetcdf_c__4_la_LDFLAGS = $(AM_LDFLAGS) -version-info 1:1:0
|
||||
|
||||
# These headers will be installed in the users header directory.
|
||||
include_HEADERS = netcdf \
|
||||
ncAtt.h ncCheck.h ncDim.h ncException.h \
|
||||
ncGroup.h ncOpaqueType.h ncVar.h ncVlenType.h \
|
||||
ncCompoundType.h ncEnumType.h ncFile.h \
|
||||
ncGroupAtt.h ncType.h ncVarAtt.h \
|
||||
ncByte.h ncChar.h ncShort.h ncInt.h ncFloat.h ncDouble.h \
|
||||
ncUbyte.h ncUshort.h ncUint.h ncInt64.h ncUint64.h ncString.h
|
||||
AM_CPPFLAGS = -I$(top_srcdir)/include
|
||||
AM_LDFLAGS = ${top_builddir}/liblib/libnetcdf.la
|
||||
LDADD = $(top_builddir)/cxx4/libnetcdf_c++4.la \
|
||||
$(top_builddir)/liblib/libnetcdf.la
|
||||
|
||||
# This is our output library.
|
||||
lib_LTLIBRARIES = libnetcdf_c++4.la
|
||||
|
||||
# See comments in libsrc/Makefile.am about the version number.
|
||||
libnetcdf_c__4_la_LDFLAGS = -version-info 1:1:0
|
||||
libnetcdf_c__4_la_LIBADD = $(top_builddir)/liblib/libnetcdf.la
|
||||
|
||||
# These headers will be installed in the users header directory.
|
||||
include_HEADERS = netcdf ncAtt.h ncCheck.h ncDim.h ncException.h \
|
||||
ncGroup.h ncOpaqueType.h ncVar.h ncVlenType.h ncCompoundType.h \
|
||||
ncEnumType.h ncFile.h ncGroupAtt.h ncType.h ncVarAtt.h ncByte.h \
|
||||
ncChar.h ncShort.h ncInt.h ncFloat.h ncDouble.h ncUbyte.h ncUshort.h \
|
||||
ncUint.h ncInt64.h ncUint64.h ncString.h
|
||||
|
||||
# Library source.
|
||||
libnetcdf_c__4_la_SOURCES = \
|
||||
ncAtt.cpp ncCheck.cpp ncCompoundType.cpp ncDim.cpp ncEnumType.cpp \
|
||||
ncException.cpp ncFile.cpp ncGroup.cpp ncGroupAtt.cpp ncOpaqueType.cpp \
|
||||
ncType.cpp ncVar.cpp ncVarAtt.cpp ncVlenType.cpp \
|
||||
ncByte.cpp ncChar.cpp ncShort.cpp ncInt.cpp ncFloat.cpp ncDouble.cpp \
|
||||
ncUbyte.cpp ncUshort.cpp ncUint.cpp ncInt64.cpp ncUint64.cpp ncString.cpp
|
||||
libnetcdf_c__4_la_SOURCES = ncAtt.cpp ncCheck.cpp ncCompoundType.cpp \
|
||||
ncDim.cpp ncEnumType.cpp ncException.cpp ncFile.cpp ncGroup.cpp \
|
||||
ncGroupAtt.cpp ncOpaqueType.cpp ncType.cpp ncVar.cpp ncVarAtt.cpp \
|
||||
ncVlenType.cpp ncByte.cpp ncChar.cpp ncShort.cpp ncInt.cpp ncFloat.cpp \
|
||||
ncDouble.cpp ncUbyte.cpp ncUshort.cpp ncUint.cpp ncInt64.cpp \
|
||||
ncUint64.cpp ncString.cpp
|
||||
|
||||
|
||||
TESTFILES = test_group$(EXEEXT) test_dim$(EXEEXT) test_att$(EXEEXT) test_var$(EXEEXT) test_var2$(EXEEXT) test_type$(EXEEXT)
|
||||
TESTFILES = test_group$(EXEEXT) test_dim$(EXEEXT) test_att$(EXEEXT) \
|
||||
test_var$(EXEEXT) test_var2$(EXEEXT) test_type$(EXEEXT)
|
||||
test_group_SOURCES = test_group.cpp
|
||||
test_dim_SOURCES = test_dim.cpp
|
||||
test_att_SOURCES = test_att.cpp test_utilities.h
|
||||
@ -50,7 +46,7 @@ test_type_SOURCES = test_type.cpp test_utilities.h
|
||||
check_PROGRAMS = $(TESTFILES)
|
||||
TESTS = $(TESTFILES)
|
||||
|
||||
CLEANFILES=firstFile.cdf
|
||||
CLEANFILES = firstFile.cdf
|
||||
|
||||
# Empty file that gets time-stamped after docs are generated
|
||||
doxygen_stamp: $(libnetcdf_c__4_la_SOURCES) $(include_HEADERS)
|
||||
|
@ -5,8 +5,8 @@
|
||||
|
||||
# $Id: Makefile.am,v 1.60 2010/05/29 00:21:22 dmh Exp $
|
||||
|
||||
AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_builddir)/liblib @EXTERN_CFLAGS@
|
||||
AM_LDFLAGS = @EXTERN_LDFLAGS@
|
||||
AM_CPPFLAGS = -I$(top_srcdir)/include
|
||||
AM_LDFLAGS = #@EXTERN_LDFLAGS@
|
||||
|
||||
# May need to set this.
|
||||
libnetcdff_la_LIBADD =
|
||||
@ -88,7 +88,7 @@ endif
|
||||
|
||||
# If we are building the dll (under MinGW) then set the correct flags.
|
||||
if BUILD_DLL
|
||||
AM_CPPFLAGS += -DNC_DLL_EXPORT
|
||||
AM_CPPFLAGS += -DDLL_EXPORT
|
||||
endif
|
||||
|
||||
# The nfconfig.in file is turned into nfconfig.inc by the configure
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include <errno.h>
|
||||
|
||||
#include "netcdf.h"
|
||||
#include "netcdf_f.h"
|
||||
#include "nfconfig.inc"
|
||||
#include "ncfortran.h"
|
||||
|
||||
|
@ -21,7 +21,7 @@ $Id: fort-lib.c,v 1.15 2009/02/13 15:58:00 ed Exp $
|
||||
/*
|
||||
* Convert a C dimension-ID vector into a FORTRAN dimension-ID vector.
|
||||
*/
|
||||
NF_INTEGER*
|
||||
EXTERNL NF_INTEGER *
|
||||
c2f_dimids(int ncid, int varid, const int* cdimids, NF_INTEGER* fdimids)
|
||||
{
|
||||
int i;
|
||||
@ -40,7 +40,7 @@ c2f_dimids(int ncid, int varid, const int* cdimids, NF_INTEGER* fdimids)
|
||||
/*
|
||||
* Convert a FORTRAN dimension-ID vector into a C dimension-ID vector.
|
||||
*/
|
||||
int*
|
||||
EXTERNL int *
|
||||
f2c_dimids(int ndims, const NF_INTEGER* fdimids, int* cdimids)
|
||||
{
|
||||
int i;
|
||||
@ -52,7 +52,7 @@ f2c_dimids(int ndims, const NF_INTEGER* fdimids, int* cdimids)
|
||||
}
|
||||
|
||||
/* Convert a C dimension-ID vector into a FORTRAN dimension-ID vector. */
|
||||
NF_INTEGER *
|
||||
EXTERNL NF_INTEGER *
|
||||
c2f_chunksizes(int ncid, int varid, const int *cchunksizes, NF_INTEGER *fchunksizes)
|
||||
{
|
||||
int i;
|
||||
@ -68,7 +68,7 @@ c2f_chunksizes(int ncid, int varid, const int *cchunksizes, NF_INTEGER *fchunksi
|
||||
}
|
||||
|
||||
/* Convert a FORTRAN dimension-ID vector into a C dimension-ID vector. */
|
||||
int *
|
||||
EXTERNL int *
|
||||
f2c_chunksizes(int ncid, int varid, const NF_INTEGER *fchunksizes, int *cchunksizes)
|
||||
{
|
||||
int i;
|
||||
@ -86,9 +86,9 @@ f2c_chunksizes(int ncid, int varid, const NF_INTEGER *fchunksizes, int *cchunksi
|
||||
/*
|
||||
* Convert FORTRAN co-ordinates into C co-ordinates.
|
||||
*/
|
||||
size_t*
|
||||
EXTERNL size_t *
|
||||
f2c_coords(int ncid, int varid, const NF_INTEGER* fcoords,
|
||||
size_t* ccoords)
|
||||
size_t *ccoords)
|
||||
{
|
||||
int i;
|
||||
int ndims;
|
||||
@ -106,7 +106,7 @@ f2c_coords(int ncid, int varid, const NF_INTEGER* fcoords,
|
||||
/*
|
||||
* Convert FORTRAN counts into C counts.
|
||||
*/
|
||||
size_t*
|
||||
EXTERNL size_t *
|
||||
f2c_counts(int ncid, int varid, const NF_INTEGER* fcounts,
|
||||
size_t* ccounts)
|
||||
{
|
||||
@ -128,7 +128,7 @@ f2c_counts(int ncid, int varid, const NF_INTEGER* fcounts,
|
||||
*
|
||||
* Helper function.
|
||||
*/
|
||||
ptrdiff_t*
|
||||
EXTERNL ptrdiff_t *
|
||||
f2c_strides(int ncid, int varid, const NF_INTEGER* fstrides,
|
||||
ptrdiff_t* cstrides)
|
||||
{
|
||||
@ -148,7 +148,7 @@ f2c_strides(int ncid, int varid, const NF_INTEGER* fstrides,
|
||||
/*
|
||||
* Convert a FORTRAN mapping vector into a C mapping vector.
|
||||
*/
|
||||
ptrdiff_t*
|
||||
EXTERNL ptrdiff_t *
|
||||
f2c_maps(int ncid, int varid, const NF_INTEGER* fmaps, ptrdiff_t* cmaps)
|
||||
{
|
||||
return f2c_strides(ncid, varid, fmaps, cmaps);
|
||||
@ -159,7 +159,7 @@ f2c_maps(int ncid, int varid, const NF_INTEGER* fmaps, ptrdiff_t* cmaps)
|
||||
|
||||
/* Get the varids for a fortran function (i.e. add 1 to each
|
||||
* varid.) */
|
||||
int
|
||||
EXTERNL int
|
||||
nc_inq_varids_f(int ncid, int *nvars, int *fvarids)
|
||||
{
|
||||
int *varids, nvars1;
|
||||
@ -187,7 +187,7 @@ nc_inq_varids_f(int ncid, int *nvars, int *fvarids)
|
||||
}
|
||||
/* Get the dimids for a fortran function (i.e. add 1 to each
|
||||
* dimid.) */
|
||||
int
|
||||
EXTERNL int
|
||||
nc_inq_dimids_f(int ncid, int *ndims, int *fdimids, int parent)
|
||||
{
|
||||
int *dimids, ndims1;
|
||||
@ -215,7 +215,7 @@ nc_inq_dimids_f(int ncid, int *ndims, int *fdimids, int parent)
|
||||
}
|
||||
|
||||
/* Swap the dim sizes for fortran. */
|
||||
int
|
||||
EXTERNL int
|
||||
nc_insert_array_compound_f(int ncid, int typeid, char *name,
|
||||
size_t offset, nc_type field_typeid,
|
||||
int ndims, int *dim_sizesp)
|
||||
@ -243,7 +243,7 @@ nc_insert_array_compound_f(int ncid, int typeid, char *name,
|
||||
return ret;
|
||||
}
|
||||
|
||||
int
|
||||
EXTERNL int
|
||||
nc_inq_compound_field_f(int ncid, nc_type xtype, int fieldid, char *name,
|
||||
size_t *offsetp, nc_type *field_typeidp, int *ndimsp,
|
||||
int *dim_sizesp)
|
||||
|
@ -1,13 +1,17 @@
|
||||
/* $Id: fort-lib.h,v 1.7 2009/02/01 16:14:54 ed Exp $ */
|
||||
/* This is part of the netCDF package.
|
||||
Copyright 2011 University Corporation for Atmospheric Research/Unidata
|
||||
See COPYRIGHT file for conditions of use.
|
||||
|
||||
Includes prototypes for some functions used to translate parameters
|
||||
between C and Fortran.
|
||||
*/
|
||||
|
||||
#ifndef UD_FORT_LIB_H
|
||||
#define UD_FORT_LIB_H
|
||||
|
||||
|
||||
#include <stddef.h> /* for ptrdiff_t, size_t */
|
||||
#include "ncfortran.h"
|
||||
|
||||
#include <netcdf_f.h>
|
||||
|
||||
/*
|
||||
* PURPOSE: Convert a C dimension-ID vector into a FORTRAN dimension-ID
|
||||
@ -17,12 +21,11 @@
|
||||
* PROMISE: The order of the dimensions will be reversed and 1 will be
|
||||
* added to each element. RESULT == <fdimids>
|
||||
*/
|
||||
extern NF_INTEGER*
|
||||
EXTERNL NF_INTEGER *
|
||||
c2f_dimids(int ncid, /* netCDF dataset ID */
|
||||
int varid, /* netCDF variable ID */
|
||||
const int* cdimids, /* C dim IDs */
|
||||
NF_INTEGER* fdimids); /* FORTRAN dim IDs */
|
||||
|
||||
const int *cdimids, /* C dim IDs */
|
||||
NF_INTEGER *fdimids); /* FORTRAN dim IDs */
|
||||
|
||||
/*
|
||||
* PURPOSE: Convert a FORTRAN dimension-ID vector into a C dimension-ID
|
||||
@ -32,18 +35,20 @@ c2f_dimids(int ncid, /* netCDF dataset ID */
|
||||
* PROMISE: The order of the dimensions will be reversed and 1 will be
|
||||
* subtracted from each element. RESULT == <cdimids>
|
||||
*/
|
||||
extern int*
|
||||
f2c_dimids(int ndims, /* number of dims */
|
||||
const NF_INTEGER* fdimids, /* FORTRAN dim IDs */
|
||||
int* cdimids); /* C dim IDs */
|
||||
EXTERNL int *
|
||||
f2c_dimids(int ndims, /* number of dims */
|
||||
const NF_INTEGER *fdimids, /* FORTRAN dim IDs */
|
||||
int *cdimids); /* C dim IDs */
|
||||
|
||||
/* These two are the same as the dimids, but for chunksizes, so that 1
|
||||
* is not added/subtracted. */
|
||||
extern NF_INTEGER* c2f_chunksizes(int ncid, int varid, const int* cchunksizes,
|
||||
NF_INTEGER *fchunksizes);
|
||||
EXTERNL NF_INTEGER *
|
||||
c2f_chunksizes(int ncid, int varid, const int* cchunksizes,
|
||||
NF_INTEGER *fchunksizes);
|
||||
|
||||
extern int* f2c_chunksizes(int ncid, int varid, const NF_INTEGER *fchunksizes,
|
||||
int *cchunksizes);
|
||||
EXTERNL int *
|
||||
f2c_chunksizes(int ncid, int varid, const NF_INTEGER *fchunksizes,
|
||||
int *cchunksizes);
|
||||
|
||||
/*
|
||||
* PURPOSE: Convert a FORTRAN co-ordinate vector into a C co-ordinate vector
|
||||
@ -53,11 +58,11 @@ extern int* f2c_chunksizes(int ncid, int varid, const NF_INTEGER *fchunksizes,
|
||||
* PROMISE: The order of the co-ordinates will be reversed and 1 will be
|
||||
* subtracted from each element. RESULT == <ccoords>.
|
||||
*/
|
||||
extern size_t*
|
||||
f2c_coords(int ncid, /* dataset ID */
|
||||
int varid, /* variable ID */
|
||||
const NF_INTEGER* fcoords, /* FORTRAN coords */
|
||||
size_t* ccoords); /* C coords */
|
||||
EXTERNL size_t *
|
||||
f2c_coords(int ncid, /* dataset ID */
|
||||
int varid, /* variable ID */
|
||||
const NF_INTEGER *fcoords, /* FORTRAN coords */
|
||||
size_t *ccoords); /* C coords */
|
||||
|
||||
/*
|
||||
* PURPOSE: Convert a FORTRAN edge-count vector into a C edge-count vector
|
||||
@ -67,7 +72,7 @@ f2c_coords(int ncid, /* dataset ID */
|
||||
* PROMISE: The order of the edge-counts will be reversed.
|
||||
* RESULT == <ccounts>.
|
||||
*/
|
||||
extern size_t*
|
||||
EXTERNL size_t *
|
||||
f2c_counts(int ncid, /* dataset ID */
|
||||
int varid, /* variable ID */
|
||||
const NF_INTEGER* fcounts, /* FORTRAN counts */
|
||||
@ -80,11 +85,11 @@ f2c_counts(int ncid, /* dataset ID */
|
||||
* <fstrides> != <cstrides>
|
||||
* PROMISE: The order of the strides will be reversed. RESULT == <cstrides>.
|
||||
*/
|
||||
extern ptrdiff_t*
|
||||
EXTERNL ptrdiff_t *
|
||||
f2c_strides(int ncid, /* dataset ID */
|
||||
int varid, /* variable ID */
|
||||
const NF_INTEGER* fstrides, /* FORTRAN strides */
|
||||
ptrdiff_t* cstrides); /* C strides */
|
||||
const NF_INTEGER *fstrides, /* FORTRAN strides */
|
||||
ptrdiff_t *cstrides); /* C strides */
|
||||
|
||||
/*
|
||||
* PURPOSE: Convert a FORTRAN mapping vector into a C mapping vector
|
||||
@ -94,11 +99,11 @@ f2c_strides(int ncid, /* dataset ID */
|
||||
* PROMISE: The order of the mapping vector will be reversed.
|
||||
* RESULT == <cmaps>.
|
||||
*/
|
||||
extern ptrdiff_t*
|
||||
EXTERNL ptrdiff_t *
|
||||
f2c_maps(int ncid, /* dataset ID */
|
||||
int varid, /* variable ID */
|
||||
const NF_INTEGER* fmaps, /* FORTRAN mapping */
|
||||
ptrdiff_t* cmaps); /* C mapping */
|
||||
const NF_INTEGER *fmaps, /* FORTRAN mapping */
|
||||
ptrdiff_t *cmaps); /* C mapping */
|
||||
|
||||
|
||||
#endif /* header-file lockout */
|
||||
|
@ -13,23 +13,10 @@ $Id: fort-nc4.c,v 1.55 2010/01/19 18:31:43 ed Exp $
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
#include "netcdf.h"
|
||||
#include "netcdf_f.h"
|
||||
#include <ncfortran.h>
|
||||
#include <fort-lib.h>
|
||||
|
||||
/* Prototypes for some extra functions in fort-lib.c. */
|
||||
int nc_inq_varids_f(int ncid, int *nvars, int *fvarids);
|
||||
int nc_inq_dimids_f(int ncid, int *ndims, int *fdimids, int parent);
|
||||
int nc_insert_array_compound_f(int ncid, int typeid, char *name,
|
||||
size_t offset, nc_type field_typeid,
|
||||
int ndims, int *dim_sizesp);
|
||||
int nc_inq_compound_field_f(int ncid, nc_type xtype, int fieldid, char *name,
|
||||
size_t *offsetp, nc_type *field_typeidp, int *ndimsp,
|
||||
int *dim_sizesp);
|
||||
|
||||
/* These are in libsrc4/nc4vars.c... */
|
||||
int nc_inq_var_chunking_ints(int ncid, int varid, int *contiguousp, int *chunksizesp);
|
||||
int nc_def_var_chunking_ints(int ncid, int varid, int contiguous, int *chunksizes);
|
||||
|
||||
FCALLSCFUN5(NF_INT, nc_create_par_fortran, NF_CREATE_PAR, nf_create_par,
|
||||
STRING, FINT2CINT, FINT2CINT, FINT2CINT, PCINT2FINT)
|
||||
|
@ -1,5 +1,3 @@
|
||||
/* $Id: ncfortran.h,v 1.41 2010/04/05 17:29:17 ed Exp $ */
|
||||
|
||||
/*
|
||||
* This file contains `cfortran.h' definitions that are specific to the
|
||||
* netCDF-3 package.
|
||||
@ -9,10 +7,10 @@
|
||||
#ifndef UD_NCFORTRAN_H
|
||||
#define UD_NCFORTRAN_H
|
||||
|
||||
#include "netcdf_f.h"
|
||||
#include "cfortran.h"
|
||||
#include "nfconfig.inc"
|
||||
|
||||
|
||||
/*
|
||||
* The type of a Fortran INTEGER:
|
||||
*/
|
||||
|
56
h5_test/Makefile.am
Normal file
56
h5_test/Makefile.am
Normal file
@ -0,0 +1,56 @@
|
||||
# This is part of the netCDF package.
|
||||
# Copyright 2011 University Corporation for Atmospheric Research/Unidata
|
||||
# See COPYRIGHT file for conditions of use.
|
||||
#
|
||||
# This entire directory will be skipped, unless the configure script
|
||||
# is run with --enable-netcdf-4. This directory contains tests that
|
||||
# only use HDF5; these tests don't use netCDF at all.
|
||||
#
|
||||
# If one of these tests fails, then netCDF-4 will not work correctly.
|
||||
#
|
||||
|
||||
# Set AM_CPPFLAGS and AM_LDFLAGS based on user choices.
|
||||
include $(top_srcdir)/lib_flags.am
|
||||
|
||||
# These programs test HDF5 to make sure it will do (some of) the stuff
|
||||
# that netCDF-4 needs.
|
||||
H5TESTS = tst_h_files tst_h_files2 tst_h_files4 tst_h_atts \
|
||||
tst_h_atts3 tst_h_atts4 tst_h_vars tst_h_vars2 tst_h_vars3 tst_h_grps \
|
||||
tst_h_compounds tst_h_compounds2 tst_h_wrt_cmp tst_h_rd_cmp tst_h_vl \
|
||||
tst_h_opaques tst_h_strings tst_h_strings1 tst_h_strings2 tst_h_ints \
|
||||
tst_h_dimscales tst_h_dimscales1 tst_h_dimscales2 tst_h_dimscales3 \
|
||||
tst_h_enums
|
||||
|
||||
# List of tests to compile.
|
||||
check_PROGRAMS = $(H5TESTS)
|
||||
|
||||
# List of tests to run.
|
||||
TESTS = $(H5TESTS)
|
||||
|
||||
# The parallel program is run from a script.
|
||||
if TEST_PARALLEL
|
||||
check_PROGRAMS += tst_h_par
|
||||
TESTS += run_par_tests.sh
|
||||
endif
|
||||
|
||||
# This will run a bunch of the test programs with valgrind, the memory
|
||||
# checking tool. (Valgrind must be present for this to work.)
|
||||
if USE_VALGRIND_TESTS
|
||||
TESTS += run_valgrind_tests.sh
|
||||
endif # USE_VALGRIND_TESTS
|
||||
|
||||
# These libraries need to be linked to our tests.
|
||||
LDADD = -lhdf5_hl -lhdf5 -lz -lm
|
||||
|
||||
# We must include these files in the distribution.
|
||||
EXTRA_DIST = run_par_tests.sh run_valgrind_tests.sh \
|
||||
ref_tst_h_compounds.h5 ref_tst_h_compounds2.h5 run_par_tests.sh \
|
||||
run_valgrind_tests.sh ref_tst_compounds.nc
|
||||
|
||||
# Clean up test results.
|
||||
CLEANFILES = tst_h_*.h5
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -2,8 +2,6 @@
|
||||
|
||||
# This shell runs the tests with valgrind.
|
||||
|
||||
# $Id: run_valgrind_tests.sh,v 1.9 2010/01/26 20:24:18 ed Exp $
|
||||
|
||||
set -e
|
||||
echo ""
|
||||
echo "Testing programs with valgrind..."
|
||||
@ -14,15 +12,7 @@ list='tst_h_files tst_h_files2 tst_h_files4 tst_h_atts '\
|
||||
'tst_h_compounds tst_h_compounds2 tst_h_wrt_cmp tst_h_rd_cmp tst_h_vl '\
|
||||
'tst_h_opaques tst_h_strings tst_h_strings1 tst_h_strings2 tst_h_ints '\
|
||||
'tst_h_dimscales tst_h_dimscales1 tst_h_dimscales2 tst_h_dimscales3 '\
|
||||
'tst_h_enums tst_dims tst_dims2 tst_dims3 tst_files tst_files4 tst_vars '\
|
||||
'tst_varms tst_unlim_vars tst_converts tst_converts2 tst_grps '\
|
||||
'tst_compounds tst_compounds2 tst_compounds3 tst_opaques tst_strings '\
|
||||
'tst_strings2 tst_interops tst_interops4 tst_interops5 tst_interops6 '\
|
||||
'tst_enums tst_coords tst_coords2 tst_coords3 tst_vars3 tst_chunks '\
|
||||
'tst_utf8 tst_fills tst_fills2 tst_fillbug tst_xplatform '\
|
||||
'tst_h_atts2 tst_endian_fill tst_atts'
|
||||
|
||||
# These don't work yet: tst_grps2 tst_xplatform2
|
||||
'tst_h_enums'
|
||||
|
||||
for tst in $list; do
|
||||
echo ""
|
@ -5,13 +5,11 @@
|
||||
Test HDF5 file code. These are not intended to be exhaustive tests,
|
||||
but they use HDF5 the same way that netCDF-4 does, so if these
|
||||
tests don't work, than netCDF-4 won't work either.
|
||||
|
||||
$Id: tst_h_dimscales2.c,v 1.19 2010/06/01 15:34:51 ed Exp $
|
||||
*/
|
||||
#include <nc_tests.h>
|
||||
#include <hdf5.h>
|
||||
#include <H5DSpublic.h>
|
||||
#include <nc4internal.h>
|
||||
#include <ncdimscale.h>
|
||||
|
||||
#define FILE_NAME "tst_h_dimscales2.h5"
|
||||
#define DIMSCALE_NAME "dimscale"
|
@ -11,7 +11,8 @@
|
||||
#include <nc_tests.h>
|
||||
#include <hdf5.h>
|
||||
#include <H5DSpublic.h>
|
||||
#include <nc4internal.h>
|
||||
#include <hdf5.h>
|
||||
#include <ncdimscale.h>
|
||||
|
||||
#define FILE_NAME "tst_h_dimscales3.h5"
|
||||
#define DIMSCALE_NAME "dimscale"
|
@ -11,7 +11,7 @@
|
||||
#include <config.h>
|
||||
#include <nc_tests.h>
|
||||
#include "netcdf.h"
|
||||
#include <nc4internal.h>
|
||||
#include <hdf5.h>
|
||||
#include <H5DSpublic.h>
|
||||
|
||||
#define FILE_NAME "tst_h_files.h5"
|
@ -11,7 +11,7 @@
|
||||
#include <config.h>
|
||||
#include <nc_tests.h>
|
||||
#include "netcdf.h"
|
||||
#include <nc4internal.h>
|
||||
#include <hdf5.h>
|
||||
#include <H5DSpublic.h>
|
||||
|
||||
#define FILE_NAME "tst_h_files2.h5"
|
@ -11,7 +11,7 @@
|
||||
#include <config.h>
|
||||
#include <nc_tests.h>
|
||||
#include "netcdf.h"
|
||||
#include <nc4internal.h>
|
||||
#include <hdf5.h>
|
||||
#include <H5DSpublic.h>
|
||||
|
||||
#define FILE_NAME "tst_h_files4.h5"
|
@ -10,4 +10,6 @@ if BUILD_PARALLEL
|
||||
include_HEADERS += netcdf_par.h
|
||||
endif
|
||||
|
||||
noinst_HEADERS = nc_logging.h nc_tests.h
|
||||
noinst_HEADERS = nc_logging.h nc_tests.h fbits.h nc3dispatch.h nc.h \
|
||||
ncio.h nclist.h nc_url.h utf8proc.h ncdispatch.h ncdimscale.h \
|
||||
netcdf_f.h
|
||||
|
12
include/ncdimscale.h
Normal file
12
include/ncdimscale.h
Normal file
@ -0,0 +1,12 @@
|
||||
/* This is part of the netCDF package.
|
||||
Copyright 2011 University Corporation for Atmospheric Research/Unidata
|
||||
See COPYRIGHT file for conditions of use.
|
||||
|
||||
Includes for some HDF5 stuff needed by tests.
|
||||
*/
|
||||
|
||||
typedef struct hdf5_objid
|
||||
{
|
||||
unsigned long fileno[2]; /* file number */
|
||||
haddr_t objno[2]; /* object number */
|
||||
} HDF5_OBJID_T;
|
@ -1650,6 +1650,10 @@ nc_inq_base_pe(int ncid, int *pe);
|
||||
|
||||
/* #endif _CRAYMPP */
|
||||
|
||||
/* This v2 function is used in the nc_test program. */
|
||||
EXTERNL int
|
||||
nctypelen(nc_type datatype);
|
||||
|
||||
/* Begin v2.4 backward compatiblity */
|
||||
/*
|
||||
* defining NO_NETCDF_2 to the preprocessor
|
||||
@ -1703,9 +1707,6 @@ nc_advise(const char *cdf_routine_name, int err, const char *fmt,...);
|
||||
*/
|
||||
typedef int nclong;
|
||||
|
||||
EXTERNL int
|
||||
nctypelen(nc_type datatype);
|
||||
|
||||
EXTERNL int
|
||||
nccreate(const char* path, int cmode);
|
||||
|
||||
|
63
include/netcdf_f.h
Normal file
63
include/netcdf_f.h
Normal file
@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright 1993-2011 University Corporation for Atmospheric Research/Unidata
|
||||
*
|
||||
* This header contains prototypes for functions only called by fortran 77.
|
||||
*/
|
||||
#ifndef _NETCDF_F_
|
||||
#define _NETCDF_F_
|
||||
|
||||
#include <netcdf.h>
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
EXTERNL int
|
||||
nc_inq_var_chunking_ints(int ncid, int varid, int *contiguousp, int *chunksizesp);
|
||||
|
||||
EXTERNL int
|
||||
nc_def_var_chunking_ints(int ncid, int varid, int contiguous, int *chunksizesp);
|
||||
|
||||
EXTERNL int
|
||||
nc_open_par_fortran(const char *path, int mode, int comm,
|
||||
int info, int *ncidp);
|
||||
|
||||
EXTERNL int
|
||||
nc_create_par_fortran(const char *path, int cmode, int comm,
|
||||
int info, int *ncidp);
|
||||
|
||||
EXTERNL int
|
||||
nc_set_chunk_cache_ints(int size, int nelems, int preemption);
|
||||
|
||||
EXTERNL int
|
||||
nc_get_chunk_cache_ints(int *sizep, int *nelemsp, int *preemptionp);
|
||||
|
||||
EXTERNL int
|
||||
nc_set_var_chunk_cache_ints(int ncid, int varid, int size, int nelems,
|
||||
int preemption);
|
||||
EXTERNL int
|
||||
nc_get_var_chunk_cache_ints(int ncid, int varid, int *sizep,
|
||||
int *nelemsp, int *preemptionp);
|
||||
|
||||
/* Prototypes for some extra functions in fort-lib.c. */
|
||||
EXTERNL int
|
||||
nc_inq_varids_f(int ncid, int *nvars, int *fvarids);
|
||||
|
||||
EXTERNL int
|
||||
nc_inq_dimids_f(int ncid, int *ndims, int *fdimids, int parent);
|
||||
|
||||
EXTERNL int
|
||||
nc_insert_array_compound_f(int ncid, int typeid, char *name,
|
||||
size_t offset, nc_type field_typeid,
|
||||
int ndims, int *dim_sizesp);
|
||||
|
||||
EXTERNL int
|
||||
nc_inq_compound_field_f(int ncid, nc_type xtype, int fieldid, char *name,
|
||||
size_t *offsetp, nc_type *field_typeidp, int *ndimsp,
|
||||
int *dim_sizesp);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
44
lib_flags.am
Normal file
44
lib_flags.am
Normal file
@ -0,0 +1,44 @@
|
||||
# This is part of the netCDF package.
|
||||
# Copyright 2005 University Corporation for Atmospheric Research/Unidata
|
||||
# See COPYRIGHT file for conditions of use.
|
||||
#
|
||||
# Assemble the CPPFLAGS and LDFLAGS that point to all the needed
|
||||
# libraries for netCDF-4.
|
||||
#
|
||||
|
||||
AM_CPPFLAGS = -I$(top_srcdir)/include
|
||||
AM_LDFLAGS =
|
||||
|
||||
# If the user specified a root location for HDF5, use it.
|
||||
if USE_HDF5_DIR
|
||||
AM_CPPFLAGS += -I@HDF5DIR@/include
|
||||
AM_LDFLAGS += -L@HDF5DIR@/lib
|
||||
endif
|
||||
|
||||
# If the user specified a root location for ZLIB, use it.
|
||||
if USE_ZLIB_DIR
|
||||
AM_CPPFLAGS += -I@ZLIBDIR@/include
|
||||
AM_LDFLAGS += -L@ZLIBDIR@/lib
|
||||
endif
|
||||
|
||||
# If the user specified a root location for SZLIB, use it.
|
||||
if USE_SZLIB_DIR
|
||||
AM_CPPFLAGS += -I@SZLIBDIR@/include
|
||||
AM_LDFLAGS += -L@SZLIBDIR@/lib
|
||||
endif
|
||||
|
||||
# If the user specified a root location for pnetcdf, use it.
|
||||
if USE_PNETCDF_DIR
|
||||
AM_CPPFLAGS += -I@PNETCDFDIR@/include
|
||||
AM_LDFLAGS += -L@PNETCDFDIR@/lib
|
||||
endif
|
||||
|
||||
# If the user specified a root location for HDF4, use it.
|
||||
if USE_HDF4_DIR
|
||||
AM_CPPFLAGS += -I@HDF4DIR@/include
|
||||
AM_LDFLAGS += -L@HDF4DIR@/lib
|
||||
endif
|
||||
|
||||
if USE_DAP
|
||||
AM_CPPFLAGS += -I${top_srcdir}/oc
|
||||
endif
|
@ -7,27 +7,30 @@
|
||||
# code. It also contains code that sit above the dispatch layer, like
|
||||
# the v2 API.
|
||||
|
||||
# $Id: Makefile.am,v 1.10 2010/06/01 15:34:50 ed Exp $
|
||||
|
||||
# Set up include directories.
|
||||
AM_CPPFLAGS = -I${top_srcdir}/include -I${top_srcdir}/liblib -I${top_srcdir}/libsrc
|
||||
AM_CPPFLAGS = -I${top_srcdir}/include
|
||||
libdispatch_la_CPPFLAGS = ${AM_CPPFLAGS}
|
||||
|
||||
# This is our output, the dispatch convenience library.
|
||||
noinst_LTLIBRARIES = libdispatch.la
|
||||
|
||||
# The source files.
|
||||
libdispatch_la_SOURCES = ncdispatch.h parallel.c copy.c file.c dim.c \
|
||||
att.c error.c var.c dispatch.c
|
||||
libdispatch_la_SOURCES = parallel.c copy.c file.c dim.c att.c error.c \
|
||||
var.c dispatch.c
|
||||
|
||||
# Provide our own version of the oc/dapurl code so we can
|
||||
# handle new url-based protocols like cdmremote.
|
||||
libdispatch_la_SOURCES += nc_url.c nc_url.h
|
||||
libdispatch_la_SOURCES += nc_url.c
|
||||
|
||||
# These really contain common utility code used by more
|
||||
# than one later library.
|
||||
# TODO: move logging code here so it can be used anywhere.
|
||||
libdispatch_la_SOURCES += nclist.c nclist.h \
|
||||
ncbytes.c ncbytes.h
|
||||
libdispatch_la_SOURCES += nclist.c ncbytes.c ncbytes.h
|
||||
|
||||
# Turn on pre-processor flag when building a DLL for windows.
|
||||
if BUILD_DLL
|
||||
libdispatch_la_CPPFLAGS += -DDLL_EXPORT
|
||||
endif # BUILD_DLL
|
||||
|
||||
# Add functions only found in netCDF-4.
|
||||
if USE_NETCDF4
|
||||
|
@ -7,6 +7,8 @@
|
||||
"$Id: parallel.c,v 1.1 2010/06/01 15:46:50 ed Exp $"
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
#include <netcdf_f.h>
|
||||
#include "ncdispatch.h"
|
||||
|
||||
/* This function creates a file for use with parallel I/O. */
|
||||
|
@ -3,11 +3,10 @@
|
||||
Research/Unidata. See COPYRIGHT file for more info.
|
||||
|
||||
This file defines the variable functions.
|
||||
|
||||
"$Id: nc4.c,v 1.1 2010/06/01 15:46:50 ed Exp $"
|
||||
*/
|
||||
|
||||
#include "ncdispatch.h"
|
||||
#include "netcdf_f.h"
|
||||
|
||||
#if defined(__cplusplus)
|
||||
/* C++ consts default to internal linkage and must be initialized */
|
||||
|
@ -6,19 +6,20 @@
|
||||
# libraries have been built (e.g. libsrc, libsrc4, libncdap3, libcdmr,
|
||||
# libncdap4, fortran).
|
||||
|
||||
AM_LDFLAGS = @EXTERN_LDFLAGS@
|
||||
AM_CPPFLAGS = -I$(top_srcdir)/include -I${top_srcdir}/libsrc \
|
||||
-I${top_srcdir}/libdispatch
|
||||
libnetcdf_la_LIBADD =
|
||||
AM_CPPFLAGS = -I$(top_srcdir)/include
|
||||
libnetcdf_la_CPPFLAGS = ${AM_CPPFLAGS}
|
||||
|
||||
# This is our output, the netcdf library the user will install.
|
||||
lib_LTLIBRARIES = libnetcdf.la
|
||||
|
||||
# These linker flags specify libtool version info.
|
||||
libnetcdf_la_LDFLAGS = -version-number 7:0:1
|
||||
libnetcdf_la_LDFLAGS = -version-number 7:0:1
|
||||
libnetcdf_la_LIBADD =
|
||||
|
||||
# Turn on some extra stuff when building a DLL for windows.
|
||||
if BUILD_DLL
|
||||
libnetcdf_la_LDFLAGS += -no-undefined
|
||||
libnetcdf_la_LDFLAGS += -no-undefined -Wl,--output-def,netcdfdll.def
|
||||
libnetcdf_la_CPPFLAGS += -DDLL_EXPORT
|
||||
endif # BUILD_DLL
|
||||
|
||||
# The v2 API...
|
||||
|
@ -4,18 +4,43 @@
|
||||
# This automake file is in charge of building the libsrc directory,
|
||||
# which contains the classic library code.
|
||||
|
||||
# $Id: Makefile.am,v 2.98 2010/06/01 15:34:50 ed Exp $
|
||||
|
||||
# We may have to add to these later.
|
||||
AM_CPPFLAGS = -I$(top_srcdir)/include -I${top_srcdir}/liblib \
|
||||
-I${top_srcdir}/libsrc -I${top_srcdir}/libdispatch -I${top_srcdir}/oc \
|
||||
@EXTERN_CFLAGS@
|
||||
AM_LDFLAGS = @EXTERN_LDFLAGS@
|
||||
AM_CPPFLAGS = -I$(top_srcdir)/include
|
||||
libnetcdf3_la_CPPFLAGS = ${AM_CPPFLAGS}
|
||||
|
||||
# Turn on a pre-processor flag when building a DLL for windows.
|
||||
if BUILD_DLL
|
||||
libnetcdf3_la_CPPFLAGS += -DDLL_EXPORT
|
||||
endif # BUILD_DLL
|
||||
|
||||
# These files comprise the netCDF-3 classic library code.
|
||||
libnetcdf3_la_SOURCES = string.c v1hpg.c onstack.h rnd.h utf8proc.c \
|
||||
utf8proc_data.h nclistmgr.c putget.m4 attr.m4 nc3dispatch.c nc.c var.c \
|
||||
dim.c ncx.m4 ncx.h lookup3.c pstdint.h
|
||||
|
||||
# Does the user want to use ffio, a replacement for posixio for Cray
|
||||
# computers?
|
||||
if USE_FFIO
|
||||
libnetcdf3_la_SOURCES += ffio.c
|
||||
else
|
||||
libnetcdf3_la_SOURCES += posixio.c
|
||||
endif
|
||||
noinst_LTLIBRARIES = libnetcdf3.la
|
||||
|
||||
# These files are cleaned on developer workstations (and then rebuilt
|
||||
# with m4), but they are included in the distribution so that the user
|
||||
# does not have to have m4.
|
||||
MAINTAINERCLEANFILES = attr.c ncx.c putget.c $(man_MANS) attrx.c putgetx.c
|
||||
EXTRA_DIST = attr.c ncx.c putget.c $(man_MANS)
|
||||
|
||||
# This tells make how to turn .m4 files into .c files.
|
||||
.m4.c:
|
||||
m4 $(AM_M4FLAGS) $(M4FLAGS) $< >$@
|
||||
|
||||
# The C API man page.
|
||||
man_MANS = netcdf.3
|
||||
|
||||
# This rule generates the C manpage.
|
||||
# Decide what goes in the man page, based on user configure options.
|
||||
ARGS_MANPAGE = -DAPI=C
|
||||
if USE_NETCDF4
|
||||
ARGS_MANPAGE += -DNETCDF4=TRUE
|
||||
@ -27,41 +52,8 @@ if BUILD_PARALLEL
|
||||
ARGS_MANPAGE += -DPARALLEL_IO=TRUE
|
||||
endif
|
||||
|
||||
# This rule generates the C manpage.
|
||||
netcdf.3: $(top_srcdir)/man4/netcdf.m4
|
||||
m4 $(M4FLAGS) $(ARGS_MANPAGE) $? >$@ || rm $@
|
||||
|
||||
# These files are part of the netCDF-3 library.
|
||||
libnetcdf3_la_SOURCES = nc.h string.c v1hpg.c fbits.h ncio.h onstack.h \
|
||||
rnd.h utf8proc.c utf8proc.h utf8proc_data.h nclistmgr.c putget.m4 \
|
||||
attr.m4 nc3dispatch.c nc3dispatch.h nc.c var.c dim.c ncx.m4 ncx.h \
|
||||
lookup3.c pstdint.h
|
||||
|
||||
# Does the user want to use ffio or posixio?
|
||||
if USE_FFIO
|
||||
libnetcdf3_la_SOURCES += ffio.c
|
||||
else
|
||||
libnetcdf3_la_SOURCES += posixio.c
|
||||
endif
|
||||
noinst_LTLIBRARIES = libnetcdf3.la
|
||||
|
||||
# Define library for local test programs to use
|
||||
LDADD = ${top_builddir}/libsrc/libnetcdf3.la stub3.lo \
|
||||
${top_builddir}/libdispatch/libdispatch.la
|
||||
|
||||
if USE_DAP
|
||||
LDADD += ${top_builddir}/oc/liboc.la
|
||||
endif
|
||||
|
||||
# These files are cleaned on developer workstations (and then rebuilt
|
||||
# with m4), but they are included in the distribution so that the user
|
||||
# does not have to have m4.
|
||||
MAINTAINERCLEANFILES = attr.c ncx.c putget.c $(man_MANS) attrx.c putgetx.c
|
||||
EXTRA_DIST = attr.c ncx.c putget.c $(man_MANS) stub3.c
|
||||
|
||||
# This tells make how to turn .m4 files into .c files.
|
||||
.m4.c:
|
||||
m4 $(AM_M4FLAGS) $(M4FLAGS) $< >$@
|
||||
|
||||
.PHONY: visualstudio
|
||||
visualstudio:
|
||||
sh ${abs_top_srcdir}/visualbuild add ${abs_srcdir} "${libnetcdf3_la_SOURCES}"
|
||||
|
@ -1,23 +0,0 @@
|
||||
/*********************************************************************
|
||||
* Copyright 2010, UCAR/Unidata
|
||||
* See netcdf/COPYRIGHT file for copying and redistribution conditions.
|
||||
*********************************************************************/
|
||||
|
||||
/* $Id: stub3.c,v 1.4 2010/05/24 19:48:16 dmh Exp $ */
|
||||
/* $Header: /upc/share/CVS/netcdf-3/libsrc/stub3.c,v 1.4 2010/05/24 19:48:16 dmh Exp $ */
|
||||
|
||||
#include "config.h"
|
||||
#include "netcdf.h"
|
||||
|
||||
/* Need to re-direct certain functions that are
|
||||
duplicated in netcdf4
|
||||
*/
|
||||
|
||||
extern int NC3_initialize(void);
|
||||
|
||||
int
|
||||
NC_initialize(void)
|
||||
{
|
||||
NC3_initialize();
|
||||
return NC_NOERR;
|
||||
}
|
@ -5,17 +5,11 @@
|
||||
# generated makefile is not run unless the user selected to build
|
||||
# netCDF-4.
|
||||
|
||||
# $Id: Makefile.am,v 1.194 2010/06/01 15:34:50 ed Exp $
|
||||
include $(top_srcdir)/lib_flags.am
|
||||
|
||||
# Initialize
|
||||
AM_CPPFLAGS = -I$(top_srcdir)/include @EXTERN_CFLAGS@ \
|
||||
-I${top_srcdir}/libsrc -I${top_srcdir}/libdispatch
|
||||
AM_LDFLAGS = @EXTERN_LDFLAGS@
|
||||
LDADD =
|
||||
|
||||
if USE_DAP
|
||||
AM_CPPFLAGS += -I${top_srcdir}/oc
|
||||
endif
|
||||
libnetcdf4_la_CPPFLAGS = ${AM_CPPFLAGS}
|
||||
|
||||
# Netcdf-4 source.
|
||||
NC4SOURCES = nc4internal.h error4.c nc4dispatch.c nc4dispatch.h \
|
||||
@ -26,88 +20,29 @@ nc4internal.c nc4hdf.c
|
||||
noinst_LTLIBRARIES = libnetcdf4.la
|
||||
libnetcdf4_la_SOURCES = ${NC4SOURCES}
|
||||
|
||||
# These linker flags will be applied to all test program compiles.
|
||||
# Currently we cannot get away from loading libnetcdf3.la and libnetcdf2.la
|
||||
# and various other things
|
||||
LDADD += stub4.lo ${top_builddir}/libsrc4/libnetcdf4.la \
|
||||
${top_builddir}/libsrc/libnetcdf3.la \
|
||||
${top_builddir}/libdispatch/libdispatch.la
|
||||
|
||||
if USE_DAP
|
||||
LDADD += ${top_builddir}/oc/liboc.la
|
||||
endif
|
||||
if BUILD_V2
|
||||
LDADD += ${top_builddir}/libdispatch/libnetcdf2.la
|
||||
endif
|
||||
|
||||
# tst_h_strings3 core dumps! Ed 11/10/10
|
||||
NC4_TESTS = tst_h_files tst_h_files2 tst_h_files4 tst_h_atts \
|
||||
tst_h_atts3 tst_h_atts4 tst_h_vars tst_h_vars2 tst_h_vars3 tst_h_grps \
|
||||
tst_h_compounds tst_h_compounds2 tst_h_wrt_cmp tst_h_rd_cmp tst_h_vl \
|
||||
tst_h_opaques tst_h_strings tst_h_strings1 tst_h_strings2 tst_h_ints \
|
||||
tst_h_dimscales tst_h_dimscales1 tst_h_dimscales2 tst_h_dimscales3 \
|
||||
tst_h_enums tst_dims tst_dims2 tst_dims3 tst_files tst_files4 tst_vars \
|
||||
tst_varms tst_unlim_vars tst_converts tst_converts2 tst_grps tst_grps2 \
|
||||
tst_compounds tst_compounds2 tst_compounds3 tst_opaques tst_strings \
|
||||
tst_strings2 tst_interops tst_interops4 tst_interops5 tst_interops6 \
|
||||
tst_enums tst_coords tst_coords2 tst_coords3 tst_vars3 tst_vars4 \
|
||||
tst_chunks tst_chunks2 tst_utf8 tst_fills tst_fills2 tst_fillbug \
|
||||
tst_xplatform tst_xplatform2 tst_h_atts2 tst_endian_fill tst_atts
|
||||
|
||||
check_PROGRAMS = $(NC4_TESTS)
|
||||
if LARGE_FILE_TESTS
|
||||
check_PROGRAMS += tst_large tst_large2
|
||||
endif
|
||||
|
||||
# The parallel program is run from a script.
|
||||
if TEST_PARALLEL
|
||||
check_PROGRAMS += tst_h_par
|
||||
endif
|
||||
|
||||
TESTS = $(NC4_TESTS)
|
||||
|
||||
EXTRA_DIST = ref_tst_compounds.nc ref_tst_h_compounds.h5 \
|
||||
ref_tst_h_compounds2.h5 run_par_tests.sh run_valgrind_tests.sh \
|
||||
run_hdf4_valgrind_tests.sh ref_tst_xplatform2_1.nc \
|
||||
ref_tst_xplatform2_2.nc ref_tst_dims.nc ref_tst_interops4.nc stub4.c
|
||||
|
||||
# These linker flags will be applied to all test program compiles.
|
||||
LDADD += ${lib_LTLIBRARIES}
|
||||
# Tell libtool what libraries are we will depend on.
|
||||
libnetcdf4_la_LIBADD =
|
||||
|
||||
# HDF4 used?
|
||||
if USE_HDF4
|
||||
LDADD += -lmfhdf -ldf -ljpeg
|
||||
libnetcdf4_la_LIBADD += -lmfhdf -ldf
|
||||
endif # USE_HDF4
|
||||
|
||||
LDADD += -lhdf5_hl -lhdf5 -lz -lm
|
||||
|
||||
# How about pnetcdf?
|
||||
if USE_PNETCDF
|
||||
LDADD += -lpnetcdf
|
||||
libnetcdf4_la_LIBADD += -lpnetcdf
|
||||
endif # USE_PNETCDF
|
||||
|
||||
# Always link to hdf5_hl, hdf5, and z.
|
||||
libnetcdf4_la_LIBADD += -lhdf5_hl -lhdf5 -lz
|
||||
|
||||
# This turns on declspec magic in netcdf.h for windows DLLs.
|
||||
if BUILD_DLL
|
||||
libnetcdf4_la_CPPFLAGS += -DDLL_EXPORT
|
||||
endif
|
||||
|
||||
# This script will run all the parallel test programs.
|
||||
if TEST_PARALLEL
|
||||
TESTS += run_par_tests.sh
|
||||
endif
|
||||
|
||||
# Add this if --enable-benchmarks was used.
|
||||
if BUILD_BENCHMARKS
|
||||
TESTS += tst_files2 tst_files3 tst_ar5 tst_h_files3
|
||||
check_PROGRAMS += tst_files2 tst_files3 tst_ar5 tst_h_files3
|
||||
endif # BUILD_BENCHMARKS
|
||||
|
||||
# This will run a bunch of the test programs with valgrind, the memory
|
||||
# checking tool. (Valgrind must be present for this to work.)
|
||||
if USE_VALGRIND_TESTS
|
||||
TESTS += run_valgrind_tests.sh
|
||||
if USE_HDF4
|
||||
TESTS += run_hdf4_valgrind_tests.sh
|
||||
endif # USE_HDF4
|
||||
endif # USE_VALGRIND_TESTS
|
||||
|
||||
# Clean up. Each test program creates one data file, with the same
|
||||
# name as the test program, and either a .h5 or .nc, for "pure" HDF5
|
||||
# files and netCDF-4 files.
|
||||
CLEANFILES = tst_nc_converts.nc tst_h_*.h5 tst_*.nc tst_interops*.h5 \
|
||||
tst_interops2.h4 tst_interops4.nc AMSR_E_* MYD29.A2*
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#include <hdf5.h>
|
||||
#include <ncdimscale.h>
|
||||
#include <nc_logging.h>
|
||||
|
||||
#ifdef USE_PARALLEL
|
||||
@ -28,6 +29,7 @@
|
||||
#define MPI_Comm int
|
||||
#include <netcdf.h>
|
||||
#endif /* USE_PARALLEL */
|
||||
#include <netcdf_f.h>
|
||||
|
||||
#ifdef USE_HDF4
|
||||
#include <mfhdf.h>
|
||||
@ -133,12 +135,6 @@ typedef struct NC_ATT_INFO
|
||||
int class;
|
||||
} NC_ATT_INFO_T;
|
||||
|
||||
typedef struct hdf5_objid
|
||||
{
|
||||
unsigned long fileno[2]; /* file number */
|
||||
haddr_t objno[2]; /* object number */
|
||||
} HDF5_OBJID_T;
|
||||
|
||||
/* This is a struct to handle the var metadata. */
|
||||
typedef struct NC_VAR_INFO
|
||||
{
|
||||
|
@ -237,93 +237,6 @@ check_chunksizes(NC_GRP_INFO_T *grp, NC_VAR_INFO_T *var, const size_t *chunksize
|
||||
return NC_NOERR;
|
||||
}
|
||||
|
||||
/* Find the default chunk nelems (i.e. length of chunk along each
|
||||
* dimension). */
|
||||
static int
|
||||
nc4_find_default_chunksizes(NC_GRP_INFO_T *grp, NC_VAR_INFO_T *var)
|
||||
{
|
||||
int d, max_dim;
|
||||
size_t type_size, max_len = 0;
|
||||
float num_values = 1, num_set = 0;
|
||||
float total_chunk_size;
|
||||
int retval;
|
||||
|
||||
if (var->type_info->nc_typeid == NC_STRING)
|
||||
type_size = sizeof(char *);
|
||||
else
|
||||
type_size = var->type_info->size;
|
||||
|
||||
/* Later this will become the total number of bytes in the default
|
||||
* chunk. */
|
||||
total_chunk_size = type_size;
|
||||
|
||||
/* How many values in the variable (or one record, if there are
|
||||
* unlimited dimensions); which is the largest dimension, and how
|
||||
* long is it? */
|
||||
for (d = 0; d < var->ndims; d++)
|
||||
{
|
||||
assert(var->dim[d]);
|
||||
if (var->dim[d]->len)
|
||||
num_values *= (float)var->dim[d]->len;
|
||||
else
|
||||
num_set++;
|
||||
|
||||
if (var->dim[d]->len > max_len)
|
||||
{
|
||||
max_len = var->dim[d]->len;
|
||||
max_dim = d;
|
||||
}
|
||||
LOG((4, "d = %d max_dim %d max_len %ld num_values %f", d, max_dim, max_len,
|
||||
num_values));
|
||||
}
|
||||
|
||||
/* If a dim is several orders of magnitude smaller than the max
|
||||
* dimension, set it's chunk size to the full extent of the smaller
|
||||
* dimension. */
|
||||
#define NC_DIM_MULTIPLIER 1000
|
||||
for (d = 0; d < var->ndims; d++)
|
||||
if (var->dim[d]->unlimited)
|
||||
var->chunksizes[d] = 1;
|
||||
else if (!var->dim[d]->unlimited && var->dim[d]->len * NC_DIM_MULTIPLIER < max_len)
|
||||
{
|
||||
var->chunksizes[d] = var->dim[d]->len;
|
||||
num_set++;
|
||||
}
|
||||
|
||||
/* Pick a chunk length for each dimension, if one has not already
|
||||
* been picked above. */
|
||||
for (d = 0; d < var->ndims; d++)
|
||||
if (!var->chunksizes[d])
|
||||
{
|
||||
size_t suggested_size;
|
||||
suggested_size = (pow((double)DEFAULT_CHUNK_SIZE/(num_values * type_size),
|
||||
1/(double)(var->ndims - num_set)) * var->dim[d]->len - .5);
|
||||
if (suggested_size > var->dim[d]->len)
|
||||
suggested_size = var->dim[d]->len;
|
||||
var->chunksizes[d] = suggested_size ? suggested_size : 1;
|
||||
total_chunk_size *= var->chunksizes[d];
|
||||
LOG((4, "nc_def_var_nc4: name %s dim %d DEFAULT_CHUNK_SIZE %d num_values %f type_size %d "
|
||||
"chunksize %ld", var->name, d, DEFAULT_CHUNK_SIZE, num_values, type_size, var->chunksizes[d]));
|
||||
}
|
||||
LOG((4, "total_chunk_size %f", total_chunk_size));
|
||||
|
||||
/* But did this add up to a chunk that is too big? */
|
||||
retval = check_chunksizes(grp, var, var->chunksizes);
|
||||
if (retval)
|
||||
{
|
||||
/* Other error? */
|
||||
if (retval != NC_EBADCHUNK)
|
||||
return retval;
|
||||
|
||||
/* Chunk is too big! Reduce each dimension by half and try again. */
|
||||
for ( ; retval == NC_EBADCHUNK; retval = check_chunksizes(grp, var, var->chunksizes))
|
||||
for (d = 0; d < var->ndims; d++)
|
||||
var->chunksizes[d] /= 2;
|
||||
}
|
||||
|
||||
return NC_NOERR;
|
||||
}
|
||||
|
||||
/* Find the default chunk nelems (i.e. length of chunk along each
|
||||
* dimension). */
|
||||
static int
|
||||
|
@ -1,104 +0,0 @@
|
||||
/* This is part of the netCDF package.
|
||||
Copyright 2006 University Corporation for Atmospheric Research/Unidata.
|
||||
See COPYRIGHT file for conditions of use.
|
||||
|
||||
This is a very simple example which writes a netCDF file with
|
||||
Unicode names encoded with UTF-8. It is the NETCDF3 equivalent
|
||||
of tst_unicode.c
|
||||
|
||||
$Id$
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
#include <stdlib.h>
|
||||
#include <nc_tests.h>
|
||||
#include <netcdf.h>
|
||||
#include <string.h>
|
||||
|
||||
/* The data file we will create. */
|
||||
#define FILE_NAME "tst_atts.nc"
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
printf("\n*** Testing netCDF-4 attributes.\n");
|
||||
printf("*** testing attribute renaming for a global attribute...");
|
||||
{
|
||||
#define OLD_NAME "Constantinople"
|
||||
#define NEW_NAME "Istanbul"
|
||||
#define CONTENTS "Lots of people!"
|
||||
|
||||
int ncid, attid;
|
||||
char *data_in;
|
||||
|
||||
if (!(data_in = malloc(strlen(CONTENTS) + 1))) ERR;
|
||||
|
||||
/* Create a file with an att. */
|
||||
if (nc_create(FILE_NAME, NC_NETCDF4|NC_CLOBBER, &ncid)) ERR;
|
||||
if (nc_put_att_text(ncid, NC_GLOBAL, OLD_NAME, strlen(CONTENTS),
|
||||
CONTENTS)) ERR;
|
||||
|
||||
/* Rename the att. */
|
||||
if (nc_rename_att(ncid, NC_GLOBAL, OLD_NAME, NEW_NAME)) ERR;
|
||||
|
||||
/* Check the file. */
|
||||
if (nc_inq_attid(ncid, NC_GLOBAL, NEW_NAME, &attid)) ERR;
|
||||
if (attid != 0) ERR;
|
||||
if (nc_get_att_text(ncid, NC_GLOBAL, NEW_NAME, data_in)) ERR;
|
||||
if (strncmp(CONTENTS, data_in, strlen(CONTENTS))) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
/* Reopen the file and check again. */
|
||||
if (nc_open(FILE_NAME, NC_NOWRITE, &ncid)) ERR;
|
||||
|
||||
if (nc_inq_attid(ncid, NC_GLOBAL, NEW_NAME, &attid)) ERR;
|
||||
if (attid != 0) ERR;
|
||||
if (nc_get_att_text(ncid, NC_GLOBAL, NEW_NAME, data_in)) ERR;
|
||||
if (strncmp(CONTENTS, data_in, strlen(CONTENTS))) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
free(data_in);
|
||||
}
|
||||
SUMMARIZE_ERR;
|
||||
printf("*** testing attribute renaming for a variable attribute...");
|
||||
{
|
||||
#define VAR_NAME "var_name"
|
||||
#define OLD_NAME1 "Constantinople"
|
||||
#define NEW_NAME1 "Istanbul____________"
|
||||
#define CONTENTS1 "Lots of people!"
|
||||
|
||||
int ncid, attid, varid;
|
||||
char *data_in;
|
||||
|
||||
if (!(data_in = malloc(strlen(CONTENTS1) + 1))) ERR;
|
||||
|
||||
/* Create a file with an att. */
|
||||
if (nc_create(FILE_NAME, NC_NETCDF4|NC_CLOBBER, &ncid)) ERR;
|
||||
if (nc_def_var(ncid, VAR_NAME, NC_INT, 0, NULL, &varid)) ERR;
|
||||
if (nc_put_att_text(ncid, varid, OLD_NAME1, strlen(CONTENTS1),
|
||||
CONTENTS1)) ERR;
|
||||
|
||||
/* Rename the att. */
|
||||
if (nc_rename_att(ncid, varid, OLD_NAME1, NEW_NAME1)) ERR;
|
||||
|
||||
/* Check the file. */
|
||||
if (nc_inq_attid(ncid, varid, NEW_NAME1, &attid)) ERR;
|
||||
if (attid != 0) ERR;
|
||||
if (nc_get_att_text(ncid, varid, NEW_NAME1, data_in)) ERR;
|
||||
if (strncmp(CONTENTS1, data_in, strlen(CONTENTS1))) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
/* Reopen the file and check again. */
|
||||
if (nc_open(FILE_NAME, NC_NOWRITE, &ncid)) ERR;
|
||||
|
||||
if (nc_inq_attid(ncid, varid, NEW_NAME1, &attid)) ERR;
|
||||
if (attid != 0) ERR;
|
||||
if (nc_get_att_text(ncid, varid, NEW_NAME1, data_in)) ERR;
|
||||
if (strncmp(CONTENTS1, data_in, strlen(CONTENTS1))) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
free(data_in);
|
||||
}
|
||||
SUMMARIZE_ERR;
|
||||
FINAL_RESULTS;
|
||||
}
|
@ -1,257 +0,0 @@
|
||||
/* This is part of the netCDF package.
|
||||
Copyright 2005 University Corporation for Atmospheric Research/Unidata
|
||||
See COPYRIGHT file for conditions of use.
|
||||
|
||||
Test netcdf-4 variables.
|
||||
$Id: tst_chunks.c,v 1.3 2010/01/21 16:00:18 ed Exp $
|
||||
*/
|
||||
|
||||
#include <nc_tests.h>
|
||||
|
||||
#define FILE_NAME "tst_chunks.nc"
|
||||
#define NDIMS1 1
|
||||
#define D_SMALL "small_dim"
|
||||
#define D_SMALL_LEN 16
|
||||
#define D_MEDIUM "medium_dim"
|
||||
#define D_MEDIUM_LEN 65546
|
||||
#define D_LARGE "large_dim"
|
||||
#define D_LARGE_LEN 1048586
|
||||
#define V_SMALL "small_var"
|
||||
#define V_MEDIUM "medium_var"
|
||||
#define V_LARGE "large_var"
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
|
||||
printf("\n*** Testing netcdf-4 variable chunking.\n");
|
||||
printf("**** testing that fixed vars with filter end up being chunked, with good sizes...");
|
||||
{
|
||||
|
||||
int ncid;
|
||||
int nvars, ndims, ngatts, unlimdimid;
|
||||
int contig;
|
||||
int ndims_in, natts_in, dimids_in;
|
||||
int small_dimid, medium_dimid, large_dimid;
|
||||
int small_varid, medium_varid, large_varid;
|
||||
char var_name_in[NC_MAX_NAME + 1];
|
||||
size_t chunksize_in[NDIMS1];
|
||||
nc_type xtype_in;
|
||||
|
||||
/* Create a netcdf-4 file with three dimensions. */
|
||||
if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
|
||||
if (nc_def_dim(ncid, D_SMALL, D_SMALL_LEN, &small_dimid)) ERR;
|
||||
if (nc_def_dim(ncid, D_MEDIUM, D_MEDIUM_LEN, &medium_dimid)) ERR;
|
||||
if (nc_def_dim(ncid, D_LARGE, D_LARGE_LEN, &large_dimid)) ERR;
|
||||
|
||||
/* Add three vars, with filters to force chunking. */
|
||||
if (nc_def_var(ncid, V_SMALL, NC_INT64, NDIMS1, &small_dimid, &small_varid)) ERR;
|
||||
if (nc_def_var_deflate(ncid, small_varid, 0, 1, 4)) ERR;
|
||||
if (nc_def_var(ncid, V_MEDIUM, NC_INT64, NDIMS1, &medium_dimid, &medium_varid)) ERR;
|
||||
if (nc_def_var_deflate(ncid, medium_varid, 1, 0, 0)) ERR;
|
||||
if (nc_def_var(ncid, V_LARGE, NC_INT64, NDIMS1, &large_dimid, &large_varid)) ERR;
|
||||
if (nc_def_var_fletcher32(ncid, large_varid, 1)) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
/* Open the file and check. */
|
||||
if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR;
|
||||
if (nc_inq(ncid, &ndims, &nvars, &ngatts, &unlimdimid)) ERR;
|
||||
if (nvars != 3 || ndims != 3 || ngatts != 0 || unlimdimid != -1) ERR;
|
||||
if (nc_inq_var(ncid, 0, var_name_in, &xtype_in, &ndims_in, &dimids_in, &natts_in)) ERR;
|
||||
if (strcmp(var_name_in, V_SMALL) || xtype_in != NC_INT64 || ndims_in != 1 ||
|
||||
natts_in != 0) ERR;
|
||||
|
||||
/* Make sure chunking sizes are what we expect. */
|
||||
if (nc_inq_var_chunking(ncid, small_varid, &contig, chunksize_in)) ERR;
|
||||
if (contig || chunksize_in[0] != D_SMALL_LEN) ERR;
|
||||
if (nc_inq_var_chunking(ncid, medium_varid, &contig, chunksize_in)) ERR;
|
||||
if (contig || chunksize_in[0] * sizeof(long long) > DEFAULT_CHUNK_SIZE) ERR;
|
||||
if (nc_inq_var_chunking(ncid, large_varid, &contig, chunksize_in)) ERR;
|
||||
if (contig || chunksize_in[0] * sizeof(long long) > DEFAULT_CHUNK_SIZE) ERR;
|
||||
|
||||
if (nc_close(ncid)) ERR;
|
||||
}
|
||||
SUMMARIZE_ERR;
|
||||
printf("**** printing table of default chunksizes...");
|
||||
{
|
||||
int nvars, ndims, ngatts, unlimdimid;
|
||||
int contig;
|
||||
#define NUM_DIM 4
|
||||
#define NUM_TYPE 2
|
||||
int ncid;
|
||||
int dim_len[NUM_DIM] = {NC_UNLIMITED, 100, 1000, 2000};
|
||||
size_t chunksize_in[NUM_DIM];
|
||||
int type_id[NUM_TYPE] = {NC_BYTE, NC_INT};
|
||||
int dimid[NUM_DIM], varid[NUM_TYPE];
|
||||
char dim_name[NC_MAX_NAME + 1], var_name[NC_MAX_NAME + 1];
|
||||
int d, t;
|
||||
|
||||
/* Create a netcdf-4 file with NUM_DIM dimensions. */
|
||||
if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
|
||||
for (d = 0; d < NUM_DIM; d++)
|
||||
{
|
||||
sprintf(dim_name, "dim_%d", dim_len[d]);
|
||||
printf("creating dim %s\n", dim_name);
|
||||
if (nc_def_dim(ncid, dim_name, dim_len[d], &dimid[d])) ERR;
|
||||
}
|
||||
|
||||
for (t = 0; t < NUM_TYPE; t++)
|
||||
{
|
||||
sprintf(var_name, "var_%d", type_id[t]);
|
||||
if (nc_def_var(ncid, var_name, type_id[t], NUM_DIM, dimid, &varid[t])) ERR;
|
||||
if (nc_inq_var_chunking(ncid, varid[t], &contig, chunksize_in)) ERR;
|
||||
printf("chunksizes for %d x %d x %d x %d var: %d x %d x %d x %d (=%d)\n",
|
||||
dim_len[0], dim_len[1], dim_len[2], dim_len[3],
|
||||
(int)chunksize_in[0], (int)chunksize_in[1], (int)chunksize_in[2],
|
||||
(int)chunksize_in[3],
|
||||
(int)(chunksize_in[0] * chunksize_in[1] * chunksize_in[2] * chunksize_in[3]));
|
||||
}
|
||||
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
/* Open the file and check. */
|
||||
if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR;
|
||||
if (nc_inq(ncid, &ndims, &nvars, &ngatts, &unlimdimid)) ERR;
|
||||
if (nvars != NUM_TYPE || ndims != NUM_DIM || ngatts != 0 || unlimdimid != 0) ERR;
|
||||
|
||||
for (t = 0; t < NUM_TYPE; t++)
|
||||
{
|
||||
sprintf(var_name, "var_%d", type_id[t]);
|
||||
if (nc_inq_var_chunking(ncid, varid[t], &contig, chunksize_in)) ERR;
|
||||
if (contig) ERR;
|
||||
printf("chunksizes for %d x %d x %d x %d var: %d x %d x %d x %d (=%d)\n",
|
||||
dim_len[0], dim_len[1], dim_len[2], dim_len[3],
|
||||
(int)chunksize_in[0], (int)chunksize_in[1], (int)chunksize_in[2],
|
||||
(int)chunksize_in[3],
|
||||
(int)(chunksize_in[0] * chunksize_in[1] * chunksize_in[2] * chunksize_in[3]));
|
||||
}
|
||||
|
||||
if (nc_close(ncid)) ERR;
|
||||
}
|
||||
SUMMARIZE_ERR;
|
||||
printf("**** testing that chunking works on classic mode files...");
|
||||
{
|
||||
#define D_SMALL_LEN2 66
|
||||
int ncid;
|
||||
int nvars, ndims, ngatts, unlimdimid;
|
||||
int contig;
|
||||
int ndims_in, natts_in, dimids_in;
|
||||
int small_dimid, medium_dimid, large_dimid;
|
||||
int small_varid, medium_varid, large_varid;
|
||||
char var_name_in[NC_MAX_NAME + 1];
|
||||
size_t chunks[1], chunksize_in;
|
||||
nc_type xtype_in;
|
||||
|
||||
/* Create a netcdf-4 file with three dimensions. */
|
||||
if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
|
||||
if (nc_def_dim(ncid, D_SMALL, D_SMALL_LEN2, &small_dimid)) ERR;
|
||||
if (nc_def_dim(ncid, D_MEDIUM, D_MEDIUM_LEN, &medium_dimid)) ERR;
|
||||
if (nc_def_dim(ncid, D_LARGE, D_LARGE_LEN, &large_dimid)) ERR;
|
||||
|
||||
/* Add three vars. */
|
||||
if (nc_def_var(ncid, V_SMALL, NC_INT64, NDIMS1, &small_dimid, &small_varid)) ERR;
|
||||
if (nc_def_var_chunking(ncid, small_varid, 1, NULL)) ERR;
|
||||
|
||||
if (nc_def_var(ncid, V_MEDIUM, NC_INT64, NDIMS1, &medium_dimid, &medium_varid)) ERR;
|
||||
chunks[0] = D_MEDIUM_LEN / 100;
|
||||
if (nc_def_var_chunking(ncid, medium_varid, 0, chunks)) ERR;
|
||||
if (nc_def_var_deflate(ncid, medium_varid, 1, 0, 0)) ERR;
|
||||
|
||||
if (nc_def_var(ncid, V_LARGE, NC_INT64, NDIMS1, &large_dimid, &large_varid)) ERR;
|
||||
chunks[0] = D_LARGE_LEN / 1000;
|
||||
if (nc_def_var_chunking(ncid, large_varid, 0, chunks)) ERR;
|
||||
if (nc_def_var_fletcher32(ncid, large_varid, 1)) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
/* Open the file and check. */
|
||||
if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR;
|
||||
if (nc_inq(ncid, &ndims, &nvars, &ngatts, &unlimdimid)) ERR;
|
||||
if (nvars != 3 || ndims != 3 || ngatts != 0 || unlimdimid != -1) ERR;
|
||||
if (nc_inq_var(ncid, 0, var_name_in, &xtype_in, &ndims_in, &dimids_in, &natts_in)) ERR;
|
||||
if (strcmp(var_name_in, V_SMALL) || xtype_in != NC_INT64 || ndims_in != 1 ||
|
||||
natts_in != 0) ERR;
|
||||
|
||||
/* Make sure chunking settings are what we expect. */
|
||||
if (nc_inq_var_chunking(ncid, small_varid, &contig, &chunksize_in)) ERR;
|
||||
if (!contig) ERR;
|
||||
if (nc_inq_var_chunking(ncid, medium_varid, &contig, &chunksize_in)) ERR;
|
||||
if (contig || chunksize_in != D_MEDIUM_LEN / 100) ERR;
|
||||
if (nc_inq_var_chunking(ncid, large_varid, &contig, &chunksize_in)) ERR;
|
||||
if (contig || chunksize_in != D_LARGE_LEN / 1000) ERR;
|
||||
|
||||
if (nc_close(ncid)) ERR;
|
||||
}
|
||||
SUMMARIZE_ERR;
|
||||
printf("**** testing many chunking and contiguous variables...");
|
||||
{
|
||||
#define NDIMS_3 3
|
||||
#define NUM_PLANS 30
|
||||
#define D_SNEAKINESS "sneakiness"
|
||||
#define D_SNEAKINESS_LEN 5
|
||||
#define D_CLEVERNESS "clevernesss"
|
||||
#define D_CLEVERNESS_LEN 3
|
||||
#define D_EFFECTIVENESS "effectiveness"
|
||||
#define D_EFFECTIVENESS_LEN 2
|
||||
|
||||
int ncid, dimids[NDIMS_3], varid[NUM_PLANS];
|
||||
size_t chunksize[NDIMS_3] = {D_SNEAKINESS_LEN, D_CLEVERNESS_LEN,
|
||||
D_EFFECTIVENESS_LEN};
|
||||
char plan_name[NC_MAX_NAME + 1];
|
||||
int contig;
|
||||
size_t chunksize_in[NDIMS_3];
|
||||
int i, j;
|
||||
|
||||
/* Create a netcdf-4 file with three dimensions. */
|
||||
if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
|
||||
if (nc_def_dim(ncid, D_SNEAKINESS, D_SNEAKINESS_LEN, &dimids[0])) ERR;
|
||||
if (nc_def_dim(ncid, D_CLEVERNESS, D_CLEVERNESS_LEN, &dimids[1])) ERR;
|
||||
if (nc_def_dim(ncid, D_EFFECTIVENESS, D_EFFECTIVENESS_LEN, &dimids[2])) ERR;
|
||||
|
||||
/* Oh that tricky Cardinal Richelieu, he had many plans! */
|
||||
for (i = 0; i < NUM_PLANS; i++)
|
||||
{
|
||||
sprintf(plan_name, "Richelieu_sneaky_plan_%d", i);
|
||||
if (nc_def_var(ncid, plan_name, i % (NC_STRING - 1) + 1, NDIMS_3,
|
||||
dimids, &varid[i])) ERR;
|
||||
if (i % 2 && nc_def_var_chunking(ncid, varid[i], 0, chunksize)) ERR;
|
||||
}
|
||||
|
||||
/* Check the chunking. */
|
||||
for (i = 0; i < NUM_PLANS; i++)
|
||||
{
|
||||
if (nc_inq_var_chunking(ncid, varid[i], &contig, chunksize_in)) ERR;
|
||||
if (i % 2)
|
||||
{
|
||||
for (j = 0; j < NDIMS_3; j++)
|
||||
if (chunksize_in[j] != chunksize[j]) ERR;
|
||||
}
|
||||
else
|
||||
if (!contig) ERR;
|
||||
}
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
/* Open the file and check. */
|
||||
if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR;
|
||||
/* Check the chunking. */
|
||||
for (i = 0; i < NUM_PLANS; i++)
|
||||
{
|
||||
if (nc_inq_var_chunking(ncid, varid[i], &contig, chunksize_in)) ERR;
|
||||
if (i % 2)
|
||||
{
|
||||
for (j = 0; j < NDIMS_3; j++)
|
||||
if (chunksize_in[j] != chunksize[j]) ERR;
|
||||
}
|
||||
else
|
||||
if (!contig) ERR;
|
||||
}
|
||||
if (nc_close(ncid)) ERR;
|
||||
}
|
||||
SUMMARIZE_ERR;
|
||||
FINAL_RESULTS;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -1,551 +0,0 @@
|
||||
/* This is part of the netCDF package.
|
||||
Copyright 2005 University Corporation for Atmospheric Research/Unidata
|
||||
See COPYRIGHT file for conditions of use.
|
||||
|
||||
Test internal netcdf-4 file code.
|
||||
$Id: tst_files.c,v 1.42 2010/05/18 12:30:05 ed Exp $
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
#include <nc4internal.h>
|
||||
#include "netcdf.h"
|
||||
#include <nc_tests.h>
|
||||
|
||||
#ifdef IGNORE
|
||||
extern NC_FILE_INFO_T *nc_file;
|
||||
#endif
|
||||
int test_redef(int format);
|
||||
|
||||
#define FILE_NAME "tst_files.nc"
|
||||
#define ATT1_NAME "MoneyOwned"
|
||||
#define ATT2_NAME "Number_of_Shoes"
|
||||
#define ATT3_NAME "att3"
|
||||
#define DIM1_NAME "Character_Growth"
|
||||
#define DIM1_LEN 10
|
||||
#define DIM2_NAME "TimeInMonths"
|
||||
#define DIM2_LEN 15
|
||||
#define VAR1_NAME "HuckFinn"
|
||||
#define VAR2_NAME "TomSawyer"
|
||||
#define VAR3_NAME "Jim"
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
printf("\n*** Testing netcdf-4 file functions.\n");
|
||||
{
|
||||
char str[NC_MAX_NAME+1];
|
||||
|
||||
/* Actually we never make any promises about the length of the
|
||||
* version string, but it is always smaller than NC_MAX_NAME. */
|
||||
if (strlen(nc_inq_libvers()) > NC_MAX_NAME) ERR;
|
||||
strcpy(str, nc_inq_libvers());
|
||||
printf("*** testing version %s...", str);
|
||||
}
|
||||
SUMMARIZE_ERR;
|
||||
printf("*** testing with bad inputs...");
|
||||
{
|
||||
int ncid;
|
||||
|
||||
/* Make sure bad create mode causes failure. */
|
||||
/*if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;*/
|
||||
|
||||
/* Create an empty file. */
|
||||
if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
if (nc_open(FILE_NAME, NC_MPIIO|NC_MPIPOSIX, &ncid) != NC_EINVAL) ERR;
|
||||
|
||||
if (nc_create(FILE_NAME, NC_64BIT_OFFSET|NC_NETCDF4, &ncid) != NC_EINVAL) ERR;
|
||||
if (nc_create(FILE_NAME, NC_CLASSIC_MODEL|NC_MPIIO|NC_MPIPOSIX, &ncid) != NC_EINVAL) ERR;
|
||||
if (nc_create(FILE_NAME, NC_MPIIO|NC_MPIPOSIX, &ncid) != NC_EINVAL) ERR;
|
||||
}
|
||||
SUMMARIZE_ERR;
|
||||
printf("*** testing simple opens and creates...");
|
||||
{
|
||||
int ncid, ncid2, ncid3, varid, dimids[2];
|
||||
int ndims, nvars, natts, unlimdimid;
|
||||
int dimids_var[1], var_type;
|
||||
size_t dim_len;
|
||||
char dim_name[NC_MAX_NAME+1], var_name[NC_MAX_NAME+1];
|
||||
unsigned char uchar_out[DIM1_LEN] = {0, 128, 255};
|
||||
|
||||
/* Open and close empty file. */
|
||||
if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
/* Recreate it again. */
|
||||
if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
|
||||
if (nc_def_dim(ncid, DIM1_NAME, DIM1_LEN, &dimids[0])) ERR;
|
||||
if (nc_def_dim(ncid, DIM2_NAME, DIM2_LEN, &dimids[1])) ERR;
|
||||
if (nc_def_var(ncid, VAR1_NAME, NC_INT, 1, dimids, &varid)) ERR;
|
||||
if (nc_enddef(ncid)) ERR;
|
||||
if (nc_def_var(ncid, VAR2_NAME, NC_UINT, 2, dimids, &varid)) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
/* Check the contents. Then define a new variable. Since it's
|
||||
* netcdf-4, nc_enddef isn't required - it's called
|
||||
* automatically. */
|
||||
if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR;
|
||||
if (nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid)) ERR;
|
||||
if (ndims != 2 || nvars != 2 || natts != 0 || unlimdimid != -1) ERR;
|
||||
if (nc_redef(ncid)) ERR;
|
||||
if (nc_enddef(ncid)) ERR;
|
||||
if (nc_def_var(ncid, VAR3_NAME, NC_INT, 2, dimids, &varid)) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
/* Open three copies of the same file. */
|
||||
if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR;
|
||||
if (nc_open(FILE_NAME, NC_WRITE, &ncid2)) ERR;
|
||||
if (nc_open(FILE_NAME, NC_WRITE, &ncid3)) ERR;
|
||||
if (nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid)) ERR;
|
||||
if (ndims != 2 || nvars != 3 || natts != 0 || unlimdimid != -1) ERR;
|
||||
if (nc_inq(ncid2, &ndims, &nvars, &natts, &unlimdimid)) ERR;
|
||||
if (ndims != 2 || nvars != 3 || natts != 0 || unlimdimid != -1) ERR;
|
||||
if (nc_inq(ncid3, &ndims, &nvars, &natts, &unlimdimid)) ERR;
|
||||
if (ndims != 2 || nvars != 3 || natts != 0 || unlimdimid != -1) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
if (nc_close(ncid2)) ERR;
|
||||
if (nc_close(ncid3)) ERR;
|
||||
|
||||
/* Open and close empty file. */
|
||||
if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
/* Check the contents. */
|
||||
if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR;
|
||||
if (nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid)) ERR;
|
||||
if (ndims != 0 || nvars != 0 || natts != 0 || unlimdimid != -1) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
/* Create a file with one dimension and nothing else. */
|
||||
if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
|
||||
if (nc_def_dim(ncid, DIM1_NAME, DIM1_LEN, &dimids[0])) ERR;
|
||||
if (nc_enddef(ncid)) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
/* Check the contents. */
|
||||
if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR;
|
||||
if (nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid)) ERR;
|
||||
if (ndims != 1 || nvars != 0 || natts != 0 || unlimdimid != -1) ERR;
|
||||
if (nc_inq_dim(ncid, 0, dim_name, &dim_len)) ERR;
|
||||
if (dim_len != DIM1_LEN || strcmp(dim_name, DIM1_NAME)) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
/* Create a simple file, and write some data to it. */
|
||||
if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
|
||||
if (nc_def_dim(ncid, DIM1_NAME, DIM1_LEN, &dimids[0])) ERR;
|
||||
if (nc_def_var(ncid, VAR1_NAME, NC_BYTE, 1, dimids, &varid)) ERR;
|
||||
if (nc_enddef(ncid)) ERR;
|
||||
if (nc_put_var_uchar(ncid, varid, uchar_out) != NC_ERANGE) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
/* Check the contents. */
|
||||
if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR;
|
||||
if (nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid)) ERR;
|
||||
if (ndims != 1 || nvars != 1 || natts != 0 || unlimdimid != -1) ERR;
|
||||
if (nc_inq_dim(ncid, 0, dim_name, &dim_len)) ERR;
|
||||
if (dim_len != DIM1_LEN || strcmp(dim_name, DIM1_NAME)) ERR;
|
||||
if (nc_inq_var(ncid, 0, var_name, &var_type, &ndims, dimids_var, &natts)) ERR;
|
||||
if (ndims != 1 || strcmp(var_name, VAR1_NAME) || var_type != NC_BYTE ||
|
||||
dimids_var[0] != dimids[0] || natts != 0) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
/* Recreate the file. */
|
||||
if (nc_create(FILE_NAME, NC_NETCDF4|NC_CLASSIC_MODEL, &ncid)) ERR;
|
||||
if (nc_def_dim(ncid, DIM1_NAME, DIM1_LEN, &dimids[0])) ERR;
|
||||
if (nc_def_var(ncid, VAR1_NAME, NC_BYTE, 1, dimids, &varid)) ERR;
|
||||
if (nc_enddef(ncid)) ERR;
|
||||
if (nc_put_var_uchar(ncid, varid, uchar_out)) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
/* Recreate it, then make sure NOCLOBBER works. */
|
||||
if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
if (nc_create(FILE_NAME, NC_NETCDF4|NC_NOCLOBBER, &ncid) != NC_EEXIST) ERR;
|
||||
|
||||
/* Recreate it again. */
|
||||
if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
|
||||
if (nc_def_dim(ncid, DIM1_NAME, DIM1_LEN, &dimids[0])) ERR;
|
||||
if (nc_def_dim(ncid, DIM2_NAME, DIM2_LEN, &dimids[1])) ERR;
|
||||
if (nc_def_var(ncid, VAR1_NAME, NC_INT, 1, dimids, &varid)) ERR;
|
||||
if (nc_enddef(ncid)) ERR;
|
||||
if (nc_def_var(ncid, VAR2_NAME, NC_UINT, 2, dimids, &varid)) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
/* Check the contents. Then define a new variable. Since it's
|
||||
* netcdf-4, nc_enddef isn't required - it's called
|
||||
* automatically. */
|
||||
if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR;
|
||||
if (nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid)) ERR;
|
||||
if (ndims != 2 || nvars != 2 || natts != 0 || unlimdimid != -1) ERR;
|
||||
if (nc_redef(ncid)) ERR;
|
||||
if (nc_enddef(ncid)) ERR;
|
||||
if (nc_def_var(ncid, VAR3_NAME, NC_INT, 2, dimids, &varid)) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
/* Recreate it again with netcdf-3 rules turned on. */
|
||||
if (nc_create(FILE_NAME, NC_NETCDF4|NC_CLASSIC_MODEL, &ncid)) ERR;
|
||||
if (nc_def_dim(ncid, DIM1_NAME, DIM1_LEN, &dimids[0])) ERR;
|
||||
if (nc_def_var(ncid, VAR1_NAME, NC_INT, 1, dimids, &varid)) ERR;
|
||||
if (nc_enddef(ncid)) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
/* Check the contents. Check that netcdf-3 rules are in effect. */
|
||||
if (nc_open(FILE_NAME, 0, &ncid)) ERR;
|
||||
if (nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid)) ERR;
|
||||
if (ndims != 1 || nvars != 1 || natts != 0 || unlimdimid != -1) ERR;
|
||||
if (nc_def_var(ncid, VAR2_NAME, NC_UINT, 2, dimids, &varid) != NC_ENOTINDEFINE) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
/* Check some other stuff about it. Closing and reopening the
|
||||
* file forces HDF5 to tell us if we forgot to free some HDF5
|
||||
* resource associated with the file. */
|
||||
if (nc_open(FILE_NAME, 0, &ncid)) ERR;
|
||||
if (nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid)) ERR;
|
||||
if (nc_inq_dim(ncid, 0, dim_name, &dim_len)) ERR;
|
||||
if (dim_len != DIM1_LEN || strcmp(dim_name, DIM1_NAME)) ERR;
|
||||
if (nc_inq_var(ncid, 0, var_name, &var_type, &ndims, dimids_var, &natts)) ERR;
|
||||
if (ndims != 1 || strcmp(var_name, VAR1_NAME) || var_type != NC_INT ||
|
||||
dimids_var[0] != dimids[0] || natts != 0) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
}
|
||||
SUMMARIZE_ERR;
|
||||
printf("*** testing more complex opens and creates...");
|
||||
{
|
||||
int ncid, varid, dimids[2];
|
||||
int ndims, nvars, natts, unlimdimid;
|
||||
int dimids_var[2], var_type;
|
||||
size_t dim_len;
|
||||
char dim_name[NC_MAX_NAME+1], var_name[NC_MAX_NAME+1];
|
||||
float float_in, float_out = 99.99;
|
||||
int int_in, int_out = -9999;
|
||||
|
||||
/* Create a file, this time with attributes. */
|
||||
if (nc_create(FILE_NAME, NC_NETCDF4|NC_CLOBBER, &ncid)) ERR;
|
||||
if (nc_def_dim(ncid, DIM1_NAME, DIM1_LEN, &dimids[0])) ERR;
|
||||
if (nc_def_dim(ncid, DIM2_NAME, DIM2_LEN, &dimids[1])) ERR;
|
||||
if (nc_def_var(ncid, VAR1_NAME, NC_INT, 2, dimids, &varid)) ERR;
|
||||
if (nc_def_var(ncid, VAR2_NAME, NC_UINT, 2, dimids, &varid)) ERR;
|
||||
if (nc_put_att_float(ncid, NC_GLOBAL, ATT1_NAME, NC_FLOAT, 1, &float_out)) ERR;
|
||||
if (nc_put_att_int(ncid, NC_GLOBAL, ATT2_NAME, NC_INT, 1, &int_out)) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
/* Reopen the file and check it. */
|
||||
if (nc_open(FILE_NAME, 0, &ncid)) ERR;
|
||||
if (nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid)) ERR;
|
||||
if (ndims != 2 || nvars != 2 || natts != 2 || unlimdimid != -1) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
/* Reopen it and check each dim, var, and att. */
|
||||
if (nc_open(FILE_NAME, 0, &ncid)) ERR;
|
||||
if (nc_inq_dim(ncid, 0, dim_name, &dim_len)) ERR;
|
||||
if (dim_len != DIM1_LEN || strcmp(dim_name, DIM1_NAME)) ERR;
|
||||
if (nc_inq_dim(ncid, 1, dim_name, &dim_len)) ERR;
|
||||
if (dim_len != DIM2_LEN || strcmp(dim_name, DIM2_NAME)) ERR;
|
||||
if (nc_inq_var(ncid, 0, var_name, &var_type, &ndims, dimids_var, &natts)) ERR;
|
||||
if (ndims != 2 || strcmp(var_name, VAR1_NAME) || var_type != NC_INT ||
|
||||
dimids_var[0] != dimids[0] || natts != 0) ERR;
|
||||
if (nc_inq_var(ncid, 1, var_name, &var_type, &ndims, dimids_var, &natts)) ERR;
|
||||
if (ndims != 2 || strcmp(var_name, VAR2_NAME) || var_type != NC_UINT ||
|
||||
dimids_var[1] != dimids[1] || natts != 0) ERR;
|
||||
if (nc_get_att_float(ncid, NC_GLOBAL, ATT1_NAME, &float_in)) ERR;
|
||||
if (float_in != float_out) ERR;
|
||||
if (nc_get_att_int(ncid, NC_GLOBAL, ATT2_NAME, &int_in)) ERR;
|
||||
if (int_in != int_out) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
}
|
||||
SUMMARIZE_ERR;
|
||||
|
||||
printf("*** testing redef for netCDF classic...");
|
||||
test_redef(NC_FORMAT_CLASSIC);
|
||||
SUMMARIZE_ERR;
|
||||
printf("*** testing redef for netCDF 64-bit offset...");
|
||||
test_redef(NC_FORMAT_64BIT);
|
||||
SUMMARIZE_ERR;
|
||||
printf("*** testing redef for netCDF-4 ...");
|
||||
test_redef(NC_FORMAT_NETCDF4);
|
||||
SUMMARIZE_ERR;
|
||||
printf("*** testing redef for netCDF-4, with strict netCDF-3 rules...");
|
||||
test_redef(NC_FORMAT_NETCDF4_CLASSIC);
|
||||
SUMMARIZE_ERR;
|
||||
printf("*** testing different formats...");
|
||||
{
|
||||
int ncid;
|
||||
int format;
|
||||
|
||||
/* Create a netcdf-3 file. */
|
||||
if (nc_create(FILE_NAME, NC_CLOBBER, &ncid)) ERR;
|
||||
if (nc_inq_format(ncid, &format)) ERR;
|
||||
if (format != NC_FORMAT_CLASSIC) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
/* Create a netcdf-3 64-bit offset file. */
|
||||
if (nc_create(FILE_NAME, NC_64BIT_OFFSET|NC_CLOBBER, &ncid)) ERR;
|
||||
if (nc_inq_format(ncid, &format)) ERR;
|
||||
if (format != NC_FORMAT_64BIT) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
/* Create a netcdf-4 file. */
|
||||
if (nc_create(FILE_NAME, NC_NETCDF4|NC_CLOBBER, &ncid)) ERR;
|
||||
if (nc_inq_format(ncid, &format)) ERR;
|
||||
if (format != NC_FORMAT_NETCDF4) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
}
|
||||
SUMMARIZE_ERR;
|
||||
printf("*** testing CLASSIC_MODEL flag with classic formats...");
|
||||
{
|
||||
int ncid;
|
||||
int format;
|
||||
|
||||
/* Create a netcdf-3 file. */
|
||||
if (nc_create(FILE_NAME, NC_CLOBBER|NC_CLASSIC_MODEL, &ncid)) ERR;
|
||||
if (nc_inq_format(ncid, &format)) ERR;
|
||||
if (format != NC_FORMAT_CLASSIC) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
/* Create a netcdf-3 64-bit offset file. */
|
||||
if (nc_create(FILE_NAME, NC_64BIT_OFFSET|NC_CLOBBER|NC_CLASSIC_MODEL, &ncid)) ERR;
|
||||
if (nc_inq_format(ncid, &format)) ERR;
|
||||
if (format != NC_FORMAT_64BIT) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
}
|
||||
SUMMARIZE_ERR;
|
||||
printf("*** testing multiple open files...");
|
||||
{
|
||||
#define VAR_NAME "Captain_Kirk"
|
||||
#define NDIMS 1
|
||||
#define NUM_FILES 30
|
||||
#define TEXT_LEN 15
|
||||
#define D1_NAME "tl"
|
||||
int ncid[NUM_FILES], varid;
|
||||
int dimid;
|
||||
size_t count[NDIMS], index[NDIMS] = {0};
|
||||
const char ttext[TEXT_LEN + 1] = "20051224.150000";
|
||||
char ttext_in[TEXT_LEN + 1];
|
||||
char file_name[NC_MAX_NAME + 1];
|
||||
size_t chunks[NDIMS] = {TEXT_LEN + 1};
|
||||
int f;
|
||||
|
||||
/* Create a bunch of files. */
|
||||
for (f = 0; f < NUM_FILES; f++)
|
||||
{
|
||||
sprintf(file_name, "tst_files2_%d.nc", f);
|
||||
if (nc_create(file_name, NC_NETCDF4, &ncid[f])) ERR;
|
||||
if (nc_def_dim(ncid[f], D1_NAME, TEXT_LEN + 1, &dimid)) ERR;
|
||||
if (nc_def_var(ncid[f], VAR_NAME, NC_CHAR, NDIMS, &dimid, &varid)) ERR;
|
||||
if (f % 2 == 0)
|
||||
if (nc_def_var_chunking(ncid[f], varid, 0, chunks)) ERR;
|
||||
|
||||
/* Write one time to the coordinate variable. */
|
||||
count[0] = TEXT_LEN + 1;
|
||||
if (nc_put_vara_text(ncid[f], varid, index, count, ttext)) ERR;
|
||||
}
|
||||
|
||||
/* Read something from each file. */
|
||||
for (f = 0; f < NUM_FILES; f++)
|
||||
{
|
||||
if (nc_get_vara_text(ncid[f], varid, index, count, (char *)ttext_in)) ERR;
|
||||
if (strcmp(ttext_in, ttext)) ERR;
|
||||
}
|
||||
|
||||
/* Close all open files. */
|
||||
for (f = 0; f < NUM_FILES; f++)
|
||||
if (nc_close(ncid[f])) ERR;
|
||||
}
|
||||
SUMMARIZE_ERR;
|
||||
FINAL_RESULTS;
|
||||
}
|
||||
#define REDEF_ATT1_NAME "CANTERBURY"
|
||||
#define REDEF_ATT2_NAME "ELY"
|
||||
#define REDEF_ATT3_NAME "KING_HENRY_V"
|
||||
#define REDEF_DIM1_NAME "performance_length"
|
||||
#define REDEF_DIM1_LEN 101
|
||||
/* Change illegal name from '?' to '/'; the latter will
|
||||
more likely be illegal even when the switch is made to
|
||||
escaped characters in identifiers.
|
||||
*/
|
||||
#define REDEF_NAME_ILLEGAL "/"
|
||||
#define REDEF_DIM2_NAME "ZZ_number_of_performers_or_perhaps_actors_or_maybe_I_should_say_players_or_one_could_call_them_artists_but_one_doesnt_like_to_get"
|
||||
|
||||
#define REDEF_DIM2_LEN 999
|
||||
#define REDEF_VAR1_NAME "Royal_Shakespeare_Company_season_of_2004"
|
||||
#define REDEF_VAR2_NAME "Ms_Beths_Kindergardern_class_of_2003"
|
||||
#define REDEF_VAR3_NAME "Costumed_Mice_in_my_Garage_in_the_Winter_of_my_Discontent"
|
||||
#define REDEF_NDIMS 2
|
||||
|
||||
#define NEW_CACHE_SIZE 32000000
|
||||
#define NEW_CACHE_NELEMS 2000
|
||||
#define NEW_CACHE_PREEMPTION .75
|
||||
|
||||
int
|
||||
test_redef(int format)
|
||||
{
|
||||
int ncid, varid, dimids[REDEF_NDIMS], dimids_in[REDEF_NDIMS];
|
||||
int ndims, nvars, natts, unlimdimid;
|
||||
int dimids_var[REDEF_NDIMS], var_type;
|
||||
int cflags = 0;
|
||||
size_t dim_len;
|
||||
char dim_name[NC_MAX_NAME+1], var_name[NC_MAX_NAME+1];
|
||||
float float_in;
|
||||
double double_out = 99E99;
|
||||
int int_in;
|
||||
unsigned char uchar_in, uchar_out = 255;
|
||||
short short_out = -999;
|
||||
nc_type xtype_in;
|
||||
size_t cache_size_in, cache_nelems_in;
|
||||
float cache_preemption_in;
|
||||
int ret;
|
||||
|
||||
if (format == NC_FORMAT_64BIT)
|
||||
cflags |= NC_64BIT_OFFSET;
|
||||
else if (format == NC_FORMAT_NETCDF4_CLASSIC)
|
||||
cflags |= (NC_NETCDF4|NC_CLASSIC_MODEL);
|
||||
else if (format == NC_FORMAT_NETCDF4)
|
||||
cflags |= NC_NETCDF4;
|
||||
|
||||
/* Change chunk cache. */
|
||||
if (nc_set_chunk_cache(NEW_CACHE_SIZE, NEW_CACHE_NELEMS,
|
||||
NEW_CACHE_PREEMPTION)) ERR;
|
||||
|
||||
/* Create a file with two dims, two vars, and two atts. */
|
||||
if (nc_create(FILE_NAME, cflags|NC_CLOBBER, &ncid)) ERR;
|
||||
|
||||
/* Retrieve the chunk cache settings, just for fun. */
|
||||
if (nc_get_chunk_cache(&cache_size_in, &cache_nelems_in,
|
||||
&cache_preemption_in)) ERR;
|
||||
if (cache_size_in != NEW_CACHE_SIZE || cache_nelems_in != NEW_CACHE_NELEMS ||
|
||||
cache_preemption_in != NEW_CACHE_PREEMPTION) ERR;
|
||||
|
||||
/* This will fail, except for netcdf-4/hdf5, which permits any
|
||||
* name. */
|
||||
if (format != NC_FORMAT_NETCDF4)
|
||||
if ((ret = nc_def_dim(ncid, REDEF_NAME_ILLEGAL, REDEF_DIM2_LEN,
|
||||
&dimids[1])) != NC_EBADNAME) ERR;
|
||||
|
||||
if (nc_def_dim(ncid, REDEF_DIM1_NAME, REDEF_DIM1_LEN, &dimids[0])) ERR;
|
||||
if (nc_def_dim(ncid, REDEF_DIM2_NAME, REDEF_DIM2_LEN, &dimids[1])) ERR;
|
||||
if (nc_def_var(ncid, REDEF_VAR1_NAME, NC_INT, REDEF_NDIMS, dimids, &varid)) ERR;
|
||||
if (nc_def_var(ncid, REDEF_VAR2_NAME, NC_BYTE, REDEF_NDIMS, dimids, &varid)) ERR;
|
||||
if (nc_put_att_double(ncid, NC_GLOBAL, REDEF_ATT1_NAME, NC_DOUBLE, 1, &double_out)) ERR;
|
||||
if (nc_put_att_short(ncid, NC_GLOBAL, REDEF_ATT2_NAME, NC_SHORT, 1, &short_out)) ERR;
|
||||
|
||||
/* Check it out. */
|
||||
if (nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid)) ERR;
|
||||
if (ndims != REDEF_NDIMS || nvars != 2 || natts != 2 || unlimdimid != -1) ERR;
|
||||
if (nc_inq_var(ncid, 0, var_name, &xtype_in, &ndims, dimids_in, &natts)) ERR;
|
||||
if (strcmp(var_name, REDEF_VAR1_NAME) || xtype_in != NC_INT || ndims != REDEF_NDIMS ||
|
||||
dimids_in[0] != dimids[0] || dimids_in[1] != dimids[1]) ERR;
|
||||
if (nc_inq_var(ncid, 1, var_name, &xtype_in, &ndims, dimids_in, &natts)) ERR;
|
||||
if (strcmp(var_name, REDEF_VAR2_NAME) || xtype_in != NC_BYTE || ndims != REDEF_NDIMS ||
|
||||
dimids_in[0] != dimids[0] || dimids_in[1] != dimids[1]) ERR;
|
||||
|
||||
/* Close it up. */
|
||||
if (format != NC_FORMAT_NETCDF4)
|
||||
if (nc_enddef(ncid)) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
/* Reopen as read only - make sure it doesn't let us change file. */
|
||||
if (nc_open(FILE_NAME, 0, &ncid)) ERR;
|
||||
if (nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid)) ERR;
|
||||
if (ndims != REDEF_NDIMS || nvars != 2 || natts != 2 || unlimdimid != -1) ERR;
|
||||
if (nc_inq_var(ncid, 0, var_name, &xtype_in, &ndims, dimids_in, &natts)) ERR;
|
||||
if (strcmp(var_name, REDEF_VAR1_NAME) || xtype_in != NC_INT || ndims != REDEF_NDIMS ||
|
||||
dimids_in[0] != dimids[0] || dimids_in[1] != dimids[1]) ERR;
|
||||
if (nc_inq_var(ncid, 1, var_name, &xtype_in, &ndims, dimids_in, &natts)) ERR;
|
||||
if (strcmp(var_name, REDEF_VAR2_NAME) || xtype_in != NC_BYTE || ndims != REDEF_NDIMS ||
|
||||
dimids_in[0] != dimids[0] || dimids_in[1] != dimids[1]) ERR;
|
||||
|
||||
/* This will fail. */
|
||||
ret = nc_def_var(ncid, REDEF_VAR3_NAME, NC_UBYTE, REDEF_NDIMS,
|
||||
dimids, &varid);
|
||||
if(format == NC_FORMAT_NETCDF4) {
|
||||
if(ret != NC_EPERM) {
|
||||
ERR;
|
||||
}
|
||||
} else {
|
||||
if(ret != NC_ENOTINDEFINE) {
|
||||
ERR;
|
||||
}
|
||||
}
|
||||
/* This will fail. */
|
||||
if (!nc_put_att_uchar(ncid, NC_GLOBAL, REDEF_ATT3_NAME, NC_CHAR, 1, &uchar_out)) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
/* Make sure we can't redef a file opened for NOWRITE. */
|
||||
if (nc_open(FILE_NAME, NC_NOWRITE, &ncid)) ERR;
|
||||
if (nc_redef(ncid) != NC_EPERM) ERR;
|
||||
|
||||
/* Check it out again. */
|
||||
if (nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid)) ERR;
|
||||
if (ndims != REDEF_NDIMS || nvars != 2 || natts != 2 || unlimdimid != -1) ERR;
|
||||
if (nc_inq_var(ncid, 0, var_name, &xtype_in, &ndims, dimids_in, &natts)) ERR;
|
||||
if (strcmp(var_name, REDEF_VAR1_NAME) || xtype_in != NC_INT || ndims != REDEF_NDIMS ||
|
||||
dimids_in[0] != dimids[0] || dimids_in[1] != dimids[1]) ERR;
|
||||
if (nc_inq_var(ncid, 1, var_name, &xtype_in, &ndims, dimids_in, &natts)) ERR;
|
||||
if (strcmp(var_name, REDEF_VAR2_NAME) || xtype_in != NC_BYTE || ndims != REDEF_NDIMS ||
|
||||
dimids_in[0] != dimids[0] || dimids_in[1] != dimids[1]) ERR;
|
||||
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
/* Reopen the file and check it, add a variable and attribute. */
|
||||
if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR;
|
||||
|
||||
/* Check it out. */
|
||||
if (nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid)) ERR;
|
||||
if (ndims != REDEF_NDIMS || nvars != 2 || natts != 2 || unlimdimid != -1) ERR;
|
||||
|
||||
/* Add var. */
|
||||
if ((format != NC_FORMAT_NETCDF4) && nc_redef(ncid)) ERR;
|
||||
if (nc_def_var(ncid, REDEF_VAR3_NAME, NC_BYTE, REDEF_NDIMS, dimids, &varid)) ERR;
|
||||
|
||||
/* Add att. */
|
||||
ret = nc_put_att_uchar(ncid, NC_GLOBAL, REDEF_ATT3_NAME, NC_BYTE, 1, &uchar_out);
|
||||
if (format != NC_FORMAT_NETCDF4 && ret) ERR;
|
||||
else if (format == NC_FORMAT_NETCDF4 && ret != NC_ERANGE) ERR;
|
||||
|
||||
/* Check it out. */
|
||||
if (nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid)) ERR;
|
||||
if (ndims != REDEF_NDIMS || nvars != 3 || natts != 3 || unlimdimid != -1) ERR;
|
||||
if (nc_inq_var(ncid, 0, var_name, &xtype_in, &ndims, dimids_in, &natts)) ERR;
|
||||
if (strcmp(var_name, REDEF_VAR1_NAME) || xtype_in != NC_INT || ndims != REDEF_NDIMS ||
|
||||
dimids_in[0] != dimids[0] || dimids_in[1] != dimids[1]) ERR;
|
||||
if (nc_inq_var(ncid, 1, var_name, &xtype_in, &ndims, dimids_in, &natts)) ERR;
|
||||
if (strcmp(var_name, REDEF_VAR2_NAME) || xtype_in != NC_BYTE || ndims != REDEF_NDIMS ||
|
||||
dimids_in[0] != dimids[0] || dimids_in[1] != dimids[1]) ERR;
|
||||
if (nc_inq_var(ncid, 2, var_name, &var_type, &ndims, dimids_var, &natts)) ERR;
|
||||
if (ndims != REDEF_NDIMS || strcmp(var_name, REDEF_VAR3_NAME) || var_type != NC_BYTE ||
|
||||
natts != 0) ERR;
|
||||
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
/* Reopen it and check each dim, var, and att. */
|
||||
if (nc_open(FILE_NAME, 0, &ncid)) ERR;
|
||||
if (nc_inq_dim(ncid, 0, dim_name, &dim_len)) ERR;
|
||||
if (dim_len != REDEF_DIM1_LEN || strcmp(dim_name, REDEF_DIM1_NAME)) ERR;
|
||||
if (nc_inq_dim(ncid, 1, dim_name, &dim_len)) ERR;
|
||||
if (dim_len != REDEF_DIM2_LEN || strcmp(dim_name, REDEF_DIM2_NAME)) ERR;
|
||||
if (nc_inq_var(ncid, 0, var_name, &var_type, &ndims, dimids_var, &natts)) ERR;
|
||||
if (ndims != REDEF_NDIMS || strcmp(var_name, REDEF_VAR1_NAME) || var_type != NC_INT ||
|
||||
natts != 0) ERR;
|
||||
if (nc_inq_var(ncid, 1, var_name, &var_type, &ndims, dimids_var, &natts)) ERR;
|
||||
if (ndims != REDEF_NDIMS || strcmp(var_name, REDEF_VAR2_NAME) || var_type != NC_BYTE ||
|
||||
natts != 0) ERR;
|
||||
if (nc_inq_var(ncid, 2, var_name, &var_type, &ndims, dimids_var, &natts)) ERR;
|
||||
if (ndims != REDEF_NDIMS || strcmp(var_name, REDEF_VAR3_NAME) || var_type != NC_BYTE ||
|
||||
natts != 0) ERR;
|
||||
if (nc_get_att_float(ncid, NC_GLOBAL, REDEF_ATT1_NAME, &float_in) != NC_ERANGE) ERR;
|
||||
if (nc_get_att_int(ncid, NC_GLOBAL, REDEF_ATT2_NAME, &int_in)) ERR;
|
||||
if (int_in != short_out) ERR;
|
||||
ret = nc_get_att_uchar(ncid, NC_GLOBAL, REDEF_ATT3_NAME, &uchar_in);
|
||||
if (format == NC_FORMAT_NETCDF4)
|
||||
{
|
||||
if (ret != NC_ERANGE) ERR;
|
||||
}
|
||||
else if (ret) ERR;
|
||||
|
||||
if (uchar_in != uchar_out) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
return NC_NOERR;
|
||||
}
|
||||
|
||||
|
@ -1,363 +0,0 @@
|
||||
/* This is part of the netCDF package.
|
||||
Copyright 2005 University Corporation for Atmospheric Research/Unidata
|
||||
See COPYRIGHT file for conditions of use.
|
||||
|
||||
Test netcdf-4 variables.
|
||||
$Id: tst_files2.c,v 1.11 2010/01/31 19:00:44 ed Exp $
|
||||
*/
|
||||
|
||||
#include <nc_tests.h>
|
||||
#include "netcdf.h"
|
||||
#include <unistd.h>
|
||||
#include <time.h>
|
||||
#include <sys/time.h> /* Extra high precision time info. */
|
||||
|
||||
#define MAX_LEN 30
|
||||
#define TMP_FILE_NAME "tst_files2_tmp.out"
|
||||
#define FILE_NAME "tst_files2_1.nc"
|
||||
#define MILLION 1000000
|
||||
|
||||
void *last_sbrk;
|
||||
|
||||
/* Subtract the `struct timeval' values X and Y, storing the result in
|
||||
RESULT. Return 1 if the difference is negative, otherwise 0. This
|
||||
function from the GNU documentation. */
|
||||
static int
|
||||
timeval_subtract (result, x, y)
|
||||
struct timeval *result, *x, *y;
|
||||
{
|
||||
/* Perform the carry for the later subtraction by updating Y. */
|
||||
if (x->tv_usec < y->tv_usec) {
|
||||
int nsec = (y->tv_usec - x->tv_usec) / MILLION + 1;
|
||||
y->tv_usec -= MILLION * nsec;
|
||||
y->tv_sec += nsec;
|
||||
}
|
||||
if (x->tv_usec - y->tv_usec > MILLION) {
|
||||
int nsec = (x->tv_usec - y->tv_usec) / MILLION;
|
||||
y->tv_usec += MILLION * nsec;
|
||||
y->tv_sec -= nsec;
|
||||
}
|
||||
|
||||
/* Compute the time remaining to wait.
|
||||
`tv_usec' is certainly positive. */
|
||||
result->tv_sec = x->tv_sec - y->tv_sec;
|
||||
result->tv_usec = x->tv_usec - y->tv_usec;
|
||||
|
||||
/* Return 1 if result is negative. */
|
||||
return x->tv_sec < y->tv_sec;
|
||||
}
|
||||
|
||||
/* This function uses the ps command to find the amount of memory in
|
||||
use by the process. From the ps man page:
|
||||
|
||||
size SZ approximate amount of swap space that would be required if
|
||||
the process were to dirty all writable pages and then be
|
||||
swapped out. This number is very rough!
|
||||
*/
|
||||
int
|
||||
get_mem_used1(int *mem_used)
|
||||
{
|
||||
char cmd[NC_MAX_NAME + 1];
|
||||
char blob[MAX_LEN + 1] = "";
|
||||
FILE *fp;
|
||||
int num_char;
|
||||
|
||||
/* Run the ps command for this process, putting output (one number)
|
||||
* into file TMP_FILE_NAME. */
|
||||
sprintf(cmd, "ps -o size= %d > %s", getpid(), TMP_FILE_NAME);
|
||||
system(cmd);
|
||||
|
||||
/* Read the results and delete temp file. */
|
||||
if (!(fp = fopen(TMP_FILE_NAME, "r"))) ERR;
|
||||
num_char = fread(blob, MAX_LEN, 1, fp);
|
||||
sscanf(blob, "%d", mem_used);
|
||||
fclose(fp);
|
||||
unlink(TMP_FILE_NAME);
|
||||
return NC_NOERR;
|
||||
}
|
||||
|
||||
void
|
||||
get_mem_used2(int *mem_used)
|
||||
{
|
||||
char buf[30];
|
||||
FILE *pf;
|
||||
|
||||
snprintf(buf, 30, "/proc/%u/statm", (unsigned)getpid());
|
||||
pf = fopen(buf, "r");
|
||||
if (pf) {
|
||||
unsigned size; /* total program size */
|
||||
unsigned resident;/* resident set size */
|
||||
unsigned share;/* shared pages */
|
||||
unsigned text;/* text (code) */
|
||||
unsigned lib;/* library */
|
||||
unsigned data;/* data/stack */
|
||||
/*unsigned dt; dirty pages (unused in Linux 2.6)*/
|
||||
fscanf(pf, "%u %u %u %u %u %u", &size, &resident, &share,
|
||||
&text, &lib, &data);
|
||||
*mem_used = data;
|
||||
}
|
||||
else
|
||||
*mem_used = -1;
|
||||
fclose(pf);
|
||||
}
|
||||
|
||||
void
|
||||
get_mem_used3(int *mem_used)
|
||||
{
|
||||
void *vp;
|
||||
vp = sbrk(0);
|
||||
*mem_used = ((char *)vp - (char *)last_sbrk)/1024;
|
||||
}
|
||||
|
||||
/* Create a sample file, with num_vars 3D or 4D variables, with dim
|
||||
* lens of dim_len size. */
|
||||
#define MAX_DIMS 4
|
||||
int
|
||||
create_sample_file(char *file_name, int ndims, int *dim_len,
|
||||
int num_vars, int mode, int num_recs)
|
||||
{
|
||||
int ncid, dimids[MAX_DIMS], *varids;
|
||||
char varname[NC_MAX_NAME + 1];
|
||||
char dim_name[NC_MAX_NAME + 1];
|
||||
float *data_out;
|
||||
size_t start[MAX_DIMS], count[MAX_DIMS];
|
||||
int slab_nelems;
|
||||
int i, d, ret;
|
||||
|
||||
if (ndims != MAX_DIMS && ndims != MAX_DIMS - 1) ERR_RET;
|
||||
|
||||
/* Create a file. */
|
||||
ret = nc_create(file_name, NC_NOCLOBBER|mode, &ncid);
|
||||
if (ret == NC_EEXIST)
|
||||
return NC_NOERR;
|
||||
else if (ret)
|
||||
ERR_RET;
|
||||
|
||||
/* Initialize sample data. Slab of data will be full extent of last
|
||||
* two dimensions. */
|
||||
slab_nelems = dim_len[ndims - 1] * dim_len[ndims - 2];
|
||||
if (!(data_out = malloc(slab_nelems * sizeof(float)))) ERR_RET;
|
||||
for (i = 0; i < slab_nelems; i++)
|
||||
data_out[i] = 42.42 + i;
|
||||
|
||||
/* Create the dimensions. */
|
||||
for (d = 0; d < ndims; d++)
|
||||
{
|
||||
sprintf(dim_name, "dim_%d", d);
|
||||
if (nc_def_dim(ncid, dim_name, dim_len[d], &dimids[d])) ERR_RET;
|
||||
}
|
||||
|
||||
/* Define num_vars variables. */
|
||||
if (!(varids = malloc(num_vars * sizeof(int)))) ERR_RET;
|
||||
for (i = 0; i < num_vars; i++)
|
||||
{
|
||||
sprintf(varname, "a_%d", i);
|
||||
if (nc_def_var(ncid, varname, NC_FLOAT, ndims, dimids,
|
||||
&varids[i])) ERR_RET;
|
||||
}
|
||||
|
||||
/* Enddef required for classic files. */
|
||||
if (nc_enddef(ncid)) ERR;
|
||||
|
||||
/* Set up start/count to write slabs of data. */
|
||||
for (d = 0; d < ndims; d++)
|
||||
{
|
||||
if (d < ndims - 2)
|
||||
count[d] = 1;
|
||||
else
|
||||
{
|
||||
start[d] = 0;
|
||||
count[d] = dim_len[d];
|
||||
}
|
||||
}
|
||||
|
||||
/* Now write some data to the vars in slabs. */
|
||||
for (i = 0; i < num_vars; i++)
|
||||
{
|
||||
if (ndims == MAX_DIMS)
|
||||
{
|
||||
for (start[0] = 0; start[0] < (dim_len[0] ? dim_len[0] : num_recs); start[0]++)
|
||||
for (start[1] = 0; start[1] < dim_len[1]; start[1]++)
|
||||
if (nc_put_vara_float(ncid, varids[i], start, count,
|
||||
data_out)) ERR_RET;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (start[0] = 0; start[0] < (dim_len[0] ? dim_len[0] : num_recs); start[0]++)
|
||||
if (nc_put_vara_float(ncid, varids[i], start, count,
|
||||
data_out)) ERR_RET;
|
||||
}
|
||||
}
|
||||
|
||||
/* Free data and close file. */
|
||||
free(data_out);
|
||||
free(varids);
|
||||
if (nc_close(ncid)) ERR_RET;
|
||||
|
||||
return NC_NOERR;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
|
||||
printf("\n*** Testing netcdf-4 file functions, some more.\n");
|
||||
last_sbrk = sbrk(0);
|
||||
printf("*** testing lots of open files...\n");
|
||||
{
|
||||
#define NUM_TRIES 6
|
||||
int *ncid_in;
|
||||
int mem_used, mem_used2;
|
||||
int mem_per_file;
|
||||
int num_files[NUM_TRIES] = {1, 1, 1, 1, 1, 1};
|
||||
char file_name[NUM_TRIES][NC_MAX_NAME + 1];
|
||||
int num_vars[NUM_TRIES];
|
||||
size_t cache_size[NUM_TRIES];
|
||||
int mode[NUM_TRIES];
|
||||
char mode_name[NUM_TRIES][8];
|
||||
int ndims[NUM_TRIES];
|
||||
int dim_len[NUM_TRIES][MAX_DIMS];
|
||||
int dim_4d[MAX_DIMS] = {NC_UNLIMITED, 10, 1000, 1000};
|
||||
char dimstr[30];
|
||||
char chunkstr[30];
|
||||
int num_recs[NUM_TRIES] = {1, 1, 1};
|
||||
struct timeval start_time, end_time, diff_time;
|
||||
struct timeval close_start_time, close_end_time, close_diff_time;
|
||||
int open_us, close_us, create_us;
|
||||
size_t chunksize[MAX_DIMS];
|
||||
int storage;
|
||||
int d, f, t;
|
||||
|
||||
printf("dims\t\tchunks\t\tformat\tnum_files\tcache(kb)\tnum_vars\tmem(kb)\t"
|
||||
"open_time(us)\tclose_time(us)\tcreate_time(us)\n");
|
||||
for (t = 0; t < NUM_TRIES; t++)
|
||||
{
|
||||
/* Set up filename. */
|
||||
sprintf(file_name[t], "tst_files2_%d.nc", t);
|
||||
strcpy(mode_name[t], "netcdf4");
|
||||
mode[t] = NC_NETCDF4;
|
||||
cache_size[t] = 16000000;
|
||||
num_vars[t] = 10;
|
||||
ndims[t] = 4;
|
||||
for (d = 0; d < ndims[t]; d++)
|
||||
dim_len[t][d] = dim_4d[d];
|
||||
|
||||
/* Create sample file (unless it already exists). */
|
||||
if (gettimeofday(&start_time, NULL)) ERR;
|
||||
if (create_sample_file(file_name[t], ndims[t], dim_len[t], num_vars[t],
|
||||
mode[t], num_recs[t])) ERR;
|
||||
|
||||
/* How long did it take? */
|
||||
if (gettimeofday(&end_time, NULL)) ERR;
|
||||
if (timeval_subtract(&diff_time, &end_time, &start_time)) ERR;
|
||||
create_us = ((int)diff_time.tv_sec * MILLION + (int)diff_time.tv_usec);
|
||||
|
||||
/* Change the cache settings. */
|
||||
if (nc_set_chunk_cache(cache_size[t], 20000, .75)) ERR;
|
||||
|
||||
/* We need storage for an array of ncids. */
|
||||
if (!(ncid_in = malloc(num_files[t] * sizeof(int)))) ERR;
|
||||
|
||||
/* How much memory is in use now? */
|
||||
if (get_mem_used1(&mem_used)) ERR;
|
||||
/* get_mem_used2(&mem_used);
|
||||
get_mem_used3(&mem_used);*/
|
||||
|
||||
/* Open the first file to get chunksizes. */
|
||||
if (gettimeofday(&start_time, NULL)) ERR;
|
||||
if (nc_open(file_name[t], 0, &ncid_in[0])) ERR;
|
||||
if (nc_inq_var_chunking(ncid_in[0], 0, &storage, chunksize)) ERR;
|
||||
|
||||
/* Now reopen this file a large number of times. */
|
||||
for (f = 1; f < num_files[t]; f++)
|
||||
if (nc_open(file_name[t], 0, &ncid_in[f])) ERR_RET;
|
||||
|
||||
/* How long did it take per file? */
|
||||
if (gettimeofday(&end_time, NULL)) ERR;
|
||||
if (timeval_subtract(&diff_time, &end_time, &start_time)) ERR;
|
||||
open_us = ((int)diff_time.tv_sec * MILLION + (int)diff_time.tv_usec);
|
||||
|
||||
/* How much memory is in use by this process now? */
|
||||
if (get_mem_used1(&mem_used2)) ERR;
|
||||
|
||||
/* Close all netcdf files. */
|
||||
if (gettimeofday(&close_start_time, NULL)) ERR;
|
||||
for (f = 0; f < num_files[t]; f++)
|
||||
if (nc_close(ncid_in[f])) ERR_RET;
|
||||
|
||||
/* How long did it take to close all files? */
|
||||
if (gettimeofday(&close_end_time, NULL)) ERR;
|
||||
if (timeval_subtract(&close_diff_time, &close_end_time, &close_start_time)) ERR;
|
||||
close_us = ((int)close_diff_time.tv_sec * MILLION + (int)close_diff_time.tv_usec);
|
||||
|
||||
/* We're done with this. */
|
||||
free(ncid_in);
|
||||
|
||||
/* How much memory was used for each open file? */
|
||||
mem_per_file = mem_used2/num_files[t];
|
||||
|
||||
/* Prepare the dimensions string. */
|
||||
if (ndims[t] == MAX_DIMS)
|
||||
sprintf(dimstr, "%dx%dx%dx%d", dim_len[t][0], dim_len[t][1],
|
||||
dim_len[t][2], dim_len[t][3]);
|
||||
else
|
||||
sprintf(dimstr, "%dx%dx%d", dim_len[t][0], dim_len[t][1],
|
||||
dim_len[t][2]);
|
||||
|
||||
/* Prepare the chunksize string. */
|
||||
if (storage == NC_CHUNKED)
|
||||
{
|
||||
if (ndims[t] == MAX_DIMS)
|
||||
sprintf(chunkstr, "%dx%dx%dx%d", (int)chunksize[0], (int)chunksize[1],
|
||||
(int)chunksize[2], (int)chunksize[3]);
|
||||
else
|
||||
sprintf(chunkstr, "%dx%dx%d", (int)chunksize[0], (int)chunksize[1],
|
||||
(int)chunksize[2]);
|
||||
}
|
||||
else
|
||||
strcpy(chunkstr, "contig ");
|
||||
|
||||
/* Output results. */
|
||||
printf("%s\t%s\t%s\t%d\t\t%d\t\t%d\t\t%d\t\t%d\t\t%d\t\t%d\n",
|
||||
dimstr, chunkstr, mode_name[t], num_files[t], (int)(cache_size[t]/1024),
|
||||
num_vars[t], mem_used2, open_us, close_us, create_us);
|
||||
}
|
||||
}
|
||||
SUMMARIZE_ERR;
|
||||
printf("Test for memory consumption...\n");
|
||||
{
|
||||
#define NUM_TRIES_100 100
|
||||
int ncid, i;
|
||||
int mem_used, mem_used1, mem_used2;
|
||||
|
||||
get_mem_used2(&mem_used);
|
||||
mem_used1 = mem_used;
|
||||
mem_used2 = mem_used;
|
||||
printf("start: memuse= %d\t%d\t%d \n",mem_used, mem_used1,
|
||||
mem_used2);
|
||||
|
||||
printf("bef_open\taft_open\taft_close\tused_open\tused_closed\n");
|
||||
for (i=0; i < NUM_TRIES_100; i++)
|
||||
{
|
||||
/* Open the file. NC_NOWRITE tells netCDF we want read-only access
|
||||
* to the file.*/
|
||||
|
||||
get_mem_used2(&mem_used);
|
||||
nc_set_chunk_cache(10,10,.5);
|
||||
if (nc_open(FILE_NAME, NC_NOWRITE, &ncid)) ERR;
|
||||
get_mem_used2(&mem_used1);
|
||||
|
||||
/* Close the file, freeing all resources. ???? */
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
get_mem_used2(&mem_used2);
|
||||
|
||||
if (mem_used2 - mem_used)
|
||||
printf("try %d - %d\t\t%d\t\t%d\t\t%d\t\t%d \n", i,
|
||||
mem_used, mem_used1, mem_used2, mem_used1 - mem_used,
|
||||
mem_used2 - mem_used);
|
||||
}
|
||||
}
|
||||
SUMMARIZE_ERR;
|
||||
FINAL_RESULTS;
|
||||
}
|
@ -1,67 +0,0 @@
|
||||
/* This is part of the netCDF package.
|
||||
Copyright 2005 University Corporation for Atmospheric Research/Unidata
|
||||
See COPYRIGHT file for conditions of use.
|
||||
|
||||
Test netcdf-4 variables.
|
||||
$Id: tst_large.c,v 1.5 2009/05/18 10:26:24 ed Exp $
|
||||
*/
|
||||
|
||||
#include <nc_tests.h>
|
||||
#include "netcdf.h"
|
||||
|
||||
#define FILE_NAME "tst_large.nc"
|
||||
#define NUMDIMS 2 /* rank of each variable in tests */
|
||||
#define DIM1 2048
|
||||
#define DIM2 2097153 /* DIM1*DIM2*sizeof(char) > 2**32 */
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
|
||||
#ifdef USE_PARALLEL
|
||||
MPI_Init(&argc, &argv);
|
||||
#endif
|
||||
|
||||
printf("\n*** Testing netcdf-4 large files.\n");
|
||||
printf("**** testing simple fill value attribute creation...");
|
||||
{
|
||||
int ncid, varid, dimids[NUMDIMS];
|
||||
size_t index[NUMDIMS] = {0, 0};
|
||||
signed char vals[DIM2];
|
||||
signed char char_val_in;
|
||||
size_t start[NUMDIMS] = {0, 0}, count[NUMDIMS] = {1, DIM2};
|
||||
int j;
|
||||
|
||||
/* Create phony data. */
|
||||
for (j = 0; j < DIM2; j++)
|
||||
vals[j] = 9 * (j + 11); /* note vals[j] is 99 when j==0 */
|
||||
|
||||
/* Create file with 2 dims and one var. */
|
||||
if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
|
||||
if (nc_set_fill(ncid, NC_NOFILL, NULL)) ERR;
|
||||
if (nc_def_dim(ncid, "dim1", DIM1, &dimids[0])) ERR;
|
||||
if (nc_def_dim(ncid, "dim2", DIM2, &dimids[1])) ERR;
|
||||
if (nc_def_var(ncid, "var", NC_BYTE, NUMDIMS, dimids, &varid)) ERR;
|
||||
if (nc_enddef(ncid)) ERR;
|
||||
|
||||
/* Write one slice, then close. */
|
||||
if (nc_put_vara_schar(ncid, varid, start, count, vals)) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
/* Reopen and read a value. */
|
||||
/* if (nc_open(FILE_NAME, NC_NOWRITE, &ncid)) ERR; */
|
||||
/* if (nc_inq_varid(ncid, "var", &varid)) ERR; */
|
||||
/* if (nc_get_var1_schar(ncid, varid, index, &char_val_in)) ERR; */
|
||||
/* if (char_val_in != 99) /\* see above, the value written when start[0]==0, j==0 *\/ */
|
||||
/* ERR; */
|
||||
/* if (nc_close(ncid)) ERR; */
|
||||
}
|
||||
SUMMARIZE_ERR;
|
||||
|
||||
#ifdef USE_PARALLEL
|
||||
MPI_Finalize();
|
||||
#endif
|
||||
FINAL_RESULTS;
|
||||
}
|
||||
|
||||
|
@ -2,24 +2,36 @@
|
||||
# Copyright 2005 University Corporation for Atmospheric Research/Unidata
|
||||
# See COPYRIGHT file for conditions of use.
|
||||
#
|
||||
# This entire directory will be skipped, unless the configure script
|
||||
# is run with --enable-netcdf-4.
|
||||
# This entire directory will be skipped if netCDF-4 is not enabled.
|
||||
#
|
||||
# $Id: Makefile.am,v 1.72 2010/05/29 00:44:02 dmh Exp $
|
||||
|
||||
AM_LDFLAGS = ${top_builddir}/liblib/libnetcdf.la @EXTERN_LDFLAGS@
|
||||
AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_builddir)/liblib @EXTERN_CFLAGS@
|
||||
# Put together AM_CPPFLAGS and AM_LDFLAGS.
|
||||
include $(top_srcdir)/lib_flags.am
|
||||
|
||||
# Unfortunately, libsrc4 contains nc_test.h
|
||||
AM_CPPFLAGS += -I$(top_srcdir)/libsrc4 -I$(top_srcdir)/libsrc
|
||||
# Link to our assembled library.
|
||||
AM_LDFLAGS += ${top_builddir}/liblib/libnetcdf.la -lhdf5_hl -lhdf5 -lz
|
||||
|
||||
# Our test programs and sources. (tst_h_vl2 must come after tst_vl.)
|
||||
NC4_TEST_PROGS = t_type cdm_sea_soundings tst_camrun tst_vl tst_atts \
|
||||
tst_atts2 tst_vars2 tst_files tst_files2
|
||||
# These are netCDF-4 test programs.
|
||||
NC4_TESTS = tst_dims tst_dims2 tst_dims3 tst_files tst_files4 tst_vars \
|
||||
tst_varms tst_unlim_vars tst_converts tst_converts2 tst_grps tst_grps2 \
|
||||
tst_compounds tst_compounds2 tst_compounds3 tst_opaques tst_strings \
|
||||
tst_strings2 tst_interops tst_interops4 tst_interops5 tst_interops6 \
|
||||
tst_enums tst_coords tst_coords2 tst_coords3 tst_vars3 tst_vars4 \
|
||||
tst_chunks tst_chunks2 tst_utf8 tst_fills tst_fills2 tst_fillbug \
|
||||
tst_xplatform tst_xplatform2 tst_h_atts2 tst_endian_fill tst_atts \
|
||||
t_type cdm_sea_soundings tst_camrun tst_vl tst_atts1 tst_atts2 \
|
||||
tst_vars2 tst_files5 tst_files6
|
||||
|
||||
check_PROGRAMS = $(NC4_TEST_PROGS)
|
||||
TESTS = $(NC4_TEST_PROGS)
|
||||
check_PROGRAMS = $(NC4_TESTS)
|
||||
|
||||
# Add these if large file tests are turned on.
|
||||
if LARGE_FILE_TESTS
|
||||
check_PROGRAMS += tst_large tst_large2
|
||||
endif
|
||||
|
||||
TESTS = $(NC4_TESTS)
|
||||
|
||||
# If the v2 API was built, add its test program.
|
||||
if BUILD_V2
|
||||
check_PROGRAMS += tst_v2
|
||||
TESTS += tst_v2
|
||||
@ -30,12 +42,17 @@ check_PROGRAMS += tst_large
|
||||
TESTS += tst_large
|
||||
endif # LARGE_FILE_TESTS
|
||||
|
||||
# If benchmarks were turned on, build and run a bunch more tests.
|
||||
if BUILD_BENCHMARKS
|
||||
check_PROGRAMS += tst_create_files bm_file tst_chunks tst_ar4 \
|
||||
tst_ar4_3d tst_ar4_4d bm_many_objs tst_h_many_atts bm_many_atts
|
||||
TESTS += tst_ar4_3d tst_create_files run_bm_test1.sh run_bm_elena.sh \
|
||||
run_bm_test2.sh run_tst_chunks.sh run_bm_ar4.sh
|
||||
check_PROGRAMS += tst_create_files bm_file tst_chunks3 tst_ar4 \
|
||||
tst_ar4_3d tst_ar4_4d bm_many_objs tst_h_many_atts bm_many_atts \
|
||||
tst_files2 tst_files3 tst_ar5 tst_h_files3
|
||||
|
||||
TESTS += tst_ar4_3d tst_create_files run_bm_test1.sh run_bm_elena.sh \
|
||||
run_bm_test2.sh run_tst_chunks.sh run_bm_ar4.sh tst_files2 tst_files3 \
|
||||
tst_ar5 tst_h_files3
|
||||
|
||||
# This will run a parallel I/O benchmark for parallel builds.
|
||||
if TEST_PARALLEL
|
||||
TESTS += run_par_bm_test.sh
|
||||
endif # TEST_PARALLEL
|
||||
@ -63,28 +80,17 @@ endif # USE_HDF4
|
||||
# This will run a bunch of the test programs with valgrind, the memory
|
||||
# checking tool. (Valgrind must be present for this to work.)
|
||||
if USE_VALGRIND_TESTS
|
||||
if USE_NETCDF4
|
||||
TESTS_ENVIRONMENT=USE_NETCDF4=1
|
||||
else
|
||||
TESTS_ENVIRONMENT=USE_NETCDF4=0
|
||||
endif
|
||||
TESTS += run_valgrind_tests.sh
|
||||
TESTS += run_valgrind_tests.sh run_valgrind_tests2.sh
|
||||
if USE_HDF4
|
||||
TESTS += run_hdf4_valgrind_tests.sh
|
||||
endif # USE_HDF4
|
||||
endif # USE_VALGRIND_TESTS
|
||||
|
||||
CLEANFILES = cdm_sea_soundings.nc bm_chunking.nc bm_radar.nc \
|
||||
bm_radar1.nc radar_3d_compression_test.txt radar_3d_compression.txt \
|
||||
radar_2d_compression.txt radar_3d_chunking.txt tst_floats_1D.cdl \
|
||||
floats_1D_3.nc floats_1D.cdl tst_*.nc tst_floats2_*.cdl \
|
||||
tst_ints2_*.cdl tst_shorts2_*.cdl tst_elena_*.cdl tst_simple*.cdl \
|
||||
tst_chunks.cdl pr_A1.* tauu_A1.* usi_01.* thetau_01.*
|
||||
|
||||
# This are extra tests that will only be run if netcdf-4 is configured
|
||||
# with --enable-parallel-tests.
|
||||
if TEST_PARALLEL
|
||||
check_PROGRAMS += tst_mpi_parallel tst_parallel tst_parallel3 \
|
||||
tst_parallel4 tst_nc4perf
|
||||
CLEANFILES += tst_mpi_parallel.bin tst_parallel.nc tst_parallel3.nc \
|
||||
tst_parallel4.nc tst_nc4perf.nc tst_parallel2.nc
|
||||
TESTS += run_par_test.sh
|
||||
if USE_PNETCDF
|
||||
check_PROGRAMS += tst_parallel2
|
||||
@ -96,7 +102,18 @@ EXTRA_DIST = run_par_test.sh run_bm.sh run_bm_test1.sh run_bm_test2.sh \
|
||||
run_bm_radar_2D.sh run_bm_radar_2D_compression1.sh run_par_bm_test.sh \
|
||||
run_bm_elena.sh run_par_bm_radar_2D.sh run_bm_radar_2D_endianness1.sh \
|
||||
run_tst_chunks.sh ref_chunks1.cdl ref_chunks2.cdl run_pnetcdf_test.sh \
|
||||
run_get_hdf4_files.sh run_valgrind_tests.sh run_bm_ar4.sh
|
||||
run_get_hdf4_files.sh run_valgrind_tests.sh run_valgrind_tests2.sh \
|
||||
run_bm_ar4.sh ref_tst_compounds.nc run_hdf4_valgrind_tests.sh \
|
||||
ref_tst_xplatform2_1.nc ref_tst_xplatform2_2.nc ref_tst_dims.nc \
|
||||
ref_tst_interops4.nc
|
||||
|
||||
CLEANFILES = tst_mpi_parallel.bin cdm_sea_soundings.nc bm_chunking.nc \
|
||||
bm_radar.nc bm_radar1.nc radar_3d_compression_test.txt \
|
||||
radar_3d_compression.txt radar_2d_compression.txt \
|
||||
radar_3d_chunking.txt tst_floats_1D.cdl floats_1D_3.nc floats_1D.cdl \
|
||||
tst_*.nc tst_floats2_*.cdl tst_ints2_*.cdl tst_shorts2_*.cdl \
|
||||
tst_elena_*.cdl tst_simple*.cdl tst_chunks.cdl pr_A1.* tauu_A1.* \
|
||||
usi_01.* thetau_01.* tst_*.nc tst_*.h5
|
||||
|
||||
if USE_HDF4_FILE_TESTS
|
||||
DISTCLEANFILES = AMSR_E_L2_Rain_V10_200905312326_A.hdf \
|
||||
@ -106,5 +123,20 @@ MYD29.A2002185.0000.005.2007160150627.hdf \
|
||||
MOD29.A2000055.0005.005.2006267200024.hdf
|
||||
endif # HDF4_FILE_TESTS
|
||||
|
||||
# These linker flags will be applied to all test program compiles.
|
||||
#LDADD = -lnetcdf
|
||||
|
||||
# if USE_HDF4
|
||||
# LDADD += -lmfhdf -ldf -ljpeg
|
||||
# endif # USE_HDF4
|
||||
|
||||
# LDADD += -lhdf5_hl -lhdf5 -lz -lm
|
||||
|
||||
# if USE_PNETCDF
|
||||
# LDADD += -lpnetcdf
|
||||
# endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
BIN
nc_test4/ref_tst_compounds.nc
Normal file
BIN
nc_test4/ref_tst_compounds.nc
Normal file
Binary file not shown.
@ -20,7 +20,7 @@ mpiexec -n 2 ./tst_parallel4
|
||||
mpiexec -n 4 ./tst_parallel4
|
||||
mpiexec -n 8 ./tst_parallel4
|
||||
mpiexec -n 16 ./tst_parallel4
|
||||
mpiexec -n 32 ./tst_parallel4
|
||||
#mpiexec -n 32 ./tst_parallel4
|
||||
#mpiexec -n 64 ./tst_parallel4
|
||||
echo
|
||||
echo "Parallel Performance Test for NASA"
|
||||
|
@ -1,15 +1,15 @@
|
||||
#!/bin/sh
|
||||
|
||||
# This shell just tests the tst_chunks program by running it a few
|
||||
# This shell just tests the tst_chunks3 program by running it a few
|
||||
# times to generate a simple test file. Then it uses ncdump -s to
|
||||
# check that the output is what it should be.
|
||||
|
||||
# $Id: run_tst_chunks.sh,v 1.2 2009/02/24 01:49:12 russ Exp $
|
||||
# $Id: run_tst_chunks3.sh,v 1.2 2009/02/24 01:49:12 russ Exp $
|
||||
|
||||
set -e
|
||||
echo ""
|
||||
|
||||
echo "*** Running benchmarking program tst_chunks for tiny test file"
|
||||
echo "*** Running benchmarking program tst_chunks3 for tiny test file"
|
||||
compress_level=1
|
||||
dim1=6
|
||||
chunk1=2
|
||||
@ -17,13 +17,13 @@ dim2=12
|
||||
chunk2=3
|
||||
dim3=4
|
||||
chunk3=1
|
||||
./tst_chunks $compress_level $dim1 $chunk1 $dim2 $chunk2 $dim3 $chunk3
|
||||
../ncdump/ncdump -s tst_chunks.nc > tst_chunks.cdl
|
||||
diff tst_chunks.cdl ref_chunks1.cdl
|
||||
./tst_chunks3 $compress_level $dim1 $chunk1 $dim2 $chunk2 $dim3 $chunk3
|
||||
../ncdump/ncdump -n tst_chunks -s tst_chunks3.nc > tst_chunks3.cdl
|
||||
diff tst_chunks3.cdl ref_chunks1.cdl
|
||||
echo '*** SUCCESS!!!'
|
||||
|
||||
echo ""
|
||||
echo "*** Testing the benchmarking program tst_chunks for larger variables ..."
|
||||
echo "*** Testing the benchmarking program tst_chunks3 for larger variables ..."
|
||||
compress_level=1
|
||||
dim1=32
|
||||
chunk1=8
|
||||
@ -34,9 +34,9 @@ chunk3=13
|
||||
cachesize=10000000
|
||||
cachehash=10000
|
||||
cachepre=0.0
|
||||
./tst_chunks $compress_level $dim1 $chunk1 $dim2 $chunk2 $dim3 $chunk3 $cachesize $cachehash $cachepre
|
||||
../ncdump/ncdump -s -h tst_chunks.nc > tst_chunks.cdl
|
||||
diff tst_chunks.cdl ref_chunks2.cdl
|
||||
./tst_chunks3 $compress_level $dim1 $chunk1 $dim2 $chunk2 $dim3 $chunk3 $cachesize $cachehash $cachepre
|
||||
../ncdump/ncdump -n tst_chunks -s -h tst_chunks3.nc > tst_chunks3.cdl
|
||||
diff tst_chunks3.cdl ref_chunks2.cdl
|
||||
echo '*** SUCCESS!!!'
|
||||
|
||||
exit 0
|
@ -2,24 +2,26 @@
|
||||
|
||||
# This shell runs the tests with valgrind.
|
||||
|
||||
# $Id: run_valgrind_tests.sh,v 1.9 2010/01/26 20:24:18 ed Exp $
|
||||
|
||||
set -e
|
||||
echo ""
|
||||
echo "Testing programs with valgrind..."
|
||||
|
||||
# These are my test programs.
|
||||
list="t_type tst_camrun tst_vl tst_v2 tst_vars2 \
|
||||
tst_atts2 tst_files2 tst_files"
|
||||
# If we are running with netcdf4, then add tst_atts
|
||||
if test "x$USE_NETCDF4" = "x1" ; then
|
||||
list="$list tst_atts"
|
||||
fi
|
||||
list='tst_dims tst_dims2 tst_dims3 tst_files tst_files4 tst_vars '\
|
||||
'tst_varms tst_unlim_vars tst_converts tst_converts2 tst_grps '\
|
||||
'tst_compounds tst_compounds2 tst_compounds3 tst_opaques tst_strings '\
|
||||
'tst_strings2 tst_interops tst_interops4 tst_interops5 tst_interops6 '\
|
||||
'tst_enums tst_coords tst_coords2 tst_coords3 tst_vars3 tst_chunks '\
|
||||
'tst_utf8 tst_fills tst_fills2 tst_fillbug tst_xplatform '\
|
||||
'tst_h_atts2 tst_endian_fill tst_atts'
|
||||
|
||||
# These don't work yet: tst_grps2 tst_xplatform2
|
||||
|
||||
for tst in $list; do
|
||||
echo ""
|
||||
echo "Memory testing with $tst:"
|
||||
valgrind -q --error-exitcode=2 --leak-check=full ./$tst
|
||||
cmd1="valgrind -q --error-exitcode=2 --leak-check=full ./$tst"
|
||||
echo "$cmd1:"
|
||||
$cmd1
|
||||
done
|
||||
|
||||
echo "SUCCESS!!!"
|
||||
|
23
nc_test4/run_valgrind_tests2.sh
Executable file
23
nc_test4/run_valgrind_tests2.sh
Executable file
@ -0,0 +1,23 @@
|
||||
#!/bin/sh
|
||||
|
||||
# This shell runs the tests with valgrind.
|
||||
|
||||
# $Id: run_valgrind_tests.sh,v 1.9 2010/01/26 20:24:18 ed Exp $
|
||||
|
||||
set -e
|
||||
echo ""
|
||||
echo "Testing programs with valgrind..."
|
||||
|
||||
# These are my test programs.
|
||||
list="t_type tst_camrun tst_vl tst_v2 tst_vars2 \
|
||||
tst_atts2 tst_files tst_atts"
|
||||
|
||||
for tst in $list; do
|
||||
echo ""
|
||||
echo "Memory testing with $tst:"
|
||||
valgrind -q --error-exitcode=2 --leak-check=full ./$tst
|
||||
done
|
||||
|
||||
echo "SUCCESS!!!"
|
||||
|
||||
exit 0
|
@ -1,792 +1,104 @@
|
||||
/* This is part of the netCDF package. Copyright 2005-2007 University
|
||||
Corporation for Atmospheric Research/Unidata. See COPYRIGHT file
|
||||
for conditions of use.
|
||||
/* This is part of the netCDF package.
|
||||
Copyright 2006 University Corporation for Atmospheric Research/Unidata.
|
||||
See COPYRIGHT file for conditions of use.
|
||||
|
||||
Test attributes.
|
||||
This is a very simple example which writes a netCDF file with
|
||||
Unicode names encoded with UTF-8. It is the NETCDF3 equivalent
|
||||
of tst_unicode.c
|
||||
|
||||
$Id: tst_atts.c,v 1.39 2009/09/27 20:52:13 ed Exp $
|
||||
$Id$
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
#include <stdlib.h>
|
||||
#include <nc_tests.h>
|
||||
#include "netcdf.h"
|
||||
#include "nc4internal.h"
|
||||
#include <signal.h>
|
||||
#include <netcdf.h>
|
||||
#include <string.h>
|
||||
|
||||
/* The data file we will create. */
|
||||
#define FILE_NAME "tst_atts.nc"
|
||||
#define FILE_NAME2 "tst_atts_2.nc"
|
||||
#define VAR1_NAME "Horace_Rumpole"
|
||||
#define VAR2_NAME "Claude_Erskine-Brown"
|
||||
#define VAR3_NAME "Phillida_Erskine-Brown_Q.C."
|
||||
#define DIM1_NAME "Old_Bailey_case_number"
|
||||
#define DIM1_LEN 10
|
||||
#define DIM2_NAME "occupancy_in_chambers"
|
||||
#define DIM2_LEN 15
|
||||
#define ATT_INT_NAME "Old_Bailey_Room_Numbers"
|
||||
#define ATT_DOUBLE_NAME "Equity_Court_Canteen_Charges"
|
||||
#define ATT_SHORT_NAME "Ecclesiastical_Court_Appearences"
|
||||
#define ATT_TEXT_NAME "Speech_to_Jury"
|
||||
#define ATT_TEXT_NAME2 "Speech_to_She_Who_Must_be_Obeyed"
|
||||
#define ATT_UCHAR_NAME "Number_of_current_briefs"
|
||||
#define ATT_SCHAR_NAME "Slate_totals_at_Pomeroys_Wine_Bar"
|
||||
#define ATT_USHORT_NAME "brief_no"
|
||||
#define ATT_UINT_NAME "Orders_from_SWMBO"
|
||||
#define ATT_INT64_NAME "judges_golf_score"
|
||||
#define ATT_UINT64_NAME "Number_of_drinks_in_career_to_date"
|
||||
|
||||
/*
|
||||
#define ATT_USHORT_NAME "Chamber_Gas_Electric_and_Telephone_Bill_Share"
|
||||
*/
|
||||
#define ATT_FLOAT_NAME "Average_Nanoseconds_for_Lose_Win_or_Appeal"
|
||||
#define ATT_LEN 3
|
||||
|
||||
char speech[] = "Once more unto the breach, dear friends, once more;\n\
|
||||
Or close the wall up with our English dead.\n\
|
||||
In peace there's nothing so becomes a man\n\
|
||||
As modest stillness and humility:\n\
|
||||
But when the blast of war blows in our ears,\n\
|
||||
Then imitate the action of the tiger;\n\
|
||||
Stiffen the sinews, summon up the blood,\n\
|
||||
Disguise fair nature with hard-favour'd rage;\n\
|
||||
Then lend the eye a terrible aspect;\n\
|
||||
Let pry through the portage of the head\n\
|
||||
Like the brass cannon; let the brow o'erwhelm it\n\
|
||||
As fearfully as doth a galled rock\n\
|
||||
O'erhang and jutty his confounded base,\n\
|
||||
Swill'd with the wild and wasteful ocean.\n\
|
||||
Now set the teeth and stretch the nostril wide,\n\
|
||||
Hold hard the breath and bend up every spirit\n\
|
||||
To his full height. On, on, you noblest English.\n\
|
||||
Whose blood is fet from fathers of war-proof!\n\
|
||||
Fathers that, like so many Alexanders,\n\
|
||||
Have in these parts from morn till even fought\n\
|
||||
And sheathed their swords for lack of argument:\n\
|
||||
Dishonour not your mothers; now attest\n\
|
||||
That those whom you call'd fathers did beget you.\n\
|
||||
Be copy now to men of grosser blood,\n\
|
||||
And teach them how to war. And you, good yeoman,\n\
|
||||
Whose limbs were made in England, show us here\n\
|
||||
The mettle of your pasture; let us swear\n\
|
||||
That you are worth your breeding; which I doubt not;\n\
|
||||
For there is none of you so mean and base,\n\
|
||||
That hath not noble lustre in your eyes.\n\
|
||||
I see you stand like greyhounds in the slips,\n\
|
||||
Straining upon the start. The game's afoot:\n\
|
||||
Follow your spirit, and upon this charge\n\
|
||||
Cry 'God for Harry, England, and Saint George!'";
|
||||
|
||||
/* Test the ordering of atts for a cmode. */
|
||||
#define NUM_ATTS 8
|
||||
#define ATT_MAX_NAME 25
|
||||
int
|
||||
tst_att_ordering(int cmode)
|
||||
{
|
||||
int ncid;
|
||||
char name[NUM_ATTS][ATT_MAX_NAME + 1] = {"Gc", "Gb", "Gs", "Gi", "Gf",
|
||||
"Gd", "Gatt-name-dashes", "Gatt.name.dots"};
|
||||
int len[NUM_ATTS] = {0, 2, 3, 3, 3, 3, 1, 1};
|
||||
signed char b[2] = {-128, 127};
|
||||
short s[3] = {-32768, 0, 32767};
|
||||
int i[3] = {42, 0, -42};
|
||||
float f[3] = {42.0, -42.0, 42.0};
|
||||
double d[3] = {420.0, -420.0, 420.0};
|
||||
int att_name_dashes = -1, att_name_dots = -2;
|
||||
char name_in[NC_MAX_NAME];
|
||||
int j;
|
||||
|
||||
/* Create a file with some global atts. */
|
||||
if (nc_create(FILE_NAME, cmode, &ncid)) ERR;
|
||||
if (nc_put_att_text(ncid, NC_GLOBAL, name[0], len[0], NULL)) ERR;
|
||||
if (nc_put_att_schar(ncid, NC_GLOBAL, name[1], NC_BYTE, len[1], b)) ERR;
|
||||
if (nc_put_att_short(ncid, NC_GLOBAL, name[2], NC_SHORT, len[2], s)) ERR;
|
||||
if (nc_put_att_int(ncid, NC_GLOBAL, name[3], NC_INT, len[3], i)) ERR;
|
||||
if (nc_put_att_float(ncid, NC_GLOBAL, name[4], NC_FLOAT, len[4], f)) ERR;
|
||||
if (nc_put_att_double(ncid, NC_GLOBAL, name[5], NC_DOUBLE, len[5], d)) ERR;
|
||||
if (nc_put_att_int(ncid, NC_GLOBAL, name[6], NC_INT, len[6], &att_name_dashes)) ERR;
|
||||
if (nc_put_att_int(ncid, NC_GLOBAL, name[7], NC_INT, len[7], &att_name_dots)) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
/* Reopen the file and check the order. */
|
||||
if (nc_open(FILE_NAME, 0, &ncid)) ERR;
|
||||
for (j = 0; j < NUM_ATTS; j++)
|
||||
{
|
||||
if (nc_inq_attname(ncid, NC_GLOBAL, j, name_in)) ERR;
|
||||
if (strcmp(name_in, name[j])) ERR;
|
||||
}
|
||||
|
||||
/* Close up shop. */
|
||||
if (nc_close(ncid)) ERR;
|
||||
return err;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
(void) signal(SIGFPE, SIG_IGN);
|
||||
|
||||
printf("\n*** Testing netcdf-4 attribute functions.\n");
|
||||
printf("*** testing really simple global atts...");
|
||||
#define NUM_SIMPLE_ATTS 9
|
||||
printf("\n*** Testing netCDF-4 attributes.\n");
|
||||
printf("*** testing attribute renaming for a global attribute...");
|
||||
{
|
||||
int ncid;
|
||||
char name[NUM_SIMPLE_ATTS][ATT_MAX_NAME + 1] = {"Gc", "Gb", "Gs", "Gi", "Gf",
|
||||
"Gd", "G7", "G8", "G9"};
|
||||
char name_in[NC_MAX_NAME];
|
||||
int j;
|
||||
#define OLD_NAME "Constantinople"
|
||||
#define NEW_NAME "Istanbul"
|
||||
#define CONTENTS "Lots of people!"
|
||||
|
||||
int ncid, attid;
|
||||
char *data_in;
|
||||
|
||||
/* Create a file with some global atts. */
|
||||
if (!(data_in = malloc(strlen(CONTENTS) + 1))) ERR;
|
||||
|
||||
/* Create a file with an att. */
|
||||
if (nc_create(FILE_NAME, NC_NETCDF4|NC_CLOBBER, &ncid)) ERR;
|
||||
for (j = 0; j < NUM_SIMPLE_ATTS; j++)
|
||||
if (nc_put_att_int(ncid, NC_GLOBAL, name[j], NC_INT, 0, NULL)) ERR;
|
||||
if (nc_put_att_text(ncid, NC_GLOBAL, OLD_NAME, strlen(CONTENTS),
|
||||
CONTENTS)) ERR;
|
||||
|
||||
/* Rename the att. */
|
||||
if (nc_rename_att(ncid, NC_GLOBAL, OLD_NAME, NEW_NAME)) ERR;
|
||||
|
||||
/* Check the file. */
|
||||
if (nc_inq_attid(ncid, NC_GLOBAL, NEW_NAME, &attid)) ERR;
|
||||
if (attid != 0) ERR;
|
||||
if (nc_get_att_text(ncid, NC_GLOBAL, NEW_NAME, data_in)) ERR;
|
||||
if (strncmp(CONTENTS, data_in, strlen(CONTENTS))) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
/* Reopen the file and check the order. */
|
||||
if (nc_open(FILE_NAME, 0, &ncid)) ERR;
|
||||
for (j = 0; j < NUM_SIMPLE_ATTS; j++)
|
||||
{
|
||||
if (nc_inq_attname(ncid, NC_GLOBAL, j, name_in)) ERR;
|
||||
if (strcmp(name_in, name[j])) ERR;
|
||||
}
|
||||
/* Reopen the file and check again. */
|
||||
if (nc_open(FILE_NAME, NC_NOWRITE, &ncid)) ERR;
|
||||
|
||||
/* Close up shop. */
|
||||
if (nc_inq_attid(ncid, NC_GLOBAL, NEW_NAME, &attid)) ERR;
|
||||
if (attid != 0) ERR;
|
||||
if (nc_get_att_text(ncid, NC_GLOBAL, NEW_NAME, data_in)) ERR;
|
||||
if (strncmp(CONTENTS, data_in, strlen(CONTENTS))) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
free(data_in);
|
||||
}
|
||||
SUMMARIZE_ERR;
|
||||
printf("*** testing simple global atts...");
|
||||
{
|
||||
int ncid;
|
||||
nc_type att_type;
|
||||
size_t att_len;
|
||||
int i;
|
||||
|
||||
char *speech_in;
|
||||
signed char schar_in[ATT_LEN], schar_out[ATT_LEN] = {NC_MIN_BYTE, 1, NC_MAX_BYTE};
|
||||
unsigned char uchar_in[ATT_LEN], uchar_out[ATT_LEN] = {0, 128, NC_MAX_CHAR};
|
||||
short short_in[ATT_LEN], short_out[ATT_LEN] = {NC_MIN_SHORT, -128, NC_MAX_SHORT};
|
||||
/*int int_in[ATT_LEN], int_out[ATT_LEN] = {NC_MIN_INT, 128, NC_MAX_INT};*/
|
||||
int int_in[ATT_LEN], int_out[ATT_LEN] = {-100000, 128, 100000};
|
||||
float float_in[ATT_LEN], float_out[ATT_LEN] = {.5, 0.25, 0.125};
|
||||
double double_in[ATT_LEN], double_out[ATT_LEN] = {0.25, .5, 0.125};
|
||||
unsigned short ushort_in[ATT_LEN], ushort_out[ATT_LEN] = {0, 128, NC_MAX_USHORT};
|
||||
unsigned int uint_in[ATT_LEN], uint_out[ATT_LEN] = {0, 128, NC_MAX_UINT};
|
||||
unsigned long long uint64_in[ATT_LEN], uint64_out[ATT_LEN] = {0, 128, 18446744073709551612ULL};
|
||||
long long int64_in[ATT_LEN], int64_out[ATT_LEN] = {NC_MIN_INT64, 128, NC_MAX_INT64};
|
||||
|
||||
|
||||
/* This won't work, because classic files can't create these types. */
|
||||
if (nc_create(FILE_NAME, NC_NETCDF4|NC_CLASSIC_MODEL, &ncid)) ERR;
|
||||
if (nc_put_att_ushort(ncid, NC_GLOBAL, ATT_USHORT_NAME, NC_USHORT, ATT_LEN,
|
||||
ushort_out) != NC_ESTRICTNC3) ERR;
|
||||
if (nc_put_att_uint(ncid, NC_GLOBAL, ATT_UINT_NAME, NC_UINT, ATT_LEN,
|
||||
uint_out) != NC_ESTRICTNC3) ERR;
|
||||
if (nc_put_att_longlong(ncid, NC_GLOBAL, ATT_INT64_NAME, NC_INT64, ATT_LEN,
|
||||
int64_out) != NC_ESTRICTNC3) ERR;
|
||||
if (nc_put_att_ulonglong(ncid, NC_GLOBAL, ATT_UINT64_NAME, NC_UINT64, ATT_LEN,
|
||||
uint64_out) != NC_ESTRICTNC3) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
/* Create a file with a global attribute of each type. */
|
||||
if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
|
||||
if (nc_put_att_text(ncid, NC_GLOBAL, ATT_TEXT_NAME, strlen(speech)+1, speech)) ERR;
|
||||
if (nc_put_att_schar(ncid, NC_GLOBAL, ATT_SCHAR_NAME, NC_BYTE, ATT_LEN, schar_out)) ERR;
|
||||
if (nc_put_att_uchar(ncid, NC_GLOBAL, ATT_UCHAR_NAME, NC_UBYTE, ATT_LEN, uchar_out)) ERR;
|
||||
if (nc_put_att_short(ncid, NC_GLOBAL, ATT_SHORT_NAME, NC_SHORT, ATT_LEN, short_out)) ERR;
|
||||
if (nc_put_att_int(ncid, NC_GLOBAL, ATT_INT_NAME, NC_INT, ATT_LEN, int_out)) ERR;
|
||||
if (nc_put_att_float(ncid, NC_GLOBAL, ATT_FLOAT_NAME, NC_FLOAT, ATT_LEN, float_out)) ERR;
|
||||
if (nc_put_att_double(ncid, NC_GLOBAL, ATT_DOUBLE_NAME, NC_DOUBLE, ATT_LEN, double_out)) ERR;
|
||||
if (nc_put_att_ushort(ncid, NC_GLOBAL, ATT_USHORT_NAME, NC_USHORT, ATT_LEN, ushort_out)) ERR;
|
||||
if (nc_put_att_uint(ncid, NC_GLOBAL, ATT_UINT_NAME, NC_UINT, ATT_LEN, uint_out)) ERR;
|
||||
if (nc_put_att_longlong(ncid, NC_GLOBAL, ATT_INT64_NAME, NC_INT64, ATT_LEN, int64_out)) ERR;
|
||||
if (nc_put_att_ulonglong(ncid, NC_GLOBAL, ATT_UINT64_NAME, NC_UINT64, ATT_LEN, uint64_out)) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
/* Open the file and check attributes. */
|
||||
if (nc_open(FILE_NAME, 0, &ncid)) ERR;
|
||||
/* Check text. */
|
||||
if (nc_inq_att(ncid, NC_GLOBAL, ATT_TEXT_NAME, &att_type, &att_len))
|
||||
ERR;
|
||||
if (att_type != NC_CHAR || att_len != strlen(speech) + 1) ERR;
|
||||
if (!(speech_in = malloc(att_len + 1))) ERR;
|
||||
if (nc_get_att_text(ncid, NC_GLOBAL, ATT_TEXT_NAME, speech_in)) ERR;
|
||||
if (strcmp(speech, speech_in)) ERR;
|
||||
free(speech_in);
|
||||
/* Check numeric values. */
|
||||
if (nc_get_att_schar(ncid, NC_GLOBAL, ATT_SCHAR_NAME, schar_in)) ERR;
|
||||
for (i = 0; i < ATT_LEN; i++)
|
||||
if (schar_in[i] != schar_out[i]) ERR;
|
||||
if (nc_get_att_uchar(ncid, NC_GLOBAL, ATT_UCHAR_NAME, uchar_in)) ERR;
|
||||
for (i = 0; i < ATT_LEN; i++)
|
||||
if (uchar_in[i] != uchar_out[i]) ERR;
|
||||
if (nc_get_att_short(ncid, NC_GLOBAL, ATT_SHORT_NAME, short_in)) ERR;
|
||||
for (i = 0; i < ATT_LEN; i++)
|
||||
if (short_in[i] != short_out[i]) ERR;
|
||||
if (nc_get_att_int(ncid, NC_GLOBAL, ATT_INT_NAME, int_in)) ERR;
|
||||
for (i = 0; i < ATT_LEN; i++)
|
||||
if (int_in[i] != int_out[i]) ERR;
|
||||
if (nc_get_att_float(ncid, NC_GLOBAL, ATT_FLOAT_NAME, float_in)) ERR;
|
||||
for (i = 0; i < ATT_LEN; i++)
|
||||
if (float_in[i] != float_out[i]) ERR;
|
||||
if (nc_get_att_double(ncid, NC_GLOBAL, ATT_DOUBLE_NAME, double_in)) ERR;
|
||||
for (i = 0; i < ATT_LEN; i++)
|
||||
if (double_in[i] != double_out[i]) ERR;
|
||||
if (nc_get_att_ushort(ncid, NC_GLOBAL, ATT_USHORT_NAME, ushort_in)) ERR;
|
||||
for (i = 0; i < ATT_LEN; i++)
|
||||
if (ushort_in[i] != ushort_out[i]) ERR;
|
||||
if (nc_get_att_uint(ncid, NC_GLOBAL, ATT_UINT_NAME, uint_in)) ERR;
|
||||
for (i = 0; i < ATT_LEN; i++)
|
||||
if (uint_in[i] != uint_out[i]) ERR;
|
||||
if (nc_get_att_longlong(ncid, NC_GLOBAL, ATT_INT64_NAME, int64_in)) ERR;
|
||||
for (i = 0; i < ATT_LEN; i++)
|
||||
if (int64_in[i] != int64_out[i]) ERR;
|
||||
if (nc_get_att_ulonglong(ncid, NC_GLOBAL, ATT_UINT64_NAME, uint64_in)) ERR;
|
||||
for (i = 0; i < ATT_LEN; i++)
|
||||
if (uint64_in[i] != uint64_out[i]) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
}
|
||||
SUMMARIZE_ERR;
|
||||
printf("*** testing attribute data type conversions...");
|
||||
|
||||
printf("*** testing attribute renaming for a variable attribute...");
|
||||
{
|
||||
int ncid;
|
||||
int i;
|
||||
#define VAR_NAME "var_name"
|
||||
#define OLD_NAME1 "Constantinople"
|
||||
#define NEW_NAME1 "Istanbul____________"
|
||||
#define CONTENTS1 "Lots of people!"
|
||||
|
||||
signed char schar_in[ATT_LEN], schar_out[ATT_LEN] = {NC_MIN_BYTE, 1, NC_MAX_BYTE};
|
||||
short short_in[ATT_LEN], short_out[ATT_LEN] = {NC_MIN_SHORT, -128, NC_MAX_SHORT};
|
||||
/*int int_in[ATT_LEN], int_out[ATT_LEN] = {NC_MIN_INT, 128, NC_MAX_INT};*/
|
||||
int int_in[ATT_LEN], int_out[ATT_LEN] = {-100000, 128, 100000};
|
||||
float float_in[ATT_LEN], float_out[ATT_LEN] = {.5, 0.25, 0.125};
|
||||
double double_in[ATT_LEN], double_out[ATT_LEN] = {0.25, .5, 0.125};
|
||||
unsigned short ushort_in[ATT_LEN];
|
||||
unsigned int uint_in[ATT_LEN];
|
||||
unsigned long long uint64_in[ATT_LEN];
|
||||
long long int64_in[ATT_LEN];
|
||||
int ncid, attid, varid;
|
||||
char *data_in;
|
||||
|
||||
/* Reopen the file and try different type conversions. */
|
||||
if (nc_open(FILE_NAME, 0, &ncid)) ERR;
|
||||
if (!(data_in = malloc(strlen(CONTENTS1) + 1))) ERR;
|
||||
|
||||
/* No text conversions are allowed, and people who try them shold
|
||||
* be locked up, away from decent folk! */
|
||||
if (nc_get_att_short(ncid, NC_GLOBAL, ATT_TEXT_NAME, short_in) != NC_ECHAR) ERR;
|
||||
if (nc_get_att_int(ncid, NC_GLOBAL, ATT_TEXT_NAME, int_in) != NC_ECHAR) ERR;
|
||||
if (nc_get_att_float(ncid, NC_GLOBAL, ATT_TEXT_NAME, float_in) != NC_ECHAR) ERR;
|
||||
if (nc_get_att_double(ncid, NC_GLOBAL, ATT_TEXT_NAME, double_in) != NC_ECHAR) ERR;
|
||||
/* if (nc_get_att_ubyte(ncid, NC_GLOBAL, ATT_TEXT_NAME, uchar_in) != NC_ECHAR) ERR;*/
|
||||
if (nc_get_att_ushort(ncid, NC_GLOBAL, ATT_TEXT_NAME, ushort_in) != NC_ECHAR) ERR;
|
||||
if (nc_get_att_uint(ncid, NC_GLOBAL, ATT_TEXT_NAME, uint_in) != NC_ECHAR) ERR;
|
||||
if (nc_get_att_longlong(ncid, NC_GLOBAL, ATT_TEXT_NAME, int64_in) != NC_ECHAR) ERR;
|
||||
if (nc_get_att_ulonglong(ncid, NC_GLOBAL, ATT_TEXT_NAME, uint64_in) != NC_ECHAR) ERR;
|
||||
|
||||
/* Read all atts (except text) as double. */
|
||||
if (nc_get_att_double(ncid, NC_GLOBAL, ATT_SCHAR_NAME, double_in)) ERR;
|
||||
for (i = 0; i < ATT_LEN; i++)
|
||||
if (double_in[i] != schar_out[i]) ERR;
|
||||
if (nc_get_att_double(ncid, NC_GLOBAL, ATT_SHORT_NAME, double_in)) ERR;
|
||||
for (i = 0; i < ATT_LEN; i++)
|
||||
if (double_in[i] != short_out[i]) ERR;
|
||||
if (nc_get_att_double(ncid, NC_GLOBAL, ATT_INT_NAME, double_in)) ERR;
|
||||
for (i = 0; i < ATT_LEN; i++)
|
||||
if (double_in[i] != int_out[i]) ERR;
|
||||
if (nc_get_att_double(ncid, NC_GLOBAL, ATT_FLOAT_NAME, double_in)) ERR;
|
||||
for (i = 0; i < ATT_LEN; i++)
|
||||
if (double_in[i] != float_out[i]) ERR;
|
||||
/* Read all atts (except text) as float. */
|
||||
if (nc_get_att_float(ncid, NC_GLOBAL, ATT_SCHAR_NAME, float_in)) ERR;
|
||||
for (i = 0; i < ATT_LEN; i++)
|
||||
if (float_in[i] != schar_out[i]) ERR;
|
||||
if (nc_get_att_float(ncid, NC_GLOBAL, ATT_SHORT_NAME, float_in)) ERR;
|
||||
for (i = 0; i < ATT_LEN; i++)
|
||||
if (float_in[i] != short_out[i]) ERR;
|
||||
if (nc_get_att_float(ncid, NC_GLOBAL, ATT_INT_NAME, float_in)) ERR;
|
||||
for (i = 0; i < ATT_LEN; i++)
|
||||
if (float_in[i] != (float)int_out[i]) ERR;
|
||||
if (nc_get_att_float(ncid, NC_GLOBAL, ATT_DOUBLE_NAME, float_in)) ERR;
|
||||
for (i = 0; i < ATT_LEN; i++)
|
||||
if (float_in[i] != (float)double_out[i]) ERR;
|
||||
/* Read all atts (except text) as int. */
|
||||
if (nc_get_att_int(ncid, NC_GLOBAL, ATT_SCHAR_NAME, int_in)) ERR;
|
||||
for (i = 0; i < ATT_LEN; i++)
|
||||
if (int_in[i] != schar_out[i]) ERR;
|
||||
if (nc_get_att_int(ncid, NC_GLOBAL, ATT_SHORT_NAME, int_in)) ERR;
|
||||
for (i = 0; i < ATT_LEN; i++)
|
||||
if (int_in[i] != short_out[i]) ERR;
|
||||
if (nc_get_att_int(ncid, NC_GLOBAL, ATT_FLOAT_NAME, int_in)) ERR;
|
||||
for (i = 0; i < ATT_LEN; i++)
|
||||
if (int_in[i] != (int)float_out[i]) ERR;
|
||||
if (nc_get_att_int(ncid, NC_GLOBAL, ATT_DOUBLE_NAME, int_in)) ERR;
|
||||
for (i = 0; i < ATT_LEN; i++)
|
||||
if (int_in[i] != (int)double_out[i]) ERR;
|
||||
/* Read all atts (except text) as short. */
|
||||
if (nc_get_att_short(ncid, NC_GLOBAL, ATT_SCHAR_NAME, short_in)) ERR;
|
||||
for (i = 0; i < ATT_LEN; i++)
|
||||
if (short_in[i] != schar_out[i]) ERR;
|
||||
if (nc_get_att_short(ncid, NC_GLOBAL, ATT_INT_NAME, short_in) != NC_ERANGE) ERR;
|
||||
for (i = 0; i < ATT_LEN; i++)
|
||||
if (short_in[i] != (short)int_out[i]) ERR;
|
||||
if (nc_get_att_short(ncid, NC_GLOBAL, ATT_FLOAT_NAME, short_in)) ERR;
|
||||
for (i = 0; i < ATT_LEN; i++)
|
||||
if (short_in[i] != (short)float_out[i]) ERR;
|
||||
if (nc_get_att_short(ncid, NC_GLOBAL, ATT_DOUBLE_NAME, short_in)) ERR;
|
||||
for (i = 0; i < ATT_LEN; i++)
|
||||
if (short_in[i] != (short)double_out[i]) ERR;
|
||||
/* Read all atts (except text) as schar. Some range errors will
|
||||
* result converting to schar. */
|
||||
if (nc_get_att_schar(ncid, NC_GLOBAL, ATT_SHORT_NAME, schar_in) != NC_ERANGE) ERR;
|
||||
for (i = 0; i < ATT_LEN; i++)
|
||||
if (schar_in[i] != (signed char)short_out[i]) ERR;
|
||||
if (nc_get_att_schar(ncid, NC_GLOBAL, ATT_INT_NAME, schar_in) != NC_ERANGE) ERR;
|
||||
for (i = 0; i < ATT_LEN; i++)
|
||||
if (schar_in[i] != (signed char)int_out[i]) ERR;
|
||||
if (nc_get_att_schar(ncid, NC_GLOBAL, ATT_FLOAT_NAME, schar_in)) ERR;
|
||||
for (i = 0; i < ATT_LEN; i++)
|
||||
if (schar_in[i] != (signed char)float_out[i]) ERR;
|
||||
if (nc_get_att_schar(ncid, NC_GLOBAL, ATT_DOUBLE_NAME, schar_in)) ERR;
|
||||
for (i = 0; i < ATT_LEN; i++)
|
||||
if (schar_in[i] != (signed char)double_out[i]) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
}
|
||||
SUMMARIZE_ERR;
|
||||
printf("*** testing simple variable atts...");
|
||||
{
|
||||
int ncid, varid, dimids[2];
|
||||
nc_type att_type;
|
||||
size_t att_len;
|
||||
int i, v;
|
||||
|
||||
char *speech_in;
|
||||
signed char schar_in[ATT_LEN], schar_out[ATT_LEN] = {NC_MIN_BYTE, 1, NC_MAX_BYTE};
|
||||
short short_in[ATT_LEN], short_out[ATT_LEN] = {NC_MIN_SHORT, -128, NC_MAX_SHORT};
|
||||
/*int int_in[ATT_LEN], int_out[ATT_LEN] = {NC_MIN_INT, 128, NC_MAX_INT};*/
|
||||
int int_in[ATT_LEN], int_out[ATT_LEN] = {-100000, 128, 100000};
|
||||
float float_in[ATT_LEN], float_out[ATT_LEN] = {.5, 0.25, 0.125};
|
||||
double double_in[ATT_LEN], double_out[ATT_LEN] = {0.25, .5, 0.125};
|
||||
|
||||
/* Create a file with two vars, attaching to each an attribute of
|
||||
* each type. */
|
||||
if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
|
||||
if (nc_def_dim(ncid, DIM1_NAME, DIM1_LEN, &dimids[0])) ERR;
|
||||
if (nc_def_dim(ncid, DIM2_NAME, DIM2_LEN, &dimids[1])) ERR;
|
||||
if (nc_def_var(ncid, VAR1_NAME, NC_INT, 2, dimids, &varid)) ERR;
|
||||
if (nc_put_att_text(ncid, varid, ATT_TEXT_NAME, strlen(speech)+1, speech)) ERR;
|
||||
if (nc_put_att_schar(ncid, varid, ATT_SCHAR_NAME, NC_BYTE, ATT_LEN, schar_out)) ERR;
|
||||
if (nc_put_att_short(ncid, varid, ATT_SHORT_NAME, NC_SHORT, 3, short_out)) ERR;
|
||||
if (nc_put_att_int(ncid, varid, ATT_INT_NAME, NC_INT, 3, int_out)) ERR;
|
||||
if (nc_put_att_float(ncid, varid, ATT_FLOAT_NAME, NC_FLOAT, 3, float_out)) ERR;
|
||||
if (nc_put_att_double(ncid, varid, ATT_DOUBLE_NAME, NC_DOUBLE, 3, double_out)) ERR;
|
||||
if (nc_def_var(ncid, VAR2_NAME, NC_UINT, 2, dimids, &varid)) ERR;
|
||||
if (nc_put_att_text(ncid, varid, ATT_TEXT_NAME, strlen(speech)+1, speech)) ERR;
|
||||
if (nc_put_att_schar(ncid, varid, ATT_SCHAR_NAME, NC_BYTE, ATT_LEN, schar_out)) ERR;
|
||||
if (nc_put_att_short(ncid, varid, ATT_SHORT_NAME, NC_SHORT, 3, short_out)) ERR;
|
||||
if (nc_put_att_int(ncid, varid, ATT_INT_NAME, NC_INT, 3, int_out)) ERR;
|
||||
if (nc_put_att_float(ncid, varid, ATT_FLOAT_NAME, NC_FLOAT, 3, float_out)) ERR;
|
||||
if (nc_put_att_double(ncid, varid, ATT_DOUBLE_NAME, NC_DOUBLE, 3, double_out)) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
/* Open the file and check attributes. */
|
||||
if (nc_open(FILE_NAME, 0, &ncid)) ERR;
|
||||
for (v=0; v<2; v++)
|
||||
{
|
||||
if (nc_inq_att(ncid, v, ATT_TEXT_NAME, &att_type, &att_len)) ERR;
|
||||
if (att_type != NC_CHAR || att_len != strlen(speech) + 1) ERR;
|
||||
if (!(speech_in = malloc(att_len + 1))) ERR;
|
||||
if (nc_get_att_text(ncid, v, ATT_TEXT_NAME, speech_in)) ERR;
|
||||
if (strcmp(speech, speech_in)) ERR;
|
||||
free(speech_in);
|
||||
if (nc_get_att_schar(ncid, v, ATT_SCHAR_NAME, schar_in)) ERR;
|
||||
for (i = 0; i < ATT_LEN; i++)
|
||||
if (schar_in[i] != schar_out[i]) ERR;
|
||||
if (nc_get_att_short(ncid, v, ATT_SHORT_NAME, short_in)) ERR;
|
||||
for (i = 0; i < ATT_LEN; i++)
|
||||
if (short_in[i] != short_out[i]) ERR;
|
||||
if (nc_get_att_int(ncid, v, ATT_INT_NAME, int_in)) ERR;
|
||||
for (i = 0; i < ATT_LEN; i++)
|
||||
if (int_in[i] != int_out[i]) ERR;
|
||||
if (nc_get_att_float(ncid, v, ATT_FLOAT_NAME, float_in)) ERR;
|
||||
for (i = 0; i < ATT_LEN; i++)
|
||||
if (float_in[i] != float_out[i]) ERR;
|
||||
if (nc_get_att_double(ncid, v, ATT_DOUBLE_NAME, double_in)) ERR;
|
||||
for (i = 0; i < ATT_LEN; i++)
|
||||
if (double_in[i] != double_out[i]) ERR;
|
||||
}
|
||||
if (nc_close(ncid)) ERR;
|
||||
}
|
||||
SUMMARIZE_ERR;
|
||||
printf("*** testing zero-length attributes...");
|
||||
{
|
||||
int ncid;
|
||||
|
||||
/*int int_in[ATT_LEN], int_out[ATT_LEN] = {NC_MIN_INT, 128, NC_MAX_INT};*/
|
||||
|
||||
/* Create a file with a global attribute of each type of zero length. */
|
||||
if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
|
||||
if (nc_put_att_text(ncid, NC_GLOBAL, ATT_TEXT_NAME, 0, NULL)) ERR;
|
||||
if (nc_put_att_schar(ncid, NC_GLOBAL, ATT_SCHAR_NAME, NC_BYTE, 0, NULL)) ERR;
|
||||
/* if (nc_put_att_uchar(ncid, NC_GLOBAL, ATT_UCHAR_NAME, NC_UCHAR, ATT_LEN, uchar_out)) ERR;*/
|
||||
if (nc_put_att_short(ncid, NC_GLOBAL, ATT_SHORT_NAME, NC_SHORT, 0, NULL)) ERR;
|
||||
if (nc_put_att_int(ncid, NC_GLOBAL, ATT_INT_NAME, NC_INT, 0, NULL)) ERR;
|
||||
if (nc_put_att_float(ncid, NC_GLOBAL, ATT_FLOAT_NAME, NC_FLOAT, 0, NULL)) ERR;
|
||||
if (nc_put_att_double(ncid, NC_GLOBAL, ATT_DOUBLE_NAME, NC_DOUBLE, 0, NULL)) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
}
|
||||
|
||||
/* Make sure we can read all these zero-length atts. */
|
||||
{
|
||||
int ncid;
|
||||
signed char schar_in[ATT_LEN];
|
||||
short short_in[ATT_LEN];
|
||||
/*int int_in[ATT_LEN], int_out[ATT_LEN] = {NC_MIN_INT, 128, NC_MAX_INT};*/
|
||||
int int_in[ATT_LEN];
|
||||
float float_in[ATT_LEN];
|
||||
double double_in[ATT_LEN];
|
||||
size_t len;
|
||||
nc_type xtype;
|
||||
|
||||
if (nc_open(FILE_NAME, 0, &ncid)) ERR;
|
||||
if (nc_get_att_text(ncid, NC_GLOBAL, ATT_TEXT_NAME, NULL)) ERR;
|
||||
if (nc_inq_att(ncid, NC_GLOBAL, ATT_TEXT_NAME, &xtype, &len)) ERR;
|
||||
if (len || xtype != NC_CHAR) ERR;
|
||||
if (nc_get_att_schar(ncid, NC_GLOBAL, ATT_SCHAR_NAME, schar_in)) ERR;
|
||||
if (nc_inq_att(ncid, NC_GLOBAL, ATT_SCHAR_NAME, &xtype, &len)) ERR;
|
||||
if (len || xtype != NC_BYTE) ERR;
|
||||
if (nc_get_att_short(ncid, NC_GLOBAL, ATT_SHORT_NAME, short_in)) ERR;
|
||||
if (nc_inq_att(ncid, NC_GLOBAL, ATT_SHORT_NAME, &xtype, &len)) ERR;
|
||||
if (len || xtype != NC_SHORT) ERR;
|
||||
if (nc_get_att_int(ncid, NC_GLOBAL, ATT_INT_NAME, int_in)) ERR;
|
||||
if (nc_inq_att(ncid, NC_GLOBAL, ATT_INT_NAME, &xtype, &len)) ERR;
|
||||
if (len || xtype != NC_INT) ERR;
|
||||
if (nc_get_att_float(ncid, NC_GLOBAL, ATT_FLOAT_NAME, float_in)) ERR;
|
||||
if (nc_inq_att(ncid, NC_GLOBAL, ATT_FLOAT_NAME, &xtype, &len)) ERR;
|
||||
if (len || xtype != NC_FLOAT) ERR;
|
||||
if (nc_get_att_double(ncid, NC_GLOBAL, ATT_DOUBLE_NAME, double_in)) ERR;
|
||||
if (nc_inq_att(ncid, NC_GLOBAL, ATT_DOUBLE_NAME, &xtype, &len)) ERR;
|
||||
if (len || xtype != NC_DOUBLE) ERR;
|
||||
/* Conversions no longer result in range errors, since there's no data. */
|
||||
if (nc_get_att_schar(ncid, NC_GLOBAL, ATT_DOUBLE_NAME, schar_in)) ERR;
|
||||
if (nc_get_att_schar(ncid, NC_GLOBAL, ATT_FLOAT_NAME, schar_in)) ERR;
|
||||
if (nc_get_att_schar(ncid, NC_GLOBAL, ATT_INT_NAME, schar_in)) ERR;
|
||||
if (nc_get_att_schar(ncid, NC_GLOBAL, ATT_SHORT_NAME, schar_in)) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
}
|
||||
|
||||
SUMMARIZE_ERR;
|
||||
printf("*** testing zero-length attributes and redef...(this test skipped for HDF5-1.8.0 beta1");
|
||||
{
|
||||
int ncid;
|
||||
signed char schar_in[ATT_LEN];
|
||||
short short_in[ATT_LEN];
|
||||
int int_in[ATT_LEN];
|
||||
float float_in[ATT_LEN];
|
||||
double double_in[ATT_LEN];
|
||||
|
||||
|
||||
/* Create a file with a global attribute of each type of zero length. */
|
||||
if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
|
||||
if (nc_enddef(ncid)) ERR;
|
||||
if (nc_redef(ncid)) ERR;
|
||||
if (nc_put_att_text(ncid, NC_GLOBAL, ATT_TEXT_NAME, 0, NULL)) ERR;
|
||||
if (nc_put_att_schar(ncid, NC_GLOBAL, ATT_SCHAR_NAME, NC_BYTE, 0, NULL)) ERR;
|
||||
/* if (nc_put_att_uchar(ncid, NC_GLOBAL, ATT_UCHAR_NAME, NC_UCHAR, ATT_LEN, uchar_out)) ERR;*/
|
||||
if (nc_put_att_short(ncid, NC_GLOBAL, ATT_SHORT_NAME, NC_SHORT, 0, NULL)) ERR;
|
||||
if (nc_put_att_int(ncid, NC_GLOBAL, ATT_INT_NAME, NC_INT, 0, NULL)) ERR;
|
||||
if (nc_put_att_float(ncid, NC_GLOBAL, ATT_FLOAT_NAME, NC_FLOAT, 0, NULL)) ERR;
|
||||
if (nc_put_att_double(ncid, NC_GLOBAL, ATT_DOUBLE_NAME, NC_DOUBLE, 0, NULL)) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
/* Make sure we can read all these zero-length atts added during a
|
||||
* redef. */
|
||||
if (nc_open(FILE_NAME, 0, &ncid)) ERR;
|
||||
if (nc_get_att_text(ncid, NC_GLOBAL, ATT_TEXT_NAME, NULL)) ERR;
|
||||
if (nc_get_att_schar(ncid, NC_GLOBAL, ATT_SCHAR_NAME, schar_in)) ERR;
|
||||
if (nc_get_att_short(ncid, NC_GLOBAL, ATT_SHORT_NAME, short_in)) ERR;
|
||||
if (nc_get_att_int(ncid, NC_GLOBAL, ATT_INT_NAME, int_in)) ERR;
|
||||
if (nc_get_att_float(ncid, NC_GLOBAL, ATT_FLOAT_NAME, float_in)) ERR;
|
||||
if (nc_get_att_double(ncid, NC_GLOBAL, ATT_DOUBLE_NAME, double_in)) ERR;
|
||||
/* Conversions no longer result in range errors, since there's no data. */
|
||||
if (nc_get_att_schar(ncid, NC_GLOBAL, ATT_DOUBLE_NAME, schar_in)) ERR;
|
||||
if (nc_get_att_schar(ncid, NC_GLOBAL, ATT_FLOAT_NAME, schar_in)) ERR;
|
||||
if (nc_get_att_schar(ncid, NC_GLOBAL, ATT_INT_NAME, schar_in)) ERR;
|
||||
if (nc_get_att_schar(ncid, NC_GLOBAL, ATT_SHORT_NAME, schar_in)) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
}
|
||||
SUMMARIZE_ERR;
|
||||
|
||||
printf("*** testing attribute deletes and renames...");
|
||||
{
|
||||
int ncid, varid, dimids[2];
|
||||
nc_type att_type;
|
||||
size_t att_len;
|
||||
char *speech_in;
|
||||
char name_in[NC_MAX_NAME + 1];
|
||||
int attid_in, natts_in;
|
||||
int int_out[ATT_LEN] = {-100000, 128, 100000};
|
||||
|
||||
/* Create a file with a global attribute. */
|
||||
if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
|
||||
if (nc_put_att_text(ncid, NC_GLOBAL, ATT_TEXT_NAME, strlen(speech)+1,
|
||||
speech)) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
/* Rename it. */
|
||||
if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR;
|
||||
if (nc_inq_attid(ncid, NC_GLOBAL, ATT_TEXT_NAME, &attid_in)) ERR;
|
||||
if (attid_in != 0) ERR;
|
||||
if (nc_inq_attname(ncid, NC_GLOBAL, attid_in, name_in)) ERR;
|
||||
if (strcmp(name_in, ATT_TEXT_NAME)) ERR;
|
||||
if (nc_rename_att(ncid, NC_GLOBAL, ATT_TEXT_NAME, ATT_TEXT_NAME2)) ERR;
|
||||
if (nc_inq_attname(ncid, NC_GLOBAL, attid_in, name_in)) ERR;
|
||||
if (strcmp(name_in, ATT_TEXT_NAME2)) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR;
|
||||
if (nc_inq_att(ncid, NC_GLOBAL, ATT_TEXT_NAME2, &att_type, &att_len)) ERR;
|
||||
if (att_type != NC_CHAR || att_len != strlen(speech) + 1) ERR;
|
||||
if (!(speech_in = malloc(att_len + 1))) ERR;
|
||||
if (nc_get_att_text(ncid, NC_GLOBAL, ATT_TEXT_NAME2, speech_in)) ERR;
|
||||
if (strcmp(speech, speech_in)) ERR;
|
||||
free(speech_in);
|
||||
if (nc_get_att_text(ncid, NC_GLOBAL, ATT_TEXT_NAME, speech_in) != NC_ENOTATT) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
/* Now delete the att. */
|
||||
if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR;
|
||||
if (nc_del_att(ncid, NC_GLOBAL, ATT_TEXT_NAME2)) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
/* Now create a file with a variable, which has an att. */
|
||||
if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
|
||||
if (nc_put_att_text(ncid, NC_GLOBAL, ATT_TEXT_NAME, strlen(speech)+1, speech)) ERR;
|
||||
if (nc_def_dim(ncid, DIM1_NAME, DIM1_LEN, &dimids[0])) ERR;
|
||||
if (nc_def_dim(ncid, DIM2_NAME, DIM2_LEN, &dimids[1])) ERR;
|
||||
if (nc_def_var(ncid, VAR1_NAME, NC_INT, 2, dimids, &varid)) ERR;
|
||||
if (nc_put_att_int(ncid, varid, ATT_INT_NAME, NC_INT, 3, int_out)) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
/* Reopen the file and delete it. Make sure it's gone. */
|
||||
if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR;
|
||||
if (nc_del_att(ncid, 0, ATT_INT_NAME)) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
/* Reopen the file and readd the attribute. Enddef and redef,
|
||||
* and delete it, then check to make sure it's gone. */
|
||||
if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR;
|
||||
if (nc_put_att_int(ncid, varid, ATT_INT_NAME, NC_INT, 3, int_out)) ERR;
|
||||
if (nc_enddef(ncid)) ERR;
|
||||
if (nc_redef(ncid)) ERR;
|
||||
if (nc_del_att(ncid, 0, ATT_INT_NAME)) ERR;
|
||||
if (nc_inq_varnatts(ncid, 0, &natts_in)) ERR;
|
||||
if (natts_in != 0) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
}
|
||||
|
||||
SUMMARIZE_ERR;
|
||||
printf("*** testing attribute create order...");
|
||||
|
||||
#define ATT0 "Maturin"
|
||||
#define ATT1 "Aubery"
|
||||
{
|
||||
int ncid, varid, dimids[2];
|
||||
int attid_in;
|
||||
const int number = 42;
|
||||
|
||||
/* Create a file with several global attributes. */
|
||||
if (nc_create(FILE_NAME, NC_NETCDF4|NC_CLASSIC_MODEL, &ncid)) ERR;
|
||||
if (nc_put_att_int(ncid, NC_GLOBAL, ATT0, NC_INT, 1, &number)) ERR;
|
||||
if (nc_put_att_int(ncid, NC_GLOBAL, ATT1, NC_INT, 1, &number)) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
/* Open it and check the order. */
|
||||
if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR;
|
||||
if (nc_inq_attid(ncid, NC_GLOBAL, ATT0, &attid_in)) ERR;
|
||||
if (attid_in != 0) ERR;
|
||||
if (nc_inq_attid(ncid, NC_GLOBAL, ATT1, &attid_in)) ERR;
|
||||
if (attid_in != 1) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
/* Now create a file with a variable, which has two atts. */
|
||||
if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
|
||||
if (nc_def_dim(ncid, DIM1_NAME, DIM1_LEN, &dimids[0])) ERR;
|
||||
if (nc_def_dim(ncid, DIM2_NAME, DIM2_LEN, &dimids[1])) ERR;
|
||||
if (nc_def_var(ncid, VAR1_NAME, NC_INT, 2, dimids, &varid)) ERR;
|
||||
if (nc_put_att_int(ncid, varid, ATT0, NC_INT, 1, &number)) ERR;
|
||||
if (nc_put_att_int(ncid, varid, ATT1, NC_INT, 1, &number)) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
/* Reopen the file and check the order of the attributes on the var. */
|
||||
if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR;
|
||||
if (nc_inq_attid(ncid, 0, ATT0, &attid_in)) ERR;
|
||||
if (attid_in != 0) ERR;
|
||||
if (nc_inq_attid(ncid, 0, ATT1, &attid_in)) ERR;
|
||||
if (attid_in != 1) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
}
|
||||
|
||||
SUMMARIZE_ERR;
|
||||
printf("*** testing attribute ordering some more...");
|
||||
|
||||
#define VAR_NAME "i"
|
||||
#define A1_NAME "i"
|
||||
#define A2_NAME "f"
|
||||
#define A3_NAME "d"
|
||||
#define A1_LEN 3
|
||||
#define A2_LEN 4
|
||||
#define A3_LEN 5
|
||||
{
|
||||
int ncid;
|
||||
int varid, natts, nvars;
|
||||
double dvalue[] = {999.99, 999.99, 999.99, 999.99, 999.99};
|
||||
int varids[1];
|
||||
char name_in[NC_MAX_NAME + 1];
|
||||
|
||||
/* Create a file with one var, and attach three atts to it. */
|
||||
if (nc_create(FILE_NAME, NC_NETCDF4|NC_CLASSIC_MODEL, &ncid)) ERR;
|
||||
/* Create a file with an att. */
|
||||
if (nc_create(FILE_NAME, NC_NETCDF4|NC_CLOBBER, &ncid)) ERR;
|
||||
if (nc_def_var(ncid, VAR_NAME, NC_INT, 0, NULL, &varid)) ERR;
|
||||
if (nc_put_att_double(ncid, varid, A1_NAME, NC_INT, A1_LEN, dvalue)) ERR;
|
||||
if (nc_put_att_double(ncid, varid, A2_NAME, NC_INT, A2_LEN, dvalue)) ERR;
|
||||
if (nc_put_att_double(ncid, varid, A3_NAME, NC_INT, A3_LEN, dvalue)) ERR;
|
||||
if (nc_put_att_text(ncid, varid, OLD_NAME1, strlen(CONTENTS1),
|
||||
CONTENTS1)) ERR;
|
||||
|
||||
/* Rename the att. */
|
||||
if (nc_rename_att(ncid, varid, OLD_NAME1, NEW_NAME1)) ERR;
|
||||
|
||||
/* Check the file. */
|
||||
if (nc_inq_attid(ncid, varid, NEW_NAME1, &attid)) ERR;
|
||||
if (attid != 0) ERR;
|
||||
if (nc_get_att_text(ncid, varid, NEW_NAME1, data_in)) ERR;
|
||||
if (strncmp(CONTENTS1, data_in, strlen(CONTENTS1))) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
/* Reopen the file and check. */
|
||||
if (nc_open(FILE_NAME, 0, &ncid)) ERR;
|
||||
if (nc_inq_varids(ncid, &nvars, varids)) ERR;
|
||||
if (nvars != 1 || varids[0] != 0) ERR;
|
||||
if (nc_inq_varnatts(ncid, 0, &natts)) ERR;
|
||||
if (natts != 3) ERR;
|
||||
if (nc_inq_attname(ncid, 0, 0, name_in)) ERR;
|
||||
if (strcmp(name_in, A1_NAME)) ERR;
|
||||
if (nc_inq_attname(ncid, 0, 1, name_in)) ERR;
|
||||
if (strcmp(name_in, A2_NAME)) ERR;
|
||||
if (nc_inq_attname(ncid, 0, 2, name_in)) ERR;
|
||||
if (strcmp(name_in, A3_NAME)) ERR;
|
||||
|
||||
/* Close up shop. */
|
||||
if (nc_close(ncid)) ERR;
|
||||
}
|
||||
|
||||
SUMMARIZE_ERR;
|
||||
printf("*** testing attribute ordering even more...");
|
||||
|
||||
/* Test the ordering of atts for each cmode. */
|
||||
if (tst_att_ordering(NC_CLOBBER)) ERR;
|
||||
if (tst_att_ordering(NC_CLOBBER|NC_64BIT_OFFSET)) ERR;
|
||||
if (tst_att_ordering(NC_CLOBBER|NC_NETCDF4)) ERR;
|
||||
if (tst_att_ordering(NC_CLOBBER|NC_NETCDF4|NC_CLASSIC_MODEL)) ERR;
|
||||
|
||||
SUMMARIZE_ERR;
|
||||
printf("*** testing attributes and enddef/redef...");
|
||||
|
||||
#define ATT_1 "a"
|
||||
#define ATT_2 "b"
|
||||
#define ATT_3 "c"
|
||||
{
|
||||
int ncid, att = 1;
|
||||
|
||||
if (nc_create(FILE_NAME, NC_NETCDF4|NC_CLASSIC_MODEL|NC_CLOBBER, &ncid)) ERR;
|
||||
if (nc_enddef(ncid)) ERR;
|
||||
if (nc_redef(ncid)) ERR;
|
||||
if (nc_put_att(ncid, NC_GLOBAL, ATT_1, NC_INT, 1, &att)) ERR;
|
||||
if (nc_put_att(ncid, NC_GLOBAL, ATT_2, NC_INT, 1, &att)) ERR;
|
||||
if (nc_put_att(ncid, NC_GLOBAL, ATT_3, NC_INT, 1, &att)) ERR;
|
||||
/* Reopen the file and check again. */
|
||||
if (nc_open(FILE_NAME, NC_NOWRITE, &ncid)) ERR;
|
||||
|
||||
if (nc_inq_attid(ncid, varid, NEW_NAME1, &attid)) ERR;
|
||||
if (attid != 0) ERR;
|
||||
if (nc_get_att_text(ncid, varid, NEW_NAME1, data_in)) ERR;
|
||||
if (strncmp(CONTENTS1, data_in, strlen(CONTENTS1))) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
if (nc_open(FILE_NAME, 0, &ncid)) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
}
|
||||
|
||||
SUMMARIZE_ERR;
|
||||
printf("*** testing copy of simple global atts...");
|
||||
{
|
||||
int ncid, ncid2;
|
||||
nc_type att_type;
|
||||
size_t att_len;
|
||||
int i;
|
||||
|
||||
char *speech_in;
|
||||
signed char schar_in[ATT_LEN], schar_out[ATT_LEN] = {NC_MIN_BYTE, 1, NC_MAX_BYTE};
|
||||
unsigned char uchar_in[ATT_LEN], uchar_out[ATT_LEN] = {0, 128, NC_MAX_CHAR};
|
||||
short short_in[ATT_LEN], short_out[ATT_LEN] = {NC_MIN_SHORT, -128, NC_MAX_SHORT};
|
||||
int int_in[ATT_LEN], int_out[ATT_LEN] = {-100000, 128, 100000};
|
||||
float float_in[ATT_LEN], float_out[ATT_LEN] = {.5, 0.25, 0.125};
|
||||
double double_in[ATT_LEN], double_out[ATT_LEN] = {0.25, .5, 0.125};
|
||||
unsigned short ushort_in[ATT_LEN], ushort_out[ATT_LEN] = {0, 128, NC_MAX_USHORT};
|
||||
unsigned int uint_in[ATT_LEN], uint_out[ATT_LEN] = {0, 128, NC_MAX_UINT};
|
||||
unsigned long long uint64_in[ATT_LEN], uint64_out[ATT_LEN] = {0, 128, 18446744073709551612ULL};
|
||||
long long int64_in[ATT_LEN], int64_out[ATT_LEN] = {NC_MIN_INT64, 128, NC_MAX_INT64};
|
||||
|
||||
/* Create a file with a global attribute of each type. */
|
||||
if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
|
||||
if (nc_put_att_text(ncid, NC_GLOBAL, ATT_TEXT_NAME, strlen(speech)+1, speech)) ERR;
|
||||
if (nc_put_att_schar(ncid, NC_GLOBAL, ATT_SCHAR_NAME, NC_BYTE, ATT_LEN, schar_out)) ERR;
|
||||
if (nc_put_att_uchar(ncid, NC_GLOBAL, ATT_UCHAR_NAME, NC_UBYTE, ATT_LEN, uchar_out)) ERR;
|
||||
if (nc_put_att_short(ncid, NC_GLOBAL, ATT_SHORT_NAME, NC_SHORT, ATT_LEN, short_out)) ERR;
|
||||
if (nc_put_att_int(ncid, NC_GLOBAL, ATT_INT_NAME, NC_INT, ATT_LEN, int_out)) ERR;
|
||||
if (nc_put_att_float(ncid, NC_GLOBAL, ATT_FLOAT_NAME, NC_FLOAT, ATT_LEN, float_out)) ERR;
|
||||
if (nc_put_att_double(ncid, NC_GLOBAL, ATT_DOUBLE_NAME, NC_DOUBLE, ATT_LEN, double_out)) ERR;
|
||||
if (nc_put_att_ushort(ncid, NC_GLOBAL, ATT_USHORT_NAME, NC_USHORT, ATT_LEN, ushort_out)) ERR;
|
||||
if (nc_put_att_uint(ncid, NC_GLOBAL, ATT_UINT_NAME, NC_UINT, ATT_LEN, uint_out)) ERR;
|
||||
if (nc_put_att_longlong(ncid, NC_GLOBAL, ATT_INT64_NAME, NC_INT64, ATT_LEN, int64_out)) ERR;
|
||||
if (nc_put_att_ulonglong(ncid, NC_GLOBAL, ATT_UINT64_NAME, NC_UINT64, ATT_LEN, uint64_out)) ERR;
|
||||
|
||||
/* Create another file and copy all the attributes. */
|
||||
if (nc_create(FILE_NAME2, NC_NETCDF4, &ncid2)) ERR;
|
||||
if (nc_copy_att(ncid, NC_GLOBAL, ATT_TEXT_NAME, ncid2, NC_GLOBAL)) ERR;
|
||||
if (nc_copy_att(ncid, NC_GLOBAL, ATT_SCHAR_NAME, ncid2, NC_GLOBAL)) ERR;
|
||||
if (nc_copy_att(ncid, NC_GLOBAL, ATT_UCHAR_NAME, ncid2, NC_GLOBAL)) ERR;
|
||||
if (nc_copy_att(ncid, NC_GLOBAL, ATT_SHORT_NAME, ncid2, NC_GLOBAL)) ERR;
|
||||
if (nc_copy_att(ncid, NC_GLOBAL, ATT_INT_NAME, ncid2, NC_GLOBAL)) ERR;
|
||||
if (nc_copy_att(ncid, NC_GLOBAL, ATT_FLOAT_NAME, ncid2, NC_GLOBAL)) ERR;
|
||||
if (nc_copy_att(ncid, NC_GLOBAL, ATT_DOUBLE_NAME, ncid2, NC_GLOBAL)) ERR;
|
||||
if (nc_copy_att(ncid, NC_GLOBAL, ATT_USHORT_NAME, ncid2, NC_GLOBAL)) ERR;
|
||||
if (nc_copy_att(ncid, NC_GLOBAL, ATT_UINT_NAME, ncid2, NC_GLOBAL)) ERR;
|
||||
if (nc_copy_att(ncid, NC_GLOBAL, ATT_INT64_NAME, ncid2, NC_GLOBAL)) ERR;
|
||||
if (nc_copy_att(ncid, NC_GLOBAL, ATT_UINT64_NAME, ncid2, NC_GLOBAL)) ERR;
|
||||
|
||||
/* Close both files. */
|
||||
if (nc_close(ncid)) ERR;
|
||||
if (nc_close(ncid2)) ERR;
|
||||
|
||||
/* Open the file and check attributes. */
|
||||
if (nc_open(FILE_NAME2, 0, &ncid)) ERR;
|
||||
/* Check text. */
|
||||
if (nc_inq_att(ncid, NC_GLOBAL, ATT_TEXT_NAME, &att_type, &att_len)) ERR;
|
||||
if (att_type != NC_CHAR || att_len != strlen(speech) + 1) ERR;
|
||||
if (!(speech_in = malloc(att_len + 1))) ERR;
|
||||
if (nc_get_att_text(ncid, NC_GLOBAL, ATT_TEXT_NAME, speech_in)) ERR;
|
||||
if (strcmp(speech, speech_in)) ERR;
|
||||
free(speech_in);
|
||||
/* Check numeric values. */
|
||||
if (nc_get_att_schar(ncid, NC_GLOBAL, ATT_SCHAR_NAME, schar_in)) ERR;
|
||||
for (i = 0; i < ATT_LEN; i++)
|
||||
if (schar_in[i] != schar_out[i]) ERR;
|
||||
if (nc_get_att_uchar(ncid, NC_GLOBAL, ATT_UCHAR_NAME, uchar_in)) ERR;
|
||||
for (i = 0; i < ATT_LEN; i++)
|
||||
if (uchar_in[i] != uchar_out[i]) ERR;
|
||||
if (nc_get_att_short(ncid, NC_GLOBAL, ATT_SHORT_NAME, short_in)) ERR;
|
||||
for (i = 0; i < ATT_LEN; i++)
|
||||
if (short_in[i] != short_out[i]) ERR;
|
||||
if (nc_get_att_int(ncid, NC_GLOBAL, ATT_INT_NAME, int_in)) ERR;
|
||||
for (i = 0; i < ATT_LEN; i++)
|
||||
if (int_in[i] != int_out[i]) ERR;
|
||||
if (nc_get_att_float(ncid, NC_GLOBAL, ATT_FLOAT_NAME, float_in)) ERR;
|
||||
for (i = 0; i < ATT_LEN; i++)
|
||||
if (float_in[i] != float_out[i]) ERR;
|
||||
if (nc_get_att_double(ncid, NC_GLOBAL, ATT_DOUBLE_NAME, double_in)) ERR;
|
||||
for (i = 0; i < ATT_LEN; i++)
|
||||
if (double_in[i] != double_out[i]) ERR;
|
||||
if (nc_get_att_ushort(ncid, NC_GLOBAL, ATT_USHORT_NAME, ushort_in)) ERR;
|
||||
for (i = 0; i < ATT_LEN; i++)
|
||||
if (ushort_in[i] != ushort_out[i]) ERR;
|
||||
if (nc_get_att_uint(ncid, NC_GLOBAL, ATT_UINT_NAME, uint_in)) ERR;
|
||||
for (i = 0; i < ATT_LEN; i++)
|
||||
if (uint_in[i] != uint_out[i]) ERR;
|
||||
if (nc_get_att_longlong(ncid, NC_GLOBAL, ATT_INT64_NAME, int64_in)) ERR;
|
||||
for (i = 0; i < ATT_LEN; i++)
|
||||
if (int64_in[i] != int64_out[i]) ERR;
|
||||
if (nc_get_att_ulonglong(ncid, NC_GLOBAL, ATT_UINT64_NAME, uint64_in)) ERR;
|
||||
for (i = 0; i < ATT_LEN; i++)
|
||||
if (uint64_in[i] != uint64_out[i]) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
free(data_in);
|
||||
}
|
||||
SUMMARIZE_ERR;
|
||||
FINAL_RESULTS;
|
||||
}
|
||||
|
||||
|
||||
|
791
nc_test4/tst_atts1.c
Normal file
791
nc_test4/tst_atts1.c
Normal file
@ -0,0 +1,791 @@
|
||||
/* This is part of the netCDF package. Copyright 2005-2007 University
|
||||
Corporation for Atmospheric Research/Unidata. See COPYRIGHT file
|
||||
for conditions of use.
|
||||
|
||||
Test attributes.
|
||||
|
||||
$Id$
|
||||
*/
|
||||
|
||||
#include <nc_tests.h>
|
||||
#include "netcdf.h"
|
||||
#include <signal.h>
|
||||
|
||||
#define FILE_NAME "tst_atts.nc"
|
||||
#define FILE_NAME2 "tst_atts_2.nc"
|
||||
#define VAR1_NAME "Horace_Rumpole"
|
||||
#define VAR2_NAME "Claude_Erskine-Brown"
|
||||
#define VAR3_NAME "Phillida_Erskine-Brown_Q.C."
|
||||
#define DIM1_NAME "Old_Bailey_case_number"
|
||||
#define DIM1_LEN 10
|
||||
#define DIM2_NAME "occupancy_in_chambers"
|
||||
#define DIM2_LEN 15
|
||||
#define ATT_INT_NAME "Old_Bailey_Room_Numbers"
|
||||
#define ATT_DOUBLE_NAME "Equity_Court_Canteen_Charges"
|
||||
#define ATT_SHORT_NAME "Ecclesiastical_Court_Appearences"
|
||||
#define ATT_TEXT_NAME "Speech_to_Jury"
|
||||
#define ATT_TEXT_NAME2 "Speech_to_She_Who_Must_be_Obeyed"
|
||||
#define ATT_UCHAR_NAME "Number_of_current_briefs"
|
||||
#define ATT_SCHAR_NAME "Slate_totals_at_Pomeroys_Wine_Bar"
|
||||
#define ATT_USHORT_NAME "brief_no"
|
||||
#define ATT_UINT_NAME "Orders_from_SWMBO"
|
||||
#define ATT_INT64_NAME "judges_golf_score"
|
||||
#define ATT_UINT64_NAME "Number_of_drinks_in_career_to_date"
|
||||
|
||||
/*
|
||||
#define ATT_USHORT_NAME "Chamber_Gas_Electric_and_Telephone_Bill_Share"
|
||||
*/
|
||||
#define ATT_FLOAT_NAME "Average_Nanoseconds_for_Lose_Win_or_Appeal"
|
||||
#define ATT_LEN 3
|
||||
|
||||
char speech[] = "Once more unto the breach, dear friends, once more;\n\
|
||||
Or close the wall up with our English dead.\n\
|
||||
In peace there's nothing so becomes a man\n\
|
||||
As modest stillness and humility:\n\
|
||||
But when the blast of war blows in our ears,\n\
|
||||
Then imitate the action of the tiger;\n\
|
||||
Stiffen the sinews, summon up the blood,\n\
|
||||
Disguise fair nature with hard-favour'd rage;\n\
|
||||
Then lend the eye a terrible aspect;\n\
|
||||
Let pry through the portage of the head\n\
|
||||
Like the brass cannon; let the brow o'erwhelm it\n\
|
||||
As fearfully as doth a galled rock\n\
|
||||
O'erhang and jutty his confounded base,\n\
|
||||
Swill'd with the wild and wasteful ocean.\n\
|
||||
Now set the teeth and stretch the nostril wide,\n\
|
||||
Hold hard the breath and bend up every spirit\n\
|
||||
To his full height. On, on, you noblest English.\n\
|
||||
Whose blood is fet from fathers of war-proof!\n\
|
||||
Fathers that, like so many Alexanders,\n\
|
||||
Have in these parts from morn till even fought\n\
|
||||
And sheathed their swords for lack of argument:\n\
|
||||
Dishonour not your mothers; now attest\n\
|
||||
That those whom you call'd fathers did beget you.\n\
|
||||
Be copy now to men of grosser blood,\n\
|
||||
And teach them how to war. And you, good yeoman,\n\
|
||||
Whose limbs were made in England, show us here\n\
|
||||
The mettle of your pasture; let us swear\n\
|
||||
That you are worth your breeding; which I doubt not;\n\
|
||||
For there is none of you so mean and base,\n\
|
||||
That hath not noble lustre in your eyes.\n\
|
||||
I see you stand like greyhounds in the slips,\n\
|
||||
Straining upon the start. The game's afoot:\n\
|
||||
Follow your spirit, and upon this charge\n\
|
||||
Cry 'God for Harry, England, and Saint George!'";
|
||||
|
||||
/* Test the ordering of atts for a cmode. */
|
||||
#define NUM_ATTS 8
|
||||
#define ATT_MAX_NAME 25
|
||||
int
|
||||
tst_att_ordering(int cmode)
|
||||
{
|
||||
int ncid;
|
||||
char name[NUM_ATTS][ATT_MAX_NAME + 1] = {"Gc", "Gb", "Gs", "Gi", "Gf",
|
||||
"Gd", "Gatt-name-dashes", "Gatt.name.dots"};
|
||||
int len[NUM_ATTS] = {0, 2, 3, 3, 3, 3, 1, 1};
|
||||
signed char b[2] = {-128, 127};
|
||||
short s[3] = {-32768, 0, 32767};
|
||||
int i[3] = {42, 0, -42};
|
||||
float f[3] = {42.0, -42.0, 42.0};
|
||||
double d[3] = {420.0, -420.0, 420.0};
|
||||
int att_name_dashes = -1, att_name_dots = -2;
|
||||
char name_in[NC_MAX_NAME];
|
||||
int j;
|
||||
|
||||
/* Create a file with some global atts. */
|
||||
if (nc_create(FILE_NAME, cmode, &ncid)) ERR;
|
||||
if (nc_put_att_text(ncid, NC_GLOBAL, name[0], len[0], NULL)) ERR;
|
||||
if (nc_put_att_schar(ncid, NC_GLOBAL, name[1], NC_BYTE, len[1], b)) ERR;
|
||||
if (nc_put_att_short(ncid, NC_GLOBAL, name[2], NC_SHORT, len[2], s)) ERR;
|
||||
if (nc_put_att_int(ncid, NC_GLOBAL, name[3], NC_INT, len[3], i)) ERR;
|
||||
if (nc_put_att_float(ncid, NC_GLOBAL, name[4], NC_FLOAT, len[4], f)) ERR;
|
||||
if (nc_put_att_double(ncid, NC_GLOBAL, name[5], NC_DOUBLE, len[5], d)) ERR;
|
||||
if (nc_put_att_int(ncid, NC_GLOBAL, name[6], NC_INT, len[6], &att_name_dashes)) ERR;
|
||||
if (nc_put_att_int(ncid, NC_GLOBAL, name[7], NC_INT, len[7], &att_name_dots)) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
/* Reopen the file and check the order. */
|
||||
if (nc_open(FILE_NAME, 0, &ncid)) ERR;
|
||||
for (j = 0; j < NUM_ATTS; j++)
|
||||
{
|
||||
if (nc_inq_attname(ncid, NC_GLOBAL, j, name_in)) ERR;
|
||||
if (strcmp(name_in, name[j])) ERR;
|
||||
}
|
||||
|
||||
/* Close up shop. */
|
||||
if (nc_close(ncid)) ERR;
|
||||
return err;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
(void) signal(SIGFPE, SIG_IGN);
|
||||
|
||||
printf("\n*** Testing netcdf-4 attribute functions.\n");
|
||||
printf("*** testing really simple global atts...");
|
||||
#define NUM_SIMPLE_ATTS 9
|
||||
{
|
||||
int ncid;
|
||||
char name[NUM_SIMPLE_ATTS][ATT_MAX_NAME + 1] = {"Gc", "Gb", "Gs", "Gi", "Gf",
|
||||
"Gd", "G7", "G8", "G9"};
|
||||
char name_in[NC_MAX_NAME];
|
||||
int j;
|
||||
|
||||
/* Create a file with some global atts. */
|
||||
if (nc_create(FILE_NAME, NC_NETCDF4|NC_CLOBBER, &ncid)) ERR;
|
||||
for (j = 0; j < NUM_SIMPLE_ATTS; j++)
|
||||
if (nc_put_att_int(ncid, NC_GLOBAL, name[j], NC_INT, 0, NULL)) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
/* Reopen the file and check the order. */
|
||||
if (nc_open(FILE_NAME, 0, &ncid)) ERR;
|
||||
for (j = 0; j < NUM_SIMPLE_ATTS; j++)
|
||||
{
|
||||
if (nc_inq_attname(ncid, NC_GLOBAL, j, name_in)) ERR;
|
||||
if (strcmp(name_in, name[j])) ERR;
|
||||
}
|
||||
|
||||
/* Close up shop. */
|
||||
if (nc_close(ncid)) ERR;
|
||||
}
|
||||
SUMMARIZE_ERR;
|
||||
printf("*** testing simple global atts...");
|
||||
{
|
||||
int ncid;
|
||||
nc_type att_type;
|
||||
size_t att_len;
|
||||
int i;
|
||||
|
||||
char *speech_in;
|
||||
signed char schar_in[ATT_LEN], schar_out[ATT_LEN] = {NC_MIN_BYTE, 1, NC_MAX_BYTE};
|
||||
unsigned char uchar_in[ATT_LEN], uchar_out[ATT_LEN] = {0, 128, NC_MAX_CHAR};
|
||||
short short_in[ATT_LEN], short_out[ATT_LEN] = {NC_MIN_SHORT, -128, NC_MAX_SHORT};
|
||||
/*int int_in[ATT_LEN], int_out[ATT_LEN] = {NC_MIN_INT, 128, NC_MAX_INT};*/
|
||||
int int_in[ATT_LEN], int_out[ATT_LEN] = {-100000, 128, 100000};
|
||||
float float_in[ATT_LEN], float_out[ATT_LEN] = {.5, 0.25, 0.125};
|
||||
double double_in[ATT_LEN], double_out[ATT_LEN] = {0.25, .5, 0.125};
|
||||
unsigned short ushort_in[ATT_LEN], ushort_out[ATT_LEN] = {0, 128, NC_MAX_USHORT};
|
||||
unsigned int uint_in[ATT_LEN], uint_out[ATT_LEN] = {0, 128, NC_MAX_UINT};
|
||||
unsigned long long uint64_in[ATT_LEN], uint64_out[ATT_LEN] = {0, 128, 18446744073709551612ULL};
|
||||
long long int64_in[ATT_LEN], int64_out[ATT_LEN] = {NC_MIN_INT64, 128, NC_MAX_INT64};
|
||||
|
||||
|
||||
/* This won't work, because classic files can't create these types. */
|
||||
if (nc_create(FILE_NAME, NC_NETCDF4|NC_CLASSIC_MODEL, &ncid)) ERR;
|
||||
if (nc_put_att_ushort(ncid, NC_GLOBAL, ATT_USHORT_NAME, NC_USHORT, ATT_LEN,
|
||||
ushort_out) != NC_ESTRICTNC3) ERR;
|
||||
if (nc_put_att_uint(ncid, NC_GLOBAL, ATT_UINT_NAME, NC_UINT, ATT_LEN,
|
||||
uint_out) != NC_ESTRICTNC3) ERR;
|
||||
if (nc_put_att_longlong(ncid, NC_GLOBAL, ATT_INT64_NAME, NC_INT64, ATT_LEN,
|
||||
int64_out) != NC_ESTRICTNC3) ERR;
|
||||
if (nc_put_att_ulonglong(ncid, NC_GLOBAL, ATT_UINT64_NAME, NC_UINT64, ATT_LEN,
|
||||
uint64_out) != NC_ESTRICTNC3) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
/* Create a file with a global attribute of each type. */
|
||||
if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
|
||||
if (nc_put_att_text(ncid, NC_GLOBAL, ATT_TEXT_NAME, strlen(speech)+1, speech)) ERR;
|
||||
if (nc_put_att_schar(ncid, NC_GLOBAL, ATT_SCHAR_NAME, NC_BYTE, ATT_LEN, schar_out)) ERR;
|
||||
if (nc_put_att_uchar(ncid, NC_GLOBAL, ATT_UCHAR_NAME, NC_UBYTE, ATT_LEN, uchar_out)) ERR;
|
||||
if (nc_put_att_short(ncid, NC_GLOBAL, ATT_SHORT_NAME, NC_SHORT, ATT_LEN, short_out)) ERR;
|
||||
if (nc_put_att_int(ncid, NC_GLOBAL, ATT_INT_NAME, NC_INT, ATT_LEN, int_out)) ERR;
|
||||
if (nc_put_att_float(ncid, NC_GLOBAL, ATT_FLOAT_NAME, NC_FLOAT, ATT_LEN, float_out)) ERR;
|
||||
if (nc_put_att_double(ncid, NC_GLOBAL, ATT_DOUBLE_NAME, NC_DOUBLE, ATT_LEN, double_out)) ERR;
|
||||
if (nc_put_att_ushort(ncid, NC_GLOBAL, ATT_USHORT_NAME, NC_USHORT, ATT_LEN, ushort_out)) ERR;
|
||||
if (nc_put_att_uint(ncid, NC_GLOBAL, ATT_UINT_NAME, NC_UINT, ATT_LEN, uint_out)) ERR;
|
||||
if (nc_put_att_longlong(ncid, NC_GLOBAL, ATT_INT64_NAME, NC_INT64, ATT_LEN, int64_out)) ERR;
|
||||
if (nc_put_att_ulonglong(ncid, NC_GLOBAL, ATT_UINT64_NAME, NC_UINT64, ATT_LEN, uint64_out)) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
/* Open the file and check attributes. */
|
||||
if (nc_open(FILE_NAME, 0, &ncid)) ERR;
|
||||
/* Check text. */
|
||||
if (nc_inq_att(ncid, NC_GLOBAL, ATT_TEXT_NAME, &att_type, &att_len))
|
||||
ERR;
|
||||
if (att_type != NC_CHAR || att_len != strlen(speech) + 1) ERR;
|
||||
if (!(speech_in = malloc(att_len + 1))) ERR;
|
||||
if (nc_get_att_text(ncid, NC_GLOBAL, ATT_TEXT_NAME, speech_in)) ERR;
|
||||
if (strcmp(speech, speech_in)) ERR;
|
||||
free(speech_in);
|
||||
/* Check numeric values. */
|
||||
if (nc_get_att_schar(ncid, NC_GLOBAL, ATT_SCHAR_NAME, schar_in)) ERR;
|
||||
for (i = 0; i < ATT_LEN; i++)
|
||||
if (schar_in[i] != schar_out[i]) ERR;
|
||||
if (nc_get_att_uchar(ncid, NC_GLOBAL, ATT_UCHAR_NAME, uchar_in)) ERR;
|
||||
for (i = 0; i < ATT_LEN; i++)
|
||||
if (uchar_in[i] != uchar_out[i]) ERR;
|
||||
if (nc_get_att_short(ncid, NC_GLOBAL, ATT_SHORT_NAME, short_in)) ERR;
|
||||
for (i = 0; i < ATT_LEN; i++)
|
||||
if (short_in[i] != short_out[i]) ERR;
|
||||
if (nc_get_att_int(ncid, NC_GLOBAL, ATT_INT_NAME, int_in)) ERR;
|
||||
for (i = 0; i < ATT_LEN; i++)
|
||||
if (int_in[i] != int_out[i]) ERR;
|
||||
if (nc_get_att_float(ncid, NC_GLOBAL, ATT_FLOAT_NAME, float_in)) ERR;
|
||||
for (i = 0; i < ATT_LEN; i++)
|
||||
if (float_in[i] != float_out[i]) ERR;
|
||||
if (nc_get_att_double(ncid, NC_GLOBAL, ATT_DOUBLE_NAME, double_in)) ERR;
|
||||
for (i = 0; i < ATT_LEN; i++)
|
||||
if (double_in[i] != double_out[i]) ERR;
|
||||
if (nc_get_att_ushort(ncid, NC_GLOBAL, ATT_USHORT_NAME, ushort_in)) ERR;
|
||||
for (i = 0; i < ATT_LEN; i++)
|
||||
if (ushort_in[i] != ushort_out[i]) ERR;
|
||||
if (nc_get_att_uint(ncid, NC_GLOBAL, ATT_UINT_NAME, uint_in)) ERR;
|
||||
for (i = 0; i < ATT_LEN; i++)
|
||||
if (uint_in[i] != uint_out[i]) ERR;
|
||||
if (nc_get_att_longlong(ncid, NC_GLOBAL, ATT_INT64_NAME, int64_in)) ERR;
|
||||
for (i = 0; i < ATT_LEN; i++)
|
||||
if (int64_in[i] != int64_out[i]) ERR;
|
||||
if (nc_get_att_ulonglong(ncid, NC_GLOBAL, ATT_UINT64_NAME, uint64_in)) ERR;
|
||||
for (i = 0; i < ATT_LEN; i++)
|
||||
if (uint64_in[i] != uint64_out[i]) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
}
|
||||
SUMMARIZE_ERR;
|
||||
printf("*** testing attribute data type conversions...");
|
||||
|
||||
{
|
||||
int ncid;
|
||||
int i;
|
||||
|
||||
signed char schar_in[ATT_LEN], schar_out[ATT_LEN] = {NC_MIN_BYTE, 1, NC_MAX_BYTE};
|
||||
short short_in[ATT_LEN], short_out[ATT_LEN] = {NC_MIN_SHORT, -128, NC_MAX_SHORT};
|
||||
/*int int_in[ATT_LEN], int_out[ATT_LEN] = {NC_MIN_INT, 128, NC_MAX_INT};*/
|
||||
int int_in[ATT_LEN], int_out[ATT_LEN] = {-100000, 128, 100000};
|
||||
float float_in[ATT_LEN], float_out[ATT_LEN] = {.5, 0.25, 0.125};
|
||||
double double_in[ATT_LEN], double_out[ATT_LEN] = {0.25, .5, 0.125};
|
||||
unsigned short ushort_in[ATT_LEN];
|
||||
unsigned int uint_in[ATT_LEN];
|
||||
unsigned long long uint64_in[ATT_LEN];
|
||||
long long int64_in[ATT_LEN];
|
||||
|
||||
/* Reopen the file and try different type conversions. */
|
||||
if (nc_open(FILE_NAME, 0, &ncid)) ERR;
|
||||
|
||||
/* No text conversions are allowed, and people who try them shold
|
||||
* be locked up, away from decent folk! */
|
||||
if (nc_get_att_short(ncid, NC_GLOBAL, ATT_TEXT_NAME, short_in) != NC_ECHAR) ERR;
|
||||
if (nc_get_att_int(ncid, NC_GLOBAL, ATT_TEXT_NAME, int_in) != NC_ECHAR) ERR;
|
||||
if (nc_get_att_float(ncid, NC_GLOBAL, ATT_TEXT_NAME, float_in) != NC_ECHAR) ERR;
|
||||
if (nc_get_att_double(ncid, NC_GLOBAL, ATT_TEXT_NAME, double_in) != NC_ECHAR) ERR;
|
||||
/* if (nc_get_att_ubyte(ncid, NC_GLOBAL, ATT_TEXT_NAME, uchar_in) != NC_ECHAR) ERR;*/
|
||||
if (nc_get_att_ushort(ncid, NC_GLOBAL, ATT_TEXT_NAME, ushort_in) != NC_ECHAR) ERR;
|
||||
if (nc_get_att_uint(ncid, NC_GLOBAL, ATT_TEXT_NAME, uint_in) != NC_ECHAR) ERR;
|
||||
if (nc_get_att_longlong(ncid, NC_GLOBAL, ATT_TEXT_NAME, int64_in) != NC_ECHAR) ERR;
|
||||
if (nc_get_att_ulonglong(ncid, NC_GLOBAL, ATT_TEXT_NAME, uint64_in) != NC_ECHAR) ERR;
|
||||
|
||||
/* Read all atts (except text) as double. */
|
||||
if (nc_get_att_double(ncid, NC_GLOBAL, ATT_SCHAR_NAME, double_in)) ERR;
|
||||
for (i = 0; i < ATT_LEN; i++)
|
||||
if (double_in[i] != schar_out[i]) ERR;
|
||||
if (nc_get_att_double(ncid, NC_GLOBAL, ATT_SHORT_NAME, double_in)) ERR;
|
||||
for (i = 0; i < ATT_LEN; i++)
|
||||
if (double_in[i] != short_out[i]) ERR;
|
||||
if (nc_get_att_double(ncid, NC_GLOBAL, ATT_INT_NAME, double_in)) ERR;
|
||||
for (i = 0; i < ATT_LEN; i++)
|
||||
if (double_in[i] != int_out[i]) ERR;
|
||||
if (nc_get_att_double(ncid, NC_GLOBAL, ATT_FLOAT_NAME, double_in)) ERR;
|
||||
for (i = 0; i < ATT_LEN; i++)
|
||||
if (double_in[i] != float_out[i]) ERR;
|
||||
/* Read all atts (except text) as float. */
|
||||
if (nc_get_att_float(ncid, NC_GLOBAL, ATT_SCHAR_NAME, float_in)) ERR;
|
||||
for (i = 0; i < ATT_LEN; i++)
|
||||
if (float_in[i] != schar_out[i]) ERR;
|
||||
if (nc_get_att_float(ncid, NC_GLOBAL, ATT_SHORT_NAME, float_in)) ERR;
|
||||
for (i = 0; i < ATT_LEN; i++)
|
||||
if (float_in[i] != short_out[i]) ERR;
|
||||
if (nc_get_att_float(ncid, NC_GLOBAL, ATT_INT_NAME, float_in)) ERR;
|
||||
for (i = 0; i < ATT_LEN; i++)
|
||||
if (float_in[i] != (float)int_out[i]) ERR;
|
||||
if (nc_get_att_float(ncid, NC_GLOBAL, ATT_DOUBLE_NAME, float_in)) ERR;
|
||||
for (i = 0; i < ATT_LEN; i++)
|
||||
if (float_in[i] != (float)double_out[i]) ERR;
|
||||
/* Read all atts (except text) as int. */
|
||||
if (nc_get_att_int(ncid, NC_GLOBAL, ATT_SCHAR_NAME, int_in)) ERR;
|
||||
for (i = 0; i < ATT_LEN; i++)
|
||||
if (int_in[i] != schar_out[i]) ERR;
|
||||
if (nc_get_att_int(ncid, NC_GLOBAL, ATT_SHORT_NAME, int_in)) ERR;
|
||||
for (i = 0; i < ATT_LEN; i++)
|
||||
if (int_in[i] != short_out[i]) ERR;
|
||||
if (nc_get_att_int(ncid, NC_GLOBAL, ATT_FLOAT_NAME, int_in)) ERR;
|
||||
for (i = 0; i < ATT_LEN; i++)
|
||||
if (int_in[i] != (int)float_out[i]) ERR;
|
||||
if (nc_get_att_int(ncid, NC_GLOBAL, ATT_DOUBLE_NAME, int_in)) ERR;
|
||||
for (i = 0; i < ATT_LEN; i++)
|
||||
if (int_in[i] != (int)double_out[i]) ERR;
|
||||
/* Read all atts (except text) as short. */
|
||||
if (nc_get_att_short(ncid, NC_GLOBAL, ATT_SCHAR_NAME, short_in)) ERR;
|
||||
for (i = 0; i < ATT_LEN; i++)
|
||||
if (short_in[i] != schar_out[i]) ERR;
|
||||
if (nc_get_att_short(ncid, NC_GLOBAL, ATT_INT_NAME, short_in) != NC_ERANGE) ERR;
|
||||
for (i = 0; i < ATT_LEN; i++)
|
||||
if (short_in[i] != (short)int_out[i]) ERR;
|
||||
if (nc_get_att_short(ncid, NC_GLOBAL, ATT_FLOAT_NAME, short_in)) ERR;
|
||||
for (i = 0; i < ATT_LEN; i++)
|
||||
if (short_in[i] != (short)float_out[i]) ERR;
|
||||
if (nc_get_att_short(ncid, NC_GLOBAL, ATT_DOUBLE_NAME, short_in)) ERR;
|
||||
for (i = 0; i < ATT_LEN; i++)
|
||||
if (short_in[i] != (short)double_out[i]) ERR;
|
||||
/* Read all atts (except text) as schar. Some range errors will
|
||||
* result converting to schar. */
|
||||
if (nc_get_att_schar(ncid, NC_GLOBAL, ATT_SHORT_NAME, schar_in) != NC_ERANGE) ERR;
|
||||
for (i = 0; i < ATT_LEN; i++)
|
||||
if (schar_in[i] != (signed char)short_out[i]) ERR;
|
||||
if (nc_get_att_schar(ncid, NC_GLOBAL, ATT_INT_NAME, schar_in) != NC_ERANGE) ERR;
|
||||
for (i = 0; i < ATT_LEN; i++)
|
||||
if (schar_in[i] != (signed char)int_out[i]) ERR;
|
||||
if (nc_get_att_schar(ncid, NC_GLOBAL, ATT_FLOAT_NAME, schar_in)) ERR;
|
||||
for (i = 0; i < ATT_LEN; i++)
|
||||
if (schar_in[i] != (signed char)float_out[i]) ERR;
|
||||
if (nc_get_att_schar(ncid, NC_GLOBAL, ATT_DOUBLE_NAME, schar_in)) ERR;
|
||||
for (i = 0; i < ATT_LEN; i++)
|
||||
if (schar_in[i] != (signed char)double_out[i]) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
}
|
||||
SUMMARIZE_ERR;
|
||||
printf("*** testing simple variable atts...");
|
||||
{
|
||||
int ncid, varid, dimids[2];
|
||||
nc_type att_type;
|
||||
size_t att_len;
|
||||
int i, v;
|
||||
|
||||
char *speech_in;
|
||||
signed char schar_in[ATT_LEN], schar_out[ATT_LEN] = {NC_MIN_BYTE, 1, NC_MAX_BYTE};
|
||||
short short_in[ATT_LEN], short_out[ATT_LEN] = {NC_MIN_SHORT, -128, NC_MAX_SHORT};
|
||||
/*int int_in[ATT_LEN], int_out[ATT_LEN] = {NC_MIN_INT, 128, NC_MAX_INT};*/
|
||||
int int_in[ATT_LEN], int_out[ATT_LEN] = {-100000, 128, 100000};
|
||||
float float_in[ATT_LEN], float_out[ATT_LEN] = {.5, 0.25, 0.125};
|
||||
double double_in[ATT_LEN], double_out[ATT_LEN] = {0.25, .5, 0.125};
|
||||
|
||||
/* Create a file with two vars, attaching to each an attribute of
|
||||
* each type. */
|
||||
if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
|
||||
if (nc_def_dim(ncid, DIM1_NAME, DIM1_LEN, &dimids[0])) ERR;
|
||||
if (nc_def_dim(ncid, DIM2_NAME, DIM2_LEN, &dimids[1])) ERR;
|
||||
if (nc_def_var(ncid, VAR1_NAME, NC_INT, 2, dimids, &varid)) ERR;
|
||||
if (nc_put_att_text(ncid, varid, ATT_TEXT_NAME, strlen(speech)+1, speech)) ERR;
|
||||
if (nc_put_att_schar(ncid, varid, ATT_SCHAR_NAME, NC_BYTE, ATT_LEN, schar_out)) ERR;
|
||||
if (nc_put_att_short(ncid, varid, ATT_SHORT_NAME, NC_SHORT, 3, short_out)) ERR;
|
||||
if (nc_put_att_int(ncid, varid, ATT_INT_NAME, NC_INT, 3, int_out)) ERR;
|
||||
if (nc_put_att_float(ncid, varid, ATT_FLOAT_NAME, NC_FLOAT, 3, float_out)) ERR;
|
||||
if (nc_put_att_double(ncid, varid, ATT_DOUBLE_NAME, NC_DOUBLE, 3, double_out)) ERR;
|
||||
if (nc_def_var(ncid, VAR2_NAME, NC_UINT, 2, dimids, &varid)) ERR;
|
||||
if (nc_put_att_text(ncid, varid, ATT_TEXT_NAME, strlen(speech)+1, speech)) ERR;
|
||||
if (nc_put_att_schar(ncid, varid, ATT_SCHAR_NAME, NC_BYTE, ATT_LEN, schar_out)) ERR;
|
||||
if (nc_put_att_short(ncid, varid, ATT_SHORT_NAME, NC_SHORT, 3, short_out)) ERR;
|
||||
if (nc_put_att_int(ncid, varid, ATT_INT_NAME, NC_INT, 3, int_out)) ERR;
|
||||
if (nc_put_att_float(ncid, varid, ATT_FLOAT_NAME, NC_FLOAT, 3, float_out)) ERR;
|
||||
if (nc_put_att_double(ncid, varid, ATT_DOUBLE_NAME, NC_DOUBLE, 3, double_out)) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
/* Open the file and check attributes. */
|
||||
if (nc_open(FILE_NAME, 0, &ncid)) ERR;
|
||||
for (v=0; v<2; v++)
|
||||
{
|
||||
if (nc_inq_att(ncid, v, ATT_TEXT_NAME, &att_type, &att_len)) ERR;
|
||||
if (att_type != NC_CHAR || att_len != strlen(speech) + 1) ERR;
|
||||
if (!(speech_in = malloc(att_len + 1))) ERR;
|
||||
if (nc_get_att_text(ncid, v, ATT_TEXT_NAME, speech_in)) ERR;
|
||||
if (strcmp(speech, speech_in)) ERR;
|
||||
free(speech_in);
|
||||
if (nc_get_att_schar(ncid, v, ATT_SCHAR_NAME, schar_in)) ERR;
|
||||
for (i = 0; i < ATT_LEN; i++)
|
||||
if (schar_in[i] != schar_out[i]) ERR;
|
||||
if (nc_get_att_short(ncid, v, ATT_SHORT_NAME, short_in)) ERR;
|
||||
for (i = 0; i < ATT_LEN; i++)
|
||||
if (short_in[i] != short_out[i]) ERR;
|
||||
if (nc_get_att_int(ncid, v, ATT_INT_NAME, int_in)) ERR;
|
||||
for (i = 0; i < ATT_LEN; i++)
|
||||
if (int_in[i] != int_out[i]) ERR;
|
||||
if (nc_get_att_float(ncid, v, ATT_FLOAT_NAME, float_in)) ERR;
|
||||
for (i = 0; i < ATT_LEN; i++)
|
||||
if (float_in[i] != float_out[i]) ERR;
|
||||
if (nc_get_att_double(ncid, v, ATT_DOUBLE_NAME, double_in)) ERR;
|
||||
for (i = 0; i < ATT_LEN; i++)
|
||||
if (double_in[i] != double_out[i]) ERR;
|
||||
}
|
||||
if (nc_close(ncid)) ERR;
|
||||
}
|
||||
SUMMARIZE_ERR;
|
||||
printf("*** testing zero-length attributes...");
|
||||
{
|
||||
int ncid;
|
||||
|
||||
/*int int_in[ATT_LEN], int_out[ATT_LEN] = {NC_MIN_INT, 128, NC_MAX_INT};*/
|
||||
|
||||
/* Create a file with a global attribute of each type of zero length. */
|
||||
if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
|
||||
if (nc_put_att_text(ncid, NC_GLOBAL, ATT_TEXT_NAME, 0, NULL)) ERR;
|
||||
if (nc_put_att_schar(ncid, NC_GLOBAL, ATT_SCHAR_NAME, NC_BYTE, 0, NULL)) ERR;
|
||||
/* if (nc_put_att_uchar(ncid, NC_GLOBAL, ATT_UCHAR_NAME, NC_UCHAR, ATT_LEN, uchar_out)) ERR;*/
|
||||
if (nc_put_att_short(ncid, NC_GLOBAL, ATT_SHORT_NAME, NC_SHORT, 0, NULL)) ERR;
|
||||
if (nc_put_att_int(ncid, NC_GLOBAL, ATT_INT_NAME, NC_INT, 0, NULL)) ERR;
|
||||
if (nc_put_att_float(ncid, NC_GLOBAL, ATT_FLOAT_NAME, NC_FLOAT, 0, NULL)) ERR;
|
||||
if (nc_put_att_double(ncid, NC_GLOBAL, ATT_DOUBLE_NAME, NC_DOUBLE, 0, NULL)) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
}
|
||||
|
||||
/* Make sure we can read all these zero-length atts. */
|
||||
{
|
||||
int ncid;
|
||||
signed char schar_in[ATT_LEN];
|
||||
short short_in[ATT_LEN];
|
||||
/*int int_in[ATT_LEN], int_out[ATT_LEN] = {NC_MIN_INT, 128, NC_MAX_INT};*/
|
||||
int int_in[ATT_LEN];
|
||||
float float_in[ATT_LEN];
|
||||
double double_in[ATT_LEN];
|
||||
size_t len;
|
||||
nc_type xtype;
|
||||
|
||||
if (nc_open(FILE_NAME, 0, &ncid)) ERR;
|
||||
if (nc_get_att_text(ncid, NC_GLOBAL, ATT_TEXT_NAME, NULL)) ERR;
|
||||
if (nc_inq_att(ncid, NC_GLOBAL, ATT_TEXT_NAME, &xtype, &len)) ERR;
|
||||
if (len || xtype != NC_CHAR) ERR;
|
||||
if (nc_get_att_schar(ncid, NC_GLOBAL, ATT_SCHAR_NAME, schar_in)) ERR;
|
||||
if (nc_inq_att(ncid, NC_GLOBAL, ATT_SCHAR_NAME, &xtype, &len)) ERR;
|
||||
if (len || xtype != NC_BYTE) ERR;
|
||||
if (nc_get_att_short(ncid, NC_GLOBAL, ATT_SHORT_NAME, short_in)) ERR;
|
||||
if (nc_inq_att(ncid, NC_GLOBAL, ATT_SHORT_NAME, &xtype, &len)) ERR;
|
||||
if (len || xtype != NC_SHORT) ERR;
|
||||
if (nc_get_att_int(ncid, NC_GLOBAL, ATT_INT_NAME, int_in)) ERR;
|
||||
if (nc_inq_att(ncid, NC_GLOBAL, ATT_INT_NAME, &xtype, &len)) ERR;
|
||||
if (len || xtype != NC_INT) ERR;
|
||||
if (nc_get_att_float(ncid, NC_GLOBAL, ATT_FLOAT_NAME, float_in)) ERR;
|
||||
if (nc_inq_att(ncid, NC_GLOBAL, ATT_FLOAT_NAME, &xtype, &len)) ERR;
|
||||
if (len || xtype != NC_FLOAT) ERR;
|
||||
if (nc_get_att_double(ncid, NC_GLOBAL, ATT_DOUBLE_NAME, double_in)) ERR;
|
||||
if (nc_inq_att(ncid, NC_GLOBAL, ATT_DOUBLE_NAME, &xtype, &len)) ERR;
|
||||
if (len || xtype != NC_DOUBLE) ERR;
|
||||
/* Conversions no longer result in range errors, since there's no data. */
|
||||
if (nc_get_att_schar(ncid, NC_GLOBAL, ATT_DOUBLE_NAME, schar_in)) ERR;
|
||||
if (nc_get_att_schar(ncid, NC_GLOBAL, ATT_FLOAT_NAME, schar_in)) ERR;
|
||||
if (nc_get_att_schar(ncid, NC_GLOBAL, ATT_INT_NAME, schar_in)) ERR;
|
||||
if (nc_get_att_schar(ncid, NC_GLOBAL, ATT_SHORT_NAME, schar_in)) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
}
|
||||
|
||||
SUMMARIZE_ERR;
|
||||
printf("*** testing zero-length attributes and redef...(this test skipped for HDF5-1.8.0 beta1");
|
||||
{
|
||||
int ncid;
|
||||
signed char schar_in[ATT_LEN];
|
||||
short short_in[ATT_LEN];
|
||||
int int_in[ATT_LEN];
|
||||
float float_in[ATT_LEN];
|
||||
double double_in[ATT_LEN];
|
||||
|
||||
|
||||
/* Create a file with a global attribute of each type of zero length. */
|
||||
if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
|
||||
if (nc_enddef(ncid)) ERR;
|
||||
if (nc_redef(ncid)) ERR;
|
||||
if (nc_put_att_text(ncid, NC_GLOBAL, ATT_TEXT_NAME, 0, NULL)) ERR;
|
||||
if (nc_put_att_schar(ncid, NC_GLOBAL, ATT_SCHAR_NAME, NC_BYTE, 0, NULL)) ERR;
|
||||
/* if (nc_put_att_uchar(ncid, NC_GLOBAL, ATT_UCHAR_NAME, NC_UCHAR, ATT_LEN, uchar_out)) ERR;*/
|
||||
if (nc_put_att_short(ncid, NC_GLOBAL, ATT_SHORT_NAME, NC_SHORT, 0, NULL)) ERR;
|
||||
if (nc_put_att_int(ncid, NC_GLOBAL, ATT_INT_NAME, NC_INT, 0, NULL)) ERR;
|
||||
if (nc_put_att_float(ncid, NC_GLOBAL, ATT_FLOAT_NAME, NC_FLOAT, 0, NULL)) ERR;
|
||||
if (nc_put_att_double(ncid, NC_GLOBAL, ATT_DOUBLE_NAME, NC_DOUBLE, 0, NULL)) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
/* Make sure we can read all these zero-length atts added during a
|
||||
* redef. */
|
||||
if (nc_open(FILE_NAME, 0, &ncid)) ERR;
|
||||
if (nc_get_att_text(ncid, NC_GLOBAL, ATT_TEXT_NAME, NULL)) ERR;
|
||||
if (nc_get_att_schar(ncid, NC_GLOBAL, ATT_SCHAR_NAME, schar_in)) ERR;
|
||||
if (nc_get_att_short(ncid, NC_GLOBAL, ATT_SHORT_NAME, short_in)) ERR;
|
||||
if (nc_get_att_int(ncid, NC_GLOBAL, ATT_INT_NAME, int_in)) ERR;
|
||||
if (nc_get_att_float(ncid, NC_GLOBAL, ATT_FLOAT_NAME, float_in)) ERR;
|
||||
if (nc_get_att_double(ncid, NC_GLOBAL, ATT_DOUBLE_NAME, double_in)) ERR;
|
||||
/* Conversions no longer result in range errors, since there's no data. */
|
||||
if (nc_get_att_schar(ncid, NC_GLOBAL, ATT_DOUBLE_NAME, schar_in)) ERR;
|
||||
if (nc_get_att_schar(ncid, NC_GLOBAL, ATT_FLOAT_NAME, schar_in)) ERR;
|
||||
if (nc_get_att_schar(ncid, NC_GLOBAL, ATT_INT_NAME, schar_in)) ERR;
|
||||
if (nc_get_att_schar(ncid, NC_GLOBAL, ATT_SHORT_NAME, schar_in)) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
}
|
||||
SUMMARIZE_ERR;
|
||||
|
||||
printf("*** testing attribute deletes and renames...");
|
||||
{
|
||||
int ncid, varid, dimids[2];
|
||||
nc_type att_type;
|
||||
size_t att_len;
|
||||
char *speech_in;
|
||||
char name_in[NC_MAX_NAME + 1];
|
||||
int attid_in, natts_in;
|
||||
int int_out[ATT_LEN] = {-100000, 128, 100000};
|
||||
|
||||
/* Create a file with a global attribute. */
|
||||
if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
|
||||
if (nc_put_att_text(ncid, NC_GLOBAL, ATT_TEXT_NAME, strlen(speech)+1,
|
||||
speech)) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
/* Rename it. */
|
||||
if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR;
|
||||
if (nc_inq_attid(ncid, NC_GLOBAL, ATT_TEXT_NAME, &attid_in)) ERR;
|
||||
if (attid_in != 0) ERR;
|
||||
if (nc_inq_attname(ncid, NC_GLOBAL, attid_in, name_in)) ERR;
|
||||
if (strcmp(name_in, ATT_TEXT_NAME)) ERR;
|
||||
if (nc_rename_att(ncid, NC_GLOBAL, ATT_TEXT_NAME, ATT_TEXT_NAME2)) ERR;
|
||||
if (nc_inq_attname(ncid, NC_GLOBAL, attid_in, name_in)) ERR;
|
||||
if (strcmp(name_in, ATT_TEXT_NAME2)) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR;
|
||||
if (nc_inq_att(ncid, NC_GLOBAL, ATT_TEXT_NAME2, &att_type, &att_len)) ERR;
|
||||
if (att_type != NC_CHAR || att_len != strlen(speech) + 1) ERR;
|
||||
if (!(speech_in = malloc(att_len + 1))) ERR;
|
||||
if (nc_get_att_text(ncid, NC_GLOBAL, ATT_TEXT_NAME2, speech_in)) ERR;
|
||||
if (strcmp(speech, speech_in)) ERR;
|
||||
free(speech_in);
|
||||
if (nc_get_att_text(ncid, NC_GLOBAL, ATT_TEXT_NAME, speech_in) != NC_ENOTATT) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
/* Now delete the att. */
|
||||
if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR;
|
||||
if (nc_del_att(ncid, NC_GLOBAL, ATT_TEXT_NAME2)) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
/* Now create a file with a variable, which has an att. */
|
||||
if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
|
||||
if (nc_put_att_text(ncid, NC_GLOBAL, ATT_TEXT_NAME, strlen(speech)+1, speech)) ERR;
|
||||
if (nc_def_dim(ncid, DIM1_NAME, DIM1_LEN, &dimids[0])) ERR;
|
||||
if (nc_def_dim(ncid, DIM2_NAME, DIM2_LEN, &dimids[1])) ERR;
|
||||
if (nc_def_var(ncid, VAR1_NAME, NC_INT, 2, dimids, &varid)) ERR;
|
||||
if (nc_put_att_int(ncid, varid, ATT_INT_NAME, NC_INT, 3, int_out)) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
/* Reopen the file and delete it. Make sure it's gone. */
|
||||
if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR;
|
||||
if (nc_del_att(ncid, 0, ATT_INT_NAME)) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
/* Reopen the file and readd the attribute. Enddef and redef,
|
||||
* and delete it, then check to make sure it's gone. */
|
||||
if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR;
|
||||
if (nc_put_att_int(ncid, varid, ATT_INT_NAME, NC_INT, 3, int_out)) ERR;
|
||||
if (nc_enddef(ncid)) ERR;
|
||||
if (nc_redef(ncid)) ERR;
|
||||
if (nc_del_att(ncid, 0, ATT_INT_NAME)) ERR;
|
||||
if (nc_inq_varnatts(ncid, 0, &natts_in)) ERR;
|
||||
if (natts_in != 0) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
}
|
||||
|
||||
SUMMARIZE_ERR;
|
||||
printf("*** testing attribute create order...");
|
||||
|
||||
#define ATT0 "Maturin"
|
||||
#define ATT1 "Aubery"
|
||||
{
|
||||
int ncid, varid, dimids[2];
|
||||
int attid_in;
|
||||
const int number = 42;
|
||||
|
||||
/* Create a file with several global attributes. */
|
||||
if (nc_create(FILE_NAME, NC_NETCDF4|NC_CLASSIC_MODEL, &ncid)) ERR;
|
||||
if (nc_put_att_int(ncid, NC_GLOBAL, ATT0, NC_INT, 1, &number)) ERR;
|
||||
if (nc_put_att_int(ncid, NC_GLOBAL, ATT1, NC_INT, 1, &number)) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
/* Open it and check the order. */
|
||||
if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR;
|
||||
if (nc_inq_attid(ncid, NC_GLOBAL, ATT0, &attid_in)) ERR;
|
||||
if (attid_in != 0) ERR;
|
||||
if (nc_inq_attid(ncid, NC_GLOBAL, ATT1, &attid_in)) ERR;
|
||||
if (attid_in != 1) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
/* Now create a file with a variable, which has two atts. */
|
||||
if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
|
||||
if (nc_def_dim(ncid, DIM1_NAME, DIM1_LEN, &dimids[0])) ERR;
|
||||
if (nc_def_dim(ncid, DIM2_NAME, DIM2_LEN, &dimids[1])) ERR;
|
||||
if (nc_def_var(ncid, VAR1_NAME, NC_INT, 2, dimids, &varid)) ERR;
|
||||
if (nc_put_att_int(ncid, varid, ATT0, NC_INT, 1, &number)) ERR;
|
||||
if (nc_put_att_int(ncid, varid, ATT1, NC_INT, 1, &number)) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
/* Reopen the file and check the order of the attributes on the var. */
|
||||
if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR;
|
||||
if (nc_inq_attid(ncid, 0, ATT0, &attid_in)) ERR;
|
||||
if (attid_in != 0) ERR;
|
||||
if (nc_inq_attid(ncid, 0, ATT1, &attid_in)) ERR;
|
||||
if (attid_in != 1) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
}
|
||||
|
||||
SUMMARIZE_ERR;
|
||||
printf("*** testing attribute ordering some more...");
|
||||
|
||||
#define VAR_NAME "i"
|
||||
#define A1_NAME "i"
|
||||
#define A2_NAME "f"
|
||||
#define A3_NAME "d"
|
||||
#define A1_LEN 3
|
||||
#define A2_LEN 4
|
||||
#define A3_LEN 5
|
||||
{
|
||||
int ncid;
|
||||
int varid, natts, nvars;
|
||||
double dvalue[] = {999.99, 999.99, 999.99, 999.99, 999.99};
|
||||
int varids[1];
|
||||
char name_in[NC_MAX_NAME + 1];
|
||||
|
||||
/* Create a file with one var, and attach three atts to it. */
|
||||
if (nc_create(FILE_NAME, NC_NETCDF4|NC_CLASSIC_MODEL, &ncid)) ERR;
|
||||
if (nc_def_var(ncid, VAR_NAME, NC_INT, 0, NULL, &varid)) ERR;
|
||||
if (nc_put_att_double(ncid, varid, A1_NAME, NC_INT, A1_LEN, dvalue)) ERR;
|
||||
if (nc_put_att_double(ncid, varid, A2_NAME, NC_INT, A2_LEN, dvalue)) ERR;
|
||||
if (nc_put_att_double(ncid, varid, A3_NAME, NC_INT, A3_LEN, dvalue)) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
/* Reopen the file and check. */
|
||||
if (nc_open(FILE_NAME, 0, &ncid)) ERR;
|
||||
if (nc_inq_varids(ncid, &nvars, varids)) ERR;
|
||||
if (nvars != 1 || varids[0] != 0) ERR;
|
||||
if (nc_inq_varnatts(ncid, 0, &natts)) ERR;
|
||||
if (natts != 3) ERR;
|
||||
if (nc_inq_attname(ncid, 0, 0, name_in)) ERR;
|
||||
if (strcmp(name_in, A1_NAME)) ERR;
|
||||
if (nc_inq_attname(ncid, 0, 1, name_in)) ERR;
|
||||
if (strcmp(name_in, A2_NAME)) ERR;
|
||||
if (nc_inq_attname(ncid, 0, 2, name_in)) ERR;
|
||||
if (strcmp(name_in, A3_NAME)) ERR;
|
||||
|
||||
/* Close up shop. */
|
||||
if (nc_close(ncid)) ERR;
|
||||
}
|
||||
|
||||
SUMMARIZE_ERR;
|
||||
printf("*** testing attribute ordering even more...");
|
||||
|
||||
/* Test the ordering of atts for each cmode. */
|
||||
if (tst_att_ordering(NC_CLOBBER)) ERR;
|
||||
if (tst_att_ordering(NC_CLOBBER|NC_64BIT_OFFSET)) ERR;
|
||||
if (tst_att_ordering(NC_CLOBBER|NC_NETCDF4)) ERR;
|
||||
if (tst_att_ordering(NC_CLOBBER|NC_NETCDF4|NC_CLASSIC_MODEL)) ERR;
|
||||
|
||||
SUMMARIZE_ERR;
|
||||
printf("*** testing attributes and enddef/redef...");
|
||||
|
||||
#define ATT_1 "a"
|
||||
#define ATT_2 "b"
|
||||
#define ATT_3 "c"
|
||||
{
|
||||
int ncid, att = 1;
|
||||
|
||||
if (nc_create(FILE_NAME, NC_NETCDF4|NC_CLASSIC_MODEL|NC_CLOBBER, &ncid)) ERR;
|
||||
if (nc_enddef(ncid)) ERR;
|
||||
if (nc_redef(ncid)) ERR;
|
||||
if (nc_put_att(ncid, NC_GLOBAL, ATT_1, NC_INT, 1, &att)) ERR;
|
||||
if (nc_put_att(ncid, NC_GLOBAL, ATT_2, NC_INT, 1, &att)) ERR;
|
||||
if (nc_put_att(ncid, NC_GLOBAL, ATT_3, NC_INT, 1, &att)) ERR;
|
||||
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
if (nc_open(FILE_NAME, 0, &ncid)) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
}
|
||||
|
||||
SUMMARIZE_ERR;
|
||||
printf("*** testing copy of simple global atts...");
|
||||
{
|
||||
int ncid, ncid2;
|
||||
nc_type att_type;
|
||||
size_t att_len;
|
||||
int i;
|
||||
|
||||
char *speech_in;
|
||||
signed char schar_in[ATT_LEN], schar_out[ATT_LEN] = {NC_MIN_BYTE, 1, NC_MAX_BYTE};
|
||||
unsigned char uchar_in[ATT_LEN], uchar_out[ATT_LEN] = {0, 128, NC_MAX_CHAR};
|
||||
short short_in[ATT_LEN], short_out[ATT_LEN] = {NC_MIN_SHORT, -128, NC_MAX_SHORT};
|
||||
int int_in[ATT_LEN], int_out[ATT_LEN] = {-100000, 128, 100000};
|
||||
float float_in[ATT_LEN], float_out[ATT_LEN] = {.5, 0.25, 0.125};
|
||||
double double_in[ATT_LEN], double_out[ATT_LEN] = {0.25, .5, 0.125};
|
||||
unsigned short ushort_in[ATT_LEN], ushort_out[ATT_LEN] = {0, 128, NC_MAX_USHORT};
|
||||
unsigned int uint_in[ATT_LEN], uint_out[ATT_LEN] = {0, 128, NC_MAX_UINT};
|
||||
unsigned long long uint64_in[ATT_LEN], uint64_out[ATT_LEN] = {0, 128, 18446744073709551612ULL};
|
||||
long long int64_in[ATT_LEN], int64_out[ATT_LEN] = {NC_MIN_INT64, 128, NC_MAX_INT64};
|
||||
|
||||
/* Create a file with a global attribute of each type. */
|
||||
if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
|
||||
if (nc_put_att_text(ncid, NC_GLOBAL, ATT_TEXT_NAME, strlen(speech)+1, speech)) ERR;
|
||||
if (nc_put_att_schar(ncid, NC_GLOBAL, ATT_SCHAR_NAME, NC_BYTE, ATT_LEN, schar_out)) ERR;
|
||||
if (nc_put_att_uchar(ncid, NC_GLOBAL, ATT_UCHAR_NAME, NC_UBYTE, ATT_LEN, uchar_out)) ERR;
|
||||
if (nc_put_att_short(ncid, NC_GLOBAL, ATT_SHORT_NAME, NC_SHORT, ATT_LEN, short_out)) ERR;
|
||||
if (nc_put_att_int(ncid, NC_GLOBAL, ATT_INT_NAME, NC_INT, ATT_LEN, int_out)) ERR;
|
||||
if (nc_put_att_float(ncid, NC_GLOBAL, ATT_FLOAT_NAME, NC_FLOAT, ATT_LEN, float_out)) ERR;
|
||||
if (nc_put_att_double(ncid, NC_GLOBAL, ATT_DOUBLE_NAME, NC_DOUBLE, ATT_LEN, double_out)) ERR;
|
||||
if (nc_put_att_ushort(ncid, NC_GLOBAL, ATT_USHORT_NAME, NC_USHORT, ATT_LEN, ushort_out)) ERR;
|
||||
if (nc_put_att_uint(ncid, NC_GLOBAL, ATT_UINT_NAME, NC_UINT, ATT_LEN, uint_out)) ERR;
|
||||
if (nc_put_att_longlong(ncid, NC_GLOBAL, ATT_INT64_NAME, NC_INT64, ATT_LEN, int64_out)) ERR;
|
||||
if (nc_put_att_ulonglong(ncid, NC_GLOBAL, ATT_UINT64_NAME, NC_UINT64, ATT_LEN, uint64_out)) ERR;
|
||||
|
||||
/* Create another file and copy all the attributes. */
|
||||
if (nc_create(FILE_NAME2, NC_NETCDF4, &ncid2)) ERR;
|
||||
if (nc_copy_att(ncid, NC_GLOBAL, ATT_TEXT_NAME, ncid2, NC_GLOBAL)) ERR;
|
||||
if (nc_copy_att(ncid, NC_GLOBAL, ATT_SCHAR_NAME, ncid2, NC_GLOBAL)) ERR;
|
||||
if (nc_copy_att(ncid, NC_GLOBAL, ATT_UCHAR_NAME, ncid2, NC_GLOBAL)) ERR;
|
||||
if (nc_copy_att(ncid, NC_GLOBAL, ATT_SHORT_NAME, ncid2, NC_GLOBAL)) ERR;
|
||||
if (nc_copy_att(ncid, NC_GLOBAL, ATT_INT_NAME, ncid2, NC_GLOBAL)) ERR;
|
||||
if (nc_copy_att(ncid, NC_GLOBAL, ATT_FLOAT_NAME, ncid2, NC_GLOBAL)) ERR;
|
||||
if (nc_copy_att(ncid, NC_GLOBAL, ATT_DOUBLE_NAME, ncid2, NC_GLOBAL)) ERR;
|
||||
if (nc_copy_att(ncid, NC_GLOBAL, ATT_USHORT_NAME, ncid2, NC_GLOBAL)) ERR;
|
||||
if (nc_copy_att(ncid, NC_GLOBAL, ATT_UINT_NAME, ncid2, NC_GLOBAL)) ERR;
|
||||
if (nc_copy_att(ncid, NC_GLOBAL, ATT_INT64_NAME, ncid2, NC_GLOBAL)) ERR;
|
||||
if (nc_copy_att(ncid, NC_GLOBAL, ATT_UINT64_NAME, ncid2, NC_GLOBAL)) ERR;
|
||||
|
||||
/* Close both files. */
|
||||
if (nc_close(ncid)) ERR;
|
||||
if (nc_close(ncid2)) ERR;
|
||||
|
||||
/* Open the file and check attributes. */
|
||||
if (nc_open(FILE_NAME2, 0, &ncid)) ERR;
|
||||
/* Check text. */
|
||||
if (nc_inq_att(ncid, NC_GLOBAL, ATT_TEXT_NAME, &att_type, &att_len)) ERR;
|
||||
if (att_type != NC_CHAR || att_len != strlen(speech) + 1) ERR;
|
||||
if (!(speech_in = malloc(att_len + 1))) ERR;
|
||||
if (nc_get_att_text(ncid, NC_GLOBAL, ATT_TEXT_NAME, speech_in)) ERR;
|
||||
if (strcmp(speech, speech_in)) ERR;
|
||||
free(speech_in);
|
||||
/* Check numeric values. */
|
||||
if (nc_get_att_schar(ncid, NC_GLOBAL, ATT_SCHAR_NAME, schar_in)) ERR;
|
||||
for (i = 0; i < ATT_LEN; i++)
|
||||
if (schar_in[i] != schar_out[i]) ERR;
|
||||
if (nc_get_att_uchar(ncid, NC_GLOBAL, ATT_UCHAR_NAME, uchar_in)) ERR;
|
||||
for (i = 0; i < ATT_LEN; i++)
|
||||
if (uchar_in[i] != uchar_out[i]) ERR;
|
||||
if (nc_get_att_short(ncid, NC_GLOBAL, ATT_SHORT_NAME, short_in)) ERR;
|
||||
for (i = 0; i < ATT_LEN; i++)
|
||||
if (short_in[i] != short_out[i]) ERR;
|
||||
if (nc_get_att_int(ncid, NC_GLOBAL, ATT_INT_NAME, int_in)) ERR;
|
||||
for (i = 0; i < ATT_LEN; i++)
|
||||
if (int_in[i] != int_out[i]) ERR;
|
||||
if (nc_get_att_float(ncid, NC_GLOBAL, ATT_FLOAT_NAME, float_in)) ERR;
|
||||
for (i = 0; i < ATT_LEN; i++)
|
||||
if (float_in[i] != float_out[i]) ERR;
|
||||
if (nc_get_att_double(ncid, NC_GLOBAL, ATT_DOUBLE_NAME, double_in)) ERR;
|
||||
for (i = 0; i < ATT_LEN; i++)
|
||||
if (double_in[i] != double_out[i]) ERR;
|
||||
if (nc_get_att_ushort(ncid, NC_GLOBAL, ATT_USHORT_NAME, ushort_in)) ERR;
|
||||
for (i = 0; i < ATT_LEN; i++)
|
||||
if (ushort_in[i] != ushort_out[i]) ERR;
|
||||
if (nc_get_att_uint(ncid, NC_GLOBAL, ATT_UINT_NAME, uint_in)) ERR;
|
||||
for (i = 0; i < ATT_LEN; i++)
|
||||
if (uint_in[i] != uint_out[i]) ERR;
|
||||
if (nc_get_att_longlong(ncid, NC_GLOBAL, ATT_INT64_NAME, int64_in)) ERR;
|
||||
for (i = 0; i < ATT_LEN; i++)
|
||||
if (int64_in[i] != int64_out[i]) ERR;
|
||||
if (nc_get_att_ulonglong(ncid, NC_GLOBAL, ATT_UINT64_NAME, uint64_in)) ERR;
|
||||
for (i = 0; i < ATT_LEN; i++)
|
||||
if (uint64_in[i] != uint64_out[i]) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
}
|
||||
SUMMARIZE_ERR;
|
||||
FINAL_RESULTS;
|
||||
}
|
||||
|
||||
|
@ -9,7 +9,6 @@
|
||||
|
||||
#include <nc_tests.h>
|
||||
#include "netcdf.h"
|
||||
#include "nc4internal.h"
|
||||
|
||||
#define FILE_NAME1 "tst_atts2.nc"
|
||||
#define FILE_NAME2 "tst_atts2_2.nc"
|
||||
|
@ -1,604 +1,257 @@
|
||||
#include <config.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/times.h>
|
||||
#include <sys/stat.h>
|
||||
#include <assert.h>
|
||||
#include <sys/time.h>
|
||||
#include <unistd.h> /* for sysconf */
|
||||
#include <sys/resource.h>
|
||||
#include <nc_tests.h> /* The ERR macro is here... */
|
||||
#include <netcdf.h>
|
||||
/* This is part of the netCDF package.
|
||||
Copyright 2005 University Corporation for Atmospheric Research/Unidata
|
||||
See COPYRIGHT file for conditions of use.
|
||||
|
||||
#define FILENAME "tst_chunks.nc"
|
||||
Test netcdf-4 variables.
|
||||
$Id: tst_chunks.c,v 1.3 2010/01/21 16:00:18 ed Exp $
|
||||
*/
|
||||
|
||||
/*
|
||||
* The following timing macros can be used by including the necessary
|
||||
* declarations with
|
||||
*
|
||||
* TIMING_DECLS(seconds)
|
||||
*
|
||||
* and surrounding sections of code to be timed with the "statements"
|
||||
*
|
||||
* TIMING_START
|
||||
* [code to be timed goes here]
|
||||
* TIMING_END(seconds)
|
||||
*
|
||||
* The macros assume the user has stored a description of what is
|
||||
* being timed in a 100-char string time_mess, and has included
|
||||
* <sys/times.h> and <sys/resource.h>. The timing message printed by
|
||||
* TIMING_END is not terminated by a new-line, to permit appending
|
||||
* additional text to that line, so user must at least printf("\n")
|
||||
* after that.
|
||||
*/
|
||||
#include <nc_tests.h>
|
||||
|
||||
#define TIMING_DECLS(seconds) \
|
||||
long TMreps; /* counts repetitions of timed code */ \
|
||||
long TMrepeats; /* repetitions needed to exceed 0.1 second */ \
|
||||
long emic ; /* elapsed time in microseconds */ \
|
||||
struct rusage ru; \
|
||||
long inb, oub; \
|
||||
char time_mess[100]; \
|
||||
float seconds;
|
||||
|
||||
#define TIMING_START \
|
||||
TMrepeats = 1; \
|
||||
do { \
|
||||
if(getrusage(RUSAGE_SELF, &ru)) { \
|
||||
printf("getrusage failed, returned %d\n", errno);} \
|
||||
emic = (1000000*(ru.ru_utime.tv_sec + ru.ru_stime.tv_sec) \
|
||||
+ ru.ru_utime.tv_usec + ru.ru_stime.tv_usec); \
|
||||
inb = ru.ru_inblock; \
|
||||
oub = ru.ru_oublock; \
|
||||
for(TMreps=0; TMreps < TMrepeats; TMreps++) {
|
||||
|
||||
#define TIMING_END(seconds) \
|
||||
} \
|
||||
if(getrusage(RUSAGE_SELF, &ru)) { \
|
||||
printf("getrusage failed, returned %d\n", errno);} \
|
||||
emic = (1000000*(ru.ru_utime.tv_sec + ru.ru_stime.tv_sec) \
|
||||
+ ru.ru_utime.tv_usec + ru.ru_stime.tv_usec) - emic; \
|
||||
inb = ru.ru_inblock - inb; \
|
||||
oub = ru.ru_oublock - oub; \
|
||||
TMrepeats *= 2; \
|
||||
} while (emic < 100000.0 ); \
|
||||
seconds = emic / (1000000.0 * TMreps); \
|
||||
printf("%-45.45s %7.2g sec", \
|
||||
time_mess, seconds);
|
||||
#define FILE_NAME "tst_chunks.nc"
|
||||
#define NDIMS1 1
|
||||
#define D_SMALL "small_dim"
|
||||
#define D_SMALL_LEN 16
|
||||
#define D_MEDIUM "medium_dim"
|
||||
#define D_MEDIUM_LEN 65546
|
||||
#define D_LARGE "large_dim"
|
||||
#define D_LARGE_LEN 1048586
|
||||
#define V_SMALL "small_var"
|
||||
#define V_MEDIUM "medium_var"
|
||||
#define V_LARGE "large_var"
|
||||
|
||||
/* This macro prints an error message with line number and name of
|
||||
* test program. */
|
||||
#define ERR1(n) do { \
|
||||
fflush(stdout); /* Make sure our stdout is synced with stderr. */ \
|
||||
fprintf(stderr, "Sorry! Unexpected result, %s, line: %d - %s\n", \
|
||||
__FILE__, __LINE__, nc_strerror(n)); \
|
||||
return n; \
|
||||
} while (0)
|
||||
|
||||
#define NC_COMPRESSED 1
|
||||
|
||||
void
|
||||
parse_args(int argc, char *argv[], /* from command-line invocation */
|
||||
int *deflate_levelp, /* returned: 0 uncompressed,
|
||||
1-9 compression level */
|
||||
int *shufflep, /* returned: 1 if shuffle, otherwise 0 */
|
||||
size_t *dims, /* returned: dimension sizes */
|
||||
size_t *chunks, /* returned: chunk sizes */
|
||||
size_t *cache_sizep, /* returned: cache size (bytes) */
|
||||
size_t *cache_nelemsp, /* returned: cache capacity (chunks) */
|
||||
float *cache_prep) /* returned: cache preemption policy (0-1) */
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
|
||||
if(argc > 1) {
|
||||
*deflate_levelp = atol(argv[1]);
|
||||
if (*deflate_levelp < 0) {
|
||||
*deflate_levelp = -*deflate_levelp;
|
||||
*shufflep = NC_SHUFFLE;
|
||||
}
|
||||
}
|
||||
if(argc > 2)
|
||||
dims[0] = atol(argv[2]);
|
||||
if(argc > 3)
|
||||
chunks[0] = atol(argv[3]);
|
||||
else
|
||||
chunks[0] = (dims[0]+7)/8;
|
||||
if(argc > 4)
|
||||
dims[1] = atol(argv[4]);
|
||||
else
|
||||
dims[1] = dims[0];
|
||||
if(argc > 5)
|
||||
chunks[1] = atol(argv[5]);
|
||||
else
|
||||
chunks[1] = chunks[0];
|
||||
if(argc > 6)
|
||||
dims[2] = atol(argv[6]);
|
||||
else
|
||||
dims[2] = dims[1];
|
||||
if(argc > 7)
|
||||
chunks[2] = atol(argv[7]);
|
||||
else
|
||||
chunks[2] = chunks[1];
|
||||
if(argc > 8)
|
||||
*cache_sizep = atol(argv[8]);
|
||||
if(argc > 9)
|
||||
*cache_nelemsp = atol(argv[9]);
|
||||
if(argc > 10)
|
||||
*cache_prep = atof(argv[10]);
|
||||
if(argc > 11) {
|
||||
printf("Usage: %s [def_level] [dim1] [chunk1] [dim2] [chunk2] [dim3] [chunk3] [cache_size] [cache_nelems] [cache_pre]\n",
|
||||
argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
return;
|
||||
}
|
||||
printf("\n*** Testing netcdf-4 variable chunking.\n");
|
||||
printf("**** testing that fixed vars with filter end up being chunked, with good sizes...");
|
||||
{
|
||||
|
||||
void *
|
||||
emalloc(size_t bytes) {
|
||||
size_t *memory;
|
||||
memory = malloc(bytes);
|
||||
if(memory == 0) {
|
||||
printf("malloc failed\n");
|
||||
exit(2);
|
||||
}
|
||||
return memory;
|
||||
int ncid;
|
||||
int nvars, ndims, ngatts, unlimdimid;
|
||||
int contig;
|
||||
int ndims_in, natts_in, dimids_in;
|
||||
int small_dimid, medium_dimid, large_dimid;
|
||||
int small_varid, medium_varid, large_varid;
|
||||
char var_name_in[NC_MAX_NAME + 1];
|
||||
size_t chunksize_in[NDIMS1];
|
||||
nc_type xtype_in;
|
||||
|
||||
/* Create a netcdf-4 file with three dimensions. */
|
||||
if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
|
||||
if (nc_def_dim(ncid, D_SMALL, D_SMALL_LEN, &small_dimid)) ERR;
|
||||
if (nc_def_dim(ncid, D_MEDIUM, D_MEDIUM_LEN, &medium_dimid)) ERR;
|
||||
if (nc_def_dim(ncid, D_LARGE, D_LARGE_LEN, &large_dimid)) ERR;
|
||||
|
||||
/* Add three vars, with filters to force chunking. */
|
||||
if (nc_def_var(ncid, V_SMALL, NC_INT64, NDIMS1, &small_dimid, &small_varid)) ERR;
|
||||
if (nc_def_var_deflate(ncid, small_varid, 0, 1, 4)) ERR;
|
||||
if (nc_def_var(ncid, V_MEDIUM, NC_INT64, NDIMS1, &medium_dimid, &medium_varid)) ERR;
|
||||
if (nc_def_var_deflate(ncid, medium_varid, 1, 0, 0)) ERR;
|
||||
if (nc_def_var(ncid, V_LARGE, NC_INT64, NDIMS1, &large_dimid, &large_varid)) ERR;
|
||||
if (nc_def_var_fletcher32(ncid, large_varid, 1)) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
/* Open the file and check. */
|
||||
if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR;
|
||||
if (nc_inq(ncid, &ndims, &nvars, &ngatts, &unlimdimid)) ERR;
|
||||
if (nvars != 3 || ndims != 3 || ngatts != 0 || unlimdimid != -1) ERR;
|
||||
if (nc_inq_var(ncid, 0, var_name_in, &xtype_in, &ndims_in, &dimids_in, &natts_in)) ERR;
|
||||
if (strcmp(var_name_in, V_SMALL) || xtype_in != NC_INT64 || ndims_in != 1 ||
|
||||
natts_in != 0) ERR;
|
||||
|
||||
/* Make sure chunking sizes are what we expect. */
|
||||
if (nc_inq_var_chunking(ncid, small_varid, &contig, chunksize_in)) ERR;
|
||||
if (contig || chunksize_in[0] != D_SMALL_LEN) ERR;
|
||||
if (nc_inq_var_chunking(ncid, medium_varid, &contig, chunksize_in)) ERR;
|
||||
if (contig || chunksize_in[0] * sizeof(long long) > DEFAULT_CHUNK_SIZE) ERR;
|
||||
if (nc_inq_var_chunking(ncid, large_varid, &contig, chunksize_in)) ERR;
|
||||
if (contig || chunksize_in[0] * sizeof(long long) > DEFAULT_CHUNK_SIZE) ERR;
|
||||
|
||||
if (nc_close(ncid)) ERR;
|
||||
}
|
||||
SUMMARIZE_ERR;
|
||||
printf("**** printing table of default chunksizes...");
|
||||
{
|
||||
int nvars, ndims, ngatts, unlimdimid;
|
||||
int contig;
|
||||
#define NUM_DIM 4
|
||||
#define NUM_TYPE 2
|
||||
int ncid;
|
||||
int dim_len[NUM_DIM] = {NC_UNLIMITED, 100, 1000, 2000};
|
||||
size_t chunksize_in[NUM_DIM];
|
||||
int type_id[NUM_TYPE] = {NC_BYTE, NC_INT};
|
||||
int dimid[NUM_DIM], varid[NUM_TYPE];
|
||||
char dim_name[NC_MAX_NAME + 1], var_name[NC_MAX_NAME + 1];
|
||||
int d, t;
|
||||
|
||||
/* Create a netcdf-4 file with NUM_DIM dimensions. */
|
||||
if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
|
||||
for (d = 0; d < NUM_DIM; d++)
|
||||
{
|
||||
sprintf(dim_name, "dim_%d", dim_len[d]);
|
||||
printf("creating dim %s\n", dim_name);
|
||||
if (nc_def_dim(ncid, dim_name, dim_len[d], &dimid[d])) ERR;
|
||||
}
|
||||
|
||||
for (t = 0; t < NUM_TYPE; t++)
|
||||
{
|
||||
sprintf(var_name, "var_%d", type_id[t]);
|
||||
if (nc_def_var(ncid, var_name, type_id[t], NUM_DIM, dimid, &varid[t])) ERR;
|
||||
if (nc_inq_var_chunking(ncid, varid[t], &contig, chunksize_in)) ERR;
|
||||
printf("chunksizes for %d x %d x %d x %d var: %d x %d x %d x %d (=%d)\n",
|
||||
dim_len[0], dim_len[1], dim_len[2], dim_len[3],
|
||||
(int)chunksize_in[0], (int)chunksize_in[1], (int)chunksize_in[2],
|
||||
(int)chunksize_in[3],
|
||||
(int)(chunksize_in[0] * chunksize_in[1] * chunksize_in[2] * chunksize_in[3]));
|
||||
}
|
||||
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
/* Open the file and check. */
|
||||
if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR;
|
||||
if (nc_inq(ncid, &ndims, &nvars, &ngatts, &unlimdimid)) ERR;
|
||||
if (nvars != NUM_TYPE || ndims != NUM_DIM || ngatts != 0 || unlimdimid != 0) ERR;
|
||||
|
||||
for (t = 0; t < NUM_TYPE; t++)
|
||||
{
|
||||
sprintf(var_name, "var_%d", type_id[t]);
|
||||
if (nc_inq_var_chunking(ncid, varid[t], &contig, chunksize_in)) ERR;
|
||||
if (contig) ERR;
|
||||
printf("chunksizes for %d x %d x %d x %d var: %d x %d x %d x %d (=%d)\n",
|
||||
dim_len[0], dim_len[1], dim_len[2], dim_len[3],
|
||||
(int)chunksize_in[0], (int)chunksize_in[1], (int)chunksize_in[2],
|
||||
(int)chunksize_in[3],
|
||||
(int)(chunksize_in[0] * chunksize_in[1] * chunksize_in[2] * chunksize_in[3]));
|
||||
}
|
||||
|
||||
if (nc_close(ncid)) ERR;
|
||||
}
|
||||
SUMMARIZE_ERR;
|
||||
printf("**** testing that chunking works on classic mode files...");
|
||||
{
|
||||
#define D_SMALL_LEN2 66
|
||||
int ncid;
|
||||
int nvars, ndims, ngatts, unlimdimid;
|
||||
int contig;
|
||||
int ndims_in, natts_in, dimids_in;
|
||||
int small_dimid, medium_dimid, large_dimid;
|
||||
int small_varid, medium_varid, large_varid;
|
||||
char var_name_in[NC_MAX_NAME + 1];
|
||||
size_t chunks[1], chunksize_in;
|
||||
nc_type xtype_in;
|
||||
|
||||
/* Create a netcdf-4 file with three dimensions. */
|
||||
if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
|
||||
if (nc_def_dim(ncid, D_SMALL, D_SMALL_LEN2, &small_dimid)) ERR;
|
||||
if (nc_def_dim(ncid, D_MEDIUM, D_MEDIUM_LEN, &medium_dimid)) ERR;
|
||||
if (nc_def_dim(ncid, D_LARGE, D_LARGE_LEN, &large_dimid)) ERR;
|
||||
|
||||
/* Add three vars. */
|
||||
if (nc_def_var(ncid, V_SMALL, NC_INT64, NDIMS1, &small_dimid, &small_varid)) ERR;
|
||||
if (nc_def_var_chunking(ncid, small_varid, 1, NULL)) ERR;
|
||||
|
||||
if (nc_def_var(ncid, V_MEDIUM, NC_INT64, NDIMS1, &medium_dimid, &medium_varid)) ERR;
|
||||
chunks[0] = D_MEDIUM_LEN / 100;
|
||||
if (nc_def_var_chunking(ncid, medium_varid, 0, chunks)) ERR;
|
||||
if (nc_def_var_deflate(ncid, medium_varid, 1, 0, 0)) ERR;
|
||||
|
||||
if (nc_def_var(ncid, V_LARGE, NC_INT64, NDIMS1, &large_dimid, &large_varid)) ERR;
|
||||
chunks[0] = D_LARGE_LEN / 1000;
|
||||
if (nc_def_var_chunking(ncid, large_varid, 0, chunks)) ERR;
|
||||
if (nc_def_var_fletcher32(ncid, large_varid, 1)) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
/* Open the file and check. */
|
||||
if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR;
|
||||
if (nc_inq(ncid, &ndims, &nvars, &ngatts, &unlimdimid)) ERR;
|
||||
if (nvars != 3 || ndims != 3 || ngatts != 0 || unlimdimid != -1) ERR;
|
||||
if (nc_inq_var(ncid, 0, var_name_in, &xtype_in, &ndims_in, &dimids_in, &natts_in)) ERR;
|
||||
if (strcmp(var_name_in, V_SMALL) || xtype_in != NC_INT64 || ndims_in != 1 ||
|
||||
natts_in != 0) ERR;
|
||||
|
||||
/* Make sure chunking settings are what we expect. */
|
||||
if (nc_inq_var_chunking(ncid, small_varid, &contig, &chunksize_in)) ERR;
|
||||
if (!contig) ERR;
|
||||
if (nc_inq_var_chunking(ncid, medium_varid, &contig, &chunksize_in)) ERR;
|
||||
if (contig || chunksize_in != D_MEDIUM_LEN / 100) ERR;
|
||||
if (nc_inq_var_chunking(ncid, large_varid, &contig, &chunksize_in)) ERR;
|
||||
if (contig || chunksize_in != D_LARGE_LEN / 1000) ERR;
|
||||
|
||||
if (nc_close(ncid)) ERR;
|
||||
}
|
||||
SUMMARIZE_ERR;
|
||||
printf("**** testing many chunking and contiguous variables...");
|
||||
{
|
||||
#define NDIMS_3 3
|
||||
#define NUM_PLANS 30
|
||||
#define D_SNEAKINESS "sneakiness"
|
||||
#define D_SNEAKINESS_LEN 5
|
||||
#define D_CLEVERNESS "clevernesss"
|
||||
#define D_CLEVERNESS_LEN 3
|
||||
#define D_EFFECTIVENESS "effectiveness"
|
||||
#define D_EFFECTIVENESS_LEN 2
|
||||
|
||||
int ncid, dimids[NDIMS_3], varid[NUM_PLANS];
|
||||
size_t chunksize[NDIMS_3] = {D_SNEAKINESS_LEN, D_CLEVERNESS_LEN,
|
||||
D_EFFECTIVENESS_LEN};
|
||||
char plan_name[NC_MAX_NAME + 1];
|
||||
int contig;
|
||||
size_t chunksize_in[NDIMS_3];
|
||||
int i, j;
|
||||
|
||||
/* Create a netcdf-4 file with three dimensions. */
|
||||
if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
|
||||
if (nc_def_dim(ncid, D_SNEAKINESS, D_SNEAKINESS_LEN, &dimids[0])) ERR;
|
||||
if (nc_def_dim(ncid, D_CLEVERNESS, D_CLEVERNESS_LEN, &dimids[1])) ERR;
|
||||
if (nc_def_dim(ncid, D_EFFECTIVENESS, D_EFFECTIVENESS_LEN, &dimids[2])) ERR;
|
||||
|
||||
/* Oh that tricky Cardinal Richelieu, he had many plans! */
|
||||
for (i = 0; i < NUM_PLANS; i++)
|
||||
{
|
||||
sprintf(plan_name, "Richelieu_sneaky_plan_%d", i);
|
||||
if (nc_def_var(ncid, plan_name, i % (NC_STRING - 1) + 1, NDIMS_3,
|
||||
dimids, &varid[i])) ERR;
|
||||
if (i % 2 && nc_def_var_chunking(ncid, varid[i], 0, chunksize)) ERR;
|
||||
}
|
||||
|
||||
/* Check the chunking. */
|
||||
for (i = 0; i < NUM_PLANS; i++)
|
||||
{
|
||||
if (nc_inq_var_chunking(ncid, varid[i], &contig, chunksize_in)) ERR;
|
||||
if (i % 2)
|
||||
{
|
||||
for (j = 0; j < NDIMS_3; j++)
|
||||
if (chunksize_in[j] != chunksize[j]) ERR;
|
||||
}
|
||||
else
|
||||
if (!contig) ERR;
|
||||
}
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
/* Open the file and check. */
|
||||
if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR;
|
||||
/* Check the chunking. */
|
||||
for (i = 0; i < NUM_PLANS; i++)
|
||||
{
|
||||
if (nc_inq_var_chunking(ncid, varid[i], &contig, chunksize_in)) ERR;
|
||||
if (i % 2)
|
||||
{
|
||||
for (j = 0; j < NDIMS_3; j++)
|
||||
if (chunksize_in[j] != chunksize[j]) ERR;
|
||||
}
|
||||
else
|
||||
if (!contig) ERR;
|
||||
}
|
||||
if (nc_close(ncid)) ERR;
|
||||
}
|
||||
SUMMARIZE_ERR;
|
||||
FINAL_RESULTS;
|
||||
}
|
||||
|
||||
|
||||
/* compare contiguous, chunked, and compressed performance */
|
||||
int
|
||||
main(int argc, char *argv[]) {
|
||||
|
||||
int stat; /* return status */
|
||||
int ncid; /* netCDF id */
|
||||
int i, j, k;
|
||||
int dim1id, dim2id, dim3id;
|
||||
int varid_g; /* varid for contiguous */
|
||||
int varid_k; /* varid for chunked */
|
||||
int varid_x; /* varid for compressed */
|
||||
|
||||
float *varxy, *varxz, *varyz; /* 2D memory slabs used for I/O */
|
||||
int mm;
|
||||
size_t dims[] = {256, 256, 256}; /* default dim lengths */
|
||||
size_t chunks[] = {32, 32, 32}; /* default chunk sizes */
|
||||
size_t start[3], count[3];
|
||||
float contig_time, chunked_time, compressed_time, ratio;
|
||||
int deflate_level = 1; /* default compression level, 9 is
|
||||
* better and slower. If negative,
|
||||
* turn on shuffle filter also. */
|
||||
int shuffle = NC_NOSHUFFLE;
|
||||
size_t cache_size_def;
|
||||
size_t cache_hash_def;
|
||||
float cache_pre_def;
|
||||
size_t cache_size = 0; /* use library default */
|
||||
size_t cache_hash = 0; /* use library default */
|
||||
float cache_pre = -1.0f; /* use library default */
|
||||
|
||||
/* rank (number of dimensions) for each variable */
|
||||
# define RANK_var1 3
|
||||
|
||||
/* variable shapes */
|
||||
int var_dims[RANK_var1];
|
||||
|
||||
TIMING_DECLS(TMsec) ;
|
||||
|
||||
/* From args, get parameters for timing, including variable and
|
||||
chunk sizes. Negative deflate level means also use shuffle
|
||||
filter. */
|
||||
parse_args(argc, argv, &deflate_level, &shuffle, dims,
|
||||
chunks, &cache_size, &cache_hash, &cache_pre);
|
||||
|
||||
/* get cache defaults, then set cache parameters that are not default */
|
||||
if((stat = nc_get_chunk_cache(&cache_size_def, &cache_hash_def,
|
||||
&cache_pre_def)))
|
||||
ERR1(stat);
|
||||
if(cache_size == 0)
|
||||
cache_size = cache_size_def;
|
||||
if(cache_hash == 0)
|
||||
cache_hash = cache_hash_def;
|
||||
if(cache_pre == -1.0f)
|
||||
cache_pre = cache_pre_def;
|
||||
if((stat = nc_set_chunk_cache(cache_size, cache_hash, cache_pre)))
|
||||
ERR1(stat);
|
||||
printf("cache: %3.2f MBytes %ld objs %3.2f preempt, ",
|
||||
cache_size/1.e6, cache_hash, cache_pre);
|
||||
|
||||
if(deflate_level == 0) {
|
||||
printf("uncompressed ");
|
||||
} else {
|
||||
printf("compression level %d", deflate_level);
|
||||
}
|
||||
if(shuffle == 1) {
|
||||
printf(", shuffled");
|
||||
}
|
||||
printf("\n\n");
|
||||
|
||||
/* initialize 2D slabs for writing along each axis with phony data */
|
||||
varyz = (float *) emalloc(sizeof(float) * 1 * dims[1] * dims[2]);
|
||||
varxz = (float *) emalloc(sizeof(float) * dims[0] * 1 * dims[2]);
|
||||
varxy = (float *) emalloc(sizeof(float) * dims[0] * dims[1] * 1);
|
||||
mm = 0;
|
||||
for(j = 0; j < dims[1]; j++) {
|
||||
for(k = 0; k < dims[2]; k++) {
|
||||
varyz[mm++] = k + dims[2]*j;
|
||||
}
|
||||
}
|
||||
mm = 0;
|
||||
for(i = 0; i < dims[0]; i++) {
|
||||
for(k = 0; k < dims[2]; k++) {
|
||||
varxz[mm++] = k + dims[2]*i;
|
||||
}
|
||||
}
|
||||
mm = 0;
|
||||
for(i = 0; i < dims[0]; i++) {
|
||||
for(j = 0; j < dims[1]; j++) {
|
||||
varxy[mm++] = j + dims[1]*i;
|
||||
}
|
||||
}
|
||||
|
||||
if((stat = nc_create(FILENAME, NC_NETCDF4 | NC_CLASSIC_MODEL, &ncid)))
|
||||
ERR1(stat);
|
||||
|
||||
/* define dimensions */
|
||||
if((stat = nc_def_dim(ncid, "dim1", dims[0], &dim1id)))
|
||||
ERR1(stat);
|
||||
if((stat = nc_def_dim(ncid, "dim2", dims[1], &dim2id)))
|
||||
ERR1(stat);
|
||||
if((stat = nc_def_dim(ncid, "dim3", dims[2], &dim3id)))
|
||||
ERR1(stat);
|
||||
|
||||
/* define variables */
|
||||
var_dims[0] = dim1id;
|
||||
var_dims[1] = dim2id;
|
||||
var_dims[2] = dim3id;
|
||||
if((stat = nc_def_var(ncid, "var_contiguous", NC_FLOAT, RANK_var1,
|
||||
var_dims, &varid_g)))
|
||||
ERR1(stat);
|
||||
if((stat = nc_def_var(ncid, "var_chunked", NC_FLOAT, RANK_var1,
|
||||
var_dims, &varid_k)))
|
||||
ERR1(stat);
|
||||
if((stat = nc_def_var(ncid, "var_compressed", NC_FLOAT, RANK_var1,
|
||||
var_dims, &varid_x)))
|
||||
ERR1(stat);
|
||||
|
||||
if((stat = nc_def_var_chunking(ncid, varid_g, NC_CONTIGUOUS, 0)))
|
||||
ERR1(stat);
|
||||
|
||||
if((stat = nc_def_var_chunking(ncid, varid_k, NC_CHUNKED, chunks)))
|
||||
ERR1(stat);
|
||||
|
||||
if((stat = nc_def_var_chunking(ncid, varid_x, NC_CHUNKED, chunks)))
|
||||
ERR1(stat);
|
||||
|
||||
if (deflate_level != 0) {
|
||||
if((stat = nc_def_var_deflate(ncid, varid_x, shuffle,
|
||||
NC_COMPRESSED, deflate_level)))
|
||||
ERR1(stat);
|
||||
}
|
||||
|
||||
/* leave define mode */
|
||||
if((stat = nc_enddef (ncid)))
|
||||
ERR1(stat);
|
||||
|
||||
/* write each variable one yz slab at a time */
|
||||
start[0] = 0;
|
||||
start[1] = 0;
|
||||
start[2] = 0;
|
||||
count[0] = 1;
|
||||
count[1] = dims[1];
|
||||
count[2] = dims[2];
|
||||
|
||||
sprintf(time_mess," contiguous write %3ld %3ld %3ld",
|
||||
1, dims[1], dims[2]);
|
||||
TIMING_START ;
|
||||
for(i = 0; i < dims[0]; i++) {
|
||||
start[0] = i;
|
||||
if((stat = nc_put_vara(ncid, varid_g, start, count, &varyz[0])))
|
||||
ERR1(stat);
|
||||
}
|
||||
TIMING_END(TMsec) ;
|
||||
printf("\n");
|
||||
contig_time = TMsec;
|
||||
|
||||
sprintf(time_mess," chunked write %3ld %3ld %3ld %3ld %3ld %3ld",
|
||||
1, dims[1], dims[2], chunks[0], chunks[1], chunks[2]);
|
||||
TIMING_START ;
|
||||
for(i = 0; i < dims[0]; i++) {
|
||||
start[0] = i;
|
||||
if((stat = nc_put_vara(ncid, varid_k, start, count, &varyz[0])))
|
||||
ERR1(stat);
|
||||
}
|
||||
TIMING_END(TMsec) ;
|
||||
chunked_time = TMsec;
|
||||
ratio = contig_time/chunked_time;
|
||||
if(ratio >= 1.0)
|
||||
printf(" %5.2g x faster\n", ratio);
|
||||
else
|
||||
printf(" %5.2g x slower\n", 1.0/ratio);
|
||||
|
||||
sprintf(time_mess," compressed write %3ld %3ld %3ld %3ld %3ld %3ld",
|
||||
1, dims[1], dims[2], chunks[0], chunks[1], chunks[2]);
|
||||
TIMING_START ;
|
||||
for(i = 0; i < dims[0]; i++) {
|
||||
start[0] = i;
|
||||
if((stat = nc_put_vara(ncid, varid_x, start, count, &varyz[0])))
|
||||
ERR1(stat);
|
||||
}
|
||||
TIMING_END(TMsec) ;
|
||||
compressed_time = TMsec;
|
||||
ratio = contig_time/compressed_time;
|
||||
if(ratio >= 1.0)
|
||||
printf(" %5.2g x faster\n", ratio);
|
||||
else
|
||||
printf(" %5.2g x slower\n", 1.0/ratio);
|
||||
printf("\n");
|
||||
|
||||
/* write each variable one xz slab at a time */
|
||||
start[0] = 0;
|
||||
start[1] = 0;
|
||||
start[2] = 0;
|
||||
count[0] = dims[0];
|
||||
count[1] = 1;
|
||||
count[2] = dims[2];
|
||||
|
||||
sprintf(time_mess," contiguous write %3ld %3ld %3ld",
|
||||
dims[0], 1, dims[2]);
|
||||
TIMING_START ;
|
||||
for(i = 0; i < dims[1]; i++) {
|
||||
start[1] = i;
|
||||
if((stat = nc_put_vara(ncid, varid_g, start, count, &varxz[0])))
|
||||
ERR1(stat);
|
||||
}
|
||||
TIMING_END(TMsec) ;
|
||||
printf("\n");
|
||||
contig_time = TMsec;
|
||||
|
||||
sprintf(time_mess," chunked write %3ld %3ld %3ld %3ld %3ld %3ld",
|
||||
dims[0], 1, dims[2], chunks[0], chunks[1], chunks[2]);
|
||||
TIMING_START ;
|
||||
for(i = 0; i < dims[1]; i++) {
|
||||
start[1] = i;
|
||||
if((stat = nc_put_vara(ncid, varid_k, start, count, &varxz[0])))
|
||||
ERR1(stat);
|
||||
}
|
||||
TIMING_END(TMsec) ;
|
||||
chunked_time = TMsec;
|
||||
ratio = contig_time/chunked_time;
|
||||
if(ratio >= 1.0)
|
||||
printf(" %5.2g x faster\n", ratio);
|
||||
else
|
||||
printf(" %5.2g x slower\n", 1.0/ratio);
|
||||
|
||||
sprintf(time_mess," compressed write %3ld %3ld %3ld %3ld %3ld %3ld",
|
||||
dims[0], 1, dims[2], chunks[0], chunks[1], chunks[2]);
|
||||
TIMING_START ;
|
||||
for(i = 0; i < dims[1]; i++) {
|
||||
start[1] = i;
|
||||
if((stat = nc_put_vara(ncid, varid_x, start, count, &varxz[0])))
|
||||
ERR1(stat);
|
||||
}
|
||||
TIMING_END(TMsec) ;
|
||||
compressed_time = TMsec;
|
||||
ratio = contig_time/compressed_time;
|
||||
if(ratio >= 1.0)
|
||||
printf(" %5.2g x faster\n", ratio);
|
||||
else
|
||||
printf(" %5.2g x slower\n", 1.0/ratio);
|
||||
printf("\n");
|
||||
|
||||
/* write each variable one xy slab at a time */
|
||||
start[0] = 0;
|
||||
start[1] = 0;
|
||||
start[2] = 0;
|
||||
count[0] = dims[0];
|
||||
count[1] = dims[1];
|
||||
count[2] = 1;
|
||||
|
||||
sprintf(time_mess," contiguous write %3ld %3ld %3ld",
|
||||
dims[0], dims[1], 1);
|
||||
TIMING_START ;
|
||||
for(i = 0; i < dims[2]; i++) {
|
||||
start[2] = i;
|
||||
if((stat = nc_put_vara(ncid, varid_g, start, count, &varxy[0])))
|
||||
ERR1(stat);
|
||||
}
|
||||
TIMING_END(TMsec) ;
|
||||
printf("\n");
|
||||
contig_time = TMsec;
|
||||
|
||||
sprintf(time_mess," chunked write %3ld %3ld %3ld %3ld %3ld %3ld",
|
||||
dims[0], dims[1], 1, chunks[0], chunks[1], chunks[2]);
|
||||
TIMING_START ;
|
||||
for(i = 0; i < dims[2]; i++) {
|
||||
start[2] = i;
|
||||
if((stat = nc_put_vara(ncid, varid_k, start, count, &varxy[0])))
|
||||
ERR1(stat);
|
||||
}
|
||||
TIMING_END(TMsec) ;
|
||||
chunked_time = TMsec;
|
||||
ratio = contig_time/chunked_time;
|
||||
if(ratio >= 1.0)
|
||||
printf(" %5.2g x faster\n", ratio);
|
||||
else
|
||||
printf(" %5.2g x slower\n", 1.0/ratio);
|
||||
|
||||
sprintf(time_mess," compressed write %3ld %3ld %3ld %3ld %3ld %3ld",
|
||||
dims[0], dims[1], 1, chunks[0], chunks[1], chunks[2]);
|
||||
TIMING_START ;
|
||||
for(i = 0; i < dims[2]; i++) {
|
||||
start[2] = i;
|
||||
if((stat = nc_put_vara(ncid, varid_x, start, count, &varxy[0])))
|
||||
ERR1(stat);
|
||||
}
|
||||
TIMING_END(TMsec) ;
|
||||
compressed_time = TMsec;
|
||||
ratio = contig_time/compressed_time;
|
||||
if(ratio >= 1.0)
|
||||
printf(" %5.2g x faster\n", ratio);
|
||||
else
|
||||
printf(" %5.2g x slower\n", 1.0/ratio);
|
||||
printf("\n");
|
||||
|
||||
/* read each variable one yz slab at a time */
|
||||
start[0] = 0;
|
||||
start[1] = 0;
|
||||
start[2] = 0;
|
||||
count[0] = 1;
|
||||
count[1] = dims[1];
|
||||
count[2] = dims[2];
|
||||
|
||||
sprintf(time_mess," contiguous read %3ld %3ld %3ld",
|
||||
1, dims[1], dims[2]);
|
||||
TIMING_START ;
|
||||
for(i = 0; i < dims[0]; i++) {
|
||||
start[0] = i;
|
||||
if((stat = nc_get_vara(ncid, varid_g, start, count, &varyz[0])))
|
||||
ERR1(stat);
|
||||
}
|
||||
TIMING_END(TMsec) ;
|
||||
printf("\n");
|
||||
contig_time = TMsec;
|
||||
|
||||
sprintf(time_mess," chunked read %3ld %3ld %3ld %3ld %3ld %3ld",
|
||||
1, dims[1], dims[2] , chunks[0], chunks[1], chunks[2]);
|
||||
TIMING_START ;
|
||||
for(i = 0; i < dims[0]; i++) {
|
||||
start[0] = i;
|
||||
if((stat = nc_get_vara(ncid, varid_k, start, count, &varyz[0])))
|
||||
ERR1(stat);
|
||||
}
|
||||
TIMING_END(TMsec) ;
|
||||
chunked_time = TMsec;
|
||||
ratio = contig_time/chunked_time;
|
||||
if(ratio >= 1.0)
|
||||
printf(" %5.2g x faster\n", ratio);
|
||||
else
|
||||
printf(" %5.2g x slower\n", 1.0/ratio);
|
||||
|
||||
sprintf(time_mess," compressed read %3ld %3ld %3ld %3ld %3ld %3ld",
|
||||
1, dims[1], dims[2] , chunks[0], chunks[1], chunks[2]);
|
||||
TIMING_START ;
|
||||
for(i = 0; i < dims[0]; i++) {
|
||||
start[0] = i;
|
||||
if((stat = nc_get_vara(ncid, varid_x, start, count, &varyz[0])))
|
||||
ERR1(stat);
|
||||
}
|
||||
TIMING_END(TMsec) ;
|
||||
compressed_time = TMsec;
|
||||
ratio = contig_time/compressed_time;
|
||||
if(ratio >= 1.0)
|
||||
printf(" %5.2g x faster\n", ratio);
|
||||
else
|
||||
printf(" %5.2g x slower\n", 1.0/ratio);
|
||||
printf("\n");
|
||||
|
||||
/* read each variable one xz slab at a time */
|
||||
start[0] = 0;
|
||||
start[1] = 0;
|
||||
start[2] = 0;
|
||||
count[0] = dims[0];
|
||||
count[1] = 1;
|
||||
count[2] = dims[2];
|
||||
|
||||
sprintf(time_mess," contiguous read %3ld %3ld %3ld",
|
||||
dims[0], 1, dims[2]);
|
||||
TIMING_START ;
|
||||
for(i = 0; i < dims[1]; i++) {
|
||||
start[1] = i;
|
||||
if((stat = nc_get_vara(ncid, varid_g, start, count, &varxz[0])))
|
||||
ERR1(stat);
|
||||
}
|
||||
TIMING_END(TMsec) ;
|
||||
printf("\n");
|
||||
contig_time = TMsec;
|
||||
|
||||
sprintf(time_mess," chunked read %3ld %3ld %3ld %3ld %3ld %3ld",
|
||||
dims[0], 1, dims[2], chunks[0], chunks[1], chunks[2]);
|
||||
TIMING_START ;
|
||||
for(i = 0; i < dims[1]; i++) {
|
||||
start[1] = i;
|
||||
if((stat = nc_get_vara(ncid, varid_k, start, count, &varxz[0])))
|
||||
ERR1(stat);
|
||||
}
|
||||
TIMING_END(TMsec) ;
|
||||
chunked_time = TMsec;
|
||||
ratio = contig_time/chunked_time;
|
||||
if(ratio >= 1.0)
|
||||
printf(" %5.2g x faster\n", ratio);
|
||||
else
|
||||
printf(" %5.2g x slower\n", 1.0/ratio);
|
||||
|
||||
sprintf(time_mess," compressed read %3ld %3ld %3ld %3ld %3ld %3ld",
|
||||
dims[0], 1, dims[2], chunks[0], chunks[1], chunks[2]);
|
||||
TIMING_START ;
|
||||
for(i = 0; i < dims[1]; i++) {
|
||||
start[1] = i;
|
||||
if((stat = nc_get_vara(ncid, varid_x, start, count, &varxz[0])))
|
||||
ERR1(stat);
|
||||
}
|
||||
TIMING_END(TMsec) ;
|
||||
compressed_time = TMsec;
|
||||
ratio = contig_time/compressed_time;
|
||||
if(ratio >= 1.0)
|
||||
printf(" %5.2g x faster\n", ratio);
|
||||
else
|
||||
printf(" %5.2g x slower\n", 1.0/ratio);
|
||||
printf("\n");
|
||||
|
||||
/* read variable one xy slab at a time */
|
||||
start[0] = 0;
|
||||
start[1] = 0;
|
||||
start[2] = 0;
|
||||
count[0] = dims[0];
|
||||
count[1] = dims[1];
|
||||
count[2] = 1;
|
||||
|
||||
sprintf(time_mess," contiguous read %3ld %3ld %3ld",
|
||||
dims[0], dims[1], 1);
|
||||
TIMING_START ;
|
||||
for(i = 0; i < dims[2]; i++) {
|
||||
start[2] = i;
|
||||
if((stat = nc_get_vara(ncid, varid_g, start, count, &varxy[0])))
|
||||
ERR1(stat);
|
||||
}
|
||||
TIMING_END(TMsec) ;
|
||||
printf("\n");
|
||||
contig_time = TMsec;
|
||||
|
||||
sprintf(time_mess," chunked read %3ld %3ld %3ld %3ld %3ld %3ld",
|
||||
dims[0], dims[1], 1, chunks[0], chunks[1], chunks[2]);
|
||||
TIMING_START ;
|
||||
for(i = 0; i < dims[2]; i++) {
|
||||
start[2] = i;
|
||||
if((stat = nc_get_vara(ncid, varid_k, start, count, &varxy[0])))
|
||||
ERR1(stat);
|
||||
}
|
||||
TIMING_END(TMsec) ;
|
||||
chunked_time = TMsec;
|
||||
ratio = contig_time/chunked_time;
|
||||
if(ratio >= 1.0)
|
||||
printf(" %5.2g x faster\n", ratio);
|
||||
else
|
||||
printf(" %5.2g x slower\n", 1.0/ratio);
|
||||
|
||||
sprintf(time_mess," compressed read %3ld %3ld %3ld %3ld %3ld %3ld",
|
||||
dims[0], dims[1], 1, chunks[0], chunks[1], chunks[2]);
|
||||
TIMING_START ;
|
||||
for(i = 0; i < dims[2]; i++) {
|
||||
start[2] = i;
|
||||
if((stat = nc_get_vara(ncid, varid_x, start, count, &varxy[0])))
|
||||
ERR1(stat);
|
||||
}
|
||||
TIMING_END(TMsec) ;
|
||||
compressed_time = TMsec;
|
||||
ratio = contig_time/compressed_time;
|
||||
if(ratio >= 1.0)
|
||||
printf(" %5.2g x faster\n", ratio);
|
||||
else
|
||||
printf(" %5.2g x slower\n", 1.0/ratio);
|
||||
|
||||
if((stat = nc_close(ncid)))
|
||||
ERR1(stat);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
604
nc_test4/tst_chunks3.c
Normal file
604
nc_test4/tst_chunks3.c
Normal file
@ -0,0 +1,604 @@
|
||||
#include <config.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/times.h>
|
||||
#include <sys/stat.h>
|
||||
#include <assert.h>
|
||||
#include <sys/time.h>
|
||||
#include <unistd.h> /* for sysconf */
|
||||
#include <sys/resource.h>
|
||||
#include <nc_tests.h> /* The ERR macro is here... */
|
||||
#include <netcdf.h>
|
||||
|
||||
#define FILENAME "tst_chunks3.nc"
|
||||
|
||||
/*
|
||||
* The following timing macros can be used by including the necessary
|
||||
* declarations with
|
||||
*
|
||||
* TIMING_DECLS(seconds)
|
||||
*
|
||||
* and surrounding sections of code to be timed with the "statements"
|
||||
*
|
||||
* TIMING_START
|
||||
* [code to be timed goes here]
|
||||
* TIMING_END(seconds)
|
||||
*
|
||||
* The macros assume the user has stored a description of what is
|
||||
* being timed in a 100-char string time_mess, and has included
|
||||
* <sys/times.h> and <sys/resource.h>. The timing message printed by
|
||||
* TIMING_END is not terminated by a new-line, to permit appending
|
||||
* additional text to that line, so user must at least printf("\n")
|
||||
* after that.
|
||||
*/
|
||||
|
||||
#define TIMING_DECLS(seconds) \
|
||||
long TMreps; /* counts repetitions of timed code */ \
|
||||
long TMrepeats; /* repetitions needed to exceed 0.1 second */ \
|
||||
long emic ; /* elapsed time in microseconds */ \
|
||||
struct rusage ru; \
|
||||
long inb, oub; \
|
||||
char time_mess[100]; \
|
||||
float seconds;
|
||||
|
||||
#define TIMING_START \
|
||||
TMrepeats = 1; \
|
||||
do { \
|
||||
if(getrusage(RUSAGE_SELF, &ru)) { \
|
||||
printf("getrusage failed, returned %d\n", errno);} \
|
||||
emic = (1000000*(ru.ru_utime.tv_sec + ru.ru_stime.tv_sec) \
|
||||
+ ru.ru_utime.tv_usec + ru.ru_stime.tv_usec); \
|
||||
inb = ru.ru_inblock; \
|
||||
oub = ru.ru_oublock; \
|
||||
for(TMreps=0; TMreps < TMrepeats; TMreps++) {
|
||||
|
||||
#define TIMING_END(seconds) \
|
||||
} \
|
||||
if(getrusage(RUSAGE_SELF, &ru)) { \
|
||||
printf("getrusage failed, returned %d\n", errno);} \
|
||||
emic = (1000000*(ru.ru_utime.tv_sec + ru.ru_stime.tv_sec) \
|
||||
+ ru.ru_utime.tv_usec + ru.ru_stime.tv_usec) - emic; \
|
||||
inb = ru.ru_inblock - inb; \
|
||||
oub = ru.ru_oublock - oub; \
|
||||
TMrepeats *= 2; \
|
||||
} while (emic < 100000.0 ); \
|
||||
seconds = emic / (1000000.0 * TMreps); \
|
||||
printf("%-45.45s %7.2g sec", \
|
||||
time_mess, seconds);
|
||||
|
||||
/* This macro prints an error message with line number and name of
|
||||
* test program. */
|
||||
#define ERR1(n) do { \
|
||||
fflush(stdout); /* Make sure our stdout is synced with stderr. */ \
|
||||
fprintf(stderr, "Sorry! Unexpected result, %s, line: %d - %s\n", \
|
||||
__FILE__, __LINE__, nc_strerror(n)); \
|
||||
return n; \
|
||||
} while (0)
|
||||
|
||||
#define NC_COMPRESSED 1
|
||||
|
||||
void
|
||||
parse_args(int argc, char *argv[], /* from command-line invocation */
|
||||
int *deflate_levelp, /* returned: 0 uncompressed,
|
||||
1-9 compression level */
|
||||
int *shufflep, /* returned: 1 if shuffle, otherwise 0 */
|
||||
size_t *dims, /* returned: dimension sizes */
|
||||
size_t *chunks, /* returned: chunk sizes */
|
||||
size_t *cache_sizep, /* returned: cache size (bytes) */
|
||||
size_t *cache_nelemsp, /* returned: cache capacity (chunks) */
|
||||
float *cache_prep) /* returned: cache preemption policy (0-1) */
|
||||
{
|
||||
|
||||
if(argc > 1) {
|
||||
*deflate_levelp = atol(argv[1]);
|
||||
if (*deflate_levelp < 0) {
|
||||
*deflate_levelp = -*deflate_levelp;
|
||||
*shufflep = NC_SHUFFLE;
|
||||
}
|
||||
}
|
||||
if(argc > 2)
|
||||
dims[0] = atol(argv[2]);
|
||||
if(argc > 3)
|
||||
chunks[0] = atol(argv[3]);
|
||||
else
|
||||
chunks[0] = (dims[0]+7)/8;
|
||||
if(argc > 4)
|
||||
dims[1] = atol(argv[4]);
|
||||
else
|
||||
dims[1] = dims[0];
|
||||
if(argc > 5)
|
||||
chunks[1] = atol(argv[5]);
|
||||
else
|
||||
chunks[1] = chunks[0];
|
||||
if(argc > 6)
|
||||
dims[2] = atol(argv[6]);
|
||||
else
|
||||
dims[2] = dims[1];
|
||||
if(argc > 7)
|
||||
chunks[2] = atol(argv[7]);
|
||||
else
|
||||
chunks[2] = chunks[1];
|
||||
if(argc > 8)
|
||||
*cache_sizep = atol(argv[8]);
|
||||
if(argc > 9)
|
||||
*cache_nelemsp = atol(argv[9]);
|
||||
if(argc > 10)
|
||||
*cache_prep = atof(argv[10]);
|
||||
if(argc > 11) {
|
||||
printf("Usage: %s [def_level] [dim1] [chunk1] [dim2] [chunk2] [dim3] [chunk3] [cache_size] [cache_nelems] [cache_pre]\n",
|
||||
argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void *
|
||||
emalloc(size_t bytes) {
|
||||
size_t *memory;
|
||||
memory = malloc(bytes);
|
||||
if(memory == 0) {
|
||||
printf("malloc failed\n");
|
||||
exit(2);
|
||||
}
|
||||
return memory;
|
||||
}
|
||||
|
||||
|
||||
/* compare contiguous, chunked, and compressed performance */
|
||||
int
|
||||
main(int argc, char *argv[]) {
|
||||
|
||||
int stat; /* return status */
|
||||
int ncid; /* netCDF id */
|
||||
int i, j, k;
|
||||
int dim1id, dim2id, dim3id;
|
||||
int varid_g; /* varid for contiguous */
|
||||
int varid_k; /* varid for chunked */
|
||||
int varid_x; /* varid for compressed */
|
||||
|
||||
float *varxy, *varxz, *varyz; /* 2D memory slabs used for I/O */
|
||||
int mm;
|
||||
size_t dims[] = {256, 256, 256}; /* default dim lengths */
|
||||
size_t chunks[] = {32, 32, 32}; /* default chunk sizes */
|
||||
size_t start[3], count[3];
|
||||
float contig_time, chunked_time, compressed_time, ratio;
|
||||
int deflate_level = 1; /* default compression level, 9 is
|
||||
* better and slower. If negative,
|
||||
* turn on shuffle filter also. */
|
||||
int shuffle = NC_NOSHUFFLE;
|
||||
size_t cache_size_def;
|
||||
size_t cache_hash_def;
|
||||
float cache_pre_def;
|
||||
size_t cache_size = 0; /* use library default */
|
||||
size_t cache_hash = 0; /* use library default */
|
||||
float cache_pre = -1.0f; /* use library default */
|
||||
|
||||
/* rank (number of dimensions) for each variable */
|
||||
# define RANK_var1 3
|
||||
|
||||
/* variable shapes */
|
||||
int var_dims[RANK_var1];
|
||||
|
||||
TIMING_DECLS(TMsec) ;
|
||||
|
||||
/* From args, get parameters for timing, including variable and
|
||||
chunk sizes. Negative deflate level means also use shuffle
|
||||
filter. */
|
||||
parse_args(argc, argv, &deflate_level, &shuffle, dims,
|
||||
chunks, &cache_size, &cache_hash, &cache_pre);
|
||||
|
||||
/* get cache defaults, then set cache parameters that are not default */
|
||||
if((stat = nc_get_chunk_cache(&cache_size_def, &cache_hash_def,
|
||||
&cache_pre_def)))
|
||||
ERR1(stat);
|
||||
if(cache_size == 0)
|
||||
cache_size = cache_size_def;
|
||||
if(cache_hash == 0)
|
||||
cache_hash = cache_hash_def;
|
||||
if(cache_pre == -1.0f)
|
||||
cache_pre = cache_pre_def;
|
||||
if((stat = nc_set_chunk_cache(cache_size, cache_hash, cache_pre)))
|
||||
ERR1(stat);
|
||||
printf("cache: %3.2f MBytes %ld objs %3.2f preempt, ",
|
||||
cache_size/1.e6, cache_hash, cache_pre);
|
||||
|
||||
if(deflate_level == 0) {
|
||||
printf("uncompressed ");
|
||||
} else {
|
||||
printf("compression level %d", deflate_level);
|
||||
}
|
||||
if(shuffle == 1) {
|
||||
printf(", shuffled");
|
||||
}
|
||||
printf("\n\n");
|
||||
|
||||
/* initialize 2D slabs for writing along each axis with phony data */
|
||||
varyz = (float *) emalloc(sizeof(float) * 1 * dims[1] * dims[2]);
|
||||
varxz = (float *) emalloc(sizeof(float) * dims[0] * 1 * dims[2]);
|
||||
varxy = (float *) emalloc(sizeof(float) * dims[0] * dims[1] * 1);
|
||||
mm = 0;
|
||||
for(j = 0; j < dims[1]; j++) {
|
||||
for(k = 0; k < dims[2]; k++) {
|
||||
varyz[mm++] = k + dims[2]*j;
|
||||
}
|
||||
}
|
||||
mm = 0;
|
||||
for(i = 0; i < dims[0]; i++) {
|
||||
for(k = 0; k < dims[2]; k++) {
|
||||
varxz[mm++] = k + dims[2]*i;
|
||||
}
|
||||
}
|
||||
mm = 0;
|
||||
for(i = 0; i < dims[0]; i++) {
|
||||
for(j = 0; j < dims[1]; j++) {
|
||||
varxy[mm++] = j + dims[1]*i;
|
||||
}
|
||||
}
|
||||
|
||||
if((stat = nc_create(FILENAME, NC_NETCDF4 | NC_CLASSIC_MODEL, &ncid)))
|
||||
ERR1(stat);
|
||||
|
||||
/* define dimensions */
|
||||
if((stat = nc_def_dim(ncid, "dim1", dims[0], &dim1id)))
|
||||
ERR1(stat);
|
||||
if((stat = nc_def_dim(ncid, "dim2", dims[1], &dim2id)))
|
||||
ERR1(stat);
|
||||
if((stat = nc_def_dim(ncid, "dim3", dims[2], &dim3id)))
|
||||
ERR1(stat);
|
||||
|
||||
/* define variables */
|
||||
var_dims[0] = dim1id;
|
||||
var_dims[1] = dim2id;
|
||||
var_dims[2] = dim3id;
|
||||
if((stat = nc_def_var(ncid, "var_contiguous", NC_FLOAT, RANK_var1,
|
||||
var_dims, &varid_g)))
|
||||
ERR1(stat);
|
||||
if((stat = nc_def_var(ncid, "var_chunked", NC_FLOAT, RANK_var1,
|
||||
var_dims, &varid_k)))
|
||||
ERR1(stat);
|
||||
if((stat = nc_def_var(ncid, "var_compressed", NC_FLOAT, RANK_var1,
|
||||
var_dims, &varid_x)))
|
||||
ERR1(stat);
|
||||
|
||||
if((stat = nc_def_var_chunking(ncid, varid_g, NC_CONTIGUOUS, 0)))
|
||||
ERR1(stat);
|
||||
|
||||
if((stat = nc_def_var_chunking(ncid, varid_k, NC_CHUNKED, chunks)))
|
||||
ERR1(stat);
|
||||
|
||||
if((stat = nc_def_var_chunking(ncid, varid_x, NC_CHUNKED, chunks)))
|
||||
ERR1(stat);
|
||||
|
||||
if (deflate_level != 0) {
|
||||
if((stat = nc_def_var_deflate(ncid, varid_x, shuffle,
|
||||
NC_COMPRESSED, deflate_level)))
|
||||
ERR1(stat);
|
||||
}
|
||||
|
||||
/* leave define mode */
|
||||
if((stat = nc_enddef (ncid)))
|
||||
ERR1(stat);
|
||||
|
||||
/* write each variable one yz slab at a time */
|
||||
start[0] = 0;
|
||||
start[1] = 0;
|
||||
start[2] = 0;
|
||||
count[0] = 1;
|
||||
count[1] = dims[1];
|
||||
count[2] = dims[2];
|
||||
|
||||
sprintf(time_mess," contiguous write %3ld %3ld %3ld",
|
||||
1, dims[1], dims[2]);
|
||||
TIMING_START ;
|
||||
for(i = 0; i < dims[0]; i++) {
|
||||
start[0] = i;
|
||||
if((stat = nc_put_vara(ncid, varid_g, start, count, &varyz[0])))
|
||||
ERR1(stat);
|
||||
}
|
||||
TIMING_END(TMsec) ;
|
||||
printf("\n");
|
||||
contig_time = TMsec;
|
||||
|
||||
sprintf(time_mess," chunked write %3ld %3ld %3ld %3ld %3ld %3ld",
|
||||
1, dims[1], dims[2], chunks[0], chunks[1], chunks[2]);
|
||||
TIMING_START ;
|
||||
for(i = 0; i < dims[0]; i++) {
|
||||
start[0] = i;
|
||||
if((stat = nc_put_vara(ncid, varid_k, start, count, &varyz[0])))
|
||||
ERR1(stat);
|
||||
}
|
||||
TIMING_END(TMsec) ;
|
||||
chunked_time = TMsec;
|
||||
ratio = contig_time/chunked_time;
|
||||
if(ratio >= 1.0)
|
||||
printf(" %5.2g x faster\n", ratio);
|
||||
else
|
||||
printf(" %5.2g x slower\n", 1.0/ratio);
|
||||
|
||||
sprintf(time_mess," compressed write %3ld %3ld %3ld %3ld %3ld %3ld",
|
||||
1, dims[1], dims[2], chunks[0], chunks[1], chunks[2]);
|
||||
TIMING_START ;
|
||||
for(i = 0; i < dims[0]; i++) {
|
||||
start[0] = i;
|
||||
if((stat = nc_put_vara(ncid, varid_x, start, count, &varyz[0])))
|
||||
ERR1(stat);
|
||||
}
|
||||
TIMING_END(TMsec) ;
|
||||
compressed_time = TMsec;
|
||||
ratio = contig_time/compressed_time;
|
||||
if(ratio >= 1.0)
|
||||
printf(" %5.2g x faster\n", ratio);
|
||||
else
|
||||
printf(" %5.2g x slower\n", 1.0/ratio);
|
||||
printf("\n");
|
||||
|
||||
/* write each variable one xz slab at a time */
|
||||
start[0] = 0;
|
||||
start[1] = 0;
|
||||
start[2] = 0;
|
||||
count[0] = dims[0];
|
||||
count[1] = 1;
|
||||
count[2] = dims[2];
|
||||
|
||||
sprintf(time_mess," contiguous write %3ld %3ld %3ld",
|
||||
dims[0], 1, dims[2]);
|
||||
TIMING_START ;
|
||||
for(i = 0; i < dims[1]; i++) {
|
||||
start[1] = i;
|
||||
if((stat = nc_put_vara(ncid, varid_g, start, count, &varxz[0])))
|
||||
ERR1(stat);
|
||||
}
|
||||
TIMING_END(TMsec) ;
|
||||
printf("\n");
|
||||
contig_time = TMsec;
|
||||
|
||||
sprintf(time_mess," chunked write %3ld %3ld %3ld %3ld %3ld %3ld",
|
||||
dims[0], 1, dims[2], chunks[0], chunks[1], chunks[2]);
|
||||
TIMING_START ;
|
||||
for(i = 0; i < dims[1]; i++) {
|
||||
start[1] = i;
|
||||
if((stat = nc_put_vara(ncid, varid_k, start, count, &varxz[0])))
|
||||
ERR1(stat);
|
||||
}
|
||||
TIMING_END(TMsec) ;
|
||||
chunked_time = TMsec;
|
||||
ratio = contig_time/chunked_time;
|
||||
if(ratio >= 1.0)
|
||||
printf(" %5.2g x faster\n", ratio);
|
||||
else
|
||||
printf(" %5.2g x slower\n", 1.0/ratio);
|
||||
|
||||
sprintf(time_mess," compressed write %3ld %3ld %3ld %3ld %3ld %3ld",
|
||||
dims[0], 1, dims[2], chunks[0], chunks[1], chunks[2]);
|
||||
TIMING_START ;
|
||||
for(i = 0; i < dims[1]; i++) {
|
||||
start[1] = i;
|
||||
if((stat = nc_put_vara(ncid, varid_x, start, count, &varxz[0])))
|
||||
ERR1(stat);
|
||||
}
|
||||
TIMING_END(TMsec) ;
|
||||
compressed_time = TMsec;
|
||||
ratio = contig_time/compressed_time;
|
||||
if(ratio >= 1.0)
|
||||
printf(" %5.2g x faster\n", ratio);
|
||||
else
|
||||
printf(" %5.2g x slower\n", 1.0/ratio);
|
||||
printf("\n");
|
||||
|
||||
/* write each variable one xy slab at a time */
|
||||
start[0] = 0;
|
||||
start[1] = 0;
|
||||
start[2] = 0;
|
||||
count[0] = dims[0];
|
||||
count[1] = dims[1];
|
||||
count[2] = 1;
|
||||
|
||||
sprintf(time_mess," contiguous write %3ld %3ld %3ld",
|
||||
dims[0], dims[1], 1);
|
||||
TIMING_START ;
|
||||
for(i = 0; i < dims[2]; i++) {
|
||||
start[2] = i;
|
||||
if((stat = nc_put_vara(ncid, varid_g, start, count, &varxy[0])))
|
||||
ERR1(stat);
|
||||
}
|
||||
TIMING_END(TMsec) ;
|
||||
printf("\n");
|
||||
contig_time = TMsec;
|
||||
|
||||
sprintf(time_mess," chunked write %3ld %3ld %3ld %3ld %3ld %3ld",
|
||||
dims[0], dims[1], 1, chunks[0], chunks[1], chunks[2]);
|
||||
TIMING_START ;
|
||||
for(i = 0; i < dims[2]; i++) {
|
||||
start[2] = i;
|
||||
if((stat = nc_put_vara(ncid, varid_k, start, count, &varxy[0])))
|
||||
ERR1(stat);
|
||||
}
|
||||
TIMING_END(TMsec) ;
|
||||
chunked_time = TMsec;
|
||||
ratio = contig_time/chunked_time;
|
||||
if(ratio >= 1.0)
|
||||
printf(" %5.2g x faster\n", ratio);
|
||||
else
|
||||
printf(" %5.2g x slower\n", 1.0/ratio);
|
||||
|
||||
sprintf(time_mess," compressed write %3ld %3ld %3ld %3ld %3ld %3ld",
|
||||
dims[0], dims[1], 1, chunks[0], chunks[1], chunks[2]);
|
||||
TIMING_START ;
|
||||
for(i = 0; i < dims[2]; i++) {
|
||||
start[2] = i;
|
||||
if((stat = nc_put_vara(ncid, varid_x, start, count, &varxy[0])))
|
||||
ERR1(stat);
|
||||
}
|
||||
TIMING_END(TMsec) ;
|
||||
compressed_time = TMsec;
|
||||
ratio = contig_time/compressed_time;
|
||||
if(ratio >= 1.0)
|
||||
printf(" %5.2g x faster\n", ratio);
|
||||
else
|
||||
printf(" %5.2g x slower\n", 1.0/ratio);
|
||||
printf("\n");
|
||||
|
||||
/* read each variable one yz slab at a time */
|
||||
start[0] = 0;
|
||||
start[1] = 0;
|
||||
start[2] = 0;
|
||||
count[0] = 1;
|
||||
count[1] = dims[1];
|
||||
count[2] = dims[2];
|
||||
|
||||
sprintf(time_mess," contiguous read %3ld %3ld %3ld",
|
||||
1, dims[1], dims[2]);
|
||||
TIMING_START ;
|
||||
for(i = 0; i < dims[0]; i++) {
|
||||
start[0] = i;
|
||||
if((stat = nc_get_vara(ncid, varid_g, start, count, &varyz[0])))
|
||||
ERR1(stat);
|
||||
}
|
||||
TIMING_END(TMsec) ;
|
||||
printf("\n");
|
||||
contig_time = TMsec;
|
||||
|
||||
sprintf(time_mess," chunked read %3ld %3ld %3ld %3ld %3ld %3ld",
|
||||
1, dims[1], dims[2] , chunks[0], chunks[1], chunks[2]);
|
||||
TIMING_START ;
|
||||
for(i = 0; i < dims[0]; i++) {
|
||||
start[0] = i;
|
||||
if((stat = nc_get_vara(ncid, varid_k, start, count, &varyz[0])))
|
||||
ERR1(stat);
|
||||
}
|
||||
TIMING_END(TMsec) ;
|
||||
chunked_time = TMsec;
|
||||
ratio = contig_time/chunked_time;
|
||||
if(ratio >= 1.0)
|
||||
printf(" %5.2g x faster\n", ratio);
|
||||
else
|
||||
printf(" %5.2g x slower\n", 1.0/ratio);
|
||||
|
||||
sprintf(time_mess," compressed read %3ld %3ld %3ld %3ld %3ld %3ld",
|
||||
1, dims[1], dims[2] , chunks[0], chunks[1], chunks[2]);
|
||||
TIMING_START ;
|
||||
for(i = 0; i < dims[0]; i++) {
|
||||
start[0] = i;
|
||||
if((stat = nc_get_vara(ncid, varid_x, start, count, &varyz[0])))
|
||||
ERR1(stat);
|
||||
}
|
||||
TIMING_END(TMsec) ;
|
||||
compressed_time = TMsec;
|
||||
ratio = contig_time/compressed_time;
|
||||
if(ratio >= 1.0)
|
||||
printf(" %5.2g x faster\n", ratio);
|
||||
else
|
||||
printf(" %5.2g x slower\n", 1.0/ratio);
|
||||
printf("\n");
|
||||
|
||||
/* read each variable one xz slab at a time */
|
||||
start[0] = 0;
|
||||
start[1] = 0;
|
||||
start[2] = 0;
|
||||
count[0] = dims[0];
|
||||
count[1] = 1;
|
||||
count[2] = dims[2];
|
||||
|
||||
sprintf(time_mess," contiguous read %3ld %3ld %3ld",
|
||||
dims[0], 1, dims[2]);
|
||||
TIMING_START ;
|
||||
for(i = 0; i < dims[1]; i++) {
|
||||
start[1] = i;
|
||||
if((stat = nc_get_vara(ncid, varid_g, start, count, &varxz[0])))
|
||||
ERR1(stat);
|
||||
}
|
||||
TIMING_END(TMsec) ;
|
||||
printf("\n");
|
||||
contig_time = TMsec;
|
||||
|
||||
sprintf(time_mess," chunked read %3ld %3ld %3ld %3ld %3ld %3ld",
|
||||
dims[0], 1, dims[2], chunks[0], chunks[1], chunks[2]);
|
||||
TIMING_START ;
|
||||
for(i = 0; i < dims[1]; i++) {
|
||||
start[1] = i;
|
||||
if((stat = nc_get_vara(ncid, varid_k, start, count, &varxz[0])))
|
||||
ERR1(stat);
|
||||
}
|
||||
TIMING_END(TMsec) ;
|
||||
chunked_time = TMsec;
|
||||
ratio = contig_time/chunked_time;
|
||||
if(ratio >= 1.0)
|
||||
printf(" %5.2g x faster\n", ratio);
|
||||
else
|
||||
printf(" %5.2g x slower\n", 1.0/ratio);
|
||||
|
||||
sprintf(time_mess," compressed read %3ld %3ld %3ld %3ld %3ld %3ld",
|
||||
dims[0], 1, dims[2], chunks[0], chunks[1], chunks[2]);
|
||||
TIMING_START ;
|
||||
for(i = 0; i < dims[1]; i++) {
|
||||
start[1] = i;
|
||||
if((stat = nc_get_vara(ncid, varid_x, start, count, &varxz[0])))
|
||||
ERR1(stat);
|
||||
}
|
||||
TIMING_END(TMsec) ;
|
||||
compressed_time = TMsec;
|
||||
ratio = contig_time/compressed_time;
|
||||
if(ratio >= 1.0)
|
||||
printf(" %5.2g x faster\n", ratio);
|
||||
else
|
||||
printf(" %5.2g x slower\n", 1.0/ratio);
|
||||
printf("\n");
|
||||
|
||||
/* read variable one xy slab at a time */
|
||||
start[0] = 0;
|
||||
start[1] = 0;
|
||||
start[2] = 0;
|
||||
count[0] = dims[0];
|
||||
count[1] = dims[1];
|
||||
count[2] = 1;
|
||||
|
||||
sprintf(time_mess," contiguous read %3ld %3ld %3ld",
|
||||
dims[0], dims[1], 1);
|
||||
TIMING_START ;
|
||||
for(i = 0; i < dims[2]; i++) {
|
||||
start[2] = i;
|
||||
if((stat = nc_get_vara(ncid, varid_g, start, count, &varxy[0])))
|
||||
ERR1(stat);
|
||||
}
|
||||
TIMING_END(TMsec) ;
|
||||
printf("\n");
|
||||
contig_time = TMsec;
|
||||
|
||||
sprintf(time_mess," chunked read %3ld %3ld %3ld %3ld %3ld %3ld",
|
||||
dims[0], dims[1], 1, chunks[0], chunks[1], chunks[2]);
|
||||
TIMING_START ;
|
||||
for(i = 0; i < dims[2]; i++) {
|
||||
start[2] = i;
|
||||
if((stat = nc_get_vara(ncid, varid_k, start, count, &varxy[0])))
|
||||
ERR1(stat);
|
||||
}
|
||||
TIMING_END(TMsec) ;
|
||||
chunked_time = TMsec;
|
||||
ratio = contig_time/chunked_time;
|
||||
if(ratio >= 1.0)
|
||||
printf(" %5.2g x faster\n", ratio);
|
||||
else
|
||||
printf(" %5.2g x slower\n", 1.0/ratio);
|
||||
|
||||
sprintf(time_mess," compressed read %3ld %3ld %3ld %3ld %3ld %3ld",
|
||||
dims[0], dims[1], 1, chunks[0], chunks[1], chunks[2]);
|
||||
TIMING_START ;
|
||||
for(i = 0; i < dims[2]; i++) {
|
||||
start[2] = i;
|
||||
if((stat = nc_get_vara(ncid, varid_x, start, count, &varxy[0])))
|
||||
ERR1(stat);
|
||||
}
|
||||
TIMING_END(TMsec) ;
|
||||
compressed_time = TMsec;
|
||||
ratio = contig_time/compressed_time;
|
||||
if(ratio >= 1.0)
|
||||
printf(" %5.2g x faster\n", ratio);
|
||||
else
|
||||
printf(" %5.2g x slower\n", 1.0/ratio);
|
||||
|
||||
if((stat = nc_close(ncid)))
|
||||
ERR1(stat);
|
||||
|
||||
return 0;
|
||||
}
|
@ -7,9 +7,8 @@
|
||||
$Id: tst_converts.c,v 1.16 2008/10/20 01:48:09 ed Exp $
|
||||
*/
|
||||
|
||||
#include <nc4internal.h>
|
||||
#include "netcdf.h"
|
||||
#include <nc_tests.h>
|
||||
#include "netcdf.h"
|
||||
|
||||
#define FILE_NAME "tst_converts.nc"
|
||||
#define ATT1_NAME "att1"
|
@ -9,7 +9,6 @@
|
||||
|
||||
#include <nc_tests.h>
|
||||
#include "netcdf.h"
|
||||
#include "nc4internal.h"
|
||||
|
||||
#define FILE_NAME "tst_converts2.nc"
|
||||
#define VAR_NAME "Monkey"
|
||||
@ -172,6 +171,7 @@ main(int argc, char **argv)
|
||||
SUMMARIZE_ERR;
|
||||
printf ("*** Testing MAX_INT conversions...");
|
||||
{
|
||||
#define X_INT_MAX 2147483647 /* from libsrc4/nc4internal.h */
|
||||
int ivalue = X_INT_MAX, ivalue_in;
|
||||
unsigned char uchar_in;
|
||||
unsigned int uivalue_in;
|
@ -1,67 +1,550 @@
|
||||
/* This is part of the netCDF package.
|
||||
Copyright 2010 University Corporation for Atmospheric Research/Unidata
|
||||
Copyright 2005 University Corporation for Atmospheric Research/Unidata
|
||||
See COPYRIGHT file for conditions of use.
|
||||
|
||||
Test netcdf files a bit.
|
||||
Test internal netcdf-4 file code.
|
||||
$Id: tst_files.c,v 1.42 2010/05/18 12:30:05 ed Exp $
|
||||
*/
|
||||
|
||||
#include <nc_tests.h>
|
||||
#include <config.h>
|
||||
#include "netcdf.h"
|
||||
#include <nc_tests.h>
|
||||
|
||||
#ifdef IGNORE
|
||||
extern NC_FILE_INFO_T *nc_file;
|
||||
#endif
|
||||
int test_redef(int format);
|
||||
|
||||
#define FILE_NAME "tst_files.nc"
|
||||
#define URL "http://test.opendap.org:8080/dods/dts/test.01"
|
||||
#define ATT1_NAME "MoneyOwned"
|
||||
#define ATT2_NAME "Number_of_Shoes"
|
||||
#define ATT3_NAME "att3"
|
||||
#define DIM1_NAME "Character_Growth"
|
||||
#define DIM1_LEN 10
|
||||
#define DIM2_NAME "TimeInMonths"
|
||||
#define DIM2_LEN 15
|
||||
#define VAR1_NAME "HuckFinn"
|
||||
#define VAR2_NAME "TomSawyer"
|
||||
#define VAR3_NAME "Jim"
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
printf("\n*** Testing netcdf file functions.\n");
|
||||
printf("*** Checking the new inq_path function...");
|
||||
printf("\n*** Testing netcdf-4 file functions.\n");
|
||||
{
|
||||
char str[NC_MAX_NAME+1];
|
||||
|
||||
/* Actually we never make any promises about the length of the
|
||||
* version string, but it is always smaller than NC_MAX_NAME. */
|
||||
if (strlen(nc_inq_libvers()) > NC_MAX_NAME) ERR;
|
||||
strcpy(str, nc_inq_libvers());
|
||||
printf("*** testing version %s...", str);
|
||||
}
|
||||
SUMMARIZE_ERR;
|
||||
printf("*** testing with bad inputs...");
|
||||
{
|
||||
int ncid;
|
||||
size_t path_len;
|
||||
char path_in[NC_MAX_NAME + 1] = "";
|
||||
|
||||
/* Test with classic file create. */
|
||||
if (nc_create(FILE_NAME, 0, &ncid)) ERR;
|
||||
if (nc_inq_path(ncid, &path_len, path_in)) ERR;
|
||||
if (path_len != strlen(FILE_NAME) || strcmp(path_in, FILE_NAME)) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
strcpy(path_in, "");
|
||||
path_len = 0;
|
||||
|
||||
/* Test with classic file open. */
|
||||
if (nc_open(FILE_NAME, 0, &ncid)) ERR;
|
||||
if (nc_inq_path(ncid, &path_len, path_in)) ERR;
|
||||
if (path_len != strlen(FILE_NAME) || strcmp(path_in, FILE_NAME)) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
strcpy(path_in, "");
|
||||
|
||||
/* Test with netCDF-4 create. */
|
||||
/* Make sure bad create mode causes failure. */
|
||||
/*if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;*/
|
||||
|
||||
/* Create an empty file. */
|
||||
if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
|
||||
if (nc_inq_path(ncid, &path_len, path_in)) ERR;
|
||||
if (path_len != strlen(FILE_NAME) || strcmp(path_in, FILE_NAME)) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
strcpy(path_in, "");
|
||||
path_len = 0;
|
||||
|
||||
/* Test with classic file open. */
|
||||
if (nc_open(FILE_NAME, NC_MPIIO|NC_MPIPOSIX, &ncid) != NC_EINVAL) ERR;
|
||||
|
||||
if (nc_create(FILE_NAME, NC_64BIT_OFFSET|NC_NETCDF4, &ncid) != NC_EINVAL) ERR;
|
||||
if (nc_create(FILE_NAME, NC_CLASSIC_MODEL|NC_MPIIO|NC_MPIPOSIX, &ncid) != NC_EINVAL) ERR;
|
||||
if (nc_create(FILE_NAME, NC_MPIIO|NC_MPIPOSIX, &ncid) != NC_EINVAL) ERR;
|
||||
}
|
||||
SUMMARIZE_ERR;
|
||||
printf("*** testing simple opens and creates...");
|
||||
{
|
||||
int ncid, ncid2, ncid3, varid, dimids[2];
|
||||
int ndims, nvars, natts, unlimdimid;
|
||||
int dimids_var[1], var_type;
|
||||
size_t dim_len;
|
||||
char dim_name[NC_MAX_NAME+1], var_name[NC_MAX_NAME+1];
|
||||
unsigned char uchar_out[DIM1_LEN] = {0, 128, 255};
|
||||
|
||||
/* Open and close empty file. */
|
||||
if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
/* Recreate it again. */
|
||||
if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
|
||||
if (nc_def_dim(ncid, DIM1_NAME, DIM1_LEN, &dimids[0])) ERR;
|
||||
if (nc_def_dim(ncid, DIM2_NAME, DIM2_LEN, &dimids[1])) ERR;
|
||||
if (nc_def_var(ncid, VAR1_NAME, NC_INT, 1, dimids, &varid)) ERR;
|
||||
if (nc_enddef(ncid)) ERR;
|
||||
if (nc_def_var(ncid, VAR2_NAME, NC_UINT, 2, dimids, &varid)) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
/* Check the contents. Then define a new variable. Since it's
|
||||
* netcdf-4, nc_enddef isn't required - it's called
|
||||
* automatically. */
|
||||
if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR;
|
||||
if (nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid)) ERR;
|
||||
if (ndims != 2 || nvars != 2 || natts != 0 || unlimdimid != -1) ERR;
|
||||
if (nc_redef(ncid)) ERR;
|
||||
if (nc_enddef(ncid)) ERR;
|
||||
if (nc_def_var(ncid, VAR3_NAME, NC_INT, 2, dimids, &varid)) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
/* Open three copies of the same file. */
|
||||
if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR;
|
||||
if (nc_open(FILE_NAME, NC_WRITE, &ncid2)) ERR;
|
||||
if (nc_open(FILE_NAME, NC_WRITE, &ncid3)) ERR;
|
||||
if (nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid)) ERR;
|
||||
if (ndims != 2 || nvars != 3 || natts != 0 || unlimdimid != -1) ERR;
|
||||
if (nc_inq(ncid2, &ndims, &nvars, &natts, &unlimdimid)) ERR;
|
||||
if (ndims != 2 || nvars != 3 || natts != 0 || unlimdimid != -1) ERR;
|
||||
if (nc_inq(ncid3, &ndims, &nvars, &natts, &unlimdimid)) ERR;
|
||||
if (ndims != 2 || nvars != 3 || natts != 0 || unlimdimid != -1) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
if (nc_close(ncid2)) ERR;
|
||||
if (nc_close(ncid3)) ERR;
|
||||
|
||||
/* Open and close empty file. */
|
||||
if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
/* Check the contents. */
|
||||
if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR;
|
||||
if (nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid)) ERR;
|
||||
if (ndims != 0 || nvars != 0 || natts != 0 || unlimdimid != -1) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
/* Create a file with one dimension and nothing else. */
|
||||
if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
|
||||
if (nc_def_dim(ncid, DIM1_NAME, DIM1_LEN, &dimids[0])) ERR;
|
||||
if (nc_enddef(ncid)) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
/* Check the contents. */
|
||||
if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR;
|
||||
if (nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid)) ERR;
|
||||
if (ndims != 1 || nvars != 0 || natts != 0 || unlimdimid != -1) ERR;
|
||||
if (nc_inq_dim(ncid, 0, dim_name, &dim_len)) ERR;
|
||||
if (dim_len != DIM1_LEN || strcmp(dim_name, DIM1_NAME)) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
/* Create a simple file, and write some data to it. */
|
||||
if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
|
||||
if (nc_def_dim(ncid, DIM1_NAME, DIM1_LEN, &dimids[0])) ERR;
|
||||
if (nc_def_var(ncid, VAR1_NAME, NC_BYTE, 1, dimids, &varid)) ERR;
|
||||
if (nc_enddef(ncid)) ERR;
|
||||
if (nc_put_var_uchar(ncid, varid, uchar_out) != NC_ERANGE) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
/* Check the contents. */
|
||||
if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR;
|
||||
if (nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid)) ERR;
|
||||
if (ndims != 1 || nvars != 1 || natts != 0 || unlimdimid != -1) ERR;
|
||||
if (nc_inq_dim(ncid, 0, dim_name, &dim_len)) ERR;
|
||||
if (dim_len != DIM1_LEN || strcmp(dim_name, DIM1_NAME)) ERR;
|
||||
if (nc_inq_var(ncid, 0, var_name, &var_type, &ndims, dimids_var, &natts)) ERR;
|
||||
if (ndims != 1 || strcmp(var_name, VAR1_NAME) || var_type != NC_BYTE ||
|
||||
dimids_var[0] != dimids[0] || natts != 0) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
/* Recreate the file. */
|
||||
if (nc_create(FILE_NAME, NC_NETCDF4|NC_CLASSIC_MODEL, &ncid)) ERR;
|
||||
if (nc_def_dim(ncid, DIM1_NAME, DIM1_LEN, &dimids[0])) ERR;
|
||||
if (nc_def_var(ncid, VAR1_NAME, NC_BYTE, 1, dimids, &varid)) ERR;
|
||||
if (nc_enddef(ncid)) ERR;
|
||||
if (nc_put_var_uchar(ncid, varid, uchar_out)) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
/* Recreate it, then make sure NOCLOBBER works. */
|
||||
if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
if (nc_create(FILE_NAME, NC_NETCDF4|NC_NOCLOBBER, &ncid) != NC_EEXIST) ERR;
|
||||
|
||||
/* Recreate it again. */
|
||||
if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
|
||||
if (nc_def_dim(ncid, DIM1_NAME, DIM1_LEN, &dimids[0])) ERR;
|
||||
if (nc_def_dim(ncid, DIM2_NAME, DIM2_LEN, &dimids[1])) ERR;
|
||||
if (nc_def_var(ncid, VAR1_NAME, NC_INT, 1, dimids, &varid)) ERR;
|
||||
if (nc_enddef(ncid)) ERR;
|
||||
if (nc_def_var(ncid, VAR2_NAME, NC_UINT, 2, dimids, &varid)) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
/* Check the contents. Then define a new variable. Since it's
|
||||
* netcdf-4, nc_enddef isn't required - it's called
|
||||
* automatically. */
|
||||
if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR;
|
||||
if (nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid)) ERR;
|
||||
if (ndims != 2 || nvars != 2 || natts != 0 || unlimdimid != -1) ERR;
|
||||
if (nc_redef(ncid)) ERR;
|
||||
if (nc_enddef(ncid)) ERR;
|
||||
if (nc_def_var(ncid, VAR3_NAME, NC_INT, 2, dimids, &varid)) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
/* Recreate it again with netcdf-3 rules turned on. */
|
||||
if (nc_create(FILE_NAME, NC_NETCDF4|NC_CLASSIC_MODEL, &ncid)) ERR;
|
||||
if (nc_def_dim(ncid, DIM1_NAME, DIM1_LEN, &dimids[0])) ERR;
|
||||
if (nc_def_var(ncid, VAR1_NAME, NC_INT, 1, dimids, &varid)) ERR;
|
||||
if (nc_enddef(ncid)) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
/* Check the contents. Check that netcdf-3 rules are in effect. */
|
||||
if (nc_open(FILE_NAME, 0, &ncid)) ERR;
|
||||
if (nc_inq_path(ncid, &path_len, path_in)) ERR;
|
||||
if (path_len != strlen(FILE_NAME) || strcmp(path_in, FILE_NAME)) ERR;
|
||||
if (nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid)) ERR;
|
||||
if (ndims != 1 || nvars != 1 || natts != 0 || unlimdimid != -1) ERR;
|
||||
if (nc_def_var(ncid, VAR2_NAME, NC_UINT, 2, dimids, &varid) != NC_ENOTINDEFINE) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
strcpy(path_in, "");
|
||||
path_len = 0;
|
||||
|
||||
/* #ifdef USE_DAP */
|
||||
/* /\* Test with URL. *\/ */
|
||||
/* if (nc_open(URL, 0, &ncid)) ERR; */
|
||||
/* if (nc_inq_path(ncid, &path_len, path_in)) ERR; */
|
||||
/* /\*if (path_len != strlen(URL) || strcmp(path_in, URL)) ERR;*\/ */
|
||||
/* if (nc_close(ncid)) ERR; */
|
||||
/* #endif /\* USE_DAP *\/ */
|
||||
/* Check some other stuff about it. Closing and reopening the
|
||||
* file forces HDF5 to tell us if we forgot to free some HDF5
|
||||
* resource associated with the file. */
|
||||
if (nc_open(FILE_NAME, 0, &ncid)) ERR;
|
||||
if (nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid)) ERR;
|
||||
if (nc_inq_dim(ncid, 0, dim_name, &dim_len)) ERR;
|
||||
if (dim_len != DIM1_LEN || strcmp(dim_name, DIM1_NAME)) ERR;
|
||||
if (nc_inq_var(ncid, 0, var_name, &var_type, &ndims, dimids_var, &natts)) ERR;
|
||||
if (ndims != 1 || strcmp(var_name, VAR1_NAME) || var_type != NC_INT ||
|
||||
dimids_var[0] != dimids[0] || natts != 0) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
}
|
||||
SUMMARIZE_ERR;
|
||||
printf("*** testing more complex opens and creates...");
|
||||
{
|
||||
int ncid, varid, dimids[2];
|
||||
int ndims, nvars, natts, unlimdimid;
|
||||
int dimids_var[2], var_type;
|
||||
size_t dim_len;
|
||||
char dim_name[NC_MAX_NAME+1], var_name[NC_MAX_NAME+1];
|
||||
float float_in, float_out = 99.99;
|
||||
int int_in, int_out = -9999;
|
||||
|
||||
/* Create a file, this time with attributes. */
|
||||
if (nc_create(FILE_NAME, NC_NETCDF4|NC_CLOBBER, &ncid)) ERR;
|
||||
if (nc_def_dim(ncid, DIM1_NAME, DIM1_LEN, &dimids[0])) ERR;
|
||||
if (nc_def_dim(ncid, DIM2_NAME, DIM2_LEN, &dimids[1])) ERR;
|
||||
if (nc_def_var(ncid, VAR1_NAME, NC_INT, 2, dimids, &varid)) ERR;
|
||||
if (nc_def_var(ncid, VAR2_NAME, NC_UINT, 2, dimids, &varid)) ERR;
|
||||
if (nc_put_att_float(ncid, NC_GLOBAL, ATT1_NAME, NC_FLOAT, 1, &float_out)) ERR;
|
||||
if (nc_put_att_int(ncid, NC_GLOBAL, ATT2_NAME, NC_INT, 1, &int_out)) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
/* Reopen the file and check it. */
|
||||
if (nc_open(FILE_NAME, 0, &ncid)) ERR;
|
||||
if (nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid)) ERR;
|
||||
if (ndims != 2 || nvars != 2 || natts != 2 || unlimdimid != -1) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
/* Reopen it and check each dim, var, and att. */
|
||||
if (nc_open(FILE_NAME, 0, &ncid)) ERR;
|
||||
if (nc_inq_dim(ncid, 0, dim_name, &dim_len)) ERR;
|
||||
if (dim_len != DIM1_LEN || strcmp(dim_name, DIM1_NAME)) ERR;
|
||||
if (nc_inq_dim(ncid, 1, dim_name, &dim_len)) ERR;
|
||||
if (dim_len != DIM2_LEN || strcmp(dim_name, DIM2_NAME)) ERR;
|
||||
if (nc_inq_var(ncid, 0, var_name, &var_type, &ndims, dimids_var, &natts)) ERR;
|
||||
if (ndims != 2 || strcmp(var_name, VAR1_NAME) || var_type != NC_INT ||
|
||||
dimids_var[0] != dimids[0] || natts != 0) ERR;
|
||||
if (nc_inq_var(ncid, 1, var_name, &var_type, &ndims, dimids_var, &natts)) ERR;
|
||||
if (ndims != 2 || strcmp(var_name, VAR2_NAME) || var_type != NC_UINT ||
|
||||
dimids_var[1] != dimids[1] || natts != 0) ERR;
|
||||
if (nc_get_att_float(ncid, NC_GLOBAL, ATT1_NAME, &float_in)) ERR;
|
||||
if (float_in != float_out) ERR;
|
||||
if (nc_get_att_int(ncid, NC_GLOBAL, ATT2_NAME, &int_in)) ERR;
|
||||
if (int_in != int_out) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
}
|
||||
SUMMARIZE_ERR;
|
||||
|
||||
printf("*** testing redef for netCDF classic...");
|
||||
test_redef(NC_FORMAT_CLASSIC);
|
||||
SUMMARIZE_ERR;
|
||||
printf("*** testing redef for netCDF 64-bit offset...");
|
||||
test_redef(NC_FORMAT_64BIT);
|
||||
SUMMARIZE_ERR;
|
||||
printf("*** testing redef for netCDF-4 ...");
|
||||
test_redef(NC_FORMAT_NETCDF4);
|
||||
SUMMARIZE_ERR;
|
||||
printf("*** testing redef for netCDF-4, with strict netCDF-3 rules...");
|
||||
test_redef(NC_FORMAT_NETCDF4_CLASSIC);
|
||||
SUMMARIZE_ERR;
|
||||
printf("*** testing different formats...");
|
||||
{
|
||||
int ncid;
|
||||
int format;
|
||||
|
||||
/* Create a netcdf-3 file. */
|
||||
if (nc_create(FILE_NAME, NC_CLOBBER, &ncid)) ERR;
|
||||
if (nc_inq_format(ncid, &format)) ERR;
|
||||
if (format != NC_FORMAT_CLASSIC) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
/* Create a netcdf-3 64-bit offset file. */
|
||||
if (nc_create(FILE_NAME, NC_64BIT_OFFSET|NC_CLOBBER, &ncid)) ERR;
|
||||
if (nc_inq_format(ncid, &format)) ERR;
|
||||
if (format != NC_FORMAT_64BIT) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
/* Create a netcdf-4 file. */
|
||||
if (nc_create(FILE_NAME, NC_NETCDF4|NC_CLOBBER, &ncid)) ERR;
|
||||
if (nc_inq_format(ncid, &format)) ERR;
|
||||
if (format != NC_FORMAT_NETCDF4) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
}
|
||||
SUMMARIZE_ERR;
|
||||
printf("*** testing CLASSIC_MODEL flag with classic formats...");
|
||||
{
|
||||
int ncid;
|
||||
int format;
|
||||
|
||||
/* Create a netcdf-3 file. */
|
||||
if (nc_create(FILE_NAME, NC_CLOBBER|NC_CLASSIC_MODEL, &ncid)) ERR;
|
||||
if (nc_inq_format(ncid, &format)) ERR;
|
||||
if (format != NC_FORMAT_CLASSIC) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
/* Create a netcdf-3 64-bit offset file. */
|
||||
if (nc_create(FILE_NAME, NC_64BIT_OFFSET|NC_CLOBBER|NC_CLASSIC_MODEL, &ncid)) ERR;
|
||||
if (nc_inq_format(ncid, &format)) ERR;
|
||||
if (format != NC_FORMAT_64BIT) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
}
|
||||
SUMMARIZE_ERR;
|
||||
printf("*** testing multiple open files...");
|
||||
{
|
||||
#define VAR_NAME "Captain_Kirk"
|
||||
#define NDIMS 1
|
||||
#define NUM_FILES 30
|
||||
#define TEXT_LEN 15
|
||||
#define D1_NAME "tl"
|
||||
int ncid[NUM_FILES], varid;
|
||||
int dimid;
|
||||
size_t count[NDIMS], index[NDIMS] = {0};
|
||||
const char ttext[TEXT_LEN + 1] = "20051224.150000";
|
||||
char ttext_in[TEXT_LEN + 1];
|
||||
char file_name[NC_MAX_NAME + 1];
|
||||
size_t chunks[NDIMS] = {TEXT_LEN + 1};
|
||||
int f;
|
||||
|
||||
/* Create a bunch of files. */
|
||||
for (f = 0; f < NUM_FILES; f++)
|
||||
{
|
||||
sprintf(file_name, "tst_files2_%d.nc", f);
|
||||
if (nc_create(file_name, NC_NETCDF4, &ncid[f])) ERR;
|
||||
if (nc_def_dim(ncid[f], D1_NAME, TEXT_LEN + 1, &dimid)) ERR;
|
||||
if (nc_def_var(ncid[f], VAR_NAME, NC_CHAR, NDIMS, &dimid, &varid)) ERR;
|
||||
if (f % 2 == 0)
|
||||
if (nc_def_var_chunking(ncid[f], varid, 0, chunks)) ERR;
|
||||
|
||||
/* Write one time to the coordinate variable. */
|
||||
count[0] = TEXT_LEN + 1;
|
||||
if (nc_put_vara_text(ncid[f], varid, index, count, ttext)) ERR;
|
||||
}
|
||||
|
||||
/* Read something from each file. */
|
||||
for (f = 0; f < NUM_FILES; f++)
|
||||
{
|
||||
if (nc_get_vara_text(ncid[f], varid, index, count, (char *)ttext_in)) ERR;
|
||||
if (strcmp(ttext_in, ttext)) ERR;
|
||||
}
|
||||
|
||||
/* Close all open files. */
|
||||
for (f = 0; f < NUM_FILES; f++)
|
||||
if (nc_close(ncid[f])) ERR;
|
||||
}
|
||||
SUMMARIZE_ERR;
|
||||
FINAL_RESULTS;
|
||||
}
|
||||
#define REDEF_ATT1_NAME "CANTERBURY"
|
||||
#define REDEF_ATT2_NAME "ELY"
|
||||
#define REDEF_ATT3_NAME "KING_HENRY_V"
|
||||
#define REDEF_DIM1_NAME "performance_length"
|
||||
#define REDEF_DIM1_LEN 101
|
||||
/* Change illegal name from '?' to '/'; the latter will
|
||||
more likely be illegal even when the switch is made to
|
||||
escaped characters in identifiers.
|
||||
*/
|
||||
#define REDEF_NAME_ILLEGAL "/"
|
||||
#define REDEF_DIM2_NAME "ZZ_number_of_performers_or_perhaps_actors_or_maybe_I_should_say_players_or_one_could_call_them_artists_but_one_doesnt_like_to_get"
|
||||
|
||||
#define REDEF_DIM2_LEN 999
|
||||
#define REDEF_VAR1_NAME "Royal_Shakespeare_Company_season_of_2004"
|
||||
#define REDEF_VAR2_NAME "Ms_Beths_Kindergardern_class_of_2003"
|
||||
#define REDEF_VAR3_NAME "Costumed_Mice_in_my_Garage_in_the_Winter_of_my_Discontent"
|
||||
#define REDEF_NDIMS 2
|
||||
|
||||
#define NEW_CACHE_SIZE 32000000
|
||||
#define NEW_CACHE_NELEMS 2000
|
||||
#define NEW_CACHE_PREEMPTION .75
|
||||
|
||||
int
|
||||
test_redef(int format)
|
||||
{
|
||||
int ncid, varid, dimids[REDEF_NDIMS], dimids_in[REDEF_NDIMS];
|
||||
int ndims, nvars, natts, unlimdimid;
|
||||
int dimids_var[REDEF_NDIMS], var_type;
|
||||
int cflags = 0;
|
||||
size_t dim_len;
|
||||
char dim_name[NC_MAX_NAME+1], var_name[NC_MAX_NAME+1];
|
||||
float float_in;
|
||||
double double_out = 99E99;
|
||||
int int_in;
|
||||
unsigned char uchar_in, uchar_out = 255;
|
||||
short short_out = -999;
|
||||
nc_type xtype_in;
|
||||
size_t cache_size_in, cache_nelems_in;
|
||||
float cache_preemption_in;
|
||||
int ret;
|
||||
|
||||
if (format == NC_FORMAT_64BIT)
|
||||
cflags |= NC_64BIT_OFFSET;
|
||||
else if (format == NC_FORMAT_NETCDF4_CLASSIC)
|
||||
cflags |= (NC_NETCDF4|NC_CLASSIC_MODEL);
|
||||
else if (format == NC_FORMAT_NETCDF4)
|
||||
cflags |= NC_NETCDF4;
|
||||
|
||||
/* Change chunk cache. */
|
||||
if (nc_set_chunk_cache(NEW_CACHE_SIZE, NEW_CACHE_NELEMS,
|
||||
NEW_CACHE_PREEMPTION)) ERR;
|
||||
|
||||
/* Create a file with two dims, two vars, and two atts. */
|
||||
if (nc_create(FILE_NAME, cflags|NC_CLOBBER, &ncid)) ERR;
|
||||
|
||||
/* Retrieve the chunk cache settings, just for fun. */
|
||||
if (nc_get_chunk_cache(&cache_size_in, &cache_nelems_in,
|
||||
&cache_preemption_in)) ERR;
|
||||
if (cache_size_in != NEW_CACHE_SIZE || cache_nelems_in != NEW_CACHE_NELEMS ||
|
||||
cache_preemption_in != NEW_CACHE_PREEMPTION) ERR;
|
||||
|
||||
/* This will fail, except for netcdf-4/hdf5, which permits any
|
||||
* name. */
|
||||
if (format != NC_FORMAT_NETCDF4)
|
||||
if ((ret = nc_def_dim(ncid, REDEF_NAME_ILLEGAL, REDEF_DIM2_LEN,
|
||||
&dimids[1])) != NC_EBADNAME) ERR;
|
||||
|
||||
if (nc_def_dim(ncid, REDEF_DIM1_NAME, REDEF_DIM1_LEN, &dimids[0])) ERR;
|
||||
if (nc_def_dim(ncid, REDEF_DIM2_NAME, REDEF_DIM2_LEN, &dimids[1])) ERR;
|
||||
if (nc_def_var(ncid, REDEF_VAR1_NAME, NC_INT, REDEF_NDIMS, dimids, &varid)) ERR;
|
||||
if (nc_def_var(ncid, REDEF_VAR2_NAME, NC_BYTE, REDEF_NDIMS, dimids, &varid)) ERR;
|
||||
if (nc_put_att_double(ncid, NC_GLOBAL, REDEF_ATT1_NAME, NC_DOUBLE, 1, &double_out)) ERR;
|
||||
if (nc_put_att_short(ncid, NC_GLOBAL, REDEF_ATT2_NAME, NC_SHORT, 1, &short_out)) ERR;
|
||||
|
||||
/* Check it out. */
|
||||
if (nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid)) ERR;
|
||||
if (ndims != REDEF_NDIMS || nvars != 2 || natts != 2 || unlimdimid != -1) ERR;
|
||||
if (nc_inq_var(ncid, 0, var_name, &xtype_in, &ndims, dimids_in, &natts)) ERR;
|
||||
if (strcmp(var_name, REDEF_VAR1_NAME) || xtype_in != NC_INT || ndims != REDEF_NDIMS ||
|
||||
dimids_in[0] != dimids[0] || dimids_in[1] != dimids[1]) ERR;
|
||||
if (nc_inq_var(ncid, 1, var_name, &xtype_in, &ndims, dimids_in, &natts)) ERR;
|
||||
if (strcmp(var_name, REDEF_VAR2_NAME) || xtype_in != NC_BYTE || ndims != REDEF_NDIMS ||
|
||||
dimids_in[0] != dimids[0] || dimids_in[1] != dimids[1]) ERR;
|
||||
|
||||
/* Close it up. */
|
||||
if (format != NC_FORMAT_NETCDF4)
|
||||
if (nc_enddef(ncid)) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
/* Reopen as read only - make sure it doesn't let us change file. */
|
||||
if (nc_open(FILE_NAME, 0, &ncid)) ERR;
|
||||
if (nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid)) ERR;
|
||||
if (ndims != REDEF_NDIMS || nvars != 2 || natts != 2 || unlimdimid != -1) ERR;
|
||||
if (nc_inq_var(ncid, 0, var_name, &xtype_in, &ndims, dimids_in, &natts)) ERR;
|
||||
if (strcmp(var_name, REDEF_VAR1_NAME) || xtype_in != NC_INT || ndims != REDEF_NDIMS ||
|
||||
dimids_in[0] != dimids[0] || dimids_in[1] != dimids[1]) ERR;
|
||||
if (nc_inq_var(ncid, 1, var_name, &xtype_in, &ndims, dimids_in, &natts)) ERR;
|
||||
if (strcmp(var_name, REDEF_VAR2_NAME) || xtype_in != NC_BYTE || ndims != REDEF_NDIMS ||
|
||||
dimids_in[0] != dimids[0] || dimids_in[1] != dimids[1]) ERR;
|
||||
|
||||
/* This will fail. */
|
||||
ret = nc_def_var(ncid, REDEF_VAR3_NAME, NC_UBYTE, REDEF_NDIMS,
|
||||
dimids, &varid);
|
||||
if(format == NC_FORMAT_NETCDF4) {
|
||||
if(ret != NC_EPERM) {
|
||||
ERR;
|
||||
}
|
||||
} else {
|
||||
if(ret != NC_ENOTINDEFINE) {
|
||||
ERR;
|
||||
}
|
||||
}
|
||||
/* This will fail. */
|
||||
if (!nc_put_att_uchar(ncid, NC_GLOBAL, REDEF_ATT3_NAME, NC_CHAR, 1, &uchar_out)) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
/* Make sure we can't redef a file opened for NOWRITE. */
|
||||
if (nc_open(FILE_NAME, NC_NOWRITE, &ncid)) ERR;
|
||||
if (nc_redef(ncid) != NC_EPERM) ERR;
|
||||
|
||||
/* Check it out again. */
|
||||
if (nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid)) ERR;
|
||||
if (ndims != REDEF_NDIMS || nvars != 2 || natts != 2 || unlimdimid != -1) ERR;
|
||||
if (nc_inq_var(ncid, 0, var_name, &xtype_in, &ndims, dimids_in, &natts)) ERR;
|
||||
if (strcmp(var_name, REDEF_VAR1_NAME) || xtype_in != NC_INT || ndims != REDEF_NDIMS ||
|
||||
dimids_in[0] != dimids[0] || dimids_in[1] != dimids[1]) ERR;
|
||||
if (nc_inq_var(ncid, 1, var_name, &xtype_in, &ndims, dimids_in, &natts)) ERR;
|
||||
if (strcmp(var_name, REDEF_VAR2_NAME) || xtype_in != NC_BYTE || ndims != REDEF_NDIMS ||
|
||||
dimids_in[0] != dimids[0] || dimids_in[1] != dimids[1]) ERR;
|
||||
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
/* Reopen the file and check it, add a variable and attribute. */
|
||||
if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR;
|
||||
|
||||
/* Check it out. */
|
||||
if (nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid)) ERR;
|
||||
if (ndims != REDEF_NDIMS || nvars != 2 || natts != 2 || unlimdimid != -1) ERR;
|
||||
|
||||
/* Add var. */
|
||||
if ((format != NC_FORMAT_NETCDF4) && nc_redef(ncid)) ERR;
|
||||
if (nc_def_var(ncid, REDEF_VAR3_NAME, NC_BYTE, REDEF_NDIMS, dimids, &varid)) ERR;
|
||||
|
||||
/* Add att. */
|
||||
ret = nc_put_att_uchar(ncid, NC_GLOBAL, REDEF_ATT3_NAME, NC_BYTE, 1, &uchar_out);
|
||||
if (format != NC_FORMAT_NETCDF4 && ret) ERR;
|
||||
else if (format == NC_FORMAT_NETCDF4 && ret != NC_ERANGE) ERR;
|
||||
|
||||
/* Check it out. */
|
||||
if (nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid)) ERR;
|
||||
if (ndims != REDEF_NDIMS || nvars != 3 || natts != 3 || unlimdimid != -1) ERR;
|
||||
if (nc_inq_var(ncid, 0, var_name, &xtype_in, &ndims, dimids_in, &natts)) ERR;
|
||||
if (strcmp(var_name, REDEF_VAR1_NAME) || xtype_in != NC_INT || ndims != REDEF_NDIMS ||
|
||||
dimids_in[0] != dimids[0] || dimids_in[1] != dimids[1]) ERR;
|
||||
if (nc_inq_var(ncid, 1, var_name, &xtype_in, &ndims, dimids_in, &natts)) ERR;
|
||||
if (strcmp(var_name, REDEF_VAR2_NAME) || xtype_in != NC_BYTE || ndims != REDEF_NDIMS ||
|
||||
dimids_in[0] != dimids[0] || dimids_in[1] != dimids[1]) ERR;
|
||||
if (nc_inq_var(ncid, 2, var_name, &var_type, &ndims, dimids_var, &natts)) ERR;
|
||||
if (ndims != REDEF_NDIMS || strcmp(var_name, REDEF_VAR3_NAME) || var_type != NC_BYTE ||
|
||||
natts != 0) ERR;
|
||||
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
/* Reopen it and check each dim, var, and att. */
|
||||
if (nc_open(FILE_NAME, 0, &ncid)) ERR;
|
||||
if (nc_inq_dim(ncid, 0, dim_name, &dim_len)) ERR;
|
||||
if (dim_len != REDEF_DIM1_LEN || strcmp(dim_name, REDEF_DIM1_NAME)) ERR;
|
||||
if (nc_inq_dim(ncid, 1, dim_name, &dim_len)) ERR;
|
||||
if (dim_len != REDEF_DIM2_LEN || strcmp(dim_name, REDEF_DIM2_NAME)) ERR;
|
||||
if (nc_inq_var(ncid, 0, var_name, &var_type, &ndims, dimids_var, &natts)) ERR;
|
||||
if (ndims != REDEF_NDIMS || strcmp(var_name, REDEF_VAR1_NAME) || var_type != NC_INT ||
|
||||
natts != 0) ERR;
|
||||
if (nc_inq_var(ncid, 1, var_name, &var_type, &ndims, dimids_var, &natts)) ERR;
|
||||
if (ndims != REDEF_NDIMS || strcmp(var_name, REDEF_VAR2_NAME) || var_type != NC_BYTE ||
|
||||
natts != 0) ERR;
|
||||
if (nc_inq_var(ncid, 2, var_name, &var_type, &ndims, dimids_var, &natts)) ERR;
|
||||
if (ndims != REDEF_NDIMS || strcmp(var_name, REDEF_VAR3_NAME) || var_type != NC_BYTE ||
|
||||
natts != 0) ERR;
|
||||
if (nc_get_att_float(ncid, NC_GLOBAL, REDEF_ATT1_NAME, &float_in) != NC_ERANGE) ERR;
|
||||
if (nc_get_att_int(ncid, NC_GLOBAL, REDEF_ATT2_NAME, &int_in)) ERR;
|
||||
if (int_in != short_out) ERR;
|
||||
ret = nc_get_att_uchar(ncid, NC_GLOBAL, REDEF_ATT3_NAME, &uchar_in);
|
||||
if (format == NC_FORMAT_NETCDF4)
|
||||
{
|
||||
if (ret != NC_ERANGE) ERR;
|
||||
}
|
||||
else if (ret) ERR;
|
||||
|
||||
if (uchar_in != uchar_out) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
return NC_NOERR;
|
||||
}
|
||||
|
||||
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user