我在我的HDF5档案中存储了一个字符串(和一个矢量),例如使用Python界面:
function formToJson(element){
let finalObject = [];
$(element).find('div').each(function(){
let innerDivId = $(this).attr('id');
let formData = {};
$(this).children().each(function(){
formData[$(this).attr('name')] = $(this).val()
});
finalObject.push({ "id":innerDivId, "formData":formData});
});
return finalObject;
}
现在我希望将字符串读取为import h5py
file = h5py.File("example.h5","w")
file['/path/to/vector'] = [0., 1., 2.]
file['/path/to/string'] = 'test'
。我知道如何读取矢量(见下文),但我完全不知道如何读取字符串。 特别不明白的是如何分配结果,如:
std::string
,类型为“String,length = variable”。以下是我阅读矢量的方法:
1
(使用#include "H5Cpp.h"
#include <vector>
#include <iostream>
int main()
{
// open file
H5::H5File fid = H5::H5File("example.h5",H5F_ACC_RDONLY);
// open dataset
H5::DataSet dataset = fid.openDataSet("/path/to/vector");
H5::DataSpace dataspace = dataset.getSpace();
H5T_class_t type_class = dataset.getTypeClass();
// check data type
if ( type_class != H5T_FLOAT )
throw std::runtime_error("Unable to read, incorrect data-type");
// check precision
// - get storage type
H5::FloatType datatype = dataset.getFloatType();
// - get number of bytes
size_t precision = datatype.getSize();
// - check precision
if ( precision != sizeof(double) )
throw std::runtime_error("Unable to read, incorrect precision");
// get the size
// - read rank (a.k.a number of dimensions)
int rank = dataspace.getSimpleExtentNdims();
// - allocate
hsize_t hshape[rank];
// - read
dataspace.getSimpleExtentDims(hshape, NULL);
// - total size
size_t size = 0;
for ( int i = 0 ; i < rank ; ++i ) size += static_cast<size_t>(hshape[i]);
// allocate output
std::vector<double> data(size);
// read data
dataset.read(const_cast<double*>(data.data()), H5::PredType::NATIVE_DOUBLE);
// print data
for ( auto &i : data )
std::cout << i << std::endl;
}
编译)
答案 0 :(得分:0)
我找到了一个解决方案:
RewriteRule ^list/([0-9a-zA-Z]+)/([0-9a-zA-Z]+) list.php?id=$1&p=$2 [NC,L]