| 1 |
/***************************************************************************** |
| 2 |
** FILE IDENTIFICATION |
| 3 |
** |
| 4 |
** Name: plotfile.h |
| 5 |
** Purpose: PlotFile class header |
| 6 |
** Programmer: Kevin Rosenberg |
| 7 |
** Date Started: Dec 2000 |
| 8 |
** |
| 9 |
** This is part of the CTSim program |
| 10 |
** Copyright (c) 1983-2009 Kevin Rosenberg |
| 11 |
** |
| 12 |
** This program is free software; you can redistribute it and/or modify |
| 13 |
** it under the terms of the GNU General Public License (version 2) as |
| 14 |
** published by the Free Software Foundation. |
| 15 |
** |
| 16 |
** This program is distributed in the hope that it will be useful, |
| 17 |
** but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 |
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 |
** GNU General Public License for more details. |
| 20 |
** |
| 21 |
** You should have received a copy of the GNU General Public License |
| 22 |
** along with this program; if not, write to the Free Software |
| 23 |
** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 24 |
******************************************************************************/ |
| 25 |
|
| 26 |
#ifndef PLOTFILE_H |
| 27 |
#define PLOTFILE_H |
| 28 |
|
| 29 |
#ifndef MSVC |
| 30 |
#include <unistd.h> |
| 31 |
#endif |
| 32 |
|
| 33 |
#include <sys/types.h> |
| 34 |
#include <cstring> |
| 35 |
#include <string> |
| 36 |
#include <iosfwd> |
| 37 |
#include <iomanip> |
| 38 |
#include <fstream> |
| 39 |
#include <iostream> |
| 40 |
#include <vector> |
| 41 |
#include "ctsupport.h" |
| 42 |
#include "plotfile.h" |
| 43 |
|
| 44 |
|
| 45 |
// Plotfile structure: |
| 46 |
// 1. Lines that begin with # are comments |
| 47 |
// 2. ASCII file format |
| 48 |
// 3. Header lines begin with <tags> and end with </tags> |
| 49 |
// 4. Valid headers |
| 50 |
// <plotfile ncolumns nrecords> (signifies beginning of plotfile) |
| 51 |
// <description> (beginning of description lines) |
| 52 |
// <ezset> (signifies beginning of ezset commands) |
| 53 |
// <columns> Beginning of data columns |
| 54 |
// 5. Data is ASCII file format, one record per line |
| 55 |
// Number of columns is variable and is set by ncolumns header |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
class PlotFile |
| 60 |
{ |
| 61 |
private: |
| 62 |
std::string m_strFilename; |
| 63 |
std::string m_strDate; |
| 64 |
std::vector<std::string> m_vecStrDescriptions; |
| 65 |
std::vector<std::string> m_vecStrEzsetCommands; |
| 66 |
std::vector<double> m_vecCurves; |
| 67 |
int m_iNumColumns; |
| 68 |
int m_iNumRecords; |
| 69 |
bool m_bScatterPlot; |
| 70 |
|
| 71 |
bool headerRead (std::iostream& os); |
| 72 |
bool headerWrite (std::iostream& os); |
| 73 |
bool columnsRead (std::iostream& os); |
| 74 |
bool columnsWrite (std::iostream& os); |
| 75 |
|
| 76 |
void initHeaders (); |
| 77 |
|
| 78 |
PlotFile (const PlotFile& rhs); // copy constructor |
| 79 |
PlotFile& operator= (const PlotFile&); // assignment operator |
| 80 |
|
| 81 |
public: |
| 82 |
PlotFile (int iNColumns, int iNRecords); |
| 83 |
PlotFile (void); |
| 84 |
~PlotFile (); |
| 85 |
|
| 86 |
void setCurveSize (int iNCurves, int iNRecords, bool bScatterPlot = false); |
| 87 |
|
| 88 |
void addDescription (const char* const pszDesc) |
| 89 |
{ m_vecStrDescriptions.push_back (pszDesc); } |
| 90 |
|
| 91 |
void addEzsetCommand (const char* const pszCmd) |
| 92 |
{ m_vecStrEzsetCommands.push_back (pszCmd); } |
| 93 |
|
| 94 |
bool addColumn (int iCol, const double* const pdColumn); |
| 95 |
bool addColumn (int iCol, const float* const pdColumn); |
| 96 |
void getColumn (int iCol, double *pdColumnData) const; |
| 97 |
|
| 98 |
const std::string& getDate () const |
| 99 |
{ return m_strDate; } |
| 100 |
|
| 101 |
int getNumColumns () const |
| 102 |
{ return m_iNumColumns; } |
| 103 |
|
| 104 |
int getNumRecords () const |
| 105 |
{ return m_iNumRecords; } |
| 106 |
|
| 107 |
bool getIsScatterPlot() const |
| 108 |
{ return m_bScatterPlot; } |
| 109 |
|
| 110 |
bool getMinMax (int startingCol, double& min, double& max) const; |
| 111 |
|
| 112 |
bool statistics (int startingCol, double& min, double& max, double& mean, double& mode, double& median, double &stddev) const; |
| 113 |
|
| 114 |
unsigned int getNumDescriptions (void) const |
| 115 |
{ return m_vecStrDescriptions.size(); } |
| 116 |
|
| 117 |
const std::string& getDescription (int iDescIndex) const |
| 118 |
{ return m_vecStrDescriptions[iDescIndex]; } |
| 119 |
|
| 120 |
unsigned int getNumEzsetCommands (void) const |
| 121 |
{ return m_vecStrEzsetCommands.size(); } |
| 122 |
|
| 123 |
const std::string& getEzsetCommand (int iIndex) const |
| 124 |
{ return m_vecStrEzsetCommands[iIndex]; } |
| 125 |
|
| 126 |
bool fileRead (const char* const filename); |
| 127 |
|
| 128 |
bool fileWrite (const char* const filename); |
| 129 |
|
| 130 |
const std::string& getFilename (void) const |
| 131 |
{ return m_strFilename; } |
| 132 |
|
| 133 |
void printHeaders (std::ostream& os) const; |
| 134 |
void printHeaders (std::ostringstream& os) const; |
| 135 |
void printHeadersBrief (std::ostream& os) const; |
| 136 |
void printHeadersBrief (std::ostringstream& os) const; |
| 137 |
}; |
| 138 |
|
| 139 |
|
| 140 |
#endif |