Switch test for nc_inq_unlimdim and nc_inq_unlimdims to use the same ordering as

the rest of the dimension queries.  Correct error in library where types used
in sub-group variables but that were added to the file after the sub-group was
created weren't available for sub-group variables to use.  Start cleaning up
test suite and un-commenting tests that were commented out (got up to
nc_test4/tst_fills2.c, alphabetically) before running into an error in HDF5.
This commit is contained in:
Quincey Koziol 2013-12-15 19:55:41 -06:00
parent 11e6343ae1
commit 0d42ac7e87
10 changed files with 583 additions and 366 deletions

View File

@ -7,6 +7,9 @@ Recent releases include references to Jira issue identifiers for more informatio
## 4.3.1 Released TBD
* Corrected behavior of nc_inq_unlimdim and nv_inq_unlimdims to report dimids
in same order as nc_inq_dimids
* Addressed an issue reported by Jeff Whitaker regarding `nc_inq_nvars` returning an incorrect number of dimensions (this issue was introduced in 4.3.1-rc5). Integrated a test contributed by Jeff Whitaker.
### 4.3.1-rc5 Released 2013-12-06

View File

@ -42,6 +42,24 @@ extern int num_spaces;
#define DIMENSION_LIST "DIMENSION_LIST"
#define NAME "NAME"
/* Struct to track information about objects in a group, for nc4_rec_read_metadata() */
typedef struct NC4_rec_read_metadata_obj_info
{
hid_t oid; /* HDF5 object ID */
char oname[NC_MAX_NAME + 1]; /* Name of object */
H5G_stat_t statbuf; /* Information about the object */
struct NC4_rec_read_metadata_obj_info *next; /* Pointer to next node in list */
} NC4_rec_read_metadata_obj_info_t;
/* User data struct for call to H5Literate() in nc4_rec_read_metadata() */
/* Tracks the groups, named datatypes and datasets in the group, for later use */
typedef struct NC4_rec_read_metadata_ud
{
NC4_rec_read_metadata_obj_info_t *types_head, *types_tail; /* Pointers to head & tail of list of named datatypes */
NC4_rec_read_metadata_obj_info_t *dsets_head, *dsets_tail; /* Pointers to head & tail of list of datasets */
NC4_rec_read_metadata_obj_info_t *grps_head, *grps_tail; /* Pointers to head & tail of list of groups */
} NC4_rec_read_metadata_ud_t;
/* Forward */
static int NC4_enddef(int ncid);
static int nc4_rec_read_metadata(NC_GRP_INFO_T *grp);
@ -1675,6 +1693,11 @@ read_grp_atts(NC_GRP_INFO_T *grp)
num_obj = H5Aget_num_attrs(grp->hdf_grpid);
for (i = 0; i < num_obj; i++)
{
/* Close an attribute from previous loop iteration */
/* (Should be from 'continue' statement, below) */
if (attid && H5Aclose(attid) < 0)
BAIL(NC_EHDFERR);
if ((attid = H5Aopen_idx(grp->hdf_grpid, (unsigned int)i)) < 0)
BAIL(NC_EATTMETA);
if (H5Aget_name(attid, NC_MAX_NAME + 1, obj_name) < 0)
@ -1717,9 +1740,6 @@ read_grp_atts(NC_GRP_INFO_T *grp)
if (type)
att->class = type->class;
}
if (H5Aclose(attid) < 0)
BAIL(NC_EATTMETA);
attid = 0;
}
exit:
@ -1784,111 +1804,120 @@ read_dataset(NC_GRP_INFO_T *grp, hid_t datasetid, const char *obj_name,
return retval;
}
static int
nc4_iter_list_add(NC4_rec_read_metadata_obj_info_t **head,
NC4_rec_read_metadata_obj_info_t **tail,
NC4_rec_read_metadata_obj_info_t *oinfo)
{
if (*tail)
{
assert(*head);
(*tail)->next = oinfo;
*tail = oinfo;
}
else
{
assert(NULL == *head);
*head = *tail = oinfo;
}
return (NC_NOERR);
}
static int
nc4_rec_read_metadata_cb(hid_t grpid, const char *name, const H5L_info_t *info,
void *_op_data)
{
hid_t oid=-1;
H5G_stat_t statbuf;
char oname[NC_MAX_NAME + 1];
NC_GRP_INFO_T *grp = (NC_GRP_INFO_T *) (_op_data);
NC_HDF5_FILE_INFO_T *h5 = grp->nc4_info;
NC4_rec_read_metadata_ud_t *udata = (NC4_rec_read_metadata_ud_t *)_op_data; /* Pointer to user data for callback */
NC4_rec_read_metadata_obj_info_t *oinfo; /* Pointer to info for object */
int retval = H5_ITER_CONT;
/* Open this critter. */
if ((oid = H5Oopen(grpid, name, H5P_DEFAULT)) < 0)
return H5_ITER_ERROR;
/* Allocate memory for the object's info */
if (!(oinfo = calloc(1, sizeof(NC4_rec_read_metadata_obj_info_t))))
return NC_ENOMEM;
/* Open this critter. */
if ((oinfo->oid = H5Oopen(grpid, name, H5P_DEFAULT)) < 0)
return H5_ITER_ERROR;
/* Get more info about the object.*/
if (H5Gget_objinfo(oid, ".", 1, &statbuf) < 0)
return H5_ITER_ERROR;
/* Get info about the object.*/
if (H5Gget_objinfo(oinfo->oid, ".", 1, &oinfo->statbuf) < 0)
return H5_ITER_ERROR;
strncpy(oname, name, NC_MAX_NAME);
strncpy(oinfo->oname, name, NC_MAX_NAME);
/* Deal with objects. */
switch(statbuf.type)
{
case H5G_GROUP:
{
NC_GRP_INFO_T *child_grp;
/* Add object to list, for later */
switch(oinfo->statbuf.type)
{
case H5G_GROUP:
LOG((3, "found group %s", oinfo->oname));
if (nc4_iter_list_add(&udata->grps_head, &udata->grps_tail, oinfo))
BAIL(H5_ITER_ERROR);
break;
LOG((3, "found group %s", oname));
case H5G_DATASET:
LOG((3, "found dataset %s", oinfo->oname));
if (nc4_iter_list_add(&udata->dsets_head, &udata->dsets_tail, oinfo))
BAIL(H5_ITER_ERROR);
break;
/* Add group to file's hierarchy */
if (nc4_grp_list_add(&(grp->children), h5->next_nc_grpid++,
grp, grp->nc4_info->controller, oname, &child_grp))
return H5_ITER_ERROR;
case H5G_TYPE:
LOG((3, "found datatype %s", oinfo->oname));
if (nc4_iter_list_add(&udata->types_head, &udata->types_tail, oinfo))
BAIL(H5_ITER_ERROR);
break;
/* Recursively read the child group's metadata */
if (nc4_rec_read_metadata(child_grp))
return H5_ITER_ERROR;
}
break;
case H5G_DATASET:
{
int retval = NC_NOERR;
LOG((3, "found dataset %s", oname));
/* Learn all about this dataset, which may be a dimscale
* (i.e. dimension metadata), or real data. */
if ((retval = read_dataset(grp, oid, oname, &statbuf)))
{
/* Allow NC_EBADTYPID to transparently skip over datasets
* which have a datatype that netCDF-4 doesn't undertand
* (currently), but break out of iteration for other
* errors.
*/
if(NC_EBADTYPID != retval)
return H5_ITER_ERROR;
}
}
break;
case H5G_TYPE:
LOG((3, "found datatype %s", oname));
if (read_type(grp, oid, oname))
return H5_ITER_ERROR;
break;
default:
LOG((0, "Unknown object class %d in %s!", statbuf.type, __func__));
default:
LOG((0, "Unknown object class %d in %s!", oinfo->statbuf.type, __func__));
BAIL(H5_ITER_ERROR);
}
/* Close the object */
if (H5Oclose(oid) < 0)
return H5_ITER_ERROR;
return (H5_ITER_CONT);
exit:
if (retval)
{
if (oinfo)
{
if (oinfo->oid > 0 && H5Oclose(oinfo->oid) < 0)
BAIL2(H5_ITER_ERROR);
free(oinfo);
}
}
return (retval);
}
static int
nc4_rec_read_metadata(NC_GRP_INFO_T *grp)
{
NC4_rec_read_metadata_ud_t udata; /* User data for iteration */
NC4_rec_read_metadata_obj_info_t *oinfo; /* Pointer to info for object */
hsize_t idx=0;
int retval;
hid_t pid = 0;
unsigned crt_order_flags = 0;
H5_index_t iter_index;
int retval = NC_NOERR; /* everything worked! */
assert(grp && grp->name);
LOG((3, "%s: grp->name %s", __func__, grp->name));
/* Portably initialize user data for iteration */
memset(&udata, 0, sizeof(udata));
/* Open this HDF5 group and retain its grpid. It will remain open
* with HDF5 until this file is nc_closed. */
if (!grp->hdf_grpid)
{
if (grp->parent)
{
if ((grp->hdf_grpid = H5Gopen2(grp->parent->hdf_grpid,
if ((grp->hdf_grpid = H5Gopen2(grp->parent->hdf_grpid,
grp->name, H5P_DEFAULT)) < 0)
return NC_EHDFERR;
BAIL(NC_EHDFERR);
}
else
{
if ((grp->hdf_grpid = H5Gopen2(grp->nc4_info->hdfid,
"/", H5P_DEFAULT)) < 0)
return NC_EHDFERR;
BAIL(NC_EHDFERR);
}
}
assert(grp->hdf_grpid > 0);
@ -1897,7 +1926,7 @@ nc4_rec_read_metadata(NC_GRP_INFO_T *grp)
pid = H5Gget_create_plist(grp->hdf_grpid);
H5Pget_link_creation_order(pid, &crt_order_flags);
if (H5Pclose(pid) < 0)
return NC_EHDFERR;
BAIL(NC_EHDFERR);
/* Set the iteration index to use */
if (crt_order_flags & H5P_CRT_ORDER_TRACKED)
@ -1908,23 +1937,125 @@ nc4_rec_read_metadata(NC_GRP_INFO_T *grp)
/* Without creation ordering, file must be read-only. */
if (!h5->no_write)
return NC_ECANTWRITE;
BAIL(NC_ECANTWRITE);
iter_index = H5_INDEX_NAME;
}
/* Iterate over links in this group, processing all the objects
* and recursively handling the types encountered
/* Iterate over links in this group, building lists for the types,
* datasets and groups encountered
*/
if (H5Literate(grp->hdf_grpid, iter_index, H5_ITER_INC, &idx,
nc4_rec_read_metadata_cb, (void *)grp) < 0)
return NC_EHDFERR;
nc4_rec_read_metadata_cb, (void *)&udata) < 0)
BAIL(NC_EHDFERR);
/* Process the types, datasets and groups found */
/* (Make certain it's in this order, so that the types are available for
* future datasets & child groups)
*/
for (oinfo = udata.types_head; oinfo; oinfo = udata.types_head)
{
/* Process the named datatype */
if ((retval = read_type(grp, oinfo->oid, oinfo->oname)))
BAIL(retval);
/* Close the object */
if (H5Oclose(oinfo->oid) < 0)
BAIL(NC_EHDFERR);
/* Advance to next node, free current node */
udata.types_head = oinfo->next;
free(oinfo);
}
for (oinfo = udata.dsets_head; oinfo; oinfo = udata.dsets_head)
{
/* Learn all about this dataset, which may be a dimscale
* (i.e. dimension metadata), or real data. */
if ((retval = read_dataset(grp, oinfo->oid, oinfo->oname, &oinfo->statbuf)))
{
/* Allow NC_EBADTYPID to transparently skip over datasets
* which have a datatype that netCDF-4 doesn't undertand
* (currently), but break out of iteration for other
* errors.
*/
if(NC_EBADTYPID != retval)
BAIL(retval);
else
retval = NC_NOERR;
}
/* Close the object */
if (H5Oclose(oinfo->oid) < 0)
BAIL(NC_EHDFERR);
/* Advance to next node, free current node */
udata.dsets_head = oinfo->next;
free(oinfo);
}
for (oinfo = udata.grps_head; oinfo; oinfo = udata.grps_head)
{
NC_GRP_INFO_T *child_grp;
NC_HDF5_FILE_INFO_T *h5 = grp->nc4_info;
/* Add group to file's hierarchy */
if ((retval = nc4_grp_list_add(&(grp->children), h5->next_nc_grpid++,
grp, grp->nc4_info->controller, oinfo->oname, &child_grp)))
BAIL(retval);
/* Recursively read the child group's metadata */
if ((retval = nc4_rec_read_metadata(child_grp)))
BAIL(retval);
/* Close the object */
if (H5Oclose(oinfo->oid) < 0)
BAIL(NC_EHDFERR);
/* Advance to next node, free current node */
udata.grps_head = oinfo->next;
free(oinfo);
}
/* Scan the group for global (i.e. group-level) attributes. */
if ((retval = read_grp_atts(grp)))
return retval;
BAIL(retval);
return NC_NOERR; /* everything worked! */
exit:
/* Clean up local information on error, if anything remains */
if (retval)
{
for (oinfo = udata.types_head; oinfo; oinfo = udata.types_head)
{
/* Close the object */
if (H5Oclose(oinfo->oid) < 0)
BAIL(NC_EHDFERR);
/* Advance to next node, free current node */
udata.types_head = oinfo->next;
free(oinfo);
}
for (oinfo = udata.dsets_head; oinfo; oinfo = udata.dsets_head)
{
/* Close the object */
if (H5Oclose(oinfo->oid) < 0)
BAIL(NC_EHDFERR);
/* Advance to next node, free current node */
udata.dsets_head = oinfo->next;
free(oinfo);
}
for (oinfo = udata.grps_head; oinfo; oinfo = udata.grps_head)
{
/* Close the object */
if (H5Oclose(oinfo->oid) < 0)
BAIL(NC_EHDFERR);
/* Advance to next node, free current node */
udata.grps_head = oinfo->next;
free(oinfo);
}
}
return retval;
}
/* Open a netcdf-4 file. Things have already been kicked off in

View File

@ -21,7 +21,7 @@ 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 tst_sync tst_h_strbug tst_h_refs \
tst_h_scalar tst_nvars
tst_h_scalar
check_PROGRAMS = $(NC4_TESTS) renamegroup
@ -120,7 +120,7 @@ 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 run_get_knmi_files.sh CMakeLists.txt \
run_grp_rename.sh ref_tst_nvars.nc
run_grp_rename.sh
CLEANFILES = tst_mpi_parallel.bin cdm_sea_soundings.nc bm_chunking.nc \
bm_radar.nc bm_radar1.nc radar_3d_compression_test.txt \

Binary file not shown.

View File

@ -683,13 +683,11 @@ main(int argc, char **argv)
{
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_uchar(ncid, NC_GLOBAL, ATT_UCHAR_NAME, NC_UBYTE, 0, 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;
@ -701,8 +699,8 @@ main(int argc, char **argv)
{
int ncid;
signed char schar_in[ATT_LEN];
unsigned char uchar_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];
@ -716,6 +714,9 @@ main(int argc, char **argv)
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_uchar(ncid, NC_GLOBAL, ATT_UCHAR_NAME, uchar_in)) ERR;
if (nc_inq_att(ncid, NC_GLOBAL, ATT_UCHAR_NAME, &xtype, &len)) ERR;
if (len || xtype != NC_UBYTE) 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;
@ -737,10 +738,11 @@ main(int argc, char **argv)
}
SUMMARIZE_ERR;
printf("*** testing zero-length attributes and redef...(this test skipped for HDF5-1.8.0 beta1");
printf("*** testing zero-length attributes and redef...");
{
int ncid;
signed char schar_in[ATT_LEN];
unsigned char uchar_in[ATT_LEN];
short short_in[ATT_LEN];
int int_in[ATT_LEN];
float float_in[ATT_LEN];
@ -753,7 +755,7 @@ main(int argc, char **argv)
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_uchar(ncid, NC_GLOBAL, ATT_UCHAR_NAME, NC_UBYTE, 0, 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;
@ -765,6 +767,7 @@ main(int argc, char **argv)
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_uchar(ncid, NC_GLOBAL, ATT_UCHAR_NAME, uchar_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;

View File

@ -179,6 +179,7 @@ main(int argc, char **argv)
unsigned short usvalue_in;
long long int64_in;
unsigned long long uint64_in;
float float_in;
double double_in;
/* Write a scalar NC_INT with value X_MAX_INT. */
@ -210,9 +211,8 @@ main(int argc, char **argv)
if (int64_in != ivalue) ERR;
if (nc_get_var_ulonglong(ncid, varid, &uint64_in)) ERR;
if (uint64_in != ivalue) ERR;
/* if (nc_get_var_float(ncid, varid, &float_in)) ERR;
f2 = (float)ivalue;
if (float_in != f2) ERR;*/
if (nc_get_var_float(ncid, varid, &float_in)) ERR;
if (float_in != (float)ivalue) ERR;
if (nc_get_var_double(ncid, varid, &double_in)) ERR;
if (double_in != (double)ivalue) ERR;
if (nc_close(ncid)) ERR;

View File

@ -986,12 +986,28 @@ main(int argc, char **argv)
dimids_in, &natts_in)) ERR;
if (nc_inq_dim(ncid, dimids_in[3], NULL, &len_in)) ERR;
if (len_in != 0) ERR;
/* if (nc_get_var_double(ncid, pres_varid, (double *)pres_in)) ERR;*/
memset(pres_in, 0, sizeof(pres_in));
if (nc_get_var_double(ncid, pres_varid, (double *)pres_in)) ERR;
/* Check our pressure values. */
for (i = 0; i < LAT_LEN; i++)
for (j = 0; j < LON_LEN; j++)
for (k = 0; k < LEVEL_LEN; k++)
for (l = 0; l <TIME_LEN; l++)
if (0 != pres_in[i][j][k][l]) ERR;
if (nc_inq_var(ncid, hp_varid, NULL, NULL, &ndims_in,
dimids_in, NULL)) ERR;
if (nc_inq_dim(ncid, dimids_in[2], NULL, &len_in)) ERR;
if (len_in != 0) ERR;
/* if (nc_get_var_ushort(ncid, hp_varid, (unsigned short *)hp_in)) ERR;*/
memset(hp_in, 0, sizeof(hp_in));
if (nc_get_var_ushort(ncid, hp_varid, (unsigned short *)hp_in)) ERR;
/* Check our hp values. */
for (i = 0; i < LAT_LEN; i++)
for (j = 0; j < LON_LEN; j++)
for (l = 0; l <TIME_LEN; l++)
if (0 != hp_in[i][j][l]) ERR;
/* Now use nc_put_vara to really write pressure and hp
* data. Write TIME_LEN (4) records of each. */

