From 790115cf8e0f526c9717a2a333f4db04d649054e Mon Sep 17 00:00:00 2001
From: Berk Geveci <berk.geveci@kitware.com>
Date: Tue, 28 Jan 2014 10:59:27 -0500
Subject: [PATCH] Removed unused code from vtkModelMetaData and vtkExodusModel

Exodus readers and writers no longer support packing and unpacking
of model meta data so I removed all of the unnecessary code.

Change-Id: Iae190a9d5ca7b10ab128728a60918602bf809ed1
---
 IO/Exodus/vtkExodusIIReader.cxx |    4 +-
 IO/Exodus/vtkExodusIIReader.h   |   14 +-
 IO/Exodus/vtkExodusModel.cxx    |   70 -
 IO/Exodus/vtkExodusModel.h      |   47 -
 IO/Exodus/vtkModelMetadata.cxx  | 2745 +++----------------------------
 IO/Exodus/vtkModelMetadata.h    |  105 +-
 6 files changed, 263 insertions(+), 2722 deletions(-)

diff --git a/IO/Exodus/vtkExodusIIReader.cxx b/IO/Exodus/vtkExodusIIReader.cxx
index f5158506b2a..2e688939584 100644
--- a/IO/Exodus/vtkExodusIIReader.cxx
+++ b/IO/Exodus/vtkExodusIIReader.cxx
@@ -3470,7 +3470,7 @@ void vtkExodusIIReader::PrintSelf( ostream& os, vtkIndent indent )
   os << indent << "TimeStep: " << this->TimeStep << "\n";
   os << indent << "TimeStepRange: [" << this->TimeStepRange[0] << ", " << this->TimeStepRange[1] << "]\n";
   os << indent << "ExodusModelMetadata: " << (this->ExodusModelMetadata ? "ON" : "OFF" ) << "\n";
-  os << indent << "PackExodusModelOntoOutput: " << (this->PackExodusModelOntoOutput ? "ON" : "OFF" ) << "\n";
+  // os << indent << "PackExodusModelOntoOutput: " << (this->PackExodusModelOntoOutput ? "ON" : "OFF" ) << "\n";
   os << indent << "ExodusModel: " << this->ExodusModel << "\n";
   os << indent << "SILUpdateStamp: " << this->SILUpdateStamp << "\n";
   os << indent << "ProducedFastPathOutput: " << this->ProducedFastPathOutput << "\n";
@@ -5004,7 +5004,7 @@ vtkExodusIIReader::vtkExodusIIReader()
   this->TimeStepRange[0] = 0;
   this->TimeStepRange[1] = 0;
   this->ExodusModelMetadata = 0;
-  this->PackExodusModelOntoOutput = 1;
+  // this->PackExodusModelOntoOutput = 1;
   this->ExodusModel = 0;
   this->DisplayType = 0;
   this->SILUpdateStamp = -1;
diff --git a/IO/Exodus/vtkExodusIIReader.h b/IO/Exodus/vtkExodusIIReader.h
index 8e9df43b90a..4ea643d70b6 100644
--- a/IO/Exodus/vtkExodusIIReader.h
+++ b/IO/Exodus/vtkExodusIIReader.h
@@ -423,18 +423,6 @@ public:
   //   Returns the object which encapsulates the model metadata.
   vtkGetObjectMacro(ExodusModel,vtkExodusModel);
 
-  // Description:
-  //  By default, the ExodusModel metadata (if requested with
-  //  ExodusModelMetadataOn()) is also encoded into field arrays
-  //  and attached to the output unstructured grid.  Set this OFF
-  //  if you don't want this to happen.  (The vtkExodusIIWriter and
-  //  the vtkEnSightWriter can unpack this metadata from the field
-  //  arrays and use it when writing out Exodus or EnSight files.)
-
-  vtkSetMacro(PackExodusModelOntoOutput, int);
-  vtkGetMacro(PackExodusModelOntoOutput, int);
-  vtkBooleanMacro(PackExodusModelOntoOutput, int);
-
   // Descriptions:
   // return boolean indicating whether the type,name is a valid variable
   int IsValidVariable( const char *type, const char *name );
@@ -805,7 +793,7 @@ protected:
   vtkExodusIIReaderPrivate* Metadata;
 
   vtkExodusModel *ExodusModel;
-  int PackExodusModelOntoOutput;
+  // int PackExodusModelOntoOutput;
   int ExodusModelMetadata;
 
   int SILUpdateStamp;
diff --git a/IO/Exodus/vtkExodusModel.cxx b/IO/Exodus/vtkExodusModel.cxx
index a5d6e082cee..c1b510cb807 100644
--- a/IO/Exodus/vtkExodusModel.cxx
+++ b/IO/Exodus/vtkExodusModel.cxx
@@ -83,44 +83,6 @@ void vtkExodusModel::SetModelMetadata(vtkModelMetadata *emd)
     }
 }
 
-//---------------------------------------------------------------
-// Initialize this ExodusModel object with the ExodusModel
-// packed into a vtkUnstructuredGrid's field arrays.
-//---------------------------------------------------------------
-
-int vtkExodusModel::HasMetadata(vtkUnstructuredGrid *grid)
-{
-  int hasIt = 0;
-
-  if (grid)
-    {
-    hasIt = vtkModelMetadata::HasMetadata(grid);
-    }
-
-  return hasIt;
-}
-int vtkExodusModel::UnpackExodusModel(vtkUnstructuredGrid *grid, int deleteIt)
-{
-  vtkModelMetadata *mmd = this->GetModelMetadata();
-
-  int fail = mmd->Unpack(grid, deleteIt);
-
-  return fail;
-}
-
-//---------------------------------------------------------------
-// Pack the metadata in this ExodusModel object into the
-// supplied vtkUnstructuredGrid.
-//---------------------------------------------------------------
-
-void vtkExodusModel::PackExodusModel(vtkUnstructuredGrid *grid)
-{
-  vtkModelMetadata *mmd = this->GetModelMetadata();
-
-  mmd->Pack(grid);
-
-  return;
-}
 //---------------------------------------------------------------
 // Set all the global fields of the Exodus Model from an open
 // Exodus file.
@@ -1143,39 +1105,7 @@ int vtkExodusModel::SetLocalSideSetInformation(
 
   return 0;
 }
-//-------------------------------------------------
-// Merge an ExodusModel into this one
-//-------------------------------------------------
-int vtkExodusModel::MergeExodusModel(vtkExodusModel *em)
-{
-  vtkModelMetadata *myMmd = this->GetModelMetadata();
-
-  vtkModelMetadata *newmd = em->GetModelMetadata();
-
-  int fail = myMmd->MergeModelMetadata(newmd);
-
-  return (fail != 0);
-}
-vtkExodusModel *vtkExodusModel::ExtractExodusModel(vtkIdTypeArray *globalCellIdList,
-                                                   vtkUnstructuredGrid *grid)
-{
-  vtkExodusModel *em = vtkExodusModel::New();
-
-  vtkModelMetadata *mmd = this->GetModelMetadata()->ExtractModelMetadata(
-    globalCellIdList, grid);
 
-  if (mmd == NULL)
-    {
-    em->Delete();
-    em = NULL;
-    }
-  else
-    {
-    em->SetModelMetadata(mmd);
-    }
-
-  return em;
-}
 //-------------------------------------------------
 // Element variables
 //-------------------------------------------------
diff --git a/IO/Exodus/vtkExodusModel.h b/IO/Exodus/vtkExodusModel.h
index ec18be7f65b..2c24ab91900 100644
--- a/IO/Exodus/vtkExodusModel.h
+++ b/IO/Exodus/vtkExodusModel.h
@@ -129,59 +129,12 @@ public:
   int SetLocalInformation(vtkUnstructuredGrid *ugrid,
         int fid, int timeStep, int newGeometry, int compute_word_size);
 
-  // Description:
-  //   Static function that returns 1 if the vtkUnstructuredGrid
-  //   has metadata packed into it's field arrays, 0 otherwise.
-
-  static int HasMetadata(vtkUnstructuredGrid *grid);
-
   // Description:
   //   Set or get the underlying vtkModelMetadata object.
 
   vtkModelMetadata *GetModelMetadata();
   void SetModelMetadata(vtkModelMetadata *emData);
 
-  // Description:
-  //    One way to initialize an ExodusModel object is to use
-  //    SetGlobalInformation, SetLocalInformation, and the Add/Remove
-  //    Variable calls to initialize it from an open Exodus file.
-  //
-  //    Another way is to initialize it with the ExodusModel which
-  //    has been packed into field arrays of a vtkUnstructuredGrid.
-  //    Set the second argument to 1 if you would like the packed
-  //    field arrays to be deleted after this ExodusModel is
-  //    initialized.
-  //    Returns 1 if there is no ExodusModel object associated with
-  //    the grid, 0 otherwise.
-
-  int UnpackExodusModel(vtkUnstructuredGrid *grid, int deleteIt);
-
-  // Description:
-  //   Merge the supplied vtkExodusModel object into this one.  It is
-  //   assumed the two objects represent portions of the same distributed
-  //   data set.  (So the list of block IDs is the same, and so on.)
-
-  int MergeExodusModel(vtkExodusModel *em);
-
-  // Description:
-  //    Create a new vtkExodusModel object representing a subset of the
-  //    cells of this vtkExodusModel object.  We need a list of the
-  //    global IDs of the cells to be extracted, the grid which
-  //    generated the Exodus Model (so we can find the points associated
-  //    with each cell), and the name of the grid's global cell ID array,
-  //    and the name of the grid's global node ID array.
-
-  vtkExodusModel *ExtractExodusModel(vtkIdTypeArray *globalCellIdList,
-                                     vtkUnstructuredGrid *grid);
-
-  // Description:
-  //    The metadata encapsulated in a vtkExodusModel object can be
-  //    written to field arrays which are then stored in the
-  //    vtkUnstructuredGrid itself.  PackExodusModel creates these
-  //    field arrays and attaches them to the supplied grid.
-
-  void PackExodusModel(vtkUnstructuredGrid *grid);
-
   // Description::
   //    Reset all fields to their initial value.
 
diff --git a/IO/Exodus/vtkModelMetadata.cxx b/IO/Exodus/vtkModelMetadata.cxx
index eb68f6302b8..24c5dbd0bd3 100644
--- a/IO/Exodus/vtkModelMetadata.cxx
+++ b/IO/Exodus/vtkModelMetadata.cxx
@@ -336,22 +336,7 @@ void vtkModelMetadata::SetInformationLines(int nlines, char **lines)
   this->NumberOfInformationLines = nlines;
   this->InformationLine = lines;
 }
-void vtkModelMetadata::AddInformationLine(char *line)
-{
-  int newNum = this->NumberOfInformationLines + 1;
-  char **lines = new char * [newNum];
-
-  for (int i=0; i<this->NumberOfInformationLines; i++)
-    {
-    lines[i] = this->InformationLine[i];
-    }
 
-  lines[newNum-1] = line;
-
-  delete [] this->InformationLine;
-
-  this->InformationLine = lines;
-}
 int vtkModelMetadata::GetInformationLines(char ***lines) const
 {
   *lines = this->InformationLine;
@@ -388,56 +373,7 @@ void vtkModelMetadata::SetQARecords(int nrecords, char *rec[][4])
     this->NumberOfQARecords = nrecords;
     }
 }
