MCPcopy Create free account
hub / github.com/Kitware/VTK / ReadArray

Method ReadArray

IO/EnSight/core/EnSightFile.h:324–385  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

322//------------------------------------------------------------------------------
323template <typename T>
324bool EnSightFile::ReadArray(T* result, vtkIdType n, bool singleLine /* = false*/,
325 bool padBeginning /* = true*/, bool padEnd /* = true*/)
326{
327 if (n <= 0)
328 {
329 return true;
330 }
331
332 if (this->Format == FileType::ASCII)
333 {
334 if (!singleLine)
335 {
336 for (int i = 0; i < n; i++)
337 {
338 this->ReadNumber(&result[i]);
339 }
340 }
341 else
342 {
343 int size = getNumChars<T>() * n + 10 * n;
344 auto lineResult = this->ReadLine(size);
345 if (!lineResult.first)
346 {
347 vtkGenericWarningMacro("ReadArray() the full ascii line was not read");
348 }
349
350 std::stringstream ss(lineResult.second);
351 for (int i = 0; i < n; i++)
352 {
353 ss >> result[i];
354 }
355 }
356 }
357 else
358 {
359 // In some cases we want to read everything in a single fortran
360 // read into a single array, but sometimes we don't want to, so
361 // we have to handle the skip bytes appropriately
362 if (padBeginning && this->FortranSkipBytes > 0)
363 {
364 this->MoveReadPosition(this->FortranSkipBytes);
365 }
366 if (!this->Stream->read((char*)result, sizeof(T) * n))
367 {
368 vtkGenericWarningMacro("read array failed");
369 return false;
370 }
371 if (padEnd && this->FortranSkipBytes > 0)
372 {
373 this->MoveReadPosition(this->FortranSkipBytes);
374 }
375 if (this->ByteOrder == Endianness::Little)
376 {
377 vtkByteSwap::Swap4LERange(result, n);
378 }
379 else if (this->ByteOrder == Endianness::Big)
380 {
381 vtkByteSwap::Swap4BERange(result, n);

Callers 15

ReadMeasuredGeometryMethod · 0.45
ReadVariableArrayMethod · 0.45
ReadDimensionsMethod · 0.45
ReadRangeMethod · 0.45
ReadOptionalValuesMethod · 0.45
ReadCellMethod · 0.45
ReadNSidedSectionMethod · 0.45

Calls 4

ReadNumberMethod · 0.95
ReadLineMethod · 0.95
MoveReadPositionMethod · 0.95
readMethod · 0.45

Tested by

no test coverage detected