Check if group exists

I am implementing HDF5 where I need to check if given group name exists in
the file or not. How do I do it?
I checked using:

H5G_info_t *grpInfo;
hid_t lapl_id = H5Pcreate(H5P_LINK_ACCESS);
H5Gget_info_by_name(file_id, groupName, grpInfo, lapl_id);

Please let me know if I can use 'grpInfo' to open existing group?

Actually, what I want is, if the group name doesn't exist then I should
create new with the same name.

But, if it is there in the file then I should open it..

Is it possible?

···

-----
Best Regards,
Santosh
--
View this message in context: http://hdf-forum.184993.n3.nabble.com/Check-if-group-exists-tp2601701p2601701.html
Sent from the hdf-forum mailing list archive at Nabble.com.

I am not sure if my solution is the 'one right way', but it seems to work. See below.

Good luck,
Paul.

    subroutine open_or_create_h5group(loc_id, group_name, group_id, hdferr)
        ! Check if group with the given name exists. Create it if it doesn't,
        ! open it if it does.
        implicit none
        integer, intent(in) :: loc_id
        character(len=*), intent(in) :: group_name
        integer, intent(inout) :: hdferr
        integer, intent(out) :: group_id
        ! Local variables
        ! Variable for checking if a group exists or not
        logical :: group_exists

        call h5lexists_f(loc_id, group_name, group_exists, hdferr)
        if (group_exists) then
            call h5gopen_f(loc_id, group_name, group_id, hdferr)
        else
            call h5gcreate_f(loc_id, group_name, group_id, hdferr)
        end if
    end subroutine open_or_create_h5group

···

On 1. mars 2011, at 10.11, santoshdarekar wrote:

I am implementing HDF5 where I need to check if given group name exists in
the file or not. How do I do it?
I checked using:

H5G_info_t *grpInfo;
hid_t lapl_id = H5Pcreate(H5P_LINK_ACCESS);
H5Gget_info_by_name(file_id, groupName, grpInfo, lapl_id);

Please let me know if I can use 'grpInfo' to open existing group?

Actually, what I want is, if the group name doesn't exist then I should
create new with the same name.

But, if it is there in the file then I should open it..

Is it possible?

-----
Best Regards,
Santosh
--
View this message in context: http://hdf-forum.184993.n3.nabble.com/Check-if-group-exists-tp2601701p2601701.html
Sent from the hdf-forum mailing list archive at Nabble.com.

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

I am not sure if my solution is the 'one right way', but it seems to work. See below.

  Yes, this is a good way to using H5Lexists() to check for an existing link to an object (a group in the original poster's case).

    Quincey

···

On Mar 1, 2011, at 4:08 AM, Paul Anton Letnes wrote:

Good luck,
Paul.

   subroutine open_or_create_h5group(loc_id, group_name, group_id, hdferr)
       ! Check if group with the given name exists. Create it if it doesn't,
       ! open it if it does.
       implicit none
       integer, intent(in) :: loc_id
       character(len=*), intent(in) :: group_name
       integer, intent(inout) :: hdferr
       integer, intent(out) :: group_id
       ! Local variables
       ! Variable for checking if a group exists or not
       logical :: group_exists

       call h5lexists_f(loc_id, group_name, group_exists, hdferr)
       if (group_exists) then
           call h5gopen_f(loc_id, group_name, group_id, hdferr)
       else
           call h5gcreate_f(loc_id, group_name, group_id, hdferr)
       end if
   end subroutine open_or_create_h5group

On 1. mars 2011, at 10.11, santoshdarekar wrote:

I am implementing HDF5 where I need to check if given group name exists in
the file or not. How do I do it?
I checked using:

H5G_info_t *grpInfo;
hid_t lapl_id = H5Pcreate(H5P_LINK_ACCESS);
H5Gget_info_by_name(file_id, groupName, grpInfo, lapl_id);

Please let me know if I can use 'grpInfo' to open existing group?

Actually, what I want is, if the group name doesn't exist then I should
create new with the same name.

But, if it is there in the file then I should open it..

Is it possible?

-----
Best Regards,
Santosh
--
View this message in context: http://hdf-forum.184993.n3.nabble.com/Check-if-group-exists-tp2601701p2601701.html
Sent from the hdf-forum mailing list archive at Nabble.com.

_______________________________________________
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

Could you please code the same in java..

···

--
View this message in context: http://hdf-forum.184993.n3.nabble.com/Check-if-group-exists-tp2601701p3828423.html
Sent from the hdf-forum mailing list archive at Nabble.com.