creating files, groups, datasets if non existant

Hello all,

The hdf5 documentation specifies that the H5Xopen (where X is F, G or D) functions return a negative value if the operation fails. I am trying to exploit this in order to create files, groups and datasets
in the case that they do not already exist, i.e.:

file = H5Fopen("E:/tmp/filename.h5", H5F_ACC_RDWR, H5P_DEFAULT);
if( file < 0 )
        file = H5Fcreate("E:/tmp/filename.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);

However, in the case that the object doesn't exist, this leads to my program crashing with multiple hdf5 error messages. Where am I going wrong? I've also tried using c++ try{} ... catch(...){} constructions, but to no avail... Is there a more elegant way of doing this I am unaware of?

Thanks a lot!

Regards,

Patrick

···

----------------------------------------------------------------------
This mailing list is for HDF software users discussion.
To subscribe to this list, send a message to hdf-forum-subscribe@hdfgroup.org.
To unsubscribe, send a message to hdf-forum-unsubscribe@hdfgroup.org.

Hmm, checking for the existence of a file is more at the level of the OS really. Are there OS routines that you can use instead? It's possible that H5is_hdf5() might work instead, but I haven't tried it...

  Quincey

···

On May 16, 2009, at 9:31 AM, Patrick wrote:

Hello all,

The hdf5 documentation specifies that the H5Xopen (where X is F, G or D) functions return a negative value if the operation fails. I am trying to exploit this in order to create files, groups and datasets
in the case that they do not already exist, i.e.:

file = H5Fopen("E:/tmp/filename.h5", H5F_ACC_RDWR, H5P_DEFAULT);
if( file < 0 )
      file = H5Fcreate("E:/tmp/filename.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);

However, in the case that the object doesn't exist, this leads to my program crashing with multiple hdf5 error messages. Where am I going wrong? I've also tried using c++ try{} ... catch(...){} constructions, but to no avail... Is there a more elegant way of doing this I am unaware of?

----------------------------------------------------------------------
This mailing list is for HDF software users discussion.
To subscribe to this list, send a message to hdf-forum-subscribe@hdfgroup.org.
To unsubscribe, send a message to hdf-forum-unsubscribe@hdfgroup.org.

Yes, you can always use forward slashes under windows. All OS calls
support that and nearly any application, except the command prompt :wink:

With respect to the former question - what does "crashing" mean?
Is that just printing error messages? If so, printing such can be
disabled via HDF5 calls.

Or does it crash physically with a segmentation fault and access
violation when trying to open that file? If so, what happens if the
file is opened using fopen()? Does it crash then as well?

  Werner

···

On Sat, 16 May 2009 10:42:01 -0500, Ray Burkholder <ray@oneunified.net> wrote:

>
> file = H5Fopen("E:/tmp/filename.h5", H5F_ACC_RDWR,
H5P_DEFAULT); if(
> file < 0 )
> file = H5Fcreate("E:/tmp/filename.h5", H5F_ACC_TRUNC,
> H5P_DEFAULT, H5P_DEFAULT);
>

If that is windows, are forward slashes allowed in the directory?

--
___________________________________________________________________________
Dr. Werner Benger <werner@cct.lsu.edu> Visualization Research
Laboratory for Creative Arts and Technology (LCAT)
Center for Computation & Technology at Louisiana State University (CCT/LSU)
239 Johnston Hall, Baton Rouge, Louisiana 70803
Tel.: +1 225 578 4809 Fax.: +1 225 578-5362

----------------------------------------------------------------------
This mailing list is for HDF software users discussion.
To subscribe to this list, send a message to hdf-forum-subscribe@hdfgroup.org.
To unsubscribe, send a message to hdf-forum-unsubscribe@hdfgroup.org.

>
> file = H5Fopen("E:/tmp/filename.h5", H5F_ACC_RDWR,
H5P_DEFAULT); if(
> file < 0 )
> file = H5Fcreate("E:/tmp/filename.h5", H5F_ACC_TRUNC,
> H5P_DEFAULT, H5P_DEFAULT);
>

If that is windows, are forward slashes allowed in the directory?

···

--
Scanned for viruses and dangerous content at
http://www.oneunified.net and is believed to be clean.

----------------------------------------------------------------------
This mailing list is for HDF software users discussion.
To subscribe to this list, send a message to hdf-forum-subscribe@hdfgroup.org.
To unsubscribe, send a message to hdf-forum-unsubscribe@hdfgroup.org.

With respect to the former question - what does "crashing" mean?

Is that just printing error messages? If so, printing such can be
disabled via HDF5 calls.

    Thanks a lot for pointing this out! In fact they are simply error messages...
     After trawling the internet for a while (this was astonishingly hard to find...), I found a convenient way to probe
    File/Group/Dataset existance:

    H5E_BEGIN_TRY{
       file = H5Fopen(...)
    }H5E_END_TRY
    if(file < 0)
       file = H5Fcreate(...)

    This gets rid of the error messages originating from functions within the block...

    Thanks again!

    Patrick

···

----------------------------------------------------------------------
This mailing list is for HDF software users discussion.
To subscribe to this list, send a message to hdf-forum-subscribe@hdfgroup.org.
To unsubscribe, send a message to hdf-forum-unsubscribe@hdfgroup.org.