[NCF-273]/HZY-708311

Add a new function called nc_inq_format_extended that
returns more detailed format information (vis-a-vis
nc_inq_format) about an open dataset.

Note that the netcdf API will present the file as if it had
the format specified by nc_inq_format.  The true file
format, however, may not even be a netcdf file; it might be
DAP, HDF4, or PNETCDF, for example. This function returns
that true file type.  It also returns the effective mode for
the file.

signature: nc_inq_format_extended(int ncid, int* formatp, int* modep)
where
* ncid is the NetCDF ID from a previous call to nc_open() or
  nc_create().
* formatp is a pointer to a location for returned true format.
* modep is a pointer to a location for returned mode flags.

Refer to the actual list in the file netcdf.h to see the
currently defined set.

Also added test cases (tst_formatx*).
This commit is contained in:
dmh 2013-12-22 12:53:20 -07:00
parent 965150f4f0
commit 582410a407
38 changed files with 2927 additions and 2752 deletions

View File

@ -4,6 +4,10 @@ This file contains a high-level description of this package's evolution. Release
## 4.3.1 Released TBD
* Add an extended format inquiry method to the netcdf API: nc_inq_format_extended. [NCF-273]
[NCF-273]:https://bugtracking.unidata.ucar.edu/browse/NCF-273
### 4.3.1-rc6 Released 2013-12-19
* Fixed fill value handling for string types in nc4\_get\_vara().

33
cf
View File

@ -8,15 +8,16 @@ fi
HDF5=1
DAP=1
HDF4=1
#PNETCDF=1
#HDF4=1
#RPC=1
#PGI=1
#M32=1
#M64=1
#INSTALL=1
#PREFIX=/usr/local
PREFIX=/usr/local
if test "x$cmds" = x ; then
cmds=""
@ -113,10 +114,9 @@ LDFLAGS="-L${stddir}/lib -lhdf5_hl -lhdf5 -lz $LDFLAGS"
LD_LIBRARY_PATH="${stddir}/lib:$LD_LIBRARY_PATH"
fi
#if test "x$HDF4" = "x1" ; then
#CPPFLAGS="-I/machine/local/include $CPPFLAGS"
#LDFLAGS="-L/machine/local/lib $LDFLAGS"
#fi
if test "x$HDF4" = "x1" ; then
LDFLAGS="$LDFLAGS -ljpeg"
fi
if test "x$DAP" = "x1" -o "x$CDMR" = "x1" -o "x$RPC" = "x1" ; then
if curl-config --version >/dev/null ; then
@ -149,12 +149,12 @@ FLAGS="$FLAGS --disable-examples"
#FLAGS="$FLAGS --enable-dap-long-tests"
#FLAGS="$FLAGS --enable-ffio"
#FLAGS="$FLAGS --enable-benchmarks"
FLAGS="$FLAGS --enable-extra-tests"
#FLAGS="$FLAGS --enable-extra-tests"
#FLAGS="$FLAGS --enable-large-file-tests"
#FLAGS="$FLAGS --disable-testsets"
#FLAGS="$FLAGS --disable-dap-remote-tests"
#FLAGS="$FLAGS --enable-doxygen"
FLAGS="$FLAGS --enable-logging"
#FLAGS="$FLAGS --enable-logging"
#FLAGS="$FLAGS --disable-diskless"
#FLAGS="$FLAGS --enable-mmap"
#FLAGS="$FLAGS --with-udunits"
@ -182,10 +182,19 @@ FLAGS="$FLAGS --enable-rpc"
fi
if test "x$PNETCDF" = x1 ; then
PATH=${PATH}:/machine/local_mpich2/bin
CC="/machine/local_mpich2/bin/mpicc"
CPPFLAGS="-I/machine/local_par7/include -I/machine/local_mpich2/include -I/machine/local_par/include"
LDFLAGS="-L/machine/local_par7/lib -L/machine/local_mpich2/lib -L/machine/local_par/lib"
if test -f /machine/local_mpich2 ; then
MPI1=/machine/local_mpich2
MPI2=/machine/local_par7
MPI3=/machine/local_par
else
MPI1=/usr/local
MPI2=${MPI1}
MPI3=${MPI1}
fi
PATH=${PATH}:${MPI1}/bin
CC="${MPI1}/bin/mpicc"
CPPFLAGS="-I${MPI2}/include -I${MPI1}/include -I${MPI3}/include"
LDFLAGS="-L${MPI2}/lib -L${MPI1}/lib -L${MPI3}/lib"
LDLIBS="-lmpich -lmpl"
FLAGS="$FLAGS --enable-pnetcdf"
FLAGS="$FLAGS --enable-parallel-tests"