-void vtkModelMetadata::AddQARecord(char *name, char *ver, char *recDate, char *recTime)
-{
-  typedef char *p4[4];
-
-  int newNum = this->NumberOfQARecords + 1;
-
-  p4 *qaRecs = new p4 [newNum];
-
-  for (int i=0; i<this->NumberOfQARecords; i++)
-    {
-    qaRecs[i][0] = this->QARecord[i][0]; qaRecs[i][1] = this->QARecord[i][1];
-    qaRecs[i][2] = this->QARecord[i][2]; qaRecs[i][3] = this->QARecord[i][3];
-    }
-
-  delete [] this->QARecord;
-
-  if ((recDate == NULL) || (recTime == NULL))
-    {
-    time_t currentTime = time(NULL);
-    struct tm *timeDate = localtime(&currentTime);
-
-    if (timeDate->tm_year >= 100) timeDate->tm_year -= 100;  // Y2K
-
-    if (recDate == NULL)
-      {
-      char *dateStr = new char [10];
-      sprintf(dateStr, "%02d/%02d/%02d",
-        timeDate->tm_mon, timeDate->tm_mday, timeDate->tm_year);
-      qaRecs[newNum-1][2] = dateStr;
-      }
-
-    if (recTime == NULL)
-      {
-      char *timeStr = new char [10];
-      sprintf(timeStr, "%02d:%02d:%02d",
-        timeDate->tm_hour, timeDate->tm_min, timeDate->tm_sec);
-      qaRecs[newNum-1][3] = timeStr;
-      }
-    }
-
-  qaRecs[newNum-1][0] = name;
-  qaRecs[newNum-1][1] = ver;
-
-  if (recDate) qaRecs[newNum-1][2] = recDate;
-  if (recTime) qaRecs[newNum-1][3] = recTime;
-
-  this->QARecord = qaRecs;
 
-  this->NumberOfQARecords = newNum;
-}
 void vtkModelMetadata::GetQARecord(int which,
                char **name, char **ver, char **date, char **time) const
 {
@@ -1246,2571 +1182,408 @@ void vtkModelMetadata::SetNodeVariableInfo(int numOrigNames, char **origNames,
 }
 
 //---------------------------------------------------------------
-// Pack all the metadata into an unstructured grid, or
-// initialize this vtkModelMetadata object with information packed
-// into an unstructured grid (i.e. unpack).
+// Merge and subset vtkModelMetadata objects.  Because grids get
+// merged and subsetted on their journey through the VTK reader and filters.
 //---------------------------------------------------------------
 
-#define SIZE_ARRAY "vtkModelMetadataSizes"
-#define INT_ARRAY "vtkModelMetadataInts"
-#define FLOAT_ARRAY "vtkModelMetadataFloats"
-#define CHAR_ARRAY "vtkModelMetadataChars"
-
-void vtkModelMetadata::RemoveMetadata(vtkDataSet *grid)
-{
-  grid->GetFieldData()->RemoveArray(SIZE_ARRAY);
-  grid->GetFieldData()->RemoveArray(INT_ARRAY);
-  grid->GetFieldData()->RemoveArray(FLOAT_ARRAY);
-  grid->GetFieldData()->RemoveArray(CHAR_ARRAY);
-}
-
-int vtkModelMetadata::HasMetadata(vtkDataSet *grid)
+int vtkModelMetadata::AppendFloatLists(
+    int numSubLists,
+    float *id1, int *id1Idx, int id1Len,
+    float *id2, int *id2Idx, int id2Len,
+    float **idNew, int **idNewIdx, int *idNewLen)
 {
-  int hasMetadata = 0;
-
-  if (grid)
+  if ((id1Len == 0) && (id2Len == 0))
     {
-    vtkFieldData *fa = grid->GetFieldData();
-
-    if (fa)
+    if (idNew)
+      {
+      *idNew = NULL;
+      }
+    if (idNewIdx)
       {
-      vtkDataArray *da = fa->GetArray(SIZE_ARRAY);
-      if (da) hasMetadata = 1;
+      *idNewIdx = NULL;
+      }
+    if (idNewLen)
+      {
+      *idNewLen = 0;
       }
+    return 0;
     }
 
-  return hasMetadata;
-}
-
-void vtkModelMetadata::Pack(vtkDataSet *grid)
-{
-  int maxStringLength, maxLineLength;
-
-  this->CalculateMaximumLengths(maxStringLength, maxLineLength);
-
-  vtkIntArray *sizes = this->PackSizeArray(maxStringLength, maxLineLength);
-  vtkIntArray *ints = this->PackIntArray();
-  vtkCharArray *chars = this->PackCharArray(maxStringLength, maxLineLength);
-  vtkFloatArray *floats = this->PackFloatArray();
-
-  vtkFieldData *fa = grid->GetFieldData();
-
-  if (!fa)
-    {
-    fa = vtkFieldData::New();
-    grid->SetFieldData(fa);
-    fa->Delete();
-    fa = grid->GetFieldData();
-    }
+  int i;
 
-  fa->AddArray(sizes);
-  sizes->Delete();
+  int newIdListLength = id1Len + id2Len;
 
-  if (ints->GetNumberOfTuples() > 0)
-    {
-    fa->AddArray(ints);
-    ints->Delete();
-    }
+  float *newIdList = new float [newIdListLength];
+  int *newIdListIndex = new int [numSubLists];
 
-  if (chars->GetNumberOfTuples() > 0)
+  if (id1Len == 0)
     {
-    fa->AddArray(chars);
-    chars->Delete();
+    memcpy(newIdList, id2, id2Len * sizeof(float));
+    memcpy(newIdListIndex, id2Idx, numSubLists * sizeof(int));
     }
-
-  if (floats->GetNumberOfTuples() > 0)
+  else if (id2Len == 0)
     {
-    fa->AddArray(floats);
-    floats->Delete();
+    memcpy(newIdList, id1, id1Len * sizeof(float));
+    memcpy(newIdListIndex, id1Idx, numSubLists * sizeof(int));
     }
-}
-int vtkModelMetadata::Unpack(vtkDataSet *grid, int deleteIt)
-{
-  vtkFieldData *fa = grid->GetFieldData();
-
-  if (!fa)
+  else
     {
-    return 1;
-    }
-
-  vtkDataArray *da = fa->GetArray(SIZE_ARRAY);
-  vtkIntArray *sizes = vtkIntArray::SafeDownCast(da);
+    newIdListIndex[0] = 0;
 
-  if (!sizes)
-    {
-    return 1;
-    }
+    int nextid = 0;
 
-  this->Reset();
+    for (i=0; i<numSubLists; i++)
+      {
+      int lastList = (i == numSubLists-1);
 
-  // NOTE: The size array must be unpacked before any other, because
-  //  it provides information about the contents of the other arrays.
-  //  We keep the sizes in a temporary object until "this" object is set.
+      float *ids = id1 + id1Idx[i];
+      int numids = (lastList ? id1Len : id1Idx[i+1]) - id1Idx[i];
+      if (numids > 0)
+        {
+        memcpy(newIdList + nextid, ids, numids * sizeof(float));
+        nextid += numids;
+        }
 
-  vtkModelMetadata *temp = vtkModelMetadata::New();
+      ids = id2 + id2Idx[i];
+      numids = (lastList ? id2Len : id2Idx[i+1]) - id2Idx[i];
 
-  int maxString=0;
-  int maxLine=0;
+      if (numids > 0)
+        {
+        memcpy(newIdList + nextid, ids, numids * sizeof(float));
+        nextid += numids;
+        }
 
-  int fail = temp->InitializeFromSizeArray(sizes, maxString, maxLine);
+      if (!lastList)
+        {
+        newIdListIndex[i+1] = nextid;
+        }
+      else
+        {
+        newIdListLength = nextid;
+        }
+      }
+    }
 
-  if (fail)
+  if (idNew)
     {
-    temp->Delete();
-    return 1;
+    *idNew = newIdList;
     }
-
-  if (deleteIt)
+  else
     {
-    fa->RemoveArray(SIZE_ARRAY);
+    delete [] newIdList;
     }
-
-  da = fa->GetArray(INT_ARRAY);
-  vtkIntArray *ints = vtkIntArray::SafeDownCast(da);
-
-  if (ints)
+  if (idNewIdx)
     {
-    fail = this->InitializeFromIntArray(temp, ints);
-
-    if (fail)
-      {
-      temp->Delete();
-      return 1;
-      }
-    if (deleteIt)
-      {
-      fa->RemoveArray(INT_ARRAY);
-      }
+    *idNewIdx = newIdListIndex;
     }
-
-  da = fa->GetArray(CHAR_ARRAY);
-  vtkCharArray *chars = vtkCharArray::SafeDownCast(da);
-
-  if (chars)
+  else
     {
-    fail = this->InitializeFromCharArray(temp, chars, maxString, maxLine);
-
-    if (fail)
-      {
-      temp->Delete();
-      return 1;
-      }
-    if (deleteIt)
-      {
-      fa->RemoveArray(CHAR_ARRAY);
-      }
+    delete [] newIdListIndex;
     }
-
-  da = fa->GetArray(FLOAT_ARRAY);
-  vtkFloatArray *floats = vtkFloatArray::SafeDownCast(da);
-
-  if (floats)
+  if (idNewLen)
     {
-    fail = this->InitializeFromFloatArray(floats);
-
-    if (fail)
-      {
-      temp->Delete();
-      return 1;
-      }
-
-    if (deleteIt)
-      {
-      fa->RemoveArray(FLOAT_ARRAY);
-      }
+    *idNewLen = newIdListLength;
     }
 
-  temp->Delete();
-
-  return 0;
-}
-vtkIntArray *vtkModelMetadata::PackSizeArray(int maxStr, int maxLine)
-{
-// Fields stored in size array:
-//  int NumberOfQARecords;
-//  int NumberOfInformationLines;
-//  int Dimension;
-//  int NumberOfBlocks;
-//  int NumberOfNodeSets;
-//  int NumberOfSideSets;
-//  int NumberOfBlockProperties;
-//  int NumberOfNodeSetProperties;
-//  int NumberOfSideSetProperties;
-//  int NumberOfGlobalVariables;
-//  int NumberOfElementVariables;
-//  int NumberOfNodeVariables;
-//  int OriginalNumberOfElementVariables;
-//  int OriginalNumberOfNodeVariables;
-//  int MaxStringLength
-//  int MaxLineLength
-
-  vtkIntArray *sizeInfo = vtkIntArray::New();
-  sizeInfo->SetName(SIZE_ARRAY);
-
-  sizeInfo->SetNumberOfValues(16);
-
-  sizeInfo->SetValue(0, this->NumberOfQARecords);
-  sizeInfo->SetValue(1, this->NumberOfInformationLines);
-  sizeInfo->SetValue(2, this->Dimension);
-  sizeInfo->SetValue(3, this->NumberOfBlocks);
-  sizeInfo->SetValue(4, this->NumberOfNodeSets);
-  sizeInfo->SetValue(5, this->NumberOfSideSets);
-  sizeInfo->SetValue(6, this->NumberOfBlockProperties);
-  sizeInfo->SetValue(7, this->NumberOfNodeSetProperties);
-  sizeInfo->SetValue(8, this->NumberOfSideSetProperties);
-  sizeInfo->SetValue(9, this->NumberOfGlobalVariables);
-  sizeInfo->SetValue(10, this->NumberOfElementVariables);
-  sizeInfo->SetValue(11, this->NumberOfNodeVariables);
-  sizeInfo->SetValue(12, this->OriginalNumberOfElementVariables);
-  sizeInfo->SetValue(13, this->OriginalNumberOfNodeVariables);
-  sizeInfo->SetValue(14, maxStr);
-  sizeInfo->SetValue(15, maxLine);
-
-  return sizeInfo;
-}
-int vtkModelMetadata::InitializeFromSizeArray(vtkIntArray *ia, int &maxS, int &maxL)
-{
-  int nvals = ia->GetNumberOfTuples();
-
-  if (nvals < 16) return 1;
-
-  this->NumberOfQARecords         = ia->GetValue(0);
-  this->NumberOfInformationLines  = ia->GetValue(1);
-  this->Dimension                 = ia->GetValue(2);
-  this->NumberOfBlocks            = ia->GetValue(3);
-  this->NumberOfNodeSets          = ia->GetValue(4);
-  this->NumberOfSideSets          = ia->GetValue(5);
-  this->NumberOfBlockProperties   = ia->GetValue(6);
-  this->NumberOfNodeSetProperties = ia->GetValue(7);
-  this->NumberOfSideSetProperties = ia->GetValue(8);
-  this->NumberOfGlobalVariables   = ia->GetValue(9);
-  this->NumberOfElementVariables  = ia->GetValue(10);
-  this->NumberOfNodeVariables     = ia->GetValue(11);
-  this->OriginalNumberOfElementVariables  = ia->GetValue(12);
-  this->OriginalNumberOfNodeVariables     = ia->GetValue(13);
-  maxS = ia->GetValue(14);
-  maxL = ia->GetValue(15);
-
   return 0;
 }
