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-2001 Kevin Rosenberg
12 ** $Id: array2dfile.h,v 1.21 2001/03/07 16:34:47 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"
47 class Array2dFileLabel
58 Array2dFileLabel(const char* const str, double ctime = 0.);
60 Array2dFileLabel(const int type, const char* const str, double ctime = 0.);
64 const std::string& getLabelString (void) const
65 { return m_strLabel; }
67 kfloat64 getCalcTime (void) const
68 { return m_calcTime; }
70 void setCalcTime (kfloat64 calcTime)
71 { m_calcTime = calcTime; }
73 void setLabelType (int labelType)
74 { m_labelType = labelType; }
76 int getLabelType (void) const
77 { return m_labelType; }
79 std::string& setLabelString (const char* const str)
80 { m_strLabel = str; return (m_strLabel); }
82 std::string& setLabelString (const std::string& str)
83 { m_strLabel = str; return (m_strLabel); }
85 void setDateTime (int year, int month, int day, int hour, int minute, int second);
87 void getDateTime (int& year, int& month, int& day, int& hour, int& minute, int& second) const;
89 const std::string& getDateString () const;
91 void print (std::ostream& os) const;
92 void printBrief (std::ostream& os) const;
93 void printBrief (std::ostringstream& os) const;
95 Array2dFileLabel (const Array2dFileLabel& rhs);
97 Array2dFileLabel& operator= (const Array2dFileLabel& rhs);
109 std::string m_strLabel;
112 mutable std::string m_strDate;
132 DATA_TYPE_INVALID = 0,
137 Array2dFile (int nx, int ny, int pixelSize, int pixelFormat = PIXEL_INVALID, int dataType = DATA_TYPE_REAL);
141 void setArraySize (int nx, int ny, int pixelSize, int pixelFormat = PIXEL_INVALID, int dataType = DATA_TYPE_REAL);
143 void setArraySize (int nx, int ny);
145 unsigned int getNumLabels (void) const
146 { return m_labels.size(); }
148 const Array2dFileLabel& labelGet (int label_num) const;
150 void labelAdd (const Array2dFileLabel& label);
152 void labelAdd (const char* const m_strLabel, double calc_time=0.);
154 void labelAdd (int type, const char* const m_strLabel, double calc_time=0.);
156 void labelsCopy (const Array2dFile& file, const char* const idStr = NULL);
158 void setPixelFormat (int type)
159 { m_pixelFormat = type; }
161 void setPixelSize (int size)
162 { m_pixelSize = size; }
164 kuint32 nx (void) const
167 kuint32 ny (void) const
170 bool isComplex() const
171 { return m_dataType == DATA_TYPE_COMPLEX; }
174 { return m_dataType == DATA_TYPE_REAL; }
176 int dataType () const
177 { return static_cast<int>(m_dataType); }
179 void setDataType (int dataType)
180 { m_dataType = dataType; }
182 void setAxisIncrement (double axisIncX, double axisIncY);
184 bool reallocRealToComplex ();
186 bool reallocComplexToReal ();
188 void getPixelValueRange (double& pvmin, double& pvmax) const;
189 void setAxisExtent (double minX, double maxX, double minY, double maxY);
190 bool getAxisExtent (double& minX, double& maxX, double& minY, double& maxY) const
191 { if (! m_axisExtentKnown) return false; minX = m_minX; maxX = m_maxX; minY = m_minY; maxY=m_maxY;
194 void doPixelOffsetScale (double offset, double scale);
196 kfloat64 axisIncrementX() const {return m_axisIncrementKnown ? m_axisIncrementX : 0.;}
197 kfloat64 axisIncrementY() const {return m_axisIncrementKnown ? m_axisIncrementY : 0.;}
199 void arrayDataClear (void);
201 bool fileRead (const char* const filename);
203 bool fileRead (const std::string& filename);
205 bool fileWrite (const char* const filename);
207 bool fileWrite (const std::string& filename);
209 const std::string& getFilename (void) const
210 { return m_filename; }
212 void printLabels (std::ostream& os) const;
213 void printLabelsBrief (std::ostream& os) const;
214 void printLabelsBrief (std::ostringstream& os) const;
216 unsigned int nLabels() const
217 { return m_labels.size(); }
219 typedef std::vector<Array2dFileLabel*>::iterator labelIterator;
220 typedef std::vector<Array2dFileLabel*>::const_iterator constLabelIterator;
223 typedef std::vector<Array2dFileLabel*> labelContainer;
225 static const kuint16 m_signature;
226 kuint16 m_headersize;
227 std::string m_filename;
230 kuint16 m_pixelFormat;
231 kuint16 m_axisIncrementKnown;
232 kfloat64 m_axisIncrementX, m_axisIncrementY;
233 kuint16 m_axisExtentKnown;
234 kfloat64 m_minX, m_maxX, m_minY, m_maxY;
235 kfloat64 m_offsetPV, m_scalePV;
239 labelContainer m_labels;
240 kuint16 m_numFileLabels;
242 unsigned char** m_arrayData;
243 unsigned char** m_imaginaryArrayData;
248 bool headerRead (frnetorderstream& fs);
250 bool headerWrite (frnetorderstream& fs);
252 bool arrayDataRead (frnetorderstream& fs);
254 bool arrayDataWrite (frnetorderstream& fs);
256 bool labelsRead (frnetorderstream& fs);
258 bool labelsWrite (frnetorderstream& fs);
260 bool labelSeek (int label_num);
265 void allocArray (unsigned char**& rppData);
266 void freeArray (unsigned char**& rppData);
268 Array2dFile (const Array2dFile& rhs); // copy constructor
269 Array2dFile& operator= (const Array2dFile&); // assignment operator