r145: *** empty log message ***
[ctsim.git] / libctsim / array2dfile.cpp
index d60381318d132fc35fe6e47b63f78c5a5231d0f8..ed04a7c04f3ee149dc6a7266a885eaa4b96be7c7 100644 (file)
@@ -9,7 +9,7 @@
 **  This is part of the CTSim program
 **  Copyright (C) 1983-2000 Kevin Rosenberg
 **
-**  $Id: array2dfile.cpp,v 1.1 2000/06/26 21:15:24 kevin Exp $
+**  $Id: array2dfile.cpp,v 1.6 2000/07/13 07:03:21 kevin Exp $
 **
 **  This program is free software; you can redistribute it and/or modify
 **  it under the terms of the GNU General Public License (version 2) as
@@ -46,8 +46,8 @@ Array2dFileLabel::init (void)
     m_labelType = L_EMPTY;
     time_t t = time(0);
     tm* lt = localtime(&t);
-    m_year = lt->tm_year + 1900;
-    m_month = lt->tm_mon + 1;
+    m_year = lt->tm_year;
+    m_month = lt->tm_mon;
     m_day = lt->tm_mday;
     m_hour = lt->tm_hour;
     m_minute = lt->tm_min;
@@ -60,7 +60,7 @@ Array2dFileLabel::Array2dFileLabel()
 }
 
 Array2dFileLabel::Array2dFileLabel(const char* const str, double ctime = 0.)
-  : m_strLabel (str)
+    : m_strLabel (str)
 {
     init();
 
@@ -107,12 +107,51 @@ const string&
 Array2dFileLabel::getDateString (void) const
 {
   ostringstream oss;
-  oss <<  m_month <<"/"<< m_day <<"/"<< m_year << " " << m_hour <<":"<<  m_minute <<":"<< m_second;
+  oss <<  static_cast<int>(m_month + 1) <<"/"<< static_cast<int>(m_day) <<"/"<< static_cast<int>(m_year + 1900) << " " << static_cast<int>(m_hour) <<":"<<  static_cast<int>(m_minute) <<":"<< static_cast<int>(m_second);
   m_strDate = oss.str();
   return m_strDate;
 }
 
 
+Array2dFileLabel::Array2dFileLabel (const Array2dFileLabel& rhs)
+{
+    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;
+}
+
+Array2dFileLabel&
+Array2dFileLabel::operator= (const Array2dFileLabel& rhs)
+{
+    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 (ostream& os) const
+{
+  if (m_labelType == L_HISTORY) {
+    os << "History: " << endl;
+    os << "  " << m_strLabel << endl;
+    os << "  calc time = " << m_calcTime << " secs" << endl;
+    os << "  Timestamp = " << getDateString() << endl;
+  } else if (m_labelType == L_USER) {
+    os << "Note: " <<  m_strLabel << endl;
+    os << "  Timestamp = %s" << getDateString() << endl;
+  } else {
+    os << "Unknown (" << m_labelType << "): " <<  m_strLabel << endl;
+    os << "  Timestamp = %s" << getDateString() << endl;
+  }
+}
+
+
 ///////////////////////////////////////////////////////////////////////////
 // CLASS IMPLEMENTATION
 //
@@ -186,7 +225,7 @@ Array2dFile::allocArray (void)
     m_arrayData = new unsigned char* [m_nx];
     
     int columnBytes = m_ny * m_pixelSize;
-    for (int i = 0; i < m_nx; i++)
+    for (unsigned int i = 0; i < m_nx; i++)
        m_arrayData[i] = new unsigned char [columnBytes];
 }
 
@@ -194,13 +233,19 @@ void
 Array2dFile::freeArray (void)
 {
     if (m_arrayData) {
-       for (int i = 0; i < m_nx; i++)
+       for (unsigned int i = 0; i < m_nx; i++)
            delete m_arrayData[i];
        delete m_arrayData;
        m_arrayData = NULL;
     }
 }
 
+bool
+Array2dFile::fileWrite (const string& filename)
+{
+  return fileWrite (filename.c_str());
+}
+
 bool
 Array2dFile::fileWrite (const char* const filename)
 {
@@ -223,6 +268,12 @@ Array2dFile::fileWrite (const char* const filename)
     return true;
 }
 
+bool
+Array2dFile::fileRead (const string& filename)
+{
+  return fileRead (filename.c_str());
+}
+
 bool
 Array2dFile::fileRead (const char* const filename)
 {
@@ -388,7 +439,7 @@ Array2dFile::arrayDataRead (frnetorderstream& fs)
 
   fs.seekg (m_headersize);
   int columnSize = m_ny * m_pixelSize;
-  for (int ix = 0; ix < m_nx; ix++) {
+  for (unsigned int ix = 0; ix < m_nx; ix++) {
       unsigned char* ptrColumn = m_arrayData[ix];
       if (NativeBigEndian()) {
          for (unsigned int iy = 0; iy < m_ny; iy++) {
@@ -500,8 +551,8 @@ void
 Array2dFile::labelsCopy (Array2dFile& copyFile, const char* const idStr)
 {
     string id = idStr;
-    for (int i = 0; i < copyFile.getNumLabels(); i++) {
-      Array2dFileLabel l = copyFile.labelGet (i);
+    for (unsigned int i = 0; i < copyFile.getNumLabels(); i++) {
+      Array2dFileLabel l (copyFile.labelGet (i));
       string lstr = l.getLabelString();
       lstr = idStr + lstr;
       l.setLabelString (lstr);
@@ -514,7 +565,7 @@ Array2dFile::arrayDataClear (void)
 {
     if (m_arrayData) {
        int columnSize = m_ny * m_pixelSize;
-       for (int ix = 0; ix < m_nx; ix++)
+       for (unsigned int ix = 0; ix < m_nx; ix++)
            memset (m_arrayData[ix], 0, columnSize);
     }
 }
@@ -522,21 +573,11 @@ Array2dFile::arrayDataClear (void)
 void
 Array2dFile::printLabels (ostream& os) const
 {
-    int nlabels = getNumLabels();
-
     for (constLabelIterator l = m_labels.begin(); l != m_labels.end(); l++) {
       const Array2dFileLabel& label = **l;
 
-      if (label.getLabelType() == Array2dFileLabel::L_HISTORY) {
-       os << "History: " << endl;
-       os << "  " << label.getLabelString() << endl;
-       os << "  calc time = " << label.getCalcTime() << " secs" << endl;
-       os << "  Timestamp = " << label.getDateString() << endl;
-      } else if (label.getLabelType() == Array2dFileLabel::L_USER) {
-       os << "Note: " <<  label.getLabelString() << endl;
-           os << "  Timestamp = %s" << label.getDateString() << endl;
-      }
-       os << endl;
+      label.print (os);
+      os << endl;
     }
 }