r309: plotfile changes
[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.3 2000/12/20 20:08:48 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"
45
46 // Plotfile structure:
47 // 1. Lines that begin with # are comments
48 // 2. ASCII file format
49 // 3. Header lines begin with <tags> and end with </tags>
50 // 4. Valid headers
51 //      <header>    (signifies beginning of headers)
52 //      <description> (multiple instances may be present)
53 //      <date>
54 //      <title>
55 //      <xlabel>
56 //      <ylabel>
57 //      <filetype>plotfile</filetype>  (required)
58 //      <ncolumns>  (required)
59 //      <nrecords>  (required)
60 //      </header>   (required, signifies end of headers)
61 // 5. Data is ASCII file format, one record per line
62 //    Number of columns is variable and is set by ncolumns header
63 // 6. Data begins with <plotdata> and ends with </plotdata>
64
65
66 class PlotFile 
67 {
68  private:
69   std::string m_strFilename;
70   std::string m_strTitle;
71   std::string m_strXLabel;
72   std::string m_strYLabel;
73   std::string m_strDate;
74   std::vector<std::string> m_vecStrDescriptions;
75   std::vector<double> m_vecCurves;
76   int m_iNumColumns;
77   int m_iNumRecords;
78
79   bool headerRead (std::iostream& os);
80   bool headerWrite (std::iostream& os);
81   bool columnsRead (std::iostream& os);
82   bool columnsWrite (std::iostream& os);
83
84   void initHeaders ();
85
86   PlotFile (const PlotFile& rhs);        // copy constructor
87   PlotFile& operator= (const PlotFile&); // assignment operator
88
89 public:
90   PlotFile (int iNColumns, int iNRecords);
91   PlotFile (void);
92   ~PlotFile ();
93
94   void setTitle (const std::string& title)
95     { m_strTitle = title; }
96         \r
97   void setTitle (const char* const title)\r
98   { m_strTitle = title; }\r
99
100   void setXLabel (const std::string& label)
101     { m_strXLabel = label; }
102         \r
103   void setXLabel (const char* const label)\r
104   { m_strXLabel = label; }\r
105
106   void setYLabel (const std::string& label)
107     { m_strYLabel = label; }
108
109   void setYLabel (const char* const label)\r
110   { m_strYLabel = label; }\r
111 \r
112   void setCurveSize (int iNCurves, int iNRecords);
113
114   void addDescription (const char* const pszDesc)
115     { m_vecStrDescriptions.push_back (pszDesc); }
116       
117   bool addColumn (int iCol, const double* const pdColumn);
118
119   bool addColumn (int iCol, const float* const pdColumn);\r
120 \r
121   void getColumn (int iCol, double *pdColumnData) const;\r
122 \r
123   const std::string& getTitle () const
124     { return m_strTitle; }
125
126   const std::string& getXLabel () const
127     { return m_strXLabel; }
128
129   const std::string& getYLabel () const
130     { return m_strXLabel; }
131
132   const std::string& getDate () const
133     { return m_strDate; }
134
135   int getNumColumns () const
136     { return m_iNumColumns; }
137
138   int getNumRecords () const
139     { return m_iNumRecords; }
140 \r
141   bool getMinMax (int startingCol, double& min, double& max) const;\r
142 \r
143   bool statistics (int startingCol, double& min, double& max, double& mean, double& mode, double& median, double &stddev) const;\r
144
145   unsigned int getNumDescriptions (void) const
146       { return m_vecStrDescriptions.size(); }
147
148   const std::string& getDescription (int iDescIndex) const
149     { return m_vecStrDescriptions[iDescIndex]; }
150
151   bool fileRead (const char* const filename);
152
153   bool fileWrite (const char* const filename);
154
155   const std::string& getFilename (void) const 
156       {  return m_strFilename; }
157
158   void printHeaders (std::ostream& os) const;
159 };
160
161
162
163 #endif