File: vtkAvtFileFormatAlgorithm.cxx

package info (click to toggle)
paraview 4.0.1-1~bpo70%2B1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy-backports
  • size: 526,572 kB
  • sloc: cpp: 2,284,430; ansic: 816,374; python: 239,936; xml: 70,162; tcl: 48,295; fortran: 39,116; yacc: 5,466; java: 3,518; perl: 3,107; lex: 1,620; sh: 1,555; makefile: 932; asm: 471; pascal: 228
file content (950 lines) | stat: -rw-r--r-- 30,356 bytes parent folder | download | duplicates (2)
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
/*=========================================================================

   Program: ParaView
   Module:    vtkAvtFileFormatAlgorithm.cxx

   Copyright (c) 2005,2006 Sandia Corporation, Kitware Inc.
   All rights reserved.

   ParaView is a free software; you can redistribute it and/or modify it
   under the terms of the ParaView license version 1.2.

   See License_v1.2.txt for the full ParaView license.
   A copy of this license can be obtained by contacting
   Kitware Inc.
   28 Corporate Drive
   Clifton Park, NY 12065
   USA

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

========================================================================*/
#include "vtkAvtFileFormatAlgorithm.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkObjectFactory.h"
#include "vtkMultiBlockDataSet.h"
#include "vtkStreamingDemandDrivenPipeline.h"
#include "vtkCompositeDataPipeline.h"
#include "vtkSmartPointer.h"
#include "vtkCompositeDataSet.h"

#include "vtkCallbackCommand.h"
#include "vtkDataArraySelection.h"

#include "vtkDataSet.h"

#include "vtkCellData.h"
#include "vtkFieldData.h"
#include "vtkPointData.h"
#include "vtkFloatArray.h"

#include "avtDatabaseMetaData.h"
#include "avtDomainNesting.h"
#include "avtFileFormat.h"
#include "avtIntervalTree.h"
#include "avtMaterial.h"
#include "avtMaterialMetaData.h"
#include "avtScalarMetaData.h"
#include "avtSpatialBoxSelection.h"
#include "avtVariableCache.h"
#include "avtVectorMetaData.h"
#include "TimingsManager.h"

#include "limits.h"

vtkStandardNewMacro(vtkAvtFileFormatAlgorithm);

//-----------------------------------------------------------------------------
vtkAvtFileFormatAlgorithm::vtkAvtFileFormatAlgorithm()
{
  this->SetNumberOfInputPorts(0);
  this->SetNumberOfOutputPorts(1);

  this->AvtFile = NULL;
  this->MetaData = NULL;
  this->Cache = NULL;

  this->PointDataArraySelection = vtkDataArraySelection::New();
  this->CellDataArraySelection = vtkDataArraySelection::New();
  this->MeshArraySelection = vtkDataArraySelection::New();
  this->MaterialArraySelection = vtkDataArraySelection::New();

  // Setup the selection callback to modify this object when an array
  // selection is changed.
  this->SelectionObserver = vtkCallbackCommand::New();
  this->SelectionObserver->SetCallback(&
    vtkAvtFileFormatAlgorithm::SelectionModifiedCallback);
  this->SelectionObserver->SetClientData(this);
  this->PointDataArraySelection->AddObserver(vtkCommand::ModifiedEvent,
                                             this->SelectionObserver);
  this->CellDataArraySelection->AddObserver(vtkCommand::ModifiedEvent,
                                            this->SelectionObserver);
  this->MeshArraySelection->AddObserver(vtkCommand::ModifiedEvent,
                                            this->SelectionObserver);
  this->MaterialArraySelection->AddObserver(vtkCommand::ModifiedEvent,
                                            this->SelectionObserver);

  //visit has this horrible singelton timer that is called in all algorithms
  //we need to initiailize it, and than disable it
  if ( !visitTimer )
    {
    TimingsManager::Initialize("");
    visitTimer->Disable();
    }
}

