X-Git-Url: http://git.kpe.io/?p=ctsim.git;a=blobdiff_plain;f=include%2Fimagefile.h;h=ccf376905fe670c38a1233c52cbdb10e2260db25;hp=3c1bb9a8ef87fec8fb4b17809350298b4f2fff32;hb=f4a23943110823118f35756dd41fbd6707f04511;hpb=7438260c07e4f3d71c7f43669678c3a912682e4c diff --git a/include/imagefile.h b/include/imagefile.h index 3c1bb9a..ccf3769 100644 --- a/include/imagefile.h +++ b/include/imagefile.h @@ -13,17 +13,20 @@ class Array2dFileLabel { 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; @@ -37,22 +40,22 @@ public: ~Array2dFileLabel(); - string getLabelString (void) const - { return label_str; } + const string& getLabelString (void) const + { return m_strLabel; } kfloat64 getCalcTime (void) const - { return calc_time; } + { return m_calcTime; } kfloat64 getLabelType (void) const - { return label_type; } + { return m_labelType; } string& setLabelString (const char* const str) - { label_str = str; return (label_str); } + { m_strLabel = str; return (m_strLabel); } string& setLabelString (const string& str) - { label_str = str; return (label_str); } + { m_strLabel = str; return (m_strLabel); } - void getDateString (string& str) const; + const string& getDateString () const; }; @@ -88,9 +91,12 @@ private: kuint32 mNX; kuint32 mNY; + Array2dFile (const Array2dFile&); + Array2dFile& operator= (const Array2dFile&); + public: - Array2d *array; + Array2d array; static const int INT8 = 1; static const int UINT8 = 2; @@ -113,9 +119,9 @@ public: 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 label_str, double calc_time=0.); + void labelAdd (int type, const char* const m_strLabel, double calc_time=0.); void labelsCopy (Array2dFile& file, const char* const idStr = NULL); @@ -139,7 +145,7 @@ public: void doPixelOffsetScale (double offset, double scale); T** getArray (void) const - { return (array == NULL ? NULL : array->getArray()); } + { return (array.getArray()); } bool arrayDataWrite (void); @@ -160,7 +166,7 @@ Array2dFile::Array2dFile (unsigned int x, unsigned int y) init(); mNX = x; mNY = y; - array = new Array2d (mNX, mNY); + array.initSetSize(mNX, mNY); } template @@ -170,7 +176,7 @@ Array2dFile::Array2dFile (const char * const str, unsigned int x, unsigned in init(); mNX = x; mNY = y; - array = new Array2d (mNX, mNY); + array.initSetSize(mNX, mNY); } template @@ -197,7 +203,6 @@ Array2dFile::init (void) mMinX = mMaxX = mMinY = mMaxY = 0; mOffsetPV = 0; mScalePV = 1; - array = NULL; io = NULL; #if 0 @@ -240,11 +245,10 @@ template void Array2dFile::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; } } @@ -272,10 +276,8 @@ Array2dFile::fileRead (void) } headerRead(); - if (array != NULL) - delete array; - array = new Array2d (mNX, mNY); + array.initSetSize(mNX, mNY); arrayDataRead(); @@ -306,8 +308,8 @@ template void Array2dFile::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++) @@ -322,14 +324,14 @@ template void Array2dFile::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; } } @@ -430,12 +432,16 @@ Array2dFile::arrayDataWrite (void) 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, &value, mPixelSize); + T value = da[ix][iy]; + ConvertReverseNetworkOrder (&value, sizeof(T)); + write (file_id, &value, mPixelSize); } return (true); @@ -450,13 +456,17 @@ Array2dFile::arrayDataRead (void) 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); @@ -471,12 +481,12 @@ Array2dFile::labelSeek (unsigned int label_num) 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); @@ -515,20 +525,21 @@ Array2dFile::labelRead (Array2dFileLabel& label, unsigned int label_num) 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); } @@ -556,17 +567,17 @@ Array2dFile::labelAdd (const Array2dFileLabel& label) { 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(label.label_str.c_str()), strlength); + write (file_id, static_cast(label.m_strLabel.c_str()), strlength); num_labels++; @@ -593,8 +604,8 @@ template void Array2dFile::arrayDataClear (void) { - if (array != NULL) { - T** v = array->getArray(); + 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; @@ -602,39 +613,31 @@ Array2dFile::arrayDataClear (void) } -#ifdef MPI_CT -#include +#ifdef HAVE_MPI +#include #endif -class F32Image +class F32Image : public Array2dFile { public: - Array2dFile 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::Array2dFile (fname, nx, ny) { - adf.setPixelType (Array2dFile::FLOAT32); + setPixelType (FLOAT32); } - F32Image (unsigned int nx, unsigned int ny) : adf (nx, ny) + F32Image (unsigned int nx, unsigned int ny) + : Array2dFile::Array2dFile (nx, ny) { - adf.setPixelType (Array2dFile::FLOAT32); + setPixelType (FLOAT32); } - F32Image (const char* const fname) : adf (fname) + F32Image (const char* const fname) + : Array2dFile::Array2dFile (fname) { - adf.setPixelType (Array2dFile::FLOAT32); + setPixelType (FLOAT32); } - 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; } @@ -642,45 +645,46 @@ public: }; -class F64Image +class F64Image : public Array2dFile { -public: - Array2dFile adf; + public: -#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) + F64Image (const char* const fname, unsigned int nx, unsigned int ny) + : Array2dFile::Array2dFile (fname, nx, ny) { - adf.setPixelType (Array2dFile::FLOAT64); + setPixelType (FLOAT64); } - F64Image (unsigned int nx, unsigned int ny) : adf (nx, ny) + F64Image (unsigned int nx, unsigned int ny) + : Array2dFile::Array2dFile (nx, ny) { - adf.setPixelType (Array2dFile::FLOAT64); + setPixelType (FLOAT64); } - F64Image (const char* const fname) : adf (fname) + F64Image (const char* const fname) + : Array2dFile::Array2dFile (fname) { - adf.setPixelType (Array2dFile::FLOAT64); + setPixelType (FLOAT64); } - kfloat64** 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::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