removing unneeded lookups

This commit is contained in:
Ed Hartnett 2018-08-22 06:08:19 -06:00
parent ff1b71a1e4
commit 8885c75ade
9 changed files with 59 additions and 120 deletions

View File

@ -346,7 +346,6 @@ int nc4_find_nc_grp_h5(int ncid, NC **nc, NC_GRP_INFO_T **grp,
NC_FILE_INFO_T **h5);
int nc4_find_grp_h5(int ncid, NC_GRP_INFO_T **grp, NC_FILE_INFO_T **h5);
int nc4_find_nc4_grp(int ncid, NC_GRP_INFO_T **grp);
NC *nc4_find_nc_file(int ncid, NC_FILE_INFO_T**);
int nc4_find_dim(NC_GRP_INFO_T *grp, int dimid, NC_DIM_INFO_T **dim, NC_GRP_INFO_T **dim_grp);
int nc4_find_var(NC_GRP_INFO_T *grp, const char *name, NC_VAR_INFO_T **var);
int nc4_find_dim_len(NC_GRP_INFO_T *grp, int dimid, size_t **len);
@ -419,7 +418,7 @@ extern void nc4_hdf5_initialize(void);
/* This is only included if --enable-logging is used for configure; it
prints info about the metadata to stderr. */
#ifdef LOGGING
int log_metadata_nc(NC *nc);
int log_metadata_nc(NC_FILE_INFO_T *h5);
#endif
/* Define accessors for the dispatchdata */

View File

