#include <string>
#include "kstddef.h"
+#include <sys/types.h>
+#include <unistd.h>
#include <array2d.h>
using namespace std;
{
private:
void init (void);
+ Array2dFileLabel (const Array2dFileLabel&);
+ Array2dFileLabel& operator= (const Array2dFileLabel&);
public:
- kfloat64 calc_time;
- kuint16 label_type;
- kuint16 year;
- kuint16 month;
- kuint16 day;
- kuint16 hour;
- kuint16 minute;
- kuint16 second;
- string label_str;
+ kfloat64 m_calcTime;
+ kuint16 m_labelType;
+ kuint16 m_year;
+ kuint16 m_month;
+ kuint16 m_day;
+ kuint16 m_hour;
+ kuint16 m_minute;
+ kuint16 m_second;
+ string m_strLabel;
+ mutable string m_strDate;
static const int L_EMPTY = 0;
static const int L_HISTORY = 1;
~Array2dFileLabel();
const string& getLabelString (void) const
- { return label_str; }
+ { return m_strLabel; }
kfloat64 getCalcTime (void) const
- { return calc_time; }
+ { return m_calcTime; }
kfloat64 getLabelType (void) const
- { return label_type; }
+ { return m_labelType; }
- void getDateString (string& str) const;
+ string& setLabelString (const char* const str)
+ { m_strLabel = str; return (m_strLabel); }
+
+ string& setLabelString (const string& str)
+ { m_strLabel = str; return (m_strLabel); }
+
+ const string& getDateString () const;
};
kuint32 mNX;
kuint32 mNY;
+ Array2dFile (const Array2dFile&);
+ Array2dFile& operator= (const Array2dFile&);
+
public:
- Array2d<T> *array;
+ Array2d<T> array;
static const int INT8 = 1;
static const int UINT8 = 2;
void labelAdd (const Array2dFileLabel& label);
- void labelAdd (const char* const label_str, double calc_time=0.);
+ void labelAdd (const char* const m_strLabel, double calc_time=0.);
+
+ void labelAdd (int type, const char* const m_strLabel, double calc_time=0.);
- void labelAdd (int type, const char* const label_str, double calc_time=0.);
+ void labelsCopy (Array2dFile& file, const char* const idStr = NULL);
void fileClose (void);
void setAxisExtent (double mMinX, double mMaxX, double mMinY, double mMaxY);
- void getPixelValueRange (T& pvmin, T& pvmax);
+ void getPixelValueRange (T& pvmin, T& pvmax) const;
void doPixelOffsetScale (double offset, double scale);
T** getArray (void) const
- { return (array == NULL ? NULL : array->getArray()); }
+ { return (array.getArray()); }
bool arrayDataWrite (void);
+ void arrayDataClear (void);
+
bool fileRead (void);
bool fileCreate (void);
init();
mNX = x;
mNY = y;
- array = new Array2d<T> (mNX, mNY);
+ array.initSetSize(mNX, mNY);
}
template<class T>
init();
mNX = x;
mNY = y;
- array = new Array2d<T> (mNX, mNY);
+ array.initSetSize(mNX, mNY);
}
template<class T>
mMinX = mMaxX = mMinY = mMaxY = 0;
mOffsetPV = 0;
mScalePV = 1;
- array = NULL;
io = NULL;
#if 0
void
Array2dFile<T>::fileClose (void)
{
- headerWrite ();
- if (file_id >= 0 && array != NULL) {
- arrayDataWrite ();
- close (file_id);
- file_id = -1;
+ if (file_id >= 0) {
+ headerWrite ();
+ close (file_id);
+ file_id = -1;
}
}
}
headerRead();
- if (array != NULL)
- delete array;
- array = new Array2d<T> (mNX, mNY);
+ array.initSetSize(mNX, mNY);
arrayDataRead();
template<class T>
void
-Array2dFile<T>::getPixelValueRange (T& pvmin, T& pvmax)
+Array2dFile<T>::getPixelValueRange (T& pvmin, T& pvmax) const
{
- if (array != NULL) {
- T** da = array.GetArray();
+ T** da = array.getArray();
+ if (da) {
pvmax = pvmin = da[0][0];
- for (int ix = 0; ix < mNX; ix++)
- for (int iy = 0; iy < mNY; iy++)
- if (pvmax < da[ix][iy])
- pvmax = da[ix][iy];
- else if (pvmin > da[ix][iy])
+ for (int ix = 0; ix < mNX; ix++)
+ for (int iy = 0; iy < mNY; 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>::doPixelOffsetScale (double offset, double scale)
{
- if (adf != NULL) {
- mOffsetPV = offset;
- mScalePV = scale;
-
- T** ad = adf->getArray();
- for (unsigned int ix = 0; ix < mNX; ix++)
- for (unsigned int iy = 0; iy < mNY; iy++)
- ad[ix][iy] = (ad[ix][iy] - offset) * scale;
+ T** ad = array.getArray();
+ if (ad) {
+ mOffsetPV = offset;
+ mScalePV = scale;
+
+ for (unsigned int ix = 0; ix < mNX; ix++)
+ for (unsigned int iy = 0; iy < mNY; iy++)
+ ad[ix][iy] = (ad[ix][iy] - offset) * scale;
}
}
return (false);
}
+ T** da = array.getArray();
+ if (! da)
+ return (false);
+
lseek (file_id, headersize, SEEK_SET);
for (unsigned int ix = 0; ix < mNX; ix++)
for (unsigned int iy = 0; iy < mNY; iy++) {
- T value = array->array_data[ix][iy];
- ConvertNetworkOrder (&value, sizeof(T));
- write (file_id, &array->array_data[ix][iy], mPixelSize);
+ T value = da[ix][iy];
+ ConvertReverseNetworkOrder (&value, sizeof(T));
+ write (file_id, &value, mPixelSize);
}
return (true);
return (false);
}
+ T** da = array.getArray();
+ if (! da)
+ return (false);
+
lseek (file_id, headersize, SEEK_SET);
T pixelBuffer;
for (int ix = 0; ix < mNX; ix++)
for (unsigned int iy = 0; iy < mNY; iy++) {
read (file_id, &pixelBuffer, mPixelSize);
- ConvertNetworkOrder (&pixelBuffer, sizeof(T));
- array->array_data[ix][iy] = pixelBuffer;
+ ConvertReverseNetworkOrder (&pixelBuffer, sizeof(T));
+ da[ix][iy] = pixelBuffer;
}
return (true);
return (false);
}
- if (array == NULL) { // Could not have written data if array not allocated
+ if (array.getArray() == NULL) { // Could not have written data if array not allocated
sys_error (ERR_WARNING, "array == NULL [labelSeek]");
return (false);
}
- off_t pos = headersize + array->sizeofArray();
+ off_t pos = headersize + array.sizeofArray();
if (lseek (file_id, pos, SEEK_SET) != pos) {
sys_error (ERR_WARNING, "Can't seek to end of data array");
return (false);
return (false);
}
- read_nint16 (&label.label_type, file_id);
- read_nint16 (&label.year, file_id);
- read_nint16 (&label.month, file_id);
- read_nint16 (&label.day, file_id);
- read_nint16 (&label.hour, file_id);
- read_nint16 (&label.minute, file_id);
- read_nint16 (&label.second, file_id);
- read_nfloat64 (&label.calc_time, file_id);
+ read_nint16 (&label.m_labelType, file_id);
+ read_nint16 (&label.m_year, file_id);
+ read_nint16 (&label.m_month, file_id);
+ read_nint16 (&label.m_day, file_id);
+ read_nint16 (&label.m_hour, file_id);
+ read_nint16 (&label.m_minute, file_id);
+ read_nint16 (&label.m_second, file_id);
+ read_nfloat64 (&label.m_calcTime, file_id);
kuint16 strlength;
read_nint16 (&strlength, file_id);
- char *str = new char [strlength+1];
+ char str [strlength+1];
read (file_id, str, strlength);
- label.label_str = str;
+ str[strlength] = 0;
+ label.m_strLabel = str;
return (true);
}
{
labelSeek (num_labels);
- write_nint16 (&label.label_type, file_id);
- write_nint16 (&label.year, file_id);
- write_nint16 (&label.month, file_id);
- write_nint16 (&label.day, file_id);
- write_nint16 (&label.hour, file_id);
- write_nint16 (&label.minute, file_id);
- write_nint16 (&label.second, file_id);
- write_nfloat64 (&label.calc_time, file_id);
- kuint16 strlength = label.label_str.length();
+ write_nint16 (&label.m_labelType, file_id);
+ write_nint16 (&label.m_year, file_id);
+ write_nint16 (&label.m_month, file_id);
+ write_nint16 (&label.m_day, file_id);
+ write_nint16 (&label.m_hour, file_id);
+ write_nint16 (&label.m_minute, file_id);
+ write_nint16 (&label.m_second, file_id);
+ write_nfloat64 (&label.m_calcTime, file_id);
+ kuint16 strlength = label.m_strLabel.length();
write_nint16 (&strlength, file_id);
- write (file_id, static_cast<const void*>(label.label_str.c_str()), strlength);
+ write (file_id, static_cast<const void*>(label.m_strLabel.c_str()), strlength);
num_labels++;
fsync(file_id);
}
+template<class T>
+void
+Array2dFile<T>::labelsCopy (Array2dFile& copyFile, const char* const idStr)
+{
+ string id = idStr;
+ for (int i = 0; i < copyFile.getNumLabels(); i++) {
+ Array2dFileLabel l;
+ copyFile.labelRead (l, i);
+ string lstr = l.getLabelString();
+ lstr = idStr + lstr;
+ l.setLabelString (lstr);
+ labelAdd (l);
+ }
+}
-#endif
+template<class T>
+void
+Array2dFile<T>::arrayDataClear (void)
+{
+ T** v = array.getArray();
+ if (v) {
+ for (unsigned int ix = 0; ix < mNX; ix++)
+ for (unsigned int iy = 0; iy < mNY; iy++)
+ v[ix][iy] = 0;
+ }
+}
-#ifdef MPI_CT
-#include <mpi.h>
+
+#ifdef HAVE_MPI
+#include <mpi++.h>
#endif
-class F32Image
+class F32Image : public Array2dFile<kfloat32>
{
public:
- Array2dFile<kfloat32> adf;
-
- F32Image (const char* const fname, unsigned int nx, unsigned int ny) : adf (fname, nx, ny)
+ F32Image (const char* const fname, unsigned int nx, unsigned int ny)
+ : Array2dFile<kfloat32>::Array2dFile (fname, nx, ny)
{
- adf.setPixelType (Array2dFile<kfloat64>::FLOAT32);
+ setPixelType (FLOAT32);
}
- F32Image (unsigned int nx, unsigned int ny) : adf (nx, ny)
+ F32Image (unsigned int nx, unsigned int ny)
+ : Array2dFile<kfloat32>::Array2dFile (nx, ny)
{
- adf.setPixelType (Array2dFile<kfloat64>::FLOAT32);
+ setPixelType (FLOAT32);
}
- F32Image (const char* const fname) : adf (fname)
+ F32Image (const char* const fname)
+ : Array2dFile<kfloat32>::Array2dFile (fname)
{
- adf.setPixelType (Array2dFile<kfloat64>::FLOAT32);
+ setPixelType (FLOAT32);
}
-#ifdef MPI_CT
- MPI_Datatype getMPIDataType (void) const
- { return MPI_FLOAT; }
+#ifdef HAVE_MPI
+ MPI::Datatype getMPIDataType (void) const
+ { return MPI::FLOAT; }
#endif
};
-class F64Image
-{
-public:
- Array2dFile<kfloat64> adf;
-#ifdef MPI_CT
- MPI_Datatype getMPIDataType (void) const
- { return MPI_DOUBLE; }
-#endif
+class F64Image : public Array2dFile<kfloat64>
+{
+ public:
- F64Image (const char* const fname, unsigned int nx, unsigned int ny) : adf (fname, nx, ny)
+ F64Image (const char* const fname, unsigned int nx, unsigned int ny)
+ : Array2dFile<kfloat64>::Array2dFile (fname, nx, ny)
{
- adf.setPixelType (Array2dFile<kfloat64>::FLOAT64);
+ setPixelType (FLOAT64);
}
- F64Image (unsigned int nx, unsigned int ny) : adf (nx, ny)
+ F64Image (unsigned int nx, unsigned int ny)
+ : Array2dFile<kfloat64>::Array2dFile (nx, ny)
{
- adf.setPixelType (Array2dFile<kfloat64>::FLOAT64);
+ setPixelType (FLOAT64);
}
- F64Image (const char* const fname) : adf (fname)
+ F64Image (const char* const fname)
+ : Array2dFile<kfloat64>::Array2dFile (fname)
{
- adf.setPixelType (Array2dFile<kfloat64>::FLOAT64);
+ setPixelType (FLOAT64);
}
+
+#ifdef HAVE_MPI
+ MPI::Datatype getMPIDataType (void) const
+ { return MPI::DOUBLE; }
+#endif
};
+#define IMAGEFILE_64_BITS 1
+#ifdef IMAGEFILE_64_BITS
typedef F64Image ImageFile;
typedef kfloat64 ImageFileValue;
typedef kfloat64* ImageFileColumn;
typedef kfloat64** ImageFileArray;
+#else
+typedef F32Image ImageFile;
+typedef kfloat32 ImageFileValue;
+typedef kfloat32* ImageFileColumn;
+typedef kfloat32** ImageFileArray;
+#endif
+
+#endif