This is what I use:

// -----------------------------------------------------------------------------
//  Reads a String dataset
// ----------------------------------------------------------------------------- herr_t H5Lite::readStringDataset(hid_t loc_id, const std::string& dsetName, std::string &data) {
  hid_t did; // dataset id
  hid_t tid; //type id
  herr_t err = 0;
  herr_t retErr = 0;
  hsize_t size;

  did = H5Dopen(loc_id, dsetName.c_str() );
  if (did < 0) {
    std::cout << "Error Opening Dataset" << std::endl;
    return -1;
  }
  tid = H5Dget_type(did);
  if ( tid >= 0 ) {

    size = H5Dget_storage_size(did);
std::vector<char> buf(static_cast<int>(size+1), 0x00); //Allocate and Zero the array err = H5Dread(did, tid, H5S_ALL, H5S_ALL, H5P_DEFAULT, &(buf.front()) );
    if (err<0) {
      std::cout << "Error Reading string dataset." << std::endl;
      retErr = err;
    } else {
data.append( &(buf.front()) ); //Append the string to the given string
    }
  }
  CloseH5D(did, err, retErr);
  CloseH5T(tid, err, retErr);
  return retErr;
}

___________________________________________________________
Mike Jackson                      www.bluequartz.net
Principal Software Engineer       [email protected]
BlueQuartz Software               Dayton, Ohio


On Jun 7, 2010, at 11:55 AM, Philipp Kraus wrote:


I know these examples and they help me to understand the structures, but I don't find string examples and (string) array examples. I have a hdf5 file (created with Matlab) and I would like to read in my C++ program. My code:

std::vector<std::string> hdf::readStringVector( const std::string& p_path )
const
   {
        H5::DataSet   l_dataset   = m_file.openDataSet( p_path.c_str() );
       H5::DataSpace l_dataspace = l_dataset.getSpace();

        hsize_t l_size[1];
       l_dataspace.getSimpleExtentDims( l_size );               
       l_dataspace.close();

        std::vector<std::string> l_vec( l_size[0] );

 *** How can I read the array data              

       return l_vec;
   }



--
View this message in context: 
http://hdf-forum.184993.n3.nabble.com/HDF5-with-C-tp874249p876706.html
Sent from the hdf-forum mailing list archive at Nabble.com.

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


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

Reply via email to