1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
/*
* Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
* Copyright (C) 2012 - Scilab Enterprises - Calixte DENIZET
*
* This file must be used under the terms of the CeCILL.
* This source file is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at
* http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
*
*/
#include "H5ArrayData.hxx"
#include "H5DataFactory.hxx"
namespace org_modules_hdf5
{
H5ArrayData::H5ArrayData(H5Object & _parent, const hsize_t _totalSize, const hsize_t _dataSize, const hsize_t _ndims, const hsize_t * _dims, char * _data, hid_t arrayType, const hsize_t _stride, const size_t _offset, const bool _dataOwner) : H5BasicData<char>(_parent, _totalSize, _dataSize, _ndims, _dims, _data, _stride, _offset, _dataOwner), cumprod(H5Object::getCumProd(_ndims, dims))
{
type = H5Tget_super(arrayType);
baseSize = H5Tget_size(type);
andims = H5Tget_array_ndims(arrayType);
adims = new hsize_t[andims];
H5Tget_array_dims(arrayType, adims);
atotalSize = 1;
if (H5Tget_class(type) == H5T_STRING && !H5Tis_variable_str(type))
{
// We have a C-string so it is null terminated
baseSize++;
}
for (unsigned int i = 0; i < andims; i++)
{
atotalSize *= adims[i];
}
}
H5ArrayData::~H5ArrayData()
{
delete[] cumprod;
delete[] adims;
H5Tclose(type);
}
bool H5ArrayData::isArray() const
{
return true;
}
H5Object & H5ArrayData::getData(const unsigned int size, const unsigned int * index) const
{
unsigned int pos = 0;
hsize_t * _dims = 0;
for (unsigned int i = 0; i < size; i++)
{
pos += (int)cumprod[i] * index[i];
}
if (pos >= totalSize)
{
throw H5Exception(__LINE__, __FILE__, _("Invalid index."));
}
return H5DataFactory::getObjectData(*const_cast<H5ArrayData *>(this), atotalSize, baseSize, type, andims, adims, static_cast<char *>(data) + offset + pos * (stride ? stride : dataSize), 0, 0, false);
}
std::string H5ArrayData::toString(const unsigned int indentLevel) const
{
std::ostringstream os;
std::string indentString = H5Object::getIndentString(indentLevel + 1);
os << H5Object::getIndentString(indentLevel) << "HDF5 Array data" << std::endl
<< indentString << _("Dimensions") << ": [";
if (ndims == 0)
{
os << "1 x 1]";
}
else if (ndims == 1)
{
os << "1 x " << dims[0] << "]";
}
else
{
for (unsigned int i = 0; i < ndims - 1; i++)
{
os << dims[i] << " x ";
}
os << dims[ndims - 1] << "]" << std::endl;
}
return os.str();
}
std::string H5ArrayData::dump(std::map<haddr_t, std::string> & alreadyVisited, const unsigned int indentLevel) const
{
return H5DataConverter::dump(alreadyVisited, indentLevel, (int)ndims, dims, *this, false);
}
void H5ArrayData::printData(std::ostream & os, const unsigned int pos, const unsigned int indentLevel) const
{
os << "[ ";
H5Data & hdata = H5DataFactory::getObjectData(*const_cast<H5ArrayData *>(this), atotalSize, baseSize, type, andims, adims, static_cast<char *>(data) + offset + pos * (stride ? stride : dataSize), 0, 0, false);
for (unsigned int i = 0; i < atotalSize - 1; i++)
{
hdata.printData(os, i, indentLevel + 1);
os << ", ";
}
hdata.printData(os, (int)atotalSize - 1, (int)indentLevel + 1);
os << " ]";
delete &hdata;
}
void H5ArrayData::toScilab(void * pvApiCtx, const int lhsPosition, int * parentList, const int listPosition, const bool flip) const
{
H5Object::toScilab(pvApiCtx, lhsPosition, parentList, listPosition, flip);
}
}
|