-#define __CHECK_COPY(to, from, size) \
-    (from ? memcpy(to, from, size) : memset(to, 0, size));
-
-vtkIntArray *vtkModelMetadata::PackIntArray()
+int vtkModelMetadata::AppendIntegerLists(
+    int numSubLists,
+    int *id1, int *id1Idx, int id1Len,
+    int *id2, int *id2Idx, int id2Len,
+    int **idNew, int **idNewIdx, int *idNewLen)
 {
-// Fields stored in the integer array
-//    3 counts: Sum of all node set sizes, sum of all side set sizes,
-//              and sum of all elements per block
-//    1 integer: the current time step index
-//    int *BlockIds;                // NumberOfBlocks
-//    int *BlockNumberOfElements;  // NumberOfBlocks
-//    int *BlockNodesPerElement;   // NumberOfBlocks
-//    int *BlockNumberOfAttributesPerElement;// NumberOfBlocks
-//    int *BlockElementIdList;     // SumElementsPerBlock
-//    int *NodeSetIds;             // NumberOfNodeSets
-//    int *NodeSetSize;            // NumberOfNodeSets
-//    int *NodeSetNumberOfDistributionFactors;  // NumberOfNodeSets
-//    int *NodeSetNodeIdList;                   // SumNodesPerNodeSet
-//    int *SideSetIds;                          // NumberOfSideSets
-//    int *SideSetSize;                         // NumberOfSideSets
-//    int *SideSetNumberOfDistributionFactors;  // NumberOfSideSets
-//    int *SideSetElementList;              // SumSidesPerSideSet
-//    int *SideSetSideList;                 // SumSidesPerSideSet
-//    int *SideSetNumDFPerSide;          // SumSidesPerSideSet
-//    int *BlockPropertyValue;              // NumBlocks * NumBlockProperties
-//    int *NodeSetPropertyValue;            // NumNodeSets * NumNodeSetProperties
-//    int *SideSetPropertyValue;            // NumSideSets * NumSideSetProperties
-//    int *ElementVariableTruthTable;  // NumBlocks * OrigNumElementVariables
-//    int *ElementVariableNumberOfComponents; // NumberOfElementVariables
-//    int *MapToOriginalElementVariableNames; // NumberOfElementVariables
-//    int *NodeVariableNumberOfComponents;    // NumberOfNodeVariables
-//    int *MapToOriginalNodeVariableNames;    // NumberOfNodeVariables
-
-  int nblocks = this->NumberOfBlocks;
-  int nnsets = this->NumberOfNodeSets;
-  int nssets = this->NumberOfSideSets;
-  int nblockProp = this->NumberOfBlockProperties;
-  int nnsetProp = this->NumberOfNodeSetProperties;
-  int nssetProp = this->NumberOfSideSetProperties;
-  int nOrigEltVars = this->OriginalNumberOfElementVariables;
-  int nEltVars = this->NumberOfElementVariables;
-  int nNodeVars = this->NumberOfNodeVariables;
-
-  vtkIdType nvals = 4 +
-    (nblocks * 4) + this->SumElementsPerBlock +
-    (nnsets * 3) + this->SumNodesPerNodeSet +
-    (nssets * 3) + (this->SumSidesPerSideSet * 3) +
-    (nblocks * nblockProp) +
-    (nnsets * nnsetProp) +
-    (nssets * nssetProp) +
-    (nblocks * nOrigEltVars) +
-    (nEltVars * 2) +
-    (nNodeVars * 2);
-
-  int *packed = new int [nvals];
-  int *p = packed;
-
-  p[0] = this->SumNodesPerNodeSet;
-  p[1] = this->SumSidesPerSideSet;
-  p[2] = this->SumElementsPerBlock;
-  p[3] = this->TimeStepIndex;
-
-  p += 4;
-
-  if (nblocks > 0)
+  if ((id1Len == 0) && (id2Len == 0))
     {
-    size_t n = sizeof(int) * nblocks;
-
-    __CHECK_COPY(p, this->BlockIds, n)
-    p += nblocks;
+    return 1;
+    }
 
-    __CHECK_COPY(p, this->BlockNumberOfElements, n)
-    p += nblocks;
+  int i;
 
-    __CHECK_COPY(p, this->BlockNodesPerElement, n)
-    p += nblocks;
+  int newIdListLength = id1Len + id2Len;
 
-    __CHECK_COPY(p, this->BlockNumberOfAttributesPerElement, n)
-    p += nblocks;
+  int *newIdList = new int [newIdListLength];
+  int *newIdListIndex = new int [numSubLists];
 
-    __CHECK_COPY(p, this->BlockElementIdList, sizeof(int) * this->SumElementsPerBlock)
-    p += this->SumElementsPerBlock;
+  if (id1Len == 0)
+    {
+    memcpy(newIdList, id2, id2Len * sizeof(int));
+    memcpy(newIdListIndex, id2Idx, numSubLists * sizeof(int));
     }
-
-  if (nnsets > 0)
+  else if (id2Len == 0)
     {
-    size_t n = sizeof(int) * nnsets;
-
-    __CHECK_COPY(p, this->NodeSetIds, n);
-    p += nnsets;
-
-    __CHECK_COPY(p, this->NodeSetSize, n);
-    p += nnsets;
-
-    __CHECK_COPY(p, this->NodeSetNumberOfDistributionFactors, n);
-    p += nnsets;
-
-    __CHECK_COPY(p, this->NodeSetNodeIdList, sizeof(int) * this->SumNodesPerNodeSet);
-    p += this->SumNodesPerNodeSet;
+    memcpy(newIdList, id1, id1Len * sizeof(int));
+    memcpy(newIdListIndex, id1Idx, numSubLists * sizeof(int));
     }
-
-  if (nssets > 0)
+  else
     {
-    size_t n = sizeof(int) * nssets;
-
-    __CHECK_COPY(p, this->SideSetIds, n);
-    p += nssets;
-
-    __CHECK_COPY(p, this->SideSetSize, n);
-    p += nssets;
+    newIdListIndex[0] = 0;
 
-    __CHECK_COPY(p, this->SideSetNumberOfDistributionFactors, n);
-    p += nssets;
+    int nextid = 0;
 
-    size_t sum = sizeof(int) * this->SumSidesPerSideSet;
+    for (i=0; i<numSubLists; i++)
+      {
+      int lastList = (i == numSubLists-1);
 
-    __CHECK_COPY(p, this->SideSetElementList, sum);
-    p += this->SumSidesPerSideSet;
+      int *ids = id1 + id1Idx[i];
+      int numids = (lastList ? id1Len : id1Idx[i+1]) - id1Idx[i];
+      if (numids > 0)
+        {
+        memcpy(newIdList + nextid, ids, numids * sizeof(int));
+        nextid += numids;
+        }
 
-    __CHECK_COPY(p, this->SideSetSideList, sum);
-    p += this->SumSidesPerSideSet;
+      ids = id2 + id2Idx[i];
+      numids = (lastList ? id2Len : id2Idx[i+1]) - id2Idx[i];
 
-    __CHECK_COPY(p, this->SideSetNumDFPerSide, sum);
-    p += this->SumSidesPerSideSet;
-    }
+      if (numids > 0)
+        {
+        memcpy(newIdList + nextid, ids, numids * sizeof(int));
+        nextid += numids;
+        }
 
-  if (nblockProp > 0)
-    {
-    __CHECK_COPY(p, this->BlockPropertyValue,
-              sizeof(int) * nblockProp * nblocks);
-    p += (nblockProp * nblocks);
+      if (!lastList)
+        {
+        newIdListIndex[i+1] = nextid;
+        }
+      else
+        {
+        newIdListLength = nextid;
+        }
+      }
     }
 
-  if (nnsetProp > 0)
+  if (idNew)
     {
-    __CHECK_COPY(p, this->NodeSetPropertyValue,
-              sizeof(int) * nnsetProp * nnsets);
-    p += (nnsetProp * nnsets);
+    *idNew = newIdList;
     }
-
-  if (nssetProp > 0)
+  else
     {
-    __CHECK_COPY(p, this->SideSetPropertyValue,
-              sizeof(int) * nssetProp * nssets);
-    p += (nssetProp * nssets);
+    delete [] newIdList;
     }
-
-  if ((nblocks > 0) && (nOrigEltVars > 0))
+  if (idNewIdx)
     {
-    __CHECK_COPY(p, this->ElementVariableTruthTable,
-              sizeof(int) * nblocks * nOrigEltVars);
-    p += (nblocks * nOrigEltVars);
+    *idNewIdx = newIdListIndex;
     }
-
-  if (nEltVars > 0)
+  else
     {
-    __CHECK_COPY(p, this->ElementVariableNumberOfComponents,
-              sizeof(int) * nEltVars);
-    p += nEltVars;
-
-    __CHECK_COPY(p, this->MapToOriginalElementVariableNames,
-              sizeof(int) * nEltVars);
-    p += nEltVars;
+    delete [] newIdListIndex;
     }
-
-  if (nNodeVars > 0)
+  if (idNewLen)
     {
-    __CHECK_COPY(p, this->NodeVariableNumberOfComponents,
-              sizeof(int) * nNodeVars);
-    p += nNodeVars;
-
-    __CHECK_COPY(p, this->MapToOriginalNodeVariableNames,
-              sizeof(int) * nNodeVars);
-    p += nNodeVars;
+    *idNewLen = newIdListLength;
     }
 
-  vtkIntArray *ia = vtkIntArray::New();
-  ia->SetName(INT_ARRAY);
-  ia->SetArray(packed, nvals, 0);
-
-  return ia;
+  return 0;
 }
