Applied initial patches for wx2.8 compatibility
[ctsim.git] / libctsupport / plotfile.cpp
index ef492d64d47a06f7b6761cbff812d093ad772ef9..86298701b3135122a9bf08db8bc11306cae9ad69 100644 (file)
@@ -1,15 +1,15 @@
 /*****************************************************************************
 ** FILE IDENTIFICATION
 **
-**     Name:         plotfile.cpp
+**      Name:         plotfile.cpp
 **      Purpose:      plotfile class
-**     Programmer:   Kevin Rosenberg
-**     Date Started: Dec 2000
+**      Programmer:   Kevin Rosenberg
+**      Date Started: Dec 2000
 **
 **  This is part of the CTSim program
-**  Copyright (C) 1983-2000 Kevin Rosenberg
+**  Copyright (c) 1983-2001 Kevin Rosenberg
 **
-**  $Id: plotfile.cpp,v 1.11 2001/01/07 22:53:36 kevin Exp $
+**  $Id$
 **
 **  This program is free software; you can redistribute it and/or modify
 **  it under the terms of the GNU General Public License (version 2) as
@@ -64,17 +64,17 @@ PlotFile::initHeaders ()
 }
 
 void
-PlotFile::setCurveSize (int nCols, int nRecords)
+PlotFile::setCurveSize (int nCols, int nRecords, bool bScatterPlot)
 {
   m_iNumColumns = nCols;
   m_iNumRecords = nRecords;
+  m_bScatterPlot = bScatterPlot;
   m_vecCurves.clear();
   m_vecCurves.reserve (m_iNumColumns * m_iNumRecords);
 }
 
 // Storage format
 //   a Column's records are stored sequentially. It begins at iCol * m_iNumRecords
-
 bool
 PlotFile::addColumn (int iCol, const double* const pdColData)
 {
@@ -82,10 +82,10 @@ PlotFile::addColumn (int iCol, const double* const pdColData)
     sys_error (ERR_SEVERE, "Illegal column number %d [PlotFile::addColumn]", iCol);
     return (false);
   }
-  
+
   for (int iRec = 0; iRec < m_iNumRecords; iRec++)
     m_vecCurves[ iRec + (iCol * m_iNumRecords) ] = pdColData [iRec];
-  
+
   return true;
 }
 
@@ -96,10 +96,10 @@ PlotFile::addColumn (int iCol, const float* const pdColData)
     sys_error (ERR_SEVERE, "Illegal column number %d [PlotFile::addColumn]", iCol);
     return (false);
   }
-  
+
   for (int iRec = 0; iRec < m_iNumRecords; iRec++)
     m_vecCurves[ iRec + (iCol * m_iNumRecords) ] = pdColData [iRec];
-  
+
   return true;
 }
 
@@ -110,10 +110,10 @@ PlotFile::getColumn (int iCol, double* pdColData) const
     sys_error (ERR_SEVERE, "Illegal column number %d [PlotFile::addColumn]", iCol);
     return;
   }
-  
+
   for (int iRec = 0; iRec < m_iNumRecords; iRec++)
     pdColData[iRec] = m_vecCurves[ iRec + (iCol * m_iNumRecords) ];
-  
+
 }
 
 bool
@@ -123,11 +123,11 @@ PlotFile::getMinMax (int iStartingCol, double& dMin, double& dMax) const
     sys_error (ERR_WARNING, "iStartingCol >= iNumColumns");
     return false;
   }
-  
+
   int iOffset = iStartingCol * m_iNumRecords;
   dMin = m_vecCurves[ 0 + iOffset ];
   dMax = dMin;
-  
+
   for (int iCol = iStartingCol; iCol < m_iNumColumns; iCol++) {
     int iOffset = iCol * m_iNumRecords;
     for (int iRec = 0; iRec < m_iNumRecords; iRec++) {
@@ -138,31 +138,31 @@ PlotFile::getMinMax (int iStartingCol, double& dMin, double& dMax) const
         dMax = dVal;
     }
   }
-  
+
   return true;
 }
 
-bool 
+bool
 PlotFile::statistics (int iStartingCol, double& min, double& max, double& mean, double& mode, double& median, double &stddev) const
 {
   if (iStartingCol >= m_iNumColumns) {
     sys_error (ERR_WARNING, "iStartingCol >= iNumColumns");
     return false;
   }
+
   int iNPoints = (m_iNumColumns - iStartingCol) * m_iNumRecords;
   std::vector<double> vec;
   vec.resize (iNPoints);
-  
+
   int iVec = 0;
   for (int iCol = iStartingCol; iCol < m_iNumColumns; iCol++) {
     int iOffset = iCol * m_iNumRecords;
     for (int iRec = 0; iRec < m_iNumRecords; iRec++)
       vec[iVec++] = m_vecCurves[ iRec + iOffset ];
   }
-  
+
   vectorNumericStatistics (vec, iNPoints, min, max, mean, mode, median, stddev);
-  
+
   return true;
 }
 
@@ -170,16 +170,16 @@ bool
 PlotFile::fileWrite (const char* const filename)
 {
   m_strFilename = filename;
-  
+
   fstream fs (m_strFilename.c_str(), std::ios::out | std::ios::trunc);
   if (fs.fail()) {
     sys_error (ERR_WARNING, "Error opening file %s for writing [fileCreate]", m_strFilename.c_str());
     return false;
   }
-  
+
   if (! headerWrite(fs) || ! columnsWrite (fs))
     return false;
-  
+
   return true;
 }
 
@@ -187,26 +187,26 @@ bool
 PlotFile::fileRead (const char* const filename)
 {
   m_strFilename = filename;
-  
+
 #ifdef MSVC
   fstream fs (m_strFilename.c_str(), std::ios::in);
 #else
-  fstream fs (m_strFilename.c_str(), std::ios::in | std::ios::nocreate);
+  fstream fs (m_strFilename.c_str(), std::ios::in); // | std::ios::nocreate);
 #endif
-  
+
   if (fs.fail()) {
     sys_error (ERR_WARNING, "Unable to open file %s [fileRead]", m_strFilename.c_str());
     return false;
   }
-  
+
   if (! headerRead(fs))
     return false;
-  
+
   setCurveSize (m_iNumColumns, m_iNumRecords);
-  
+
   if (! columnsRead(fs))
     return false;;
-  
+
   return true;
 }
 
@@ -217,7 +217,7 @@ PlotFile::headerRead (std::iostream& fs)
     sys_error (ERR_WARNING, "Tried to read header with file closed [headerRead]");
     return false;
   }
-  
+
   initHeaders();
   fs.seekg (0);
   bool bFinishedHeaders = false;
@@ -261,20 +261,20 @@ PlotFile::headerWrite (std::iostream& fs)
     sys_error (ERR_WARNING, "Tried to write header with ! fs");
     return false;
   }
-  
+
   fs.seekp (0);
   fs << m_iNumColumns << " " << m_iNumRecords << "\n";
 
   unsigned int i;
   for (i = 0; i < m_vecStrEzsetCommands.size(); i++)
       fs << m_vecStrEzsetCommands[i] << "\n";
-  
+
   for (i = 0; i < m_vecStrDescriptions.size(); i++)
       fs << "# " << m_vecStrDescriptions[i] << "\n";
-  
+
   if (! m_strDate.empty())
     fs << "# Date: " << m_strDate << "\n";
-    
+
   return ! fs.fail();
 }
 
@@ -286,20 +286,20 @@ PlotFile::columnsWrite (std::iostream& fs)
     sys_error (ERR_WARNING, "Tried to columnWrite with !fs");
     return false;
   }
-  
+
   fs << "<datapoints>\n";
-  
+
   int iStride = m_iNumRecords;
   for (int iRec = 0; iRec < m_iNumRecords; iRec++) {
     for (int iCol = 0; iCol < m_iNumColumns; iCol++)
       fs << m_vecCurves [iRec + (iCol * iStride)] << " ";
     fs << "\n";
   }
-  
+
   fs << "</datapoints>\n";
-  
+
   fs << "</plotfile>\n";
-  
+
   return ! fs.fail();
 }
 
@@ -311,7 +311,7 @@ PlotFile::columnsRead (std::iostream& fs)
     sys_error (ERR_WARNING, "Tried to arrayDataRead with ! fs");
     return false;
   }
-  
+
   if (m_iNumColumns == 0 || m_iNumRecords == 0) {
     sys_error (ERR_WARNING, "Called PlotFile::columnsRead with 0 columns or records");
     return false;