Unfortunately, a Plot3D file written in C is trickier to check because it has no byte count markers. We need to do a bit more brute force checks based on reading data and estimating file size.
| 248 | // to do a bit more brute force checks based on reading |
| 249 | // data and estimating file size. |
| 250 | int vtkMultiBlockPLOT3DReaderInternals::CheckCFile(FILE* fp, size_t fileSize) |
| 251 | { |
| 252 | int precisions[2] = { 4, 8 }; |
| 253 | int blankings[2] = { 0, 1 }; |
| 254 | int dimensions[2] = { 2, 3 }; |
| 255 | |
| 256 | clearerr(fp); // clear error and EOF flags |
| 257 | fseek(fp, 0, SEEK_SET); // move to beginning |
| 258 | int gridDims[3]; |
| 259 | if (this->ReadInts(fp, 3, gridDims) != 3) |
| 260 | { |
| 261 | return 0; |
| 262 | } |
| 263 | |
| 264 | // Single grid |
| 265 | for (int i = 0; i < 2; i++) |
| 266 | { |
| 267 | int precision = precisions[i]; |
| 268 | for (int j = 0; j < 2; j++) |
| 269 | { |
| 270 | int blanking = blankings[j]; |
| 271 | for (int k = 0; k < 2; k++) |
| 272 | { |
| 273 | int dimension = dimensions[k]; |
| 274 | |
| 275 | if (fileSize == |
| 276 | this->CalculateFileSize(false, precision, blanking, dimension, |
| 277 | false, // always |
| 278 | 1, gridDims)) |
| 279 | { |
| 280 | this->Settings.MultiGrid = 0; |
| 281 | this->Settings.Precision = precision; |
| 282 | this->Settings.IBlanking = blanking; |
| 283 | this->Settings.NumberOfDimensions = dimension; |
| 284 | return 1; |
| 285 | } |
| 286 | } |
| 287 | } |
| 288 | } |
| 289 | |
| 290 | // Multi grid |
| 291 | int nGrids; |
| 292 | clearerr(fp); // clear error and EOF flags |
| 293 | fseek(fp, 0, SEEK_SET); // move to beginning |
| 294 | if (!this->ReadInts(fp, 1, &nGrids)) |
| 295 | { |
| 296 | return 0; |
| 297 | } |
| 298 | std::vector<int> gridDims2(3 * nGrids); |
| 299 | if (this->ReadInts(fp, nGrids * 3, gridDims2.data()) != nGrids * 3) |
| 300 | { |
| 301 | return 0; |
| 302 | } |
| 303 | |
| 304 | for (int i = 0; i < 2; i++) |
| 305 | { |
| 306 | int precision = precisions[i]; |
| 307 | for (int j = 0; j < 2; j++) |
no test coverage detected