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

Method ReadHeader

IO/Legacy/vtkDataReader.cxx:534–656  ·  view source on GitHub ↗

------------------------------------------------------------------------------ Read the header of a vtk data file. Returns 0 if error.

Source from the content-addressed store, hash-verified

532//------------------------------------------------------------------------------
533// Read the header of a vtk data file. Returns 0 if error.
534int 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;

Callers 15

IsFileValidMethod · 0.95
CharacterizeFileMethod · 0.95
ReadMetaDataSimpleMethod · 0.45
ReadMeshSimpleMethod · 0.45
ReadOutputTypeMethod · 0.45
ReadOutputTypeMethod · 0.45
ReadMeshSimpleMethod · 0.45
ReadMeshSimpleMethod · 0.45
ReadMeshSimpleMethod · 0.45
ReadMeshSimpleMethod · 0.45
ReadMetaDataSimpleMethod · 0.45
ReadMeshSimpleMethod · 0.45

Calls 8

GetFileNameMethod · 0.95
ReadLineMethod · 0.95
ReadStringMethod · 0.95
LowerCaseMethod · 0.95
GetNumberOfFileNamesMethod · 0.45
valuesMethod · 0.45
GetProgressMethod · 0.45
UpdateProgressMethod · 0.45

Tested by

no test coverage detected