- char szDate [128];\r
- snprintf (szDate, sizeof(szDate), "%2d/%02d/%4d %02d:%02d:%02d",\r
- m_month + 1, m_day, m_year + 1900, m_hour, m_minute, m_second);
+ char szDate [128];
+ snprintf (szDate, sizeof(szDate), "%2d/%02d/%4d %02d:%02d:%02d",
+ m_month + 1, m_day, m_year + 1900, m_hour, m_minute, m_second);
- m_calcTime = rhs.m_calcTime;
- m_labelType = rhs.m_labelType;
- m_strLabel = rhs.m_strLabel;
- m_year = rhs.m_year; m_month = rhs.m_month; m_day = rhs.m_day;
- m_hour = rhs.m_hour; m_minute = rhs.m_minute; m_second = rhs.m_second;
+ m_calcTime = rhs.m_calcTime;
+ m_labelType = rhs.m_labelType;
+ m_strLabel = rhs.m_strLabel;
+ m_year = rhs.m_year; m_month = rhs.m_month; m_day = rhs.m_day;
+ m_hour = rhs.m_hour; m_minute = rhs.m_minute; m_second = rhs.m_second;
- m_calcTime = rhs.m_calcTime;
- m_labelType = rhs.m_labelType;
- m_strLabel = rhs.m_strLabel;
- m_year = rhs.m_year; m_month = rhs.m_month; m_day = rhs.m_day;
- m_hour = rhs.m_hour; m_minute = rhs.m_minute; m_second = rhs.m_second;
+ m_calcTime = rhs.m_calcTime;
+ m_labelType = rhs.m_labelType;
+ m_strLabel = rhs.m_strLabel;
+ m_year = rhs.m_year; m_month = rhs.m_month; m_day = rhs.m_day;
+ m_hour = rhs.m_hour; m_minute = rhs.m_minute; m_second = rhs.m_second;
+
+ return (*this);
+}
+void
+Array2dFileLabel::print (std::ostream& os) const
+{
+ if (m_labelType == L_HISTORY) {
+ os << "History: " << std::endl;
+ os << " " << m_strLabel << std::endl;
+ os << " calc time = " << m_calcTime << " secs" << std::endl;
+ os << " Timestamp = " << getDateString() << std::endl;
+ } else if (m_labelType == L_USER) {
+ os << "Note: " << m_strLabel << std::endl;
+ os << " Timestamp = %s" << getDateString() << std::endl;
+ } else {
+ os << "Unknown (" << m_labelType << "): " << m_strLabel << std::endl;
+ os << " Timestamp = %s" << getDateString() << std::endl;
+ }
+}
+
+void
+Array2dFileLabel::printBrief (std::ostream& os) const
+{
+ if (m_labelType == L_HISTORY) {
+ os << "History (";
+ if (m_calcTime > 0)
+ os << m_calcTime << " secs, ";
+ os << getDateString() << "): " << m_strLabel << std::endl;
+ } else if (m_labelType == L_USER) {
+ os << "Note (" << getDateString() << "): " << m_strLabel << std::endl;
+ } else {
+ os << "Unknown (" << getDateString() << "): " << m_strLabel << std::endl;
+ }
- m_arraySize = m_nx * m_ny * m_pixelSize;
- m_arrayData = new unsigned char* [m_nx];
-
- int columnBytes = m_ny * m_pixelSize;
- for (unsigned int i = 0; i < m_nx; i++)
- m_arrayData[i] = new unsigned char [columnBytes];
+ allocArray (m_arrayData);
+ if (m_dataType == DATA_TYPE_COMPLEX)
+ allocArray (m_imaginaryArrayData);
+}
+
+void
+Array2dFile::allocArray (unsigned char**& rppData)
+{
+ m_arraySize = m_nx * m_ny * m_pixelSize;
+ rppData = new unsigned char* [m_nx];
+ int columnBytes = m_ny * m_pixelSize;
+ for (unsigned int i = 0; i < m_nx; i++)
+ rppData[i] = new unsigned char [columnBytes];
- m_filename = filename;
-
- frnetorderstream fs (m_filename.c_str(), ios::out | ios::in | ios::trunc | ios::binary);
- if (fs.fail()) {
- sys_error (ERR_WARNING, "Error opening file %s for writing [fileCreate]", m_filename.c_str());
- return false;
- }
- if (! headerWrite(fs))
- return false;
-
- if (! arrayDataWrite (fs))
- return false;
-
- if (! labelsWrite (fs))
- return false;
-
- return true;
+ m_filename = filename;
+
+ frnetorderstream fs (m_filename.c_str(), std::ios::out | std::ios::in | std::ios::trunc | std::ios::binary);
+ if (fs.fail()) {
+ sys_error (ERR_WARNING, "Error opening file %s for writing [fileCreate]", m_filename.c_str());
+ return false;
+ }
+ if (! headerWrite(fs))
+ return false;
+
+ if (! arrayDataWrite (fs))
+ return false;
+
+ if (! labelsWrite (fs))
+ return false;
+
+ return true;
- m_filename = filename;
-
-#ifdef MSVC\r
- frnetorderstream fs (m_filename.c_str(), ios::out | ios::in | ios::binary);\r
-#else\r
- frnetorderstream fs (m_filename.c_str(), ios::out | ios::in | ios::binary | ios::nocreate);\r
-#endif\r
- if (fs.fail()) {
- sys_error (ERR_WARNING, "Unable to open file %s [fileRead]", m_filename.c_str());
- return false;
- }
-
- if (! headerRead(fs))
- return false;
-
- allocArray ();
-
- if (! arrayDataRead(fs))
- return false;;
-
- if (! labelsRead (fs))
- return false;
-
- return true;
+ m_filename = filename;
+
+#ifdef MSVC
+ frnetorderstream fs (m_filename.c_str(), std::ios::out | std::ios::in | std::ios::binary);
+#else
+ frnetorderstream fs (m_filename.c_str(), std::ios::out | std::ios::in | std::ios::binary | std::ios::nocreate);
+#endif
+ if (fs.fail()) {
+ sys_error (ERR_WARNING, "Unable to open file %s [fileRead]", m_filename.c_str());
+ return false;
+ }
+
+ if (! headerRead(fs))
+ return false;
+
+ allocArrays ();
+
+ if (! arrayDataRead(fs))
+ return false;;
+
+ if (! labelsRead (fs))
+ return false;
+
+ return true;
int read_m_headersize = fs.tellg();
if (read_m_headersize != m_headersize) {
sys_error (ERR_WARNING, "Read m_headersize %d != file m_headersize %d", read_m_headersize, m_headersize);
int read_m_headersize = fs.tellg();
if (read_m_headersize != m_headersize) {
sys_error (ERR_WARNING, "Read m_headersize %d != file m_headersize %d", read_m_headersize, m_headersize);
- unsigned char* ptrColumn = m_arrayData[ix];
+ unsigned char* ptrColumn = m_arrayData[ix];
+ if (NativeBigEndian()) {
+ for (unsigned int iy = 0; iy < m_ny; iy++) {
+ ConvertReverseNetworkOrder (ptrColumn, m_pixelSize);
+ fs.write (reinterpret_cast<const char*>(ptrColumn), m_pixelSize);
+ ptrColumn += m_pixelSize;
+ }
+ } else
+ fs.write (reinterpret_cast<const char*>(ptrColumn), columnSize);
+ }
+ if (m_dataType == DATA_TYPE_COMPLEX) {
+ for (unsigned int ix = 0; ix < m_nx; ix++) {
+ unsigned char* ptrColumn = m_imaginaryArrayData[ix];
- for (unsigned int iy = 0; iy < m_ny; iy++) {
- ConvertReverseNetworkOrder (ptrColumn, m_pixelSize);
- fs.write (reinterpret_cast<const char*>(ptrColumn), m_pixelSize);
- ptrColumn += m_pixelSize;
- }
+ for (unsigned int iy = 0; iy < m_ny; iy++) {
+ ConvertReverseNetworkOrder (ptrColumn, m_pixelSize);
+ fs.write (reinterpret_cast<const char*>(ptrColumn), m_pixelSize);
+ ptrColumn += m_pixelSize;
+ }
- unsigned char* ptrColumn = m_arrayData[ix];
+ unsigned char* ptrColumn = m_arrayData[ix];
+ if (NativeBigEndian()) {
+ for (unsigned int iy = 0; iy < m_ny; iy++) {
+ fs.read (reinterpret_cast<char*>(ptrColumn), m_pixelSize);
+ ConvertReverseNetworkOrder (ptrColumn, m_pixelSize);
+ ptrColumn += m_pixelSize;
+ }
+ } else
+ fs.read (reinterpret_cast<char*>(ptrColumn), columnSize);
+ }
+ if (m_dataType == DATA_TYPE_COMPLEX) {
+ for (unsigned int ix = 0; ix < m_nx; ix++) {
+ unsigned char* ptrColumn = m_imaginaryArrayData[ix];
- for (unsigned int iy = 0; iy < m_ny; iy++) {
- fs.read (reinterpret_cast<char*>(ptrColumn), m_pixelSize);
- ConvertReverseNetworkOrder (ptrColumn, m_pixelSize);
- ptrColumn += m_pixelSize;
- }
+ for (unsigned int iy = 0; iy < m_ny; iy++) {
+ fs.read (reinterpret_cast<char*>(ptrColumn), m_pixelSize);
+ ConvertReverseNetworkOrder (ptrColumn, m_pixelSize);
+ ptrColumn += m_pixelSize;
+ }
- off_t pos = m_headersize + m_arraySize;
- fs.seekg (pos);
- if (fs.fail())
- return false;
-
- for (int i = 0; i < m_numFileLabels; i++) {
- kuint16 labelType, year, month, day, hour, minute, second;
- kfloat64 calcTime;
-
- fs.readInt16 (labelType);
- fs.readInt16 (year);
- fs.readInt16 (month);
- fs.readInt16 (day);
- fs.readInt16 (hour);
- fs.readInt16 (minute);
- fs.readInt16 (second);
- fs.readFloat64 (calcTime);
-
- kuint16 strLength;
- fs.readInt16 (strLength);
- char* pszLabelStr = new char [strLength+1];
- fs.read (pszLabelStr, strLength);
- pszLabelStr[strLength] = 0;
-
- Array2dFileLabel* pLabel = new Array2dFileLabel (labelType, pszLabelStr, calcTime);
- delete pszLabelStr;\r
-\r
- pLabel->setDateTime (year, month, day, hour, minute, second);
- m_labels.push_back (pLabel);\r
- }
-
- return true;
+ off_t pos = m_headersize + m_arraySize;
+ fs.seekg (pos);
+ if (fs.fail())
+ return false;
+
+ for (int i = 0; i < m_numFileLabels; i++) {
+ kuint16 labelType, year, month, day, hour, minute, second;
+ kfloat64 calcTime;
+
+ fs.readInt16 (labelType);
+ fs.readInt16 (year);
+ fs.readInt16 (month);
+ fs.readInt16 (day);
+ fs.readInt16 (hour);
+ fs.readInt16 (minute);
+ fs.readInt16 (second);
+ fs.readFloat64 (calcTime);
+
+ kuint16 strLength;
+ fs.readInt16 (strLength);
+ char* pszLabelStr = new char [strLength+1];
+ fs.read (pszLabelStr, strLength);
+ pszLabelStr[strLength] = 0;
+
+ Array2dFileLabel* pLabel = new Array2dFileLabel (labelType, pszLabelStr, calcTime);
+ delete pszLabelStr;
+
+ pLabel->setDateTime (year, month, day, hour, minute, second);
+ m_labels.push_back (pLabel);
+ }
+
+ return true;
- off_t pos = m_headersize + m_arraySize;
- fs.seekp (pos);
-
- for (constLabelIterator l = m_labels.begin(); l != m_labels.end(); l++) {
- const Array2dFileLabel& label = **l;
- kuint16 labelType = label.getLabelType();
- kfloat64 calcTime = label.getCalcTime();
- const char* const labelString = label.getLabelString().c_str();
- int year, month, day, hour, minute, second;
- kuint16 yearBuf, monthBuf, dayBuf, hourBuf, minuteBuf, secondBuf;
-
- label.getDateTime (year, month, day, hour, minute, second);
- yearBuf = year; monthBuf = month; dayBuf = day;
- hourBuf = hour; minuteBuf = minute; secondBuf = second;
-
- fs.writeInt16 (labelType);
- fs.writeInt16 (yearBuf);
- fs.writeInt16 (monthBuf);
- fs.writeInt16 (dayBuf);
- fs.writeInt16 (hourBuf);
- fs.writeInt16 (minuteBuf);
- fs.writeInt16 (secondBuf);
- fs.writeFloat64 (calcTime);
- kuint16 strlength = strlen (labelString);
- fs.writeInt16 (strlength);
- fs.write (labelString, strlength);
- }
-
- return true;
+ off_t pos = m_headersize + m_arraySize;
+ fs.seekp (pos);
+
+ for (constLabelIterator l = m_labels.begin(); l != m_labels.end(); l++) {
+ const Array2dFileLabel& label = **l;
+ kuint16 labelType = label.getLabelType();
+ kfloat64 calcTime = label.getCalcTime();
+ const char* const labelString = label.getLabelString().c_str();
+ int year, month, day, hour, minute, second;
+ kuint16 yearBuf, monthBuf, dayBuf, hourBuf, minuteBuf, secondBuf;
+
+ label.getDateTime (year, month, day, hour, minute, second);
+ yearBuf = year; monthBuf = month; dayBuf = day;
+ hourBuf = hour; minuteBuf = minute; secondBuf = second;
+
+ fs.writeInt16 (labelType);
+ fs.writeInt16 (yearBuf);
+ fs.writeInt16 (monthBuf);
+ fs.writeInt16 (dayBuf);
+ fs.writeInt16 (hourBuf);
+ fs.writeInt16 (minuteBuf);
+ fs.writeInt16 (secondBuf);
+ fs.writeFloat64 (calcTime);
+ kuint16 strlength = strlen (labelString);
+ fs.writeInt16 (strlength);
+ fs.write (labelString, strlength);
+ }
+
+ return true;
-Array2dFile::labelsCopy (Array2dFile& copyFile, const char* const pszId)
-{
- string id;
- if (pszId)
- id = pszId;
- for (unsigned int i = 0; i < copyFile.getNumLabels(); i++) {
- Array2dFileLabel l (copyFile.labelGet (i));
- string lstr = l.getLabelString();
- lstr = idStr + lstr;
- l.setLabelString (lstr);
- labelAdd (l);
- }
+Array2dFile::labelsCopy (const Array2dFile& copyFile, const char* const pszId)
+{
+ std::string id;
+ if (pszId)
+ id = pszId;
+ for (unsigned int i = 0; i < copyFile.getNumLabels(); i++) {
+ Array2dFileLabel l (copyFile.labelGet (i));
+ std::string lstr = l.getLabelString();
+ lstr = id + lstr;
+ l.setLabelString (lstr);
+ labelAdd (l);
+ }
- if (m_arrayData) {
- int columnSize = m_ny * m_pixelSize;
- for (unsigned int ix = 0; ix < m_nx; ix++)
- memset (m_arrayData[ix], 0, columnSize);
- }
+ if (m_arrayData) {
+ int columnSize = m_ny * m_pixelSize;
+ for (unsigned int ix = 0; ix < m_nx; ix++)
+ memset (m_arrayData[ix], 0, columnSize);
+ }
+ if (m_imaginaryArrayData) {
+ int columnSize = m_ny * m_pixelSize;
+ for (unsigned int ix = 0; ix < m_nx; ix++)
+ memset (m_arrayData[ix], 0, columnSize);
+ }