//-----------------------------------------------------------------------------
vtkAvtFileFormatAlgorithm::~vtkAvtFileFormatAlgorithm()
{
  this->CleanupAVTReader();

  this->CellDataArraySelection->RemoveObserver(this->SelectionObserver);
  this->PointDataArraySelection->RemoveObserver(this->SelectionObserver);
  this->MeshArraySelection->RemoveObserver(this->SelectionObserver);
  this->MaterialArraySelection->RemoveObserver(this->SelectionObserver);

  this->SelectionObserver->Delete();
  this->CellDataArraySelection->Delete();
  this->PointDataArraySelection->Delete();
  this->MeshArraySelection->Delete();
  this->MaterialArraySelection->Delete();
}

//-----------------------------------------------------------------------------
bool vtkAvtFileFormatAlgorithm::InitializeAVTReader( const int &timestep )
{
  return false;
}

//-----------------------------------------------------------------------------
void vtkAvtFileFormatAlgorithm::CleanupAVTReader()
{
  if ( this->AvtFile )
    {
    this->AvtFile->FreeUpResources();
    delete this->AvtFile;
    this->AvtFile = NULL;
    }

  if ( this->MetaData )
    {
    delete this->MetaData;
    this->MetaData = NULL;
    }

  if ( this->Cache )
    {
    delete this->Cache;
    this->Cache = NULL;
    }
}

//----------------------------------------------------------------------------
int vtkAvtFileFormatAlgorithm::ProcessRequest(vtkInformation* request,
                                         vtkInformationVector** inputVector,
                                         vtkInformationVector* outputVector)
{
  // generate the needed data for each time step
  // to handle domain level piece loading
  if(request->Has(
  vtkStreamingDemandDrivenPipeline::REQUEST_UPDATE_EXTENT_INFORMATION()))
    {
    vtkInformation *outInfo = outputVector->GetInformationObject(0);
    this->SetupBlockBoundsInformation(outInfo);
    }

  return this->Superclass::ProcessRequest(request, inputVector, outputVector);
}


//-----------------------------------------------------------------------------
int vtkAvtFileFormatAlgorithm::RequestInformation(vtkInformation *request,
    vtkInformationVector **inputVector, vtkInformationVector *outputVector)
{
  if (!this->InitializeAVTReader())
    {
    return 0;
    }
  vtkInformation *outInfo = outputVector->GetInformationObject(0);

  if ( this->MetaData->GetNumMeshes() > 0 )
    {
    int maxPieces = (this->MetaData->GetMeshes(0).numBlocks > 1)?
      -1:1;
    //only MD classes have blocks inside a mesh, and therefore
    //we can use that to determine if we support reading on each processor
    outInfo->Set(vtkStreamingDemandDrivenPipeline::MAXIMUM_NUMBER_OF_PIECES(),
      maxPieces);
    }

  //Set up ghost levels

  //setup user selection of meshes to load
  this->SetupMeshSelections();
  //setup user selection of arrays to load
  this->SetupDataArraySelections();

  //setup the materials that are on all the meshes
  this->SetupMaterialSelections();

  //setup the timestep and cylce info
  this->SetupTemporalInformation(outInfo);

  return 1;
}


//-----------------------------------------------------------------------------
int vtkAvtFileFormatAlgorithm::RequestData(vtkInformation *request,
    vtkInformationVector **inputVector, vtkInformationVector *outputVector)
{
  return 1;
}

//-----------------------------------------------------------------------------
int vtkAvtFileFormatAlgorithm::RequestUpdateExtent(vtkInformation *request,
    vtkInformationVector **inputVector, vtkInformationVector *outputVector)
{
  return 1;
}

//-----------------------------------------------------------------------------
int vtkAvtFileFormatAlgorithm::FillOutputPortInformation(int, vtkInformation *info)
{
  info->Set(vtkDataObject::DATA_TYPE_NAME(), "vtkDataObject");
  return 1;
}