View File

@ -70,75 +70,106 @@ main(int argc, char **argv)
if (nc_close(ncid)) ERR;
/* free(data_in); */
}
SUMMARIZE_ERR;
/* printf("*** testing read of string record var with no data..."); */
/* { */
/* #define STRING_VAR_NAME "I_Have_A_Dream" */
/* #define NDIMS_STRING 1 */
/* #define FILLVALUE_LEN 1 /\* There is 1 string, the empty one. *\/ */
/* #define DATA_START 2 /\* Real data here. *\/ */
printf("*** testing read of string record var w/fill-value with no data...");
{
#undef STRING_VAR_NAME
#define STRING_VAR_NAME "I_Have_A_Dream"
#undef NDIMS_STRING
#define NDIMS_STRING 1
#define FILLVALUE_LEN 1 /* There is 1 string, the empty one. */
#undef DATA_START
#define DATA_START 2 /* Real data here. */
/* int ncid, varid, dimid, varid_in; */
/* const char *missing_val[FILLVALUE_LEN] = {""}; */
/* const char *missing_val_in[FILLVALUE_LEN]; */
/* const char *data_out[1] = { */
/* "With this faith, we will be able to hew out of the mountain of " */
/* "despair a stone of hope. With this faith, we will be able to " */
/* "transform the jangling discords of our nation into a beautiful " */
/* "symphony of brotherhood. With this faith, we will be able to work " */
/* "together, to pray together, to struggle together, to go to jail " */
/* "together, to stand up for freedom together, knowing that we will " */
/* "be free one day."}; */
/* char *data_in; */
/* size_t index = DATA_START; */
int ncid, varid, dimid, varid_in;
const char *missing_val[FILLVALUE_LEN] = {""};
const char *missing_val_in[FILLVALUE_LEN];
const char *data_out[1] = {
"With this faith, we will be able to hew out of the mountain of "
"despair a stone of hope. With this faith, we will be able to "
"transform the jangling discords of our nation into a beautiful "
"symphony of brotherhood. With this faith, we will be able to work "
"together, to pray together, to struggle together, to go to jail "
"together, to stand up for freedom together, knowing that we will "
"be free one day."};
char *data_in;
size_t index = DATA_START;
/* /\* Create file with a 1D string var. Set its fill value to the */
/* * empty string. *\/ */
/* if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR; */
/* if (nc_def_dim(ncid, "sentence", NC_UNLIMITED, &dimid)) ERR; */
/* if (nc_def_var(ncid, STRING_VAR_NAME, NC_STRING, NDIMS_STRING, */
/* &dimid, &varid)) ERR; */
/* /\* if (nc_put_att_string(ncid, varid, "_FillValue", FILLVALUE_LEN, */
/* missing_val)) ERR;*\/ */
/* Create file with a 1D string var. Set its fill value to the
* empty string. */
if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
if (nc_def_dim(ncid, "sentence", NC_UNLIMITED, &dimid)) ERR;
if (nc_def_var(ncid, STRING_VAR_NAME, NC_STRING, NDIMS_STRING,
&dimid, &varid)) ERR;
if (nc_put_att_string(ncid, varid, "_FillValue", FILLVALUE_LEN,
missing_val)) ERR;
/* /\* Check it out. *\/ */
/* /\* if (nc_inq_varid(ncid, STRING_VAR_NAME, &varid_in)) ERR; *\/ */
/* /\* if (nc_get_att_string(ncid, varid_in, "_FillValue", *\/ */
/* /\* (char **)missing_val_in)) ERR; *\/ */
/* /\* if (strcmp(missing_val[0], missing_val_in[0])) ERR; *\/ */
/* /\* if (nc_free_string(FILLVALUE_LEN, (char **)missing_val_in)) ERR; *\/ */
/* Check it out. */
if (nc_inq_varid(ncid, STRING_VAR_NAME, &varid_in)) ERR;
if (nc_get_att_string(ncid, varid_in, "_FillValue",
(char **)missing_val_in)) ERR;
if (strcmp(missing_val[0], missing_val_in[0])) ERR;
if (nc_free_string(FILLVALUE_LEN, (char **)missing_val_in)) ERR;
/* /\* Write one string, leaving some blank records which will then */
/* * get the fill value. *\/ */
/* if (nc_put_var1_string(ncid, varid_in, &index, data_out)) ERR; */
/* Write one string, leaving some blank records which will then
* get the fill value. */
if (nc_put_var1_string(ncid, varid_in, &index, data_out)) ERR;
/* /\* Get all the data from the variable. *\/ */
/* if (nc_get_var1_string(ncid, varid_in, &index, &data_in)) ERR; */
/* if (strcmp(data_in, data_out[0])) ERR; */
/* free(data_in); */
/* Get all the data from the variable. */
index = 0;
data_in = NULL;
if (nc_get_var1_string(ncid, varid_in, &index, &data_in)) ERR;
if (strcmp(data_in, missing_val[0])) ERR;
free(data_in);
index = 1;
data_in = NULL;
if (nc_get_var1_string(ncid, varid_in, &index, &data_in)) ERR;
if (strcmp(data_in, missing_val[0])) ERR;
free(data_in);
index = DATA_START;
data_in = NULL;
if (nc_get_var1_string(ncid, varid_in, &index, &data_in)) ERR;
if (strcmp(data_in, data_out[0])) ERR;
free(data_in);
/* if (nc_close(ncid)) ERR; */
if (nc_close(ncid)) ERR;
/* /\* Now re-open file, read data, and check values again. *\/ */
/* if (nc_open(FILE_NAME, NC_NOWRITE, &ncid)) ERR; */
/* /\* if (nc_inq_varid(ncid, STRING_VAR_NAME, &varid_in)) ERR; *\/ */
/* /\* if (nc_get_att_string(ncid, varid_in, "_FillValue", *\/ */
/* /\* (char **)missing_val_in)) ERR; *\/ */
/* /\* if (strcmp(missing_val[0], missing_val_in[0])) ERR; *\/ */
/* /\* if (nc_free_string(FILLVALUE_LEN, (char **)missing_val_in)) ERR; *\/ */
/* Now re-open file, read data, and check values again. */
if (nc_open(FILE_NAME, NC_NOWRITE, &ncid)) ERR;
if (nc_inq_varid(ncid, STRING_VAR_NAME, &varid_in)) ERR;
if (nc_get_att_string(ncid, varid_in, "_FillValue",
(char **)missing_val_in)) ERR;
if (strcmp(missing_val[0], missing_val_in[0])) ERR;
if (nc_free_string(FILLVALUE_LEN, (char **)missing_val_in)) ERR;
/* data_in = NULL; */
/* if (nc_get_var1_string(ncid, varid_in, &index, &data_in)) ERR; */
/* if (strcmp(data_in, data_out[0])) ERR; */
/* free(data_in); */
/* Get all the data from the variable. */
/* As of HDF5-1.8.12, reading from an unwritten chunk in a dataset with a
* variable-length datatype and a fill-value set will error, instead
* of retrieving the fill-value. -QAK
*/
#ifdef NOT_YET
index = 0;
data_in = NULL;
if (nc_get_var1_string(ncid, varid_in, &index, &data_in)) ERR;
if (strcmp(data_in, missing_val[0])) ERR;
free(data_in);
index = 1;
data_in = NULL;
if (nc_get_var1_string(ncid, varid_in, &index, &data_in)) ERR;
if (strcmp(data_in, missing_val[0])) ERR;
free(data_in);
#endif /* NOT_YET */
index = DATA_START;
data_in = NULL;
if (nc_get_var1_string(ncid, varid_in, &index, &data_in)) ERR;
if (strcmp(data_in, data_out[0])) ERR;
free(data_in);
/* if (nc_close(ncid)) ERR; */
if (nc_close(ncid)) ERR;
/* /\* free(data_in); *\/ */
/* } */
/* SUMMARIZE_ERR; */
}
SUMMARIZE_ERR;
/* printf("*** testing empty fill values of a string var..."); */
/* { */
/* #define STRING_VAR_NAME "The_String" */

