r242: *** empty log message ***
[ctsim.git] / libctsim / array2dfile.cpp
index 03a5f1afdf0424fb3b66584ba1d808e3f5aad6f0..f918471f54e7278a5789f5095efddaae9f091231 100644 (file)
@@ -9,7 +9,7 @@
 **  This is part of the CTSim program
 **  Copyright (C) 1983-2000 Kevin Rosenberg
 **
-**  $Id: array2dfile.cpp,v 1.4 2000/06/29 12:39:46 kevin Exp $
+**  $Id: array2dfile.cpp,v 1.13 2000/12/04 04:15:48 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
 #include <ctime>
 #include <sstream>
 
+
 using namespace std;
 
+const kuint16 Array2dFile::m_signature = ('I'*256+'F');
 
 ///////////////////////////////////////////////////////////////////////////
 // CLASS IMPLEMENTATION
@@ -59,7 +61,7 @@ Array2dFileLabel::Array2dFileLabel()
     init();
 }
 
-Array2dFileLabel::Array2dFileLabel(const char* const str, double ctime = 0.)
+Array2dFileLabel::Array2dFileLabel(const char* const str, double ctime)
     : m_strLabel (str)
 {
     init();
@@ -68,7 +70,7 @@ Array2dFileLabel::Array2dFileLabel(const char* const str, double ctime = 0.)
     m_calcTime = ctime;
 }
 
-Array2dFileLabel::Array2dFileLabel(const int type, const char* const str, double ctime = 0.)
+Array2dFileLabel::Array2dFileLabel(const int type, const char* const str, double ctime)
   :  m_strLabel (str)
 {
     init();
@@ -107,7 +109,7 @@ const string&
 Array2dFileLabel::getDateString (void) const
 {
   ostringstream oss;
-  oss <<  m_month + 1 <<"/"<< m_day <<"/"<< m_year + 1900 << " " << 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;
 }
@@ -170,7 +172,7 @@ Array2dFile::~Array2dFile (void)
 {
     freeArray ();
     for (labelIterator l = m_labels.begin(); l != m_labels.end(); l++)
-       delete *l;
+      delete *l;
 }
 
 Array2dFile::Array2dFile (void)
@@ -199,12 +201,9 @@ Array2dFile::init (void)
 void
 Array2dFile::setArraySize (int x, int y, int pixelSize, int pixelFormat)
 {
-    m_nx = x;
-    m_ny = y;
     m_pixelSize = pixelSize;
-    m_arraySize = m_nx * m_ny * m_pixelSize;
     m_pixelFormat = pixelFormat;
-    allocArray ();
+    setArraySize (x, y);
 }
 
 void
@@ -225,7 +224,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];
 }
 
@@ -233,13 +232,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)
 {
@@ -262,6 +267,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)
 {
@@ -403,11 +414,11 @@ Array2dFile::arrayDataWrite (frnetorderstream& fs)
       if (NativeBigEndian()) {
          for (unsigned int iy = 0; iy < m_ny; iy++) {
              ConvertReverseNetworkOrder (ptrColumn, m_pixelSize);
-             fs.write (ptrColumn, m_pixelSize);
+             fs.write (reinterpret_cast<const char*>(ptrColumn), m_pixelSize);
              ptrColumn += m_pixelSize;
          }
       } else 
-         fs.write (ptrColumn, columnSize);
+         fs.write (reinterpret_cast<const char*>(ptrColumn), columnSize);
   }
 
   return true;
@@ -427,16 +438,16 @@ 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++) {
-             fs.read (ptrColumn, m_pixelSize);
+             fs.read (reinterpret_cast<char*>(ptrColumn), m_pixelSize);
              ConvertReverseNetworkOrder (ptrColumn, m_pixelSize);
              ptrColumn += m_pixelSize;
          } 
       } else
-         fs.read (ptrColumn, columnSize);
+         fs.read (reinterpret_cast<char*>(ptrColumn), columnSize);
   }
 
   return true;
@@ -512,14 +523,14 @@ Array2dFile::labelsWrite (frnetorderstream& fs)
 }
 
 void
-Array2dFile::labelAdd (const char* const lstr, double calc_time=0.)
+Array2dFile::labelAdd (const char* const lstr, double calc_time)
 {
   labelAdd (Array2dFileLabel::L_HISTORY, lstr, calc_time);
 }
 
 
 void
-Array2dFile::labelAdd (int type, const char* const lstr, double calc_time=0.)
+Array2dFile::labelAdd (int type, const char* const lstr, double calc_time)
 {
   Array2dFileLabel label (type, lstr, calc_time);
 
@@ -539,7 +550,7 @@ void
 Array2dFile::labelsCopy (Array2dFile& copyFile, const char* const idStr)
 {
     string id = idStr;
-    for (int i = 0; i < copyFile.getNumLabels(); i++) {
+    for (unsigned int i = 0; i < copyFile.getNumLabels(); i++) {
       Array2dFileLabel l (copyFile.labelGet (i));
       string lstr = l.getLabelString();
       lstr = idStr + lstr;
@@ -553,7 +564,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);
     }
 }
@@ -561,8 +572,6 @@ 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;