Hi folks
  yesterday I discovered an interesting behavior of the HDF5 1.8.12
(Debian Wheezy system) library when accessing objects in a group by
index (see the attached C file for an example). 

If the parent group has only a single child and this child is an
external link H5Oopen_by_idx fails if the index type is
H5_INDEX_CRT_ORDER. When using H5_INDEX_NAME everything seems to work
fine.

Is this a bug or a feature?

best regards
  Eugen

-- 
------------------------------------
DI. Dr. Eugen Wintersberger         
                                    
FS-EC                              
DESY                    
Notkestrasse 85                       
D-22607 Hamburg                    
Germany                            
                                   
E-Mail: [email protected]
Telefon: +49-40-8998-1917          
-----------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <hdf5.h>

void create_data_file(const char *fname)
{
    hid_t file_id, dataset_id, datatype_id, dataspace_id;
    hsize_t dims[] = {1,100,200};

    /* open the data file*/
    file_id = H5Fcreate(fname,H5F_ACC_TRUNC,H5P_DEFAULT,H5P_DEFAULT);

    /*create data  type*/
    datatype_id = H5Tcopy(H5T_NATIVE_INT);

    /*create dataspace*/
    dataspace_id = H5Screate_simple(3,dims,dims);

    /*create the dataset*/
    dataset_id = H5Dcreate(file_id,"data",datatype_id,dataspace_id,
                           H5P_DEFAULT,H5P_DEFAULT,H5P_DEFAULT);

    /*close everything*/
    H5Dclose(dataset_id);
    H5Sclose(dataspace_id);
    H5Tclose(datatype_id);
    H5Fclose(file_id);
}

/*----------------------------------------------------------------------------*/
hid_t create_link_file(const char *fname)
{
    hid_t file_id;

    file_id = H5Fcreate(fname,H5F_ACC_TRUNC,H5P_DEFAULT,H5P_DEFAULT);

    H5Lcreate_external("external_data.h5","/data",file_id,"linked_data",
                       H5P_DEFAULT,H5P_DEFAULT);

    return file_id;
}

/*----------------------------------------------------------------------------*/
void open_dataset_by_name(hid_t group_id)
{
    hid_t dataset_id;
    /*try to access the linked data by its name*/
    dataset_id = H5Oopen(group_id,"linked_data",H5P_DEFAULT);
    if((dataset_id<0) && (H5Iget_type(dataset_id)!=H5I_DATASET))
    {
        fprintf(stderr,"Could not open external link by name!\n");
    }
    H5Oclose(dataset_id);
}

/*----------------------------------------------------------------------------*/
size_t get_number_of_links(hid_t group_id)
{
    H5G_info_t group_info;

    H5Gget_info(group_id,&group_info);
    return group_info.nlinks;
}

/*----------------------------------------------------------------------------*/
void open_dataset_by_index(hid_t group_id)
{
    hid_t child_id;
    size_t child_index = 0;
    size_t nlinks = get_number_of_links(group_id);

    /*check the number of links below the root group*/
    fprintf(stderr,"Number of children %u\n",nlinks);

    for(child_index = 0;child_index < nlinks;++child_index)
    {
        /* this would work */
        child_id = H5Oopen_by_idx(group_id,".",H5_INDEX_NAME,H5_ITER_NATIVE,
                                  child_index,H5P_DEFAULT);
        /*
        This would fail 

        child_id = H5Oopen_by_idx(group_id,".",H5_INDEX_CRT_ORDER,H5_ITER_NATIVE,
                                  child_index,H5P_DEFAULT);

        with the following error message

        HDF5-DIAG: Error detected in HDF5 (1.8.12) thread 140305466562304:
          #000: ../../../src/H5O.c line 312 in H5Oopen_by_idx(): group not found
            major: Symbol table
            minor: Object not found
          #001: ../../../src/H5Gloc.c line 541 in H5G_loc_find_by_idx(): can't find object
            major: Symbol table
            minor: Object not found
          #002: ../../../src/H5Gtraverse.c line 861 in H5G_traverse(): internal path traversal failed
            major: Symbol table
            minor: Object not found
          #003: ../../../src/H5Gtraverse.c line 780 in H5G_traverse_real(): traversal operator failed
            major: Symbol table
            minor: Can't move to next iterator location
          #004: ../../../src/H5Gloc.c line 472 in H5G_loc_find_by_idx_cb(): link not found
            major: Symbol table
            minor: Object not found
          #005: ../../../src/H5Gobj.c line 1199 in H5G_obj_lookup_by_idx(): creation order not tracked for links in group
            major: Symbol table
            minor: Object not found

        The reason might be that there has never been an object created in the
        group (creating a link maybe does not count as object creation ;)).

        */

        if(child_id < 0)
        {
            fprintf(stderr,"Error opening child!");
        }

    }
}

/*----------------------------------------------------------------------------*/
int main(int argc,char **argv)
{
    hid_t file_id;  /*ID to the file holding the link*/
    hid_t root_id;  /*ID to the root group*/
    size_t nlinks = 0;

    create_data_file("external_data.h5");
    file_id = create_link_file("external_link.h5");
    root_id = H5Oopen(file_id,"/",H5P_DEFAULT);

    /*open the dataset by name - should work*/
    open_dataset_by_name(root_id);

    /*open the dataset by index*/
    open_dataset_by_index(root_id);

    /*close root group and file*/
    H5Gclose(root_id);
    H5Fclose(file_id);

    return 0;
}

Attachment: signature.asc
Description: This is a digitally signed message part

_______________________________________________
Hdf-forum is for HDF software users discussion.
[email protected]
http://lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org
Twitter: https://twitter.com/hdf5

Reply via email to