Help! I've been beating my head on this for a while now and I can't figure
out what's wrong!

I'm trying to read from an HDF5 file using the C++ API with the code below,
but I keep getting an Access Violation error in the read command, within
H5D_scatter_mem's while loop. I've tried reading the entire data set and
hyperslabs, but the only successful read I've done is if I read one element
from the set. The HDF5 file and the library I built seems fine as I can use
the h5dump tool to read the dataset in question

I'd appreciate any help anyone can give me. Thanks!

-John

--------------
John Kua
Research Scientist
Electrical Engineering and Computer Science Department
University of California, Berkeley
email: [email protected]



int fileReader::readHdf5File(string fileName){

/*
    * Try block to detect exceptions raised by any of the calls inside it
    */
 try
{
/*
 * Turn off the auto-printing when failure occurs so that we can
* handle the errors appropriately
 */
Exception::dontPrint();

/*
 * Open the specified file and the specified dataset in the file.
*/
H5File file( fileName.c_str(), H5F_ACC_RDONLY );
 Group group = file.openGroup("/Lidar");
DataSet dataset = group.openDataSet("range1");

/*
* Get the class of the datatype that is used by the dataset.
 */
H5T_class_t type_class = dataset.getTypeClass();

/*
 * Get class of datatype and print message if it's an integer.
*/
if( type_class == H5T_INTEGER )
 {
cout << "Data set has INTEGER type" << endl;

 /*
* Get the integer datatype
        */
 IntType intype = dataset.getIntType();

/*
* Get order of datatype and print message if it's a little endian.
 */
H5std_string order_string;
H5T_order_t order = intype.getOrder( order_string );
 cout << order_string << endl;

/*
* Get size of the data element stored in file and print it.
 */
size_t size = intype.getSize();
cout << "Data size is " << size << endl;
 }

/*
* Get dataspace of the dataset.
 */
DataSpace dataspace = dataset.getSpace();

/*
 * Get the number of dimensions in the dataspace.
*/
int rank = dataspace.getSimpleExtentNdims();

/*
* Get the dimension size of each dimension in the dataspace and
 * display them.
*/
hsize_t dims_out[2];
 int ndims = dataspace.getSimpleExtentDims( dims_out, NULL);
cout << "rank " << rank << ", dimensions " <<
 (unsigned long)(dims_out[0]) << " x " <<
 (unsigned long)(dims_out[1]) << endl;

//dataspace.selectAll();
hsize_t      offset[2];   // hyperslab offset in the file
 hsize_t      count[2];    // size of the hyperslab in the file
offset[0] = 0;
 offset[1] = 0;
count[0]  = 5;
count[1]  = 5;
 dataspace.selectHyperslab( H5S_SELECT_SET, count, offset );

/*
 * Define the memory dataspace.
*/
hsize_t     dimsm[2];              /* memory space dimensions */
 dimsm[0] = dims_out[0];
dimsm[1] = dims_out[1];
DataSpace memspace( rank, dimsm );
 //memspace.selectAll();
memspace.selectHyperslab( H5S_SELECT_SET, count, offset );

int ** data_out = new int*[dims_out[0]];
for ( int i = 0; i < dims_out[0]; i++ ){
 data_out[i] = new int[dims_out[1]];
for ( int j = 0; j < dims_out[1]; j++ ){
 data_out[i][j] = 0;
}
}
 cout << "Finished init" << endl;

for (int j = 0; j < dims_out[0]; j++)
 {
cout << j << ": ";
for (int i = 0; i < 10; i++)
 cout << data_out[j][i] << " ";
cout << endl;
 }

dataset.read( data_out, PredType::NATIVE_INT, memspace, dataspace );
 //dataset.read( data_out, PredType::NATIVE_INT);

for (int j = 0; j < dims_out[0]; j++)
 {
for (int i = 0; i < 10; i++)
cout << data_out[j][i] << " ";
 cout << endl;
}

}  // end of try block

// catch failure caused by the H5File operations
catch( FileIException error )
 {
error.printError();
return -1;
 }
// catch failure caused by the DataSet operations
catch( DataSetIException error )
 {
error.printError();
return -1;
 }
// catch failure caused by the DataSpace operations
catch( DataSpaceIException error )
 {
error.printError();
return -1;
 }
// catch failure caused by the DataSpace operations
catch( DataTypeIException error )
 {
error.printError();
return -1;
 }

   return 0;  // successfully terminated
}
_______________________________________________
Hdf-forum is for HDF software users discussion.
[email protected]
http://mail.hdfgroup.org/mailman/listinfo/hdf-forum_hdfgroup.org

Reply via email to