View File

@ -75,6 +75,7 @@ main(int argc, char **argv)
if (nc_close(ncid)) ERR;
}
SUMMARIZE_ERR;
printf("*** testing netcdf-3 and group functions...");
{
int ncid;
@ -90,131 +91,132 @@ main(int argc, char **argv)
if (nc_close(ncid)) ERR;
}
SUMMARIZE_ERR;
/* printf("*** testing use of unlimited dim in parent group..."); */
/* { */
/* #define NDIMS_IN_VAR 1 */
/* #define NDIMS_IN_FILE 2 */
/* #define BABE_LIMIT 3 */
/* #define DIM_NAME1 "Influence" */
/* #define DIM_NAME2 "Babe_Factor" */
/* #define VAR_NAME1 "Court_of_Star_Chamber" */
/* #define VAR_NAME2 "Justice_of_the_Peace" */
/* #define VAR_NAME3 "Bosworth_Field" */
/* int ncid, dimid1, dimid2, varid1, varid2, varid3, henry_vii_id; */
/* int grpid_in, varid_in1, varid_in2, varid_in3; */
/* nc_type xtype_in; */
/* int ndims_in, dimids_in[NDIMS_IN_FILE], dimid1_in, natts; */
/* char name_in[NC_MAX_NAME + 1]; */
/* size_t len_in, index[NDIMS_IN_VAR] = {0}; */
/* long long value = NC_FILL_INT64 + 1, value_in; */
/* /\* Create a file with an unlimited dim and a limited, used by */
/* * variables in child groups. *\/ */
/* if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR; */
/* if (nc_def_dim(ncid, DIM_NAME1, NC_UNLIMITED, &dimid1)) ERR; */
/* if (nc_def_dim(ncid, DIM_NAME2, BABE_LIMIT, &dimid2)) ERR; */
/* if (nc_def_grp(ncid, HENRY_VII, &henry_vii_id)) ERR; */
/* if (nc_def_var(henry_vii_id, VAR_NAME1, NC_INT64, NDIMS_IN_VAR, &dimid1, &varid1)) ERR; */
/* if (nc_def_var(henry_vii_id, VAR_NAME2, NC_INT64, NDIMS_IN_VAR, &dimid1, &varid2)) ERR; */
/* if (nc_def_var(henry_vii_id, VAR_NAME3, NC_INT64, NDIMS_IN_VAR, &dimid2, &varid3)) ERR; */
/* /\* Check it out. Find the group by name. *\/ */
/* if (nc_inq_ncid(ncid, HENRY_VII, &grpid_in)) ERR; */
printf("*** testing use of unlimited dim in parent group...");
{
#define NDIMS_IN_VAR 1
#define NDIMS_IN_FILE 2
#define BABE_LIMIT 3
#define DIM_NAME1 "Influence"
#define DIM_NAME2 "Babe_Factor"
#define VAR_NAME1 "Court_of_Star_Chamber"
#define VAR_NAME2 "Justice_of_the_Peace"
#define VAR_NAME3 "Bosworth_Field"
int ncid, dimid1, dimid2, varid1, varid2, varid3, henry_vii_id;
int grpid_in, varid_in1, varid_in2, varid_in3;
nc_type xtype_in;
int ndims_in, dimids_in[NDIMS_IN_FILE], dimid1_in, natts;
char name_in[NC_MAX_NAME + 1];
size_t len_in, index[NDIMS_IN_VAR] = {0};
long long value = NC_FILL_INT64 + 1, value_in;
/* /\* Ensure that dimensions in parent are visible and correct. *\/ */
/* if (nc_inq_dimids(grpid_in, &ndims_in, dimids_in, 1)) ERR; */
/* if (ndims_in != NDIMS_IN_FILE || dimids_in[0] != dimid1 || dimids_in[1] != dimid2) ERR; */
/* if (nc_inq_dim(grpid_in, dimids_in[0], name_in, &len_in)) ERR; */
/* if (strcmp(name_in, DIM_NAME1) || len_in != 0) ERR; */
/* if (nc_inq_dim(grpid_in, dimids_in[1], name_in, &len_in)) ERR; */
/* if (strcmp(name_in, DIM_NAME2) || len_in != BABE_LIMIT) ERR; */
/* Create a file with an unlimited dim and a limited, used by
* variables in child groups. */
if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
if (nc_def_dim(ncid, DIM_NAME1, NC_UNLIMITED, &dimid1)) ERR;
if (nc_def_dim(ncid, DIM_NAME2, BABE_LIMIT, &dimid2)) ERR;
if (nc_def_grp(ncid, HENRY_VII, &henry_vii_id)) ERR;
if (nc_def_var(henry_vii_id, VAR_NAME1, NC_INT64, NDIMS_IN_VAR, &dimid1, &varid1)) ERR;
if (nc_def_var(henry_vii_id, VAR_NAME2, NC_INT64, NDIMS_IN_VAR, &dimid1, &varid2)) ERR;
if (nc_def_var(henry_vii_id, VAR_NAME3, NC_INT64, NDIMS_IN_VAR, &dimid2, &varid3)) ERR;
/* Check it out. Find the group by name. */
if (nc_inq_ncid(ncid, HENRY_VII, &grpid_in)) ERR;
/* /\* Check the vars in the group. *\/ */
/* if (nc_inq_varid(grpid_in, VAR_NAME1, &varid_in1)) ERR; */
/* if (nc_inq_varid(grpid_in, VAR_NAME2, &varid_in2)) ERR; */
/* if (nc_inq_varid(grpid_in, VAR_NAME3, &varid_in3)) ERR; */
/* if (varid_in1 != varid1 || varid_in2 != varid2 || varid_in3 != varid3) ERR; */
/* if (nc_inq_var(grpid_in, varid1, name_in, &xtype_in, &ndims_in, &dimid1_in, &natts)) ERR; */
/* if (strcmp(name_in, VAR_NAME1) || xtype_in != NC_INT64 || ndims_in != NDIMS_IN_VAR || */
/* dimid1_in != dimid1 || natts != 0) ERR; */
/* if (nc_inq_var(grpid_in, varid2, name_in, &xtype_in, &ndims_in, &dimid1_in, &natts)) ERR; */
/* if (strcmp(name_in, VAR_NAME2) || xtype_in != NC_INT64 || ndims_in != NDIMS_IN_VAR || */
/* dimid1_in != dimid1 || natts != 0) ERR; */
/* if (nc_inq_var(grpid_in, varid3, name_in, &xtype_in, &ndims_in, &dimid1_in, &natts)) ERR; */
/* if (strcmp(name_in, VAR_NAME3) || xtype_in != NC_INT64 || ndims_in != NDIMS_IN_VAR || */
/* dimid1_in != dimid2 || natts != 0) ERR; */
/* Ensure that dimensions in parent are visible and correct. */
if (nc_inq_dimids(grpid_in, &ndims_in, dimids_in, 1)) ERR;
if (ndims_in != NDIMS_IN_FILE || dimids_in[0] != dimid1 || dimids_in[1] != dimid2) ERR;
if (nc_inq_dim(grpid_in, dimids_in[0], name_in, &len_in)) ERR;
if (strcmp(name_in, DIM_NAME1) || len_in != 0) ERR;
if (nc_inq_dim(grpid_in, dimids_in[1], name_in, &len_in)) ERR;
if (strcmp(name_in, DIM_NAME2) || len_in != BABE_LIMIT) ERR;
/* /\* Write one value to one variable. *\/ */
/* if (nc_put_var1_longlong(grpid_in, varid_in1, index, &value)) ERR; */
/* Check the vars in the group. */
if (nc_inq_varid(grpid_in, VAR_NAME1, &varid_in1)) ERR;
if (nc_inq_varid(grpid_in, VAR_NAME2, &varid_in2)) ERR;
if (nc_inq_varid(grpid_in, VAR_NAME3, &varid_in3)) ERR;
if (varid_in1 != varid1 || varid_in2 != varid2 || varid_in3 != varid3) ERR;
if (nc_inq_var(grpid_in, varid1, name_in, &xtype_in, &ndims_in, &dimid1_in, &natts)) ERR;
if (strcmp(name_in, VAR_NAME1) || xtype_in != NC_INT64 || ndims_in != NDIMS_IN_VAR ||
dimid1_in != dimid1 || natts != 0) ERR;
if (nc_inq_var(grpid_in, varid2, name_in, &xtype_in, &ndims_in, &dimid1_in, &natts)) ERR;
if (strcmp(name_in, VAR_NAME2) || xtype_in != NC_INT64 || ndims_in != NDIMS_IN_VAR ||
dimid1_in != dimid1 || natts != 0) ERR;
if (nc_inq_var(grpid_in, varid3, name_in, &xtype_in, &ndims_in, &dimid1_in, &natts)) ERR;
if (strcmp(name_in, VAR_NAME3) || xtype_in != NC_INT64 || ndims_in != NDIMS_IN_VAR ||
dimid1_in != dimid2 || natts != 0) ERR;
/* /\* Read one value from the second unlim dim variable. It should */
/* * be the fill value. *\/ */
/* if (nc_get_var1_longlong(grpid_in, varid_in2, index, &value_in)) ERR; */
/* if (value_in != NC_FILL_INT64) ERR; */
/* Write one value to one variable. */
if (nc_put_var1_longlong(grpid_in, varid_in1, index, &value)) ERR;
/* /\* Read one value from the variable with limited dim. It should */
/* * be the fill value. *\/ */
/* if (nc_get_var1_longlong(grpid_in, varid_in3, index, &value_in)) ERR; */
/* if (value_in != NC_FILL_INT64) ERR; */
/* Read one value from the second unlim dim variable. It should
* be the fill value. */
if (nc_get_var1_longlong(grpid_in, varid_in2, index, &value_in)) ERR;
if (value_in != NC_FILL_INT64) ERR;
/* /\* Attempt to read beyond end of dimensions to generate error. *\/ */
/* index[0] = BABE_LIMIT; */
/* if (nc_get_var1_longlong(grpid_in, varid_in1, index, &value_in) != NC_EINVALCOORDS) ERR; */
/* if (nc_get_var1_longlong(grpid_in, varid_in2, index, &value_in) != NC_EINVALCOORDS) ERR; */
/* if (nc_get_var1_longlong(grpid_in, varid_in3, index, &value_in) != NC_EINVALCOORDS) ERR; */
/* Read one value from the variable with limited dim. It should
* be the fill value. */
if (nc_get_var1_longlong(grpid_in, varid_in3, index, &value_in)) ERR;
if (value_in != NC_FILL_INT64) ERR;
/* if (nc_close(ncid)) ERR; */
/* Attempt to read beyond end of dimensions to generate error. */
index[0] = BABE_LIMIT;
if (nc_get_var1_longlong(grpid_in, varid_in1, index, &value_in) != NC_EINVALCOORDS) ERR;
if (nc_get_var1_longlong(grpid_in, varid_in2, index, &value_in) != NC_EINVALCOORDS) ERR;
if (nc_get_var1_longlong(grpid_in, varid_in3, index, &value_in) != NC_EINVALCOORDS) ERR;
/* /\* Check it out again. *\/ */
/* if (nc_open(FILE_NAME, NC_NOWRITE, &ncid)) ERR; */
if (nc_close(ncid)) ERR;
/* /\* Find the group by name. *\/ */
/* if (nc_inq_ncid(ncid, HENRY_VII, &grpid_in)) ERR; */
/* Check it out again. */
if (nc_open(FILE_NAME, NC_NOWRITE, &ncid)) ERR;
/* /\* Ensure that dimensions in parent are visible and correct. *\/ */
/* if (nc_inq_dimids(grpid_in, &ndims_in, dimids_in, 1)) ERR; */
/* if (ndims_in != NDIMS_IN_FILE || dimids_in[0] != dimid1 || dimids_in[1] != dimid2) ERR; */
/* if (nc_inq_dim(grpid_in, dimids_in[0], name_in, &len_in)) ERR; */
/* if (strcmp(name_in, DIM_NAME1) || len_in != 1) ERR; */
/* if (nc_inq_dim(grpid_in, dimids_in[1], name_in, &len_in)) ERR; */
/* if (strcmp(name_in, DIM_NAME2) || len_in != BABE_LIMIT) ERR; */
/* Find the group by name. */
if (nc_inq_ncid(ncid, HENRY_VII, &grpid_in)) ERR;
/* /\* Check the vars in the group. *\/ */
/* if (nc_inq_varid(grpid_in, VAR_NAME1, &varid_in1)) ERR; */
/* if (nc_inq_varid(grpid_in, VAR_NAME2, &varid_in2)) ERR; */
/* if (nc_inq_varid(grpid_in, VAR_NAME3, &varid_in3)) ERR; */
/* if (varid_in1 != varid1 || varid_in2 != varid2 || varid_in3 != varid3) ERR; */
/* if (nc_inq_var(grpid_in, varid1, name_in, &xtype_in, &ndims_in, &dimid1_in, &natts)) ERR; */
/* if (strcmp(name_in, VAR_NAME1) || xtype_in != NC_INT64 || ndims_in != NDIMS_IN_VAR || */
/* dimid1_in != dimid1 || natts != 0) ERR; */
/* if (nc_inq_var(grpid_in, varid2, name_in, &xtype_in, &ndims_in, &dimid1_in, &natts)) ERR; */
/* if (strcmp(name_in, VAR_NAME2) || xtype_in != NC_INT64 || ndims_in != NDIMS_IN_VAR || */
/* dimid1_in != dimid1 || natts != 0) ERR; */
/* if (nc_inq_var(grpid_in, varid3, name_in, &xtype_in, &ndims_in, &dimid1_in, &natts)) ERR; */
/* if (strcmp(name_in, VAR_NAME3) || xtype_in != NC_INT64 || ndims_in != NDIMS_IN_VAR || */
/* dimid1_in != dimid2 || natts != 0) ERR; */
/* Ensure that dimensions in parent are visible and correct. */
if (nc_inq_dimids(grpid_in, &ndims_in, dimids_in, 1)) ERR;
if (ndims_in != NDIMS_IN_FILE || dimids_in[0] != dimid1 || dimids_in[1] != dimid2) ERR;
if (nc_inq_dim(grpid_in, dimids_in[0], name_in, &len_in)) ERR;
if (strcmp(name_in, DIM_NAME1) || len_in != 1) ERR;
if (nc_inq_dim(grpid_in, dimids_in[1], name_in, &len_in)) ERR;
if (strcmp(name_in, DIM_NAME2) || len_in != BABE_LIMIT) ERR;
/* /\* Read one value from the second unlim dim variable. It should */
/* * be the fill value. *\/ */
/* index[0] = 0; */
/* if (nc_get_var1_longlong(grpid_in, varid_in2, index, &value_in)) ERR; */
/* if (value_in != NC_FILL_INT64) ERR; */
/* Check the vars in the group. */
if (nc_inq_varid(grpid_in, VAR_NAME1, &varid_in1)) ERR;
if (nc_inq_varid(grpid_in, VAR_NAME2, &varid_in2)) ERR;
if (nc_inq_varid(grpid_in, VAR_NAME3, &varid_in3)) ERR;
if (varid_in1 != varid1 || varid_in2 != varid2 || varid_in3 != varid3) ERR;
if (nc_inq_var(grpid_in, varid1, name_in, &xtype_in, &ndims_in, &dimid1_in, &natts)) ERR;
if (strcmp(name_in, VAR_NAME1) || xtype_in != NC_INT64 || ndims_in != NDIMS_IN_VAR ||
dimid1_in != dimid1 || natts != 0) ERR;
if (nc_inq_var(grpid_in, varid2, name_in, &xtype_in, &ndims_in, &dimid1_in, &natts)) ERR;
if (strcmp(name_in, VAR_NAME2) || xtype_in != NC_INT64 || ndims_in != NDIMS_IN_VAR ||
dimid1_in != dimid1 || natts != 0) ERR;
if (nc_inq_var(grpid_in, varid3, name_in, &xtype_in, &ndims_in, &dimid1_in, &natts)) ERR;
if (strcmp(name_in, VAR_NAME3) || xtype_in != NC_INT64 || ndims_in != NDIMS_IN_VAR ||
dimid1_in != dimid2 || natts != 0) ERR;
/* /\* Read one value from the variable with limited dim. It should */
/* * be the fill value. *\/ */
/* if (nc_get_var1_longlong(grpid_in, varid_in3, index, &value_in)) ERR; */
/* if (value_in != NC_FILL_INT64) ERR; */
/* Read one value from the second unlim dim variable. It should
* be the fill value. */
index[0] = 0;
if (nc_get_var1_longlong(grpid_in, varid_in2, index, &value_in)) ERR;
if (value_in != NC_FILL_INT64) ERR;
/* /\* Attempt to read beyond end of dimensions to generate error. *\/ */
/* index[0] = BABE_LIMIT; */
/* if (nc_get_var1_longlong(grpid_in, varid_in1, index, &value_in) != NC_EINVALCOORDS) ERR; */
/* if (nc_get_var1_longlong(grpid_in, varid_in2, index, &value_in) != NC_EINVALCOORDS) ERR; */
/* if (nc_get_var1_longlong(grpid_in, varid_in3, index, &value_in) != NC_EINVALCOORDS) ERR; */
/* Read one value from the variable with limited dim. It should
* be the fill value. */
if (nc_get_var1_longlong(grpid_in, varid_in3, index, &value_in)) ERR;
if (value_in != NC_FILL_INT64) ERR;
/* if (nc_close(ncid)) ERR; */
/* } */
/* Attempt to read beyond end of dimensions to generate error. */
index[0] = BABE_LIMIT;
if (nc_get_var1_longlong(grpid_in, varid_in1, index, &value_in) != NC_EINVALCOORDS) ERR;
if (nc_get_var1_longlong(grpid_in, varid_in2, index, &value_in) != NC_EINVALCOORDS) ERR;
if (nc_get_var1_longlong(grpid_in, varid_in3, index, &value_in) != NC_EINVALCOORDS) ERR;
if (nc_close(ncid)) ERR;
}
SUMMARIZE_ERR;
/* SUMMARIZE_ERR; */
printf("*** testing simple nested group creates...");
{
int ncid, grp_ncid;
@ -353,8 +355,8 @@ main(int argc, char **argv)
/* Close up shop. */
if (nc_close(ncid)) ERR;
}
SUMMARIZE_ERR;
printf("*** testing simple sibling group creates...");
{
int ncid;
@ -401,10 +403,9 @@ main(int argc, char **argv)
if (strcmp(name_in, JAMES_VI_OF_SCOTLAND_AND_I_OF_ENGLAND)) ERR;
if (nc_close(ncid)) ERR;
}
SUMMARIZE_ERR;
printf("*** testing more group attributes...");
{
int ncid, num_grps, dynasty, ncid_in;
int grpid_in[MAX_SIBLING_GROUPS];
@ -461,10 +462,9 @@ main(int argc, char **argv)
if (strcmp(name_in, JAMES_VI_OF_SCOTLAND_AND_I_OF_ENGLAND)) ERR;
if (nc_close(ncid)) ERR;
}
SUMMARIZE_ERR;
printf("*** testing groups and dimensions...");
printf("*** testing groups and dimensions...");
{
int ncid;
int tudor_id;
@ -494,10 +494,9 @@ main(int argc, char **argv)
if (len_in != DIM1_LEN) ERR;
if (nc_close(ncid)) ERR;
}
SUMMARIZE_ERR;
printf("*** testing groups and vars...");
printf("*** testing groups and vars...");
{
int ncid, ndims_in;
int tudor_id;
@ -530,10 +529,9 @@ main(int argc, char **argv)
dimids_in[0] != 0 || natts_in != 0) ERR;
if (nc_close(ncid)) ERR;
}
SUMMARIZE_ERR;
printf("*** testing group functions in netCDF classic file...");
printf("*** testing group functions in netCDF classic file...");
{
int ncid;
int num_grps;
@ -551,10 +549,9 @@ main(int argc, char **argv)
if (num_grps) ERR;
if (nc_close(ncid)) ERR;
}
SUMMARIZE_ERR;
printf("*** testing groups and vars...");
printf("*** testing groups and vars...");
{
int ncid, ndims_in;
int henry_vii_id, margaret_id, james_v_of_scotland_id, mary_i_of_scotland_id;
@ -647,10 +644,9 @@ main(int argc, char **argv)
if (nc_close(ncid)) ERR;
}
SUMMARIZE_ERR;
printf("*** testing very simple groups and dimension scoping...");
printf("*** testing very simple groups and dimension scoping...");
{
int ncid;
int dimids_in[MAX_SIBLING_GROUPS], nvars_in, ndims_in;
@ -704,13 +700,11 @@ main(int argc, char **argv)
/* Close the file. */
if (nc_close(ncid)) ERR;
}
SUMMARIZE_ERR;
printf("*** testing groups and dimension scoping...");
#define NUM_GRPS 5
{
#define NUM_GRPS 5
int ncid;
int henry_vii_id, margaret_id, james_v_of_scotland_id, mary_i_of_scotland_id;
int james_i_of_england_id, tudor_id;
@ -794,8 +788,8 @@ main(int argc, char **argv)
/* Close the file. */
if (nc_close(ncid)) ERR;
}
SUMMARIZE_ERR;
printf("*** testing more groups and dimension scoping...");
{
int ncid;
@ -853,52 +847,54 @@ main(int argc, char **argv)
}
SUMMARIZE_ERR;
/* printf("*** testing groups and unlimited dimensions..."); */
/* { */
/* int ncid; */
/* int henry_vii_id; */
/* int tudor_id; */
/* int dimids_in[MAX_SIBLING_GROUPS], ndims_in; */
/* int num_grps; */
/* int dimid, dynasty, varid; */
/* size_t len_in; */
/* int natts_in; */
/* int grpids_in[10]; */
/* nc_type xtype_in; */
/* char name_in[NC_MAX_NAME + 1]; */
/* int data_out[DIM1_LEN] = {0, 2, 6}, data_in[DIM1_LEN]; */
/* size_t start[1] = {0}, count[1] = {3}; */
/* int j; */
printf("*** testing groups and unlimited dimensions...");
{
int ncid;
int henry_vii_id;
int tudor_id;
int dimids_in[MAX_SIBLING_GROUPS], ndims_in;
int num_grps;
int dimid, dynasty, varid;
size_t len_in;
int natts_in;
int grpids_in[10];
nc_type xtype_in;
char name_in[NC_MAX_NAME + 1];
int data_out[DIM1_LEN] = {0, 2, 6}, data_in[DIM1_LEN];
size_t start[1] = {0}, count[1] = {3};
int j;
/* /\* Create one group, with one var, which has one dimension, which is unlimited. *\/ */
/* if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR; */
/* if (nc_def_grp(ncid, DYNASTY, &tudor_id)) ERR; */
/* if (nc_def_dim(tudor_id, DIM1_NAME, NC_UNLIMITED, &dimid)) ERR; */
/* if (nc_def_grp(tudor_id, HENRY_VII, &henry_vii_id)) ERR; */
/* if (nc_def_var(henry_vii_id, VAR1_NAME, NC_INT, 1, &dimid, &varid)) ERR; */
/* if (nc_put_vara_int(henry_vii_id, varid, start, count, data_out)) ERR; */
/* if (nc_close(ncid)) ERR; */
/* Create one group, with one var, which has one dimension, which is unlimited. */
if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
if (nc_def_grp(ncid, DYNASTY, &tudor_id)) ERR;
if (nc_def_dim(tudor_id, DIM1_NAME, NC_UNLIMITED, &dimid)) ERR;
if (nc_def_grp(tudor_id, HENRY_VII, &henry_vii_id)) ERR;
if (nc_def_var(henry_vii_id, VAR1_NAME, NC_INT, 1, &dimid, &varid)) ERR;
if (nc_put_vara_int(henry_vii_id, varid, start, count, data_out)) ERR;
if (nc_close(ncid)) ERR;
/* Now check the file to see if the dimension and variable are
* there. */
if (nc_open(FILE_NAME, NC_NOWRITE, &ncid)) ERR;
if (nc_inq_grps(ncid, &num_grps, &dynasty)) ERR;
if (num_grps != 1) ERR;
if (nc_inq_grps(dynasty, &num_grps, grpids_in)) ERR;
if (num_grps != 1) ERR;
if (nc_inq_dim(grpids_in[0], 0, name_in, &len_in)) ERR;
if (strcmp(name_in, DIM1_NAME) || len_in != DIM1_LEN) ERR;
if (nc_inq_var(grpids_in[0], 0, name_in, &xtype_in, &ndims_in, dimids_in,
&natts_in)) ERR;
if (strcmp(name_in, VAR1_NAME) || xtype_in != NC_INT || ndims_in != 1 ||
dimids_in[0] != 0 || natts_in != 0) ERR;
if (nc_get_vara_int(grpids_in[0], 0, start, count, data_in)) ERR;
for (j=0; j<DIM1_LEN; j++)
if (data_in[j] != data_out[j]) ERR;
if (nc_close(ncid)) ERR;
}
SUMMARIZE_ERR;
/* /\* Now check the file to see if the dimension and variable are */
/* * there. *\/ */
/* if (nc_open(FILE_NAME, NC_NOWRITE, &ncid)) ERR; */
/* if (nc_inq_grps(ncid, &num_grps, &dynasty)) ERR; */
/* if (num_grps != 1) ERR; */
/* if (nc_inq_grps(dynasty, &num_grps, grpids_in)) ERR; */
/* if (num_grps != 1) ERR; */
/* if (nc_inq_dim(grpids_in[0], 0, name_in, &len_in)) ERR; */
/* if (strcmp(name_in, DIM1_NAME) || len_in != DIM1_LEN) ERR; */
/* if (nc_inq_var(grpids_in[0], 0, name_in, &xtype_in, &ndims_in, dimids_in, */
/* &natts_in)) ERR; */
/* if (strcmp(name_in, VAR1_NAME) || xtype_in != NC_INT || ndims_in != 1 || */
/* dimids_in[0] != 0 || natts_in != 0) ERR; */
/* if (nc_get_vara_int(grpids_in[0], 0, start, count, data_in)) ERR; */
/* for (j=0; j<DIM1_LEN; j++) */
/* if (data_in[j] != data_out[j]) ERR; */
/* if (nc_close(ncid)) ERR; */
/* } */
/* SUMMARIZE_ERR; */
printf("*** testing nested groups...");
{
#define DIM_NAME "dim"
#define DIM_LEN 3
#define VAR_NAME "var"
@ -910,7 +906,6 @@ main(int argc, char **argv)
#define G1_NAME "the_in_crowd"
#define G2_NAME "the_out_crowd"
#define G3_NAME "the_confused_crowd"
{
int ncid;
int dimid, varid;
int var_dims[VAR_RANK];
@ -960,13 +955,13 @@ main(int argc, char **argv)
}
SUMMARIZE_ERR;
printf("*** testing nested groups, user defined types, and enddef...");
printf("*** testing nested groups, user defined types, and enddef...");
{
#define SCI_FI "Science_Fiction"
#define BASE_SIZE 2
#define TYPE_NAME "The_Blob"
#define DATE_MOVIE "data_movie"
{
int ncid, xtype, g1id, class;
char name_in[NC_MAX_NAME + 1];
size_t len_in;
@ -1009,6 +1004,7 @@ main(int argc, char **argv)
}
SUMMARIZE_ERR;
printf("*** creating file with lots of user-defined types...");
{
int ncid, typeid;
@ -1043,8 +1039,8 @@ main(int argc, char **argv)
if (nc_close(ncid)) ERR;
}
SUMMARIZE_ERR;
printf("*** creating file with lots of groups...");
{
#define PARENT_NUM_GRPS 6
@ -1075,8 +1071,88 @@ main(int argc, char **argv)
if (nc_close(ncid)) ERR;
}
SUMMARIZE_ERR;
printf("*** creating file with type defined after group...");
{
#define GRP_NAME "phony_group"
#define CMP1_NAME "cmp1"
#define CMP2_NAME "cmp2"
int ncid, varid, varid2, grpid, numvars, retval;
int typeid, typeid2;
size_t nfields;
char name[NC_MAX_NAME + 1];
size_t size;
struct s1
{
int i1;
int i2;
};
struct s2
{
int i3;
double f1;
};
struct s1 data;
struct s2 data2;
/* Create some phony data. */
data.i1 = 5;
data.i2 = 10;
data2.i3 = 50;
data2.f1 = 100.0;
/* Create file */
if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
/* Create compound datatype #1, in root group */
if (nc_def_compound(ncid, sizeof(struct s1), CMP1_NAME, &typeid)) ERR;
if (nc_inq_compound(ncid, typeid, name, &size, &nfields)) ERR;
if (size != sizeof(struct s1) || strcmp(name, CMP1_NAME) || nfields) ERR;
if (nc_insert_compound(ncid, typeid, "i1",
NC_COMPOUND_OFFSET(struct s1, i1), NC_INT)) ERR;
if (nc_insert_compound(ncid, typeid, "i2",
NC_COMPOUND_OFFSET(struct s1, i2), NC_INT)) ERR;
/* Create variable with compound datatype #1, in root group */
if (nc_def_var(ncid, VAR_NAME, typeid, 0, NULL, &varid)) ERR;
if (nc_put_var(ncid, varid, &data)) ERR;
/* Create child group, in root group*/
if (nc_def_grp(ncid, GRP_NAME, &grpid)) ERR;
/* Close and re-open file, to guarantee the creation ordering is difficult
* for the library to deal with.
*/
if (nc_close(ncid)) ERR;
if ((retval = nc_open(FILE_NAME, NC_WRITE, &ncid))) ERR;
/* Create compound datatype #2, in root group */
if (nc_def_compound(ncid, sizeof(struct s2), CMP2_NAME, &typeid2)) ERR;
if (nc_inq_compound(ncid, typeid2, name, &size, &nfields)) ERR;
if (size != sizeof(struct s2) || strcmp(name, CMP2_NAME) || nfields) ERR;
if (nc_insert_compound(ncid, typeid2, "i3",
NC_COMPOUND_OFFSET(struct s2, i3), NC_INT)) ERR;
if (nc_insert_compound(ncid, typeid2, "f1",
NC_COMPOUND_OFFSET(struct s2, f1), NC_DOUBLE)) ERR;
/* Create variable with compound datatype #2, in root group */
if (nc_def_var(grpid, VAR_NAME, typeid2, 0, NULL, &varid2)) ERR;
if (nc_put_var(ncid, varid2, &data2)) ERR;
if (nc_close(ncid)) ERR;
/* Verify that the variable in the child group was recognized by the library */
if (nc_open(FILE_NAME, NC_NOWRITE, &ncid)) ERR;
if (nc_inq_grp_ncid(ncid, GRP_NAME, &grpid)) ERR;
if (nc_inq_nvars(grpid, &numvars)) ERR;
if (numvars != 1) ERR;
if (nc_close(ncid)) ERR;
}
SUMMARIZE_ERR;
FINAL_RESULTS;
}

View File

@ -1,43 +0,0 @@
/* This test was contributed by Jeff Whitaker to illustrate
a bug introduced in netcdf-c 4.3.1-rc5.
nc_inq_nvars should return 1.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <netcdf.h>
#define FILE_NAME "ref_tst_nvars.nc"
#define GRP_NAME "phony_group"
void
check_err(const int stat, const int line, const char *file) {
if (stat != NC_NOERR) {
(void)fprintf(stderr,"line %d of %s: %s\n", line, file, nc_strerror(stat));
fflush(stderr);
exit(1);
}
}
int
main()
{
int ncid, varid, grpid, numvars, retval;
if ((retval = nc_open(FILE_NAME, NC_NOWRITE, &ncid)))
check_err(retval,__LINE__,__FILE__);
if ((retval = nc_inq_grp_ncid(ncid, GRP_NAME, &grpid)))
check_err(retval,__LINE__,__FILE__);
if ((retval = nc_inq_nvars(grpid, &numvars)))
check_err(retval,__LINE__,__FILE__);
(void)fprintf(stdout,"number of vars %d\n", numvars);
return (numvars != 1);
}