View File

@ -26,10 +26,8 @@ typedef struct NC {
struct NC_Dispatch* dispatch;
void* dispatchdata; /*per-'file' data; points to e.g. NC3_INFO data*/
char* path;
int mode; /* as provided to nc_open/nc_create */
int substrate;
#if 0
void* instance;
#endif
} NC;
/*
@ -83,6 +81,6 @@ extern int count_NCList(void); /* return # of entries in NClist */
/* Defined in nc.c */
extern void free_NC(NC*);
extern int new_NC(struct NC_Dispatch*, const char*, NC**);
extern int new_NC(struct NC_Dispatch*, const char*, int, NC**);
#endif /* _NC_H_ */

View File

@ -94,6 +94,9 @@ NC3_inq_base_pe(int ncid, int *pe);
EXTERNL int
NC3_inq_format(int ncid, int *formatp);
EXTERNL int
NC3_inq_format_extended(int ncid, int *formatp, int *modep);
EXTERNL int
NC3_inq(int ncid, int *ndimsp, int *nvarsp, int *nattsp, int *unlimdimidp);

View File

@ -209,6 +209,7 @@ int (*set_fill)(int,int,int*);
int (*inq_base_pe)(int,int*);
int (*set_base_pe)(int,int);
int (*inq_format)(int,int*);
int (*inq_format_extended)(int,int*,int*);
int (*inq)(int,int*,int*,int*,int*);
int (*inq_type)(int, nc_type, char*, size_t*);

View File

@ -155,15 +155,43 @@ Use this in mode flags for both nc_create() and nc_open(). */
#define NC_MPIPOSIX 0x4000
#define NC_PNETCDF 0x8000 /**< Use parallel-netcdf library. Mode flag for nc_open(). */
/** Format specifier for nc_set_default_format(). Starting with
* version 3.6, there are different format netCDF files. 4.0
* introduces the third one. \see netcdf_format
/** Format specifier for nc_set_default_format() and returned
* by nc_inq_format. This returns the format as provided by
* the API. See nc_inq_format_extended to see the true file format.
* Starting with version 3.6, there are different format netCDF files.
* 4.0 introduces the third one. \see netcdf_format
*/
/**@{*/
#define NC_FORMAT_CLASSIC (1)
#define NC_FORMAT_64BIT (2)
#define NC_FORMAT_NETCDF4 (3)
#define NC_FORMAT_NETCDF4_CLASSIC (4)
/**@}*/
/** Extended format specifier returned by nc_inq_format_extended()
* Added in version 4.3.1. This returns the true format of the
* underlying data
* The function returns two values
* 1. a small integer indicating the underlying source type
* of the data. Note that this may differ from what the user
* sees from nc_inq_format() because this latter function
* returns what the user can expect to see thru the API.
* 2. A mode value indicating what mode flags are effectively
* set for this dataset. This usually will be a superset
* of the mode flags used as the argument to nc_open
* or nc_create.
* More or less, the #1 values track the set of dispatch tables.
* The #1 values are as follows.
*/
/**@{*/
#define NC_FORMAT_NC3 (1)
#define NC_FORMAT_NC_HDF5 (2) /*cdf 4 subset of HDF5 */
#define NC_FORMAT_NC_HDF4 (3) /* netcdf 4 subset of HDF4 */
#define NC_FORMAT_PNETCDF (4)
#define NC_FORMAT_DAP2 (5)
#define NC_FORMAT_DAP4 (6)
#define NC_FORMAT_UNDEFINED (0)
/**@}*/
/** Let nc__create() or nc__open() figure out a suitable buffer size. */
@ -861,6 +889,10 @@ nc_inq_unlimdims(int ncid, int *nunlimdimsp, int *unlimdimidsp);
EXTERNL int
nc_inq_format(int ncid, int *formatp);
/* Added in 4.3.1 to return additional format info */
EXTERNL int
nc_inq_format_extended(int ncid, int *formatp, int* modep);
/* Begin _dim */
EXTERNL int

