Skip to content

Commit

Permalink
Merge branch 'master' into fix-warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
WardF authored Jan 31, 2019
2 parents 688c06d + 69c4ed6 commit 9ca942b
Show file tree
Hide file tree
Showing 24 changed files with 171 additions and 135 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,7 @@ IF(USE_HDF5 OR ENABLE_NETCDF_4)
SET(H5_USE_16_API 0)
ENDIF()

FIND_PATH(HAVE_HDF5_H hdf5.h)
FIND_PATH(HAVE_HDF5_H hdf5.h PATHS ${HDF5_INCLUDE_DIR})
IF(NOT HAVE_HDF5_H)
MESSAGE(FATAL_ERROR "Compiling a test with hdf5 failed. Either hdf5.h cannot be found, or the log messages should be checked for another reason.")
ELSE(NOT HAVE_HDF5_H)
Expand Down
6 changes: 2 additions & 4 deletions examples/C/parallel_vara.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* See COPYRIGHT notice in top-level directory.
*
*********************************************************************/

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* This example shows how to use nc_put_vara_int() to write a 2D 4-byte integer
* array in parallel and read it back using the same array partitioning pattern.
Expand Down Expand Up @@ -81,7 +80,7 @@ int main(int argc, char** argv)
{
extern int optind;
char filename[128];
int i, j, rank, nprocs, verbose=1, err;
int i, j, rank, nprocs, err;
int ncid, cmode, omode, varid, dimid[2], buf[NY][NX];
char str_att[128];
float float_att[100];
Expand All @@ -94,8 +93,7 @@ int main(int argc, char** argv)
/* get command-line arguments */
while ((i = getopt(argc, argv, "hq")) != EOF)
switch(i) {
case 'q': verbose = 0;
break;
case 'q': break;
case 'h':
default: if (rank==0) usage(argv[0]);
MPI_Finalize();
Expand Down
2 changes: 1 addition & 1 deletion include/hdf5internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ int hdf5_set_log_level();
/* These functions deal with HDF5 dimension scales. */
int rec_detach_scales(NC_GRP_INFO_T *grp, int dimid, hid_t dimscaleid);
int rec_reattach_scales(NC_GRP_INFO_T *grp, int dimid, hid_t dimscaleid);
int delete_existing_dimscale_dataset(NC_GRP_INFO_T *grp, int dimid, NC_DIM_INFO_T *dim);
int delete_dimscale_dataset(NC_GRP_INFO_T *grp, int dimid, NC_DIM_INFO_T *dim);

/* Write metadata. */
int nc4_rec_write_metadata(NC_GRP_INFO_T *grp, nc_bool_t bad_coord_order);
Expand Down
4 changes: 3 additions & 1 deletion libdap2/cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,10 @@ nclog(NCLOGDBG,"prefetch: %s",var->ncfullname);
newconstraint->selections = dceclonelist(urlconstraint->selections);

for(i=0;i<nclistlength(vars);i++) {
CDFnode* var = (CDFnode*)nclistget(vars,i);
DCEprojection* varprojection;
CDFnode* var = (CDFnode*)nclistget(vars,i);
/* Ignore invisible vars */
if(var->invisible) continue;
/* convert var to a projection */
ncstat = dapvar2projection(var,&varprojection);
if(ncstat != NC_NOERR) {THROWCHK(ncstat); goto done;}
Expand Down
5 changes: 2 additions & 3 deletions libhdf5/hdf5attr.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ nc4_get_att_special(NC_FILE_INFO_T* h5, const char* name,
int
NC4_HDF5_rename_att(int ncid, int varid, const char *name, const char *newname)
{
NC *nc;
NC_GRP_INFO_T *grp;
NC_FILE_INFO_T *h5;
NC_VAR_INFO_T *var = NULL;
Expand All @@ -174,9 +173,9 @@ NC4_HDF5_rename_att(int ncid, int varid, const char *name, const char *newname)
return NC_EMAXNAME;

/* Find info for this file, group, and h5 info. */
if ((retval = nc4_find_nc_grp_h5(ncid, &nc, &grp, &h5)))
if ((retval = nc4_find_grp_h5(ncid, &grp, &h5)))
return retval;
assert(h5 && grp && h5);
assert(h5 && grp);

/* If the file is read-only, return an error. */
if (h5->no_write)
Expand Down
10 changes: 5 additions & 5 deletions libhdf5/hdf5dim.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@ NC4_inq_dim(int ncid, int dimid, char *name, size_t *lenp)
int
NC4_rename_dim(int ncid, int dimid, const char *name)
{
NC *nc;
NC_GRP_INFO_T *grp;
NC_DIM_INFO_T *dim;
NC_HDF5_DIM_INFO_T *hdf5_dim;
Expand All @@ -222,9 +221,9 @@ NC4_rename_dim(int ncid, int dimid, const char *name)
dimid, name));

/* Find info for this file and group, and set pointer to each. */
if ((retval = nc4_find_nc_grp_h5(ncid, &nc, &grp, &h5)))
if ((retval = nc4_find_grp_h5(ncid, &grp, &h5)))
return retval;
assert(nc && h5 && grp);
assert(h5 && grp);

/* Trying to write to a read-only file? No way, Jose! */
if (h5->no_write)
Expand All @@ -251,7 +250,7 @@ NC4_rename_dim(int ncid, int dimid, const char *name)
LOG((3, "dim %s is a dim without variable", dim->hdr.name));

/* Delete the dimscale-only dataset. */
if ((retval = delete_existing_dimscale_dataset(grp, dimid, dim)))
if ((retval = delete_dimscale_dataset(grp, dimid, dim)))
return retval;
}

Expand All @@ -262,8 +261,9 @@ NC4_rename_dim(int ncid, int dimid, const char *name)
if (!(dim->hdr.name = strdup(norm_name)))
return NC_ENOMEM;
LOG((3, "dim is now named %s", dim->hdr.name));
dim->hdr.hashkey = NC_hashmapkey(dim->hdr.name,strlen(dim->hdr.name)); /* Fix hash key */

/* Fix hash key and rebuild index. */
dim->hdr.hashkey = NC_hashmapkey(dim->hdr.name,strlen(dim->hdr.name));
if (!ncindexrebuild(grp->dim))
return NC_EINTERNAL;

Expand Down
7 changes: 3 additions & 4 deletions libhdf5/hdf5file.c
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ NC4_enddef(int ncid)
LOG((1, "%s: ncid 0x%x", __func__, ncid));

/* Find pointer to group and nc4_info. */
if ((retval = nc4_find_nc_grp_h5(ncid, NULL, &grp, &nc4_info)))
if ((retval = nc4_find_grp_h5(ncid, &grp, &nc4_info)))
return retval;

/* When exiting define mode, mark all variable written. */
Expand Down Expand Up @@ -650,7 +650,6 @@ int
NC4_close(int ncid, void* params)
{
NC_GRP_INFO_T *grp;
NC *nc;
NC_FILE_INFO_T *h5;
int retval;
int inmemory;
Expand All @@ -659,10 +658,10 @@ NC4_close(int ncid, void* params)
LOG((1, "%s: ncid 0x%x", __func__, ncid));

/* Find our metadata for this file. */
if ((retval = nc4_find_nc_grp_h5(ncid, &nc, &grp, &h5)))
if ((retval = nc4_find_grp_h5(ncid, &grp, &h5)))
return retval;

assert(nc && h5 && grp);
assert(h5 && grp);

/* This must be the root group. */
if (grp->parent)
Expand Down
3 changes: 1 addition & 2 deletions libhdf5/hdf5internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -346,8 +346,7 @@ nc4_break_coord_var(NC_GRP_INFO_T *grp, NC_VAR_INFO_T *coord_var,
* @author Ed Hartnett
*/
int
delete_existing_dimscale_dataset(NC_GRP_INFO_T *grp, int dimid,
NC_DIM_INFO_T *dim)
delete_dimscale_dataset(NC_GRP_INFO_T *grp, int dimid, NC_DIM_INFO_T *dim)
{
NC_HDF5_DIM_INFO_T *hdf5_dim;
NC_HDF5_GRP_INFO_T *hdf5_grp;
Expand Down
27 changes: 21 additions & 6 deletions libhdf5/hdf5open.c
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,8 @@ dimscale_visitor(hid_t did, unsigned dim, hid_t dsid,
{
H5G_stat_t statbuf;

LOG((4, "%s", __func__));

/* Get more info on the dimscale object.*/
if (H5Gget_objinfo(dsid, ".", 1, &statbuf) < 0)
return -1;
Expand Down Expand Up @@ -1070,31 +1072,40 @@ get_attached_info(NC_VAR_INFO_T *var, NC_HDF5_VAR_INFO_T *hdf5_var, int ndims,
int d;
int num_scales = 0;

LOG((4, "%s ndims %d datasetid %ld", __func__, ndims, datasetid));

/* Find out how many scales are attached to this
* dataset. H5DSget_num_scales returns an error if there are no
* scales, so convert a negative return value to zero. */
num_scales = H5DSget_num_scales(datasetid, 0);
if (num_scales < 0)
num_scales = 0;
LOG((4, "num_scales %d", num_scales));

if (num_scales && ndims)
/* If an enddef has already been called, the dimscales will already
* be taken care of. */
if (num_scales && ndims && !var->dimscale_attached)
{
/* Allocate space to remember whether the dimscale has been
* attached for each dimension. */
* attached for each dimension, and the HDF5 object IDs of the
* scale(s). */
assert(!hdf5_var->dimscale_hdf5_objids);
if (!(var->dimscale_attached = calloc(ndims, sizeof(nc_bool_t))))
return NC_ENOMEM;

/* Store id information allowing us to match hdf5
* dimscales to netcdf dimensions. */
if (!(hdf5_var->dimscale_hdf5_objids = malloc(ndims *
sizeof(struct hdf5_objid))))
return NC_ENOMEM;

/* Store id information allowing us to match hdf5 dimscales to
* netcdf dimensions. */
for (d = 0; d < var->ndims; d++)
{
LOG((4, "about to iterate scales for dim %d", d));
if (H5DSiterate_scales(hdf5_var->hdf_datasetid, d, NULL, dimscale_visitor,
&(hdf5_var->dimscale_hdf5_objids[d])) < 0)
return NC_EHDFERR;
var->dimscale_attached[d] = NC_TRUE;
LOG((4, "dimscale attached"));
}
}

Expand Down Expand Up @@ -1131,13 +1142,17 @@ get_scale_info(NC_GRP_INFO_T *grp, NC_DIM_INFO_T *dim, NC_VAR_INFO_T *var,
{
assert(ndims);
var->dimscale = NC_TRUE;

/* If this is a multi-dimensional coordinate var, then the
* dimids must be stored in the hidden coordinates attribute. */
if (var->ndims > 1)
{
if ((retval = read_coord_dimids(grp, var)))
return retval;
}
else
{
/* This is a 1-dimensional coordinate var. */
assert(!strcmp(var->hdr.name, dim->hdr.name));
var->dimids[0] = dim->hdr.id;
var->dim[0] = dim;
Expand Down Expand Up @@ -1176,7 +1191,7 @@ nc4_get_var_meta(NC_VAR_INFO_T *var)
int retval = NC_NOERR;

assert(var && var->format_var_info);
LOG((3, "%s: var %s", var->hdr.name));
LOG((3, "%s: var %s", __func__, var->hdr.name));

/* Have we already read the var metadata? */
if (var->meta_read)
Expand Down
14 changes: 5 additions & 9 deletions libhdf5/hdf5type.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,17 @@ NC4_inq_type_equal(int ncid1, nc_type typeid1, int ncid2,
if ((typeid1 <= NC_STRING && typeid2 > NC_STRING) ||
(typeid2 <= NC_STRING && typeid1 > NC_STRING))
{
if (equalp) *equalp = 0;
*equalp = 0;
return NC_NOERR;
}

/* If both are atomic types, the answer is easy. */
if (typeid1 <= NUM_ATOMIC_TYPES)
{
if (equalp)
{
if (typeid1 == typeid2)
*equalp = 1;
else
*equalp = 0;
}
if (typeid1 == typeid2)
*equalp = 1;
else
*equalp = 0;
return NC_NOERR;
}

Expand All @@ -80,7 +77,6 @@ NC4_inq_type_equal(int ncid1, nc_type typeid1, int ncid2,
return NC_EBADTYPE;

/* Are the two types equal? */
if (equalp)
{
hid_t hid1, hid2;

Expand Down
43 changes: 21 additions & 22 deletions libhdf5/hdf5var.c
Original file line number Diff line number Diff line change
Expand Up @@ -1034,23 +1034,21 @@ NC4_def_var_filter(int ncid, int varid, unsigned int id, size_t nparams,
int
NC4_rename_var(int ncid, int varid, const char *name)
{
NC *nc;
NC_GRP_INFO_T *grp;
NC_HDF5_GRP_INFO_T *hdf5_grp;
NC_FILE_INFO_T *h5;
NC_VAR_INFO_T *var, *tmpvar;
NC_VAR_INFO_T *var;
int retval = NC_NOERR;

if (!name)
return NC_EINVAL;

LOG((2, "%s: ncid 0x%x varid %d name %s", __func__, ncid, varid,
name));
LOG((2, "%s: ncid 0x%x varid %d name %s", __func__, ncid, varid, name));

/* Find info for this file and group, and set pointer to each. */
if ((retval = nc4_find_nc_grp_h5(ncid, &nc, &grp, &h5)))
if ((retval = nc4_find_grp_h5(ncid, &grp, &h5)))
return retval;
assert(h5 && grp && grp->format_grp_info && h5);
assert(h5 && grp && grp->format_grp_info);

/* Get HDF5-specific group info. */
hdf5_grp = (NC_HDF5_GRP_INFO_T *)grp->format_grp_info;
Expand All @@ -1069,14 +1067,12 @@ NC4_rename_var(int ncid, int varid, const char *name)
return retval;

/* Get the variable wrt varid */
var = (NC_VAR_INFO_T*)ncindexith(grp->vars,varid);
if (!var)
if (!(var = (NC_VAR_INFO_T *)ncindexith(grp->vars, varid)))
return NC_ENOTVAR;

/* Check if new name is in use; note that renaming to same name is still an error
according to the nc_test/test_write.c code. Why?*/
tmpvar = (NC_VAR_INFO_T*)ncindexlookup(grp->vars,name);
if(tmpvar != NULL)
if (ncindexlookup(grp->vars, name))
return NC_ENAMEINUSE;

/* If we're not in define mode, new name must be of equal or
Expand All @@ -1103,8 +1099,8 @@ NC4_rename_var(int ncid, int varid, const char *name)
* so, it must be deleted. */
if (hdf5_d0->hdf_dimscaleid)
{
if ((retval = delete_existing_dimscale_dataset(grp, var->dim[0]->hdr.id,
var->dim[0])))
if ((retval = delete_dimscale_dataset(grp, var->dim[0]->hdr.id,
var->dim[0])))
return retval;
}
}
Expand All @@ -1119,37 +1115,40 @@ NC4_rename_var(int ncid, int varid, const char *name)
if (!(var->hdr.name = strdup(name)))
return NC_ENOMEM;
LOG((3, "var is now %s", var->hdr.name));
var->hdr.hashkey = NC_hashmapkey(var->hdr.name,strlen(var->hdr.name)); /* Fix hash key */

if(!ncindexrebuild(grp->vars))
/* Fix hash key and rebuild index. */
var->hdr.hashkey = NC_hashmapkey(var->hdr.name, strlen(var->hdr.name));
if (!ncindexrebuild(grp->vars))
return NC_EINTERNAL;

/* Check if this was a coordinate variable previously, but names are different now */
/* Check if this was a coordinate variable previously, but names
* are different now */
if (var->dimscale && strcmp(var->hdr.name, var->dim[0]->hdr.name))
{
/* Break up the coordinate variable */
if ((retval = nc4_break_coord_var(grp, var, var->dim[0])))
return retval;
}

/* Check if this should become a coordinate variable */
/* Check if this should become a coordinate variable. */
if (!var->dimscale)
{
/* Only variables with >0 dimensions can become coordinate variables */
/* Only variables with >0 dimensions can become coordinate
* variables. */
if (var->ndims)
{
NC_GRP_INFO_T *dim_grp;
NC_DIM_INFO_T *dim;

/* Check to see if this is became a coordinate variable. If so, it
* will have the same name as dimension index 0. If it is a
* coordinate var, is it a coordinate var in the same group as the dim?
*/
/* Check to see if this is became a coordinate variable. If
* so, it will have the same name as dimension index 0. If it
* is a coordinate var, is it a coordinate var in the same
* group as the dim? */
if ((retval = nc4_find_dim(grp, var->dimids[0], &dim, &dim_grp)))
return retval;
if (!strcmp(dim->hdr.name, name) && dim_grp == grp)
{
/* Reform the coordinate variable */
/* Reform the coordinate variable. */
if ((retval = nc4_reform_coord_var(grp, var, dim)))
return retval;
var->became_coord_var = NC_TRUE;
Expand Down
Loading

0 comments on commit 9ca942b

Please sign in to comment.