r309: plotfile changes
[ctsim.git] / libctsupport / plotfile.cpp
index b8744515cfc61ef8ac0a66e524e9dfecd1f1fed5..5a160cdbe4bbf31a1f18291b1f887e0962bc8c81 100644 (file)
@@ -9,7 +9,7 @@
 **  This is part of the CTSim program
 **  Copyright (C) 1983-2000 Kevin Rosenberg
 **
-**  $Id: plotfile.cpp,v 1.2 2000/12/20 14:39:09 kevin Exp $
+**  $Id: plotfile.cpp,v 1.3 2000/12/20 20:08:48 kevin Exp $
 **
 **  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
@@ -117,6 +117,55 @@ PlotFile::getColumn (int iCol, double* pdColData) const
 \r
 }\r
 \r
+bool\r
+PlotFile::getMinMax (int iStartingCol, double& dMin, double& dMax) const\r
+{\r
+       if (iStartingCol >= m_iNumColumns) {\r
+               sys_error (ERR_WARNING, "iStartingCol >= iNumColumns");\r
+               return false;\r
+       }\r
+\r
+       int iOffset = iStartingCol * m_iNumRecords;\r
+       dMin = m_vecCurves[ 0 + iOffset ];\r
+       dMax = dMin;\r
+\r
+       for (int iCol = iStartingCol; iCol < m_iNumColumns; iCol++) {\r
+               int iOffset = iCol * m_iNumRecords;\r
+               for (int iRec = 0; iRec < m_iNumRecords; iRec++) {\r
+                       double dVal = m_vecCurves[ iRec + iOffset ];\r
+                       if (dVal < dMin)\r
+                               dMin = dVal;\r
+                       else if (dVal > dMax)\r
+                               dMax = dVal;\r
+               }\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+bool \r
+PlotFile::statistics (int iStartingCol, double& min, double& max, double& mean, double& mode, double& median, double &stddev) const\r
+{\r
+       if (iStartingCol >= m_iNumColumns) {\r
+               sys_error (ERR_WARNING, "iStartingCol >= iNumColumns");\r
+               return false;\r
+       }\r
+\r
+       int iOffset = iStartingCol * m_iNumRecords;\r
+       int iNPoints = (m_iNumColumns - iStartingCol) * m_iNumRecords;\r
+       std::vector<double> vec (iNPoints);\r
+\r
+       for (int iCol = iStartingCol; iCol < m_iNumColumns; iCol++) {\r
+               int iOffset = iCol * m_iNumRecords;\r
+               for (int iRec = 0; iRec < m_iNumRecords; iRec++)\r
+                       vec.push_back( m_vecCurves[ iRec + iOffset ] );\r
+       }\r
+\r
+       vectorNumericStatistics (vec, min, max, mean, mode, median, stddev);\r
+\r
+       return true;\r
+}\r
+\r
 bool
 PlotFile::fileWrite (const char* const filename)
 {