| 322 | //------------------------------------------------------------------------------ |
| 323 | template <typename T> |
| 324 | bool 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); |
no test coverage detected