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-2009 Kevin Rosenberg
12 ** This program is free software; you can redistribute it and/or modify
13 ** it under the terms of the GNU General Public License (version 2) as
14 ** published by the Free Software Foundation.
16 ** This program is distributed in the hope that it will be useful,
17 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ** GNU General Public License for more details.
21 ** You should have received a copy of the GNU General Public License
22 ** along with this program; if not, write to the Free Software
23 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 ******************************************************************************/
33 #include <sys/types.h>
41 #include "ctsupport.h"
42 #include "fnetorderstream.h"
45 class Array2dFileLabel
56 Array2dFileLabel(const char* const str, double ctime = 0.);
58 Array2dFileLabel(const int type, const char* const str, double ctime = 0.);
62 const std::string& getLabelString (void) const
63 { return m_strLabel; }
65 kfloat64 getCalcTime (void) const
66 { return m_calcTime; }
68 void setCalcTime (kfloat64 calcTime)
69 { m_calcTime = calcTime; }
71 void setLabelType (int labelType)
72 { m_labelType = labelType; }
74 int getLabelType (void) const
75 { return m_labelType; }
77 std::string& setLabelString (const char* const str)
78 { m_strLabel = str; return (m_strLabel); }
80 std::string& setLabelString (const std::string& str)
81 { m_strLabel = str; return (m_strLabel); }
83 void setDateTime (int year, int month, int day, int hour, int minute, int second);
85 void getDateTime (int& year, int& month, int& day, int& hour, int& minute, int& second) const;
87 const std::string& getDateString () const;
89 void print (std::ostream& os) const;
90 void printBrief (std::ostream& os) const;
91 void printBrief (std::ostringstream& os) const;
93 Array2dFileLabel (const Array2dFileLabel& rhs);
95 Array2dFileLabel& operator= (const Array2dFileLabel& rhs);
107 std::string m_strLabel;
110 mutable std::string m_strDate;
130 DATA_TYPE_INVALID = 0,
135 Array2dFile (int nx, int ny, int pixelSize, int pixelFormat = PIXEL_INVALID, int dataType = DATA_TYPE_REAL);
139 void setArraySize (int nx, int ny, int pixelSize, int pixelFormat = PIXEL_INVALID, int dataType = DATA_TYPE_REAL);
141 void setArraySize (int nx, int ny);
143 unsigned int getNumLabels (void) const
144 { return m_labels.size(); }
146 const Array2dFileLabel& labelGet (int label_num) const;
148 void labelAdd (const Array2dFileLabel& label);
150 void labelAdd (const char* const m_strLabel, double calc_time=0.);
152 void labelAdd (int type, const char* const m_strLabel, double calc_time=0.);
154 void labelsCopy (const Array2dFile& file, const char* const idStr = NULL);
156 void setPixelFormat (int type)
157 { m_pixelFormat = type; }
159 void setPixelSize (int size)
160 { m_pixelSize = size; }
162 kuint32 nx (void) const
165 kuint32 ny (void) const
168 bool isComplex() const
169 { return m_dataType == DATA_TYPE_COMPLEX; }
172 { return m_dataType == DATA_TYPE_REAL; }
174 int dataType () const
175 { return static_cast<int>(m_dataType); }
177 void setDataType (int dataType)
178 { m_dataType = dataType; }
180 void setAxisIncrement (double axisIncX, double axisIncY);
182 bool reallocRealToComplex ();
184 bool reallocComplexToReal ();
186 void getPixelValueRange (double& pvmin, double& pvmax) const;
187 void setAxisExtent (double minX, double maxX, double minY, double maxY);
188 bool getAxisExtent (double& minX, double& maxX, double& minY, double& maxY) const
189 { if (! m_axisExtentKnown) return false; minX = m_minX; maxX = m_maxX; minY = m_minY; maxY=m_maxY;
192 void doPixelOffsetScale (double offset, double scale);
194 kfloat64 axisIncrementX() const {return m_axisIncrementKnown ? m_axisIncrementX : 0.;}
195 kfloat64 axisIncrementY() const {return m_axisIncrementKnown ? m_axisIncrementY : 0.;}
197 void arrayDataClear (void);
199 bool fileRead (const char* const filename);
201 bool fileRead (const std::string& filename);
203 bool fileWrite (const char* const filename);
205 bool fileWrite (const std::string& filename);
207 const std::string& getFilename (void) const
208 { return m_filename; }
210 void printLabels (std::ostream& os) const;
211 void printLabelsBrief (std::ostream& os) const;
212 void printLabelsBrief (std::ostringstream& os) const;
214 unsigned int nLabels() const
215 { return m_labels.size(); }
217 typedef std::vector<Array2dFileLabel*>::iterator labelIterator;
218 typedef std::vector<Array2dFileLabel*>::const_iterator constLabelIterator;
221 typedef std::vector<Array2dFileLabel*> labelContainer;
223 static const kuint16 m_signature;
224 kuint16 m_headersize;
225 std::string m_filename;
228 kuint16 m_pixelFormat;
229 kuint16 m_axisIncrementKnown;
230 kfloat64 m_axisIncrementX, m_axisIncrementY;
231 kuint16 m_axisExtentKnown;
232 kfloat64 m_minX, m_maxX, m_minY, m_maxY;
233 kfloat64 m_offsetPV, m_scalePV;
237 labelContainer m_labels;
238 kuint16 m_numFileLabels;
240 unsigned char** m_arrayData;
241 unsigned char** m_imaginaryArrayData;
246 bool headerRead (frnetorderstream& fs);
248 bool headerWrite (frnetorderstream& fs);
250 bool arrayDataRead (frnetorderstream& fs);
252 bool arrayDataWrite (frnetorderstream& fs);
254 bool labelsRead (frnetorderstream& fs);
256 bool labelsWrite (frnetorderstream& fs);
258 bool labelSeek (int label_num);
263 void allocArray (unsigned char**& rppData);
264 void freeArray (unsigned char**& rppData);
266 Array2dFile (const Array2dFile& rhs); // copy constructor
267 Array2dFile& operator= (const Array2dFile&); // assignment operator