X-Git-Url: http://git.kpe.io/?p=ctsim.git;a=blobdiff_plain;f=libctsupport%2Fplotfile.cpp;h=b9e8ac641b5a80a3b5e905600634bf4f41605473;hp=b8744515cfc61ef8ac0a66e524e9dfecd1f1fed5;hb=f7d2b7144f32a7bd157b7689022e62944b82fcc1;hpb=739e435359d44546dd812fff8c86b815a214d587 diff --git a/libctsupport/plotfile.cpp b/libctsupport/plotfile.cpp index b874451..b9e8ac6 100644 --- a/libctsupport/plotfile.cpp +++ b/libctsupport/plotfile.cpp @@ -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.4 2000/12/21 03:40:58 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,57 @@ PlotFile::getColumn (int iCol, double* pdColData) const } +bool +PlotFile::getMinMax (int iStartingCol, double& dMin, double& dMax) const +{ + if (iStartingCol >= m_iNumColumns) { + 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++) { + double dVal = m_vecCurves[ iRec + iOffset ]; + if (dVal < dMin) + dMin = dVal; + else if (dVal > dMax) + dMax = dVal; + } + } + + return true; +} + +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 iOffset = iStartingCol * m_iNumRecords; + int iNPoints = (m_iNumColumns - iStartingCol) * m_iNumRecords; + std::vector 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; +} + bool PlotFile::fileWrite (const char* const filename) {