Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use coordinates hidden att to speed opens... #1262

Merged
merged 12 commits into from
Jan 16, 2019
6 changes: 6 additions & 0 deletions include/hdf5internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,5 +174,11 @@ int nc4_hdf5_find_grp_var_att(int ncid, int varid, const char *name, int attnum,
NC_GRP_INFO_T **grp, NC_VAR_INFO_T **var,
NC_ATT_INFO_T **att);

/* Find var, doing lazy var metadata read if needed. */
int nc4_hdf5_find_grp_h5_var(int ncid, int varid, NC_FILE_INFO_T **h5,
NC_GRP_INFO_T **grp, NC_VAR_INFO_T **var);

/* Perform lazy read of the rest of the metadata for a var. */
int nc4_get_var_meta(NC_VAR_INFO_T *var);

#endif /* _HDF5INTERNAL_ */
2 changes: 2 additions & 0 deletions include/nc4internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ typedef struct NC_VAR_INFO
nc_bool_t written_to; /* True if variable has data written to it */
struct NC_TYPE_INFO *type_info;
int atts_not_read; /* If true, the atts have not yet been read. */
nc_bool_t meta_read; /* True if this vars metadata has been completely read. */
nc_bool_t coords_read; /* True if this var has hidden coordinates att, and it has been read. */
NCindex *att; /* NCindex<NC_ATT_INFO_T*> */
nc_bool_t no_fill; /* True if no fill value is defined for var */
void *fill_value;
Expand Down
62 changes: 60 additions & 2 deletions libhdf5/hdf5internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -728,8 +728,61 @@ nc4_rec_grp_HDF5_del(NC_GRP_INFO_T *grp)
}

/**
* @internal Given an ncid and varid, find an att. Lazy reads are done
* as needed.
* @internal Given an ncid and varid, get pointers to the group and var
* metadata. Lazy var metadata reads are done as needed.
*
* @param ncid File ID.
* @param varid Variable ID.
* @param h5 Pointer that gets pointer to the NC_FILE_INFO_T struct
* for this file. Ignored if NULL.
* @param grp Pointer that gets pointer to group info. Ignored if
* NULL.
* @param var Pointer that gets pointer to var info. Ignored if NULL.
*
* @return ::NC_NOERR No error.
* @return ::NC_ENOTVAR Variable not found.
* @author Ed Hartnett
*/
int
nc4_hdf5_find_grp_h5_var(int ncid, int varid, NC_FILE_INFO_T **h5,
NC_GRP_INFO_T **grp, NC_VAR_INFO_T **var)
{
NC_FILE_INFO_T *my_h5;
NC_GRP_INFO_T *my_grp;
NC_VAR_INFO_T *my_var;
int retval;

/* Look up file and group metadata. */
if ((retval = nc4_find_grp_h5(ncid, &my_grp, &my_h5)))
return retval;
assert(my_grp && my_h5);

/* Find the var. */
if (!(my_var = (NC_VAR_INFO_T *)ncindexith(my_grp->vars, varid)))
return NC_ENOTVAR;
assert(my_var && my_var->hdr.id == varid);

/* Do we need to read var metadata? */
if (!my_var->meta_read && my_var->created)
if ((retval = nc4_get_var_meta(my_var)))
return retval;

/* Return pointers that caller wants. */
if (h5)
*h5 = my_h5;
if (grp)
*grp = my_grp;
if (var)
*var = my_var;

return NC_NOERR;
}

/**
* @internal Given an ncid, varid, and attribute name, return
* normalized name and pointers to the file, group, var, and att info
* structs. Lazy reads of attributes and variable metadata are done as
* needed.
*
* @param ncid File/group ID.
* @param varid Variable ID.
Expand Down Expand Up @@ -801,6 +854,11 @@ nc4_hdf5_find_grp_var_att(int ncid, int varid, const char *name, int attnum,
if ((retval = nc4_read_atts(my_grp, my_var)))
return retval;

/* Do we need to read var metadata? */
if (!my_var->meta_read && my_var->created)
if ((retval = nc4_get_var_meta(my_var)))
return retval;

attlist = my_var->att;
}
assert(attlist);
Expand Down
Loading