Error with H5Oget_info_by_idx on soft links

Hi,

I don't understand why the following code returns an error (hdf5 version is 1.8.8 with Debian testing):

#include <hdf5.h>
#include <stdio.h>

int main(int argc, char ** argv)
{
     hid_t file = H5Fcreate("/tmp/plop.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
     H5Lcreate_soft("abc", file, "def", H5P_DEFAULT, H5P_DEFAULT);
     H5Fclose(file);

     file = H5Fopen("/tmp/plop.h5", H5F_ACC_RDONLY, H5P_DEFAULT);
     hid_t root = H5Gopen2(file, "/", H5P_DEFAULT);
     H5G_info_t info;
     herr_t err = H5Gget_info(root, &info);
     hsize_t i = 0;

     printf("nlinks=%i\n", info.nlinks);

     for (; i < info.nlinks; i++)
     {
     H5O_info_t objinfo;
     err = H5Oget_info_by_idx(root, ".", H5_INDEX_NAME, H5_ITER_INC, i, &objinfo, H5P_DEFAULT);
     printf("addr=%u\n", objinfo.addr);
     }

     H5Gclose(root);
     H5Fclose(file);

     return 0;
}

Is it a bug ? or is a link not an object ?

Thanks

Calixte

Calixte, how are you? It's the latter. The documentation is not very precise
on this,
but HDF5 links aren't HDF5 objects. See section '1.2.2 Group', Figures 5 and
6 in the HDF5 User Guide.

http://www.hdfgroup.org/HDF5/doc/UG/

The H5L interface has several functions for inspecting HDF5 links.

Best, G.

···

-----Original Message-----
From: hdf-forum-bounces@hdfgroup.org [mailto:hdf-forum-bounces@hdfgroup.org]
On Behalf Of Calixte Denizet
Sent: Wednesday, September 12, 2012 2:19 PM
To: hdf-forum@hdfgroup.org
Subject: [Hdf-forum] Error with H5Oget_info_by_idx on soft links

Hi,

I don't understand why the following code returns an error (hdf5 version is
1.8.8 with Debian testing):

#include <hdf5.h>
#include <stdio.h>

int main(int argc, char ** argv)
{
     hid_t file = H5Fcreate("/tmp/plop.h5", H5F_ACC_TRUNC, H5P_DEFAULT,
H5P_DEFAULT);
     H5Lcreate_soft("abc", file, "def", H5P_DEFAULT, H5P_DEFAULT);
     H5Fclose(file);

     file = H5Fopen("/tmp/plop.h5", H5F_ACC_RDONLY, H5P_DEFAULT);
     hid_t root = H5Gopen2(file, "/", H5P_DEFAULT);
     H5G_info_t info;
     herr_t err = H5Gget_info(root, &info);
     hsize_t i = 0;

     printf("nlinks=%i\n", info.nlinks);

     for (; i < info.nlinks; i++)
     {
     H5O_info_t objinfo;
     err = H5Oget_info_by_idx(root, ".", H5_INDEX_NAME, H5_ITER_INC, i,
&objinfo, H5P_DEFAULT);
     printf("addr=%u\n", objinfo.addr);
     }

     H5Gclose(root);
     H5Fclose(file);

     return 0;
}

Is it a bug ? or is a link not an object ?

Thanks

Calixte

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

Hi Gerd,

Calixte, how are you ?

fine, thanks.

It's the latter. The documentation is not very precise
on this,
but HDF5 links aren't HDF5 objects. See section '1.2.2 Group', Figures 5 and
6 in the HDF5 User Guide.

I finally found this page :wink: and I understood my error.

My misunderstanding was coming from the fact that the following code is working:

  for (; i < info.nlinks; i++)
  {
     H5O_info_t objinfo;
     int type = H5Gget_objtype_by_idx(root, i);
     printf("type=%d\n", type);
  }

when there are only dangling links (found in the test file tslink.h5). And the doc about H5Gget_objtype_by_idx just said that this function is deprecated in favor of H5Oget_info_by_idx.

Thanks for your answer.

Regards

Calixte

···

On 13/09/2012 17:27, Gerd Heber wrote:

http://www.hdfgroup.org/HDF5/doc/UG/

The H5L interface has several functions for inspecting HDF5 links.

Best, G.

-----Original Message-----
From: hdf-forum-bounces@hdfgroup.org [mailto:hdf-forum-bounces@hdfgroup.org]
On Behalf Of Calixte Denizet
Sent: Wednesday, September 12, 2012 2:19 PM
To: hdf-forum@hdfgroup.org
Subject: [Hdf-forum] Error with H5Oget_info_by_idx on soft links

Hi,

I don't understand why the following code returns an error (hdf5 version is
1.8.8 with Debian testing):

#include<hdf5.h>
#include<stdio.h>

int main(int argc, char ** argv)
{
      hid_t file = H5Fcreate("/tmp/plop.h5", H5F_ACC_TRUNC, H5P_DEFAULT,
H5P_DEFAULT);
      H5Lcreate_soft("abc", file, "def", H5P_DEFAULT, H5P_DEFAULT);
      H5Fclose(file);

      file = H5Fopen("/tmp/plop.h5", H5F_ACC_RDONLY, H5P_DEFAULT);
      hid_t root = H5Gopen2(file, "/", H5P_DEFAULT);
      H5G_info_t info;
      herr_t err = H5Gget_info(root,&info);
      hsize_t i = 0;

      printf("nlinks=%i\n", info.nlinks);

      for (; i< info.nlinks; i++)
      {
      H5O_info_t objinfo;
      err = H5Oget_info_by_idx(root, ".", H5_INDEX_NAME, H5_ITER_INC, i,
&objinfo, H5P_DEFAULT);
      printf("addr=%u\n", objinfo.addr);
      }

      H5Gclose(root);
      H5Fclose(file);

      return 0;
}

Is it a bug ? or is a link not an object ?

Thanks

Calixte

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

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