Merge branch 'master' into ejh_next

This commit is contained in:
Ed Hartnett 2019-08-16 03:42:32 -06:00 committed by GitHub
commit bce3fa6169
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 305 additions and 438 deletions

View File

@ -14,6 +14,12 @@ developed. Programmers interested in parallel I/O should see
nc_open_par() and nc_create_par(). nc_open_par() and nc_create_par().
See [GitHub #1436](https://github.com/Unidata/netcdf-c/issues/1459) See [GitHub #1436](https://github.com/Unidata/netcdf-c/issues/1459)
* [Enhancement] Remove obsolete and deprecated functions
nc_set_base_pe() and nc_inq_base_pe() from the dispatch table. (Both
functions are still supported in the library, this is an internal
change only.)
See [GitHub #1436](https://github.com/Unidata/netcdf-c/issues/1468)
* [Bug Fix] Reverted nccopy behavior so that if no -c parameters * [Bug Fix] Reverted nccopy behavior so that if no -c parameters
are given, then any default chunking is left to the netcdf-c library are given, then any default chunking is left to the netcdf-c library
to decide. to decide.

View File

@ -132,7 +132,7 @@ Next, specify where you want to install HDF5 in another shell variable, for exam
~~~~{.py} ~~~~{.py}
$ # Build and install HDF5 $ # Build and install HDF5
$ H5DIR=/usr/local $ H5DIR=/usr/local
$ ./configure --with-zlib=${ZDIR} --prefix=${H5DIR} --eanble-hl $ ./configure --with-zlib=${ZDIR} --prefix=${H5DIR} --enable-hl
$ make check $ make check
$ make install # or sudo make install, if root permissions required $ make install # or sudo make install, if root permissions required
~~~~ ~~~~

View File

@ -128,8 +128,8 @@ main(int argc, char **argv)
if (nc_inq(ncid + TEST_VAL_42, NULL, NULL, NULL, NULL) != NC_EBADID) ERR; if (nc_inq(ncid + TEST_VAL_42, NULL, NULL, NULL, NULL) != NC_EBADID) ERR;
/* These only work for netCDF-3 files. */ /* These only work for netCDF-3 files. */
if (nc_set_base_pe(ncid, 0) != NC_ENOTNC3) ERR; if (nc_set_base_pe(ncid, 0)) ERR;
if (nc_inq_base_pe(ncid, NULL) != NC_ENOTNC3) ERR; if (nc_inq_base_pe(ncid, NULL)) ERR;
/* Attempt to write. */ /* Attempt to write. */
if (nc_rename_att(ncid, NC_GLOBAL, ATT_NAME, NAME_DUMB) != NC_EPERM) ERR; if (nc_rename_att(ncid, NC_GLOBAL, ATT_NAME, NAME_DUMB) != NC_EPERM) ERR;

View File

@ -49,17 +49,6 @@ check_inq_format(int ncid, int expected_format, int expected_extended_format, in
if (mode != expected_mode) ERR; if (mode != expected_mode) ERR;
if (extended_format != expected_extended_format) ERR; if (extended_format != expected_extended_format) ERR;
/* Nothing to do with inq_format, but let's check the base_pe
* functions. */
if (expected_format == NC_FORMAT_CLASSIC || expected_format == NC_FORMAT_64BIT_OFFSET ||
expected_format == NC_FORMAT_CDF5) {
if (nc_set_base_pe(ncid, 0)) ERR;
if (nc_inq_base_pe(ncid, NULL)) ERR;
} else {
if (nc_set_base_pe(ncid, 0) != NC_ENOTNC3) ERR;
if (nc_inq_base_pe(ncid, NULL) != NC_ENOTNC3) ERR;
}
return 0; return 0;
} }

View File

@ -83,12 +83,6 @@ extern "C" {
extern int extern int
NC3_set_fill(int ncid, int fillmode, int *old_modep); NC3_set_fill(int ncid, int fillmode, int *old_modep);
extern int
NC3_set_base_pe(int ncid, int pe);
extern int
NC3_inq_base_pe(int ncid, int *pe);
extern int extern int
NC3_inq_format(int ncid, int *formatp); NC3_inq_format(int ncid, int *formatp);

View File

@ -49,12 +49,6 @@ extern "C" {
EXTERNL int EXTERNL int
NC4_set_fill(int ncid, int fillmode, int *old_modep); NC4_set_fill(int ncid, int fillmode, int *old_modep);
EXTERNL int
NC4_set_base_pe(int ncid, int pe);
EXTERNL int
NC4_inq_base_pe(int ncid, int *pe);
EXTERNL int EXTERNL int
NC4_inq_format(int ncid, int *formatp); NC4_inq_format(int ncid, int *formatp);

View File

@ -35,8 +35,6 @@ struct NC_Dispatch
int (*abort)(int); int (*abort)(int);
int (*close)(int, void *); int (*close)(int, void *);
int (*set_fill)(int, int, int *); 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)(int, int*);
int (*inq_format_extended)(int, int *, int *); int (*inq_format_extended)(int, int *, int *);
@ -163,8 +161,6 @@ EXTERNL int NC_RO_set_fill(int ncid, int fillmode, int *old_modep);
/* These functions are for dispatch layers that don't implement these /* These functions are for dispatch layers that don't implement these
* legacy functions. They return NC_ENOTNC3. */ * legacy functions. They return NC_ENOTNC3. */
EXTERNL int NC_NOTNC3_set_base_pe(int ncid, int pe);
EXTERNL int NC_NOTNC3_inq_base_pe(int ncid, int *pe);
EXTERNL int NC_NOTNC3_put_varm(int ncid, int varid, const size_t * start, EXTERNL int NC_NOTNC3_put_varm(int ncid, int varid, const size_t * start,
const size_t *edges, const ptrdiff_t *stride, const size_t *edges, const ptrdiff_t *stride,
const ptrdiff_t *imapp, const void *value0, const ptrdiff_t *imapp, const void *value0,

View File

@ -101,8 +101,6 @@ NCD2_sync,
NCD2_abort, NCD2_abort,
NCD2_close, NCD2_close,
NCD2_set_fill, NCD2_set_fill,
NCD2_inq_base_pe,
NCD2_set_base_pe,
NCD2_inq_format, NCD2_inq_format,
NCD2_inq_format_extended, /*inq_format_extended*/ NCD2_inq_format_extended, /*inq_format_extended*/
@ -2257,12 +2255,6 @@ NCD2_set_fill(int ncid, int fillmode, int* old_modep)
return THROW(NC_EPERM); return THROW(NC_EPERM);
} }
int
NCD2_set_base_pe(int ncid, int pe)
{
return THROW(NC_EPERM);
}
int int
NCD2_def_dim(int ncid, const char* name, size_t len, int* idp) NCD2_def_dim(int ncid, const char* name, size_t len, int* idp)
{ {
@ -2287,16 +2279,6 @@ NCD2_def_var(int ncid, const char *name,
Following functions basically return the netcdf-3 value WRT to the nc3id. Following functions basically return the netcdf-3 value WRT to the nc3id.
*/ */
int
NCD2_inq_base_pe(int ncid, int* pe)
{
NC* drno;
int ret;
if((ret = NC_check_id(ncid, (NC**)&drno)) != NC_NOERR) return THROW(ret);
ret = nc_inq_base_pe(getnc3id(drno), pe);
return THROW(ret);
}
int int
NCD2_inq_format(int ncid, int* formatp) NCD2_inq_format(int ncid, int* formatp)
{ {

View File

@ -57,12 +57,6 @@ NCD2_inq_format_extended(int ncid, int* formatp, int* modep);
extern int extern int
NCD2_set_fill(int ncid, int fillmode, int *old_modep); NCD2_set_fill(int ncid, int fillmode, int *old_modep);
extern int
NCD2_set_base_pe(int ncid, int pe);
extern int
NCD2_inq_base_pe(int ncid, int *pe);
extern int extern int
NCD2_inq_format(int ncid, int *formatp); NCD2_inq_format(int ncid, int *formatp);

View File

@ -117,12 +117,6 @@ NCD4_set_fill(int ncid, int fillmode, int* old_modep)
return (NC_EPERM); return (NC_EPERM);
} }
static int
NCD4_set_base_pe(int ncid, int pe)
{
return (NC_EPERM);
}
static int static int
NCD4_def_dim(int ncid, const char* name, size_t len, int* idp) NCD4_def_dim(int ncid, const char* name, size_t len, int* idp)
{ {
@ -253,18 +247,6 @@ Following functions basically return the netcdf-4 value WRT to the nc4id.
However, it is necessary to modify the grpid(ncid) to point to the substrate. However, it is necessary to modify the grpid(ncid) to point to the substrate.
*/ */
static int
NCD4_inq_base_pe(int ncid, int* pe)
{
NC* ncp;
int ret = NC_NOERR;
int substrateid;
if((ret = NC_check_id(ncid, (NC**)&ncp)) != NC_NOERR) return (ret);
substrateid = makenc4id(ncp,ncid);
ret = nc_inq_base_pe(substrateid, pe);
return (ret);
}
static int static int
NCD4_inq_format(int ncid, int* formatp) NCD4_inq_format(int ncid, int* formatp)
{ {
@ -806,8 +788,6 @@ NCD4_sync,
NCD4_abort, NCD4_abort,
NCD4_close, NCD4_close,
NCD4_set_fill, NCD4_set_fill,
NCD4_inq_base_pe,
NCD4_set_base_pe,
NCD4_inq_format, NCD4_inq_format,
NCD4_inq_format_extended, /*inq_format_extended*/ NCD4_inq_format_extended, /*inq_format_extended*/

View File

@ -1454,8 +1454,8 @@ nc_set_fill(int ncid, int fillmode, int *old_modep)
* @internal Learn base PE. * @internal Learn base PE.
* *
* @deprecated This function was used in the old days with the Cray at * @deprecated This function was used in the old days with the Cray at
* NCAR. The Cray is long gone, and this call is supported only for * NCAR. The Cray is long gone, and this call is now meaningless. The
* backward compatibility. * value returned for pe is always 0.
* *
* @param ncid File and group ID. * @param ncid File and group ID.
* @param pe Pointer for base PE. * @param pe Pointer for base PE.
@ -1470,7 +1470,8 @@ nc_inq_base_pe(int ncid, int *pe)
NC* ncp; NC* ncp;
int stat = NC_check_id(ncid, &ncp); int stat = NC_check_id(ncid, &ncp);
if(stat != NC_NOERR) return stat; if(stat != NC_NOERR) return stat;
return ncp->dispatch->inq_base_pe(ncid,pe); if (pe) *pe = 0;
return NC_NOERR;
} }
/** /**
@ -1493,26 +1494,25 @@ nc_set_base_pe(int ncid, int pe)
NC* ncp; NC* ncp;
int stat = NC_check_id(ncid, &ncp); int stat = NC_check_id(ncid, &ncp);
if(stat != NC_NOERR) return stat; if(stat != NC_NOERR) return stat;
return ncp->dispatch->set_base_pe(ncid,pe); return NC_NOERR;
} }
/** \ingroup datasets /**
Inquire about the binary format of a netCDF file * @ingroup datasets
as presented by the API. * Inquire about the binary format of a netCDF file
* as presented by the API.
This function returns the (rarely needed) format version. *
* This function returns the (rarely needed) format version.
\param ncid NetCDF ID, from a previous call to nc_open() or *
nc_create(). * @param ncid NetCDF ID, from a previous call to nc_open() or
* nc_create().
\param formatp Pointer to location for returned format version, one of * @param formatp Pointer to location for returned format version, one
NC_FORMAT_CLASSIC, NC_FORMAT_64BIT_OFFSET, NC_FORMAT_CDF5, NC_FORMAT_NETCDF4, * of NC_FORMAT_CLASSIC, NC_FORMAT_64BIT_OFFSET, NC_FORMAT_CDF5,
NC_FORMAT_NETCDF4_CLASSIC. * NC_FORMAT_NETCDF4, NC_FORMAT_NETCDF4_CLASSIC.
*
\returns ::NC_NOERR No error. * @returns ::NC_NOERR No error.
* @returns ::NC_EBADID Invalid ncid passed.
\returns ::NC_EBADID Invalid ncid passed. * @author Dennis Heimbigner
*/ */
int int
nc_inq_format(int ncid, int *formatp) nc_inq_format(int ncid, int *formatp)

View File

@ -1,7 +1,7 @@
/* Copyright 2018, UCAR/Unidata See netcdf/COPYRIGHT file for copying /* Copyright 2018, UCAR/Unidata See netcdf/COPYRIGHT file for copying
* and redistribution conditions.*/ * and redistribution conditions.*/
/** /**
* @file @internal This file handles the *_base_pe() * @file @internal This file handles the *_varm()
* functions for dispatch layers that need to return ::NC_ENOTNC3. * functions for dispatch layers that need to return ::NC_ENOTNC3.
* *
* @author Ed Hartnett * @author Ed Hartnett
@ -9,36 +9,6 @@
#include "nc4dispatch.h" #include "nc4dispatch.h"
/**
* @internal This function only does anything for netcdf-3 files.
*
* @param ncid Ignored.
* @param pe Ignored.
*
* @return ::NC_ENOTNC3 Not a netCDF classic format file.
* @author Ed Hartnett
*/
int
NC_NOTNC3_set_base_pe(int ncid, int pe)
{
return NC_ENOTNC3;
}
/**
* @internal This function only does anything for netcdf-3 files.
*
* @param ncid Ignored.
* @param pe Ignored.
*
* @return ::NC_ENOTNC3 Not a netCDF classic format file.
* @author Ed Hartnett
*/
int
NC_NOTNC3_inq_base_pe(int ncid, int *pe)
{
return NC_ENOTNC3;
}
/** /**
* @internal This function only does anything for netcdf-3 files. * @internal This function only does anything for netcdf-3 files.
* *

View File

@ -28,8 +28,6 @@ static const NC_Dispatch HDF4_dispatcher = {
NC_HDF4_abort, NC_HDF4_abort,
NC_HDF4_close, NC_HDF4_close,
NC_RO_set_fill, NC_RO_set_fill,
NC_NOTNC3_inq_base_pe,
NC_NOTNC3_set_base_pe,
NC_HDF4_inq_format, NC_HDF4_inq_format,
NC_HDF4_inq_format_extended, NC_HDF4_inq_format_extended,

View File

@ -28,8 +28,6 @@ static const NC_Dispatch HDF5_dispatcher = {
NC4_abort, NC4_abort,
NC4_close, NC4_close,
NC4_set_fill, NC4_set_fill,
NC_NOTNC3_inq_base_pe,
NC_NOTNC3_set_base_pe,
NC4_inq_format, NC4_inq_format,
NC4_inq_format_extended, NC4_inq_format_extended,

View File

@ -91,8 +91,6 @@ NC3_sync,
NC3_abort, NC3_abort,
NC3_close, NC3_close,
NC3_set_fill, NC3_set_fill,
NC3_inq_base_pe,
NC3_set_base_pe,
NC3_inq_format, NC3_inq_format,
NC3_inq_format_extended, NC3_inq_format_extended,

View File

@ -1537,39 +1537,6 @@ NC3_set_fill(int ncid,
return NC_NOERR; return NC_NOERR;
} }
/**
* This obsolete function is retained for backward compatibility. It
* does nothing.
*
* @param ncid Ignored.
* @param pe Ignored.
*
* @return NC_NOERR No error.
* @author Glenn Davis, Ed Hartnett
*/
int
NC3_set_base_pe(int ncid, int pe)
{
return NC_NOERR;
}
/**
* This obsolete function is retained for backward compatibility. It
* does nothing, and always returns pe = 0.
*
* @param ncid Ignored.
* @param pe Pointer to int that gets a 0. Ignored if NULL.
*
* @return NC_NOERR No error.
* @author Glenn Davis, Ed Hartnett
*/
int
NC3_inq_base_pe(int ncid, int *pe)
{
if (pe) *pe = 0;
return NC_NOERR;
}
/** /**
* Return the file format. * Return the file format.
* *

View File

@ -8,8 +8,7 @@
* This file is part of netcdf-4, a netCDF-like interface for HDF5, or a * 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. * HDF5 backend for netCDF, depending on your point of view.
* *
* This file handles the (useless) *_base_pe() functions, and the * This file handles the inq_format functions.
* inq_format functions.
* *
* @author Ed Hartnett, Dennis Heimbigner * @author Ed Hartnett, Dennis Heimbigner
*/ */

View File

@ -238,19 +238,6 @@ NCP_set_fill(int ncid, int fillmode, int *old_mode_ptr)
#endif #endif
} }
static int
NCP_inq_base_pe(int ncid, int *pep)
{
if (pep) *pep = 0;
return NC_NOERR;
}
static int
NCP_set_base_pe(int ncid, int pe)
{
return NC_NOERR;
}
static int static int
NCP_inq_format(int ncid, int *formatp) NCP_inq_format(int ncid, int *formatp)
{ {
@ -1399,8 +1386,6 @@ NCP_sync,
NCP_abort, NCP_abort,
NCP_close, NCP_close,
NCP_set_fill, NCP_set_fill,
NCP_inq_base_pe,
NCP_set_base_pe,
NCP_inq_format, NCP_inq_format,
NCP_inq_format_extended, NCP_inq_format_extended,

View File

@ -87,14 +87,8 @@ check_inq_format(int ncid, int expected_format, int expected_extended_format, in
/* Nothing to do with inq_format, but let's check the base_pe /* Nothing to do with inq_format, but let's check the base_pe
* functions. */ * functions. */
if (expected_format == NC_FORMAT_CLASSIC || expected_format == NC_FORMAT_64BIT_OFFSET || if (nc_set_base_pe(ncid, 0)) ERR;
expected_format == NC_FORMAT_CDF5) { if (nc_inq_base_pe(ncid, NULL)) ERR;
if (nc_set_base_pe(ncid, 0)) ERR;
if (nc_inq_base_pe(ncid, NULL)) ERR;
} else {
if (nc_set_base_pe(ncid, 0) != NC_ENOTNC3) ERR;
if (nc_inq_base_pe(ncid, NULL) != NC_ENOTNC3) ERR;
}
return 0; return 0;
} }

View File

@ -4,7 +4,7 @@ See COPYRIGHT file for copying and redistribution conditions.
This program tests netcdf-4 parallel I/O. This program tests netcdf-4 parallel I/O.
$Id: tst_parallel.c,v 1.7 2009/08/19 15:58:57 ed Exp $ Ed Hartnett, 2009/08/19
*/ */
/* Defining USE_MPE causes the MPE trace library to be used (and you /* Defining USE_MPE causes the MPE trace library to be used (and you

View File

@ -24,274 +24,299 @@
int int
main(int argc, char **argv) main(int argc, char **argv)
{ {
int mpi_size, mpi_rank; int mpi_size, mpi_rank;
MPI_Comm comm = MPI_COMM_WORLD; MPI_Comm comm = MPI_COMM_WORLD;
MPI_Info info = MPI_INFO_NULL; MPI_Info info = MPI_INFO_NULL;
int ncid, v1id, dimid; int ncid, v1id, dimid;
size_t start[NDIMS1] = {0}, count[NDIMS1] = {0}; size_t start[NDIMS1] = {0}, count[NDIMS1] = {0};
int data = MASTS; int data = MASTS;
int data_in = TEST_VAL_42; int data_in = TEST_VAL_42;
int acc; int acc;
/* Initialize MPI. */ /* Initialize MPI. */
MPI_Init(&argc, &argv); MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &mpi_size); MPI_Comm_size(MPI_COMM_WORLD, &mpi_size);
MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank); MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank);
/* Require exactly 4 tasks. */ /* Require exactly 4 tasks. */
if (mpi_size != NUM_PROC) ERR; if (mpi_size != NUM_PROC) ERR;
if (!mpi_rank) if (!mpi_rank)
printf("\n*** Testing parallel I/O.\n"); printf("\n*** Testing parallel I/O.\n");
if (!mpi_rank) if (!mpi_rank)
printf("*** testing whether we can write 0 elements from some tasks..."); printf("*** testing whether we can write 0 elements from some tasks...");
{ {
for (acc = 0; acc < NUM_ACCESS_TESTS; acc++) for (acc = 0; acc < NUM_ACCESS_TESTS; acc++)
{ {
/* Create a parallel netcdf-4 file. */ /* Create a parallel netcdf-4 file. */
/*nc_set_log_level(3);*/ /*nc_set_log_level(3);*/
if (nc_create_par(FILE, NC_NETCDF4, comm, info, &ncid)) ERR; if (nc_create_par(FILE, NC_NETCDF4, comm, info, &ncid)) ERR;
/* Create a dimension. */
if (nc_def_dim(ncid, DIM_NAME, DIMSIZE, &dimid)) ERR;
/* Create one var. */
if (nc_def_var(ncid, VAR_NAME, NC_INT, NDIMS1, &dimid, &v1id)) ERR;
/* Write metadata to file. */
if (nc_enddef(ncid)) ERR;
/* Set up slab for this process. */
if (!mpi_rank)
count[0] = 1;
if (nc_var_par_access(ncid, v1id, acc ? NC_COLLECTIVE : NC_INDEPENDENT)) ERR;
/* Write phoney data. */
if (nc_put_vara_int(ncid, v1id, start, count, &data)) ERR;
if (nc_sync(ncid)) ERR;
/* Read phoney data. */
if (nc_get_vara_int(ncid, v1id, start, count, &data_in)) ERR;
/* Task 0 has MASTS, the others have data_in remaining, as
* initialized, at TEST_VAL_42. */
if (data_in != (mpi_rank ? TEST_VAL_42 : MASTS)) ERR;
/* Close the netcdf file. */
if (nc_close(ncid)) ERR;
}
}
if (!mpi_rank)
SUMMARIZE_ERR;
if (!mpi_rank)
printf("*** testing enum type and parallel I/O...");
{
for (acc = 0; acc < NUM_ACCESS_TESTS; acc++)
{
#define ENUM_NAME "cargo"
#define ENUM_VAR_NAME "in_the_hold_of_the_Irish_Rover"
#define NUM_ENUM_FIELDS 8
int typeid;
int f;
char field_name[NUM_ENUM_FIELDS][NC_MAX_NAME + 1] = {"bags of the best Sligo rags", "barrels of bones",
"bails of old nanny goats' tails", "barrels of stones",
"dogs", "hogs", "barrels of porter",
"sides of old blind horses hides"};
unsigned long long field_value[NUM_ENUM_FIELDS] = {1000000, 2000000, 3000000, 4000000,
5000000, 6000000, 7000000, 8000000};
unsigned long long data = 1000000, data_in = TEST_VAL_42;
/* Create a parallel netcdf-4 file. */
/*nc_set_log_level(3);*/
if (nc_create_par(FILE, NC_NETCDF4, comm, info, &ncid)) ERR;
/* Create a dimension. */
if (nc_def_dim(ncid, DIM_NAME, DIMSIZE, &dimid)) ERR;
/* Create an enum type. */
if (nc_def_enum(ncid, NC_UINT64, ENUM_NAME, &typeid)) ERR;
for (f = 0; f < NUM_ENUM_FIELDS; f++)
if (nc_insert_enum(ncid, typeid, field_name[f], &field_value[f])) ERR;
/* Create one var. */
if (nc_def_var(ncid, ENUM_VAR_NAME, typeid, NDIMS1, &dimid, &v1id)) ERR;
/* Write metadata to file. */
if (nc_enddef(ncid)) ERR;
/* Set up slab for this process. */
if (!mpi_rank)
count[0] = 1;
if (nc_var_par_access(ncid, v1id, acc ? NC_COLLECTIVE : NC_INDEPENDENT)) ERR;
/* Write phoney data. */
if (nc_put_vara(ncid, v1id, start, count, &data)) ERR;
if (nc_sync(ncid)) ERR;
/* Read phoney data. */
if (nc_get_vara(ncid, v1id, start, count, &data_in)) ERR;
/* Task 0 has 1000000, the others have data_in remaining, as
* initialized, at TEST_VAL_42. */
if (data_in != (mpi_rank ? TEST_VAL_42 : 1000000)) ERR;
/* Close the netcdf file. */
if (nc_close(ncid)) ERR;
}
}
if (!mpi_rank)
SUMMARIZE_ERR;
if (!mpi_rank)
printf("*** testing compound type and parallel I/O...");
{
for (acc = 0; acc < NUM_ACCESS_TESTS; acc++)
{
#define COMPOUND_NAME "crew_info"
#define COMPOUND_VAR_NAME "whale_of_a_crew"
#define NUM_CREW 5
#define CREW_DIM_NAME "number_of_crew"
int typeid;
struct crew
{
char name[NC_MAX_NAME + 1];
char description[NC_MAX_NAME + 1];
char origin[NC_MAX_NAME + 1];
int age;
};
struct crew data = {"Mick McCann", "the skipper of the Irish Rover",
"from the banks of the Bann", 42};
struct crew data_in = {"", "", "", -42};
int dim_size = NC_MAX_NAME + 1;
/* Create a parallel netcdf-4 file. */
/*nc_set_log_level(3);*/
if (nc_create_par(FILE, NC_NETCDF4, comm, info, &ncid)) ERR;
/* Create a dimension. */
if (nc_def_dim(ncid, CREW_DIM_NAME, NUM_CREW, &dimid)) ERR;
/* Create a compound type. */
if (nc_def_compound(ncid, sizeof(struct crew), COMPOUND_NAME, &typeid)) ERR;
if (nc_insert_array_compound(ncid, typeid, "name", NC_COMPOUND_OFFSET(struct crew, name), NC_CHAR, 1, &dim_size)) ERR;
if (nc_insert_array_compound(ncid, typeid, "description", NC_COMPOUND_OFFSET(struct crew, description), NC_CHAR, 1, &dim_size)) ERR;
if (nc_insert_array_compound(ncid, typeid, "origin", NC_COMPOUND_OFFSET(struct crew, origin), NC_CHAR, 1, &dim_size)) ERR;
if (nc_insert_compound(ncid, typeid, "age", NC_COMPOUND_OFFSET(struct crew, age), NC_INT)) ERR;
/* Create one var. */
if (nc_def_var(ncid, COMPOUND_VAR_NAME, typeid, NDIMS1, &dimid, &v1id)) ERR;
/* Write metadata to file. */
if (nc_enddef(ncid)) ERR;
/* Set up slab for this process. */
if (!mpi_rank)
count[0] = 1;
if (nc_var_par_access(ncid, v1id, acc ? NC_COLLECTIVE : NC_INDEPENDENT)) ERR;
/* Write phoney data. */
if (nc_put_vara(ncid, v1id, start, count, &data)) ERR;
if (nc_sync(ncid)) ERR;
/* Read phoney data. */
if (nc_get_vara(ncid, v1id, start, count, &data_in)) ERR;
/* Task 0 has data, the others have nothing. */
if (!mpi_rank)
{
if (strcmp(data_in.name, data.name) || strcmp(data_in.description, data.description) ||
strcmp(data_in.origin, data.origin) || data_in.age != data.age) ERR;
}
else
{
if (strcmp(data_in.name, "") || strcmp(data_in.description, "") ||
strcmp(data_in.origin, "") || data_in.age != -42) ERR;
}
/* Close the netcdf file. */
if (nc_close(ncid)) ERR;
}
}
if (!mpi_rank)
SUMMARIZE_ERR;
if (!mpi_rank)
printf("*** testing string type and parallel I/O...");
{
for (acc = 0; acc < NUM_ACCESS_TESTS; acc++)
{
#define STORY_VAR_NAME "fate_of_the_Irish_Rover"
#define STORY_DIM_NAME "number_of_lines"
#define STORY_LEN 8
char *story[STORY_LEN] = {"We had sailed seven years when the measles broke out",
"And the ship lost it's way in the fog",
"And that whale of the crew was reduced down to two",
"Just myself and the captain's old dog",
"Then the ship struck a rock, oh Lord what a shock",
"The bulkhead was turned right over",
"Turned nine times around, and the poor dog was drowned",
"I'm the last of the Irish Rover"};
char *story_in[STORY_LEN];
int s;
/* Create a netcdf-4 file. Turns out that HDF5 does not
* support VLEN writes with parallel I/O. Strings are
* VLENS. So here I write a file with task 0 and then read it
* with all tasks. */
if (!mpi_rank)
{
if (nc_create(FILE, NC_NETCDF4, &ncid)) ERR;
/* Create a dimension. */ /* Create a dimension. */
if (nc_def_dim(ncid, STORY_DIM_NAME, STORY_LEN, &dimid)) ERR; if (nc_def_dim(ncid, DIM_NAME, DIMSIZE, &dimid)) ERR;
/* Create one var. */ /* Create one var. */
if (nc_def_var(ncid, STORY_VAR_NAME, NC_STRING, NDIMS1, &dimid, &v1id)) ERR; if (nc_def_var(ncid, VAR_NAME, NC_INT, NDIMS1, &dimid, &v1id)) ERR;
/* Write metadata to file. */ /* Write metadata to file. */
if (nc_enddef(ncid)) ERR; if (nc_enddef(ncid)) ERR;
/* Set up slab for this process. */ /* Set up slab for this process. */
count[0] = STORY_LEN; if (!mpi_rank)
count[0] = 1;
if (nc_var_par_access(ncid, v1id, acc ? NC_COLLECTIVE : NC_INDEPENDENT)) ERR;
/* Write phoney data. */ /* Write phoney data. */
if (nc_put_vara(ncid, v1id, start, count, story)) ERR; if (nc_put_vara_int(ncid, v1id, start, count, &data)) ERR;
if (nc_sync(ncid)) ERR;
/* Read phoney data. */
if (nc_get_vara_int(ncid, v1id, start, count, &data_in)) ERR;
/* Task 0 has MASTS, the others have data_in remaining, as
* initialized, at TEST_VAL_42. */
if (data_in != (mpi_rank ? TEST_VAL_42 : MASTS)) ERR;
/* Close the netcdf file. */ /* Close the netcdf file. */
if (nc_close(ncid)) ERR; if (nc_close(ncid)) ERR;
} }
}
if (!mpi_rank)
SUMMARIZE_ERR;
/* Now try parallel read. */ if (!mpi_rank)
if (nc_open_par(FILE, 0, comm, info, &ncid)) ERR; printf("*** testing enum type and parallel I/O...");
{
for (acc = 0; acc < NUM_ACCESS_TESTS; acc++)
{
#define ENUM_NAME "cargo"
#define ENUM_VAR_NAME "in_the_hold_of_the_Irish_Rover"
#define NUM_ENUM_FIELDS 8
int typeid;
int f;
char field_name[NUM_ENUM_FIELDS][NC_MAX_NAME + 1] = {"bags of the best Sligo rags", "barrels of bones",
"bails of old nanny goats' tails", "barrels of stones",
"dogs", "hogs", "barrels of porter",
"sides of old blind horses hides"};
unsigned long long field_value[NUM_ENUM_FIELDS] = {1000000, 2000000, 3000000, 4000000,
5000000, 6000000, 7000000, 8000000};
unsigned long long data = 1000000, data_in = TEST_VAL_42;
/* Task 0 reads all 8 lines, other tasks read 0. */ /* Create a parallel netcdf-4 file. */
if (nc_get_vara(ncid, v1id, start, count, story_in)) ERR; /*nc_set_log_level(3);*/
if (nc_create_par(FILE, NC_NETCDF4, comm, info, &ncid)) ERR;
if (!mpi_rank) /* Create a dimension. */
{ if (nc_def_dim(ncid, DIM_NAME, DIMSIZE, &dimid)) ERR;
for (s = 0; s < STORY_LEN; s++)
if (strcmp(story_in[s], story[s])) ERR;
if (nc_free_string(STORY_LEN, (char **)story_in)) ERR;
}
/* Close the netcdf file. */ /* Create an enum type. */
if (nc_close(ncid)) ERR; if (nc_def_enum(ncid, NC_UINT64, ENUM_NAME, &typeid)) ERR;
} for (f = 0; f < NUM_ENUM_FIELDS; f++)
} if (nc_insert_enum(ncid, typeid, field_name[f], &field_value[f])) ERR;
if (!mpi_rank)
SUMMARIZE_ERR;
/* Shut down MPI. */ /* Create one var. */
MPI_Finalize(); if (nc_def_var(ncid, ENUM_VAR_NAME, typeid, NDIMS1, &dimid, &v1id)) ERR;
if (!mpi_rank) /* Write metadata to file. */
FINAL_RESULTS; if (nc_enddef(ncid)) ERR;
return 0; /* Set up slab for this process. */
if (!mpi_rank)
count[0] = 1;
if (nc_var_par_access(ncid, v1id, acc ? NC_COLLECTIVE : NC_INDEPENDENT)) ERR;
/* Write phoney data. */
if (nc_put_vara(ncid, v1id, start, count, &data)) ERR;
if (nc_sync(ncid)) ERR;
/* Read phoney data. */
if (nc_get_vara(ncid, v1id, start, count, &data_in)) ERR;
/* Task 0 has 1000000, the others have data_in remaining, as
* initialized, at TEST_VAL_42. */
if (data_in != (mpi_rank ? TEST_VAL_42 : 1000000)) ERR;
/* Close the netcdf file. */
if (nc_close(ncid)) ERR;
}
}
if (!mpi_rank)
SUMMARIZE_ERR;
if (!mpi_rank)
printf("*** testing compound type and parallel I/O...");
{
for (acc = 0; acc < NUM_ACCESS_TESTS; acc++)
{
#define COMPOUND_NAME "crew_info"
#define COMPOUND_VAR_NAME "whale_of_a_crew"
#define NUM_CREW 5
#define CREW_DIM_NAME "number_of_crew"
int typeid;
struct crew
{
char name[NC_MAX_NAME + 1];
char description[NC_MAX_NAME + 1];
char origin[NC_MAX_NAME + 1];
int age;
};
struct crew data = {"Mick McCann", "the skipper of the Irish Rover",
"from the banks of the Bann", 42};
struct crew data_in = {"", "", "", -42};
int dim_size = NC_MAX_NAME + 1;
/* Create a parallel netcdf-4 file. */
/*nc_set_log_level(3);*/
if (nc_create_par(FILE, NC_NETCDF4, comm, info, &ncid)) ERR;
/* Create a dimension. */
if (nc_def_dim(ncid, CREW_DIM_NAME, NUM_CREW, &dimid)) ERR;
/* Create a compound type. */
if (nc_def_compound(ncid, sizeof(struct crew), COMPOUND_NAME, &typeid)) ERR;
if (nc_insert_array_compound(ncid, typeid, "name", NC_COMPOUND_OFFSET(struct crew, name), NC_CHAR, 1, &dim_size)) ERR;
if (nc_insert_array_compound(ncid, typeid, "description", NC_COMPOUND_OFFSET(struct crew, description), NC_CHAR, 1, &dim_size)) ERR;
if (nc_insert_array_compound(ncid, typeid, "origin", NC_COMPOUND_OFFSET(struct crew, origin), NC_CHAR, 1, &dim_size)) ERR;
if (nc_insert_compound(ncid, typeid, "age", NC_COMPOUND_OFFSET(struct crew, age), NC_INT)) ERR;
/* Create one var. */
if (nc_def_var(ncid, COMPOUND_VAR_NAME, typeid, NDIMS1, &dimid, &v1id)) ERR;
/* Write metadata to file. */
if (nc_enddef(ncid)) ERR;
/* Set up slab for this process. */
if (!mpi_rank)
count[0] = 1;
if (nc_var_par_access(ncid, v1id, acc ? NC_COLLECTIVE : NC_INDEPENDENT)) ERR;
/* Write phoney data. */
if (nc_put_vara(ncid, v1id, start, count, &data)) ERR;
if (nc_sync(ncid)) ERR;
/* Read phoney data. */
if (nc_get_vara(ncid, v1id, start, count, &data_in)) ERR;
/* Task 0 has data, the others have nothing. */
if (!mpi_rank)
{
if (strcmp(data_in.name, data.name) || strcmp(data_in.description, data.description) ||
strcmp(data_in.origin, data.origin) || data_in.age != data.age) ERR;
}
else
{
if (strcmp(data_in.name, "") || strcmp(data_in.description, "") ||
strcmp(data_in.origin, "") || data_in.age != -42) ERR;
}
/* Close the netcdf file. */
if (nc_close(ncid)) ERR;
}
}
if (!mpi_rank)
SUMMARIZE_ERR;
if (!mpi_rank)
printf("*** testing string type and parallel I/O...");
{
for (acc = 0; acc < NUM_ACCESS_TESTS; acc++)
{
#define STORY_VAR_NAME "fate_of_the_Irish_Rover"
#define STORY_DIM_NAME "number_of_lines"
#define STORY_LEN 8
char *story[STORY_LEN] = {"We had sailed seven years when the measles broke out",
"And the ship lost it's way in the fog",
"And that whale of the crew was reduced down to two",
"Just myself and the captain's old dog",
"Then the ship struck a rock, oh Lord what a shock",
"The bulkhead was turned right over",
"Turned nine times around, and the poor dog was drowned",
"I'm the last of the Irish Rover"};
char *story_in[STORY_LEN];
int s;
/* Create a netcdf-4 file. Turns out that HDF5 does not
* support VLEN writes with parallel I/O. Strings are
* VLENS. So here I write a file with task 0 and then read it
* with all tasks. */
if (!mpi_rank)
{
if (nc_create(FILE, NC_NETCDF4, &ncid)) ERR;
/* Create a dimension. */
if (nc_def_dim(ncid, STORY_DIM_NAME, STORY_LEN, &dimid)) ERR;
/* Create one var. */
if (nc_def_var(ncid, STORY_VAR_NAME, NC_STRING, NDIMS1, &dimid, &v1id)) ERR;
/* Write metadata to file. */
if (nc_enddef(ncid)) ERR;
/* Set up slab for this process. */
count[0] = STORY_LEN;
/* Write phoney data. */
if (nc_put_vara(ncid, v1id, start, count, story)) ERR;
/* Close the netcdf file. */
if (nc_close(ncid)) ERR;
}
/* Now try parallel read. */
if (nc_open_par(FILE, 0, comm, info, &ncid)) ERR;
/* Task 0 reads all 8 lines, other tasks read 0. */
if (nc_get_vara(ncid, v1id, start, count, story_in)) ERR;
if (!mpi_rank)
{
for (s = 0; s < STORY_LEN; s++)
if (strcmp(story_in[s], story[s])) ERR;
if (nc_free_string(STORY_LEN, (char **)story_in)) ERR;
}
/* Close the netcdf file. */
if (nc_close(ncid)) ERR;
}
}
if (!mpi_rank)
SUMMARIZE_ERR;
if (!mpi_rank)
printf("*** testing NC_BYTE type and parallel I/O...");
{
/* This test is related to
* https://github.com/Unidata/netcdf-c/issues/1462. */
int ncid, varid;
signed char test_data_in, test_data = 42;
/* Crate a file with a scalar NC_BYTE value. */
if (nc_create_par(FILE, NC_NETCDF4, MPI_COMM_WORLD, MPI_INFO_NULL,
&ncid)) ERR;
if (nc_def_var(ncid, "fred", NC_BYTE, 0, NULL, &varid)) ERR;
if (nc_enddef(ncid)) ERR;
if (nc_put_var_schar(ncid, varid, &test_data));
if (nc_close(ncid)) ERR;
/* Reopen the file and check. */
if (nc_open_par(FILE, 0, comm, info, &ncid)) ERR;
if (nc_get_var_schar(ncid, varid, &test_data_in));
if (test_data_in != test_data) ERR;
if (nc_close(ncid)) ERR;
}
if (!mpi_rank)
SUMMARIZE_ERR;
/* Shut down MPI. */
MPI_Finalize();
if (!mpi_rank)
FINAL_RESULTS;
return 0;
} }

View File

@ -77,8 +77,6 @@ NC_RO_sync,
tst_abort, tst_abort,
tst_close, tst_close,
NC_RO_set_fill, NC_RO_set_fill,
NC_NOTNC3_inq_base_pe,
NC_NOTNC3_set_base_pe,
tst_inq_format, tst_inq_format,
tst_inq_format_extended, tst_inq_format_extended,