[prev in list] [next in list] [prev in thread] [next in thread] 

List:       paraview
Subject:    [Paraview] Ensight filename numbers patch
From:       "Olesen, Mark" <Mark.Olesen () emcontechnologies ! com>
Date:       2008-04-24 14:14:33
Message-ID: E05ABC9A7FBFB942B70D7533AF5BE68D643055 () augexmsg001 ! euro ! corp ! dir
[Download RAW message or body]

I finally found out the root of my problem and have attached a
corresponding patch.

Problem: the VTK EnSight reader had complete garbage when expanding
wildcard names (eg, "scalar per element: k  data/********/k").

Cause: the reader assumed that the filename numbers occur on a single
line and immediately follow the "filename numbers:" introducer and did
not check the sscanf() return value. This can result in very incorrect
values for the filenameNum and/or useless animation values.

Example of a correct syntax (according to ens_checker) that triggers the
problem:

TIME
time set:        1
number of steps: 72
filename numbers:
 40           80           120          160          200          240
 280          320          360          400          440          480
 520          560          600          640          680          720
...


The patch has been created against the CVS HEAD
(vtkEnSightReader, "$Revision: 1.75 $");

If the mailing list is not the appropriate means of submitting a patch,
please let me know.

/mark

This e-mail message and any attachments may contain 
legally privileged, confidential or proprietary Information, 
or information otherwise protected by law of EMCON 
Technologies, its affiliates, or third parties. This notice 
serves as marking of its “Confidential” status as defined 
in any confidentiality agreements concerning the sender 
and recipient. If you are not the intended recipient(s), 
or the employee or agent responsible for delivery of this 
message to the intended recipient(s), you are hereby 
notified that any dissemination, distribution or copying 
of this e-mail message is strictly prohibited. 
If you have received this message in error, please 
immediately notify the sender and delete this e-mail 
message from your computer.

["ensight-filename-numbers.patch" (application/octet-stream)]

--- VTK/IO/vtkEnSightReader.cxx.orig	2008-04-22 11:41:14.000000000 +0200
+++ VTK/IO/vtkEnSightReader.cxx	2008-04-24 15:52:51.000000000 +0200
@@ -204,11 +204,11 @@
       cnt++;
       }
     this->ActualTimeValue = steps[cnt];
     }
 
-  cout << "Executing with: " << this->ActualTimeValue << endl;
+  // cout << "Executing with: " << this->ActualTimeValue << endl;
 
   int i, timeSet, fileSet, timeStep, timeStepInFile, fileNum;
   vtkDataArray *times;
   vtkIdList *numStepsList, *filenameNumbers;
   float newTime;
