Fix bug with scalar coordinate variables in netCDF-4 files, causing failure with --enable-extra-tests, [NCF-149]

This commit is contained in:
Russ Rew 2012-03-01 02:06:14 +00:00
parent 629f712c77
commit 22beaf407c
3 changed files with 136 additions and 135 deletions

View File

@ -1297,10 +1297,10 @@ read_var(NC_GRP_INFO_T *grp, hid_t datasetid, char *obj_name,
if (!(var->name = malloc((strlen(obj_name) + 1) * sizeof(char))))
return NC_ENOMEM;
/* Check for a weird case: a non-coordinate variable that has the
* same name as a dimension. It's legal in netcdf, and requires
* that the HDF5 dataset name be changed. */
if (!strncmp(obj_name, NON_COORD_PREPEND, strlen(NON_COORD_PREPEND)))
/* Check for a weird case: a non-coordinate (and non-scalar)
* variable that has the same name as a dimension. It's legal in
* netcdf, and requires that the HDF5 dataset name be changed. */
if (var->ndims && !strncmp(obj_name, NON_COORD_PREPEND, strlen(NON_COORD_PREPEND)))
{
if (strlen(obj_name) > NC_MAX_NAME)
return NC_EMAXNAME;
@ -1740,43 +1740,43 @@ read_dataset(NC_GRP_INFO_T *grp, char *obj_name)
static int
nc4_rec_read_types_cb(hid_t grpid, const char *name, const H5L_info_t *info,
void *_op_data)
void *_op_data)
{
hid_t oid=-1;
hid_t oid=-1;
H5I_type_t otype;
char oname[NC_MAX_NAME + 1];
NC_GRP_INFO_T *child_grp;
NC_GRP_INFO_T *grp = (NC_GRP_INFO_T *) (_op_data);
NC_HDF5_FILE_INFO_T *h5 = grp->file->nc4_info;
char oname[NC_MAX_NAME + 1];
NC_GRP_INFO_T *child_grp;
NC_GRP_INFO_T *grp = (NC_GRP_INFO_T *) (_op_data);
NC_HDF5_FILE_INFO_T *h5 = grp->file->nc4_info;
/* Open this critter. */
if ((oid = H5Oopen(grpid, name, H5P_DEFAULT)) < 0)
return H5_ITER_ERROR;
if ((otype = H5Iget_type( oid ))<0) {
H5Oclose(oid);
return H5_ITER_ERROR;
}
H5Oclose(oid);
return H5_ITER_ERROR;
}
H5Oclose(oid);
strncpy(oname, name, NC_MAX_NAME);
strncpy(oname, name, NC_MAX_NAME);
/* Deal with groups and types; ignore the rest. */
/* Deal with groups and types; ignore the rest. */
if (otype == H5I_GROUP)
{
LOG((3, "found group %s", oname));
if (nc4_grp_list_add(&(grp->children), h5->next_nc_grpid++,
grp, grp->file, oname, &child_grp))
return H5_ITER_ERROR;
LOG((3, "found group %s", oname));
if (nc4_grp_list_add(&(grp->children), h5->next_nc_grpid++,
grp, grp->file, oname, &child_grp))
return H5_ITER_ERROR;
if (nc4_rec_read_types(child_grp))
return H5_ITER_ERROR;
}
if (nc4_rec_read_types(child_grp))
return H5_ITER_ERROR;
}
else if (otype == H5I_DATATYPE)
{
LOG((3, "found datatype %s", oname));
if (read_type(grp, oname))
return H5_ITER_ERROR;
LOG((3, "found datatype %s", oname));
if (read_type(grp, oname))
return H5_ITER_ERROR;
}
return (H5_ITER_CONT);
@ -1786,9 +1786,9 @@ int
nc4_rec_read_types(NC_GRP_INFO_T *grp)
{
hsize_t idx=0;
int res = 0;
hid_t pid = 0;
unsigned crt_order_flags = 0;
int res = 0;
hid_t pid = 0;
unsigned crt_order_flags = 0;
NC_HDF5_FILE_INFO_T *h5 = grp->file->nc4_info;
assert(grp && grp->name);
@ -1806,93 +1806,91 @@ nc4_rec_read_types(NC_GRP_INFO_T *grp)
}
else
{
if ((grp->hdf_grpid = H5Gopen2(grp->file->nc4_info->hdfid,
"/", H5P_DEFAULT)) < 0)
return NC_EHDFERR;
if ((grp->hdf_grpid = H5Gopen2(grp->file->nc4_info->hdfid,
"/", H5P_DEFAULT)) < 0)
return NC_EHDFERR;
}
}
assert(grp->hdf_grpid > 0);
pid = H5Gget_create_plist(grp->hdf_grpid);
H5Pget_link_creation_order(pid, &crt_order_flags);
H5Pclose(pid);
crt_order_flags = crt_order_flags & H5_INDEX_CRT_ORDER;
pid = H5Gget_create_plist(grp->hdf_grpid);
H5Pget_link_creation_order(pid, &crt_order_flags);
H5Pclose(pid);
crt_order_flags = crt_order_flags & H5_INDEX_CRT_ORDER;
if (crt_order_flags == H5_INDEX_CRT_ORDER)
{
res = H5Literate(grp->hdf_grpid, H5_INDEX_CRT_ORDER, H5_ITER_INC,
&idx, nc4_rec_read_types_cb, (void *)grp);
if (crt_order_flags == H5_INDEX_CRT_ORDER)
{
res = H5Literate(grp->hdf_grpid, H5_INDEX_CRT_ORDER, H5_ITER_INC,
&idx, nc4_rec_read_types_cb, (void *)grp);
} else
{
/* Without creation ordering, file must be read-only. */
if (!idx && !h5->no_write)
return NC_ECANTWRITE;
{
/* Without creation ordering, file must be read-only. */
if (!idx && !h5->no_write)
return NC_ECANTWRITE;
res = H5Literate(grp->hdf_grpid, H5_INDEX_NAME, H5_ITER_INC,
&idx, nc4_rec_read_types_cb, (void *)grp);
if (res<0)
return NC_EHDFERR;
}
return NC_NOERR; /* everything worked! */
res = H5Literate(grp->hdf_grpid, H5_INDEX_NAME, H5_ITER_INC,
&idx, nc4_rec_read_types_cb, (void *)grp);
if (res<0)
return NC_EHDFERR;
}
return NC_NOERR; /* everything worked! */
}
static int
nc4_rec_read_vars_cb(hid_t grpid, const char *name, const H5L_info_t *info,
void *_op_data)
void *_op_data)
{
hid_t oid=-1;
hid_t oid=-1;
H5I_type_t otype;
char oname[NC_MAX_NAME + 1];
NC_GRP_INFO_T *child_grp;
NC_GRP_INFO_T *grp = (NC_GRP_INFO_T *) (_op_data);
NC_HDF5_FILE_INFO_T *h5 = grp->file->nc4_info;
char oname[NC_MAX_NAME + 1];
NC_GRP_INFO_T *child_grp;
NC_GRP_INFO_T *grp = (NC_GRP_INFO_T *) (_op_data);
NC_HDF5_FILE_INFO_T *h5 = grp->file->nc4_info;
/* Open this critter. */
if ((oid = H5Oopen(grpid, name, H5P_DEFAULT)) < 0)
return H5_ITER_ERROR;
if ((otype = H5Iget_type( oid ))<0) {
H5Oclose(oid);
return H5_ITER_ERROR;
}
H5Oclose(oid);
return H5_ITER_ERROR;
}
H5Oclose(oid);
strncpy(oname, name, NC_MAX_NAME);
strncpy(oname, name, NC_MAX_NAME);
/* Deal with datasets. */
switch(otype)
{
case H5I_GROUP:
LOG((3, "re-encountering group %s", oname));
case H5I_GROUP:
LOG((3, "re-encountering group %s", oname));
/* The NC_GROUP_INFO_T for this group already exists. Find it. */
for (child_grp = grp->children; child_grp; child_grp = child_grp->next)
if (!strcmp(child_grp->name, oname))
break;
if (!child_grp)
return H5_ITER_ERROR;
/* The NC_GROUP_INFO_T for this group already exists. Find it. */
for (child_grp = grp->children; child_grp; child_grp = child_grp->next)
if (!strcmp(child_grp->name, oname))
break;
if (!child_grp)
return H5_ITER_ERROR;
/* Recursively read the child group's vars. */
if (nc4_rec_read_vars(child_grp))
return H5_ITER_ERROR;
break;
case H5I_DATASET:
LOG((3, "found dataset %s", oname));
/* Recursively read the child group's vars. */
if (nc4_rec_read_vars(child_grp))
return H5_ITER_ERROR;
break;
case H5I_DATASET:
LOG((3, "found dataset %s", oname));
/* Learn all about this dataset, which may be a dimscale
* (i.e. dimension metadata), or real data. */
if (read_dataset(grp, oname))
return H5_ITER_ERROR;
break;
case H5I_DATATYPE:
LOG((3, "already handled type %s", oname));
break;
default:
LOG((0, "Unknown object class %d in nc4_rec_read_vars!", otype));
}
/* Learn all about this dataset, which may be a dimscale
* (i.e. dimension metadata), or real data. */
if (read_dataset(grp, oname))
return H5_ITER_ERROR;
break;
case H5I_DATATYPE:
LOG((3, "already handled type %s", oname));
break;
default:
LOG((0, "Unknown object class %d in nc4_rec_read_vars!", otype));
}
return (H5_ITER_CONT);
}
@ -1901,41 +1899,41 @@ nc4_rec_read_vars(NC_GRP_INFO_T *grp)
{
hsize_t idx = 0;
int retval = NC_NOERR;
int res = 0;
hid_t pid = 0;
unsigned crt_order_flags = 0;
int res = 0;
hid_t pid = 0;
unsigned crt_order_flags = 0;
NC_HDF5_FILE_INFO_T *h5 = grp->file->nc4_info;
assert(grp && grp->name && grp->hdf_grpid > 0);
LOG((3, "nc4_rec_read_vars: grp->name %s", grp->name));
assert(grp && grp->name && grp->hdf_grpid > 0);
LOG((3, "nc4_rec_read_vars: grp->name %s", grp->name));
pid = H5Gget_create_plist(grp->hdf_grpid);
H5Pget_link_creation_order(pid, &crt_order_flags);
H5Pclose(pid);
crt_order_flags = crt_order_flags & H5_INDEX_CRT_ORDER;
pid = H5Gget_create_plist(grp->hdf_grpid);
H5Pget_link_creation_order(pid, &crt_order_flags);
H5Pclose(pid);
crt_order_flags = crt_order_flags & H5_INDEX_CRT_ORDER;
if (crt_order_flags == H5_INDEX_CRT_ORDER)
{
res = H5Literate(grp->hdf_grpid, H5_INDEX_CRT_ORDER, H5_ITER_INC,
&idx, nc4_rec_read_vars_cb, (void *)grp);
if (crt_order_flags == H5_INDEX_CRT_ORDER)
{
res = H5Literate(grp->hdf_grpid, H5_INDEX_CRT_ORDER, H5_ITER_INC,
&idx, nc4_rec_read_vars_cb, (void *)grp);
} else
{
/* Without creation ordering, file must be read-only. */
if (!idx && !h5->no_write)
return NC_ECANTWRITE;
{
/* Without creation ordering, file must be read-only. */
if (!idx && !h5->no_write)
return NC_ECANTWRITE;
res = H5Literate(grp->hdf_grpid, H5_INDEX_NAME, H5_ITER_INC,
&idx, nc4_rec_read_vars_cb, (void *)grp);
if (res<0)
return NC_EHDFERR;
}
res = H5Literate(grp->hdf_grpid, H5_INDEX_NAME, H5_ITER_INC,
&idx, nc4_rec_read_vars_cb, (void *)grp);
if (res<0)
return NC_EHDFERR;
}
/* Scan the group for global (i.e. group-level) attributes. */
if ((retval = read_grp_atts(grp)))
return retval;
return NC_NOERR; /* everything worked! */
/* Scan the group for global (i.e. group-level) attributes. */
if ((retval = read_grp_atts(grp)))
return retval;
return NC_NOERR; /* everything worked! */
}
#else

View File

@ -567,17 +567,19 @@ nc4_put_vara(NC_FILE_INFO_T *nc, int ncid, int varid, const size_t *startp,
count[i] = countp[i];
}
/* Open this dataset if necessary, first checking for the case of
* a non-coordinate variable that has the same name as a dimension. */
/* Open this dataset if necessary, also checking for a weird case:
* a non-coordinate (and non-scalar) variable that has the same
* name as a dimension. */
if (var->hdf5_name && strlen(var->hdf5_name) >= strlen(NON_COORD_PREPEND) &&
strncmp(var->hdf5_name, NON_COORD_PREPEND, strlen(NON_COORD_PREPEND)) == 0)
strncmp(var->hdf5_name, NON_COORD_PREPEND, strlen(NON_COORD_PREPEND)) == 0 &&
var->ndims)
if ((var->hdf_datasetid = H5Dopen2(grp->hdf_grpid, var->hdf5_name,
H5P_DEFAULT)) < 0)
return NC_ENOTVAR;
if (!var->hdf_datasetid)
if ((var->hdf_datasetid = H5Dopen2(grp->hdf_grpid, var->name,
H5P_DEFAULT)) < 0)
return NC_ENOTVAR;
if ((var->hdf_datasetid = H5Dopen2(grp->hdf_grpid, var->name,
H5P_DEFAULT)) < 0)
return NC_ENOTVAR;
/* Get file space of data. */
if ((file_spaceid = H5Dget_space(var->hdf_datasetid)) < 0)
@ -870,17 +872,18 @@ nc4_get_vara(NC_FILE_INFO_T *nc, int ncid, int varid, const size_t *startp,
}
/* Open this dataset if necessary, also checking for a weird case:
* a non-coordinate variable that has the same name as a
* dimension. */
* a non-coordinate (and non-scalar) variable that has the same
* name as a dimension. */
if (var->hdf5_name && strlen(var->hdf5_name) >= strlen(NON_COORD_PREPEND) &&
strncmp(var->hdf5_name, NON_COORD_PREPEND, strlen(NON_COORD_PREPEND)) == 0)
strncmp(var->hdf5_name, NON_COORD_PREPEND, strlen(NON_COORD_PREPEND)) == 0 &&
var->ndims)
if ((var->hdf_datasetid = H5Dopen2(grp->hdf_grpid, var->hdf5_name,
H5P_DEFAULT)) < 0)
return NC_ENOTVAR;
if (!var->hdf_datasetid)
if ((var->hdf_datasetid = H5Dopen2(grp->hdf_grpid, var->name,
H5P_DEFAULT)) < 0)
return NC_ENOTVAR;
if ((var->hdf_datasetid = H5Dopen2(grp->hdf_grpid, var->name,
H5P_DEFAULT)) < 0)
return NC_ENOTVAR;
/* Get file space of data. */
if ((file_spaceid = H5Dget_space(var->hdf_datasetid)) < 0)

