#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( "SDSextendible.h5" );
const H5std_string DATASET_NAME( "ExtendibleArray" );
const int NX = 10;
const int NY = 5;
const int RANK = 2;
int main (void)
{
try
{
Exception::dontPrint();
hsize_t dims[2] = { 3, 3};
hsize_t maxdims[2] = {H5S_UNLIMITED, H5S_UNLIMITED};
DataSpace mspace1( RANK, dims, maxdims);
H5File file( FILE_NAME, H5F_ACC_TRUNC );
DSetCreatPropList cparms;
hsize_t chunk_dims[2] ={2, 5};
cparms.setChunk( RANK, chunk_dims );
int fill_val = 0;
cparms.setFillValue( PredType::NATIVE_INT, &fill_val);
DataSet dataset = file.createDataSet( DATASET_NAME, PredType::NATIVE_INT, mspace1, cparms);
hsize_t size[2];
size[0] = 3;
size[1] = 3;
dataset.extend( size );
DataSpace fspace1 = dataset.getSpace ();
hsize_t offset[2];
offset[0] = 0;
offset[1] = 0;
hsize_t dims1[2] = { 3, 3};
fspace1.selectHyperslab( H5S_SELECT_SET, dims1, offset );
int data1[3][3] = { {1, 1, 1},
{1, 1, 1},
{1, 1, 1} };
dataset.write( data1, PredType::NATIVE_INT, mspace1, fspace1 );
hsize_t dims2[2] = { 7, 1};
dims[0] = dims1[0] + dims2[0];
size[0] = dims[0];
size[1] = dims[1];
dataset.extend( size );
DataSpace fspace2 = dataset.getSpace ();
offset[0] = 3;
offset[1] = 0;
fspace2.selectHyperslab( H5S_SELECT_SET, dims2, offset );
DataSpace mspace2( RANK, dims2 );
int data2[7] = { 2, 2, 2, 2, 2, 2, 2};
dataset.write( data2, PredType::NATIVE_INT, mspace2, fspace2 );
hsize_t dims3[2] = { 2, 2};
dims[1] = dims1[1] + dims3[1];
size[0] = dims[0];
size[1] = dims[1];
dataset.extend( size );
DataSpace fspace3 = dataset.getSpace ();
offset[0] = 0;
offset[1] = 3;
fspace3.selectHyperslab( H5S_SELECT_SET, dims3, offset );
DataSpace mspace3( RANK, dims3 );
int data3[2][2] = { {3, 3}, {3, 3} };
dataset.write( data3, PredType::NATIVE_INT, mspace3, fspace3 );
int i, j;
int data_out[NX][NY];
for (i = 0; i < NX; i++)
{
for (j = 0; j < NY; j++)
data_out[i][j] = 0;
}
dataset.read( data_out, PredType::NATIVE_INT );
for (i=0; i < NX; i++)
{
for(j=0; j < NY; j++)
cout << data_out[i][j] << " ";
cout << endl;
}
}
catch( FileIException error )
{
error.printError();
return -1;
}
catch( DataSetIException error )
{
error.printError();
return -1;
}
catch( DataSpaceIException error )
{
error.printError();
return -1;
}
catch( DataTypeIException error )
{
error.printError();
return -1;
}
return 0;
}