diff --git a/CMakeLists.txt b/CMakeLists.txt index 8d1a327cc..791b9d6ea 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1032,56 +1032,87 @@ IF(ENABLE_PNETCDF) ENDIF() # Options to enable use of fill values for elements causing NC_ERANGE -SET(STATUS_ERANGE_FILL "OFF") -OPTION(ENABLE_ERANGE_FILL "Enable use of fill value when out-of-range type conversion causes NC_ERANGE error." OF) -IF(ENABLE_ERANGE_FILL) - SET(STATUS_ERANGE_FILL "ON") - ADD_DEFINITIONS(-DERANGE_FILL) -ENDIF() +SET(ENABLE_ERANGE_FILL AUTO CACHE STRING "AUTO") +OPTION(ENABLE_ERANGE_FILL "Enable use of fill value when out-of-range type conversion causes NC_ERANGE error." OFF) +IF(ENABLE_ERANGE_FILL) # enable or auto + STRING(TOUPPER ${ENABLE_ERANGE_FILL} ENABLE_ERANGE_FILL) + IF(ENABLE_ERANGE_FILL AND NOT ENABLE_ERANGE_FILL STREQUAL "AUTO") + # explicitly enabled + SET(ENABLE_ERANGE_FILL ON) + ELSE() + IF(NOT ENABLE_ERANGE_FILL STREQUAL "AUTO") + SET(ENABLE_ERANGE_FILL OFF) + ENDIF() + ENDIF() +ENDIF(ENABLE_ERANGE_FILL) +# Now ENABLE_ERANGE_FILL is either AUTO, ON, or OFF # Options to use a more relaxed coordinate argument boundary check -SET(STATUS_RELAX_COORD_BOUND "OFF") +SET(ENABLE_ZERO_LENGTH_COORD_BOUND AUTO CACHE STRING "AUTO") OPTION(ENABLE_ZERO_LENGTH_COORD_BOUND "Enable a more relaxed boundary error check NC_EINVALCOORDS to allow coordinate start argument equal to dimension size when argument count is zero." OFF) -IF(ENABLE_ZERO_LENGTH_COORD_BOUND) - SET(STATUS_RELAX_COORD_BOUND "ON") -ENDIF() +IF(ENABLE_ZERO_LENGTH_COORD_BOUND) # enable or auto + STRING(TOUPPER ${ENABLE_ZERO_LENGTH_COORD_BOUND} ENABLE_ZERO_LENGTH_COORD_BOUND) + IF(ENABLE_ZERO_LENGTH_COORD_BOUND AND NOT ENABLE_ZERO_LENGTH_COORD_BOUND STREQUAL "AUTO") + # explicitly enabled + SET(ENABLE_ZERO_LENGTH_COORD_BOUND ON) + ELSE() + IF(NOT ENABLE_ZERO_LENGTH_COORD_BOUND STREQUAL "AUTO") + SET(ENABLE_ZERO_LENGTH_COORD_BOUND OFF) + ENDIF() + ENDIF() +ENDIF(ENABLE_ZERO_LENGTH_COORD_BOUND) +# Now ENABLE_ZERO_LENGTH_COORD_BOUND is either AUTO, ON, or OFF # check and conform with PnetCDF settings on ERANGE_FILL and RELAX_COORD_BOUND IF(STATUS_PNETCDF) file(STRINGS "${pnetcdf_h}" enable_erange_fill_pnetcdf REGEX "^#define PNETCDF_ERANGE_FILL") string(REGEX REPLACE "[^0-9]" "" erange_fill_pnetcdf "${enable_erange_fill_pnetcdf}") IF("x${erange_fill_pnetcdf}" STREQUAL "x1") - IF(NOT STATUS_ERANGE_FILL) - MESSAGE(WARNING "Enable erange-fill to conform with PnetCDF setting") - SET(STATUS_ERANGE_FILL "ON") - ENDIF() + SET(erange_fill_pnetcdf "ON") ELSE() - IF(STATUS_ERANGE_FILL) - MESSAGE(WARNING "Disable erange-fill to conform with PnetCDF setting") - SET(STATUS_ERANGE_FILL "OFF") + SET(erange_fill_pnetcdf "OFF") + ENDIF() + IF(ENABLE_ERANGE_FILL STREQUAL "AUTO") # not set on command line + SET(ENABLE_ERANGE_FILL "${erange_fill_pnetcdf}") + ELSE() + # user explicitly set this option on command line + IF(NOT ENABLE_ERANGE_FILL STREQUAL "${erange_fill_pnetcdf}") + IF(ENABLE_ERANGE_FILL) + MESSAGE(FATAL_ERROR "Enabling erange-fill conflicts with PnetCDF setting") + ELSE() + MESSAGE(FATAL_ERROR "Disabling erange-fill conflicts with PnetCDF setting") + ENDIF() ENDIF() ENDIF() + file(STRINGS "${pnetcdf_h}" relax_coord_bound_pnetcdf REGEX "^#define PNETCDF_RELAX_COORD_BOUND") string(REGEX REPLACE "[^0-9]" "" relax_coord_bound "${relax_coord_bound_pnetcdf}") IF("x${relax_coord_bound}" STREQUAL "x1") - IF(NOT STATUS_RELAX_COORD_BOUND) - MESSAGE(WARNING "Enable relax-coord-bound to conform with PnetCDF setting") - SET(STATUS_RELAX_COORD_BOUND "ON") - ENDIF() + SET(relax_coord_bound_pnetcdf "ON") ELSE() - IF(STATUS_RELAX_COORD_BOUND) - MESSAGE(WARNING "Disable relax-coord-bound to conform with PnetCDF setting") - SET(STATUS_RELAX_COORD_BOUND "OFF") + SET(relax_coord_bound_pnetcdf "OFF") + ENDIF() + IF(ENABLE_ZERO_LENGTH_COORD_BOUND STREQUAL "AUTO") # not set on command line + SET(ENABLE_ZERO_LENGTH_COORD_BOUND "${relax_coord_bound_pnetcdf}") + ELSE() + # user explicitly set this option on command line + IF(NOT ENABLE_ZERO_LENGTH_COORD_BOUND STREQUAL "${relax_coord_bound_pnetcdf}") + IF(ENABLE_ZERO_LENGTH_COORD_BOUND) + MESSAGE(FATAL_ERROR "Enabling relax-coord-bound conflicts with PnetCDF setting") + ELSE() + MESSAGE(FATAL_ERROR "Disabling relax-coord-bound conflicts with PnetCDF setting") + ENDIF() ENDIF() ENDIF() ENDIF() -IF(STATUS_ERANGE_FILL) +IF(ENABLE_ERANGE_FILL) + MESSAGE(STATUS "Enabling use of fill value when NC_ERANGE") SET(M4FLAGS "-DERANGE_FILL" CACHE STRING "") ENDIF() -IF(STATUS_RELAX_COORD_BOUND) - MESSAGE(STATUS "Enabling a more relatexed check for NC_EINVALCOORDS") +IF(ENABLE_ZERO_LENGTH_COORD_BOUND) + MESSAGE(STATUS "Enabling a more relatexed check when NC_EINVALCOORDS") ADD_DEFINITIONS(-DRELAX_COORD_BOUND) ENDIF() @@ -1887,7 +1918,7 @@ is_enabled(ENABLE_DAP4 HAS_DAP4) is_enabled(ENABLE_DISKLESS HAS_DISKLESS) is_enabled(USE_MMAP HAS_MMAP) is_enabled(JNA HAS_JNA) -is_enabled(STATUS_RELAX_COORD_BOUND RELAX_COORD_BOUND) +is_enabled(ENABLE_ZERO_LENGTH_COORD_BOUND RELAX_COORD_BOUND) is_enabled(USE_CDF5 HAS_CDF5) is_enabled(ENABLE_ERANGE_FILL HAS_ERANGE_FILL) diff --git a/configure.ac b/configure.ac index 48f88a944..76b15a223 100644 --- a/configure.ac +++ b/configure.ac @@ -1102,21 +1102,13 @@ if test "x$enable_pnetcdf" = xyes; then # Pnetcdf did not support utf-8 until 1.6.0 - # Save/restore CFLAGS - SAVELIBS=$LIBS - LIBS="$LIBS -lpnetcdf" - AC_RUN_IFELSE([AC_LANG_PROGRAM([#include ], - [[ - int major = PNETCDF_VERSION_MAJOR; - int minor = PNETCDF_VERSION_MINOR; - int version = major*1000 + minor; - int ok = (version >= (1*1000 + 6)); - return (ok?0:1);]])], - [pnetcdf16=yes], - [pnetcdf16=no]) - CFLAGS="$SAVECFLAGS" - LIBS="$SAVELIBS" AC_MSG_CHECKING([Is libpnetcdf version 1.6.0 or later?]) + AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [[ +#include +#if (PNETCDF_VERSION_MAJOR*1000 + PNETCDF_VERSION_MINOR < 1006) + choke me +#endif + ]])], [pnetcdf16=yes], [pnetcdf16=no]) AC_MSG_RESULT([$pnetcdf16]) if test x$pnetcdf16 = xno; then AC_MSG_ERROR([--enable-pnetcdf requires version 1.6.0 or later]) @@ -1156,15 +1148,15 @@ AC_ARG_ENABLE([erange_fill], [AS_HELP_STRING([--enable-erange-fill], [Enable use of fill value when out-of-range type conversion causes NC_ERANGE error. @<:@default: disabled@:>@])], - [enable_erange_fill=${enableval}], [enable_erange_fill=no] + [enable_erange_fill=${enableval}], [enable_erange_fill=auto] ) AC_ARG_ENABLE([zero-length-coord-bound], - [AS_HELP_STRING([--enable-zero-length-coord-bound], - [Enable a more relaxed boundary error check NC_EINVALCOORDS + [AS_HELP_STRING([--disable-zero-length-coord-bound], + [Disable a more relaxed boundary error check NC_EINVALCOORDS to allow coordinate start argument equal to dimension size - when argument count is zero. @<:@default: disabled@:>@])], - [enable_zero_length_coord_bound=${enableval}], [enable_zero_length_coord_bound=no] + when argument count is zero. @<:@default: enabled@:>@])], + [enable_zero_length_coord_bound=${enableval}], [enable_zero_length_coord_bound=auto] ) # check PnetCDF's settings on enable_erange_fill and relax_coord_bound @@ -1172,48 +1164,46 @@ if test "x$enable_pnetcdf" = xyes; then UD_CHECK_HEADER_PATH([pnetcdf.h]) AC_MSG_CHECKING([if erange-fill is enabled in PnetCDF]) - erange_fill_pnetcdf=`grep PNETCDF_ERANGE_FILL ${ac_cv_header_path_pnetcdf_h}` - if test "x$erange_fill_pnetcdf" = x; then - erange_fill_pnetcdf=no - else - erange_fill_pnetcdf=`echo ${erange_fill_pnetcdf} | cut -d' ' -f3` - if test "x$erange_fill_pnetcdf" = x0; then - enable_erange_fill_pnetcdf=no - else - enable_erange_fill_pnetcdf=yes - fi - fi + AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [[ +#include +#if !defined(PNETCDF_ERANGE_FILL) || PNETCDF_ERANGE_FILL == 0 + choke me +#endif]])], [enable_erange_fill_pnetcdf=yes], [enable_erange_fill_pnetcdf=no]) AC_MSG_RESULT([$enable_erange_fill_pnetcdf]) - if test "$enable_erange_fill" != "$enable_erange_fill_pnetcdf"; then - if test "$enable_erange_fill_pnetcdf" = yes; then - AC_MSG_WARN([Enable erange-fill to conform with PnetCDF setting]) - else - AC_MSG_WARN([Disable erange-fill to conform with PnetCDF setting]) - fi + if test "x$enable_erange_fill" = xauto ; then enable_erange_fill=$enable_erange_fill_pnetcdf + elif test "$enable_erange_fill" != "$enable_erange_fill_pnetcdf"; then + if test "$enable_erange_fill" = yes; then + AC_MSG_ERROR([Enabling erange-fill conflicts with PnetCDF setting]) + else + AC_MSG_ERROR([Disabling erange-fill conflicts with PnetCDF setting]) + fi fi AC_MSG_CHECKING([if relax-coord-bound is enabled in PnetCDF]) - relax_coord_bound_pnetcdf=`grep PNETCDF_RELAX_COORD_BOUND ${ac_cv_header_path_pnetcdf_h}` - if test "x$relax_coord_bound_pnetcdf" = x; then - elax_coord_bound_pnetcdf=no - else - coord_bound_pnetcdf=`echo ${relax_coord_bound_pnetcdf} | cut -d' ' -f3` - if test "x$coord_bound_pnetcdf" = x0; then - relax_coord_bound_pnetcdf=no - else - relax_coord_bound_pnetcdf=yes - fi - fi + AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [[ +#include +#if !defined(PNETCDF_RELAX_COORD_BOUND) || PNETCDF_RELAX_COORD_BOUND == 0 + choke me +#endif]])], [relax_coord_bound_pnetcdf=yes], [relax_coord_bound_pnetcdf=no]) AC_MSG_RESULT([$relax_coord_bound_pnetcdf]) - if test "$enable_zero_length_coord_bound" != "$relax_coord_bound_pnetcdf"; then - if test "$relax_coord_bound_pnetcdf" = yes; then - AC_MSG_WARN([Enable relax-coord-bound to conform with PnetCDF setting]) - else - AC_MSG_WARN([Disable relax-coord-bound to conform with PnetCDF setting]) - fi + if test "x$enable_zero_length_coord_bound" = xauto ; then enable_zero_length_coord_bound=$relax_coord_bound_pnetcdf + elif test "$enable_zero_length_coord_bound" != "$relax_coord_bound_pnetcdf"; then + if test "$enable_zero_length_coord_bound" = yes; then + AC_MSG_ERROR([Enabling relax-coord-bound conflicts with PnetCDF setting]) + else + AC_MSG_ERROR([Disabling relax-coord-bound conflicts with PnetCDF setting]) + fi fi +else + # default setting + enable_erange_fill=no + enable_zero_length_coord_bound=yes +fi + +if test "x$enable_zero_length_coord_bound" = xyes; then + AC_DEFINE([RELAX_COORD_BOUND], [1], [if true, NC_EINVALCOORDS check is more relaxed]) fi if test "x$enable_erange_fill" = xyes ; then @@ -1226,10 +1216,6 @@ if test "x$enable_erange_fill" = xyes ; then fi AC_SUBST(M4FLAGS) -if test "x$enable_zero_length_coord_bound" = xyes; then - AC_DEFINE([RELAX_COORD_BOUND], [1], [if true, NC_EINVALCOORDS check is more relaxed]) -fi - # Check for downloading/building fortran via postinstall script. if test "x$enable_remote_fortran_bootstrap" = xyes; then AC_DEFINE([BUILD_FORTRAN], 1, [If true, will attempt to download and build netcdf-fortran.]) diff --git a/libnetcdf.settings.in b/libnetcdf.settings.in index 0384faca9..aa37ee0f7 100644 --- a/libnetcdf.settings.in +++ b/libnetcdf.settings.in @@ -36,3 +36,4 @@ MMap Support: @HAS_MMAP@ JNA Support: @HAS_JNA@ CDF5 Support: @HAS_CDF5@ ERANGE fill Support: @HAS_ERANGE_FILL@ +relaxed boundary check: @RELAX_COORD_BOUND@ diff --git a/ncdump/nccopy.c b/ncdump/nccopy.c index ec9e0d9d3..bae9930a9 100644 --- a/ncdump/nccopy.c +++ b/ncdump/nccopy.c @@ -1984,8 +1984,8 @@ usage(void) /* Don't document this flaky option until it works better */ /* [-x] use experimental computed estimates for variable-specific chunk caches\n\ */ - error("%s [-k kind] [-[3|4|6|7]] [-d n] [-s] [-c chunkspec] [-u] [-w] [-[v|V] varlist] [-[g|G] grplist] [-m n] [-h n] [-e n] [-r] infile outfile\n%s\nnetCDF library version %s", - progname, USAGE, nc_inq_libvers()); + error("[-k kind] [-[3|4|6|7]] [-d n] [-s] [-c chunkspec] [-u] [-w] [-[v|V] varlist] [-[g|G] grplist] [-m n] [-h n] [-e n] [-r] infile outfile\n%s\nnetCDF library version %s", + USAGE, nc_inq_libvers()); } int