1 /*****************************************************************************
5 ** Purpose: 2-dimension array file class
6 ** Programmer: Kevin Rosenberg
7 ** Date Started: June 2000
9 ** This is part of the CTSim program
10 ** Copyright (C) 1983-2000 Kevin Rosenberg
12 ** $Id: array2dfile.h,v 1.10 2000/12/16 02:44:26 kevin Exp $
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.
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.
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 ******************************************************************************/
35 #include <sys/types.h>
43 #include "ctsupport.h"
44 #include "fnetorderstream.h"
49 class Array2dFileLabel
60 Array2dFileLabel(const char* const str, double ctime = 0.);
62 Array2dFileLabel(const int type, const char* const str, double ctime = 0.);
66 const string& getLabelString (void) const
67 { return m_strLabel; }
69 kfloat64 getCalcTime (void) const
70 { return m_calcTime; }
72 void setCalcTime (kfloat64 calcTime)
73 { m_calcTime = calcTime; }
75 void setLabelType (int labelType)
76 { m_labelType = labelType; }
78 int getLabelType (void) const
79 { return m_labelType; }
81 string& setLabelString (const char* const str)
82 { m_strLabel = str; return (m_strLabel); }
84 string& setLabelString (const string& str)
85 { m_strLabel = str; return (m_strLabel); }
87 void setDateTime (int year, int month, int day, int hour, int minute, int second);
89 void getDateTime (int& year, int& month, int& day, int& hour, int& minute, int& second) const;
91 const string& getDateString () const;
93 void print (std::ostream& os) const;
95 Array2dFileLabel (const Array2dFileLabel& rhs);
97 Array2dFileLabel& operator= (const Array2dFileLabel& rhs);
112 mutable string m_strDate;
131 Array2dFile (int nx, int ny, int pixelSize, int pixelFormat = PIXEL_INVALID);
135 void setArraySize (int nx, int ny, int pixelSize, int pixelFormat = PIXEL_INVALID);
137 void setArraySize (int nx, int ny);
139 unsigned int getNumLabels (void) const
140 { return m_labels.size(); }
142 const Array2dFileLabel& labelGet (int label_num) const;
144 void labelAdd (const Array2dFileLabel& label);
146 void labelAdd (const char* const m_strLabel, double calc_time=0.);
148 void labelAdd (int type, const char* const m_strLabel, double calc_time=0.);
150 void labelsCopy (Array2dFile& file, const char* const idStr = NULL);
152 void setPixelFormat (int type)
153 { m_pixelFormat = type; }
155 void setPixelSize (int size)
156 { m_pixelSize = size; }
158 kuint32 nx (void) const
161 kuint32 ny (void) const
164 void setAxisIncrement (double axisIncX, double axisIncY);
166 void setAxisExtent (double minX, double maxX, double minY, double maxY);
168 void getPixelValueRange (double& pvmin, double& pvmax) const;
170 void doPixelOffsetScale (double offset, double scale);
172 void arrayDataClear (void);
174 bool fileRead (const char* const filename);
176 bool fileRead (const string& filename);
178 bool fileWrite (const char* const filename);
180 bool fileWrite (const string& filename);
182 const string& getFilename (void) const
183 { return m_filename; }
185 void printLabels (ostream& os) const;
187 typedef vector<Array2dFileLabel*>::iterator labelIterator;
188 typedef vector<Array2dFileLabel*>::const_iterator constLabelIterator;
191 typedef vector<Array2dFileLabel*> labelContainer;
193 static const kuint16 m_signature;
194 kuint16 m_headersize;
198 kuint16 m_pixelFormat;
199 kuint16 m_axisIncrementKnown;
200 kfloat64 m_axisIncrementX, m_axisIncrementY;
201 kuint16 m_axisExtentKnown;
202 kfloat64 m_minX, m_maxX, m_minY, m_maxY;
203 kfloat64 m_offsetPV, m_scalePV;
207 labelContainer m_labels;
208 kuint16 m_numFileLabels;
209 unsigned char** m_arrayData;
214 bool headerRead (frnetorderstream& fs);
216 bool headerWrite (frnetorderstream& fs);
218 bool arrayDataRead (frnetorderstream& fs);
220 bool arrayDataWrite (frnetorderstream& fs);
222 bool labelsRead (frnetorderstream& fs);
224 bool labelsWrite (frnetorderstream& fs);
226 bool labelSeek (int label_num);
228 void allocArray (void);
230 void freeArray (void);
232 Array2dFile (const Array2dFile& rhs); // copy constructor
233 Array2dFile& operator= (const Array2dFile&); // assignment operator