//-----------------------------------------------------------------------------
void vtkAvtFileFormatAlgorithm::AssignProperties( vtkDataSet *data,
    const vtkStdString &meshName, const int &timestep, const int &domain)
{
  int size = this->MetaData->GetNumScalars();
  for ( int i=0; i < size; ++i)
    {
    const avtScalarMetaData scalarMeta = this->MetaData->GetScalars(i);
    if ( meshName != scalarMeta.meshName )
      {
      //this mesh doesn't have this scalar property, go to next
      continue;
      }

    std::string name = scalarMeta.name;

    //now check against what arrays the user has selected to load
    bool selected = false;
    if (scalarMeta.centering == AVT_ZONECENT)
      {
      //cell array
      selected = this->GetCellArrayStatus(name.c_str());
      }
    else if (scalarMeta.centering == AVT_NODECENT)
      {
      //point array
      selected = this->GetPointArrayStatus(name.c_str());
      }
    if (!selected)
      {
      //don't add the array since the user hasn't selected it
      continue;
      }

    //some readers will throw exceptions when they can't find
    //the file containing properties, so we have to ignore that property
    vtkDataArray *scalar = NULL;
    CATCH_VISIT_EXCEPTIONS(scalar,
      this->AvtFile->GetVar(timestep,domain,name.c_str()));
    if ( !scalar )
      {
      //it seems that we had a bad array for this domain
      continue;
      }

    //update the vtkDataArray to have the name, since GetVar doesn't require
    //placing a name on the returned array
    scalar->SetName( name.c_str() );

    //based on the centering we go determine if this is cell or point based
    switch(scalarMeta.centering)
      {
      case AVT_ZONECENT:
        //cell property
        data->GetCellData()->AddArray( scalar );
        break;
      case AVT_NODECENT:
        //point based
        data->GetPointData()->AddArray( scalar );
        break;
      case AVT_NO_VARIABLE:
      case AVT_UNKNOWN_CENT:
      default:
        break;
      }
    scalar->Delete();
    }

  //now do vector properties
  size = this->MetaData->GetNumVectors();
  for ( int i=0; i < size; ++i)
    {
    const avtVectorMetaData vectorMeta = this->MetaData->GetVectors(i);
    if ( meshName != vectorMeta.meshName )
      {
      //this mesh doesn't have this vector property, go to next
      continue;
      }
    std::string name = vectorMeta.name;

    //now check agianst what arrays the user has selected to load
    bool selected = false;
    if (vectorMeta.centering == AVT_ZONECENT)
      {
      //cell array
      selected = this->GetCellArrayStatus(name.c_str());
      }
    else if (vectorMeta.centering == AVT_NODECENT)
      {
      //point array
      selected = this->GetPointArrayStatus(name.c_str());
      }
    if (!selected)
      {
      //don't add the array since the user hasn't selected it
      continue;
      }

    vtkDataArray *vector = NULL;
    CATCH_VISIT_EXCEPTIONS(vector,
      this->AvtFile->GetVectorVar(timestep,domain,name.c_str()));
    if ( !vector )
      {
      //it seems that we had a bad array for this domain
      continue;
      }

    //update the vtkDataArray to have the name, since GetVar doesn't require
    //placing a name on the returned array
    vector->SetName( name.c_str() );

    //based on the centering we go determine if this is cell or point based
    switch(vectorMeta.centering)
      {
      case AVT_ZONECENT:
        //cell property
        data->GetCellData()->AddArray( vector );
        break;
      case AVT_NODECENT:
        //point based
        data->GetPointData()->AddArray( vector );
        break;
      case AVT_NO_VARIABLE:
      case AVT_UNKNOWN_CENT:
        break;
      }
    vector->Delete();
    }

  //now call the materials
  this->AssignMaterials( data, meshName, timestep, domain);
}

