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