------------------------------------------------------------------------------
| 70 | |
| 71 | //------------------------------------------------------------------------------ |
| 72 | int vtkPDataSetWriter::Write() |
| 73 | { |
| 74 | int i; |
| 75 | int length; |
| 76 | |
| 77 | ostream* fptr; |
| 78 | vtkDataSet* input = this->GetInput(); |
| 79 | int inputAlgPort; |
| 80 | vtkAlgorithm* inputAlg = this->GetInputAlgorithm(0, 0, inputAlgPort); |
| 81 | |
| 82 | if (this->FileName == nullptr) |
| 83 | { |
| 84 | vtkErrorMacro("No file name."); |
| 85 | return 0; |
| 86 | } |
| 87 | |
| 88 | this->StartPiece = std::max(this->StartPiece, 0); |
| 89 | if (this->NumberOfPieces < 0 || this->EndPiece < this->StartPiece) |
| 90 | { |
| 91 | vtkWarningMacro("No pieces to write."); |
| 92 | return 1; |
| 93 | } |
| 94 | |
| 95 | // Only one piece? The just write one vtk file. |
| 96 | if (this->StartPiece == 0 && this->NumberOfPieces == 1) |
| 97 | { |
| 98 | return this->vtkDataSetWriter::Write(); |
| 99 | } |
| 100 | |
| 101 | // Lets compute the file root from the file name supplied by the user. |
| 102 | length = static_cast<int>(strlen(this->FileName)); |
| 103 | std::vector<char> fileRoot(length + 1); |
| 104 | size_t fileNameSize = length + this->FilePatternStdFormat.size() + 20; |
| 105 | std::vector<char> fileName(fileNameSize); |
| 106 | strncpy(fileRoot.data(), this->FileName, length); |
| 107 | fileRoot[length] = '\0'; |
| 108 | // Trim off the pvtk extension. |
| 109 | if (strncmp(fileRoot.data() + length - 5, ".pvtk", 5) == 0) |
| 110 | { |
| 111 | fileRoot[length - 5] = '\0'; |
| 112 | } |
| 113 | if (strncmp(fileRoot.data() + length - 4, ".vtk", 4) == 0) |
| 114 | { |
| 115 | fileRoot[length - 4] = '\0'; |
| 116 | } |
| 117 | // If we are using relative file names, trim off the directory path. |
| 118 | if (this->UseRelativeFileNames) |
| 119 | { |
| 120 | char *tmp, *slash; |
| 121 | // Find the last / or \ in the file name. |
| 122 | slash = nullptr; |
| 123 | tmp = fileRoot.data(); |
| 124 | while (*tmp != '\0') |
| 125 | { |
| 126 | if (*tmp == '/' || *tmp == '\\') |
| 127 | { |
| 128 | slash = tmp; |
| 129 | } |