//-----------------------------------------------------------------------------
void vtkAvtFileFormatAlgorithm::AssignMaterials( vtkDataSet *data,
  const vtkStdString &meshName, const int &timestep, const int &domain )
{
  //now we check for materials
  int size = this->MetaData->GetNumMaterials();
  void_ref_ptr vr;
  avtMaterial *material = NULL;
  for ( int i=0; i < size; ++i)
    {
    const avtMaterialMetaData* materialMetaData = this->MetaData->GetMaterial(i);
    if ( meshName != materialMetaData->meshName )
      {
      continue;
      }

    std::string name = materialMetaData->name;
    //lets first try and see if the data has been cached
    //get the aux data from the cache for the material
    vr = this->Cache->GetVoidRef(name.c_str(),
                    AUXILIARY_DATA_MATERIAL, timestep, domain);
    material = reinterpret_cast<avtMaterial*>(*vr);
    if ( !material)
      {
      //data wasn't cached! time to ask dataset itself
      DestructorFunction df;
      void* ref = this->AvtFile->GetAuxiliaryData(name.c_str(),timestep,domain,
        AUXILIARY_DATA_MATERIAL,NULL,df);
      if ( !ref )
        {
        continue;
        }

      //add the material to the cache
      vr = void_ref_ptr(ref,df);
      this->Cache->CacheVoidRef(name.c_str(),AUXILIARY_DATA_MATERIAL, timestep, domain, vr );
      material = reinterpret_cast<avtMaterial*>(*vr);
      if ( !material)
        {
        continue;
        }
      }

    //decompose the material class into a collection of float arrays
    //that we will than push into vtkFloatArrays and place on the dataset
    int numCells = material->GetNZones();
    int mats = material->GetNMaterials();
    float** materials = new float*[mats];
    for ( int i=0; i < mats; ++i)
      {
      materials[i] = new float[numCells];
      for ( int j=0; j < numCells; ++j)
        {
        materials[i][j] = -1.0;
        }
      }

    const int *matlist = material->GetMatlist();
    const int *mixMat = material->GetMixMat();
    const int *mixNext = material->GetMixNext();
    const float *mixValues = material->GetMixVF();
    for ( int i=0; i < numCells; ++i)
      {
      if ( matlist[i] >= 0 )
        {
        //this material is pure
        materials[matlist[i]][i] = 1.0;
        }
      else
        {
        float sum = 0.0;
        int lookupIndex = (matlist[i]+1) * -1;
        while ( sum < 1.0 )
          {
          materials[mixMat[lookupIndex]][i] = mixValues[lookupIndex];
          sum += mixValues[lookupIndex];
          if ( mixNext[lookupIndex] == 0 )
            {
            //just in case a material doesn't sum up to 100
            break;
            }
          lookupIndex = mixNext[lookupIndex]-1;
          }
        }
      }

    //we now have all our arrays loaded with the material mixtures
    //time to pass them to vtk
    stringVector mNames = materialMetaData->materialNames;
    for ( int i=0; i < mNames.size(); ++i)
      {
      //TODO: change this so that we check selection enabled before we
      //decompose the avtMaterial class
      if ( this->MaterialArraySelection->ArrayIsEnabled(mNames.at(i).c_str()) )
        {
        vtkFloatArray* tempMaterial = vtkFloatArray::New();
        tempMaterial->SetName( mNames.at(i).c_str() );
        tempMaterial->SetArray(materials[i],numCells,0);
        data->GetCellData()->AddArray( tempMaterial );
        tempMaterial->Delete();
        }
      }
    }
}

