Writing comment to attribute succeeds?

Hi all,

My understanding is that it is not valid to write a comment to an
attribute. However, the following code runs without error on
1.8.5-p1:

#include <hdf5.h>

int main()
{
    const hid_t f = H5Fcreate(
            "foo.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
    H5Oset_comment(f, "file comment");

    hsize_t dims = 1;
    const hid_t s = H5Screate_simple(1, &dims, NULL);
    const hid_t a = H5Acreate2(
            f, "x", H5T_NATIVE_INT, s, H5P_DEFAULT, H5P_DEFAULT);
    H5Sclose(s);
    int x = 5;
    H5Awrite(a, H5T_NATIVE_INT, &x);
    H5Oset_comment(a, "attribute comment");
    H5Aclose(a);
    H5Fclose(f);

    return 0;
}

Running the compiled binary and examining the foo.h5 file it produces
with h5dump shows

HDF5 "foo.h5" {
GROUP "/" {
   COMMENT "attribute comment"
   ATTRIBUTE "x" {
      DATATYPE H5T_STD_I32LE
      DATASPACE SIMPLE { ( 1 ) / ( 1 ) }
      DATA {
      (0): 5
      }
   }
}
}

where it appears that setting the comment on an attribute overwrites
the file-level comment.

Two questions arise:

1) Am I incorrect in saying that an attribute cannot contain a comment?
2) Is HDF5 1.8.5-p1 failing to detect a usage error in my sample code?

Thanks,
Rhys

Rhys,

Hmmm...Looks like combination of a bug and a feature :wink:

According to the RM entry for H5Oset_comment, an attribute cannot have a comment because it is not "an HDF5 object" - attribute doesn't have a header; it is stored in the object header for a dataset, group, or named datatype.

But I would expect the second H5Oset_comment call to fail and leave a root group comment intact. This looks like a bug to me. Will add it to our issues database.

Thank you!

Elena

···

On Jan 14, 2011, at 4:43 PM, Rhys Ulerich wrote:

Hi all,

My understanding is that it is not valid to write a comment to an
attribute. However, the following code runs without error on
1.8.5-p1:

#include <hdf5.h>

int main()
{
   const hid_t f = H5Fcreate(
           "foo.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
   H5Oset_comment(f, "file comment");

   hsize_t dims = 1;
   const hid_t s = H5Screate_simple(1, &dims, NULL);
   const hid_t a = H5Acreate2(
           f, "x", H5T_NATIVE_INT, s, H5P_DEFAULT, H5P_DEFAULT);
   H5Sclose(s);
   int x = 5;
   H5Awrite(a, H5T_NATIVE_INT, &x);
   H5Oset_comment(a, "attribute comment");
   H5Aclose(a);
   H5Fclose(f);

   return 0;
}

Running the compiled binary and examining the foo.h5 file it produces
with h5dump shows

HDF5 "foo.h5" {
GROUP "/" {
  COMMENT "attribute comment"
  ATTRIBUTE "x" {
     DATATYPE H5T_STD_I32LE
     DATASPACE SIMPLE { ( 1 ) / ( 1 ) }
     DATA {
     (0): 5
     }
  }
}
}

where it appears that setting the comment on an attribute overwrites
the file-level comment.

Two questions arise:

1) Am I incorrect in saying that an attribute cannot contain a comment?
2) Is HDF5 1.8.5-p1 failing to detect a usage error in my sample code?

Thanks,
Rhys

_______________________________________________
Hdf-forum is for HDF software users discussion.
Hdf-forum@hdfgroup.org
http://mail.hdfgroup.org/mailman/listinfo/hdf-forum_hdfgroup.org