forked from Kitware/VTK
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathvtkEnSightReader.cxx
2287 lines (2105 loc) · 78.8 KB
/
vtkEnSightReader.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*=========================================================================
Program: Visualization Toolkit
Module: vtkEnSightReader.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "vtkEnSightReader.h"
#include "vtkDataArrayCollection.h"
#include "vtkFloatArray.h"
#include "vtkMultiBlockDataSet.h"
#include "vtkIdList.h"
#include "vtkIdListCollection.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkObjectFactory.h"
#include "vtkRectilinearGrid.h"
#include "vtkSmartPointer.h"
#include "vtkStreamingDemandDrivenPipeline.h"
#include "vtkStructuredGrid.h"
#include "vtkStructuredPoints.h"
#include "vtkUnstructuredGrid.h"
#include <vtkstd/algorithm>
#include <vtkstd/string>
#include <vtkstd/vector>
//----------------------------------------------------------------------------
typedef vtkstd::vector< vtkSmartPointer<vtkIdList> > vtkEnSightReaderCellIdsTypeBase;
class vtkEnSightReaderCellIdsType: public vtkEnSightReaderCellIdsTypeBase {};
//----------------------------------------------------------------------------
vtkEnSightReader::vtkEnSightReader()
{
this->MeasuredFileName = NULL;
this->MatchFileName = NULL;
this->ParticleCoordinatesByIndex = 0;
this->IS = NULL;
this->VariableMode = -1;
this->UnstructuredPartIds = vtkIdList::New();
this->CellIds = NULL;
this->VariableFileNames = NULL;
this->ComplexVariableFileNames = NULL;
this->VariableDescriptions = NULL;
this->ComplexVariableDescriptions = NULL;
this->VariableTimeSetIds = vtkIdList::New();
this->ComplexVariableTimeSetIds = vtkIdList::New();
this->VariableFileSetIds = vtkIdList::New();
this->ComplexVariableFileSetIds = vtkIdList::New();
this->TimeSetFileNameNumbers = vtkIdListCollection::New();
this->TimeSetsWithFilenameNumbers = vtkIdList::New();
this->TimeSets = vtkDataArrayCollection::New();
this->FileSetFileNameNumbers = vtkIdListCollection::New();
this->FileSetsWithFilenameNumbers = vtkIdList::New();
this->FileSetNumberOfSteps = vtkIdListCollection::New();
this->TimeSetIds = vtkIdList::New();
this->FileSets = vtkIdList::New();
this->GeometryTimeSet = 1;
this->GeometryFileSet = 1;
this->MeasuredTimeSet = 1;
this->MeasuredFileSet = 1;
this->UseTimeSets = 0;
this->UseFileSets = 0;
this->GeometryTimeValue = -1;
this->MeasuredTimeValue = -1;
this->NumberOfGeometryParts = 0;
this->NumberOfMeasuredPoints = 0;
this->InitialRead = 1;
this->NumberOfNewOutputs = 0;
this->PreviousTimeStepInFile = 1;
this->ForwardTimeStepShiftIS = NULL;
this->ForwardTimeStepShiftMode = FORWARD_TIME_STEP_SHIFT_NON;
}
//----------------------------------------------------------------------------
vtkEnSightReader::~vtkEnSightReader()
{
int i;
if (this->CellIds)
{
delete this->CellIds;
this->CellIds = NULL;
}
if (this->MeasuredFileName)
{
delete [] this->MeasuredFileName;
this->MeasuredFileName = NULL;
}
if (this->MatchFileName)
{
delete [] this->MatchFileName;
this->MatchFileName = NULL;
}
if (this->NumberOfVariables > 0)
{
for (i = 0; i < this->NumberOfVariables; i++)
{
delete [] this->VariableFileNames[i];
}
delete [] this->VariableFileNames;
this->VariableFileNames = NULL;
}
if (this->NumberOfComplexVariables > 0)
{
for (i = 0; i < this->NumberOfComplexVariables*2; i++)
{
delete [] this->ComplexVariableFileNames[i];
}
delete [] this->ComplexVariableFileNames;
this->ComplexVariableFileNames = NULL;
}
this->UnstructuredPartIds->Delete();
this->UnstructuredPartIds = NULL;
this->VariableTimeSetIds->Delete();
this->VariableTimeSetIds = NULL;
this->ComplexVariableTimeSetIds->Delete();
this->ComplexVariableTimeSetIds = NULL;
this->VariableFileSetIds->Delete();
this->VariableFileSetIds = NULL;
this->ComplexVariableFileSetIds->Delete();
this->ComplexVariableFileSetIds = NULL;
this->TimeSetFileNameNumbers->Delete();
this->TimeSetFileNameNumbers = NULL;
this->TimeSetsWithFilenameNumbers->Delete();
this->TimeSetsWithFilenameNumbers = NULL;
this->TimeSets->Delete();
this->TimeSets = NULL;
this->FileSetFileNameNumbers->Delete();
this->FileSetFileNameNumbers = NULL;
this->FileSetsWithFilenameNumbers->Delete();
this->FileSetsWithFilenameNumbers = NULL;
this->FileSetNumberOfSteps->Delete();
this->FileSetNumberOfSteps = NULL;
this->TimeSetIds->Delete();
this->TimeSets = NULL;
this->FileSets->Delete();
this->FileSets = NULL;
this->ActualTimeValue = 0.0;
if ( this->ForwardTimeStepShiftIS )
{
delete this->ForwardTimeStepShiftIS;
this->ForwardTimeStepShiftIS = NULL;
}
}
//----------------------------------------------------------------------------
int vtkEnSightReader::RequestData(
vtkInformation *vtkNotUsed(request),
vtkInformationVector **vtkNotUsed(inputVector),
vtkInformationVector *outputVector)
{
vtkDebugMacro("In execute ");
vtkInformation *outInfo = outputVector->GetInformationObject(0);
vtkMultiBlockDataSet *output = vtkMultiBlockDataSet::SafeDownCast(
outInfo->Get(vtkDataObject::DATA_OBJECT()));
int tsLength =
outInfo->Length(vtkStreamingDemandDrivenPipeline::TIME_STEPS());
double* steps =
outInfo->Get(vtkStreamingDemandDrivenPipeline::TIME_STEPS());
this->ActualTimeValue = this->TimeValue;
// Check if a particular time was requested by the pipeline.
// This overrides the ivar.
if(outInfo->Has(vtkStreamingDemandDrivenPipeline::UPDATE_TIME_STEPS()) && tsLength>0)
{
// Get the requested time step. We only supprt requests of a single time
// step in this reader right now
double *requestedTimeSteps =
outInfo->Get(vtkStreamingDemandDrivenPipeline::UPDATE_TIME_STEPS());
// find the first time value larger than requested time value
// this logic could be improved
int cnt = 0;
while (cnt < tsLength-1 && steps[cnt] < requestedTimeSteps[0])
{
cnt++;
}
this->ActualTimeValue = steps[cnt];
}
int i, timeSet, fileSet, timeStep, timeStepInFile, fileNum;
int numSteps;
int filenameNum;
float newTime;
char * fileName = NULL;
vtkDataArray * times = NULL;
vtkIdList * numStepsList = NULL;
vtkIdList * filenameNumbers = NULL;
static char prevFileName[300] = { "" }; // for forward time step shifting
if ( ! this->CaseFileRead)
{
vtkErrorMacro("error reading case file");
return 0;
}
this->NumberOfNewOutputs = 0;
this->NumberOfGeometryParts = 0;
if (this->GeometryFileName)
{
timeStep = timeStepInFile = 1;
fileNum = 1;
fileName = new char[strlen(this->GeometryFileName) + 10];
strcpy(fileName, this->GeometryFileName);
if (this->UseTimeSets)
{
// The TIME section may declare multiple time sets, each coupled with
// an index. We first need to obtain its corresponding index in a list.
timeSet = this->TimeSetIds->IsId(this->GeometryTimeSet);
if (timeSet >= 0)
{
// Each time set declares some time values
times = this->TimeSets->GetItem(timeSet);
// access the beginning time step value
this->GeometryTimeValue = times->GetComponent(0, 0);
for (i = 1; i < times->GetNumberOfTuples(); i++)
{
newTime = times->GetComponent(i, 0);
// If the value of the current time-array item is no greater than
// the target time step, we need to update the time step.
if (newTime <= this->ActualTimeValue &&
newTime > this->GeometryTimeValue)
{
this->GeometryTimeValue = newTime;
timeStep++;
timeStepInFile++;
}
}
// obtain the target file name
if (this->TimeSetFileNameNumbers->GetNumberOfItems() > 0)
{
// The TIME section declares possibly multiple time sets and the
// files referenced by each time set are accessed via some filename
// numbers that constitute a list. Thus the entire TIME section may
// include multiple such lists.
// obtain the index of the list (of filename numbers) for the
// target time set
int collectionNum = this->TimeSetsWithFilenameNumbers->
IsId(this->GeometryTimeSet);
// get the list (of filename numbers) for the target time set and
// then obtain the filename number of the target file via (timeStep - 1)
if (collectionNum > -1)
{
filenameNumbers =
this->TimeSetFileNameNumbers->GetItem(collectionNum);
filenameNum = filenameNumbers->GetId(timeStep-1);
this->ReplaceWildcards(fileName, filenameNum);
}
}
// --------------------------------------------------------------------
// If FILE SETS are declared, we need to determine the target file name
// by means of the method below.
// --------------------------------------------------------------------
// There can only be file sets if there are also time sets.
if (this->UseFileSets)
{
// The FILE section may declare multiple file sets, each coupled
// with an index.
fileSet = this->FileSets->IsId(this->GeometryFileSet);
// Each file set may include multiple filename indices, each coupled
// with the number of steps covered by the file. These numbers, of
// the entire file set, are stored in a list.
numStepsList = static_cast<vtkIdList*>(this->FileSetNumberOfSteps->
GetItemAsObject(fileSet));
// number of all steps of this file set, index of the target file,
// and the index of the time step in the target file
if (timeStep > numStepsList->GetId(0))
{
// Given the file set (determined above) covering the target
// time step, its FIRST file just does not include the target
// time step. Thus we need to skip at least one file to locate
// the target file.
numSteps = numStepsList->GetId(0);
timeStepInFile -= numSteps;
for (i = 1; i < numStepsList->GetNumberOfIds(); i++)
{
numSteps += numStepsList->GetId(i);
if (timeStep > numSteps)
{
fileNum++;
timeStepInFile -= numStepsList->GetId(i);
}
}
}
// the index of the target file has been determined, i.e., fileNum.
if (this->FileSetFileNameNumbers->GetNumberOfItems() > 0)
{
// The FILE section declares possibly multiple file sets and
// the files referenced by each file set are accessed via
// some filename numbers that constitute a list. The entire
// FILE section may include mutiple such lists.
// obtain the index of the list (of filename numbers) for the
// target file set
int collectionNum = this->FileSetsWithFilenameNumbers->
IsId(this->GeometryFileSet);
// get the list (of filename numbers) for the target file set
// and then obtain the filename number of the target file
// via (fileNum - 1)
if (collectionNum > -1)
{
filenameNumbers = this->FileSetFileNameNumbers->
GetItem(collectionNum);
filenameNum = filenameNumbers->GetId(fileNum-1);
this->ReplaceWildcards(fileName, filenameNum);
}
}
}
}
}
// set the forward time step shifting mode
// for accelerated data loading (bug #9289)
if ( ( strcmp( prevFileName, fileName ) == 0 )
&& ( timeStepInFile > this->PreviousTimeStepInFile )
&& ( numStepsList != NULL ) // in case each time step of the time-
// varying geometry is stored in a
// single file (bug #10117)
&& ( timeStepInFile <= numStepsList->GetId( fileNum - 1 ) )
)
{
this->ForwardTimeStepShiftMode = FORWARD_TIME_STEP_SHIFT_YES;
if ( numStepsList
&& numStepsList->GetId( fileNum - 1 ) == timeStepInFile
)
{
this->ForwardTimeStepShiftMode = FORWARD_TIME_STEP_SHIFT_END;
}
}
else
{
this->ForwardTimeStepShiftMode = FORWARD_TIME_STEP_SHIFT_NON;
}
if (!this->ReadGeometryFile(fileName, timeStepInFile, output))
{
vtkErrorMacro("error reading geometry file");
delete [] fileName;
fileName = NULL;
return 0;
}
// update the geometry file name and the in-file time step in support
// of forward time step shifting for accelerated data loading (bug #9289)
strcpy( prevFileName, fileName );
prevFileName[ strlen( fileName ) ] = '\0';
this->PreviousTimeStepInFile = timeStepInFile;
delete [] fileName;
fileName = NULL;
}
if (this->MeasuredFileName)
{
timeStep = timeStepInFile = 1;
fileNum = 1;
fileName = new char[strlen(this->MeasuredFileName) + 10];
strcpy(fileName, this->MeasuredFileName);
if (this->UseTimeSets)
{
timeSet = this->TimeSetIds->IsId(this->MeasuredTimeSet);
if (timeSet >= 0)
{
times = this->TimeSets->GetItem(timeSet);
this->MeasuredTimeValue = times->GetComponent(0, 0);
for (i = 1; i < times->GetNumberOfTuples(); i++)
{
newTime = times->GetComponent(i, 0);
if (newTime <= this->ActualTimeValue &&
newTime > this->MeasuredTimeValue)
{
this->MeasuredTimeValue = newTime;
timeStep++;
timeStepInFile++;
}
}
if (this->TimeSetFileNameNumbers->GetNumberOfItems() > 0)
{
int collectionNum = this->TimeSetsWithFilenameNumbers->
IsId(this->MeasuredTimeSet);
if (collectionNum > -1)
{
filenameNumbers = this->TimeSetFileNameNumbers->
GetItem(collectionNum);
filenameNum = filenameNumbers->GetId(timeStep-1);
this->ReplaceWildcards(fileName, filenameNum);
}
}
// There can only be file sets if there are also time sets.
if (this->UseFileSets)
{
fileSet = this->FileSets->IsId(this->MeasuredFileSet);
numStepsList = static_cast<vtkIdList*>(this->FileSetNumberOfSteps->
GetItemAsObject(fileSet));
if (timeStep > numStepsList->GetId(0))
{
numSteps = numStepsList->GetId(0);
timeStepInFile -= numSteps;
for (i = 1; i < numStepsList->GetNumberOfIds(); i++)
{
numSteps += numStepsList->GetId(i);
if (timeStep > numSteps)
{
fileNum++;
timeStepInFile -= numStepsList->GetId(i);
}
}
}
if (this->FileSetFileNameNumbers->GetNumberOfItems() > 0)
{
int collectionNum = this->FileSetsWithFilenameNumbers->
IsId(this->MeasuredFileSet);
if (collectionNum > -1)
{
filenameNumbers = this->FileSetFileNameNumbers->
GetItem(fileSet);
filenameNum = filenameNumbers->GetId(fileNum-1);
this->ReplaceWildcards(fileName, filenameNum);
}
}
}
}
}
if (!this->ReadMeasuredGeometryFile(fileName, timeStepInFile, output))
{
vtkErrorMacro("error reading measured geometry file");
delete [] fileName;
return 0;
}
delete [] fileName;
}
if ((this->NumberOfVariables + this->NumberOfComplexVariables) > 0)
{
if (!this->ReadVariableFiles(output))
{
vtkErrorMacro("error reading variable files");
return 0;
}
}
return 1;
}
//----------------------------------------------------------------------------
int vtkEnSightReader::RequestInformation(
vtkInformation *vtkNotUsed(request),
vtkInformationVector **vtkNotUsed(inputVector),
vtkInformationVector *outputVector)
{
vtkDebugMacro("In execute information");
this->CaseFileRead = this->ReadCaseFile();
// Convert time steps to one sorted and uniquefied list.
vtkstd::vector<double> timeValues;
if (this->GetTimeSets())
{
int numItems = this->GetTimeSets()->GetNumberOfItems();
for (int i=0; i<numItems; i++)
{
vtkDataArray* array = this->GetTimeSets()->GetItem(i);
if (array)
{
vtkIdType numTuples = array->GetNumberOfTuples();
for (vtkIdType j=0; j<numTuples; j++)
{
timeValues.push_back(array->GetComponent(j, 0));
}
}
}
}
if (timeValues.size() > 0)
{
vtkstd::sort(timeValues.begin(), timeValues.end());
vtkstd::vector<double> uniqueTimeValues(
timeValues.begin(),
vtkstd::unique(timeValues.begin(), timeValues.end()));
int numTimeValues = static_cast<int>(uniqueTimeValues.size());
if (numTimeValues > 0)
{
vtkInformation* outInfo = outputVector->GetInformationObject(0);
outInfo->Set(vtkStreamingDemandDrivenPipeline::TIME_STEPS(),
&uniqueTimeValues[0],
numTimeValues);
double timeRange[2];
timeRange[0] = uniqueTimeValues[0];
timeRange[1] = uniqueTimeValues[numTimeValues-1];
outInfo->Set(vtkStreamingDemandDrivenPipeline::TIME_RANGE(),
timeRange, 2);
}
}
return this->CaseFileRead;
}
//----------------------------------------------------------------------------
int vtkEnSightReader::ReadCaseFile()
{
char line[256], formatLine[256];
char subLine[256], subLine2[256];
int stringRead;
int timeSet, fileSet, numTimeSteps, i, filenameNum, increment, lineRead;
float timeStep;
// Initialize
//
if (!this->CaseFileName)
{
vtkErrorMacro("A CaseFileName must be specified.");
return 0;
}
vtkstd::string sfilename;
if (this->FilePath)
{
sfilename = this->FilePath;
if (sfilename.at(sfilename.length()-1) != '/')
{
sfilename += "/";
}
sfilename += this->CaseFileName;
vtkDebugMacro("full path to case file: " << sfilename.c_str());
}
else
{
sfilename = this->CaseFileName;
}
this->IS = new ifstream(sfilename.c_str(), ios::in);
if (this->IS->fail())
{
vtkErrorMacro("Unable to open file: " << sfilename.c_str());
delete this->IS;
this->IS = NULL;
return 0;
}
this->TimeSets->RemoveAllItems();
for (i = 0; i < this->NumberOfVariables; i++)
{
delete [] this->VariableFileNames[i];
this->VariableFileNames[i] = NULL;
delete [] this->VariableDescriptions[i];
this->VariableDescriptions[i] = NULL;
}
delete [] this->VariableFileNames;
this->VariableFileNames = NULL;
delete [] this->VariableDescriptions;
this->VariableDescriptions = NULL;
delete [] this->VariableTypes;
this->VariableTypes = NULL;
for (i = 0; i < this->NumberOfComplexVariables; i++)
{
delete [] this->ComplexVariableFileNames[2*i];
this->ComplexVariableFileNames[2*i] = NULL;
delete [] this->ComplexVariableFileNames[2*i+1];
this->ComplexVariableFileNames[2*i+1] = NULL;
delete [] this->ComplexVariableDescriptions[i];
this->ComplexVariableDescriptions[i] = NULL;
}
delete [] this->ComplexVariableFileNames;
this->ComplexVariableFileNames = NULL;
delete [] this->ComplexVariableDescriptions;
this->ComplexVariableDescriptions = NULL;
delete [] this->ComplexVariableTypes;
this->ComplexVariableTypes = NULL;
this->NumberOfVariables = 0;
this->NumberOfComplexVariables = 0;
this->ReadNextDataLine(line);
if (strncmp(line, "FORMAT", 6) == 0)
{
// found the FORMAT section
vtkDebugMacro("*** FORMAT section");
this->ReadNextDataLine(line);
stringRead = sscanf(line, " %*s %*s %s", subLine);
if (stringRead == 1)
{
if (strcmp(subLine, "gold") == 0 &&
strcmp(this->GetClassName(), "vtkEnSight6Reader") == 0)
{
// The class is vtkEnSight6Reader, but the case file says "gold".
vtkErrorMacro("This is not an EnSight6 file.");
delete this->IS;
this->IS = NULL;
return 0;
}
}
else
{
if (strcmp(this->GetClassName(), "vtkEnSightGoldReader") == 0)
{
// The class is vtkEnSightGoldReader, but the case file does
// not say "gold".
vtkErrorMacro("This is not an EnSight Gold file.");
delete this->IS;
this->IS = NULL;
return 0;
}
}
}
// We know how many lines to read in the FORMAT section, so we haven't read
// the "GEOMETRY" line yet.
this->ReadNextDataLine(line);
if (strncmp(line, "GEOMETRY", 8) == 0)
{
// found the GEOMETRY section
vtkDebugMacro("*** GEOMETRY section");
// There will definitely be a "model" line. There may also be "measured"
// and "match" lines.
while(this->ReadNextDataLine(line) != 0 &&
strncmp(line, "m", 1) == 0)
{
if (strncmp(line, "model:", 6) == 0)
{
if (sscanf(line, " %*s %d%*[ \t]%d%*[ \t]%s", &timeSet, &fileSet, subLine) == 3)
{
this->GeometryTimeSet = timeSet;
this->GeometryFileSet = fileSet;
this->SetGeometryFileName(subLine);
vtkDebugMacro(<<this->GetGeometryFileName());
}
else if (sscanf(line, " %*s %d%*[ \t]%s", &timeSet, subLine) == 2)
{
this->GeometryTimeSet = timeSet;
this->SetGeometryFileName(subLine);
vtkDebugMacro(<<this->GetGeometryFileName());
}
else if (sscanf(line, " %*s %s", subLine) == 1)
{
this->SetGeometryFileName(subLine);
vtkDebugMacro(<<this->GetGeometryFileName());
}
}
else if (strncmp(line, "measured:", 9) == 0)
{
if (sscanf(line, " %*s %d%*[ \t]%d%*[ \t]%s", &timeSet, &fileSet, subLine) == 3)
{
this->MeasuredTimeSet = timeSet;
this->MeasuredFileSet = fileSet;
this->SetMeasuredFileName(subLine);
vtkDebugMacro(<< this->GetMeasuredFileName());
}
else if (sscanf(line, " %*s %d%*[ \t]%s", &timeSet, subLine) == 2)
{
this->MeasuredTimeSet = timeSet;
this->SetMeasuredFileName(subLine);
vtkDebugMacro(<< this->GetMeasuredFileName());
}
else if (sscanf(line, " %*s %s", subLine) == 1)
{
this->SetMeasuredFileName(subLine);
vtkDebugMacro(<< this->GetMeasuredFileName());
}
}
else if (strncmp(line, "match:", 6) == 0)
{
sscanf(line, " %*s %s", subLine);
this->SetMatchFileName(subLine);
vtkDebugMacro(<< this->GetMatchFileName());
}
}
}
if (strncmp(line, "VARIABLE", 8) == 0)
{
// found the VARIABLE section
vtkDebugMacro(<< "*** VARIABLE section");
this->NumberOfScalarsPerNode = 0;
this->NumberOfVectorsPerNode = 0;
this->NumberOfTensorsSymmPerNode = 0;
this->NumberOfScalarsPerElement = 0;
this->NumberOfVectorsPerElement = 0;
this->NumberOfTensorsSymmPerElement = 0;
this->NumberOfScalarsPerMeasuredNode = 0;
this->NumberOfVectorsPerMeasuredNode = 0;
this->NumberOfComplexScalarsPerNode = 0;
this->NumberOfComplexVectorsPerNode = 0;
this->NumberOfComplexScalarsPerElement = 0;
this->NumberOfComplexVectorsPerElement = 0;
while(this->ReadNextDataLine(line) != 0 &&
strncmp(line, "TIME", 4) != 0 &&
strncmp(line, "FILE", 4) != 0)
{
if (strncmp(line, "constant", 8) == 0)
{
vtkDebugMacro(<< line);
}
else if (strncmp(line, "scalar", 6) == 0)
{
sscanf(line, " %*s %*s %s", subLine);
if (strcmp(subLine, "node:") == 0)
{
vtkDebugMacro("scalar per node");
this->VariableMode = vtkEnSightReader::SCALAR_PER_NODE;
if (sscanf(line, " %*s %*s %*s %d %d %s", &timeSet, &fileSet,
subLine) == 3)
{
this->VariableTimeSetIds->InsertNextId(timeSet);
this->VariableFileSetIds->InsertNextId(fileSet);
this->AddVariableDescription(subLine);
sscanf(line, " %*s %*s %*s %*d %*d %*s %s", subLine);
}
else if (sscanf(line, " %*s %*s %*s %d %s", &timeSet, subLine) == 2)
{
this->VariableTimeSetIds->InsertNextId(timeSet);
this->AddVariableDescription(subLine);
sscanf(line, " %*s %*s %*s %*d %*s %s", subLine);
}
else if (sscanf(line, " %*s %*s %*s %s", subLine) == 1)
{
this->VariableTimeSetIds->InsertNextId(1);
this->AddVariableDescription(subLine);
sscanf(line, " %*s %*s %*s %*s %s", subLine);
}
this->AddVariableType();
this->NumberOfScalarsPerNode++;
}
else if (strcmp(subLine, "element:") == 0)
{
vtkDebugMacro("scalar per element");
this->VariableMode = vtkEnSightReader::SCALAR_PER_ELEMENT;
if (sscanf(line, " %*s %*s %*s %d %d %s", &timeSet, &fileSet,
subLine) == 3)
{
this->VariableTimeSetIds->InsertNextId(timeSet);
this->VariableFileSetIds->InsertNextId(fileSet);
this->AddVariableDescription(subLine);
sscanf(line, " %*s %*s %*s %*d %*d %*s %s", subLine);
}
else if (sscanf(line, " %*s %*s %*s %d %s", &timeSet, subLine) == 2)
{
this->VariableTimeSetIds->InsertNextId(timeSet);
this->AddVariableDescription(subLine);
sscanf(line, " %*s %*s %*s %*d %*s %s", subLine);
}
else if (sscanf(line, " %*s %*s %*s %s", subLine) == 1)
{
this->VariableTimeSetIds->InsertNextId(1);
this->AddVariableDescription(subLine);
sscanf(line, " %*s %*s %*s %*s %s", subLine);
}
this->AddVariableType();
this->NumberOfScalarsPerElement++;
}
else if (strcmp(subLine, "measured") == 0)
{
vtkDebugMacro("scalar per measured node");
this->VariableMode = vtkEnSightReader::SCALAR_PER_MEASURED_NODE;
if (sscanf(line, " %*s %*s %*s %*s %d %d %s", &timeSet, &fileSet,
subLine) == 3)
{
this->VariableTimeSetIds->InsertNextId(timeSet);
this->VariableFileSetIds->InsertNextId(fileSet);
this->AddVariableDescription(subLine);
sscanf(line, " %*s %*s %*s %*s %*d %*d %*s %s", subLine);
}
else if (sscanf(line, " %*s %*s %*s %*s %d %s", &timeSet,
subLine) == 2)
{
this->VariableTimeSetIds->InsertNextId(timeSet);
this->AddVariableDescription(subLine);
sscanf(line, " %*s %*s %*s %*s %*d %*s %s", subLine);
}
else if (sscanf(line, " %*s %*s %*s %*s %s", subLine) == 1)
{
this->VariableTimeSetIds->InsertNextId(1);
this->AddVariableDescription(subLine);
sscanf(line, " %*s %*s %*s %*s %*s %s", subLine);
}
this->AddVariableType();
this->NumberOfScalarsPerMeasuredNode++;
}
this->AddVariableFileName(subLine);
this->NumberOfVariables++;
}
else if (strncmp(line, "vector", 6) == 0)
{
sscanf(line, " %*s %*s %s", subLine);
if (strcmp(subLine, "node:") == 0)
{
vtkDebugMacro("vector per node");
this->VariableMode = vtkEnSightReader::VECTOR_PER_NODE;
if (sscanf(line, " %*s %*s %*s %d %d %s", &timeSet, &fileSet,
subLine) == 3)
{
this->VariableTimeSetIds->InsertNextId(timeSet);
this->VariableFileSetIds->InsertNextId(fileSet);
this->AddVariableDescription(subLine);
sscanf(line, " %*s %*s %*s %*d %*d %*s %s", subLine);
}
else if (sscanf(line, " %*s %*s %*s %d %s", &timeSet, subLine) == 2)
{
this->VariableTimeSetIds->InsertNextId(timeSet);
this->AddVariableDescription(subLine);
sscanf(line, " %*s %*s %*s %*d %*s %s", subLine);
}
else if (sscanf(line, " %*s %*s %*s %s", subLine) == 1)
{
this->VariableTimeSetIds->InsertNextId(1);
this->AddVariableDescription(subLine);
sscanf(line, " %*s %*s %*s %*s %s", subLine);
}
this->AddVariableType();
this->NumberOfVectorsPerNode++;
}
else if (strcmp(subLine, "element:") == 0)
{
vtkDebugMacro("vector per element");
this->VariableMode = vtkEnSightReader::VECTOR_PER_ELEMENT;
if (sscanf(line, " %*s %*s %*s %d %d %s", &timeSet, &fileSet,
subLine) == 3)
{
this->VariableTimeSetIds->InsertNextId(timeSet);
this->VariableFileSetIds->InsertNextId(fileSet);
this->AddVariableDescription(subLine);
sscanf(line, " %*s %*s %*s %*d %*d %*s %s", subLine);
}
else if (sscanf(line, " %*s %*s %*s %d %s", &timeSet, subLine) == 2)
{
this->VariableTimeSetIds->InsertNextId(timeSet);
this->AddVariableDescription(subLine);
sscanf(line, " %*s %*s %*s %*d %*s %s", subLine);
}
else if (sscanf(line, " %*s %*s %*s %s", subLine) == 1)
{
this->VariableTimeSetIds->InsertNextId(1);
this->AddVariableDescription(subLine);
sscanf(line, " %*s %*s %*s %*s %s", subLine);
}
this->AddVariableType();
this->NumberOfVectorsPerElement++;
}
else if (strcmp(subLine, "measured") == 0)
{
vtkDebugMacro("vector per measured node");
this->VariableMode = vtkEnSightReader::VECTOR_PER_MEASURED_NODE;
if (sscanf(line, " %*s %*s %*s %*s %d %d %s", &timeSet, &fileSet,
subLine) == 3)
{
this->VariableTimeSetIds->InsertNextId(timeSet);
this->VariableFileSetIds->InsertNextId(fileSet);
this->AddVariableDescription(subLine);
sscanf(line, " %*s %*s %*s %*s %*d %*d %*s %s", subLine);
}
else if (sscanf(line, " %*s %*s %*s %*s %d %s", &timeSet,
subLine) == 2)
{
this->VariableTimeSetIds->InsertNextId(timeSet);
this->AddVariableDescription(subLine);
sscanf(line, " %*s %*s %*s %*s %*d %*s %s", subLine);
}
else if (sscanf(line, " %*s %*s %*s %*s %s", subLine) == 1)
{
this->VariableTimeSetIds->InsertNextId(1);
this->AddVariableDescription(subLine);
sscanf(line, " %*s %*s %*s %*s %*s %s", subLine);
}
this->AddVariableType();
this->NumberOfVectorsPerMeasuredNode++;
}
this->AddVariableFileName(subLine);
this->NumberOfVariables++;
}
else if (strncmp(line, "tensor", 6) == 0)
{
// According to EnSight documentation tensor entry should be of the form:
// tensor symm per node/element
// but it seems like you can also find:
// tensor per node/element
// Let handle this case here:
char symm[10];
char per[10];
if( sscanf(line, " %*s %s %s %s", symm, per, subLine) != 3 )
{
vtkErrorMacro( "Error while reading: " << line );
}
if (!(strcmp(symm, "symm") == 0 && strcmp(per, "per") == 0))
{
if( sscanf(line, " %*s %s %s", per, subLine) != 2 )
{
vtkErrorMacro( "Error while reading: " << line );
}
if (strcmp(per, "per") == 0)
{
//Not valid file but seems alright, only 'symm' is missing
vtkWarningMacro( "Looks almost like a valid case file, continuing" );
}
else
{
vtkErrorMacro("Trouble reading: " << line );
}
}
if (strcmp(subLine, "node:") == 0)
{
vtkDebugMacro("tensor symm per node");
this->VariableMode = vtkEnSightReader::TENSOR_SYMM_PER_NODE;
if (sscanf(line, " %*s %*s %*s %*s %d %d %s", &timeSet, &fileSet,
subLine) == 3)
{
this->VariableTimeSetIds->InsertNextId(timeSet);
this->VariableFileSetIds->InsertNextId(fileSet);
this->AddVariableDescription(subLine);
sscanf(line, " %*s %*s %*s %*s %*d %*d %*s %s", subLine);
}
else if (sscanf(line, " %*s %*s %*s %*s %d %s", &timeSet,
subLine) == 2)
{
this->VariableTimeSetIds->InsertNextId(timeSet);
this->AddVariableDescription(subLine);
sscanf(line, " %*s %*s %*s %*s %*d %*s %s", subLine);
}
else if (sscanf(line, " %*s %*s %*s %*s %s", subLine) == 1)
{
this->VariableTimeSetIds->InsertNextId(1);
this->AddVariableDescription(subLine);
sscanf(line, " %*s %*s %*s %*s %*s %s", subLine);
}
this->AddVariableType();
this->NumberOfTensorsSymmPerNode++;
}
else if (strcmp(subLine, "element:") == 0)
{
vtkDebugMacro("tensor symm per element");
this->VariableMode = vtkEnSightReader::TENSOR_SYMM_PER_ELEMENT;
if (sscanf(line, " %*s %*s %*s %*s %d %d %s", &timeSet, &fileSet,
subLine) == 3)
{
this->VariableTimeSetIds->InsertNextId(timeSet);
this->VariableFileSetIds->InsertNextId(fileSet);
this->AddVariableDescription(subLine);
sscanf(line, " %*s %*s %*s %*s %*d %*d %*s %s", subLine);
}
else if (sscanf(line, " %*s %*s %*s %*s %d %s", &timeSet,
subLine) == 2)
{
this->VariableTimeSetIds->InsertNextId(timeSet);
this->AddVariableDescription(subLine);
sscanf(line, " %*s %*s %*s %*s %*d %*s %s", subLine);
}