@@ -456,13 +456,11 @@
 //----------------------------------------------------------------------------
 int vtkEnSightReader::ReadCaseFile()
 {
   char line[256], formatLine[256];
   char subLine[256], subLine2[256];
-  int stringRead;
-  int timeSet, fileSet, numTimeSteps, i, filenameNum, increment, lineRead;
-  float timeStep;
+  int lineRead, timeSet, fileSet, numTimeSteps = 0;
   
   // Initialize
   //
   if (!this->CaseFileName)
     {
@@ -494,11 +492,11 @@
     return 0;
     }
 
   this->TimeSets->RemoveAllItems();
 
-  for (i = 0; i < this->NumberOfVariables; i++)
+  for (int i = 0; i < this->NumberOfVariables; i++)
     {
     delete [] this->VariableFileNames[i];
     this->VariableFileNames[i] = NULL;
     delete [] this->VariableDescriptions[i];
     this->VariableDescriptions[i] = NULL;
@@ -508,11 +506,11 @@
   delete [] this->VariableDescriptions;
   this->VariableDescriptions = NULL;
   delete [] this->VariableTypes;
   this->VariableTypes = NULL;
   
-  for (i = 0; i < this->NumberOfComplexVariables; i++)
+  for (int i = 0; i < this->NumberOfComplexVariables; i++)
     {
     delete [] this->ComplexVariableFileNames[2*i];
     this->ComplexVariableFileNames[2*i] = NULL;
     delete [] this->ComplexVariableFileNames[2*i+1];
     this->ComplexVariableFileNames[2*i+1] = NULL;
@@ -535,12 +533,11 @@
     {
     // found the FORMAT section
     vtkDebugMacro("*** FORMAT section");
     this->ReadNextDataLine(line);
     
-    stringRead = sscanf(line, " %*s %*s %s", subLine);
-    if (stringRead == 1)
+    if (sscanf(line, " %*s %*s %s", subLine) == 1)
       {
       if (strcmp(subLine, "gold") == 0 &&
           strcmp(this->GetClassName(), "vtkEnSight6Reader") == 0)
         {
         // The class is vtkEnSight6Reader, but the case file says "gold".
@@ -915,11 +912,11 @@
           this->AddVariableType();
           this->NumberOfTensorsSymmPerElement++;
           }
         else
           {
-          vtkErrorMacro("Unknow type, faulty line was:" << line );
+          vtkErrorMacro("Unknown type, faulty line was:" << line );
           }
         this->AddVariableFileName(subLine);
         this->NumberOfVariables++;
         }
       else if (strncmp(line, "complex", 6) == 0)
@@ -1073,64 +1070,117 @@
     
     this->UseTimeSetsOn();
     while(this->ReadNextDataLine(line) != 0 &&
           strncmp(line, "FILE", 4) != 0)
       {
-      sscanf(line, "%*s %*s %d", &timeSet);
+      // parse 'time set: <int>'
+      if (sscanf(line, "%*s %*s %d", &timeSet) != 1)
+        {
+        vtkErrorMacro("error reading 'time set: <int>'");
+        }
       this->TimeSetIds->InsertNextId(timeSet);
       this->ReadNextDataLine(line);
-      sscanf(line, "%*s %*s %*s %d", &numTimeSteps);
+      // parse 'number of steps: <int>'
+      if (sscanf(line, "%*s %*s %*s %d", &numTimeSteps) != 1)
+        {
+        vtkErrorMacro("error reading 'number of steps: <int>'");
+        }
       this->ReadNextDataLine(line);
+      // parse 'filename numbers:'
+      // parse 'filename start number:'
+      // parse 'filename increment:'
       if (strncmp(line, "filename", 8) == 0)
         {
         vtkIdList *filenameNumbers = vtkIdList::New();
         this->TimeSetsWithFilenameNumbers->InsertNextId(timeSet);
         sscanf(line, "%*s %s", subLine);
         if (strncmp(subLine, "numbers", 7) == 0)
           {
+          // parsing 'filename numbers:'
+          // NB: the values may start on the next line and
+          //     can span several lines
           strcpy(formatLine, "%*s %*s");
           strcpy(subLine, "%*s %*s");
-          for (i = 0; i < numTimeSteps; i++)
+          for (int i = 0; i < numTimeSteps; i++)
             {
+            int filenameNum;
+
             strcat(formatLine, " %d");
-            sscanf(line, formatLine, &filenameNum);
-            filenameNumbers->InsertNextId(filenameNum);
             strcat(subLine, " %*d");
+
+            // get next line as required, possible infinite loop on bad data
+            while (sscanf(line, formatLine, &filenameNum) != 1)
+              {
+              vtkDebugMacro("old line:'" << line << "'");
+              lineRead = this->ReadNextDataLine(line);
+              strcpy(formatLine, " %d");
+              strcpy(subLine, " %*d");
+              if (!lineRead)
+                {
+                vtkErrorMacro("error while reading 'filename numbers:' at index " << i);
+                }
+              }
+
+            // read okay: insert
+            filenameNumbers->InsertNextId(filenameNum);
             strcpy(formatLine, subLine);
             }
           }
-        else
+        else if (strncmp(subLine, "start", 5) == 0)
           {
-          sscanf(line, "%*s %*s %*s %d", &filenameNum);
+          int filenameNum, increment;
+
+          // parsing 'filename start number:'
+          if (sscanf(line, "%*s %*s %*s %d", &filenameNum) != 1)
+            {
+            vtkErrorMacro("error reading 'filename start number:'");
+            }
           this->ReadNextDataLine(line);
-          sscanf(line, "%*s %*s %d", &increment);
-          for (i = 0; i < numTimeSteps; i++)
+          // should now be parsing 'filename increment:'
+          if (sscanf(line, "%*s %*s %d", &increment) != 1)
+            {
+            vtkWarningMacro("problem parsing filename increment, assume increment=1");
+            increment = 1;
+            }
+
+          for (int i = 0; i < numTimeSteps; i++)
             {
             filenameNumbers->InsertNextId(filenameNum + i*increment);
             }
           }
+        else
+          {
+          vtkErrorMacro("unknown/untreated filename set:'" << line <<"'");
+          }
+
         this->TimeSetFileNameNumbers->AddItem(filenameNumbers);
         filenameNumbers->Delete();
         this->ReadLine(line);
         }
+
+      // should be parsing 'time values:'
+      // NB: the values may start on the next line and
+      //     can span several lines
       vtkFloatArray *timeValues = vtkFloatArray::New();
       timeValues->SetNumberOfComponents(1);
       timeValues->SetNumberOfTuples(numTimeSteps);
       strcpy(formatLine, "%*s %*s");
       strcpy(subLine, "%*s %*s");
-      for (i = 0; i < numTimeSteps; i++)
+      for (int i = 0; i < numTimeSteps; i++)
         {
+        float timeStep;
+
         strcat(formatLine, " %f");
-        if (sscanf(line, formatLine, &timeStep) != 1)
+        strcat(subLine, " %*f");
+        while (sscanf(line, formatLine, &timeStep) != 1)
           {
-          this->ReadNextDataLine(line);
+          lineRead = this->ReadNextDataLine(line);
           strcpy(formatLine, " %f");
-          strcpy(subLine, "");
-          while (sscanf(line, formatLine, &timeStep) < 1)
+          strcpy(subLine, " %*f");
+          if (!lineRead)
             {
-            // The time values may start on the next line after "time values:".
-            this->ReadNextDataLine(line);
+            vtkErrorMacro("error while reading 'time values:' at index " << i);
             }
           }
         if (firstTimeStep)
           {
           this->MinimumTimeValue = timeStep;
@@ -1152,11 +1202,10 @@
             {
             this->MaximumTimeValue = timeStep;
             }
           }
         timeValues->SetComponent(i, 0, timeStep);
-        strcat(subLine, " %*f");
         strcpy(formatLine, subLine);
         }
       this->TimeSets->AddItem(timeValues);
       timeValues->Delete();
       }
@@ -1177,10 +1226,11 @@
       if (strncmp(line, "filename", 8) == 0)
         {
         this->FileSetsWithFilenameNumbers->InsertNextId(fileSet);
         while (lineRead != 0 && strncmp(line, "filename", 8) == 0)
           {
+          int filenameNum;
           sscanf(line, "%*s %*s %d", &filenameNum);
           filenameNums->InsertNextId(filenameNum);
           this->ReadNextDataLine(line);
           sscanf(line, "%*s %*s %*s %d", &numTimeSteps);
           numSteps->InsertNextId(numTimeSteps);


_______________________________________________
ParaView mailing list
ParaView@paraview.org
http://www.paraview.org/mailman/listinfo/paraview


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic