X-Git-Url: http://git.kpe.io/?p=ctsim.git;a=blobdiff_plain;f=libctsupport%2Fplotfile.cpp;h=ef8d26420a5dfb95aec58445d17eac3d4667c4ea;hp=706fce1d352bcd367e22e257965c7ea4c3ebbb2b;hb=9b2bb510160bdb56f04847f5b55ab61dd8a47976;hpb=65732cc5d8dbf867ed56a021c07c5636cea93b5a diff --git a/libctsupport/plotfile.cpp b/libctsupport/plotfile.cpp index 706fce1..ef8d264 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.6 2000/12/27 03:16:02 kevin Exp $ +** $Id: plotfile.cpp,v 1.8 2001/01/02 05:34:57 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 @@ -40,7 +40,7 @@ PlotFile::PlotFile (int nCurves, int nRecords) { initHeaders (); - setCurveSize (nCurves, nRecords); + setCurveSize (nCurves, nRecords); } PlotFile::PlotFile () @@ -57,7 +57,8 @@ PlotFile::initHeaders () { m_iNumColumns = 0; m_iNumRecords = 0; - m_strDate = ""; + time_t currentTime = time (NULL); + m_strDate = ctime (¤tTime); m_vecStrDescriptions.clear(); m_vecStrEzsetCommands.clear(); } @@ -148,8 +149,7 @@ PlotFile::statistics (int iStartingCol, double& min, double& max, double& mean, 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); @@ -222,11 +222,32 @@ PlotFile::headerRead (std::iostream& fs) fs.seekg (0); bool bFinishedHeaders = false; + fs >> m_iNumColumns; + fs >> m_iNumRecords; + + if (fs.fail() || m_iNumColumns == 0 || m_iNumRecords == 0) + return false; + while (! bFinishedHeaders && ! fs.eof() && ! fs.fail()) { char line[1024]; fs.getline (line, sizeof(line)); - if (strstr (line, "") != NULL) + int iSP = 0; + while (line[iSP] == ' ') + iSP++; + if (line[iSP] == '\n' || ! line[iSP]) + ; + else if (line[iSP] == '#') { + iSP++; + while (line[iSP] == ' ') + iSP++; + if (line[iSP] == '\n' || ! line[iSP]) + ; + else + addDescription (&line[iSP]); + } else if (strstr (&line[iSP], "") != NULL) { bFinishedHeaders = true; + } else + addEzsetCommand (&line[iSP]); } return ! fs.fail(); @@ -242,27 +263,18 @@ PlotFile::headerWrite (std::iostream& fs) } fs.seekp (0); - fs << "\n"; - - int iNEzset = m_vecStrEzsetCommands.size(); - if (iNEzset > 0) { - fs << "\n"; - for (int i = 0; i < iNEzset; i++) + fs << m_iNumColumns << " " << m_iNumRecords << "\n"; + + int i; + for (i = 0; i < m_vecStrEzsetCommands.size(); i++) fs << m_vecStrEzsetCommands[i] << "\n"; - fs << "\n"; - } + + for (i = 0; i < m_vecStrDescriptions.size(); i++) + fs << "# " << m_vecStrDescriptions[i] << "\n"; if (! m_strDate.empty()) - fs << "" << m_strDate << "\n"; - - int iNDesc = m_vecStrDescriptions.size(); - if (iNDesc > 0) { - fs << "\n"; - for (int i = 0; i < iNDesc; i++) - fs << m_vecStrDescriptions[i] << "\n"; - fs << "\n"; - } - + fs << "# Date: " << m_strDate << "\n"; + return ! fs.fail(); } @@ -300,8 +312,6 @@ PlotFile::columnsRead (std::iostream& fs) return false; } - return ! fs.fail(); - if (m_iNumColumns == 0 || m_iNumRecords == 0) { sys_error (ERR_WARNING, "Called PlotFile::columnsRead with 0 columns or records"); return false; @@ -328,5 +338,12 @@ PlotFile::columnsRead (std::iostream& fs) void PlotFile::printHeaders (std::ostream& os) const -{ +{ + os << "EZSet Commands\n"; + for (unsigned int iEZ = 0; iEZ < m_vecStrEzsetCommands.size(); iEZ++) + os << m_vecStrEzsetCommands[iEZ] << "\n"; + + os << "Descriptions\n"; + for (unsigned int iDesc = 0; iDesc < m_vecStrDescriptions.size(); iDesc++) + os << m_vecStrDescriptions[iDesc] << "\n"; }