21 #ifndef SELDON_FILE_VECTOR_CXX
33 template <
class T,
class Allocator>
45 template <
class T,
class Allocator>
54 for (
size_t i = 0; i < min(this->m_, n); i++)
55 X_new(i) = this->data_[i];
71 template <
class T,
class Allocator>
72 typename ClassComplexType<T>::Treal
75 typename ClassComplexType<T>::Treal res(0);
76 for (
size_t i = 0; i < this->GetLength(); i++)
87 template <
class T,
class Allocator>
91 #ifdef SELDON_CHECK_DIMENSIONS
92 if (this->GetLength() == 0)
93 throw WrongDim(
"Vector<VectFull>::GetNormInfIndex()",
97 typename ClassComplexType<T>::Treal res(0), temp;
99 for (
size_t i = 0; i < this->GetLength(); i++)
103 if (temp != res) j = i;
122 template <
class T,
class Allocator>
124 ::Write(
string FileName,
bool with_size)
const
127 FileStream.open(FileName.c_str(), ofstream::binary);
129 #ifdef SELDON_CHECK_IO
131 if (!FileStream.is_open())
132 throw IOError(
"Vector<VectFull>::Write(string FileName, "
134 string(
"Unable to open file \"") + FileName +
"\".");
137 this->Write(FileStream, with_size);
150 template <
class T,
class Allocator>
152 ::Write(ostream& FileStream,
bool with_size)
const
155 #ifdef SELDON_CHECK_IO
157 if (!FileStream.good())
158 throw IOError(
"Vector<VectFull>::Write(ostream& FileStream, "
160 "The stream is not ready.");
164 FileStream.write(
reinterpret_cast<char*
>(&n),
167 FileStream.write(
reinterpret_cast<char*
>(this->data_),
168 this->m_ *
sizeof(value_type));
170 #ifdef SELDON_CHECK_IO
172 if (!FileStream.good())
173 throw IOError(
"Vector<VectFull>::Write(ostream& FileStream, "
175 "Output operation failed.");
187 template <
class T,
class Allocator>
191 FileStream.precision(cout.precision());
192 FileStream.flags(cout.flags());
193 FileStream.open(FileName.c_str());
195 #ifdef SELDON_CHECK_IO
197 if (!FileStream.is_open())
198 throw IOError(
"Vector<VectFull>::WriteText(string FileName)",
199 string(
"Unable to open file \"") + FileName +
"\".");
202 this->WriteText(FileStream);
217 template <
class T,
class Allocator>
221 #ifdef SELDON_CHECK_IO
223 if (!FileStream.good())
224 throw IOError(
"Vector<VectFull>::WriteText(ostream& FileStream)",
225 "The stream is not ready.");
228 if (this->GetLength() != 0)
229 FileStream << (*this)(0);
231 for (
size_t i = 1; i < this->GetLength(); i++)
232 FileStream <<
"\t" << (*
this)(i);
234 #ifdef SELDON_CHECK_IO
236 if (!FileStream.good())
237 throw IOError(
"Vector<VectFull>::WriteText(ostream& FileStream)",
238 "Output operation failed.");
244 #ifdef SELDON_WITH_HDF5
252 template <
class T,
class Allocator>
255 string dataset_name)
const
257 hid_t file_id = H5Fopen(FileName.c_str(), H5F_ACC_RDWR, H5P_DEFAULT);
259 #ifdef SELDON_CHECK_IO
262 throw IOError(
"Vector<VectFull>::WriteHDF5(string FileName)",
263 string(
"Unable to open file \"") + FileName +
"\".");
266 hid_t dataset_id, dataspace_id, group_id;
271 hid_t datatype = GetH5Type(x);
273 if (!H5Lexists(file_id, group_name.c_str(), H5P_DEFAULT))
274 group_id = H5Gcreate(file_id, group_name.c_str(), 0);
275 group_id = H5Gopen(file_id, group_name.c_str());
277 if (!H5Lexists(group_id, dataset_name.c_str(), H5P_DEFAULT))
280 hsize_t dim[1] = {0};
281 hsize_t maxdims[1] = {H5S_UNLIMITED};
282 dataspace_id = H5Screate_simple(1, dim, maxdims);
285 hid_t cparms = H5Pcreate(H5P_DATASET_CREATE);
286 hsize_t chunk_dims[1] = {this->GetLength()};
287 status = H5Pset_chunk(cparms, 1, chunk_dims);
290 hid_t filetype = H5Tvlen_create(datatype);
291 dataset_id = H5Dcreate(group_id, dataset_name.c_str(),
292 filetype, dataspace_id, cparms);
296 dataset_id = H5Dopen(group_id, dataset_name.c_str());
297 dataspace_id = H5Dget_space(dataset_id);
299 status = H5Sget_simple_extent_dims(dataspace_id, dims_out, NULL);
300 hsize_t new_dim[1]= {dims_out[0] + 1};
301 status = H5Dextend(dataset_id, new_dim);
304 hsize_t offset[1] = {dims_out[0]};
305 hsize_t dim2[1] = {1};
306 dataspace_id = H5Dget_space(dataset_id);
307 status = H5Sselect_hyperslab(dataspace_id, H5S_SELECT_SET,
312 hid_t dataspace = H5Screate_simple(1, dim2, NULL);
315 hid_t memtype = H5Tvlen_create(datatype);
317 wdata[0].len = this->GetLength();
318 wdata[0].p = this->GetDataVoid();
319 status = H5Dwrite(dataset_id, memtype, dataspace,
320 dataspace_id, H5P_DEFAULT, wdata);
323 status = H5Dclose(dataset_id);
324 status = H5Gclose(group_id);
325 status = H5Fclose(file_id);
339 template <
class T,
class Allocator>
344 FileStream.open(FileName.c_str(), ifstream::binary);
346 #ifdef SELDON_CHECK_IO
348 if (!FileStream.is_open())
349 throw IOError(
"Vector<VectFull>::Read(string FileName, bool with_size)",
350 string(
"Unable to open file \"") + FileName +
"\".");
353 this->Read(FileStream, with_size);
368 template <
class T,
class Allocator>
370 ::Read(istream& FileStream,
bool with_size)
373 #ifdef SELDON_CHECK_IO
375 if (!FileStream.good())
376 throw IOError(
"Vector<VectFull>::Read(istream& FileStream, "
378 "The stream is not ready.");
384 FileStream.read(
reinterpret_cast<char*
>(&new_size),
sizeof(
int));
385 this->Reallocate(new_size);
388 FileStream.read(
reinterpret_cast<char*
>(this->data_),
389 this->GetLength() *
sizeof(value_type));
391 #ifdef SELDON_CHECK_IO
393 if (!FileStream.good())
394 throw IOError(
"Vector<VectFull>::Read(istream& FileStream, "
396 "Output operation failed.");
408 template <
class T,
class Allocator>
412 FileStream.open(FileName.c_str());
414 #ifdef SELDON_CHECK_IO
416 if (!FileStream.is_open())
417 throw IOError(
"Vector<VectFull>::ReadText(string FileName)",
418 string(
"Unable to open file \"") + FileName +
"\".");
421 this->ReadText(FileStream);
433 template <
class T,
class Allocator>
439 #ifdef SELDON_CHECK_IO
441 if (!FileStream.good())
442 throw IOError(
"Vector<VectFull>::ReadText(istream& FileStream)",
443 "The stream is not ready.");
447 size_t number_element = 0;
448 while (!FileStream.eof())
452 if (FileStream.fail())
460 if (number_element > this->m_)
461 this->Resize(2 * number_element);
463 this->data_[number_element - 1] = entry;
468 if (number_element > 0)
469 this->Resize(number_element);
481 template <
class T,
class Storage,
class Allocator>
485 if (V.GetLength() >= 1)
486 for (
size_t i = 0; i < V.GetLength() - 1; i++)
489 if (V.GetLength() != 0)
490 out << V(V.GetLength() - 1);
498 #define SELDON_FILE_VECTOR_CXX