Вопрос

I'm trying to work with HDF5-Files (in C++). Therefor I work with the Examples from the HDF5-API: http://www.hdfgroup.org/HDF5/doc/cpplus_RM/namespaceH5.html

There are a lot of useful examples but I have trouble when I try to "mix" it with other examples from the Tutorial: http://www.hdfgroup.org/HDF5/Tutor/

For example I try to find out if an attribute exists in an HDF5-File. Therefor I open an existing file and then I get problems with the function: H5Aexists

#ifdef OLD_HEADER_FILENAME
#include <iostream.h>
#else
#include <iostream>
#endif
#include <string>
#ifndef H5_NO_NAMESPACE
#ifndef H5_NO_STD
using std::cout;
using std::endl;
#endif // H5_NO_STD
#endif
#include "H5Cpp.h"
#ifndef H5_NO_NAMESPACE
using namespace H5;
#endif

const H5std_string FILE_NAME ("file.h5");
const H5std_string DATASET_NAME ("/dataset1/data1/data");


int main (void)
{

     Exception::dontPrint();

     /*
    * Open the specified file and the specified dataset in the file.
    */
    H5File file( FILE_NAME, H5F_ACC_RDONLY );
    DataSet dataset = file.openDataSet( DATASET_NAME );


    const char* where;

    //H5Aexists(file,where);

    return 0;

}

H5exists expects an integer hid_t with the object id. When I use examples from the Tutorial, then I get an object id by using:

hid_t file_id;

file_id = H5File( FILE_NAME_dBBSC, H5F_ACC_RDONLY );

therefore they always include hdf5.h not H5Cpp.h.

But where here do I get my "obj_id" from my code?

In general, I don't get the difference between H5Cpp.h and hdf5.h. Or between the HDF5-API and the other functions?!

Thanks for your help!

edit:

I guess this is how I get an file id?!

hid_t file_id = file.getId();

but how can I get the Id of an attribute? I can't find how to open an Attribute (not a DataSet) so that I can read the contents?!

Это было полезно?

Решение 2

hid_t H5Aopen( hid_t obj_id, const char *attr_name, hid_t aapl_id )

will open your attribute. If you do something like

hid_t pizza = H5Aopen(file_id, "Attribute_name", H5P_DEFAULT)

pizza will be your attribute_id.

Im not sure either what the difference is between hdf5.h and H5Cpp.h. I think I have them both included, and it does not give an error. Maybe that helps too?

Другие советы

As you said, you are mixing different examples: C code and C++ code.

That works, thank you! But nevertheless I don't get the Difference between e.g.: DataSet dataset = file.openDataSet( DATASET_NAME ); and hid_t dataset = H5Dopen(file, DATASET_NAME); ?!

DataSet dataset = file.openDataSet( DATASET_NAME );

This is C++ style. file is an object and you use the methode openDataSet(..).

hid_t dataset = H5Dopen(file, DATASET_NAME); ?!

This is the C version of the same library call.

they always include hdf5.h not H5Cpp.h.

You have to decide if you want to do C or C++ and choose the corresponding header.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top