@ -659,7 +659,7 @@ NC_HDF4_open(const char *path, int mode, int basepe, size_t *chunksizehintp,
#ifdef LOGGING
/* This will print out the names, types, lens, etc of the vars and
atts in the file, if the logging level is 2 or greater. */
log_metadata_nc(h5->root_grp->nc4_info->controller);
log_metadata_nc(h5);
#endif
return retval;

View File

@ -50,15 +50,15 @@ int
NC_HDF4_inq_format_extended(int ncid, int *formatp, int *modep)
{
NC *nc;
NC_FILE_INFO_T* h5;
int retval;
LOG((2, "%s: ncid 0x%x", __func__, ncid));
if (!(nc = nc4_find_nc_file(ncid, &h5)))
if ((retval = nc4_find_nc_grp_h5(ncid, &nc, NULL, NULL)))
return NC_EBADID;
if (modep)
*modep = (nc->mode|NC_NETCDF4);
*modep = nc->mode|NC_NETCDF4;
if (formatp)
*formatp = NC_FORMATX_NC_HDF4;

View File

@ -111,7 +111,7 @@ sync_netcdf4_file(NC_FILE_INFO_T *h5)
#ifdef LOGGING
/* This will print out the names, types, lens, etc of the vars and
atts in the file, if the logging level is 2 or greater. */
log_metadata_nc(h5->root_grp->nc4_info->controller);
log_metadata_nc(h5);
#endif
/* Write any metadata that has changed. */

View File

@ -517,7 +517,7 @@ nc4_open_file(const char *path, int mode, void* parameters, NC *nc)
#ifdef LOGGING
/* This will print out the names, types, lens, etc of the vars and
atts in the file, if the logging level is 2 or greater. */
log_metadata_nc(nc);
log_metadata_nc(nc4_info);
#endif
/* Close the property list. */

View File

@ -349,23 +349,13 @@ NC4_inq_attid(int ncid, int varid, const char *name, int *attnump)
int
NC4_inq_attname(int ncid, int varid, int attnum, char *name)
{
NC *nc;
NC_ATT_INFO_T *att;
NC_FILE_INFO_T *h5;
int retval = NC_NOERR;
int retval;
LOG((2, "nc_inq_attname: ncid 0x%x varid %d attnum %d",
ncid, varid, attnum));
LOG((2, "nc_inq_attname: ncid 0x%x varid %d attnum %d", ncid, varid,
attnum));
/* Find metadata. */
if (!(nc = nc4_find_nc_file(ncid,NULL)))
return NC_EBADID;
/* get netcdf-4 metadata */
h5 = NC4_DATA(nc);
assert(h5);
/* Handle netcdf-4 files. */
/* Find the attribute metadata. */
if ((retval = nc4_find_nc_att(ncid, varid, NULL, attnum, &att)))
return retval;

View File

@ -184,9 +184,14 @@ nc4_find_nc_grp_h5(int ncid, NC **nc, NC_GRP_INFO_T **grp, NC_FILE_INFO_T **h5)
NC_GRP_INFO_T *my_grp = NULL;
NC_FILE_INFO_T *my_h5 = NULL;
NC *my_nc;
int retval;
if (!(my_nc = nc4_find_nc_file(ncid, &my_h5)))
return NC_EBADID;
if ((retval = NC_check_id(ncid, &my_nc)))
return retval;
my_h5 = my_nc->dispatchdata;
/* if (!(my_nc = nc4_find_nc_file(ncid, &my_h5))) */
/* return NC_EBADID; */
assert(my_h5 && my_h5->root_grp);
/* If we can't find it, the grp id part of ncid is bad. */
@ -502,32 +507,6 @@ nc4_find_nc_att(int ncid, int varid, const char *name, int attnum,
return nc4_find_grp_att(grp,varid,name,attnum,att);
}
/**
* @internal Given an id, walk the list and find the appropriate NC.
*
* @param ext_ncid File/group ID to find.
* @param h5p Pointer to pointer that gets the HDF5 file info struct.
*
* @return ::NC_NOERR No error.
* @author Ed Hartnett, Dennis Heimbigner
*/
NC*
nc4_find_nc_file(int ext_ncid, NC_FILE_INFO_T** h5p)
{
NC* nc;
int stat;
stat = NC_check_id(ext_ncid,&nc);
if(stat != NC_NOERR)
nc = NULL;
if(nc)
if(h5p) *h5p = (NC_FILE_INFO_T*)nc->dispatchdata;
return nc;
}
/**
* @internal Add NC_OBJ to allXXX lists in a file
*
@ -1692,23 +1671,24 @@ rec_print_metadata(NC_GRP_INFO_T *grp, int tab_count)
* useful to check that netCDF is working! Nonetheless, this function
* will print nothing if logging is not set to at least two.
*
* @param Pointer to the file info struct.
*
* @return ::NC_NOERR No error.
* @author Ed Hartnett
*/
int
log_metadata_nc(NC *nc)
log_metadata_nc(NC_FILE_INFO_T *h5)
{
NC_FILE_INFO_T *h5 = NC4_DATA(nc);
LOG((2, "*** NetCDF-4 Internal Metadata: int_ncid 0x%x ext_ncid 0x%x",
nc->int_ncid, nc->ext_ncid));
h5->root_grp->nc4_info->controller->int_ncid,
h5->root_grp->nc4_info->controller->ext_ncid));
if (!h5)
{
LOG((2, "This is a netCDF-3 file."));
return NC_NOERR;
}
LOG((2, "FILE - path: %s cmode: 0x%x parallel: %d redef: %d "
"fill_mode: %d no_write: %d next_nc_grpid: %d", nc->path,
"fill_mode: %d no_write: %d next_nc_grpid: %d", h5->root_grp->nc4_info->controller->path,
h5->cmode, (int)h5->parallel, (int)h5->redef, h5->fill_mode, (int)h5->no_write,
h5->next_nc_grpid));
if(nc_log_level >= 2)
@ -1734,16 +1714,16 @@ NC4_show_metadata(int ncid)
{
int retval = NC_NOERR;
#ifdef LOGGING
NC *nc;
NC_FILE_INFO_T *h5;
int old_log_level = nc_log_level;
/* Find file metadata. */
if (!(nc = nc4_find_nc_file(ncid,NULL)))
return NC_EBADID;
if ((retval = nc4_find_grp_h5(ncid, NULL, &h5)))
return retval;
/* Log level must be 2 to see metadata. */
nc_log_level = 2;
retval = log_metadata_nc(nc);
retval = log_metadata_nc(h5);
nc_log_level = old_log_level;
#endif /*LOGGING*/
return retval;

View File

@ -256,50 +256,20 @@ NC4_inq_compound_field(int ncid, nc_type typeid1, int fieldid, char *name,
return NC_EBADTYPE;
/* Find the field. */
field = (NC_FIELD_INFO_T*)nclistget(type->u.c.field,fieldid);
if(field)
{
if (name)
strcpy(name, field->hdr.name);
if (offsetp)
*offsetp = field->offset;
if (field_typeidp)
*field_typeidp = field->nc_typeid;
if (ndimsp)
*ndimsp = field->ndims;
if (dim_sizesp)
for (d = 0; d < field->ndims; d++)
dim_sizesp[d] = field->dim_size[d];
return NC_NOERR;
}
if (!(field = nclistget(type->u.c.field,fieldid)))
return NC_EBADFIELD;
return NC_EBADFIELD;
}
/**
* @internal Find a netcdf-4 file. THis will return an error if it
* finds a netcdf-3 file, or a netcdf-4 file with strict nc3 rules.
*
* @param ncid File and group ID.
* @param nc Pointer to pointer that gets NC struct for file.
*
* @return ::NC_NOERR No error.
* @return ::NC_EBADID Bad ncid.
* @return ::NC_ESTRICTNC3 File uses classic model.
* @author Ed Hartnett
*/
static int
find_nc4_file(int ncid, NC **nc)
{
NC_FILE_INFO_T *h5;
/* Find file metadata. */
if (!((*nc) = nc4_find_nc_file(ncid, &h5)))
return NC_EBADID;
assert(h5);
if (h5->cmode & NC_CLASSIC_MODEL)
return NC_ESTRICTNC3;
if (name)
strcpy(name, field->hdr.name);
if (offsetp)
*offsetp = field->offset;
if (field_typeidp)
*field_typeidp = field->nc_typeid;
if (ndimsp)
*ndimsp = field->ndims;
if (dim_sizesp)
for (d = 0; d < field->ndims; d++)
dim_sizesp[d] = field->dim_size[d];
return NC_NOERR;
}
@ -321,7 +291,7 @@ find_nc4_file(int ncid, NC **nc)
int
NC4_inq_compound_fieldindex(int ncid, nc_type typeid1, const char *name, int *fieldidp)
{
NC *nc;
NC_FILE_INFO_T *h5;
NC_TYPE_INFO_T *type;
NC_FIELD_INFO_T *field;
char norm_name[NC_MAX_NAME + 1];
@ -332,11 +302,11 @@ NC4_inq_compound_fieldindex(int ncid, nc_type typeid1, const char *name, int *fi
ncid, typeid1, name));
/* Find file metadata. */
if ((retval = find_nc4_file(ncid, &nc)))
if ((retval = nc4_find_grp_h5(ncid, NULL, &h5)))
return retval;
/* Find the type. */
if ((retval = nc4_find_type(NC4_DATA(nc), typeid1, &type)))
if ((retval = nc4_find_type(h5, typeid1, &type)))
return retval;
/* Did the user give us a good compound type typeid? */
@ -348,8 +318,10 @@ NC4_inq_compound_fieldindex(int ncid, nc_type typeid1, const char *name, int *fi
return retval;
/* Find the field with this name. */
for(i=0;i<nclistlength(type->u.c.field);i++) {
if((field = (NC_FIELD_INFO_T*)nclistget(type->u.c.field,i)) == NULL) continue;
for (i = 0; i < nclistlength(type->u.c.field); i++)
{
field = nclistget(type->u.c.field, i);
assert(field);
if (!strcmp(field->hdr.name, norm_name))
break;
field = NULL; /* because this is the indicator of not found */
@ -406,7 +378,8 @@ NC4_inq_enum_ident(int ncid, nc_type xtype, long long value, char *identifier)
/* Move to the desired enum member in the list. */
for (found = 0, i = 0; i < nclistlength(type->u.e.enum_member); i++)
{
if((enum_member = (NC_ENUM_MEMBER_INFO_T*)nclistget(type->u.e.enum_member,i)) == NULL) continue;
enum_member = nclistget(type->u.e.enum_member, i);
assert(enum_member);
switch (type->u.e.base_nc_typeid)
{
case NC_BYTE:
@ -491,9 +464,7 @@ NC4_inq_enum_member(int ncid, nc_type typeid1, int idx, char *identifier,
return NC_EBADTYPE;
/* Move to the desired enum member in the list. */
/* Check index. */
enum_member = (NC_ENUM_MEMBER_INFO_T*)nclistget(type->u.e.enum_member,idx);
if(enum_member == NULL)
if (!(enum_member = nclistget(type->u.e.enum_member, idx)))
return NC_EINVAL;
/* Give the people what they want. */

View File

@ -31,8 +31,8 @@
int
NC4_inq_format(int ncid, int *formatp)
{
NC *nc;
NC_FILE_INFO_T *nc4_info;
int retval;
LOG((2, "nc_inq_format: ncid 0x%x", ncid));
@ -40,11 +40,10 @@ NC4_inq_format(int ncid, int *formatp)
return NC_NOERR;
/* Find the file metadata. */
if (!(nc = nc4_find_nc_file(ncid,&nc4_info)))
return NC_EBADID;
if ((retval = nc4_find_nc_grp_h5(ncid, NULL, NULL, &nc4_info)))
return retval;
/* Otherwise, this is a netcdf-4 file. Check if classic NC3 rules
* are in effect for this file. */
/* Check if classic NC3 rules are in effect for this file. */
if (nc4_info->cmode & NC_CLASSIC_MODEL)
*formatp = NC_FORMAT_NETCDF4_CLASSIC;
else
@ -73,15 +72,15 @@ int
NC4_inq_format_extended(int ncid, int *formatp, int *modep)
{
NC *nc;
NC_FILE_INFO_T *h5;
int retval;
LOG((2, "%s: ncid 0x%x", __func__, ncid));
/* Find the file metadata. */
if (!(nc = nc4_find_nc_file(ncid,&h5)))
if ((retval = nc4_find_nc_grp_h5(ncid, &nc, NULL, NULL)))
return NC_EBADID;
if(modep) *modep = (nc->mode|NC_NETCDF4);
if(modep)
*modep = nc->mode|NC_NETCDF4;
if (formatp)
*formatp = NC_FORMATX_NC_HDF5;