------------------------------------------------------------------------------
| 188 | |
| 189 | //------------------------------------------------------------------------------ |
| 190 | bool EnSightFile::SetTimeStepToRead(double ts) |
| 191 | { |
| 192 | if ((this->FileSet == -1 && this->TimeSet == -1) || !this->TimeInfo) |
| 193 | { |
| 194 | // non transient data |
| 195 | return this->OpenFile(this->FileNamePattern); |
| 196 | } |
| 197 | |
| 198 | if (this->TimeInfo->TimeValues.empty()) |
| 199 | { |
| 200 | vtkGenericWarningMacro( |
| 201 | "Time sets are used, but some error has caused the TimeValues to be empty"); |
| 202 | return false; |
| 203 | } |
| 204 | |
| 205 | auto tsIdx = getFileNameNumberIndex(ts, this->TimeInfo); |
| 206 | if (this->TimeSet != -1 && this->FileSet == -1) |
| 207 | { |
| 208 | // only using time sets |
| 209 | if (tsIdx != this->TimeStepIndex) |
| 210 | { |
| 211 | this->TimeStepIndex = tsIdx; |
| 212 | this->CloseFile(); |
| 213 | std::string filename = this->FileNamePattern; |
| 214 | |
| 215 | // check if the filename contains wildcards |
| 216 | std::regex exp("\\*+"); |
| 217 | std::smatch sm; |
| 218 | if (std::regex_search(this->FileNamePattern, sm, exp)) |
| 219 | { |
| 220 | if (!this->TimeInfo) |
| 221 | { |
| 222 | vtkGenericWarningMacro("TimeSet is " << this->TimeSet << ", but TimeInfo was not set"); |
| 223 | return false; |
| 224 | } |
| 225 | filename = replaceWildcards(filename, this->TimeInfo->FileNameNumbers[this->TimeStepIndex]); |
| 226 | } |
| 227 | if (!this->OpenFile(filename)) |
| 228 | { |
| 229 | vtkGenericWarningMacro("the file " << filename << " could not be opened"); |
| 230 | return false; |
| 231 | } |
| 232 | } |
| 233 | this->ResetFile(); |
| 234 | } |
| 235 | else if (this->TimeSet != -1 && this->FileSet != -1) |
| 236 | { |
| 237 | std::streampos posToRead; |
| 238 | int fileIndex = -1; |
| 239 | int tsIndexForFile = tsIdx; |
| 240 | if (!this->FileInfo->FileNameIndex.empty()) |
| 241 | { |
| 242 | // in this case we may have to switch files, depending on what |
| 243 | // time step we're on |
| 244 | // otherwise we just stay in the file we already have opened |
| 245 | fileIndex = getFileSetIndex(tsIdx, this->FileInfo); |
| 246 | tsIndexForFile = this->FileInfo->TimeStepIndexInFile[tsIdx]; |
| 247 | this->CurrentFileIndex = fileIndex; |
no test coverage detected