View File

@ -58,6 +58,7 @@ NULL, /*set_fill*/
NULL, /*inq_base_pe*/
NULL, /*set_base_pe*/
NULL, /*inq_format*/
NCD3_inq_format_extended, /*inq_format_extended*/
NULL, /*inq*/
NULL, /*inq_type*/

View File

@ -52,6 +52,10 @@ NCD3_open(const char *path, int mode,
EXTERNL int
NCD3_close(int ncid);
EXTERNL int
NCD3_inq_format_extended(int ncid, int* formatp, int* modep);
/* End _var */
extern int NCD3_initialize(void);

View File

@ -762,3 +762,14 @@ NCDAP_ping(const char* url)
ocstat = oc_ping(url);
return ocerrtoncerr(ocstat);
}
int
NCD3_inq_format_extended(int ncid, int* formatp, int* modep)
{
NC* nc;
int ncstatus = NC_check_id(ncid, (NC**)&nc);
if(ncstatus != NC_NOERR) return THROW(ncstatus);
if(modep) *modep = nc->mode;
if(formatp) *formatp = NC_FORMAT_DAP2;
return NC_NOERR;
}

View File

@ -1243,7 +1243,8 @@ nc_set_base_pe(int ncid, int pe)
}
/**
Inquire about the binary format of a netCDF file.
Inquire about the binary format of a netCDF file
as presented by the API.
This function returns the (rarely needed) format version.
@ -1268,6 +1269,40 @@ nc_inq_format(int ncid, int *formatp)
return ncp->dispatch->inq_format(ncid,formatp);
}
/**
Obtain more detailed (vis-a-vis nc_inq_format)
format information about an open dataset.
Note that the netcdf API will present the file
as if it had the format specified by nc_inq_format.
The true file format, however, may not even be
a netcdf file; it might be DAP, HDF4, or PNETCDF,
for example. This function returns that true file type.
It also returns the effective mode for the file.
\param ncid NetCDF ID, from a previous call to nc_open() or
nc_create().
\param formatp Pointer to location for returned true format.
\param modep Pointer to location for returned mode flags.
Refer to the actual list in the file netcdf.h to see the
currently defined set.
\returns ::NC_NOERR No error.
\returns ::NC_EBADID Invalid ncid passed.
*/
int
nc_inq_format_extended(int ncid, int *formatp, int *modep)
{
NC* ncp;
int stat = NC_check_id(ncid, &ncp);
if(stat != NC_NOERR) return stat;
return ncp->dispatch->inq_format_extended(ncid,formatp,modep);
}
/**
Inquire about a file or group.
@ -1549,7 +1584,7 @@ NC_create(const char *path, int cmode, size_t initialsz,
}
/* Create the NC* instance and insert its dispatcher */
stat = new_NC(dispatcher,path,&ncp);
stat = new_NC(dispatcher,path,cmode,&ncp);
if(stat) return stat;
/* Add to list of known open files and define ext_ncid */
@ -1688,7 +1723,7 @@ NC_open(const char *path, int cmode,
havetable:
/* Create the NC* instance and insert its dispatcher */
stat = new_NC(dispatcher,path,&ncp);
stat = new_NC(dispatcher,path,cmode,&ncp);
if(stat) return stat;
/* Add to list of known open files */

View File

@ -138,6 +138,17 @@ NCSUB_inq_format(int ncid, int* a1)
return ncsub->dispatch->inq_format(nc->substrate,a1);
}
static int
NCSUB_inq_format_extended(int ncid, int* a1, int *a2)
{
NC *nc, *ncsub;
int ncstat = NC_check_id(ncid, &nc);
if(ncstat != NC_NOERR) return ncstat;
ncstat = NC_check_id(nc->substrate, &ncsub);
if(ncstat != NC_NOERR) return ncstat;
return ncsub->dispatch->inq_format_extended(nc->substrate,a1,a2);
}
static int
NCSUB_inq(int ncid, int* a1, int* a2, int* a3, int* a4)
{
@ -844,6 +855,7 @@ NCSUB_set_fill,
NCSUB_inq_base_pe,
NCSUB_set_base_pe,
NCSUB_inq_format,
NCSUB_inq_format_extended,
NCSUB_inq,
NCSUB_inq_type,

View File

@ -52,12 +52,13 @@ free_NC(NC *ncp)
}
int
new_NC(NC_Dispatch* dispatcher, const char* path, NC** ncpp)
new_NC(NC_Dispatch* dispatcher, const char* path, int mode, NC** ncpp)
{
NC *ncp = (NC*)calloc(1,sizeof(NC));
if(ncp == NULL) return NC_ENOMEM;
ncp->dispatch = dispatcher;
ncp->path = nulldup(path);
ncp->mode = mode;
if(ncp->path == NULL) { /* fail */
free_NC(ncp);
return NC_ENOMEM;

View File

@ -38,7 +38,7 @@ 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
MAINTAINERCLEANFILES = $(man_MANS) attrx.c putgetx.c
EXTRA_DIST = attr.m4 ncx.m4 putget.m4 $(man_MANS) CMakeLists.txt XGetopt.c
# This tells make how to turn .m4 files into .c files.

View File

@ -94,6 +94,7 @@ NC3_set_fill,
NC3_inq_base_pe,
NC3_set_base_pe,
NC3_inq_format,
NC3_inq_format_extended,
NC3_inq,
NC3_inq_type,

View File

@ -1535,6 +1535,20 @@ NC3_inq_format(int ncid, int *formatp)
return NC_NOERR;
}
int
NC3_inq_format_extended(int ncid, int *formatp, int *modep)
{
int status;
NC *nc;
status = NC_check_id(ncid, &nc);
if(status != NC_NOERR)
return status;
if(formatp) *formatp = NC_FORMAT_NC3;
if(modep) *modep = nc->mode;
return NC_NOERR;
}
/* The sizes of types may vary from platform to platform, but within
* netCDF files, type sizes are fixed. */
#define NC_BYTE_LEN 1

View File

@ -26,6 +26,7 @@ NC4_set_fill,
NC4_inq_base_pe,
NC4_set_base_pe,
NC4_inq_format,
NC4_inq_format_extended,
NC4_inq,
NC4_inq_type,

View File

@ -65,6 +65,9 @@ NC4_inq_base_pe(int ncid, int *pe);
EXTERNL int
NC4_inq_format(int ncid, int *formatp);
EXTERNL int
NC4_inq_format_extended(int ncid, int *formatp, int *modep);
EXTERNL int
NC4_inq(int ncid, int *ndimsp, int *nvarsp, int *nattsp, int *unlimdimidp);

View File

@ -66,3 +66,24 @@ NC4_inq_format(int ncid, int *formatp)
return NC_NOERR;
}
/* Get the extended format of an open file. */
int
NC4_inq_format_extended(int ncid, int *formatp, int *modep)
{
NC *nc;
NC_HDF5_FILE_INFO_T* h5;
LOG((2, "nc_inq_format_extended: ncid 0x%x", ncid));
/* Find the file metadata. */
if (!(nc = nc4_find_nc_file(ncid,&h5)))
return NC_EBADID;
if(modep) *modep = (nc->mode|NC_NETCDF4);
if(formatp) {
/* Distinguish HDF5 from HDF4 */
*formatp = (h5->hdf4 ? NC_FORMAT_NC_HDF4 : NC_FORMAT_NC_HDF5);
}
return NC_NOERR;
}

