Introduction


Table of contents


What is HDF++ ?

Why HDF++ ?

HDF++ is a C++ API for HDF 5. The aim is to facilitate HDF integration in C++ programs.

Limitations

In this version (V 0.2), HDF++ only provides services on the following HDF objects : HDF++ is still under development.

HDF++ : classes architecture

Class Hierarchy

The following figure shows the hierarchical relationship between the classes which compose HDF++.
The classes which are directly manipulated by the user are : The remaining classes are base classes for commonalties of HDF objects :

HDFfile class

HDFfile class provides functions that access a HDF5 file. It inherits functions about attributes from its parents classes (HDFobject, HDFinternalObject and HDFcontainerObject).

The member functions of HDFfile class are the following :

HDFgroup class

HDFgroup class provides functions that access a HDF5 group. It inherits functions about attributes from its parents classes (HDFobject, HDFinternalObject and HDFcontainerObject).

The member functions of HDFgroup class are the following :

HDFdataset class

HDFdataset class provides functions that access a HDF5 dataset. It inherits functions about attributes from its parents classes (HDFobject and HDFinternalObject).

The member functions of HDFdataset class are the following :

HDFattribute class

HDFattribute class provides functions that access a HDF5 attribute. It inherits functions about attributes from it parent class (HDFobject).

The member functions of HDFattribute class are the following :

HDFexplorer class

HDFexplorer class provides the mecanism to explore following class intances :

The member functions of HDFexplorer class are the following :

HDFexception class

HDFexception class provides the mecanism for handling errors returned by other classes.

The member functions of HDFfile class are the following :

The HDF++ API

Include Files

The declarations and definitions which must be included with any code which uses HDF++, are gathered in the HDFOI.hxx include file.

Programming Models

In this section, we describe how to program some operations to :

How to create a HDFfile object and to use it to create or open an HDF5 file

This programming model shows how to
HDFfile *hdf_file;
...
hdf_file = new HDFfile("titi.hdf");
hdf_file->CreateOnDisk();
...
hdf_file->CloseOnDisk();
...
hdf_file->OpenOnDisk(HDF_RDONLY);
hdf_file->CloseOnDisk();
delete hdf_file

Getting some informations about an existing HDF file.

This programming model shows how to

n = hdf_file->nInternalObjects(); 
for (i=0;iInternalObjectIndentify(i,name);
  cout << " First Level Internal Object Name : " << name << endl;
}   

This programming model shows how to

if (hdf_file->ExistInternalObject("MESH"))
  cout << " The object 'MESH' is in the file " << endl;

This programming model shows how to

type = hdf_file->InternalObjectType("MESH");
switch (type)
  {
   case HDF_GROUP :
     cout << " Its type is HDF_GROUP" << endl;
     break;
	  
   case HDF_DATASET :
     cout << " Its type is HDF_DATASET" << endl;
     break;
  }

How to create a HDFgroup object and use it to create a new HDF5 group or open an existing one

This programming model shows how to

HDFgroup *hdf_group;
...
// A new HDF group object
hdf_group = new HDFgroup("MESH",hdf_file);
cout << " A HDFgroup object 'MESH' is created" << endl;

hdf_group->CreateOnDisk();
cout << " The HDF group is created " << endl;
...
hdf_group->CloseOnDisk();
cout << " The HDF group is closed " << endl;
...
hdf_group->OpenOnDisk();
cout << " The group is opened" << endl;
...
hdf_group->CloseOnDisk();
cout << " The HDF group is closed " << endl;
delete hdf_group;

Getting some informations about the HDF5 objects that contains an existing HDF5 group

This programming model shows how to

n = hdf_group->nInternalObjects();  
for (i=0;i < n; i++)     
{
  hdf_group->InternalObjectIndentify(i,name);
  type = hdf_group->InternalObjectType(name);
  cout << " First Level Internal Object Name : " << name << endl;
  switch (type)
    {
    case HDF_GROUP :
      cout << " Its type is HDF_GROUP" << endl;
      break;
	      
    case HDF_DATASET :
      cout << " Its type is HDF_DATASET" << endl;
      break;
    }
} 

Mounting and unmounting a HDF5 file at the HDFgroup object

This programming model shows how to

study = new HDFfile("study.hdf");
cout << " The HDFfile object for 'study.hdf' is created" << endl;

study->OpenOnDisk(HDF_RDONLY);
cout << " The file is opened" << endl;

geom = new HDFgroup("GEOM",study);
cout << " The HDFgroup object for 'GEOM' is created" << endl;

geom->FileMount("geom.hdf",HDF_RDONLY);
cout << " 'GEOM' becomes a mounted point for the file 'geom.hdf'" << endl;

