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:
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: