diff --git a/libsrc/nc3internal.c b/libsrc/nc3internal.c index db056125f..123274b09 100644 --- a/libsrc/nc3internal.c +++ b/libsrc/nc3internal.c @@ -1621,14 +1621,12 @@ NC3_inq_format(int ncid, int *formatp) * associated with an open file. * * \param ncid the ID of the open file. - * \param formatp a pointer that gets the extended format. Note that * this is not the same as the format provided by nc_inq_format(). The * extended foramt indicates the dispatch layer model. Classic, 64-bit * offset, and CDF5 files all have an extended format of * ::NC_FORMATX_NC3. Ignored if NULL. - * - * \modep a pointer that gets the open/create mode associated with + * \param modep a pointer that gets the open/create mode associated with * this file. Ignored if NULL. * * \returns NC_NOERR No error. diff --git a/libsrc4/ncfunc.c b/libsrc4/ncfunc.c index 8cc1d5704..0f7cd4c0f 100644 --- a/libsrc4/ncfunc.c +++ b/libsrc4/ncfunc.c @@ -1,15 +1,15 @@ /* -Copyright 2003, University Corporation for Atmospheric Research. See -netcdf-4/docs/COPYRIGHT file for copying and redistribution -conditions. + Copyright 2003, University Corporation for Atmospheric Research. See + netcdf-4/docs/COPYRIGHT file for copying and redistribution + conditions. -This file is part of netcdf-4, a netCDF-like interface for HDF5, or a -HDF5 backend for netCDF, depending on your point of view. + This file is part of netcdf-4, a netCDF-like interface for HDF5, or a + HDF5 backend for netCDF, depending on your point of view. -This file handles the (useless) *_base_pe() functions, and the -inq_format functions. + This file handles the (useless) *_base_pe() functions, and the + inq_format functions. -@author Ed Hartnett, Dennis Heimbigner + @author Ed Hartnett, Dennis Heimbigner */ @@ -17,30 +17,50 @@ inq_format functions. #include "nc4dispatch.h" /** - * This function only does anything for netcdf-3 files. - * + * This function only does anything for netcdf-3 files. + * * \param ncid File ID (ignored). * \param pe Processor element (ignored). * - * \returns NC_ENOTNC3 - Not a netCDF classic format file. + * \returns ::NC_ENOTNC3 Not a netCDF classic format file. * \internal * \author Ed Hartnett -*/ + */ int NC4_set_base_pe(int ncid, int pe) { - return NC_ENOTNC3; + return NC_ENOTNC3; } -/* This function only does anything for netcdf-3 files. */ +/** + * This function only does anything for netcdf-3 files. + * + * \param ncid File ID (ignored). + * \param pe Pointer to processor element. Ignored if NULL. Gets a 0 + * if present. + * + * \returns ::NC_ENOTNC3 Not a netCDF classic format file. + * \internal + * \author Ed Hartnett + */ int NC4_inq_base_pe(int ncid, int *pe) { return NC_ENOTNC3; } -/* Get the format (i.e. classic, 64-bit-offset, or netcdf-4) of an - * open file. */ +/** + * Get the format (i.e. NC_FORMAT_NETCDF4 pr + * NC_FORMAT_NETCDF4_CLASSIC) of an open netCDF-4 file. + * + * \param ncid File ID (ignored). + * \param formatp Pointer that gets the constant indicating format. + + * \returns ::NC_NOERR No error. + * \returns ::NC_EBADID Bad ncid. + * \internal + * \author Ed Hartnett + */ int NC4_inq_format(int ncid, int *formatp) { @@ -66,7 +86,24 @@ NC4_inq_format(int ncid, int *formatp) return NC_NOERR; } -/* Get the extended format of an open file. */ +/** + * Return the extended format (i.e. the dispatch model), plus the mode + * associated with an open file. + * + * \param ncid File ID (ignored). + * \param formatp a pointer that gets the extended format. Note that + * this is not the same as the format provided by nc_inq_format(). The + * extended foramt indicates the dispatch layer model. NetCDF-4 files + * will always get NC_FORMATX_NC4 for netCDF files, NC_FORMATX_HDF4 + * for HDF4 files. + * \param modep a pointer that gets the open/create mode associated with + * this file. Ignored if NULL. + + * \returns ::NC_NOERR No error. + * \returns ::NC_EBADID Bad ncid. + * \internal + * \author Dennis Heimbigner + */ int NC4_inq_format_extended(int ncid, int *formatp, int *modep) { @@ -83,10 +120,10 @@ NC4_inq_format_extended(int ncid, int *formatp, int *modep) if(formatp) { #ifdef USE_HDF4 - /* Distinguish HDF5 from HDF4 */ - *formatp = (h5->hdf4 ? NC_FORMATX_NC_HDF4 : NC_FORMATX_NC_HDF5); + /* Distinguish HDF5 from HDF4 */ + *formatp = (h5->hdf4 ? NC_FORMATX_NC_HDF4 : NC_FORMATX_NC_HDF5); #else /* USE_HDF4 */ - *formatp = NC_FORMATX_NC_HDF5; + *formatp = NC_FORMATX_NC_HDF5; #endif /* USE_HDF4 */ } return NC_NOERR; diff --git a/nc_test/Makefile.am b/nc_test/Makefile.am index dd1494897..6163cca55 100644 --- a/nc_test/Makefile.am +++ b/nc_test/Makefile.am @@ -92,10 +92,10 @@ endif # USE_VALGRIND_TESTS # Distribute the .c files so that m4 isn't required on the users # machine. -EXTRA_DIST = test_get.m4 test_put.m4 run_valgrind_tests.sh \ -run_diskless.sh run_diskless2.sh run_diskless5.sh run_mmap.sh \ -run_pnetcdf_test.sh test_read.m4 test_write.m4 ref_tst_diskless2.cdl \ -tst_diskless5.cdl CMakeLists.txt +EXTRA_DIST = test_get.m4 test_put.m4 run_valgrind_tests.sh \ +run_diskless.sh run_diskless2.sh run_diskless5.sh run_mmap.sh \ +run_pnetcdf_test.sh test_read.m4 test_write.m4 ref_tst_diskless2.cdl \ +tst_diskless5.cdl CMakeLists.txt ref_contiguous.hdf4 # These files are created by the tests. CLEANFILES = nc_test_classic.nc nc_test_64bit.nc nc_test_netcdf4.nc \ diff --git a/nc_test/ref_contiguous.hdf4 b/nc_test/ref_contiguous.hdf4 new file mode 100644 index 000000000..487dd6155 Binary files /dev/null and b/nc_test/ref_contiguous.hdf4 differ diff --git a/nc_test/tst_formats.c b/nc_test/tst_formats.c index 43ee3a0d1..924cdcf47 100644 --- a/nc_test/tst_formats.c +++ b/nc_test/tst_formats.c @@ -12,6 +12,7 @@ #include "err_macros.h" #define FILE_NAME_BASE "tst_formats" +#define HDF4_FILE "ref_contiguous.hdf4" /* Determine how many formats are available, and what they are. */ void @@ -55,7 +56,10 @@ check_inq_format(int ncid, int expected_format, int expected_extended_format, in if (nc_inq_format(ncid + 66000, NULL) != NC_EBADID) ERR; if (nc_inq_format(ncid, NULL)) ERR; if (nc_inq_format(ncid, &format)) ERR; - if (format != expected_format) ERR; + if (format != expected_format) { + printf("format %d expected_format %d\n", format, expected_format); + ERR; + } if (nc_inq_format_extended(ncid + 66000, &extended_format, &mode) != NC_EBADID) ERR; { int mode; @@ -92,19 +96,18 @@ check_inq_format(int ncid, int expected_format, int expected_extended_format, in int main(int argc, char **argv) { - int format[MAX_NUM_FORMATS]; - int num_formats; - char file_name[NC_MAX_NAME + 1]; - int f; - - /* How many formats to be tested? */ - determine_test_formats(&num_formats, format); - printf("\n*** Testing netcdf format functions.\n"); { int ncid; int expected_mode; int expected_extended_format; + char file_name[NC_MAX_NAME + 1]; + int f; + int format[MAX_NUM_FORMATS]; + int num_formats; + + /* How many formats to be tested? */ + determine_test_formats(&num_formats, format); for (f = 0; f < num_formats; f++) { @@ -136,7 +139,7 @@ main(int argc, char **argv) } if (nc_set_default_format(format[f], NULL)) ERR; - /* Create a file with some global atts. */ + /* Create a file. */ if (nc_create(file_name, 0, &ncid)) ERR; if (check_inq_format(ncid, format[f], expected_extended_format, expected_mode)) ERR; if (nc_close(ncid)) ERR; @@ -152,5 +155,25 @@ main(int argc, char **argv) SUMMARIZE_ERR; } /* next format */ } +#ifdef USE_HDF4 + printf("\n*** Testing netcdf format functions for HDF4.\n"); + { + int ncid; + int expected_mode; + int expected_extended_format; + + printf("*** testing nc_inq_format() and nc_inq_format_extended() with HDF4..."); + + /* Set up test. */ + expected_extended_format = NC_FORMATX_NC_HDF4; + expected_mode = NC_NETCDF4; + + /* Open a HDF4 file and check it. */ + if (nc_open(HDF4_FILE, 0, &ncid)) ERR; + if (check_inq_format(ncid, NC_FORMAT_NETCDF4, expected_extended_format, expected_mode)) ERR; + if (nc_close(ncid)) ERR; + } + SUMMARIZE_ERR; +#endif /* USE_HDF4 */ FINAL_RESULTS; }