r305: Initial CVS import
[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.1 2000/12/19 21:37:10 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
97   void setXLabel (const std::string& label)
98     { m_strXLabel = label; }
99
100   void setYLabel (const std::string& label)
101     { m_strYLabel = label; }
102
103   void setCurveSize (int iNCurves, int iNRecords);
104
105   void addDescription (const char* const pszDesc)
106     { m_vecStrDescriptions.push_back (pszDesc); }
107       
108   bool addColumn (int iCol, const double* const pdColumn);
109
110   bool addColumn (int iCol, const float* const pdColumn);\r
111 \r
112   const std::string& getTitle () const
113     { return m_strTitle; }
114
115   const std::string& getXLabel () const
116     { return m_strXLabel; }
117
118   const std::string& getYLabel () const
119     { return m_strXLabel; }
120
121   const std::string& getData () const
122     { return m_strDate; }
123
124   int getNumColumns () const
125     { return m_iNumColumns; }
126
127   int getNumRecords () const
128     { return m_iNumRecords; }
129
130   unsigned int getNumDescriptions (void) const
131       { return m_vecStrDescriptions.size(); }
132
133   const std::string& getDescription (int iDescIndex) const
134     { return m_vecStrDescriptions[iDescIndex]; }
135
136   bool fileRead (const char* const filename);
137
138   bool fileWrite (const char* const filename);
139
140   const std::string& getFilename (void) const 
141       {  return m_strFilename; }
142
143   void printHeaders (std::ostream& os) const;
144 };
145
146
147
148 #endif