Hi Corey,
-----Original Message-----
From: hdf-forum-bounces@hdfgroup.org [mailto:hdf-forum-bounces@hdfgroup.org]
On Behalf Of Corey Bettenhausen
Sent: Friday, April 22, 2011 11:39 AM
To: HDF Users Discussion List
Subject: [Hdf-forum] Scalar vs array attributes, HDF5, ncdump
Hello,
I'm trying to create HDF5 files that are as compatible as possible with the
netCDF library and its tools. I recently came across an issue that I can't
figure out.
ncdump (v4.1.2) cannot read scalar, numeric attributes written with the HDF5
library. However, it can if they're written as a single element array. I've
attached a short Fortran program and example output, HDF5 files. Any
thoughts on what's causing this incompatibility?
Regards,
-Corey
I ran into a similar problem a few months ago with a Simple 1x1 attribute of
type H5T_STD_I32LE. I couldn't remember quite what the issue was, so I used
gdb to trace the error message for that particular attribute type to this
code in nc4file.c line 872:
/* All netcdf attributes are 1-D only. */
if (att_ndims != 1)
BAIL(NC_EATTMETA);
According to the comments in the entire section of code that contains these
lines, netCDF-4 supports: 1. Zero length attributes. 2. Scalar, NC_CHAR,
H5ST_C_S1, variable length string attributes, and 3. 1 dimensional
attributes of other (i.e. numeric) types. Scalar, numeric attributes fail
because they have dimension 0 but att_npoints (length) > 0, therefore they
don't fall in any of the three supported categories. The section of code,
lines 847-878 of nc4file.c is below.
I don't know for sure why netCDF-4 limits attributes to these 3 categories,
but I plan to ask, in the hope they can be expanded.
Regards,
Larry
Nc4file.c:847 - 878
/* If both att_ndims and att_npoints are zero, then this is a
* zero length att. */
if (att_ndims == 0 && att_npoints == 0)
{
dims[0] = 0;
}
else if (att->xtype == NC_CHAR)
{
/* NC_CHAR attributes are written as a scalar in HDF5, of type
* H5T_C_S1, of variable length. */
if (att_ndims == 0)
{
if (!(dims[0] = H5Tget_size(file_typeid)))
BAIL(NC_EATTMETA);
}
else
{
/* This is really a string type! */
att->xtype = NC_STRING;
dims[0] = att_npoints;
}
}
else
{
/* All netcdf attributes are 1-D only. */
if (att_ndims != 1)
BAIL(NC_EATTMETA);
/* Read the size of this attribute. */
if (H5Sget_simple_extent_dims(spaceid, dims, NULL) < 0)
BAIL(NC_EATTMETA);
}