-int vtkModelMetadata::InitializeFromIntArray(vtkModelMetadata *sizes, vtkIntArray *ia)
+
+int vtkModelMetadata::MergeIdLists(int numSubLists,
+    int *id1, int *id1Idx, int id1Len,
+      float *dist1, int *dist1Idx, int dist1Len,
+    int *id2, int *id2Idx, int id2Len,
+      float *dist2, int *dist2Idx, int dist2Len,
+    int **idNew, int **idNewIdx, int *idNewLen,
+      float **distNew, int **distNewIdx, int *distNewLen)
 {
-  int nblocks = sizes->NumberOfBlocks;
-  int nnsets = sizes->NumberOfNodeSets;
-  int nssets = sizes->NumberOfSideSets;
-  int nblockProp = sizes->NumberOfBlockProperties;
-  int nnsetProp = sizes->NumberOfNodeSetProperties;
-  int nssetProp = sizes->NumberOfSideSetProperties;
-  int nEltVars = sizes->NumberOfElementVariables;
-  int nNodeVars = sizes->NumberOfNodeVariables;
-  int ttsize = nblocks * sizes->OriginalNumberOfElementVariables;
+  if ((id1Len == 0) && (id2Len == 0))
+    {
+    return 1;
+    }
 
-  int *p = ia->GetPointer(0);
+  // Here we take two lists of IDs, and their associated lists of
+  // floating point factors.  Some of the IDs in the second list may
+  // be duplicates of IDs in the first list, and we need to filter
+  // these out when we build the lists combining both.
 
-  int sumNodeSetSizes = p[0];
-  int sumSideSetSizes = p[1];
-  int sumElementIds = p[2];
+  int i, id;
 
-  this->TimeStepIndex = p[3];
+  int *newIdList=NULL;
+  int *newIdListIndex = NULL;
+  int newIdListLength = 0;
 
-  p += 4;
-
-  if (nblocks > 0)
-    {
-    int *buf = new int [nblocks];
-    memcpy(buf, p, nblocks * sizeof(int));
-    p += nblocks;
-
-    this->SetNumberOfBlocks(nblocks);
-    this->SetBlockIds(buf);
-
-    buf = new int [nblocks];
-    memcpy(buf, p, nblocks * sizeof(int));
-    p += nblocks;
-
-    this->SetBlockNumberOfElements(buf);
-
-    buf = new int [nblocks];
-    memcpy(buf, p, nblocks * sizeof(int));
-    p += nblocks;
-
-    this->SetBlockNodesPerElement(buf);
-
-    buf = new int [nblocks];
-    memcpy(buf, p, nblocks * sizeof(int));
-    p += nblocks;
-
-    this->SetBlockNumberOfAttributesPerElement(buf);
-
-    buf = new int [sumElementIds];
-    memcpy(buf, p, sumElementIds * sizeof(int));
-    p += sumElementIds;
-
-    this->SetBlockElementIdList(buf);
-    }
-
-  if (nnsets > 0)
-    {
-    int *buf = new int [nnsets];
-    memcpy(buf, p, nnsets * sizeof(int));
-    p += nnsets;
-
-    this->SetNumberOfNodeSets(nnsets);
-    this->SetNodeSetIds(buf);
-
-    buf = new int [nnsets];
-    memcpy(buf, p, nnsets * sizeof(int));
-    p += nnsets;
-
-    this->SetNodeSetSize(buf);
-
-    buf = new int [nnsets];
-    memcpy(buf, p, nnsets * sizeof(int));
-    p += nnsets;
-
-    this->SetNodeSetNumberOfDistributionFactors(buf);
-
-    buf = new int [sumNodeSetSizes];
-    memcpy(buf, p, sumNodeSetSizes * sizeof(int));
-    p += sumNodeSetSizes;
-
-    this->SetNodeSetNodeIdList(buf);
-    }
-
-  if (nssets > 0)
-    {
-    int *buf = new int [nssets];
-    memcpy(buf, p, nssets * sizeof(int));
-    p += nssets;
-
-    this->SetNumberOfSideSets(nssets);
-    this->SetSideSetIds(buf);
-
-    buf = new int [nssets];
-    memcpy(buf, p, nssets * sizeof(int));
-    p += nssets;
-
-    this->SetSideSetSize(buf);
-
-    buf = new int [nssets];
-    memcpy(buf, p, nssets * sizeof(int));
-    p += nssets;
-
-    this->SetSideSetNumberOfDistributionFactors(buf);
-
-    buf = new int [sumSideSetSizes];
-    memcpy(buf, p, sumSideSetSizes * sizeof(int));
-    p += sumSideSetSizes;
-
-    this->SetSideSetElementList(buf);
-
-    buf = new int [sumSideSetSizes];
-    memcpy(buf, p, sumSideSetSizes * sizeof(int));
-    p += sumSideSetSizes;
-
-    this->SetSideSetSideList(buf);
-
-    buf = new int [sumSideSetSizes];
-    memcpy(buf, p, sumSideSetSizes * sizeof(int));
-    p += sumSideSetSizes;
-
-    this->SetSideSetNumDFPerSide(buf);
-    }
-
-  if (nblockProp > 0)
-    {
-    int nvals = nblocks * nblockProp;
-
-    int *buf = new int [nvals];
-    memcpy(buf, p, nvals * sizeof(int));
-    p += nvals ;
-
-    this->SetBlockPropertyValue(buf);
-    }
-
-  if (nnsetProp > 0)
-    {
-    int nvals = nnsets * nnsetProp;
-
-    int *buf = new int [nvals];
-    memcpy(buf, p, nvals * sizeof(int));
-    p += nvals ;
-
-    this->SetNodeSetPropertyValue(buf);
-    }
-
-  if (nssetProp > 0)
-    {
-    int nvals = nssets * nssetProp;
-
-    int *buf = new int [nvals];
-    memcpy(buf, p, nvals * sizeof(int));
-    p += nvals ;
-
-    this->SetSideSetPropertyValue(buf);
-    }
-
-  if (ttsize > 0)
-    {
-    int *buf = new int [ttsize];
-    memcpy(buf, p, ttsize * sizeof(int));
-    p += ttsize;
-
-    this->SetElementVariableTruthTable(buf);
-    }
-
-  if (nEltVars > 0)
-   {
-    int *buf1 = new int [nEltVars];
-    memcpy(buf1, p, nEltVars * sizeof(int));
-    p += nEltVars;
-
-    int *buf2 = new int [nEltVars];
-    memcpy(buf2, p, nEltVars * sizeof(int));
-    p += nEltVars;
-
-    this->SetElementVariableNumberOfComponents(buf1);
-    this->SetMapToOriginalElementVariableNames(buf2);
-   }
-
-  if (nNodeVars > 0)
-    {
-    int *buf1 = new int [nNodeVars];
-    memcpy(buf1, p, nNodeVars * sizeof(int));
-    p += nNodeVars;
-
-    int *buf2 = new int [nNodeVars];
-    memcpy(buf2, p, nNodeVars * sizeof(int));
-    p += nNodeVars;
-
-    this->SetNodeVariableNumberOfComponents(buf1);
-    this->SetMapToOriginalNodeVariableNames(buf2);
-    }
-
-  return 0;
-}
-char *vtkModelMetadata::WriteLines(
-    char *p, int maxLines, int maxLen, char **lines)
-{
-  for (int i=0; i<maxLines; i++)
-    {
-    if (lines[i])
-      {
-      strcpy(p, lines[i]);
-      }
-    p += maxLen;
-    }
-
-  return p;
-}
-
-vtkCharArray *vtkModelMetadata::PackCharArray(int maxS, int maxL)
-{
-// Fields that go into the char array:
-// char *Title;             // MaxLineLength
-// char *QARecord[][4];     // NumberOfQARecords * 4 * MaxStringLength
-// char **InformationLine;  // each record is MaxLineLength
-// char **CoordinateNames;  // MaxStringLength each (at most 3 of these)
-// char **BlockElementType;      // NumberOfBlocks, length MaxStringLength
-// char **BlockPropertyNames;    // one per property, MaxStringLength
-// char **NodeSetPropertyNames;  // one per property, MaxStringLength
-// char **SideSetPropertyNames;  // one per property, MaxStringLength
-// char **GlobalVariableNames;   // one per global variable, MaxStringLength
-// char **OriginalElementVariableNames; // OriginalNumberOfElementVariables, MaxStr
-// char **ElementVariableNames;     // NumberOfElementVariables, MaxStringLength
-// char **OriginalNodeVariableNames;    // OriginalNumberOfNodeVariables, MaxStr
-// char **NodeVariableNames;        // NumberOfNodeVariables, MaxStringLength
-//
-  vtkIdType len = 0;
-
-  len += maxL;  // for the title
-
-  len += (this->NumberOfQARecords * 4 * maxS);
-
-  len += (this->NumberOfInformationLines * maxL);
-
-  len += (this->Dimension * maxS);
-
-  len += (this->NumberOfBlocks * maxS);
-
-  len += (this->NumberOfBlockProperties * maxS);
-
-  len += (this->NumberOfNodeSetProperties * maxS);
-
-  len += (this->NumberOfSideSetProperties * maxS);
-
-  len += (this->NumberOfGlobalVariables * maxS);
-
-  len += (this->OriginalNumberOfElementVariables * maxS);
-
-  len += (this->NumberOfElementVariables * maxS);
-
-  len += (this->OriginalNumberOfNodeVariables * maxS);
-
-  len += (this->NumberOfNodeVariables * maxS);
-
-  char *uc = new char [len];
-
-  memset(uc, 0, len);
-
-  char *p = uc;
-
-  if (this->Title)
-    {
-    strcpy(p, this->Title);
-    }
-  else
-    {
-    strcpy(p, "NULL");
-    }
-
-  p += maxL;
-
-  for (int i=0; i<this->NumberOfQARecords; i++)
-    {
-    for (int j=0; j<4; j++)
-      {
-      int l = static_cast<int>(strlen(this->QARecord[i][j]));
-      if (l > maxS) l = maxS;
-
-      memcpy(p, this->QARecord[i][j], l);
-
-      p += maxS;
-      }
-    }
-
-  p = vtkModelMetadata::WriteLines(p, this->NumberOfInformationLines,
-                        maxL, this->InformationLine);
-
-  p = vtkModelMetadata::WriteLines(p, this->Dimension,
-                        maxS, this->CoordinateNames);
-
-  p = vtkModelMetadata::WriteLines(p, this->NumberOfBlocks,
-                        maxS, this->BlockElementType);
-
-  p = vtkModelMetadata::WriteLines(p, this->NumberOfBlockProperties,
-                        maxS, this->BlockPropertyNames);
-
-  p = vtkModelMetadata::WriteLines(p, this->NumberOfNodeSetProperties,
-                        maxS, this->NodeSetPropertyNames);
-
-  p = vtkModelMetadata::WriteLines(p, this->NumberOfSideSetProperties,
-                        maxS, this->SideSetPropertyNames);
-
-  p = vtkModelMetadata::WriteLines(p, this->NumberOfGlobalVariables,
-                        maxS, this->GlobalVariableNames);
-
-  p = vtkModelMetadata::WriteLines(p, this->OriginalNumberOfElementVariables,
-                        maxS, this->OriginalElementVariableNames);
-
-  p = vtkModelMetadata::WriteLines(p, this->NumberOfElementVariables,
-                        maxS, this->ElementVariableNames);
-
-  p = vtkModelMetadata::WriteLines(p, this->OriginalNumberOfNodeVariables,
-                        maxS, this->OriginalNodeVariableNames);
-
-  p = vtkModelMetadata::WriteLines(p, this->NumberOfNodeVariables,
-                        maxS, this->NodeVariableNames);
-
-  vtkCharArray *uca = vtkCharArray::New();
-  uca->SetArray(uc, len, 0);
-  uca->SetName(CHAR_ARRAY);
-
-  return uca;
-}
-char *vtkModelMetadata::ReadLines(
-    char ***to, int maxLines, int maxLen, char *from)
-{
-  char **lineList = new char * [maxLines];
-
-  for (int i=0; i<maxLines; i++)
-    {
-    lineList[i] = new char [maxLen+1];
-    memcpy(lineList[i], from, maxLen);
-    lineList[i][maxLen] = '\0';
-    from += maxLen;
-    }
-
-  *to = lineList;
-
-  return from;
-}
-int vtkModelMetadata::InitializeFromCharArray(vtkModelMetadata *sizes,
-                          vtkCharArray *uca, int maxS, int maxL)
-{
-  char *uc = uca->GetPointer(0);
-  char **buf = NULL;
-
-  if (!uc)
-    {
-    return 1;
-    }
-
-  this->Title = new char [maxL + 1];
-  memcpy(this->Title, uc, maxL);
-  this->Title[maxL] = '\0';
-
-  uc += maxL;
-
-  int num = sizes->GetNumberOfQARecords();
-
-  if (num > 0)
-    {
-    typedef char *p4[4];
-
-    p4 *qaRec = new p4 [num];
-
-    for (int i=0; i<num; i++)
-      {
-      for (int j=0; j<4; j++)
-        {
-        qaRec[i][j] = new char [maxS + 1];
-        memcpy(qaRec[i][j], uc, maxS);
-        qaRec[i][j][maxS] = '\0';
-        uc += maxS;
-        }
-      }
-
-    this->SetQARecords(num, qaRec);
-    }
-
-  num = sizes->GetNumberOfInformationLines();
-
-  if (num > 0)
-    {
-    uc = vtkModelMetadata::ReadLines(&buf, num, maxL, uc);
-    this->SetInformationLines(num, buf);
-    }
-
-  num = sizes->GetDimension();
-
-  if (num)
-    {
-    uc = vtkModelMetadata::ReadLines(&buf, num, maxS, uc);
-    this->SetCoordinateNames(num, buf);
-    }
-
-  if (this->NumberOfBlocks)    // set in InitializeFromIntArray
-    {
-    uc = vtkModelMetadata::ReadLines(&this->BlockElementType,
-                            this->NumberOfBlocks, maxS, uc);
-    }
-
-  num = sizes->GetNumberOfBlockProperties();
-
-  if (num)
-    {
-    uc = vtkModelMetadata::ReadLines(&buf, num, maxS, uc);
-    this->SetBlockPropertyNames(num, buf);
-    }
-
-  num = sizes->GetNumberOfNodeSetProperties();
-
-  if (num)
-    {
-    uc = vtkModelMetadata::ReadLines(&buf, num, maxS, uc);
-    this->SetNodeSetPropertyNames(num, buf);
-    }
-
-  num = sizes->GetNumberOfSideSetProperties();
-
-  if (num)
-    {
-    uc = vtkModelMetadata::ReadLines(&buf, num, maxS, uc);
-    this->SetSideSetPropertyNames(num, buf);
-    }
-
-  num = sizes->GetNumberOfGlobalVariables();
-
-  if (num)
-    {
-    uc = vtkModelMetadata::ReadLines(&buf, num, maxS, uc);
-    this->SetGlobalVariableNames(num, buf);
-    }
-
-  num = sizes->OriginalNumberOfElementVariables;
-
-  if (num)
-    {
-    uc = vtkModelMetadata::ReadLines(&buf, num, maxS, uc);
-    this->SetOriginalElementVariableNames(num, buf);
-    }
-
-  num = sizes->NumberOfElementVariables;
-
-  if (num)
-    {
-    uc = vtkModelMetadata::ReadLines(&buf, num, maxS, uc);
-    this->SetElementVariableNames(num, buf);
-    }
-
-  num = sizes->OriginalNumberOfNodeVariables;
-
-  if (num)
-    {
-    uc = vtkModelMetadata::ReadLines(&buf, num, maxS, uc);
-    this->SetOriginalNodeVariableNames(num, buf);
-    }
-
-  num = sizes->NumberOfNodeVariables;
-
-  if (num)
-    {
-    uc = vtkModelMetadata::ReadLines(&buf, num, maxS, uc);
-    this->SetNodeVariableNames(num, buf);
-    }
-
-  return 0;
-}
-vtkFloatArray *vtkModelMetadata::PackFloatArray()
-{
-// Fields stored in the float array:
-//   4 counts: SizeBlockAttributeArray, SumDistFactPerNodeSet,
-//             SumDistFactPerSideSet, and NumberOfTimeSteps
-//   float *BlockAttributes;               // SizeBlockAttributeArray
-//   float *NodeSetDistributionFactors;    // SumDistFactPerNodeSet
-//   float *SideSetDistributionFactors;    // SumDistFactPerSideSet
-//   float *GlobalVariableValue;           // NumberOfGlobalVariables
-//   float *TimeStepValues;                // NumberOfTimeSteps
-//
-
-  vtkIdType len = 4 +
-                  this->SizeBlockAttributeArray +
-                  this->SumDistFactPerNodeSet +
-                  this->SumDistFactPerSideSet +
-                  this->NumberOfGlobalVariables +
-                  this->NumberOfTimeSteps;
-
-  float *f = new float [len];
-
-  f[0] = static_cast<float>(this->SizeBlockAttributeArray);
-  f[1] = static_cast<float>(this->SumDistFactPerNodeSet);
-  f[2] = static_cast<float>(this->SumDistFactPerSideSet);
-  f[3] = static_cast<float>(this->NumberOfTimeSteps);
-
-  float *nextf = f + 4;
-
-  if (this->SizeBlockAttributeArray)
-    {
-    memcpy(nextf, this->BlockAttributes,
-              this->SizeBlockAttributeArray * sizeof(float));
-    nextf += this->SizeBlockAttributeArray;
-    }
-
-  if (this->SumDistFactPerNodeSet)
-    {
-    memcpy(nextf, this->NodeSetDistributionFactors,
-              this->SumDistFactPerNodeSet * sizeof(float));
-    nextf += this->SumDistFactPerNodeSet;
-    }
-
-  if (this->SumDistFactPerSideSet)
-    {
-    memcpy(nextf, this->SideSetDistributionFactors,
-              this->SumDistFactPerSideSet * sizeof(float));
-    nextf += this->SumDistFactPerSideSet;
-    }
-
-  if (this->NumberOfGlobalVariables)
-    {
-    memcpy(nextf, this->GlobalVariableValue,
-              this->NumberOfGlobalVariables * sizeof(float));
-    nextf += this->NumberOfGlobalVariables;
-    }
-
-  if (this->NumberOfTimeSteps)
-    {
-    memcpy(nextf, this->TimeStepValues,
-              this->NumberOfTimeSteps* sizeof(float));
-    nextf += this->NumberOfTimeSteps;
-    }
-
-  vtkFloatArray *fa = vtkFloatArray::New();
-  fa->SetArray(f, len, 0);
-  fa->SetName(FLOAT_ARRAY);
-
-  return fa;
-}
-int vtkModelMetadata::InitializeFromFloatArray(vtkFloatArray *fa)
-{
-  float *f = fa->GetPointer(0);
-
-  int sizeBlockAttributeArray = static_cast<int>(f[0]);
-  int sumDistFactPerNodeSet= static_cast<int>(f[1]);
-  int sumDistFactPerSideSet= static_cast<int>(f[2]);
-  int numTimeSteps  = static_cast<int>(f[3]);
-
-  f += 4;
-
-  if ((sizeBlockAttributeArray != this->SizeBlockAttributeArray) ||
-      (sumDistFactPerNodeSet != this->SumDistFactPerNodeSet) ||
-      (sumDistFactPerSideSet != this->SumDistFactPerSideSet))
-    {
-    return 1;
-    }
-
-  if (this->SizeBlockAttributeArray)
-    {
-    float *buf = new float [this->SizeBlockAttributeArray];
-    memcpy(buf, f, sizeof(float) * this->SizeBlockAttributeArray);
-    this->SetBlockAttributes(buf);
-
-    f += this->SizeBlockAttributeArray;
-    }
-
-  if (this->SumDistFactPerNodeSet)
-    {
-    float *buf = new float [this->SumDistFactPerNodeSet];
-    memcpy(buf, f, sizeof(float) * this->SumDistFactPerNodeSet);
-    this->SetNodeSetDistributionFactors(buf);
-
-    f += this->SumDistFactPerNodeSet;
-    }
-
-  if (this->SumDistFactPerSideSet)
-    {
-    float *buf = new float [this->SumDistFactPerSideSet];
-    memcpy(buf, f, sizeof(float) * this->SumDistFactPerSideSet);
-    this->SetSideSetDistributionFactors(buf);
-
-    f += this->SumDistFactPerSideSet;
-    }
-
-  if (this->NumberOfGlobalVariables)
-    {
-    float *buf = new float [this->NumberOfGlobalVariables];
-    memcpy(buf, f, sizeof(float) * this->NumberOfGlobalVariables);
-    this->SetGlobalVariableValue(buf);
-
-    f += this->NumberOfGlobalVariables;
-    }
-
-  if (numTimeSteps)
-    {
-    float *buf = new float [numTimeSteps];
-    memcpy(buf, f, sizeof(float) * numTimeSteps);
-    this->SetTimeSteps(numTimeSteps, buf);
-
-    f += numTimeSteps;
-    }
-
-  return 0;
-}
-
-//---------------------------------------------------------------
-// Merge and subset vtkModelMetadata objects.  Because grids get
-// merged and subsetted on their journey through the VTK reader and filters.
-//---------------------------------------------------------------
-
-int vtkModelMetadata::AppendFloatLists(
-    int numSubLists,
-    float *id1, int *id1Idx, int id1Len,
-    float *id2, int *id2Idx, int id2Len,
-    float **idNew, int **idNewIdx, int *idNewLen)
-{
-  if ((id1Len == 0) && (id2Len == 0))
-    {
-    if (idNew)
-      {
-      *idNew = NULL;
-      }
-    if (idNewIdx)
-      {
-      *idNewIdx = NULL;
-      }
-    if (idNewLen)
-      {
-      *idNewLen = 0;
-      }
-    return 0;
-    }
-
-  int i;
-
-  int newIdListLength = id1Len + id2Len;
-
-  float *newIdList = new float [newIdListLength];
-  int *newIdListIndex = new int [numSubLists];
-
-  if (id1Len == 0)
-    {
-    memcpy(newIdList, id2, id2Len * sizeof(float));
-    memcpy(newIdListIndex, id2Idx, numSubLists * sizeof(int));
-    }
-  else if (id2Len == 0)
-    {
-    memcpy(newIdList, id1, id1Len * sizeof(float));
-    memcpy(newIdListIndex, id1Idx, numSubLists * sizeof(int));
-    }
-  else
-    {
-    newIdListIndex[0] = 0;
-
-    int nextid = 0;
-
-    for (i=0; i<numSubLists; i++)
-      {
-      int lastList = (i == numSubLists-1);
-
-      float *ids = id1 + id1Idx[i];
-      int numids = (lastList ? id1Len : id1Idx[i+1]) - id1Idx[i];
-      if (numids > 0)
-        {
-        memcpy(newIdList + nextid, ids, numids * sizeof(float));
-        nextid += numids;
-        }
-
-      ids = id2 + id2Idx[i];
-      numids = (lastList ? id2Len : id2Idx[i+1]) - id2Idx[i];
-
-      if (numids > 0)
-        {
-        memcpy(newIdList + nextid, ids, numids * sizeof(float));
-        nextid += numids;
-        }
-
-      if (!lastList)
-        {
-        newIdListIndex[i+1] = nextid;
-        }
-      else
-        {
-        newIdListLength = nextid;
-        }
-      }
-    }
-
-  if (idNew)
-    {
-    *idNew = newIdList;
-    }
-  else
-    {
-    delete [] newIdList;
-    }
-  if (idNewIdx)
-    {
-    *idNewIdx = newIdListIndex;
-    }
-  else
-    {
-    delete [] newIdListIndex;
-    }
-  if (idNewLen)
-    {
-    *idNewLen = newIdListLength;
-    }
-
-  return 0;
-}
-int vtkModelMetadata::AppendIntegerLists(
-    int numSubLists,
-    int *id1, int *id1Idx, int id1Len,
-    int *id2, int *id2Idx, int id2Len,
-    int **idNew, int **idNewIdx, int *idNewLen)
-{
-  if ((id1Len == 0) && (id2Len == 0))
-    {
-    return 1;
-    }
-
-  int i;
-
-  int newIdListLength = id1Len + id2Len;
-
-  int *newIdList = new int [newIdListLength];
-  int *newIdListIndex = new int [numSubLists];
-
-  if (id1Len == 0)
-    {
-    memcpy(newIdList, id2, id2Len * sizeof(int));
-    memcpy(newIdListIndex, id2Idx, numSubLists * sizeof(int));
-    }
-  else if (id2Len == 0)
-    {
-    memcpy(newIdList, id1, id1Len * sizeof(int));
-    memcpy(newIdListIndex, id1Idx, numSubLists * sizeof(int));
-    }
-  else
-    {
-    newIdListIndex[0] = 0;
-
-    int nextid = 0;
-
-    for (i=0; i<numSubLists; i++)
-      {
-      int lastList = (i == numSubLists-1);
-
-      int *ids = id1 + id1Idx[i];
-      int numids = (lastList ? id1Len : id1Idx[i+1]) - id1Idx[i];
-      if (numids > 0)
-        {
-        memcpy(newIdList + nextid, ids, numids * sizeof(int));
-        nextid += numids;
-        }
-
-      ids = id2 + id2Idx[i];
-      numids = (lastList ? id2Len : id2Idx[i+1]) - id2Idx[i];
-
-      if (numids > 0)
-        {
-        memcpy(newIdList + nextid, ids, numids * sizeof(int));
-        nextid += numids;
-        }
-
-      if (!lastList)
-        {
-        newIdListIndex[i+1] = nextid;
-        }
-      else
-        {
-        newIdListLength = nextid;
-        }
-      }
-    }
-
-  if (idNew)
-    {
-    *idNew = newIdList;
-    }
-  else
-    {
-    delete [] newIdList;
-    }
-  if (idNewIdx)
-    {
-    *idNewIdx = newIdListIndex;
-    }
-  else
-    {
-    delete [] newIdListIndex;
-    }
-  if (idNewLen)
-    {
-    *idNewLen = newIdListLength;
-    }
-
-  return 0;
-}
-
-int vtkModelMetadata::MergeIdLists(int numSubLists,
-    int *id1, int *id1Idx, int id1Len,
-      float *dist1, int *dist1Idx, int dist1Len,
-    int *id2, int *id2Idx, int id2Len,
-      float *dist2, int *dist2Idx, int dist2Len,
-    int **idNew, int **idNewIdx, int *idNewLen,
-      float **distNew, int **distNewIdx, int *distNewLen)
-{
-  if ((id1Len == 0) && (id2Len == 0))
-    {
-    return 1;
-    }
-
-  // Here we take two lists of IDs, and their associated lists of
-  // floating point factors.  Some of the IDs in the second list may
-  // be duplicates of IDs in the first list, and we need to filter
-  // these out when we build the lists combining both.
-
-  int i, id;
-
-  int *newIdList=NULL;
-  int *newIdListIndex = NULL;
-  int newIdListLength = 0;
-
-  float *newDistFact=NULL;
-  int *newDistFactIndex=NULL;
-  int newDistFactLength = 0;
-
-  int maxIdListLength = id1Len + id2Len;
-  int maxDistFactLength = dist1Len + dist2Len;
-
-  newIdList = new int [maxIdListLength];
-  newIdListIndex = new int [numSubLists];
-  newIdListIndex[0] = 0;
-
-  int distFact = (maxDistFactLength > 0);
-
-  if (distFact)
-    {
-    newDistFact = new float [maxDistFactLength];
-    newDistFactIndex = new int [numSubLists];
-    newDistFactIndex[0] = 0;
-    }
-
-  if (id1Len == 0)
-    {
-    memcpy(newIdList, id2, sizeof(int) * id2Len);
-    memcpy(newIdListIndex, id2Idx, sizeof(int) * numSubLists);
-    newIdListLength = id2Len;
-
-    if (newDistFact)
-      {
-      memcpy(newDistFact, dist2, sizeof(float) * dist2Len);
-      memcpy(newDistFactIndex, dist2Idx, sizeof(int) * numSubLists);
-      }
-
-    newDistFactLength = dist2Len;
-    }
-  else if (id2Len == 0)
-    {
-    memcpy(newIdList, id1, sizeof(int) * id1Len);
-    memcpy(newIdListIndex, id1Idx, sizeof(int) * numSubLists);
-    newIdListLength = id1Len;
-
-    if (newDistFact)
-      {
-      memcpy(newDistFact, dist1, sizeof(float) * dist1Len);
-      memcpy(newDistFactIndex, dist1Idx, sizeof(int) * numSubLists);
-      }
-
-    newDistFactLength = dist1Len;
-    }
-  else
-    {
-    int nextid = 0;
-    int nextdf = 0;
-
-    float *dist = NULL;
-    int numdf = 0;
-
-    for (i=0; i<numSubLists; i++)
-      {
-      int lastList = (i == numSubLists-1);
-
-      int *ids = id1 + id1Idx[i];
-      int numids = (lastList ? id1Len : id1Idx[i+1]) - id1Idx[i];
-      if (numids > 0)
-        {
-        memcpy(newIdList + nextid, ids, numids * sizeof(int));
-        }
-
-      nextid += numids;
-
-      if (distFact)
-        {
-        dist = dist1 + dist1Idx[i];
-        numdf = (lastList ? dist1Len : dist1Idx[i+1]) - dist1Idx[i];
-        if (numdf > 0)
-          {
-          memcpy(newDistFact + nextdf, dist, numdf * sizeof(float));
-          nextdf += numdf;
-          }
-        }
-
-      // Make a set of the ids we've just written.  We only want to add
-      // ids from list 2 if they did not exist in list 1.
-
-      std::set<int> idSet;
-
-      for (id=0; id < numids; id++)
-        {
-        idSet.insert(ids[id]);
-        }
-
-      ids = id2 + id2Idx[i];
-      numids = (lastList ? id2Len : id2Idx[i+1]) - id2Idx[i];
-
-      if (distFact)
-        {
-        dist = dist2 + dist2Idx[i];
-        numdf = (lastList ? dist2Len : dist2Idx[i+1]) - dist2Idx[i];
-        }
-      else
-        {
-        numdf = 0;
-        }
-
-      for (id=0; id < numids; id++)
-        {
-        std::pair<std::set<int>::iterator, bool> inserted =
-
-          idSet.insert(ids[id]);
-
-        if (inserted.second)    // here's a new ID
-          {
-          newIdList[nextid++] = ids[id];
-
-          if (numdf > 0)
-            {
-            // There is either 1 or 0 distribution factors
-
-            newDistFact[nextdf++] = dist[id];
-            }
-          }
-        }
-
-      if (!lastList)
-        {
-        newIdListIndex[i+1] = nextid;
-        if (distFact)
-          {
-          newDistFactIndex[i+1] = nextdf;
-          }
-        }
-      else
-        {
-        newIdListLength = nextid;
-        newDistFactLength = nextdf;
-        }
-      }
-    }
-
-  if (idNew)
-    {
-    *idNew = newIdList;
-    }
-  else
-    {
-    delete [] newIdList;
-    }
-  if (idNewIdx)
-    {
-    *idNewIdx = newIdListIndex;
-    }
-  else
-    {
-    delete [] newIdListIndex;
-    }
-  if (idNewLen)
-    {
-    *idNewLen = newIdListLength;
-    }
-
-  if (distNew)
-    {
-    *distNew = newDistFact;
-    }
-  else if (newDistFact)
-    {
-    delete [] newDistFact;
-    }
-  if (distNewIdx)
-    {
-    *distNewIdx = newDistFactIndex;
-    }
-  else if (newDistFactIndex)
-    {
-    delete [] newDistFactIndex;
-    }
-  if (distNewLen)
-    {
-    *distNewLen = newDistFactLength;
-    }
-
-  return 0;
-}
-
-// This merge function serves two purposes.  It can initialize
-// the global fields of the current object with the values in the
-// the global fields on the object passed in.
-//
-// Or it can carefully merge missing global fields in to our global
-// fields.  Often in Exodus files, global data is missing if it
-// is irrelevant.  For example, a block name is "NULL" if the
-// the file has no cells in that block.
-//
-// "Global" in this context means merge all fields which don't depend
-// on which cells are included in the model.  (In other contexts we
-// use "global" to refer to all metadata which doesn't depend on the
-// cells, the time step, or the variables chosen.)
-//
-// TODO - We may need to write a version that detects duplicate
-//   cells in the two models that are to be merged.  Maybe detecting
-//   and filtering duplicate cells should be an option.
-
-int vtkModelMetadata::MergeGlobalInformation(const vtkModelMetadata *em)
-{
-  int i;
-
-  if (!this->Title && em->GetTitle())
-    {
-    this->SetTitle(vtkModelMetadata::StrDupWithNew(em->GetTitle()));
-    }
-
-  int num = em->GetNumberOfQARecords();
-
-  if (this->NumberOfQARecords < num)
-    {
-    typedef char *p4[4];
-
-    p4 *qaRecs = new p4 [num];
-    char *name = 0;
-    char *version = 0;
-    char *date = 0;
-    char *time = 0;
-
-    for (i=0; i<num; i++)
-      {
-      em->GetQARecord(i, &name, &version, &date, &time);
-      qaRecs[i][0] = vtkModelMetadata::StrDupWithNew(name);
-      qaRecs[i][1] = vtkModelMetadata::StrDupWithNew(version);
-      qaRecs[i][2] = vtkModelMetadata::StrDupWithNew(date);
-      qaRecs[i][3] = vtkModelMetadata::StrDupWithNew(time);
-      }
-
-    this->SetQARecords(num, qaRecs);
-    }
-
-  num = em->GetNumberOfInformationLines();
-
-  if (this->NumberOfInformationLines < num)
-    {
-    char **newLines;
-    em->GetInformationLines(&newLines);
-
-    char **lines = vtkModelMetadata::CopyLines(newLines, num);
-    this->SetInformationLines(num, lines);
-    }
-
-  if (this->CoordinateNames == NULL)
-    {
-    num = em->GetDimension();
-    char **lines = vtkModelMetadata::CopyLines(em->GetCoordinateNames(), num);
-    this->SetCoordinateNames(num, lines);
-    }
-
-  num = em->GetNumberOfTimeSteps();
-
-  if (this->NumberOfTimeSteps < num)
-    {
-    float *ts = new float [num];
-    memcpy(ts, em->GetTimeStepValues(), num * sizeof(float));
-
-    this->SetTimeSteps(num, ts);
-    this->TimeStepIndex = em->TimeStepIndex;
-    }
-
-  // Assumption - Either we have no block information and are copying
-  //   it from the supplied model, or the block IDs are the same and in the
-  //   same order in both models, but we may be missing some information.
-
-  num = em->GetNumberOfBlocks();
-  int nblocks = this->GetNumberOfBlocks();
-
-  if (nblocks == 0)
-    {
-    this->SetNumberOfBlocks(num);
-
-    this->SetBlockIds(
-      vtkModelMetadata::CopyInts(em->GetBlockIds(), num));
-
-    int *nvals = new int [num];
-    memset(nvals , 0, sizeof(int) * num);
-
-    this->SetBlockNumberOfElements(nvals);
-
-    this->SetBlockElementType(
-      vtkModelMetadata::CopyLines(em->GetBlockElementType(), num));
-
-    this->SetBlockNodesPerElement(
-      vtkModelMetadata::CopyInts(em->GetBlockNodesPerElement(), num));
-
-    this->SetBlockNumberOfAttributesPerElement(
-      vtkModelMetadata::CopyInts(em->GetBlockNumberOfAttributesPerElement(), num));
-    }
-  else if (nblocks != num)
-    {
-    vtkErrorMacro(<< "Merging metadata from different files");
-    return 1;
-    }
-  else
-    {
-    char **types = em->GetBlockElementType();
-    int *nodes = em->GetBlockNodesPerElement();
-    int *atts = em->GetBlockNumberOfAttributesPerElement();
-
-    for (i=0; i < nblocks; i++)
-      {
-      if (!strcmp(this->BlockElementType[i], "NULL") &&
-          strcmp(em->BlockElementType[i], "NULL"))
-        {
-        delete [] this->BlockElementType[i];
-        this->BlockElementType[i] = vtkModelMetadata::StrDupWithNew(types[i]);
-        this->BlockNodesPerElement[i] = nodes[i];
-        this->BlockNumberOfAttributesPerElement[i] = atts[i];
-        }
-      }
-    }
-
-  num = em->GetNumberOfNodeSets();
-
-  if (this->NumberOfNodeSets < num)
-    {
-    int *ids = vtkModelMetadata::CopyInts(em->GetNodeSetIds(), num);
-
-    this->SetNumberOfNodeSets(num);
-    this->SetNodeSetIds(ids);
-    }
-
-  num = em->GetNumberOfSideSets();
-
-  if (this->NumberOfSideSets < num)
-    {
-    int *ids = vtkModelMetadata::CopyInts(em->GetSideSetIds(), num);
-
-    this->SetNumberOfSideSets(num);
-    this->SetSideSetIds(ids);
-    }
-
-  num = em->GetNumberOfBlockProperties();
-  int nblockProp = this->NumberOfBlockProperties;
-  int nvals = num * this->NumberOfBlocks;
-
-  if (nvals > 0)
-    {
-    if (nblockProp < num)
-      {
-      this->SetBlockPropertyNames(num,
-        vtkModelMetadata::CopyLines(em->GetBlockPropertyNames(), num));
-
-      this->SetBlockPropertyValue(
-        vtkModelMetadata::CopyInts(em->GetBlockPropertyValue(), nvals));
-      }
-    else if (nblockProp == num)
-      {
-      int *myVal = this->BlockPropertyValue;
-      int *newVal = em->GetBlockPropertyValue();
-
-      for (i=0; i<nvals; i++)
-        {
-        if ((myVal[i] == 0) && (newVal[i] != 0)) myVal[i] = newVal[i];
-        }
-      }
-    else
-      {
-      vtkErrorMacro(<< "Merging metadata from different files");
-      return 1;
-      }
-    }
-
-  num = em->GetNumberOfNodeSetProperties();
-  int nnsetProp = this->NumberOfNodeSetProperties;
-  nvals = num * this->NumberOfNodeSets;
-
-  if (nvals > 0)
-    {
-    if (nnsetProp < num)
-      {
-      this->SetNodeSetPropertyNames(num,
-        vtkModelMetadata::CopyLines(em->GetNodeSetPropertyNames(), num));
-
-      this->SetNodeSetPropertyValue(
-        vtkModelMetadata::CopyInts(em->GetNodeSetPropertyValue(), nvals));
-      }
-    else if (nnsetProp == num)
-      {
-      int *myVal = this->NodeSetPropertyValue;
-      int *newVal = em->GetNodeSetPropertyValue();
-
-      for (i=0; i<nvals; i++)
-        {
-        if ((myVal[i] == 0) && (newVal[i] != 0)) myVal[i] = newVal[i];
-        }
-      }
-    else
-      {
-      vtkErrorMacro(<< "Merging metadata from different files");
-      return 1;
-      }
-    }
-
-  num = em->GetNumberOfSideSetProperties();
-  int nssetProp = this->NumberOfSideSetProperties;
-  nvals = num * this->NumberOfSideSets;
-
-  if (nvals > 0)
-    {
-    if (nssetProp < num)
-      {
-      this->SetSideSetPropertyNames(num,
-        vtkModelMetadata::CopyLines(em->GetSideSetPropertyNames(), num));
-
-      this->SetSideSetPropertyValue(
-        vtkModelMetadata::CopyInts(em->GetSideSetPropertyValue(), nvals));
-      }
-    else if (nssetProp == num)
-      {
-      int *myVal = this->SideSetPropertyValue;
-      int *newVal = em->GetSideSetPropertyValue();
-
-      for (i=0; i<nvals; i++)
-        {
-        if ((myVal[i] == 0) && (newVal[i] != 0)) myVal[i] = newVal[i];
-        }
-      }
-    else
-      {
-      vtkErrorMacro(<< "Merging metadata from different files");
-      return 1;
-      }
-    }
-
-  num = em->GetNumberOfGlobalVariables();
-
-  if (num > this->NumberOfGlobalVariables)
-    {
-    this->SetGlobalVariableNames(num,
-        vtkModelMetadata::CopyLines(em->GetGlobalVariableNames(), num));
-
-    float *gv = new float [num];
-    memcpy(gv, em->GetGlobalVariableValue(), sizeof(float) * num);
-
-    this->SetGlobalVariableValue(gv);
-    }
-
-  num = em->GetOriginalNumberOfElementVariables();
-
-  if (num > this->OriginalNumberOfElementVariables)
-    {
-    char **orig =
-      vtkModelMetadata::CopyLines(em->GetOriginalElementVariableNames(), num);
-
-    int numvar = em->GetNumberOfElementVariables();
-    char **varname =
-      vtkModelMetadata::CopyLines(em->GetElementVariableNames(), numvar);
-
-    int *comp =
-      vtkModelMetadata::CopyInts(em->GetElementVariableNumberOfComponents(),
-                                 numvar);
-    int *map =
-      vtkModelMetadata::CopyInts(em->GetMapToOriginalElementVariableNames(),
-                                 numvar);
-
-    this->SetElementVariableInfo(num, orig, numvar, varname, comp, map);
-    }
-
-  num = em->GetOriginalNumberOfNodeVariables();
-
-  if (num > this->OriginalNumberOfNodeVariables)
-    {
-    char **orig =
-      vtkModelMetadata::CopyLines(em->GetOriginalNodeVariableNames(), num);
-
-    int numvar = em->GetNumberOfNodeVariables();
-    char **varname =
-      vtkModelMetadata::CopyLines(em->GetNodeVariableNames(), numvar);
-
-    int *comp =
-      vtkModelMetadata::CopyInts(em->GetNodeVariableNumberOfComponents(), numvar);
-    int *map =
-      vtkModelMetadata::CopyInts(em->GetMapToOriginalNodeVariableNames(), numvar);
-
-    this->SetNodeVariableInfo(num, orig, numvar, varname, comp, map);
-    }
-
-  int *mytt = this->ElementVariableTruthTable;
-  int *newtt = em->GetElementVariableTruthTable();
-  int nvars = em->GetOriginalNumberOfElementVariables();
-
-  if (newtt)
-    {
-    int ttsize = this->NumberOfBlocks * nvars;
-
-    if (mytt == NULL)
-      {
-      mytt = new int [ttsize];
-      memcpy(mytt, newtt, ttsize * sizeof(int));
-      this->SetElementVariableTruthTable(mytt);
-      }
-    else
-      {
-      for (i=0; i<ttsize; i++)
-        {
-        if (newtt[i] == 1) mytt[i] = 1;
-        }
-      }
-    }
-
-  return 0;
-}
-
-// Merge the metadata passed in to this metadata.  If this metadata
-// object is empty, initialize it from the metadata passed in.
-//
-// ASSUMPTION:
-//   The vtkModelMetadata object passed in comes from the same
-//   distributed file that this object was initialized from.
-//   It has the same variables and is for the same time step.  What
-//   will be different is the cells that are represented in the
-//   two models.
-//
-//   We assume that a given cell ID does not appear in more than one
-//   file in a distributed data set.  So when merging two ModelMetadata objects
-//   we just append element lists.  However, we assume that node IDs may
-//   appear in more than one file, and we filter out duplicate IDs when
-//   merging the ModelMetadata data from two files.
-//
-// TODO - vtkDistributedDataFilter has a mode where boundary cells
-//    are duplicated.  In that case, when merging one submesh's
-//    metadata with another, we would have to filter out duplicate cells.
-//    It would be good to have a flag that says whether this need to
-//    be done or not.
-
-int vtkModelMetadata::MergeModelMetadata(const vtkModelMetadata *em)
-{
-  int i, rc;
-
-  // Merge the global information - that which doesn't depend on
-  // which elements (cells) are in the two models.
-
-  rc = this->MergeGlobalInformation(em);
-
-  if (rc)
-    {
-    return 1;
-    }
-
-  // If the input object is empty, we're done
-
-  int nBlocksNew = em->GetNumberOfBlocks();
-  int *nelts = em->GetBlockNumberOfElements();
-  int nCellsNew = 0;
-
-  for (i=0; nelts && (i < nBlocksNew); i++)
-    {
-    nCellsNew += nelts[i];
-    }
-
-  if (nCellsNew == 0) return 0;
-
-  // BLOCKS
-
-  float *farray = NULL;
-  int *index = NULL;
-  int newSize = 0;
-  int nblocks = this->NumberOfBlocks;
-
-  this->AppendFloatLists(nblocks,
-     this->BlockAttributes, this->BlockAttributesIndex, this->SizeBlockAttributeArray,
-     em->BlockAttributes, em->BlockAttributesIndex, em->SizeBlockAttributeArray,
-     &farray, &index, &newSize);
-
-  FREE(this->BlockAttributes);
-  FREE(this->BlockAttributesIndex);
-
-  this->BlockAttributes = farray;
-  this->BlockAttributesIndex = index;
-  this->SizeBlockAttributeArray = newSize;
-
-  int *iarray = NULL;
-
-  this->AppendIntegerLists(nblocks,
-     this->BlockElementIdList, this->BlockElementIdListIndex, this->SumElementsPerBlock,
-     em->BlockElementIdList, em->BlockElementIdListIndex, em->SumElementsPerBlock,
-     &iarray, &index, &newSize);
-
-  FREE(this->BlockElementIdList);
-  FREE(this->BlockElementIdListIndex);
-
-  this->BlockElementIdList = iarray;
-  this->BlockElementIdListIndex = index;
-  this->SumElementsPerBlock = newSize;
-
-  for (i=0; i<nblocks; i++)
-    {
-    this->BlockNumberOfElements[i] += em->BlockNumberOfElements[i];
-    }
-
-  // NODE SETS
-
-  if (em->SumNodesPerNodeSet > 0)
-    {
-    int *index2 = NULL;
-    int newSize2 = 0;
-    int nnsets = this->NumberOfNodeSets;
-
-    this->MergeIdLists( nnsets,
-      this->NodeSetNodeIdList, this->NodeSetNodeIdListIndex, this->SumNodesPerNodeSet,
-        this->NodeSetDistributionFactors, this->NodeSetDistributionFactorIndex,
-        this->SumDistFactPerNodeSet,
-      em->NodeSetNodeIdList, em->NodeSetNodeIdListIndex, em->SumNodesPerNodeSet,
-        em->NodeSetDistributionFactors, em->NodeSetDistributionFactorIndex,
-        em->SumDistFactPerNodeSet,
-      &iarray, &index, &newSize,
-      &farray, &index2, &newSize2);
-
-    FREE(this->NodeSetNodeIdList);
-    FREE(this->NodeSetNodeIdListIndex);
-    FREE(this->NodeSetDistributionFactors);
-    FREE(this->NodeSetDistributionFactorIndex);
-
-    this->NodeSetNodeIdList = iarray;
-    this->NodeSetNodeIdListIndex = index;
-    this->NodeSetDistributionFactors = farray;
-    this->NodeSetDistributionFactorIndex = index2;
-
-    this->SumNodesPerNodeSet = newSize;
-    this->SumDistFactPerNodeSet = newSize2;
-
-    int lastset = nnsets-1;
-    int *setSize = new int [nnsets];
-    int *setDF = new int [nnsets];
-
-    for (i=0; i<lastset; i++)
-      {
-      setSize[i] = index[i+1] - index[i];
-      if (index2)
-        {
-        setDF[i] = index2[i+1] - index2[i];
-        }
-      else
-        {
-        setDF[i] = 0;
-        }
-      }
-
-    setSize[lastset] = newSize - index[lastset];
-
-    if (index2)
-      {
-      setDF[lastset] = newSize2 - index2[lastset];
-      }
-    else
-      {
-      setDF[lastset] = 0;
-      }
-
-    FREE(this->NodeSetNumberOfDistributionFactors);
-    this->NodeSetNumberOfDistributionFactors = setDF;
-
-    FREE(this->NodeSetSize);
-    this->NodeSetSize = setSize;
-    }
-
-  // SIDE SETS
-
-  if (em->SumSidesPerSideSet > 0)
-    {
-    int nssets = this->NumberOfSideSets;
-
-    this->AppendIntegerLists(nssets,
-       this->SideSetElementList, this->SideSetListIndex, this->SumSidesPerSideSet,
-       em->SideSetElementList, em->SideSetListIndex, em->SumSidesPerSideSet,
-       &iarray, &index, &newSize);
-
-    FREE(this->SideSetElementList);
-    this->SideSetElementList = iarray;
-
-    FREE(index);
-
-    this->AppendIntegerLists(nssets,
-       this->SideSetSideList, this->SideSetListIndex, this->SumSidesPerSideSet,
-       em->SideSetSideList, em->SideSetListIndex, em->SumSidesPerSideSet,
-       &iarray, &index, &newSize);
-
-    FREE(this->SideSetSideList);
-    this->SideSetSideList = iarray;
-
-    FREE(index);
-
-    this->AppendIntegerLists(nssets,
-       this->SideSetNumDFPerSide, this->SideSetListIndex, this->SumSidesPerSideSet,
-       em->SideSetNumDFPerSide, em->SideSetListIndex, em->SumSidesPerSideSet,
-       &iarray, &index, &newSize);
-
-    FREE(this->SideSetNumDFPerSide);
-    this->SideSetNumDFPerSide= iarray;
-
-    FREE(this->SideSetListIndex);
-    this->SideSetListIndex = index;
-
-    this->SumSidesPerSideSet = newSize;
-
-    this->AppendFloatLists(nssets,
-       this->SideSetDistributionFactors, this->SideSetDistributionFactorIndex,
-         this->SumDistFactPerSideSet,
-       em->SideSetDistributionFactors, em->SideSetDistributionFactorIndex,
-         em->SumDistFactPerSideSet,
-       &farray, &index, &newSize);
-
-    FREE(this->SideSetDistributionFactors);
-    FREE(this->SideSetDistributionFactorIndex);
-
-    this->SideSetDistributionFactors = farray;
-    this->SideSetDistributionFactorIndex = index;
-    this->SumDistFactPerSideSet = newSize;
-
-    int lastset = nssets - 1;
-    int *setSize = new int [nssets];
-    int *setDF = new int [nssets];
-
-    for (i=0; i<lastset; i++)
-      {
-      setSize[i] = this->SideSetListIndex[i+1] - this->SideSetListIndex[i];
-      if (index)
-        {
-        setDF[i] = index[i+1] - index[i];
-        }
-      else
-        {
-        setDF[i] = 0;
-        }
-      }
-
-    setSize[lastset] = this->SumSidesPerSideSet - this->SideSetListIndex[lastset];
-
-    if (index)
-      {
-      setDF[lastset] = newSize - index[lastset];
-      }
-    else
-      {
-      setDF[lastset] = 0;
-      }
-
-    FREE(this->SideSetNumberOfDistributionFactors);
-    this->SideSetNumberOfDistributionFactors = setDF;
-
-    FREE(this->SideSetSize);
-    this->SideSetSize = setSize;
-    }
-
-  return 0;
-}
-int *vtkModelMetadata::CopyInts(int *vals, int num)
-{
-  int *newvals = NULL;
-
-  if (num == 0) return newvals;
-
-  newvals = new int [num];
-  memcpy(newvals, vals, sizeof(int) * num);
-
-  return newvals;
-}
-char **vtkModelMetadata::CopyLines(char **lines, int num)
-{
-  char **newlines = NULL;
-
-  if (num == 0) return newlines;
-
-  newlines = new char * [num];
-
-  for (int i=0; i<num; i++)
-    {
-    newlines[i]  = vtkModelMetadata::StrDupWithNew(lines[i]);
-    }
-
-  return newlines;
-}
-void vtkModelMetadata::ExtractCellsFromBlockData(vtkModelMetadataSTLCloak *idset,
-                          vtkModelMetadata *mmd)
-{
-  int i, j, k;
-  int nblocks, nelts;
-
-  if ((nblocks = this->NumberOfBlocks) < 1) return;
-
-  if ((nelts = this->SumElementsPerBlock) < 1) return;
-
-  char *extractElt = new char [nelts];
-
-  int *eltIds = this->BlockElementIdList;
-  float *eltAtts = this->BlockAttributes;
-  int *blockSize = this->BlockNumberOfElements;
-  int *blockAtts = this->BlockNumberOfAttributesPerElement;
-
-  int *newEltIds = NULL;
-  float *newEltAtts = NULL;
-  int *newBlockSize = new int [nblocks];
-
-  int numNewElts = 0;
-  int numNewAtts = 0;
-  int ii=0;
-
-  for (i=0; i<nblocks; i++)
-    {
-    newBlockSize[i] = 0;
-
-    for (j=0; j<blockSize[i]; j++)
-      {
-      std::set<int>::iterator it = idset->IntSet.find(eltIds[ii]);
-
-      if (it == idset->IntSet.end())
-        {
-        extractElt[ii] = 0;
-        }
-      else
-        {
-        extractElt[ii] = 1;
-        newBlockSize[i]++;
-        }
-
-      ii++;
-      }
-
-    numNewElts += newBlockSize[i];
-    numNewAtts += (newBlockSize[i] * blockAtts[i]);
-    }
-
-  if (numNewElts > 0)
-    {
-    newEltIds = new int [numNewElts];
-
-    if (numNewAtts > 0)
-      {
-      newEltAtts = new float [numNewAtts];
-      }
-
-    int *nextId = newEltIds;
-    float *nextAtt = newEltAtts;
-
-    ii=0;
-
-    for (i=0; i<nblocks; i++)
-      {
-      for (j=0; j<blockSize[i]; j++)
-        {
-        if (extractElt[ii++])
-          {
-          *nextId++ = *eltIds;
-
-          for (k=0; k<blockAtts[i]; k++)
-            {
-            *nextAtt++ = eltAtts[k];
-            }
-          }
-
-        eltIds++;
-        eltAtts += blockAtts[i];
-        }
-      }
-    }
-
-  mmd->SetBlockNumberOfElements(newBlockSize);
-
-  if (newEltIds)
-    {
-    mmd->SetBlockElementIdList(newEltIds);
-
-    if (newEltAtts)
-      {
-      mmd->SetBlockAttributes(newEltAtts);
-      }
-    }
-
-  delete [] extractElt;
-
-  return;
-}
-void vtkModelMetadata::ExtractNodesFromNodeSetData(vtkModelMetadataSTLCloak *idset,
-                          vtkModelMetadata *mmd)
-{
-  int i, j;
-  int nnsets, nnodes;
-
-  if ((nnsets = this->NumberOfNodeSets) < 1) return;
-
-  if ((nnodes = this->SumNodesPerNodeSet) < 1) return;
-
-  char *extractNodes = new char [nnodes];
+  float *newDistFact=NULL;
+  int *newDistFactIndex=NULL;
+  int newDistFactLength = 0;
 
-  int *nsIds = this->NodeSetNodeIdList;
-  float *nsDF = this->NodeSetDistributionFactors;
-  int *nsSize = this->NodeSetSize;
-  int *nsNumDF = this->NodeSetNumberOfDistributionFactors;
+  int maxIdListLength = id1Len + id2Len;
+  int maxDistFactLength = dist1Len + dist2Len;
 
-  int *newnsIds = NULL;
-  float *newnsDF = NULL;
-  int *newnsSize = new int [nnsets];
-  int *newnsNumDF = new int [nnsets];
+  newIdList = new int [maxIdListLength];
+  newIdListIndex = new int [numSubLists];
+  newIdListIndex[0] = 0;
 
-  int numNewNodes = 0;
-  int numNewDF = 0;
-  int ii=0;
+  int distFact = (maxDistFactLength > 0);
 
-  for (i=0; i<nnsets; i++)
+  if (distFact)
     {
-    newnsSize[i] = 0;
-
-    for (j=0; j<nsSize[i]; j++)
-      {
-      std::set<int>::iterator it = idset->IntSet.find(nsIds[ii]);
-
-      if (it == idset->IntSet.end())
-        {
-        extractNodes[ii] = 0;
-        }
-      else
-        {
-        extractNodes[ii] = 1;
-        newnsSize[i]++;
-        }
-
-      ii++;
-      }
-
-    if (nsNumDF[i] > 0) newnsNumDF[i] = newnsSize[i];
-    else                newnsNumDF[i] = 0;
-
-    numNewNodes += newnsSize[i];
-    numNewDF += newnsNumDF[i];
+    newDistFact = new float [maxDistFactLength];
+    newDistFactIndex = new int [numSubLists];
+    newDistFactIndex[0] = 0;
     }
 
-  if (numNewNodes > 0)
+  if (id1Len == 0)
     {
-    newnsIds = new int [numNewNodes];
+    memcpy(newIdList, id2, sizeof(int) * id2Len);
+    memcpy(newIdListIndex, id2Idx, sizeof(int) * numSubLists);
+    newIdListLength = id2Len;
 
-    if (numNewDF > 0)
+    if (newDistFact)
       {
-      newnsDF = new float [numNewDF];
+      memcpy(newDistFact, dist2, sizeof(float) * dist2Len);
+      memcpy(newDistFactIndex, dist2Idx, sizeof(int) * numSubLists);
       }
 
-    int *nextId = newnsIds;
-    float *nextDF = newnsDF;
-    ii = 0;
-
-    for (i=0; i<nnsets; i++)
-      {
-      int hasDF = (nsNumDF[i] > 0);
-
-      for (j=0; j<nsSize[i]; j++)
-        {
-        if (extractNodes[ii++])
-          {
-          *nextId++ = *nsIds;
-
-          if (hasDF)
-            {
-            *nextDF++ = *nsDF;
-            }
-          }
-
-        nsIds++;
-        if (hasDF) nsDF++;
-        }
-      }
+    newDistFactLength = dist2Len;
     }
-
-  mmd->SetNodeSetSize(newnsSize);
-  mmd->SetNodeSetNumberOfDistributionFactors(newnsNumDF);
-
-  if (newnsIds)
+  else if (id2Len == 0)
     {
-    mmd->SetNodeSetNodeIdList(newnsIds);
+    memcpy(newIdList, id1, sizeof(int) * id1Len);
+    memcpy(newIdListIndex, id1Idx, sizeof(int) * numSubLists);
+    newIdListLength = id1Len;
 
-    if (newnsDF)
+    if (newDistFact)
       {
-      mmd->SetNodeSetDistributionFactors(newnsDF);
+      memcpy(newDistFact, dist1, sizeof(float) * dist1Len);
+      memcpy(newDistFactIndex, dist1Idx, sizeof(int) * numSubLists);
       }
-    }
 
-  delete [] extractNodes;
+    newDistFactLength = dist1Len;
+    }
+  else
+    {
+    int nextid = 0;
+    int nextdf = 0;
 
-  return;
-}
-void vtkModelMetadata::ExtractSidesFromSideSetData(vtkModelMetadataSTLCloak *idset,
-                          vtkModelMetadata *mmd)
-{
-  int i, j;
-  int nssets, nsides;
+    float *dist = NULL;
+    int numdf = 0;
 
-  if ((nssets = this->NumberOfSideSets) < 1) return;
+    for (i=0; i<numSubLists; i++)
+      {
+      int lastList = (i == numSubLists-1);
 
-  if ((nsides = this->SumSidesPerSideSet) < 1) return;
+      int *ids = id1 + id1Idx[i];
+      int numids = (lastList ? id1Len : id1Idx[i+1]) - id1Idx[i];
+      if (numids > 0)
+        {
+        memcpy(newIdList + nextid, ids, numids * sizeof(int));
+        }
 
-  char *extractSides = new char [nsides];
+      nextid += numids;
 
-  int *ssElts = this->SideSetElementList;
-  int *ssSides = this->SideSetSideList;
-  int *ssNumDFperSide = this->SideSetNumDFPerSide;
-  float *ssDF = this->SideSetDistributionFactors;
-  int *ssSize = this->SideSetSize;
+      if (distFact)
+        {
+        dist = dist1 + dist1Idx[i];
+        numdf = (lastList ? dist1Len : dist1Idx[i+1]) - dist1Idx[i];
+        if (numdf > 0)
+          {
+          memcpy(newDistFact + nextdf, dist, numdf * sizeof(float));
+          nextdf += numdf;
+          }
+        }
 
-  int *newssElts = NULL;
-  int *newssSides = NULL;
-  int *newssNumDFperSide = NULL;
-  float *newssDF = NULL;
-  int *newssSize = new int [nssets];
-  int *newssNumDF = new int [nssets];
+      // Make a set of the ids we've just written.  We only want to add
+      // ids from list 2 if they did not exist in list 1.
 
-  int numNewSides = 0;
-  int numNewDF = 0;
-  int ii=0;
+      std::set<int> idSet;
 
-  for (i=0; i<nssets; i++)
-    {
-    newssSize[i] = 0;
-    newssNumDF[i] = 0;
+      for (id=0; id < numids; id++)
+        {
+        idSet.insert(ids[id]);
+        }
 
-    for (j=0; j<ssSize[i]; j++)
-      {
-      std::set<int>::iterator it = idset->IntSet.find(ssElts[ii]);
+      ids = id2 + id2Idx[i];
+      numids = (lastList ? id2Len : id2Idx[i+1]) - id2Idx[i];
 
-      if (it == idset->IntSet.end())
+      if (distFact)
         {
-        extractSides[ii] = 0;
+        dist = dist2 + dist2Idx[i];
+        numdf = (lastList ? dist2Len : dist2Idx[i+1]) - dist2Idx[i];
         }
       else
         {
-        extractSides[ii] = 1;
-        newssSize[i]++;
-        newssNumDF[i] += ssNumDFperSide[ii];
+        numdf = 0;
         }
 
-      ii++;
-      }
-
-    numNewSides += newssSize[i];
-    numNewDF += newssNumDF[i];
-    }
+      for (id=0; id < numids; id++)
+        {
+        std::pair<std::set<int>::iterator, bool> inserted =
 
-  if (numNewSides > 0)
-    {
-    newssElts = new int [numNewSides];
-    newssSides = new int [numNewSides];
-    newssNumDFperSide = new int [numNewSides];
+          idSet.insert(ids[id]);
 
-    if (numNewDF > 0)
-      {
-      newssDF = new float [numNewDF];
-      }
+        if (inserted.second)    // here's a new ID
+          {
+          newIdList[nextid++] = ids[id];
 
-    int nextId = 0;
-    int nextDF = 0;
+          if (numdf > 0)
+            {
+            // There is either 1 or 0 distribution factors
 
-    for (ii=0; ii<nsides; ii++)
-      {
-      int ndf = ssNumDFperSide[ii];
+            newDistFact[nextdf++] = dist[id];
+            }
+          }
+        }
 
-      if (extractSides[ii])
+      if (!lastList)
         {
-        newssElts[nextId] = ssElts[ii];
-        newssSides[nextId] = ssSides[ii];
-        newssNumDFperSide[nextId] = ndf;
-
-        nextId++;
-
-        for (i=0; i<ndf; i++)
+        newIdListIndex[i+1] = nextid;
+        if (distFact)
           {
-          newssDF[nextDF++] = ssDF[i];
+          newDistFactIndex[i+1] = nextdf;
           }
         }
-
-      ssDF += ndf;
-      }
-    }
-
-  delete [] extractSides;
-
-  mmd->SetSideSetSize(newssSize);
-  mmd->SetSideSetNumberOfDistributionFactors(newssNumDF);
-
-  if (newssElts)
-    {
-    mmd->SetSideSetElementList(newssElts);
-    mmd->SetSideSetSideList(newssSides);
-    mmd->SetSideSetNumDFPerSide(newssNumDFperSide);
-
-    if (newssDF)
-      {
-      mmd->SetSideSetDistributionFactors(newssDF);
-      }
-    }
-
-  return;
-}
-
-vtkModelMetadata *vtkModelMetadata::ExtractGlobalMetadata()
-{
-  vtkModelMetadata *mmd = vtkModelMetadata::New();
-
-  mmd->MergeGlobalInformation(this);
-
-  return mmd;
-}
-
-vtkModelMetadata *vtkModelMetadata::ExtractModelMetadata(
-  vtkIdTypeArray *globalCellIdList,
-  vtkDataSet *grid)
-{
-  int i;
-
-  vtkModelMetadata *em = this->ExtractGlobalMetadata();
-
-  vtkIdType ncells = globalCellIdList->GetNumberOfTuples();
-
-  if (ncells < 1)
-    {
-    return em;
-    }
-
-  vtkModelMetadataSTLCloak *cellIds =
-    new vtkModelMetadataSTLCloak;     // the cells we want to extract
-  vtkModelMetadataSTLCloak *nodeIds =
-    new vtkModelMetadataSTLCloak;     // the nodes they include
-
-  vtkIdType *ids = globalCellIdList->GetPointer(0);
-
-  for (i=0; i<ncells; i++)
-    {
-    cellIds->IntSet.insert(ids[i]);
-    }
-
-  ncells = cellIds->IntSet.size();
-
-  vtkDataArray *ca = grid->GetCellData()->GetGlobalIds();
-  vtkDataArray *pa = grid->GetPointData()->GetGlobalIds();
-
-  if (!ca || !pa)
-    {
-    vtkErrorMacro(<< "vtkModelMetadata::ExtractModelMetadata needs id arrays");
-    em->Delete();
-    return NULL;
-    }
-
-  vtkIdTypeArray *ica  = vtkIdTypeArray::SafeDownCast(ca);
-  vtkIdTypeArray *ipa  = vtkIdTypeArray::SafeDownCast(pa);
-
-  if (!ica || !ipa)
-    {
-    vtkErrorMacro(<< "vtkModelMetadata::ExtractModelMetadata id arrays not vtkIdType");
-    em->Delete();
-    return NULL;
-    }
-
-  vtkIdType *gcids = ica->GetPointer(0);  // global cell ids
-  vtkIdType *gpids = ipa->GetPointer(0);  // global point ids
-
-  int gridCells = grid->GetNumberOfCells();
-  vtkIdList *ptIds = vtkIdList::New();
-
-  for (vtkIdType c = 0; c<gridCells; c++)
-    {
-    std::set<int>::iterator it = cellIds->IntSet.find(gcids[c]);
-
-    if (it != cellIds->IntSet.end())
-      {
-      grid->GetCellPoints(c, ptIds);
-
-      vtkIdType npoints = ptIds->GetNumberOfIds();
-
-      for (i=0; i<npoints; i++)
+      else
         {
-        nodeIds->IntSet.insert(gpids[ptIds->GetId(i)]);
+        newIdListLength = nextid;
+        newDistFactLength = nextdf;
         }
       }
     }
 
-  ptIds->Delete();
-
-  // Block information
-
-  if (this->NumberOfBlocks)
+  if (idNew)
     {
-    this->ExtractCellsFromBlockData(cellIds, em);
+    *idNew = newIdList;
     }
-
-  // Node set information
-
-  if (this->NumberOfNodeSets)
+  else
     {
-    this->ExtractNodesFromNodeSetData(nodeIds, em);
+    delete [] newIdList;
     }
-
-  // Side set information
-
-  if (this->NumberOfSideSets)
+  if (idNewIdx)
     {
-    this->ExtractSidesFromSideSetData(cellIds, em);
+    *idNewIdx = newIdListIndex;
     }
-
-  delete cellIds;
-  delete nodeIds;
-
-  return em;
-}
-char *vtkModelMetadata::StrDupWithNew(const char *s)
-{
-  char *newstr = NULL;
-
-  if (s)
+  else
     {
-    int len = static_cast<int>(strlen(s));
-    if (len == 0)
-      {
-      newstr = new char [1];
-      newstr[0] = '\0';
-      }
-    else
-      {
-      newstr = new char [len + 1];
-      strcpy(newstr, s);
-      }
+    delete [] newIdListIndex;
     }
-
-  return newstr;
-}
-
-char *vtkModelMetadata::FindOriginalNodeVariableName(const char *name, int component)
-{
-  int idx = -1;
-
-  for (int i=0; i<this->NumberOfNodeVariables; i++)
+  if (idNewLen)
     {
-    if (!strcmp(name, this->NodeVariableNames[i]))
-      {
-      idx = i;
-      break;
-      }
+    *idNewLen = newIdListLength;
     }
 
-  if (idx < 0)
+  if (distNew)
     {
-    return NULL;
+    *distNew = newDistFact;
     }
-
-  int origIdx = this->MapToOriginalNodeVariableNames[idx];
-
-  if ( (component<0) ||
-       (component >= this->NodeVariableNumberOfComponents[idx]))
+  else if (newDistFact)
     {
-    return NULL;
+    delete [] newDistFact;
     }
-
-  return this->OriginalNodeVariableNames[origIdx + component];
-}
-int vtkModelMetadata::ElementVariableIsDefinedInBlock(char *varname, int blockId)
-{
-  int i;
-  int varIdx = -1;
-
-  if (this->AllVariablesDefinedInAllBlocks)
+  if (distNewIdx)
     {
-    return 1;
+    *distNewIdx = newDistFactIndex;
     }
-
-  for (i=0; i<this->OriginalNumberOfElementVariables; i++)
+  else if (newDistFactIndex)
     {
-    if (!strcmp(varname, this->OriginalElementVariableNames[i]))
-      {
-      varIdx = i;
-      break;
-      }
+    delete [] newDistFactIndex;
     }
-
-  int blockIdx = this->GetBlockLocalIndex(blockId);
-
-  if ( (blockIdx<0) || (varIdx<0))
+  if (distNewLen)
     {
-    return 1;   // by default we say everything is defined
+    *distNewLen = newDistFactLength;
     }
 
-  int loc = (blockIdx * this->OriginalNumberOfElementVariables) + varIdx;
-
-  return (int)this->ElementVariableTruthTable[loc];
+  return 0;
 }
 
-char *vtkModelMetadata::FindOriginalElementVariableName(const char *name, int component)
-{
-  int idx = -1;
-
-  for (int i=0; i<this->NumberOfElementVariables; i++)
-    {
-    if (!strcmp(name, this->ElementVariableNames[i]))
-      {
-      idx = i;
-      break;
-      }
-    }
-
-  if (idx < 0)
-    {
-    return NULL;
-    }
-
-  int origIdx = this->MapToOriginalElementVariableNames[idx];
-
-  if ( (component<0) ||
-       (component >= this->ElementVariableNumberOfComponents[idx]))
-    {
-    return NULL;
-    }
-
-  return this->OriginalElementVariableNames[origIdx + component];
-}
 //-------------------------------------
 // Display contents for debugging
 //-------------------------------------
diff --git a/IO/Exodus/vtkModelMetadata.h b/IO/Exodus/vtkModelMetadata.h
index 92e11195b47..92113871cee 100644
--- a/IO/Exodus/vtkModelMetadata.h
+++ b/IO/Exodus/vtkModelMetadata.h
@@ -19,9 +19,7 @@
 
 // .NAME vtkModelMetadata - This class encapsulates the metadata
 //   that appear in mesh-based file formats but do not appear in
-//   vtkUnstructuredGrid.  It can pack itself into the field
-//   arrays of a vtkUnstructuredGrid, and be unpacked by metadata
-//   aware filters and writers later on.
+//   vtkUnstructuredGrid.
 //
 // .SECTION Description
 //   This class is inspired by the Exodus II file format, but
@@ -120,10 +118,6 @@ public:
   //   Set the information lines.
   void SetInformationLines(int numLines, char **lines);
 
-  // Description:
-  //   Add an information line.
-  void AddInformationLine(char *info);
-
   // Description:
   //   Get a pointer to all the information lines.  The number
   //   of lines is returned;
@@ -140,14 +134,6 @@ public:
   //   pointer and delete the records when done.
   void SetQARecords(int numberOfRecords, char *QARecords[][4]);
 
-  // Description:
-  //   Add a QA record.  They fields are:
-  //    The code name
-  //    The code version number
-  //    The date (MM/DD/YY or NULL for today)
-  //    The time (HH:MM:SS or NULL for right now)
-  void AddQARecord(char *name, char *version, char *date, char *time);
-
   // Description:
   //   Get a pointer to the 4 fields of a QA record
   void GetQARecord(int which, char **name, char **version,
@@ -525,16 +511,6 @@ public:
   int GetAllVariablesDefinedInAllBlocks() const {
     return this->AllVariablesDefinedInAllBlocks;}
 
-  // Description:
-  //   If the element variable named is defined for the block Id
-  //   provided (in the element variable truth table) return a
-  //   1, otherwise return a 0.  If the variable name or block Id
-  //   are unrecognized, the default value of 1 is returned.
-  //   (This is an "original" variable name, from the file,
-  //   not a name created for the vtkUnstructuredGrid.  Use
-  //   FindOriginal*VariableName to map between the two.)
-  int ElementVariableIsDefinedInBlock(char *varname, int blockId);
-
   // Description:
   //   The ModelMetadata object may contain these lists:
   //    o  the variables in the original data file
@@ -594,28 +570,6 @@ public:
   //   read into VTK.
   char *FindOriginalNodeVariableName(const char *name, int component);
 
-  // Description:
-  //   Static function that returns 1 if the vtkUnstructuredGrid
-  //   has metadata packed into it's field arrays, and 0 otherwise.
-  static int HasMetadata(vtkDataSet *grid);
-
-  // Description:
-  //   Static function that removes the packed metadata arrays
-  //   from a dataset.
-  static void RemoveMetadata(vtkDataSet *grid);
-
-  // Description:
-  //   Pack this object's metadata into a field array of a dataset.
-  void Pack(vtkDataSet *ugrid);
-
-  // Description:
-  //   Unpack the metadata stored in a dataset,
-  //   and initialize this object with it.  Return 1 if there's
-  //   no metadata packed into the grid, 0 if OK.
-  //   If deleteIt is ON, then delete the grid's packed data after
-  //   unpacking it into the object.
-  int Unpack(vtkDataSet *ugrid, int deleteIt);
-
   // Description:
   //   In order to write Exodus files from vtkUnstructuredGrid
   //   objects that were read from Exodus files, we need to know
@@ -636,40 +590,6 @@ public:
   int AddUGridNodeVariable(char *ugridVarName, char *origName, int numComponents);
   int RemoveUGridNodeVariable(char *ugridVarName);
 
-  // Description:
-  //   In VTK we take vtkUnstructuredGrids and perform
-  //   operations on them, including subsetting and merging
-  //   grids.  We need to modify the metadata object
-  //   when this happens.  MergeModelMetadata merges the supplied
-  //   model (both global and local metadata) into this model.
-  //   The models must be from the same file set.
-  //
-  //   MergeModelMetadata assumes that no element in one metadata
-  //   object appears in the other.  (It doesn't test for duplicate
-  //   elements when merging the two metadata objects.)
-  int MergeModelMetadata(const vtkModelMetadata *em);
-
-  // Description:
-  //   The metadata is divided into global metadata and local
-  //   metadata.  MergeGlobalInformation merges just the
-  //   global metadata of the supplied object into the
-  //   global metadata of this object.
-  int MergeGlobalInformation(const vtkModelMetadata *em);
-
-  // Description:
-  //   Create and return a new metadata object which contains
-  //   the information for the subset of global cell IDs provided.
-  //   We need the grid containing the cells so we can find point
-  //   Ids as well, and also the name of the global cell ID array
-  //   and the name of the global point ID array.
-  vtkModelMetadata *ExtractModelMetadata(vtkIdTypeArray *globalCellIdList,
-                                         vtkDataSet *grid);
-
-  // Description:
-  //   Create and return a new metadata object containing only the
-  //   global metadata of this metadata object.
-  vtkModelMetadata *ExtractGlobalMetadata();
-
   // Description:
   //   Free selected portions of the metadata when updating values
   //   in the vtkModelMetadata object.  Resetting a particular field,
@@ -722,24 +642,8 @@ private:
   int BuildSideSetListIndex();
   int BuildSideSetDistributionFactorIndex();
 
-  int InitializeFromSizeArray(vtkIntArray *ia, int &maxStr, int &maxLine);
-  vtkIntArray *PackSizeArray(int maxStr, int maxLine);
-  int InitializeFromIntArray(vtkModelMetadata *sizes, vtkIntArray *ia);
-  vtkIntArray *PackIntArray();
-  int InitializeFromCharArray(vtkModelMetadata *sizes,
-                   vtkCharArray *uca, int maxStr, int maxLine);
-  vtkCharArray *PackCharArray(int maxStr, int maxLine);
-  int InitializeFromFloatArray(vtkFloatArray *fa);
-  vtkFloatArray *PackFloatArray();
-
   static char *StrDupWithNew(const char *s);
 
-  static char *WriteLines(char *p, int maxLines, int maxLen, char **lines);
-  static char *ReadLines(char ***to, int maxLines,
-                            int maxLen, char *from);
-  static char **CopyLines(char **lines, int num);
-  static int *CopyInts(int *vals, int num);
-
   static int FindNameOnList(char *name, char **list, int listLen);
 
   int MergeIdLists(int numSubLists,
@@ -760,13 +664,6 @@ private:
     int *id2, int *id2Idx, int id2Len,
     int **idNew, int **idNewIdx, int *idNewLen);
 
-  void ExtractCellsFromBlockData(vtkModelMetadataSTLCloak *idset,
-                                 vtkModelMetadata *mmd);
-  void ExtractNodesFromNodeSetData(vtkModelMetadataSTLCloak *idset,
-                                   vtkModelMetadata *mmd);
-  void ExtractSidesFromSideSetData(vtkModelMetadataSTLCloak *idset,
-                                   vtkModelMetadata *mmd);
-
   void ShowFloats(const char *what, int num, float *f);
   void ShowLines(const char *what, int num, char **l);
   void ShowIntArray(const char *what, int numx, int numy, int *id);
-- 
GitLab