------------------------------------------------------------------------------
| 392 | |
| 393 | //------------------------------------------------------------------------------ |
| 394 | bool vtkMultiBlockPLOT3DReaderRecord::Initialize(FILE* fp, vtkTypeUInt64 offset, |
| 395 | const vtkMultiBlockPLOT3DReaderInternals::InternalSettings& settings, |
| 396 | vtkMultiProcessController* controller) |
| 397 | { |
| 398 | this->SubRecords.clear(); |
| 399 | if (!settings.BinaryFile || !settings.HasByteCount) |
| 400 | { |
| 401 | return true; |
| 402 | } |
| 403 | const int rank = controller ? controller->GetLocalProcessId() : 0; |
| 404 | int error = 0; |
| 405 | if (rank == 0) |
| 406 | { |
| 407 | vtkTypeUInt64 pos = vtk_ftell(fp); |
| 408 | unsigned int leadingLengthField; |
| 409 | int signBit = 0; |
| 410 | try |
| 411 | { |
| 412 | do |
| 413 | { |
| 414 | vtkSubRecord subrecord; |
| 415 | subrecord.HeaderOffset = offset; |
| 416 | vtkTypeUInt64 dataOffset = subrecord.HeaderOffset + sizeof(int); |
| 417 | vtk_fseek(fp, offset, SEEK_SET); |
| 418 | if (fread(&leadingLengthField, sizeof(unsigned int), 1, fp) != 1) |
| 419 | { |
| 420 | throw Plot3DException(); |
| 421 | } |
| 422 | if (settings.ByteOrder == vtkMultiBlockPLOT3DReader::FILE_LITTLE_ENDIAN) |
| 423 | { |
| 424 | vtkByteSwap::Swap4LE(&leadingLengthField); |
| 425 | } |
| 426 | else |
| 427 | { |
| 428 | vtkByteSwap::Swap4BE(&leadingLengthField); |
| 429 | } |
| 430 | signBit = (0x80000000 & leadingLengthField) ? 1 : 0; |
| 431 | if (signBit) |
| 432 | { |
| 433 | unsigned int length = 0xffffffff ^ (leadingLengthField - 1); |
| 434 | subrecord.FooterOffset = dataOffset + length; |
| 435 | } |
| 436 | else |
| 437 | { |
| 438 | subrecord.FooterOffset = dataOffset + leadingLengthField; |
| 439 | } |
| 440 | this->SubRecords.push_back(subrecord); |
| 441 | offset = subrecord.FooterOffset + sizeof(int); |
| 442 | } while (signBit == 1); |
| 443 | } |
| 444 | catch (Plot3DException&) |
| 445 | { |
| 446 | error = 1; |
| 447 | } |
| 448 | vtk_fseek(fp, pos, SEEK_SET); |
| 449 | } |
| 450 | |
| 451 | if (controller == nullptr) |