#include <string>
#include "kstddef.h"
+#include <sys/types.h>
+#include <unistd.h>
#include <array2d.h>
using namespace std;
~Array2dFileLabel();
- const string& getLabelString (void) const
+ string getLabelString (void) const
{ return label_str; }
kfloat64 getCalcTime (void) const
kfloat64 getLabelType (void) const
{ return label_type; }
+ string& setLabelString (const char* const str)
+ { label_str = str; return (label_str); }
+
+ string& setLabelString (const string& str)
+ { label_str = str; return (label_str); }
+
void getDateString (string& str) const;
};
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 setPixelType (int type)
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);
bool arrayDataWrite (void);
+ void arrayDataClear (void);
+
bool fileRead (void);
bool fileCreate (void);
Array2dFile<T>::~Array2dFile (void)
{
fileClose ();
+ delete array;
}
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;
}
}
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();
+ if (array != NULL) {
+ T** da = array->getArray();
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>
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);
+ ConvertReverseNetworkOrder (&value, sizeof(T));
+ write (file_id, &value, mPixelSize);
}
return (true);
for (int ix = 0; ix < mNX; ix++)
for (unsigned int iy = 0; iy < mNY; iy++) {
read (file_id, &pixelBuffer, mPixelSize);
- ConvertNetworkOrder (&pixelBuffer, sizeof(T));
+ ConvertReverseNetworkOrder (&pixelBuffer, sizeof(T));
array->array_data[ix][iy] = pixelBuffer;
}
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);
+ }
+}
+
+template<class T>
+void
+Array2dFile<T>::arrayDataClear (void)
+{
+ if (array != NULL) {
+ T** v = array->getArray();
+ for (unsigned int ix = 0; ix < mNX; ix++)
+ for (unsigned int iy = 0; iy < mNY; iy++)
+ v[ix][iy] = 0;
+ }
+}
-#endif
#ifdef MPI_CT
#include <mpi.h>
adf.setPixelType (Array2dFile<kfloat64>::FLOAT32);
}
-#ifdef MPI_CT
- MPI_Datatype getMPIDataType (void) const
- { return MPI_FLOAT; }
+ kfloat32** getArray(void) const
+ { return adf.getArray(); }
+
+ kuint32 nx(void) const
+ { return adf.nx(); }
+
+ kuint32 ny(void) const
+ { return adf.ny(); }
+
+#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; }
+#ifdef HAVE_MPI
+ MPI::Datatype getMPIDataType (void) const
+ { return MPI::DOUBLE; }
#endif
F64Image (const char* const fname, unsigned int nx, unsigned int ny) : adf (fname, nx, ny)
{
adf.setPixelType (Array2dFile<kfloat64>::FLOAT64);
}
+
+ kfloat64** getArray(void) const
+ { return adf.getArray(); }
+
+ kuint32 nx(void) const
+ { return adf.nx(); }
+
+ kuint32 ny(void) const
+ { return adf.ny(); }
};
typedef F64Image ImageFile;
typedef kfloat64* ImageFileColumn;
typedef kfloat64** ImageFileArray;
+#endif
+