2
0
mirror of https://github.com/Unidata/netcdf-c.git synced 2025-03-25 17:40:27 +08:00

further condensing code

This commit is contained in:
Ed Hartnett 2018-07-21 10:43:36 -06:00
parent 48d6473844
commit 5a52f28bb7
7 changed files with 16 additions and 80 deletions

@ -334,8 +334,6 @@ int nc4_rec_write_groups_types(NC_GRP_INFO_T *grp);
int nc4_enddef_netcdf4_file(NC_FILE_INFO_T *h5);
int nc4_reopen_dataset(NC_GRP_INFO_T *grp, NC_VAR_INFO_T *var);
int nc4_adjust_var_cache(NC_GRP_INFO_T *grp, NC_VAR_INFO_T * var);
int nc4_read_grp_atts2(NC_GRP_INFO_T *grp);
int nc4_read_var_atts(NC_GRP_INFO_T *grp, NC_VAR_INFO_T *var);
int nc4_read_atts(NC_GRP_INFO_T *grp, NC_VAR_INFO_T *var);
/* The following functions manipulate the in-memory linked list of

@ -42,7 +42,7 @@ getattlist(NC_GRP_INFO_T *grp, int varid, NC_VAR_INFO_T **varp,
{
/* Do we need to read the atts? */
if (grp->atts_not_read)
if ((retval = nc4_read_grp_atts2(grp)))
if ((retval = nc4_read_atts(grp, NULL)))
return retval;
if (varp)

@ -711,7 +711,7 @@ NC4_inq(int ncid, int *ndimsp, int *nvarsp, int *nattsp, int *unlimdimidp)
{
/* Do we need to read the atts? */
if (grp->atts_not_read)
if ((retval = nc4_read_grp_atts2(grp)))
if ((retval = nc4_read_atts(grp, NULL)))
return retval;
*nattsp = ncindexcount(grp->att);

@ -1567,7 +1567,7 @@ att_read_callbk(hid_t loc_id, const char *att_name, const H5A_info_t *ainfo,
/* Read the rest of the info about the att,
* including its values. */
if ((retval = read_hdf5_att(att_info->grp, attid, att)))
BAIL(-1);
BAIL(retval);
if (att)
att->created = NC_TRUE;
@ -1577,81 +1577,19 @@ exit:
{
/* NC_EBADTYPID will be normally converted to NC_NOERR so that
the parent iterator does not fail. */
retval = nc4_att_list_del(att_info->grp->att, att);
retval = nc4_att_list_del(list, att);
att = NULL;
}
if (attid > 0 && H5Aclose(attid) < 0)
retval = NC_EHDFERR;
retval = -1;
/* Since this is a HDF5 iterator callback, return -1 for any error
* to stop iteration. */
if (retval)
retval = -1;
return retval;
}
/**
* @internal This function reads all the group level attributes (the
* NC_GLOBAL atts for this group).
*
* @param grp Pointer to group info struct.
*
* @return ::NC_NOERR No error.
* @return ::NC_EHDFERR HDF5 returned error.
* @author Ed Hartnett
*/
int
nc4_read_grp_atts2(NC_GRP_INFO_T *grp)
{
att_iter_info att_info; /* Custom iteration information */
/* Check inputs. */
assert(grp);
/* Assign var and grp in struct. */
att_info.var = NULL;
att_info.grp = grp;
/* Now read all the attributes of this variable, ignoring the
ones that hold HDF5 dimension scale information. */
if ((H5Aiterate2(grp->hdf_grpid, H5_INDEX_CRT_ORDER, H5_ITER_INC, NULL,
att_read_callbk, &att_info)) < 0)
return NC_EATTMETA;
/* Remember that we have read the atts for this var. */
grp->atts_not_read = 0;
return NC_NOERR;
}
/**
* @internal This function reads all the attributes of a variable.
*
* @param grp Pointer to the group info.
* @param var Pointer to the var info.
*
* @return NC_NOERR No error.
* @author Ed Hartnett
*/
int
nc4_read_var_atts(NC_GRP_INFO_T *grp, NC_VAR_INFO_T *var)
{
att_iter_info att_info; /* Custom iteration information */
/* Check inputs. */
assert(grp && var);
/* Assign var and grp in struct. */
att_info.var = var;
att_info.grp = grp;
/* 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_callbk, &att_info)) < 0)
return NC_EATTMETA;
/* Remember that we have read the atts for this var. */
var->atts_not_read = 0;
return NC_NOERR;
}
/**
* @internal This function reads all the attributes of a variable or
* the global attributes of a group.

@ -156,13 +156,13 @@ nc4_get_att(int ncid, int varid, const char *name, nc_type *xtype,
if (varid == NC_GLOBAL)
{
if (grp->atts_not_read)
if ((retval = nc4_read_grp_atts2(grp)))
if ((retval = nc4_read_atts(grp, NULL)))
return retval;
}
else
{
if (var->atts_not_read)
if ((retval = nc4_read_var_atts(grp, var)))
if ((retval = nc4_read_atts(grp, var)))
return retval;
}

@ -473,7 +473,7 @@ nc4_find_grp_att(NC_GRP_INFO_T *grp, int varid, const char *name, int attnum,
/* Do we need to read the atts? */
if (grp->atts_not_read)
if ((retval = nc4_read_grp_atts2(grp)))
if ((retval = nc4_read_atts(grp, NULL)))
return retval;
}
else
@ -483,7 +483,7 @@ nc4_find_grp_att(NC_GRP_INFO_T *grp, int varid, const char *name, int attnum,
/* Do we need to read the var attributes? */
if (var->atts_not_read)
if ((retval = nc4_read_var_atts(grp, var)))
if ((retval = nc4_read_atts(grp, var)))
return retval;
attlist = var->att;

@ -261,7 +261,7 @@ NC4_inq_var_all(int ncid, int varid, char *name, nc_type *xtypep,
{
/* Do we need to read the atts? */
if (grp->atts_not_read)
if ((retval = nc4_read_grp_atts2(grp)))
if ((retval = nc4_read_atts(grp, NULL)))
return retval;
*nattsp = ncindexcount(grp->att);
@ -288,7 +288,7 @@ NC4_inq_var_all(int ncid, int varid, char *name, nc_type *xtypep,
if (nattsp)
{
if (var->atts_not_read)
if ((retval = nc4_read_var_atts(grp, var)))
if ((retval = nc4_read_atts(grp, var)))
return retval;
*nattsp = ncindexcount(var->att);
}