X-Git-Url: http://git.kpe.io/?p=ctsim.git;a=blobdiff_plain;f=libctsupport%2Fplotfile.cpp;h=5a160cdbe4bbf31a1f18291b1f887e0962bc8c81;hp=b8744515cfc61ef8ac0a66e524e9dfecd1f1fed5;hb=fd1d136a94a6d20013f38d6a997bdfefad0f5e98;hpb=efc398029330f4d9170257db29e4420e50f25625 diff --git a/libctsupport/plotfile.cpp b/libctsupport/plotfile.cpp index b874451..5a160cd 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.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 } +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 (iNPoints); + + for (int iCol = iStartingCol; iCol < m_iNumColumns; iCol++) { + int iOffset = iCol * m_iNumRecords; + for (int iRec = 0; iRec < m_iNumRecords; iRec++) + vec.push_back( m_vecCurves[ iRec + iOffset ] ); + } + + vectorNumericStatistics (vec, min, max, mean, mode, median, stddev); + + return true; +} + bool PlotFile::fileWrite (const char* const filename) {