//-----------------------------------------------------------------------------
void vtkAvtFileFormatAlgorithm::SetupBlockBoundsInformation(
  vtkInformation *outInfo)
{
  //this allows the VisIt Readers to support individual
  //domain and block loading
  vtkSmartPointer<vtkMultiBlockDataSet> metadata =
      vtkSmartPointer<vtkMultiBlockDataSet>::New();

  unsigned int index = 0; //converting the multiblock to a flat index

  int size = this->MetaData->GetNumMeshes();
  int timeStep = this->GetCurrentTimeStep(outInfo);
  for ( int i=0; i < size; ++i)
    {
    const avtMeshMetaData *meshMetaData = this->MetaData->GetMesh(i);

    int numBlocks = meshMetaData->numBlocks;

    //setup the block that represents this mesh
    vtkMultiBlockDataSet* childDS = vtkMultiBlockDataSet::New();
    childDS->SetNumberOfBlocks(numBlocks);
    metadata->SetBlock(i,childDS);
    childDS->FastDelete();

    //setup the bounding box for each domain in this block
    for ( int dom=0; dom < numBlocks; ++dom )
      {

      //create the block for this domain
      childDS->SetBlock(dom,NULL);
      vtkInformation* piece_metadata = childDS->GetMetaData(dom);

      double bounds[6] = {0.0,0.0,0.0,0.0,0.0,0.0};
      bool valid =
        this->GetDataSpatialExtents(meshMetaData->name.c_str(),
        timeStep, dom, bounds);
      if ( valid )
        {
        piece_metadata->Set(
        vtkStreamingDemandDrivenPipeline::PIECE_BOUNDING_BOX(),bounds,6);
        }
      ++index;
      }
    }

  outInfo->Set(vtkCompositeDataPipeline::COMPOSITE_DATA_META_DATA(),
            metadata);
}

//-----------------------------------------------------------------------------
bool vtkAvtFileFormatAlgorithm::GetDataSpatialExtents(const char* meshName,
    const int &timestep, const int &domain, double bounds[6])
{
    void_ref_ptr vr = this->Cache->GetVoidRef(meshName,
                  AUXILIARY_DATA_SPATIAL_EXTENTS, timestep, domain);
    if (!(*vr))
      {
      //the specfic domain failed, try the global size for the timestep
      void_ref_ptr vr = this->Cache->GetVoidRef(meshName,
        AUXILIARY_DATA_SPATIAL_EXTENTS, timestep, -1);
      }
    if (!(*vr))
      {
      //the specfic timestep failed, try the gloabl extent
      void_ref_ptr vr = this->Cache->GetVoidRef(meshName,
        AUXILIARY_DATA_SPATIAL_EXTENTS, -1, -1);
      }
    if (!(*vr))
      {
      //everything failed we don't have information!
      return false;
      }
    avtIntervalTree *tree = NULL;
    tree = reinterpret_cast<avtIntervalTree*>(*vr);
    if ( tree )
      {
      tree->GetExtents(bounds);
      return true;
      }
  }

//-----------------------------------------------------------------------------
void vtkAvtFileFormatAlgorithm::CreateAVTDataSelections()
{
  //by default the box selection is a box from FLT MIN to FLT MAX so
  //we will be asking the reader to load everything in.
  avtSpatialBoxSelection* selectWholeMesh = new avtSpatialBoxSelection();

  std::vector<avtDataSelection_p> selections;
  selections.push_back(selectWholeMesh);

  std::vector<bool> selectionResults(selections.size());

  this->AvtFile->RegisterDataSelections(selections,&selectionResults);
}

//-----------------------------------------------------------------------------
unsigned int vtkAvtFileFormatAlgorithm::GetCurrentTimeStep(vtkInformation *outInfo)
{
  int tsLength =
    outInfo->Length(vtkStreamingDemandDrivenPipeline::TIME_STEPS());
  double* steps =
    outInfo->Get(vtkStreamingDemandDrivenPipeline::TIME_STEPS());

  unsigned int TimeIndex = 0;
  // Check if a particular time was requested by the pipeline.
  // This overrides the ivar.
  if(outInfo->Has(vtkStreamingDemandDrivenPipeline::UPDATE_TIME_STEP()) && tsLength>0)
    {
    // Get the requested time step. We only supprt requests of a single time
    // step in this reader right now
    double requestedTimeStep =
      outInfo->Get(vtkStreamingDemandDrivenPipeline::UPDATE_TIME_STEP());

    // find the first time value larger than requested time value
    // this logic could be improved
    while (TimeIndex < tsLength-1 && steps[TimeIndex] < requestedTimeStep)
      {
      TimeIndex++;
      }
    }
  return TimeIndex;
}

