more progress towards lazy read of atts for vars

This commit is contained in:
Ed Hartnett 2018-06-19 08:25:19 -06:00
parent b524cd04bc
commit 77936f2884
3 changed files with 76 additions and 17 deletions

View File

@ -43,6 +43,54 @@ getattlist(NC_GRP_INFO_T *grp, int varid, NC_VAR_INFO_T **varp)
}
}
/**
* @internal Get the attribute list for either a varid or NC_GLOBAL
*
* @param grp Group
* @param varid Variable ID | NC_BLOGAL
* @param varp Pointer that gets pointer to NC_VAR_INFO_T
* instance. Ignored if NULL.
* @param attlist Pointer that gets pointer to attribute list.
*
* @return NC_NOERR No error.
* @author Dennis Heimbigner, Ed Hartnett
*/
static int
getattlist2(NC_GRP_INFO_T *grp, int varid, NC_VAR_INFO_T **varp,
NCindex **attlist)
{
NC_VAR_INFO_T* var;
int retval;
if (varid == NC_GLOBAL)
{
/* Do we need to read the atts? */
if (grp->atts_not_read)
if ((retval = nc4_read_grp_atts(grp)))
return retval;
if (varp)
*varp = NULL;
*attlist = grp->att;
}
else
{
if (!(var = (NC_VAR_INFO_T *)ncindexith(grp->vars, varid)))
return NC_ENOTVAR;
assert(var->hdr.id == varid);
/* Do we need to read the atts? */
if (var->atts_not_read)
if ((retval = nc4_read_var_atts(grp, var)))
return retval;
if (varp)
*varp = var;
*attlist = var->att;
}
return NC_NOERR;
}
/**
* @internal I think all atts should be named the exact same thing, to
* avoid confusion!
@ -92,11 +140,13 @@ NC4_rename_att(int ncid, int varid, const char *name, const char *newname)
if ((retval = nc4_check_name(newname, norm_newname)))
return retval;
/* Is new name in use? */
list = getattlist(grp,varid,&var);
if(list == NULL)
return NC_ENOTVAR;
/* Get the list of attributes. */
/* if (!(list = getattlist(grp,varid,&var))) */
/* return NC_ENOTVAR; */
if ((retval = getattlist2(grp, varid, &var, &list)))
return retval;
/* Is new name in use? */
att = (NC_ATT_INFO_T*)ncindexlookup(list,norm_newname);
if(att != NULL)
return NC_ENAMEINUSE;
@ -204,17 +254,15 @@ NC4_del_att(int ncid, int varid, const char *name)
BAIL(retval);
}
/* Do we need to read the atts? */
if (varid == NC_GLOBAL)
if (grp->atts_not_read)
if ((retval = nc4_read_grp_atts(grp)))
return retval;
/* Get either the global or a variable attribute list. */
/* if (!(attlist = getattlist(grp,varid,NULL))) */
/* return NC_ENOTVAR; */
if ((retval = getattlist2(grp, varid, &var, &attlist)))
return retval;
/* if (!(attlist = getattlist(grp,varid,NULL))) */
/* return NC_ENOTVAR; */
/* Get either the global or a variable attribute list. Also figure
out the HDF5 location it's attached to. */
attlist = getattlist(grp,varid,&var);
if(attlist == NULL)
return NC_ENOTVAR;
/* Determine the location id in the HDF5 file. */
if (varid == NC_GLOBAL)
locid = grp->hdf_grpid;
else if (var->created)
@ -303,9 +351,11 @@ NC4_put_att(int ncid, int varid, const char *name, nc_type file_type,
/* Find att, if it exists. (Must check varid first or nc_test will
* break.) */
attlist = getattlist(grp,varid,&var);
if(attlist == NULL)
return NC_ENOTVAR;
if ((ret = getattlist2(grp, varid, &var, &attlist)))
return ret;
/* attlist = getattlist(grp,varid,&var); */
/* if(attlist == NULL) */
/* return NC_ENOTVAR; */
/* The length needs to be positive (cast needed for braindead
systems with signed size_t). */

View File

@ -1827,6 +1827,9 @@ nc4_read_var_atts(NC_GRP_INFO_T *grp, NC_VAR_INFO_T *var)
att_read_var_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;
}

View File

@ -480,6 +480,12 @@ nc4_find_grp_att(NC_GRP_INFO_T *grp, int varid, const char *name, int attnum,
{
var = (NC_VAR_INFO_T*)ncindexith(grp->vars,varid);
if (!var) return NC_ENOTVAR;
/* Do we need to read the var attributes? */
if (var->atts_not_read)
if ((retval = nc4_read_var_atts(grp, var)))
return retval;
attlist = var->att;
assert(var->hdr.id == varid);
}