View File

@ -45,7 +45,7 @@
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories=".;&quot;$(SolutionDir)&quot;;..\..\..\libsrc4;..\..\..\libsrc;..\..\..\fortran;C:\include"
AdditionalIncludeDirectories=".;&quot;$(SolutionDir)&quot;;..\..\..\libsrc4;..\..\..\libsrc;C:\include"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;NETCDF_EXPORTS;_HDF5USEDLL_;DLL_NETCDF;DLL_EXPORT;VISUAL_CPLUSPLUS;_FILE_OFFSET_BITS=64;NC_DLL_EXPORT;USE_DISPATCH;H5_HAVE_WINDOWS;USE_NETCDF4"
MinimalRebuild="true"
BasicRuntimeChecks="3"
@ -128,7 +128,7 @@
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories=".;&quot;$(SolutionDir)&quot;;..\..\..\libsrc4;..\..\..\libsrc;..\..\..\fortran;C:\include"
AdditionalIncludeDirectories=".;&quot;$(SolutionDir)&quot;;..\..\..\libsrc4;..\..\..\libsrc;C:\include"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;NETCDF_EXPORTS;_HDF5USEDLL_;DLL_NETCDF;DLL_EXPORT;VISUAL_CPLUSPLUS;_FILE_OFFSET_BITS=64;NC_DLL_EXPORT;USE_DISPATCH;H5_HAVE_WINDOWS;USE_NETCDF4"
MinimalRebuild="true"
BasicRuntimeChecks="3"
@ -209,8 +209,8 @@
/>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="&quot;C:\Users\Unidata\netcdf-4.1.3-win-dev\include\hdf5&quot;;&quot;C:\Users\Unidata\netcdf-4.1.3-win-dev\include&quot;;..\..\..\include;.;&quot;$(SolutionDir)&quot;;..;..\..\..\libsrc4;..\..\..\libsrc;..\..\..\libdispatch;..\..\..\libncdap3;..\..\..\fortran;..\..\..\oc"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;CURL_STATICLIB;NETCDF_EXPORTS;DLL_NETCDF;DLL_EXPORT;pgiFortran;NC_DLL_EXPORT;USE_DISPATCH;H5_HAVE_WINDOWS;USE_NETCDF4"
AdditionalIncludeDirectories="&quot;C:\Users\Unidata\netcdf-4.1.3-win-dev\include\hdf5&quot;;&quot;C:\Users\Unidata\netcdf-4.1.3-win-dev\include&quot;;..\..\..\include;.;&quot;$(SolutionDir)&quot;;..;..\..\..\libsrc4;..\..\..\libsrc;..\..\..\libdispatch;..\..\..\libncdap3;..\..\..\oc"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;CURL_STATICLIB;NETCDF_EXPORTS;DLL_NETCDF;DLL_EXPORT;NC_DLL_EXPORT;USE_DISPATCH;H5_HAVE_WINDOWS;USE_NETCDF4"
RuntimeLibrary="2"
UsePrecompiledHeader="0"
ProgramDataBaseFileName="$(IntDir)/vc90_netcdf.pdb"
@ -291,8 +291,8 @@
/>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=".;&quot;$(SolutionDir)&quot;;..;..\..\..\libsrc4;..\..\..\libsrc;..\..\..\libdispatch;..\..\..\libncdap3;..\..\..\fortran;..\..\..\oc;..\..\..\include"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;CURL_STATICLIB;NETCDF_EXPORTS;DLL_NETCDF;DLL_EXPORT;pgiFortran;NC_DLL_EXPORT;USE_DISPATCH;H5_HAVE_WINDOWS;USE_NETCDF4"
AdditionalIncludeDirectories=".;&quot;$(SolutionDir)&quot;;..;..\..\..\libsrc4;..\..\..\libsrc;..\..\..\libdispatch;..\..\..\libncdap3;..\..\..\oc;..\..\..\include"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;CURL_STATICLIB;NETCDF_EXPORTS;DLL_NETCDF;DLL_EXPORT;NC_DLL_EXPORT;USE_DISPATCH;H5_HAVE_WINDOWS;USE_NETCDF4"
RuntimeLibrary="2"
UsePrecompiledHeader="0"
ProgramDataBaseFileName="$(IntDir)/vc90_netcdf.pdb"