//-----------------------------------------------------------------------------
void vtkAvtFileFormatAlgorithm::SetupTemporalInformation(
  vtkInformation *outInfo)
{

  int numTimeValues;
  double timeRange[2];
  std::vector< double > timesteps;
  std::vector< int > cycles;

  try
    {
    this->AvtFile->FormatGetTimes( timesteps );
    this->AvtFile->FormatGetCycles( cycles );
    }
  catch(...)
    {
    //unable to get time or cycles
    return;
    }

  bool hasTime = timesteps.size() > 0;
  bool hasCycles = cycles.size() > 0;
  bool hasTimeAndCycles = hasTime && hasCycles;

  //in some case the times and cycles have all zero values.
  //This is caused by a file reader that generates the time value
  //once the reader moves to that timestep.
  //That kind of behaviour is not possible currently in ParaView. Instead
  //we will force the reader to generate the time values for each timestep
  //by cycling through everytime step but not requesting any data.
  if(hasTime && timesteps[0] == timesteps[timesteps.size()-1])
    {
    //FormatGetTimes expect the timesteps vector that is passed
    //in has an empty size. If you use the timesteps variable
    //readers will push_back values causing an infinte loop or
    //duplicate time steps
    std::vector< double > newTimesSteps;

    //we have hit a timestep range that needs to be cycled
    //we use a const size variable so
    const std::size_t size = timesteps.size();
    for(int i=0; i < size;++i)
      {
      this->ActivateTimestep(i);
      //Nek and other readers don't update the time info intill you
      //call gettimes.
      this->AvtFile->FormatGetTimes(newTimesSteps);
      }

    //use the updated timestep values
    timesteps = newTimesSteps;
    }


  //need to figure out the use case of when cycles and timesteps don't match
  if (hasTimeAndCycles && timesteps.size()==cycles.size() )
    {
    //presume that timesteps and cycles are just duplicates of each other
    numTimeValues = static_cast<int>(timesteps.size());
    outInfo->Set(vtkStreamingDemandDrivenPipeline::TIME_STEPS(),
      &timesteps[0],numTimeValues);
    timeRange[0] = timesteps[0];
    timeRange[1] = timesteps[numTimeValues-1];
    outInfo->Set(vtkStreamingDemandDrivenPipeline::TIME_RANGE(),
      timeRange, 2);
    }
  else if( hasTime )
    {
    numTimeValues = static_cast<int>(timesteps.size());

    outInfo->Set(vtkStreamingDemandDrivenPipeline::TIME_STEPS(),
      &timesteps[0],numTimeValues);
    timeRange[0] = timesteps[0];
    timeRange[1] = timesteps[numTimeValues-1];
    outInfo->Set(vtkStreamingDemandDrivenPipeline::TIME_RANGE(),
      timeRange, 2);
    }
  else if( hasCycles )
    {
    //convert the cycles over to time steps now
    for ( unsigned int i=0; i < cycles.size(); ++i)
      {
      timesteps.push_back( static_cast<double>(cycles[i]) );
      }

    numTimeValues = static_cast<int>(timesteps.size());

    outInfo->Set(vtkStreamingDemandDrivenPipeline::TIME_STEPS(),
      &timesteps[0],numTimeValues);
    timeRange[0] = timesteps[0];
    timeRange[1] = timesteps[numTimeValues-1];
    outInfo->Set(vtkStreamingDemandDrivenPipeline::TIME_RANGE(),
      timeRange, 2);
    }
}

