How to quietly check the existence of an H5File

I have code which opens an hdf file, and if the file does not exist it does
create an hdf file.

std::string filename_;
hid_t file_;
hid_t filename_;
void open()
{
        file_ = H5Fopen(filename_.c_str(), H5F_ACC_RDWR, fileaccessProp_);
if(file_ < 0 ) //if file does not exist creat one
{
file_ = H5Fcreate(filename_.c_str(), H5F_ACC_TRUNC, H5P_DEFAULT,
fileaccessProp_ );
}
}

The problem with that code is that if the file does not exist already than
H5open not just returns -1 but also prints multiple lines of error messages
on the command prompt
Is there a 'quiet' way to check for the existence of an hdf file?

I do have a very similar problem when trying to open a dataset which does
not exist yet in an open hdf file.

if(file_ > 0)
{
         dataset_ = H5Dopen2(file_,dsname.c_str(),H5P_DEFAULT );
         if(dataset_ < 0)//open failed
         {

Again H5Dopen2 will print many lines of error messages. I am again looking
for a quiet way to check for the existence of an dataset.

Advice are appreciated.

Eryk

···

--
Witold Eryk Wolski

Heidmark str 5
D-28329 Bremen
tel.: 04215261837

Hi Eryk,

I have code which opens an hdf file, and if the file does not exist it does create an hdf file.

std::string filename_;
hid_t file_;
hid_t filename_;
void open()
{
        file_ = H5Fopen(filename_.c_str(), H5F_ACC_RDWR, fileaccessProp_);
if(file_ < 0 ) //if file does not exist creat one
{
file_ = H5Fcreate(filename_.c_str(), H5F_ACC_TRUNC, H5P_DEFAULT, fileaccessProp_ );
}

The problem with that code is that if the file does not exist already than H5open not just returns -1 but also prints multiple lines of error messages on the command prompt
Is there a 'quiet' way to check for the existence of an hdf file?

  You could wrap the call to H5Fopen() in the H5E_BEGIN_TRY/H5E_END_TRY macros.

I do have a very similar problem when trying to open a dataset which does not exist yet in an open hdf file.

if(file_ > 0)
{
         dataset_ = H5Dopen2(file_,dsname.c_str(),H5P_DEFAULT );
         if(dataset_ < 0)//open failed
         {

Again H5Dopen2 will print many lines of error messages. I am again looking for a quiet way to check for the existence of an dataset.

  You want to use H5Lexists() here.

    Quincey

···

On Jul 9, 2009, at 4:10 AM, W Eryk Wolski wrote:

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

Add this call to silence error messages...

H5Eset_auto(NULL, NULL);

Mark

···

On Thu, 2009-07-09 at 02:10, W Eryk Wolski wrote:

I have code which opens an hdf file, and if the file does not exist it
does create an hdf file.

std::string filename_;
hid_t file_;
hid_t filename_;
void open()
{
        file_ = H5Fopen(filename_.c_str(), H5F_ACC_RDWR,
fileaccessProp_);
if(file_ < 0 ) //if file does not exist creat one
{
file_ = H5Fcreate(filename_.c_str(), H5F_ACC_TRUNC, H5P_DEFAULT,
fileaccessProp_ );

}

}

The problem with that code is that if the file does not exist already
than H5open not just returns -1 but also prints multiple lines of
error messages on the command prompt
Is there a 'quiet' way to check for the existence of an hdf file?

I do have a very similar problem when trying to open a dataset which
does not exist yet in an open hdf file.

if(file_ > 0)
{
         dataset_ = H5Dopen2(file_,dsname.c_str(),H5P_DEFAULT );
         if(dataset_ < 0)//open failed
         {

Again H5Dopen2 will print many lines of error messages. I am again
looking for a quiet way to check for the existence of an dataset.

Advice are appreciated.

Eryk

--
Witold Eryk Wolski

Heidmark str 5
D-28329 Bremen
tel.: 04215261837

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

--
Mark C. Miller, Lawrence Livermore National Laboratory
email: mailto:miller86@llnl.gov
(M/T/W) (925)-423-5901 (!!LLNL BUSINESS ONLY!!)
(Th/F) (530)-753-8511 (!!LLNL BUSINESS ONLY!!)

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

Dear Eryk,

You can avoid the printing of error messages by using

H5Eset_auto(NULL,NULL); - H5Eset_auto turns on or off automatic
printing of errors.

Call this before and after the call to H5Fopen .

Regards

Ramakrishnan

···

-----Original Message-----
From: hdf-forum-bounces@hdfgroup.org
[mailto:hdf-forum-bounces@hdfgroup.org] On Behalf Of W Eryk Wolski
Sent: Thursday, July 09, 2009 2:40 PM
To: hdf-forum@hdfgroup.org
Subject: [Hdf-forum] How to quietly check the existence of an H5File

I have code which opens an hdf file, and if the file does not exist it
does create an hdf file.

std::string filename_;
hid_t file_;
hid_t filename_;
void open()
{
        file_ = H5Fopen(filename_.c_str(), H5F_ACC_RDWR,
fileaccessProp_);

if(file_ < 0 ) //if file does not exist creat one
{

file_ = H5Fcreate(filename_.c_str(), H5F_ACC_TRUNC, H5P_DEFAULT,
fileaccessProp_ );

}

}

The problem with that code is that if the file does not exist already
than H5open not just returns -1 but also prints multiple lines of error
messages on the command prompt
Is there a 'quiet' way to check for the existence of an hdf file?

I do have a very similar problem when trying to open a dataset which
does not exist yet in an open hdf file.

if(file_ > 0)
{
         dataset_ = H5Dopen2(file_,dsname.c_str(),H5P_DEFAULT );
         if(dataset_ < 0)//open failed
         {

Again H5Dopen2 will print many lines of error messages. I am again
looking for a quiet way to check for the existence of an dataset.

Advice are appreciated.

Eryk

--
Witold Eryk Wolski

Heidmark str 5
D-28329 Bremen
tel.: 04215261837

Hi Eryk,

a simple way to stop the error messages appearing is the following

H5E_BEGIN_TRY{
    file_ = H5Fopen(filename_.c_str(), H5F_ACC_RDWR, fileaccessProp_);
}H5E_END_TRY

Regards,

Patrick

W Eryk Wolski wrote:

···

I have code which opens an hdf file, and if the file does not exist it does create an hdf file.

std::string filename_;
hid_t file_;
hid_t filename_;
void open()
{
        file_ = H5Fopen(filename_.c_str(), H5F_ACC_RDWR, fileaccessProp_);
if(file_ < 0 ) //if file does not exist creat one
{
file_ = H5Fcreate(filename_.c_str(), H5F_ACC_TRUNC, H5P_DEFAULT, fileaccessProp_ );
}

The problem with that code is that if the file does not exist already than H5open not just returns -1 but also prints multiple lines of error messages on the command prompt
Is there a 'quiet' way to check for the existence of an hdf file?

I do have a very similar problem when trying to open a dataset which does not exist yet in an open hdf file.

if(file_ > 0)
{
         dataset_ = H5Dopen2(file_,dsname.c_str(),H5P_DEFAULT );
         if(dataset_ < 0)//open failed
         {

Again H5Dopen2 will print many lines of error messages. I am again looking for a quiet way to check for the existence of an dataset.

Advice are appreciated.

Eryk

--
Witold Eryk Wolski

Heidmark str 5
D-28329 Bremen
tel.: 04215261837

------------------------------------------------------------------------

_______________________________________________
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

late to the game but ...

The easiest way to check for the existence of any file is to use stat()

Cheers,

Allen

···

On Jul 9, 2009, at 3:10 AM, W Eryk Wolski wrote:

I have code which opens an hdf file, and if the file does not exist it does create an hdf file.

std::string filename_;
hid_t file_;
hid_t filename_;
void open()
{
        file_ = H5Fopen(filename_.c_str(), H5F_ACC_RDWR, fileaccessProp_);
if(file_ < 0 ) //if file does not exist creat one
{
file_ = H5Fcreate(filename_.c_str(), H5F_ACC_TRUNC, H5P_DEFAULT, fileaccessProp_ );
}

The problem with that code is that if the file does not exist already than H5open not just returns -1 but also prints multiple lines of error messages on the command prompt
Is there a 'quiet' way to check for the existence of an hdf file?

I do have a very similar problem when trying to open a dataset which does not exist yet in an open hdf file.

if(file_ > 0)
{
         dataset_ = H5Dopen2(file_,dsname.c_str(),H5P_DEFAULT );
         if(dataset_ < 0)//open failed
         {

Again H5Dopen2 will print many lines of error messages. I am again looking for a quiet way to check for the existence of an dataset.

Advice are appreciated.

Eryk

--
Witold Eryk Wolski

Heidmark str 5
D-28329 Bremen
tel.: 04215261837

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