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.2 2000/06/27 10:48:11 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 ******************************************************************************/
31 #include <sys/types.h>
38 #include "ctsupport.h"
39 #include "fnetorderstream.h"
44 class Array2dFileLabel
47 static const int L_EMPTY = 0;
48 static const int L_HISTORY = 1;
49 static const int L_USER = 2;
53 Array2dFileLabel(const char* const str, double ctime = 0.);
55 Array2dFileLabel(const int type, const char* const str, double ctime = 0.);
59 const string& getLabelString (void) const
60 { return m_strLabel; }
62 kfloat64 getCalcTime (void) const
63 { return m_calcTime; }
65 void setCalcTime (kfloat64 calcTime)
66 { m_calcTime = calcTime; }
68 void setLabelType (int labelType)
69 { m_labelType = labelType; }
71 int getLabelType (void) const
72 { return m_labelType; }
74 string& setLabelString (const char* const str)
75 { m_strLabel = str; return (m_strLabel); }
77 string& setLabelString (const string& str)
78 { m_strLabel = str; return (m_strLabel); }
80 void setDateTime (int year, int month, int day, int hour, int minute, int second);
82 void getDateTime (int& year, int& month, int& day, int& hour, int& minute, int& second) const;
84 const string& getDateString () const;
86 // Array2dFileLabel (const Array2dFileLabel&);
88 // Array2dFileLabel& operator= (const Array2dFileLabel&);
103 mutable string m_strDate;
110 static const int PIXEL_INVALID = 0;
111 static const int PIXEL_INT8 = 1;
112 static const int PIXEL_UINT8 = 2;
113 static const int PIXEL_INT16 = 3;
114 static const int PIXEL_UINT16 = 4;
115 static const int PIXEL_INT32 = 5;
116 static const int PIXEL_UINT32 = 6;
117 static const int PIXEL_FLOAT32 = 7;
118 static const int PIXEL_FLOAT64 = 8;
120 Array2dFile (int nx, int ny, int pixelSize, int pixelFormat = PIXEL_INVALID);
124 void setArraySize (int nx, int ny, int pixelSize, int pixelFormat = PIXEL_INVALID);
126 void setArraySize (int nx, int ny);
128 unsigned int getNumLabels (void) const
129 { return m_labels.size(); }
131 const Array2dFileLabel& labelGet (int label_num) const;
133 void labelAdd (const Array2dFileLabel& label);
135 void labelAdd (const char* const m_strLabel, double calc_time=0.);
137 void labelAdd (int type, const char* const m_strLabel, double calc_time=0.);
139 void labelsCopy (Array2dFile& file, const char* const idStr = NULL);
141 void setPixelFormat (int type)
142 { m_pixelFormat = type; }
144 void setPixelSize (int size)
145 { m_pixelSize = size; }
147 kuint32 nx (void) const
150 kuint32 ny (void) const
153 void setAxisIncrement (double axisIncX, double axisIncY);
155 void setAxisExtent (double minX, double maxX, double minY, double maxY);
157 void getPixelValueRange (double& pvmin, double& pvmax) const;
159 void doPixelOffsetScale (double offset, double scale);
161 void arrayDataClear (void);
163 bool fileRead (const char* const filename);
165 bool fileWrite (const char* const filename);
167 const string& getFilename (void) const
168 { return m_filename; }
170 void printLabels (ostream& os) const;
172 typedef vector<Array2dFileLabel*>::iterator labelIterator;
173 typedef vector<Array2dFileLabel*>::const_iterator constLabelIterator;
176 typedef vector<Array2dFileLabel*> labelContainer;
178 static const kuint16 m_signature = ('I'*256+'F');
179 kuint16 m_headersize;
183 kuint16 m_pixelFormat;
184 kuint16 m_axisIncrementKnown;
185 kfloat64 m_axisIncrementX, m_axisIncrementY;
186 kuint16 m_axisExtentKnown;
187 kfloat64 m_minX, m_maxX, m_minY, m_maxY;
188 kfloat64 m_offsetPV, m_scalePV;
192 labelContainer m_labels;
193 kuint16 m_numFileLabels;
194 unsigned char** m_arrayData;
199 bool headerRead (frnetorderstream& fs);
201 bool headerWrite (frnetorderstream& fs);
203 bool arrayDataRead (frnetorderstream& fs);
205 bool arrayDataWrite (frnetorderstream& fs);
207 bool labelsRead (frnetorderstream& fs);
209 bool labelsWrite (frnetorderstream& fs);
211 bool labelSeek (int label_num);
213 void allocArray (void);
215 void freeArray (void);
217 Array2dFile (const Array2dFile& rhs); // copy constructor
218 Array2dFile& operator= (const Array2dFile&); // assignment operator