void HDFAtom<std::vector<std::string> >::Read(std::vector<std::string> &values) { std::string value; /* * This attribute is an array of std::strings. They are read in by * storing pointers to std::strings in memory controlled by HDF. To read * the std::strings, read the pointers into a temporary array, then copy * those std::strings to the values array. This way when the values array * is destroyed, it will not try and get rid of space that is under * HDF control. */ H5::DataSpace attributeSpace = attribute.getSpace(); hsize_t nPoints; nPoints = attributeSpace.getSelectNpoints(); H5::DataType attrType = attribute.getDataType(); // necessary for attr.read() // Declare and initialize std::vector of pointers to std::string attribute list. std::vector<char*> ptrsToHDFControlledMemory; ptrsToHDFControlledMemory.resize(nPoints); // Copy the pointers. attribute.read(attrType, &ptrsToHDFControlledMemory[0]); // Copy the std::strings into memory the main program has control over. unsigned int i; for (i = 0; i < ptrsToHDFControlledMemory.size(); i++ ){ values.push_back(ptrsToHDFControlledMemory[i]); free(ptrsToHDFControlledMemory[i]); } }
void Datafile::write_time_step_history(size_t index, double eps) { // pack values of index and eps into a struct in memory time_step_history_pair pair; pair.step = static_cast<int>(index); pair.time_step = eps; try { ensure_time_step_history_data(); // calculate current size, extend if needed, and write data. You know the drill. H5::DataSpace tempspace = time_step_history_data.getSpace(); tempspace.selectAll(); hsize_t cur_size = tempspace.getSelectNpoints(); hsize_t new_size = cur_size + 1; space_1d.setExtentSimple(1, &new_size); time_step_history_data.extend(&new_size); space_1d.selectElements(H5S_SELECT_SET, 1, &cur_size); validate_selection(space_1d); time_step_history_data.write(&pair, time_step_history_type, scalar_space, space_1d); } catch(H5::Exception& e) { e.printError(); throw; } }