Skip to content

Commit

Permalink
Modified nc_inq_type so that it will return valid information for val…
Browse files Browse the repository at this point in the history
…id data types even if the associated ncid doesn't have access to those data types. See #240 for more information.
  • Loading branch information
WardF committed Apr 5, 2016
1 parent aa6a396 commit 6409b11
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion include/netcdf.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ extern "C" {
#define NC_CHAR 2 /**< ISO/ASCII character */
#define NC_SHORT 3 /**< signed 2 byte integer */
#define NC_INT 4 /**< signed 4 byte integer */
#define NC_LONG NC_INT /**< deprecated, but required for backward compatibility. */
#define NC_LONG NC_INT /**< \deprecated required for backward compatibility. */
#define NC_FLOAT 5 /**< single precision floating point number */
#define NC_DOUBLE 6 /**< double precision floating point number */
#define NC_UBYTE 7 /**< unsigned 1 byte int */
Expand Down
2 changes: 1 addition & 1 deletion libdispatch/dfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -1587,7 +1587,7 @@ nc_inq_type(int ncid, nc_type xtype, char *name, size_t *size)
if(stat != NC_NOERR) { /* bad ncid; do what we can */
/* For compatibility, we need to allow inq about
atomic types, even if ncid is ill-defined */
if(xtype <= ATOMICTYPEMAX3) {
if(xtype <= ATOMICTYPEMAX5) {
if(name) strncpy(name,NC_atomictypename(xtype),NC_MAX_NAME);
if(size) *size = NC_atomictypelen(xtype);
return NC_NOERR;
Expand Down
11 changes: 9 additions & 2 deletions libsrc/nc3internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ NC_check_vlens(NC3_INFO *ncp)
if (fIsSet(ncp->flags,NC_64BIT_DATA)) {
/* CDF5 format allows many large vars */
return NC_NOERR;
}
}
if (fIsSet(ncp->flags,NC_64BIT_OFFSET) && sizeof(off_t) > 4) {
/* CDF2 format and LFS */
vlen_max = X_UINT_MAX - 3; /* "- 3" handles rounded-up size */
Expand Down Expand Up @@ -1582,7 +1582,7 @@ NC3_inq_format(int ncid, int *formatp)
else if (fIsSet(nc3->flags, NC_64BIT_OFFSET))
*formatp = NC_FORMAT_64BIT_OFFSET;
else
*formatp = NC_FORMAT_CLASSIC;
*formatp = NC_FORMAT_CLASSIC;
return NC_NOERR;
}

Expand Down Expand Up @@ -1628,11 +1628,18 @@ NC3_inq_type(int ncid, nc_type typeid, char *name, size_t *size)
return stat;

/* Only netCDF classic model and CDF-5 need to be handled. */
/* After discussion, this seems like an artificial limitation.
See https://github.com/Unidata/netcdf-c/issues/240 for more
discussion. */
/*
if((ncp->mode & NC_CDF5) != 0) {
if (typeid < NC_BYTE || typeid > NC_STRING)
return NC_EBADTYPE;
} else if (typeid < NC_BYTE || typeid > NC_DOUBLE)
return NC_EBADTYPE;
*/
if(typeid < NC_BYTE || typeid > NC_STRING)
return NC_EBADTYPE;

/* Give the user the values they want. Subtract one because types
* are numbered starting at 1, not 0. */
Expand Down

0 comments on commit 6409b11

Please sign in to comment.