//-----------------------------------------------------------------------------
void vtkAvtFileFormatAlgorithm::SetupDataArraySelections( )
{
  if (!this->MetaData)
    {
    return;
    }
  //go through the meta data and get all the scalar and vector property names
  //add them to the point & cell selection arrays for user control if they don't already exist
  //by default all properties are disabled
  int size = this->MetaData->GetNumScalars();
  std::string name;
  for ( int i=0; i < size; ++i)
    {
    const avtScalarMetaData scalarMetaData = this->MetaData->GetScalars(i);
    name = scalarMetaData.name;
    switch(scalarMetaData.centering)
      {
      case AVT_ZONECENT:
        //cell property
        if (!this->CellDataArraySelection->ArrayExists(name.c_str()))
          {
          this->CellDataArraySelection->DisableArray(name.c_str());
          }
        break;
      case AVT_NODECENT:
        //point based
        if (!this->PointDataArraySelection->ArrayExists(name.c_str()))
          {
          this->PointDataArraySelection->DisableArray(name.c_str());
          }
        break;
      case AVT_NO_VARIABLE:
      case AVT_UNKNOWN_CENT:
        break;
      }

    }

  size = this->MetaData->GetNumVectors();
  for ( int i=0; i < size; ++i)
    {
    const avtVectorMetaData vectorMetaData = this->MetaData->GetVectors(i);
    name = vectorMetaData.name;
    switch(vectorMetaData.centering)
      {
      case AVT_ZONECENT:
        //cell property
        if (!this->CellDataArraySelection->ArrayExists(name.c_str()))
          {
          this->CellDataArraySelection->DisableArray(name.c_str());
          }
        break;
      case AVT_NODECENT:
        //point based
        if (!this->PointDataArraySelection->ArrayExists(name.c_str()))
          {
          this->PointDataArraySelection->DisableArray(name.c_str());
          }
        break;
      case AVT_NO_VARIABLE:
      case AVT_UNKNOWN_CENT:
        break;
      }
    }
}

//-----------------------------------------------------------------------------
void vtkAvtFileFormatAlgorithm::SetupMeshSelections( )
{
  if (!this->MetaData)
    {
    return;
    }
  //go through the meta data and get all the mesh names
  //by default all meshes are disabled but the first one
  int size = this->MetaData->GetNumMeshes();
  std::string name;
  for ( int i=0; i < size; ++i)
    {
    const avtMeshMetaData *meshMetaData = this->MetaData->GetMesh(i);
    name = meshMetaData->name;
    if ( i == 0 && !this->MeshArraySelection->ArrayExists(name.c_str()))
      {
      this->MeshArraySelection->EnableArray(name.c_str());
      }
    else if (!this->MeshArraySelection->ArrayExists(name.c_str()))
      {
      this->MeshArraySelection->DisableArray(name.c_str());
      }
    }
}


//-----------------------------------------------------------------------------
void vtkAvtFileFormatAlgorithm::SetupMaterialSelections()
{
  if (!this->MetaData)
    {
    return;
    }
  //go through the meta data and get all the material names
  int size = this->MetaData->GetNumMaterials();
  std::string name;
  for ( int i=0; i < size; ++i)
    {
    const avtMaterialMetaData* matMetaData = this->MetaData->GetMaterial(i);
    //we are going to decompose the material into a separate array for each
    //component in the material collection.
    stringVector materials = matMetaData->materialNames;
    for ( int j=0; j < materials.size(); ++j )
      {
      name = materials.at(j);
      if (!this->MaterialArraySelection->ArrayExists(name.c_str()))
        {
        this->MaterialArraySelection->DisableArray(name.c_str());
        }
      }
    }
}

//----------------------------------------------------------------------------
int vtkAvtFileFormatAlgorithm::GetNumberOfPointArrays()
{
  return this->PointDataArraySelection->GetNumberOfArrays();
}

//----------------------------------------------------------------------------
const char* vtkAvtFileFormatAlgorithm::GetPointArrayName(int index)
{
  return this->PointDataArraySelection->GetArrayName(index);
}

