------------------------------------------------------------------------------ Read the header of a vtk data file. Returns 0 if error.
| 532 | //------------------------------------------------------------------------------ |
| 533 | // Read the header of a vtk data file. Returns 0 if error. |
| 534 | int vtkDataReader::ReadHeader(const char* fname) |
| 535 | { |
| 536 | if (!fname && this->GetNumberOfFileNames() > 0) |
| 537 | { |
| 538 | fname = this->GetFileName(0); |
| 539 | } |
| 540 | char line[256]; |
| 541 | |
| 542 | vtkDebugMacro(<< "Reading vtk file header"); |
| 543 | // |
| 544 | // read header |
| 545 | // |
| 546 | if (!this->ReadLine(line)) |
| 547 | { |
| 548 | vtkErrorMacro(<< "Premature EOF reading first line! " |
| 549 | << " for file: " << (fname ? fname : "(Null FileName)")); |
| 550 | this->SetErrorCode(vtkErrorCode::PrematureEndOfFileError); |
| 551 | return 0; |
| 552 | } |
| 553 | constexpr int VERSION_PREFIX_LENGTH = 22; |
| 554 | if (strncmp("# vtk DataFile Version", line, VERSION_PREFIX_LENGTH) != 0) |
| 555 | { |
| 556 | vtkErrorMacro(<< "Unrecognized file type: " << line |
| 557 | << " for file: " << (fname ? fname : "(Null FileName)")); |
| 558 | |
| 559 | this->SetErrorCode(vtkErrorCode::UnrecognizedFileTypeError); |
| 560 | return 0; |
| 561 | } |
| 562 | auto result = vtk::scan<int, int>(std::string_view(line + VERSION_PREFIX_LENGTH), "{:d}.{:d}"); |
| 563 | if (!result) |
| 564 | { |
| 565 | vtkWarningMacro(<< "Cannot read file version: " << line |
| 566 | << " for file: " << (fname ? fname : "(Null FileName)")); |
| 567 | this->FileMajorVersion = 0; |
| 568 | this->FileMinorVersion = 0; |
| 569 | } |
| 570 | std::tie(this->FileMajorVersion, this->FileMinorVersion) = result->values(); |
| 571 | if (this->FileMajorVersion > vtkLegacyReaderMajorVersion || |
| 572 | (this->FileMajorVersion == vtkLegacyReaderMajorVersion && |
| 573 | this->FileMinorVersion > vtkLegacyReaderMinorVersion)) |
| 574 | { |
| 575 | // newer file than the reader version |
| 576 | vtkWarningMacro(<< "Reading file version: " << this->FileMajorVersion << "." |
| 577 | << this->FileMinorVersion << " with older reader version " |
| 578 | << vtkLegacyReaderMajorVersion << "." << vtkLegacyReaderMinorVersion); |
| 579 | } |
| 580 | // Compose FileVersion |
| 581 | this->FileVersion = 10 * this->FileMajorVersion + this->FileMinorVersion; |
| 582 | |
| 583 | // |
| 584 | // read title |
| 585 | // |
| 586 | if (!this->ReadLine(line)) |
| 587 | { |
| 588 | vtkErrorMacro(<< "Premature EOF reading title! " |
| 589 | << " for file: " << (fname ? fname : "(Null FileName)")); |
| 590 | this->SetErrorCode(vtkErrorCode::PrematureEndOfFileError); |
| 591 | return 0; |
no test coverage detected