mirror of
https://github.com/Unidata/netcdf-c.git
synced 2025-04-24 18:30:51 +08:00
removing unneeded lookups
This commit is contained in:
parent
ff1b71a1e4
commit
8885c75ade
@ -346,7 +346,6 @@ int nc4_find_nc_grp_h5(int ncid, NC **nc, NC_GRP_INFO_T **grp,
|
|||||||
NC_FILE_INFO_T **h5);
|
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_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);
|
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_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_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);
|
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
|
/* This is only included if --enable-logging is used for configure; it
|
||||||
prints info about the metadata to stderr. */
|
prints info about the metadata to stderr. */
|
||||||
#ifdef LOGGING
|
#ifdef LOGGING
|
||||||
int log_metadata_nc(NC *nc);
|
int log_metadata_nc(NC_FILE_INFO_T *h5);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Define accessors for the dispatchdata */
|
/* Define accessors for the dispatchdata */
|
||||||
|
@ -659,7 +659,7 @@ NC_HDF4_open(const char *path, int mode, int basepe, size_t *chunksizehintp,
|
|||||||
#ifdef LOGGING
|
#ifdef LOGGING
|
||||||
/* This will print out the names, types, lens, etc of the vars and
|
/* 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. */
|
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
|
#endif
|
||||||
|
|
||||||
return retval;
|
return retval;
|
||||||
|
@ -50,15 +50,15 @@ int
|
|||||||
NC_HDF4_inq_format_extended(int ncid, int *formatp, int *modep)
|
NC_HDF4_inq_format_extended(int ncid, int *formatp, int *modep)
|
||||||
{
|
{
|
||||||
NC *nc;
|
NC *nc;
|
||||||
NC_FILE_INFO_T* h5;
|
int retval;
|
||||||
|
|
||||||
LOG((2, "%s: ncid 0x%x", __func__, ncid));
|
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;
|
return NC_EBADID;
|
||||||
|
|
||||||
if (modep)
|
if (modep)
|
||||||
*modep = (nc->mode|NC_NETCDF4);
|
*modep = nc->mode|NC_NETCDF4;
|
||||||
|
|
||||||
if (formatp)
|
if (formatp)
|
||||||
*formatp = NC_FORMATX_NC_HDF4;
|
*formatp = NC_FORMATX_NC_HDF4;
|
||||||
|
@ -111,7 +111,7 @@ sync_netcdf4_file(NC_FILE_INFO_T *h5)
|
|||||||
#ifdef LOGGING
|
#ifdef LOGGING
|
||||||
/* This will print out the names, types, lens, etc of the vars and
|
/* 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. */
|
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
|
#endif
|
||||||
|
|
||||||
/* Write any metadata that has changed. */
|
/* Write any metadata that has changed. */
|
||||||
|
@ -517,7 +517,7 @@ nc4_open_file(const char *path, int mode, void* parameters, NC *nc)
|
|||||||
#ifdef LOGGING
|
#ifdef LOGGING
|
||||||
/* This will print out the names, types, lens, etc of the vars and
|
/* 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. */
|
atts in the file, if the logging level is 2 or greater. */
|
||||||
log_metadata_nc(nc);
|
log_metadata_nc(nc4_info);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Close the property list. */
|
/* Close the property list. */
|
||||||
|
@ -349,23 +349,13 @@ NC4_inq_attid(int ncid, int varid, const char *name, int *attnump)
|
|||||||
int
|
int
|
||||||
NC4_inq_attname(int ncid, int varid, int attnum, char *name)
|
NC4_inq_attname(int ncid, int varid, int attnum, char *name)
|
||||||
{
|
{
|
||||||
NC *nc;
|
|
||||||
NC_ATT_INFO_T *att;
|
NC_ATT_INFO_T *att;
|
||||||
NC_FILE_INFO_T *h5;
|
int retval;
|
||||||
int retval = NC_NOERR;
|
|
||||||
|
|
||||||
LOG((2, "nc_inq_attname: ncid 0x%x varid %d attnum %d",
|
LOG((2, "nc_inq_attname: ncid 0x%x varid %d attnum %d", ncid, varid,
|
||||||
ncid, varid, attnum));
|
attnum));
|
||||||
|
|
||||||
/* Find metadata. */
|
/* Find the attribute 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. */
|
|
||||||
if ((retval = nc4_find_nc_att(ncid, varid, NULL, attnum, &att)))
|
if ((retval = nc4_find_nc_att(ncid, varid, NULL, attnum, &att)))
|
||||||
return retval;
|
return retval;
|
||||||
|
|
||||||
|
@ -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_GRP_INFO_T *my_grp = NULL;
|
||||||
NC_FILE_INFO_T *my_h5 = NULL;
|
NC_FILE_INFO_T *my_h5 = NULL;
|
||||||
NC *my_nc;
|
NC *my_nc;
|
||||||
|
int retval;
|
||||||
|
|
||||||
if (!(my_nc = nc4_find_nc_file(ncid, &my_h5)))
|
if ((retval = NC_check_id(ncid, &my_nc)))
|
||||||
return NC_EBADID;
|
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);
|
assert(my_h5 && my_h5->root_grp);
|
||||||
|
|
||||||
/* If we can't find it, the grp id part of ncid is bad. */
|
/* 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);
|
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
|
* @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
|
* useful to check that netCDF is working! Nonetheless, this function
|
||||||
* will print nothing if logging is not set to at least two.
|
* will print nothing if logging is not set to at least two.
|
||||||
*
|
*
|
||||||
|
* @param Pointer to the file info struct.
|
||||||
|
*
|
||||||
* @return ::NC_NOERR No error.
|
* @return ::NC_NOERR No error.
|
||||||
* @author Ed Hartnett
|
* @author Ed Hartnett
|
||||||
*/
|
*/
|
||||||
int
|
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",
|
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)
|
if (!h5)
|
||||||
{
|
{
|
||||||
LOG((2, "This is a netCDF-3 file."));
|
LOG((2, "This is a netCDF-3 file."));
|
||||||
return NC_NOERR;
|
return NC_NOERR;
|
||||||
}
|
}
|
||||||
LOG((2, "FILE - path: %s cmode: 0x%x parallel: %d redef: %d "
|
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->cmode, (int)h5->parallel, (int)h5->redef, h5->fill_mode, (int)h5->no_write,
|
||||||
h5->next_nc_grpid));
|
h5->next_nc_grpid));
|
||||||
if(nc_log_level >= 2)
|
if(nc_log_level >= 2)
|
||||||
@ -1734,16 +1714,16 @@ NC4_show_metadata(int ncid)
|
|||||||
{
|
{
|
||||||
int retval = NC_NOERR;
|
int retval = NC_NOERR;
|
||||||
#ifdef LOGGING
|
#ifdef LOGGING
|
||||||
NC *nc;
|
NC_FILE_INFO_T *h5;
|
||||||
int old_log_level = nc_log_level;
|
int old_log_level = nc_log_level;
|
||||||
|
|
||||||
/* Find file metadata. */
|
/* Find file metadata. */
|
||||||
if (!(nc = nc4_find_nc_file(ncid,NULL)))
|
if ((retval = nc4_find_grp_h5(ncid, NULL, &h5)))
|
||||||
return NC_EBADID;
|
return retval;
|
||||||
|
|
||||||
/* Log level must be 2 to see metadata. */
|
/* Log level must be 2 to see metadata. */
|
||||||
nc_log_level = 2;
|
nc_log_level = 2;
|
||||||
retval = log_metadata_nc(nc);
|
retval = log_metadata_nc(h5);
|
||||||
nc_log_level = old_log_level;
|
nc_log_level = old_log_level;
|
||||||
#endif /*LOGGING*/
|
#endif /*LOGGING*/
|
||||||
return retval;
|
return retval;
|
||||||
|
@ -256,50 +256,20 @@ NC4_inq_compound_field(int ncid, nc_type typeid1, int fieldid, char *name,
|
|||||||
return NC_EBADTYPE;
|
return NC_EBADTYPE;
|
||||||
|
|
||||||
/* Find the field. */
|
/* Find the field. */
|
||||||
field = (NC_FIELD_INFO_T*)nclistget(type->u.c.field,fieldid);
|
if (!(field = nclistget(type->u.c.field,fieldid)))
|
||||||
if(field)
|
return NC_EBADFIELD;
|
||||||
{
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
return NC_EBADFIELD;
|
if (name)
|
||||||
}
|
strcpy(name, field->hdr.name);
|
||||||
|
if (offsetp)
|
||||||
/**
|
*offsetp = field->offset;
|
||||||
* @internal Find a netcdf-4 file. THis will return an error if it
|
if (field_typeidp)
|
||||||
* finds a netcdf-3 file, or a netcdf-4 file with strict nc3 rules.
|
*field_typeidp = field->nc_typeid;
|
||||||
*
|
if (ndimsp)
|
||||||
* @param ncid File and group ID.
|
*ndimsp = field->ndims;
|
||||||
* @param nc Pointer to pointer that gets NC struct for file.
|
if (dim_sizesp)
|
||||||
*
|
for (d = 0; d < field->ndims; d++)
|
||||||
* @return ::NC_NOERR No error.
|
dim_sizesp[d] = field->dim_size[d];
|
||||||
* @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;
|
|
||||||
|
|
||||||
return NC_NOERR;
|
return NC_NOERR;
|
||||||
}
|
}
|
||||||
@ -321,7 +291,7 @@ find_nc4_file(int ncid, NC **nc)
|
|||||||
int
|
int
|
||||||
NC4_inq_compound_fieldindex(int ncid, nc_type typeid1, const char *name, int *fieldidp)
|
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_TYPE_INFO_T *type;
|
||||||
NC_FIELD_INFO_T *field;
|
NC_FIELD_INFO_T *field;
|
||||||
char norm_name[NC_MAX_NAME + 1];
|
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));
|
ncid, typeid1, name));
|
||||||
|
|
||||||
/* Find file metadata. */
|
/* Find file metadata. */
|
||||||
if ((retval = find_nc4_file(ncid, &nc)))
|
if ((retval = nc4_find_grp_h5(ncid, NULL, &h5)))
|
||||||
return retval;
|
return retval;
|
||||||
|
|
||||||
/* Find the type. */
|
/* Find the type. */
|
||||||
if ((retval = nc4_find_type(NC4_DATA(nc), typeid1, &type)))
|
if ((retval = nc4_find_type(h5, typeid1, &type)))
|
||||||
return retval;
|
return retval;
|
||||||
|
|
||||||
/* Did the user give us a good compound type typeid? */
|
/* 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;
|
return retval;
|
||||||
|
|
||||||
/* Find the field with this name. */
|
/* Find the field with this name. */
|
||||||
for(i=0;i<nclistlength(type->u.c.field);i++) {
|
for (i = 0; i < nclistlength(type->u.c.field); i++)
|
||||||
if((field = (NC_FIELD_INFO_T*)nclistget(type->u.c.field,i)) == NULL) continue;
|
{
|
||||||
|
field = nclistget(type->u.c.field, i);
|
||||||
|
assert(field);
|
||||||
if (!strcmp(field->hdr.name, norm_name))
|
if (!strcmp(field->hdr.name, norm_name))
|
||||||
break;
|
break;
|
||||||
field = NULL; /* because this is the indicator of not found */
|
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. */
|
/* Move to the desired enum member in the list. */
|
||||||
for (found = 0, i = 0; i < nclistlength(type->u.e.enum_member); i++)
|
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)
|
switch (type->u.e.base_nc_typeid)
|
||||||
{
|
{
|
||||||
case NC_BYTE:
|
case NC_BYTE:
|
||||||
@ -491,9 +464,7 @@ NC4_inq_enum_member(int ncid, nc_type typeid1, int idx, char *identifier,
|
|||||||
return NC_EBADTYPE;
|
return NC_EBADTYPE;
|
||||||
|
|
||||||
/* Move to the desired enum member in the list. */
|
/* Move to the desired enum member in the list. */
|
||||||
/* Check index. */
|
if (!(enum_member = nclistget(type->u.e.enum_member, idx)))
|
||||||
enum_member = (NC_ENUM_MEMBER_INFO_T*)nclistget(type->u.e.enum_member,idx);
|
|
||||||
if(enum_member == NULL)
|
|
||||||
return NC_EINVAL;
|
return NC_EINVAL;
|
||||||
|
|
||||||
/* Give the people what they want. */
|
/* Give the people what they want. */
|
||||||
|
@ -31,8 +31,8 @@
|
|||||||
int
|
int
|
||||||
NC4_inq_format(int ncid, int *formatp)
|
NC4_inq_format(int ncid, int *formatp)
|
||||||
{
|
{
|
||||||
NC *nc;
|
|
||||||
NC_FILE_INFO_T *nc4_info;
|
NC_FILE_INFO_T *nc4_info;
|
||||||
|
int retval;
|
||||||
|
|
||||||
LOG((2, "nc_inq_format: ncid 0x%x", ncid));
|
LOG((2, "nc_inq_format: ncid 0x%x", ncid));
|
||||||
|
|
||||||
@ -40,11 +40,10 @@ NC4_inq_format(int ncid, int *formatp)
|
|||||||
return NC_NOERR;
|
return NC_NOERR;
|
||||||
|
|
||||||
/* Find the file metadata. */
|
/* Find the file metadata. */
|
||||||
if (!(nc = nc4_find_nc_file(ncid,&nc4_info)))
|
if ((retval = nc4_find_nc_grp_h5(ncid, NULL, NULL, &nc4_info)))
|
||||||
return NC_EBADID;
|
return retval;
|
||||||
|
|
||||||
/* Otherwise, this is a netcdf-4 file. Check if classic NC3 rules
|
/* Check if classic NC3 rules are in effect for this file. */
|
||||||
* are in effect for this file. */
|
|
||||||
if (nc4_info->cmode & NC_CLASSIC_MODEL)
|
if (nc4_info->cmode & NC_CLASSIC_MODEL)
|
||||||
*formatp = NC_FORMAT_NETCDF4_CLASSIC;
|
*formatp = NC_FORMAT_NETCDF4_CLASSIC;
|
||||||
else
|
else
|
||||||
@ -73,15 +72,15 @@ int
|
|||||||
NC4_inq_format_extended(int ncid, int *formatp, int *modep)
|
NC4_inq_format_extended(int ncid, int *formatp, int *modep)
|
||||||
{
|
{
|
||||||
NC *nc;
|
NC *nc;
|
||||||
NC_FILE_INFO_T *h5;
|
int retval;
|
||||||
|
|
||||||
LOG((2, "%s: ncid 0x%x", __func__, ncid));
|
LOG((2, "%s: ncid 0x%x", __func__, ncid));
|
||||||
|
|
||||||
/* Find the file metadata. */
|
if ((retval = nc4_find_nc_grp_h5(ncid, &nc, NULL, NULL)))
|
||||||
if (!(nc = nc4_find_nc_file(ncid,&h5)))
|
|
||||||
return NC_EBADID;
|
return NC_EBADID;
|
||||||
|
|
||||||
if(modep) *modep = (nc->mode|NC_NETCDF4);
|
if(modep)
|
||||||
|
*modep = nc->mode|NC_NETCDF4;
|
||||||
|
|
||||||
if (formatp)
|
if (formatp)
|
||||||
*formatp = NC_FORMATX_NC_HDF5;
|
*formatp = NC_FORMATX_NC_HDF5;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user