comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » How to check for existence of an HDF5 group
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
How to check for existence of an HDF5 group [message #90182] Sat, 07 February 2015 10:24 Go to next message
dg86 is currently offline  dg86
Messages: 118
Registered: September 2012
Senior Member
Dear Folks,

I want to create new groups within an HDF5 file. Before creating a new group, however,
I'd like to check whether a group of the same name already exists. What's the right
way to do this?

Calling H5G_OPEN or H5G_GET_OBJINFO with a new group name throws an error.
I could write a wrapper routine that catches the error and returns a "group not found"
value but that seems kludgy.

H5_LIST returns a whole lot of information, which I suppose I could parse. That also seems
clunky.

Is there a more elegant solution? Something along the lines of FILE_TEST that works
for HDF5 groups (H5G_TEST, e.g.)?

All the best,

David
Re: How to check for existence of an HDF5 group [message #90185 is a reply to message #90182] Sun, 08 February 2015 01:39 Go to previous messageGo to next message
markb77 is currently offline  markb77
Messages: 217
Registered: July 2006
Senior Member
On Saturday, February 7, 2015 at 7:24:50 PM UTC+1, David Grier wrote:
> Dear Folks,
>
> I want to create new groups within an HDF5 file. Before creating a new group, however,
> I'd like to check whether a group of the same name already exists. What's the right
> way to do this?
>
> Calling H5G_OPEN or H5G_GET_OBJINFO with a new group name throws an error.
> I could write a wrapper routine that catches the error and returns a "group not found"
> value but that seems kludgy.
>
> H5_LIST returns a whole lot of information, which I suppose I could parse. That also seems
> clunky.
>
> Is there a more elegant solution? Something along the lines of FILE_TEST that works
> for HDF5 groups (H5G_TEST, e.g.)?
>
> All the best,
>
> David


hi David,

The way to do it is to use H5_LIST with the FILTER keyword.

Also, I have a routine for this in my library: wmb_h5_group_exists()

which can be found at http://www.github.com/superchromix/wmb_lib

best,
Mark
Re: How to check for existence of an HDF5 group [message #90186 is a reply to message #90185] Sun, 08 February 2015 17:24 Go to previous messageGo to next message
dg86 is currently offline  dg86
Messages: 118
Registered: September 2012
Senior Member
On Sunday, February 8, 2015 at 4:39:51 AM UTC-5, superchromix wrote:
> On Saturday, February 7, 2015 at 7:24:50 PM UTC+1, David Grier wrote:
>> Dear Folks,
>>
>> I want to create new groups within an HDF5 file. Before creating a new group, however,
>> I'd like to check whether a group of the same name already exists. What's the right
>> way to do this?
>>
>> Calling H5G_OPEN or H5G_GET_OBJINFO with a new group name throws an error.
>> I could write a wrapper routine that catches the error and returns a "group not found"
>> value but that seems kludgy.
>>
>> H5_LIST returns a whole lot of information, which I suppose I could parse. That also seems
>> clunky.
>>
>> Is there a more elegant solution? Something along the lines of FILE_TEST that works
>> for HDF5 groups (H5G_TEST, e.g.)?
>>
>> All the best,
>>
>> David
>
>
> hi David,
>
> The way to do it is to use H5_LIST with the FILTER keyword.
>
> Also, I have a routine for this in my library: wmb_h5_group_exists()
>
> which can be found at http://www.github.com/superchromix/wmb_lib
>
> best,
> Mark

Thanks for the pointer to your repository, Mark. I'll have to look through
the HDF5 routines closely. In the meanwhile, the following kludge is working
for me. I try to open the group, and catch the error if the group
doesn't exist. This is part of an object definition for storing multi-volume
video data in an HDF5 archive:

;;;;
function h5video::H5G_OPEN, loc_id, group

COMPILE_OPT IDL2, HIDDEN

catch, error
if (error ne 0L) then begin
return, 0L
catch, /cancel
endif

gid = h5g_open(loc_id, group)
return, gid
end
Re: How to check for existence of an HDF5 group [message #94460 is a reply to message #90182] Tue, 30 May 2017 02:44 Go to previous message
ferdonbbp is currently offline  ferdonbbp
Messages: 1
Registered: May 2017
Junior Member
> Is there a more elegant solution?

Although this answer comes much later I didn't find the correct answer anywhere.
I believe H5Lexists is what you are looking for:
https://support.hdfgroup.org/HDF5/doc1.8/RM/RM_H5L.html#Link -Exists

Cheers,
Fernando
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: IDL to python bridge Library not loaded: libidl.8.5.dylib
Next Topic: =?UTF-8?B?UmU6INmF2LTYp9mH2K/YqSDYqNix2YbYp9mF2Kwg2LHYp9mF2LIg2KrYrdiqINin2YTYpw==?= رض حلقه 4 الشاب خالد

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 07:24:14 PDT 2025

Total time taken to generate the page: 0.00440 seconds