------------------------------------------------------------------------------ Open a vtk data file. Returns zero if error.
| 457 | //------------------------------------------------------------------------------ |
| 458 | // Open a vtk data file. Returns zero if error. |
| 459 | int vtkDataReader::OpenVTKFile(const char* fname) |
| 460 | { |
| 461 | if (!fname && this->GetNumberOfFileNames() > 0) |
| 462 | { |
| 463 | fname = this->GetFileName(0); |
| 464 | } |
| 465 | this->CurrentFileName = fname ? fname : std::string(); |
| 466 | |
| 467 | if (this->IS != nullptr) |
| 468 | { |
| 469 | this->CloseVTKFile(); |
| 470 | } |
| 471 | if (this->ReadFromInputString) |
| 472 | { |
| 473 | if (this->InputArray) |
| 474 | { |
| 475 | vtkDebugMacro(<< "Reading from InputArray"); |
| 476 | std::string str(this->InputArray->GetPointer(0), |
| 477 | static_cast<size_t>( |
| 478 | this->InputArray->GetNumberOfTuples() * this->InputArray->GetNumberOfComponents())); |
| 479 | this->IS = new std::istringstream(str); |
| 480 | return 1; |
| 481 | } |
| 482 | else if (this->InputString) |
| 483 | { |
| 484 | vtkDebugMacro(<< "Reading from InputString"); |
| 485 | std::string str(this->InputString, this->InputStringLength); |
| 486 | this->IS = new std::istringstream(str); |
| 487 | return 1; |
| 488 | } |
| 489 | } |
| 490 | else |
| 491 | { |
| 492 | vtkDebugMacro(<< "Opening vtk file"); |
| 493 | |
| 494 | if (!fname || (strlen(fname) == 0)) |
| 495 | { |
| 496 | vtkErrorMacro(<< "No file specified!"); |
| 497 | this->SetErrorCode(vtkErrorCode::NoFileNameError); |
| 498 | return 0; |
| 499 | } |
| 500 | |
| 501 | // first make sure the file exists, this prevents an empty file from |
| 502 | // being created on older compilers |
| 503 | vtksys::SystemTools::Stat_t fs; |
| 504 | if (vtksys::SystemTools::Stat(fname, &fs) != 0) |
| 505 | { |
| 506 | vtkErrorMacro(<< "Unable to open file: " << fname); |
| 507 | this->SetErrorCode(vtkErrorCode::CannotOpenFileError); |
| 508 | return 0; |
| 509 | } |
| 510 | |
| 511 | this->IS = new vtksys::ifstream(fname, ios::in | ios::binary); |
| 512 | if (this->IS->fail()) |
| 513 | { |
| 514 | vtkErrorMacro(<< "Unable to open file: " << fname); |
| 515 | delete this->IS; |
| 516 | this->IS = nullptr; |
no test coverage detected