code cleanup

This commit is contained in:
Ed Hartnett 2018-07-21 09:09:12 -06:00
parent a17d66f66b
commit b56a8edcc9
2 changed files with 13 additions and 66 deletions

View File

@ -985,7 +985,8 @@ get_netcdf_type(NC_FILE_INFO_T *h5, hid_t native_typeid,
}
/**
* @internal Read an attribute. This is called by att_read_var_callbk().
* @internal Read an attribute. This is called by
* att_read_grp_callbk().
*
* @param grp Pointer to group info struct.
* @param attid Attribute ID.
@ -1509,65 +1510,6 @@ read_type(NC_GRP_INFO_T *grp, hid_t hdf_typeid, char *type_name)
return retval;
}
/**
* @internal Callback function for reading attributes. This is used by
* read_var().
*
* @param loc_id HDF5 attribute ID.
* @param att_name Name of the attrigute.
* @param ainfo HDF5 info struct for attribute.
* @param att_data The attribute data.
*
* @return ::NC_NOERR No error.
* @return ::NC_EHDFERR HDF5 returned error.
* @return ::NC_ENOMEM Out of memory.
* @return ::NC_EATTMETA HDF5 can't open attribute.
* @return ::NC_EBADTYPID Can't read attribute type.
*/
static herr_t
att_read_var_callbk(hid_t loc_id, const char *att_name,
const H5A_info_t *ainfo, void *att_data)
{
hid_t attid = 0;
int retval = NC_NOERR;
NC_ATT_INFO_T *att;
att_iter_info *att_info = (att_iter_info *)att_data;
/* Should we ignore this attribute? */
if (NC_findreserved(att_name))
return NC_NOERR;
/* Add to the end of the list of atts for this var. */
if ((retval = nc4_att_list_add(att_info->var->att, att_name, &att)))
BAIL(retval);
/* Open the att by name. */
if ((attid = H5Aopen(loc_id, att_name, H5P_DEFAULT)) < 0)
BAIL(NC_EATTMETA);
LOG((4, "%s:: att_name %s", __func__, att_name));
/* Read the rest of the info about the att,
* including its values. */
if ((retval = read_hdf5_att(att_info->grp, attid, att)))
BAIL(retval);
if (att)
att->created = NC_TRUE;
exit:
if (retval == NC_EBADTYPID)
{
/* NC_EBADTYPID will be normally converted to NC_NOERR so that
the parent iterator does not fail. */
retval = nc4_att_list_del(att_info->var->att,att);
att = NULL;
}
if (attid > 0 && H5Aclose(attid) < 0)
retval = NC_EHDFERR;
return retval;
}
/**
* @internal Callback function for reading attributes. This is used by
* read_var().
@ -1591,15 +1533,21 @@ att_read_grp_callbk(hid_t loc_id, const char *att_name,
hid_t attid = 0;
int retval = NC_NOERR;
NC_ATT_INFO_T *att;
NCindex *list;
att_iter_info *att_info = (att_iter_info *)att_data;
/* Determin what list is being added to. */
list = att_info->var ? att_info->var->att : att_info->grp->att;
/* This may be an attribute telling us that strict netcdf-3 rules
* are in effect. If so, we will make note of the fact, but not add
* this attribute to the metadata. It's not a user attribute, but
* an internal netcdf-4 one. */
if (!strcmp(att_name, NC3_STRICT_ATT_NAME))
{
att_info->grp->nc4_info->cmode |= NC_CLASSIC_MODEL;
/* Only relevant for groups, not vars. */
if (!att_info->var)
att_info->grp->nc4_info->cmode |= NC_CLASSIC_MODEL;
return NC_NOERR;
}
@ -1608,7 +1556,7 @@ att_read_grp_callbk(hid_t loc_id, const char *att_name,
return NC_NOERR;
/* Add to the end of the list of atts for this var. */
if ((retval = nc4_att_list_add(att_info->grp->att, att_name, &att)))
if ((retval = nc4_att_list_add(list, att_name, &att)))
BAIL(retval);
/* Open the att by name. */
@ -1695,7 +1643,7 @@ nc4_read_var_atts(NC_GRP_INFO_T *grp, NC_VAR_INFO_T *var)
/* Now read all the attributes of this variable, ignoring the
ones that hold HDF5 dimension scale information. */
if ((H5Aiterate2(var->hdf_datasetid, H5_INDEX_CRT_ORDER, H5_ITER_INC, NULL,
att_read_var_callbk, &att_info)) < 0)
att_read_grp_callbk, &att_info)) < 0)
return NC_EATTMETA;
/* Remember that we have read the atts for this var. */

View File

@ -168,7 +168,7 @@ readfile_hdf5(char *file_name, long long *delta, int do_inq, int num_vars)
#define NUM_RUNS 5
#define NUM_STEPS 20
#define FACTOR 5
#define FACTOR 100
#define NUM_INQ_TESTS 2
int
main(int argc, char **argv)
@ -186,8 +186,7 @@ main(int argc, char **argv)
/* Reset. */
num_atts = 1;
/* Set higher factor for var atts, since they are much faster. */
factor = num_vars ? FACTOR * 10 : FACTOR;
factor = FACTOR;
printf("*** %s %s\n", num_vars ? "variable attributes" : "global attributes",
do_inq ? "with inq" : "");