geom->OpenOnDisk();
cout << " The group is opened" << endl;
geom1 = new HDFgroup("GEOM_1",geom);
cout << " The HDF group object is created for 'GEOM_1' with 'GEOM' as father" << endl;
cout << " This group is in fact in the file 'geom.hdf'"<OpenOnDisk();
cout << " The group 'GEOM_1' is opened" << endl;

...

geom1->CloseOnDisk();
cout  << " The group 'GEOM_1' is closed" << endl;

geom->FileUnMount();
cout << " The file 'geom.hdf' is unmounted from 'GEOM' " << endl; 

geom->CloseOnDisk();

study->CloseOnDisk();

delete geom1;
delete geom;
delete study;

How to create a HDFdataset object and use it to create a new HDF5 dataset or open an existing one

This programming model shows how to

HDFdataset *hdf_dataset;
hdf_size size[1] = 3;
...
hdf_dataset = new HDFdataset("COORDINATES",hdf_group,HDF_FLOAT64,size,1);
cout << " A HDFdataset object 'COORDINATES' is created" << endl;

hdf_dataset->CreateOnDisk();
cout << " The HDF dataset is created" << endl;
...
hdf_dataset->CloseOnDisk();
cout << " The HDF dataset is closed" << endl;
...
delete hdf_dataset;

This programming model shows how to

HDFdataset *hdf_dataset;
...
hdf_dataset = new HDFdataset("COORDINATES",hdf_group);
cout << " The dataset object 'COORDINATES' is created in memory " << endl;

hdf_dataset->OpenOnDisk();
cout << " The dataset 'COORDINATES' is opened " << endl;      c
...
hdf_dataset->CloseOnDisk();
cout << " The dataset 'COORDINATES' is closed " << endl;
...
delete hdf_dataset;

Getting some informations about an existing HDF5 dataset

This programming model shows how to

hdf_type data_type;
...
data_type = hdf_dataset->GetType();
switch(data_type)
{
 case HDF_INT32 :
   cout << " Type of data : HDF_INT32 " << endl;
   break; 

 case HDF_INT64 :
   cout << " Type of data : HDF_INT64 " << endl;
   break; 

 case HDF_FLOAT64 :
   cout << " Type of data : HDF_FLOAT64 " << endl;
   break;

 default :
   cout << " Type of data : HDF_STRING " << endl;
	}

This programming model shows how to

hdf_size *dim;
...
ndim = hdf_dataset->nDim();
cout << " Number of dimensions : " << ndim << endl;

dim = new hdf_size[ndim];
hdf_dataset->GetDim(dim);
for (i = 0;i < ndim;i++)
  cout << " Dimension " << i+1 << " of size : " << dim[i] << endl;
...
delete dim;

This programming model shows how to

int size;
...
size = hdf_dataset->GetSize();

Reading/writing the values of a HDFdataset

This programming model shows how to

hdf_dataset->WriteOnDisk(coordinates);
cout << " The HDF dataset is written in the file " << endl;

This programming model shows how to

hdf_float64 *val;
int size;
...
size = hdf_dataset->GetSize();
val = new hdf_float64[size];
hdf_dataset1->ReadFromDisk(val);
delete val;

How to create a HDFattribute object and use it to create a new HDF5 attribute or open an existing one

This programming model shows how to

HDFattribute *hdf_attribute;
...
hdf_attribute = new HDFattribute("ATTRIBUTE",hdf_dataset,HDF_INT32);
cout << " A HDF attribute  object is created for hdf_dataset " << endl;
...
hdf_attribute->CreateOnDisk();
cout << " The HDF attribute is created on Disk " << endl;
...
hdf_attribute->CloseOnDisk();
cout << " The HDF attribute closed on" << endl;  
...
hdf_attribute->OpenOnDisk();
cout << " The HDF attribute is created on Disk " << endl;
...
hdf_attribute->CloseOnDisk();
cout << " The HDF attribute closed on" << endl;  
...
delete hdf_attribute;

Reading/writing the value of a HDFattribute

This programming model shows how to

hdf_attribute->WriteOnDisk(&attribute); 
cout << " The HDF attribute is written on Disk " << endl;

hdf_attribute->ReadFromDisk(&attribute); 
cout << " The HDF attribute is written on Disk " << endl;

How to Create and use an HDFexplorer object

This programming model shows how to

HDFexplorer *explorer;
...
explorer = new HDFexplorer(hdf_file);
cout << " A HDF explorer object is created" << endl;

cout << " File Exploration " << endl;
for (explorer->Init();explorer->More();explorer->Next())
{
  object = explorer->Value();
  cout << " Name of the object : " << 
            object->GetName() << endl;
}
...      
cout << " Group exploration" << endl;
explorer->Reset(hdf_group); 
for (explorer->Init();explorer->More();explorer->Next())
{
  object = explorer->Value();
  cout << " Name of the object : " << object->GetName() << endl;
}
...
delete explorer;