-class Array2dFileLabel
-{
-private:
- void init (void);
-
-public:
- kfloat64 calc_time;
- kuint16 label_type;
- kuint16 year;
- kuint16 month;
- kuint16 day;
- kuint16 hour;
- kuint16 minute;
- kuint16 second;
- string label_str;
-
- static const int L_EMPTY = 0;
- static const int L_HISTORY = 1;
- static const int L_USER = 2;
-
- Array2dFileLabel();
-
- Array2dFileLabel(const char* const str, double ctime = 0.);
-
- Array2dFileLabel(const int type, const char* const str, double ctime = 0.);
-
- ~Array2dFileLabel();
-
- const string& getLabelString (void) const
- { return label_str; }
-
- kfloat64 getCalcTime (void) const
- { return calc_time; }
-
- kfloat64 getLabelType (void) const
- { return label_type; }
-
- void getDateString (string& str) const;
-};
-
-
-template<class T>
-class Array2dFile
-{
-private:
- void init (void);
- kuint16 signature;
- kuint16 num_labels;
- kuint16 headersize;
- string filename;
- int file_id;
- iostream *io;
- bool bHeaderWritten;
- bool bDataWritten;
-
- bool headerWrite (void);
-
- bool headerRead (void);
-
- bool arrayDataRead (void);
-
- bool labelSeek (unsigned int label_num);
-
-public:
- kuint16 pixel_size;
- kuint16 pixel_type;
- kuint32 nx;
- kuint32 ny;
-
- kuint16 axis_increment_known;
- kfloat64 xinc, yinc;
- kuint16 axis_extent_known;
- kfloat64 xmin, xmax, ymin, ymax;
- kfloat64 pv_offset, pv_scale;
-
- Array2d<T> *array;
-
- static const int INT8 = 1;
- static const int UINT8 = 2;
- static const int INT16 = 3;
- static const int UINT16 = 4;
- static const int INT32 = 5;
- static const int UINT32 = 6;
- static const int FLOAT32 = 7;
- static const int FLOAT64 = 8;
-
- Array2dFile (unsigned int nx, unsigned int ny);
- Array2dFile (const char* const filename);
- Array2dFile (const char* const filename, unsigned int nx, unsigned int ny);
- ~Array2dFile ();
-
- unsigned int getNumLabels (void) const
- { return num_labels; }
-
- bool labelRead (Array2dFileLabel& label, unsigned int label_num);
-
- void labelAdd (const Array2dFileLabel& label);
-
- void labelAdd (const char* const label_str, double calc_time=0.);
-
- void labelAdd (int type, const char* const label_str, double calc_time=0.);
-
- void fileClose (void);
-
- void set_axis_increment (double xinc, double yinc);
-
- void set_axis_extent (double xmin, double xmax, double ymin, double ymax);
-
- void get_pixel_extent (T& pvmin, T& pvmax);
-
- void set_pixel_offset_extent (double offset, double scale);
-
- T** getArray (void) const
- { return (array == NULL ? NULL : array->getArray()); }
-
- bool arrayDataWrite (void);
-
- bool fileRead (void);
-
- bool fileCreate (void);
-
- const string& GetFilename (void) const
- { return filename; }
-};
-
-
-template<class T>
-void
-Array2dFile<T>::set_axis_increment (double xinc, double yinc)
-{
- axis_increment_known = true;
- this.xinc = xinc;
- this.yinc = yinc;
-}
-
-template<class T>
-void
-Array2dFile<T>::set_axis_extent (double xmin, double xmax, double ymin, double ymax)
-{
- axis_extent_known = true;
- this.xmin = xmin;
- this.ymax = xmax;
- this.xmin = xmin;
- this.ymax = ymax;
-}
-
-template<class T>
-void
-Array2dFile<T>::get_pixel_extent (T& pvmin, T& pvmax)
-{
- if (array != NULL) {
- T** da = array.GetArray();
- pvmax = pvmin = da[0][0];
- for (int ix = 0; ix < nx; ix++)
- for (int iy = 0; iy < ny; iy++)
- if (pvmax < da[ix][iy])
- pvmax = da[ix][iy];
- else if (pvmin > da[ix][iy])
- pvmin = da[ix][iy];
- }
-}
-
-template<class T>
-void
-Array2dFile<T>::set_pixel_offset_extent (double offset, double scale)
-{
- pv_offset = offset;
- pv_scale = scale;
-}
-
-template<class T>
-void
-Array2dFile<T>::init (void)
-{
- pixel_size = sizeof(T);
- signature = ('I' * 256 + 'F');
- file_id = -1;
- nx = 0;
- ny = 0;
- headersize = 0;
- num_labels = 0;
- axis_increment_known = false;
- axis_extent_known = false;
- xinc = ymin = 0;
- xmin = xmax = ymin = ymax = 0;
- pv_offset = 0;
- pv_scale = 1;
- array = NULL;
- io = NULL;
-
-#if 0
- const type_info& t_id = typeid(T);
- cout << t_id.name() << endl;
- const type_info& comp_id = typeid(T);
-
- if (t_id == comp_id)
- pixel_type = FLOAT64;
- else if (t_id == typeid(kfloat32))
- pixel_type = FLOAT32;
- else if (t_id == typeid(kint32))
- pixel_type = INT32;
- else if (t_id == typeid(kuint32))
- pixel_type = UINT32;
- else if (t_id == typeid(kint16))
- pixel_type = INT16;
- else if (t_id == typeid(kuint16))
- pixel_type = UINT16;
- else if (t_id == typeid(kint8))
- pixel_type = INT8;
- else if (t_id == typeid(kuint8))
- pixel_type = UINT8;
- else