View File

@ -113,8 +113,13 @@ NC5_open(const char *path, int cmode,
if(cmode & (NC_64BIT_OFFSET))
return NC_EINVAL;
comm = ((NC_MPI_INFO *)mpidata)->comm;
info = ((NC_MPI_INFO *)mpidata)->info;
if(mpidata != NULL) {
comm = ((NC_MPI_INFO *)mpidata)->comm;
info = ((NC_MPI_INFO *)mpidata)->info;
} else {
comm = MPI_COMM_WORLD;
info = MPI_INFO_NULL;
}
/* Fix up the cmode by keeping only essential flags;
these are the flags that are the same in netcf.h and pnetcdf.h
@ -251,6 +256,17 @@ NC5_inq_format(int ncid, int* formatp)
return ncmpi_inq_format(nc->int_ncid,formatp);
}
static int
NC5_inq_format_extended(int ncid, int* formatp, int *modep)
{
NC* nc;
int status = NC_check_id(ncid, &nc);
if(status != NC_NOERR) return status;
if(modep) *modep = nc->mode;
if(formatp) *formatp = NC_FORMAT_PNETCDF;
return NC_NOERR;
}
static int
NC5_inq(int ncid,
int *ndimsp,
@ -1057,6 +1073,7 @@ NC5_set_fill,
NC5_inq_base_pe,
NC5_set_base_pe,
NC5_inq_format,
NC5_inq_format_extended,
NC5_inq,
NC5_inq_type,

View File

@ -12,7 +12,7 @@ CLEANFILES = nc_test_classic.nc nc_test_64bit.nc nc_test_netcdf4.nc \
tst_*.nc t_nc.nc large_files.nc quick_large_files.nc \
tst_diskless.nc tst_diskless2.nc \
tst_diskless3.nc tst_diskless3_file.cdl tst_diskless3_memory.cdl \
tst_diskless4.cdl tst_diskless4.nc
tst_diskless4.cdl tst_diskless4.nc tst_formatx.nc
# These are the tests which are always run.
TESTPROGRAMS = t_nc tst_small nc_test tst_misc tst_norm tst_names \
@ -23,7 +23,7 @@ TESTPROGRAMS += tst_atts
endif
if USE_PNETCDF
TESTPROGRAMS += tst_parallel2 tst_pnetcdf
TESTPROGRAMS += tst_parallel2 tst_pnetcdf tst_formatx_pnetcdf
endif
# if EXTRA_TESTS

View File

@ -270,7 +270,7 @@ check_fill_seq(int id)
size_t *cc, *mm;
union getret got;
int ii = 0;
float val;
/*float val;*/
sizes[0] = NUM_RECS;
cc = vindices;
@ -288,7 +288,7 @@ check_fill_seq(int id)
{
if(nc_get_var1_float(id, Float_id, vindices, &got.fl[0]) == -1)
goto bad_ret;
val = (float) ii;
/* val = (float) ii; */
/* if(val != got.fl[0]) */
/* { */
/* parray("indices", NUM_DIMS, vindices); */

View File

@ -0,0 +1,75 @@
/* This is part of the netCDF package.
Copyright 2005 University Corporation for Atmospheric Research/Unidata
See COPYRIGHT file for conditions of use.
Test fix of bug involving creation of a file with pnetcdf APIs,
then opening and modifying the file with netcdf.
Author: Wei-keng Liao.
*/
#include <nc_tests.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <mpi.h>
#include <netcdf.h>
#include <netcdf_par.h>
#include <assert.h>
#define NVARS 6
#define NX 5
#define FILENAME "tst_formatx.nc"
int main(int argc, char* argv[])
{
int err = 0;
int ecode = 0;
int ncid;
int cmode, format;
int nprocs, rank;
MPI_Comm comm=MPI_COMM_SELF;
MPI_Info info=MPI_INFO_NULL;
printf("\n*** Testing nc_inq_format_extended for pnetcdf...");
MPI_Init(&argc,&argv);
MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
if (nprocs > 1 && rank == 0)
printf("This test program is intended to run on ONE process\n");
if (rank > 0) goto fn_exit;
/* first, use PnetCDF to create a file with default header/variable alignment */
#ifdef DISABLE_PNETCDF_ALIGNMENT
MPI_Info_create(&info);
MPI_Info_set(info, "nc_header_align_size", "1");
MPI_Info_set(info, "nc_var_align_size", "1");
#endif
cmode = NC_PNETCDF | NC_CLOBBER;
if (nc_create_par(FILENAME, cmode, comm, info, &ncid)) ERR_RET;
if (nc_enddef(ncid)) ERR;
if(nc_inq_format_extended(ncid,&format,&cmode)) ERR;
if(cmode != 0x8000) {
printf("***FAIL: mode was %08x ; expected %08x\n",cmode,0);
ecode = 1;
ERR;
}
if(format != NC_FORMAT_PNETCDF) {
printf("***FAIL: format was %d ; expected %d\n",format,NC_FORMAT_PNETCDF);
ecode = 1;
ERR;
}
if (nc_abort(ncid)) ERR;
fn_exit:
MPI_Finalize();
SUMMARIZE_ERR;
FINAL_RESULTS;
return ecode;
}

View File

@ -29,7 +29,6 @@ test_small_atts(const char *testfile)
int ndims, nvars, natts, unlimdimid;
size_t len_in;
int t, f;
/* Run this with and without fill mode. */
for (f = 0; f < 2; f++)

View File

@ -85,8 +85,8 @@ endif # BUILD_BENCHMARKS
# These are the tests for HDF4.
if USE_HDF4
check_PROGRAMS += tst_interops2
TESTS += tst_interops2
check_PROGRAMS += tst_interops2
TESTS += tst_interops2 tst_formatx_hdf4.sh
if USE_HDF4_FILE_TESTS
check_PROGRAMS += tst_interops3
TESTS += run_get_hdf4_files.sh tst_interops3

26
nc_test4/tst_formatx_hdf4.sh Executable file
View File

@ -0,0 +1,26 @@
#!/bin/sh
# This shell script tests the output several previous tests.
# $Id: tst_output.sh,v 1.17 2010/05/14 16:21:15 ed Exp $
FILE=tst_interops2.h4
ECODE=0
echo ""
echo "*** Testing extended file format output."
set -e
echo "Test extended format output for a HDF4 file"
rm -f tmp
../ncdump/ncdump -K $FILE >tmp
if ! fgrep 'HDF4 mode=00001000' <tmp ; then
TMP=`cat tmp`
echo "*** Fail: extended format for an HDF4 file: result=" $TMP
ECODE=1
fi
rm -f tmp
exit $ECODE

View File

@ -25,7 +25,7 @@ TESTS += tst_ncdap3.sh
if ENABLE_DAP_REMOTE_TESTS
TESTS += tst_remote3.sh
TESTS += tst_remote3.sh tst_formatx.sh
if ENABLE_DAP_LONG_TESTS
TESTS += tst_longremote3.sh
@ -84,7 +84,7 @@ EXTRA_DIST = tst_ncdap3.sh tst_ncdap4.sh \
tst_remote3.sh tst_remote4.sh \
tst_longremote3.sh tst_longremote4.sh \
tst_ncdap.sh tst_ncdap_shared.sh tst_remote.sh \
t_dap.c CMakeLists.txt
t_dap.c CMakeLists.txt tst_formatx.sh
CLEANFILES = test_varm3 test_cvt3 results/*.dmp results/*.das results/*.dds datadds* t_dap3a test_nstride_cached

View File

@ -146,7 +146,6 @@ int main()
/* open file, get varid */
CHECK(nc_open(url, NC_NOWRITE, &ncid));
/* extract the string case for netcdf-3*/
#ifndef USE_NETCDF4
CHECK(nc_inq_varid(ncid, "s", &varid));

29
ncdap_test/tst_formatx.sh Executable file
View File

@ -0,0 +1,29 @@
#!/bin/sh
# This shell script tests the output several previous tests.
# $Id: tst_output.sh,v 1.17 2010/05/14 16:21:15 ed Exp $
echo ""
echo "*** Testing extended file format output."
set -e
# Figure our dst server
SVC=`./nctestserver dts`
if test "x$SVC" = "x" ; then
echo "cannot locate test server"
exit
fi
URL="$SVC/dts/test.03"
ECODE=0
echo "Test extended format output for a DAP2 file"
rm -f tmp
../ncdump/ncdump -K $URL >tmp
if ! fgrep 'DAP2 mode=00000000' <tmp ; then
echo "*** Fail: extended format for a DAP2 file"
ECODE=1
fi
rm tmp
exit $ECODE

0
ncdap_test/tst_nocache3.sh Normal file → Executable file
View File

0
ncdap_test/tst_nocache4.sh Normal file → Executable file
View File

View File

@ -31,7 +31,7 @@ if BUILD_TESTSETS
check_PROGRAMS = rewrite-scalar ctest ctest64 ncdump tst_utf8
TESTS = run_tests.sh tst_64bit.sh ctest ctest64 tst_output.sh \
tst_lengths.sh tst_calendars.sh tst_utf8 run_utf8_tests.sh \
tst_nccopy3.sh tst_charfill.sh tst_iter.sh
tst_nccopy3.sh tst_charfill.sh tst_iter.sh tst_formatx3.sh
if LARGE_FILE_TESTS
TESTS += tst_iter.sh
@ -48,7 +48,7 @@ TESTS += tst_create_files tst_group_data tst_enum_data tst_opaque_data \
tst_string_data tst_vlen_data tst_comp tst_comp2 tst_nans \
tst_special_atts tst_netcdf4.sh tst_h_rdc0 tst_unicode tst_fillbug \
tst_fillbug.sh tst_netcdf4_4.sh tst_compress tst_nccopy4.sh \
tst_grp_spec.sh tst_mud.sh tst_h_scalar tst_h_scalar.sh
tst_grp_spec.sh tst_mud.sh tst_h_scalar tst_h_scalar.sh tst_formatx4.sh
if EXTRA_TESTS
TESTS += run_back_comp_tests.sh
@ -123,13 +123,15 @@ ref_nc_test_netcdf4.cdl ref_tst_special_atts3.cdl tst_brecs.cdl \
ref_tst_grp_spec0.cdl ref_tst_grp_spec.cdl tst_grp_spec.sh \
ref_tst_charfill.cdl tst_charfill.cdl tst_charfill.sh \
tst_iter.sh tst_mud.sh ref_tst_mud4.cdl ref_tst_mud4-bc.cdl \
ref_tst_ncf213.cdl cdl4/ref_tst_h_scalar.cdl tst_h_scalar.sh CMakeLists.txt \
XGetopt.c
ref_tst_ncf213.cdl cdl4/ref_tst_h_scalar.cdl tst_h_scalar.sh \
tst_formatx3.sh tst_formatx4.sh \
CMakeLists.txt XGetopt.c
# NCGEN4 additions
SUBDIRS=cdl4 expected4
EXTRA_DIST += tst_ncgen4_shared.sh tst_ncgen4.sh tst_ncgen4_classic.sh \
tst_ncgen4_diff.sh tst_ncgen4_cycle.sh ref_ctest.c ref_ctest64.c
tst_ncgen4_diff.sh tst_ncgen4_cycle.sh ref_ctest.c ref_ctest64.c \
ctest.c ctest64.c
CLEANFILES += results/*.nc results/*.dmp results/*.dmp2 tmp*.cdl
DISTCLEANFILES = results

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -239,6 +239,45 @@ kind_string(int kind)
}
/* Return extended format string */
static const char *
kind_string_extended(int kind, int mode)
{
static char text[1024];
switch (kind) {
case NC_FORMAT_NC3:
if(mode & NC_64BIT_OFFSET)
snprintf(text,sizeof(text),"%s mode=%08x", "64-bit offset",mode);
else
snprintf(text,sizeof(text),"%s mode=%08x", "classic",mode);
break;
case NC_FORMAT_NC_HDF5:
snprintf(text,sizeof(text),"%s mode=%08x", "HDF5",mode);
break;
case NC_FORMAT_NC_HDF4:
snprintf(text,sizeof(text),"%s mode=%08x", "HDF4",mode);
break;
case NC_FORMAT_PNETCDF:
snprintf(text,sizeof(text),"%s mode=%08x", "PNETCDF",mode);
break;
case NC_FORMAT_DAP2:
snprintf(text,sizeof(text),"%s mode=%08x", "DAP2",mode);
break;
case NC_FORMAT_DAP4:
snprintf(text,sizeof(text),"%s mode=%08x", "DAP4",mode);
break;
case NC_FORMAT_UNDEFINED:
snprintf(text,sizeof(text),"%s mode=%08x", "unknown",mode);
break;
default:
error("unrecognized extended format: %d",kind);
snprintf(text,sizeof(text),"%s mode=%08x", "unrecognized",mode);
break;
}
return text;
}
/*
* Emit initial line of output for NcML
*/
@ -2132,6 +2171,7 @@ main(int argc, char *argv[])
int nameopt = 0;
bool_t xml_out = false; /* if true, output NcML instead of CDL */
bool_t kind_out = false; /* if true, just output kind of netCDF file */
bool_t kind_out_extended = false; /* output inq_format vs inq_format_extended */
#if defined(WIN32) || defined(msdos) || defined(WIN64)
putenv("PRINTF_EXPONENT_DIGITS=2"); /* Enforce unix/linux style exponent formatting. */
@ -2156,7 +2196,7 @@ main(int argc, char *argv[])
#endif
}
while ((c = getopt(argc, argv, "b:cd:f:g:hikl:n:p:stv:xw")) != EOF)
while ((c = getopt(argc, argv, "b:cd:f:g:hikl:n:p:stv:xwK")) != EOF)
switch(c) {
case 'h': /* dump header only, no data */
formatting_specs.header_only = true;
@ -2224,6 +2264,9 @@ main(int argc, char *argv[])
case 'k': /* just output what kind of netCDF file */
kind_out = true;
break;
case 'K': /* extended format info */
kind_out_extended = true;
break;
case 't': /* human-readable strings for date-time values */
formatting_specs.string_times = true;
formatting_specs.iso_separator = false;
@ -2288,8 +2331,13 @@ main(int argc, char *argv[])
error("%s: %s", path, nc_strerror(nc_status));
}
NC_CHECK( nc_inq_format(ncid, &formatting_specs.nc_kind) );
NC_CHECK( nc_inq_format_extended(ncid,
&formatting_specs.nc_extended,
&formatting_specs.nc_mode) );
if (kind_out) {
printf ("%s\n", kind_string(formatting_specs.nc_kind));
} else if (kind_out_extended) {
printf ("%s\n", kind_string_extended(formatting_specs.nc_extended,formatting_specs.nc_mode));
} else {
/* Initialize list of types. */
init_types(ncid);

View File

@ -71,6 +71,10 @@ typedef struct { /* specification for how to format dump */
* command line, 1 (classic), 2
* (64-bit offset), 3 (netCDF-4), 4
* (netCDF-4 classic model) */
int nc_extended; /* extended format info fornetCDF file named
* on command line.
*/
int nc_mode; /* mode as reported by inq_format_extended */
} fspec_t;
#endif /*_NCDUMP_H_ */

37
ncdump/tst_formatx3.sh Executable file
View File

@ -0,0 +1,37 @@
#!/bin/sh
# This shell script tests the output several previous tests.
# $Id: tst_output.sh,v 1.17 2010/05/14 16:21:15 ed Exp $
if test "x$srcdir" = x ; then
srcdir="."
fi
ECODE=0
echo ""
echo "*** Testing extended file format output."
set -e
echo "Test extended format output for a netcdf-3 file"
rm -f tmp
../ncgen/ncgen -k1 -b -o ./test.nc $srcdir/ref_tst_small.cdl
./ncdump -K test.nc >tmp
if ! fgrep 'classic mode=00000000' <tmp ; then
echo "*** Fail: extended format for a classic file"
ECODE=1
fi
echo "Test extended format output for a 64-bit netcdf-3 file"
rm -f tmp
../ncgen/ncgen -k2 -b -o ./test.nc $srcdir/ref_tst_small.cdl
./ncdump -K test.nc >tmp
if ! fgrep '64-bit offset mode=00000200' <tmp ; then
echo "*** Fail: extended format for a 64-bit classic file"
ECODE=1
fi
rm -f tmp test.nc
exit $ECODE

34
ncdump/tst_formatx4.sh Executable file
View File

@ -0,0 +1,34 @@
#!/bin/sh
# This shell script tests the output several previous tests.
# $Id: tst_output.sh,v 1.17 2010/05/14 16:21:15 ed Exp $
if test "x$srcdir" = x ; then
srcdir="."
fi
ECODE=0
echo ""
echo "*** Testing extended file format output."
set -e
echo "Test extended format output for a netcdf-4 file"
rm -f tmp
../ncgen/ncgen -k3 -b -o ./test.nc $srcdir/ref_tst_small.cdl
./ncdump -K test.nc >tmp
if ! fgrep 'HDF5 mode=00001000' <tmp ; then
echo "*** Fail: extended format for a netcdf-4 file"
ECODE=1
fi
echo "Test extended format output for a classic netcdf-4 file"
rm -f tmp
../ncgen/ncgen -k4 -b -o ./test.nc $srcdir/ref_tst_small.cdl
./ncdump -K test.nc >tmp
if ! fgrep 'HDF5 mode=00001000' <tmp ; then
echo "*** Fail: extended format for a classic netcdf-4 file"
ECODE=1
fi
rm -f tmp test.nc
exit $ECODE

0
ncdump/tst_ncgen4_shared.sh Normal file → Executable file
View File