//----------------------------------------------------------------------------
int vtkAvtFileFormatAlgorithm::GetPointArrayStatus(const char* name)
{
  return this->PointDataArraySelection->ArrayIsEnabled(name);
}

//----------------------------------------------------------------------------
void vtkAvtFileFormatAlgorithm::SetPointArrayStatus(const char* name, int status)
{
  if(status)
    {
    this->PointDataArraySelection->EnableArray(name);
    }
  else
    {
    this->PointDataArraySelection->DisableArray(name);
    }
}

//----------------------------------------------------------------------------
int vtkAvtFileFormatAlgorithm::GetNumberOfCellArrays()
{
  return this->CellDataArraySelection->GetNumberOfArrays();
}

//----------------------------------------------------------------------------
const char* vtkAvtFileFormatAlgorithm::GetCellArrayName(int index)
{
  return this->CellDataArraySelection->GetArrayName(index);
}

//----------------------------------------------------------------------------
int vtkAvtFileFormatAlgorithm::GetCellArrayStatus(const char* name)
{
  return this->CellDataArraySelection->ArrayIsEnabled(name);
}

//----------------------------------------------------------------------------
void vtkAvtFileFormatAlgorithm::SetCellArrayStatus(const char* name, int status)
{
  if(status)
    {
    this->CellDataArraySelection->EnableArray(name);
    }
  else
    {
    this->CellDataArraySelection->DisableArray(name);
    }
}

//----------------------------------------------------------------------------
int vtkAvtFileFormatAlgorithm::GetNumberOfMeshArrays()
{
  return this->MeshArraySelection->GetNumberOfArrays();
}

//----------------------------------------------------------------------------
const char* vtkAvtFileFormatAlgorithm::GetMeshArrayName(int index)
{
  return this->MeshArraySelection->GetArrayName(index);
}

//----------------------------------------------------------------------------
int vtkAvtFileFormatAlgorithm::GetMeshArrayStatus(const char* name)
{
  return this->MeshArraySelection->ArrayIsEnabled(name);
}

//----------------------------------------------------------------------------
void vtkAvtFileFormatAlgorithm::SetMeshArrayStatus(const char* name, int status)
{
  if(status)
    {
    this->MeshArraySelection->EnableArray(name);
    }
  else
    {
    this->MeshArraySelection->DisableArray(name);
    }
}

//----------------------------------------------------------------------------
int vtkAvtFileFormatAlgorithm::GetNumberOfMaterialArrays()
{
  return this->MaterialArraySelection->GetNumberOfArrays();
}

//----------------------------------------------------------------------------
const char* vtkAvtFileFormatAlgorithm::GetMaterialArrayName(int index)
{
  return this->MaterialArraySelection->GetArrayName(index);
}

//----------------------------------------------------------------------------
int vtkAvtFileFormatAlgorithm::GetMaterialArrayStatus(const char* name)
{
  return this->MaterialArraySelection->ArrayIsEnabled(name);
}

//----------------------------------------------------------------------------
void vtkAvtFileFormatAlgorithm::SetMaterialArrayStatus(const char* name, int status)
{
  if(status)
    {
    this->MaterialArraySelection->EnableArray(name);
    }
  else
    {
    this->MaterialArraySelection->DisableArray(name);
    }
}

//----------------------------------------------------------------------------
void vtkAvtFileFormatAlgorithm::SelectionModifiedCallback(vtkObject*, unsigned long,
                                             void* clientdata, void*)
{
  static_cast<vtkAvtFileFormatAlgorithm*>(clientdata)->Modified();
}


//-----------------------------------------------------------------------------
void vtkAvtFileFormatAlgorithm::PrintSelf(ostream& os, vtkIndent indent)
{
  this->Superclass::PrintSelf(os, indent);
   os << indent << "Output Type: " << this->OutputType << "\n";
}