r348: fix linefeed problem
[ctsim.git] / libctsim / projections.cpp
index 49aaa9942b078ea417817adb45789a0de5df26bc..f6fff539bb7c4f6a7d7e5b8362b71cb5f09964bc 100644 (file)
@@ -8,7 +8,7 @@
 **  This is part of the CTSim program
 **  Copyright (C) 1983-2000 Kevin Rosenberg
 **
-**  $Id: projections.cpp,v 1.29 2000/12/16 02:31:00 kevin Exp $
+**  $Id: projections.cpp,v 1.35 2001/01/02 16:02:13 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
@@ -25,8 +25,8 @@
 ******************************************************************************/
 
 #include "ct.h"
-\r
-const kuint16 Projections::m_signature = ('P'*256 + 'J');\r
+
+const kuint16 Projections::m_signature = ('P'*256 + 'J');
 
 /* NAME
  *    Projections              Constructor for projections matrix storage 
@@ -71,6 +71,15 @@ Projections::init (const int nView, const int nDet)
   m_nView = nView;
   m_nDet = nDet;
   newProjData ();
+
+  time_t t = time (NULL);
+  tm* lt = localtime (&t);
+  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;
+  m_second = lt->tm_sec;
 }
 
 void
@@ -91,7 +100,7 @@ Projections::initFromScanner (const Scanner& scanner)
 #if 0
   if (m_geometry == Scanner::GEOMETRY_EQUILINEAR) {
     m_detInc /= 2;
-    cout << "Kludge: detInc /= 2 in Projections::initFromScanner" << endl;
+       std::cout << "Kludge: detInc /= 2 in Projections::initFromScanner" << endl;
   }
 #endif
 }
@@ -262,7 +271,7 @@ Projections::headerRead (fnetorderstream& fs)
   }
   pszRemarkStorage[_remarksize] = 0;
   m_remark = pszRemarkStorage;
-  delete pszRemarkStorage;\r
+  delete pszRemarkStorage;
 
   off_t _hsizeread = fs.tellg();
   if (!fs || _hsizeread != _hsize) {
@@ -298,7 +307,7 @@ Projections::headerRead (fnetorderstream& fs)
 }
 
 bool
-Projections::read (const string& filename)
+Projections::read (const std::string& filename)
 {
   return read (filename.c_str());
 }
@@ -307,10 +316,14 @@ Projections::read (const string& filename)
 bool
 Projections::read (const char* filename)
 {
-  frnetorderstream fileRead (filename, ios::in | ios::binary);
   m_filename = filename;
+#ifdef MSVC
+  frnetorderstream fileRead (m_filename.c_str(), std::ios::in | std::ios::binary);
+#else
+  frnetorderstream fileRead (m_filename.c_str(), std::ios::in | std::ios::binary | std::ios::nocreate);
+#endif
 
-  if (! fileRead)
+  if (fileRead.fail())
     return false;
 
   if (! headerRead (fileRead))
@@ -330,13 +343,13 @@ Projections::read (const char* filename)
 
 
 bool 
-Projections::copyViewData (const string& filename, ostream& os, int startView, int endView)
+Projections::copyViewData (const std::string& filename, std::ostream& os, int startView, int endView)
 {
     return copyViewData (filename.c_str(), os, startView, endView);
 }
 
 bool 
-Projections::copyViewData (const char* const filename, ostream& os, int startView, int endView)
+Projections::copyViewData (const char* const filename, std::ostream& os, int startView, int endView)
 {
   frnetorderstream is (filename, ios::in | ios::binary);
   kuint16 sizeHeader, signature;
@@ -372,8 +385,8 @@ Projections::copyViewData (const char* const filename, ostream& os, int startVie
 
   for (int i = startView; i <= endView; i++) {
       is.seekg (sizeHeader + i * sizeView);
-      is.read (pViewData, sizeView);
-      os.write (pViewData, sizeView);
+      is.read (reinterpret_cast<char*>(pViewData), sizeView);
+      os.write (reinterpret_cast<char*>(pViewData), sizeView);
       if (is.fail() || os.fail())
          break;
   }
@@ -388,15 +401,15 @@ Projections::copyViewData (const char* const filename, ostream& os, int startVie
 }
 
 bool 
-Projections::copyHeader (const string& filename, ostream& os)
+Projections::copyHeader (const std::string& filename, std::ostream& os)
 {
     return copyHeader (filename.c_str(), os);
 }
 
 bool
-Projections::copyHeader (const char* const filename, ostream& os)
+Projections::copyHeader (const char* const filename, std::ostream& os)
 {
-  frnetorderstream is (filename, ios::in | ios::binary);
+  frnetorderstream is (filename, std::ios::in | std::ios::binary);
   kuint16 sizeHeader, signature;
   is.readInt16 (sizeHeader);
   is.readInt16 (signature);
@@ -407,13 +420,13 @@ Projections::copyHeader (const char* const filename, ostream& os)
   }
 
   unsigned char* pHdrData = new unsigned char [sizeHeader];
-  is.read (pHdrData, sizeHeader);
+  is.read (reinterpret_cast<char*>(pHdrData), sizeHeader);
   if (is.fail()) {
       sys_error (ERR_FATAL, "Error reading header");
       return false;
   }
 
-  os.write (pHdrData, sizeHeader);
+  os.write (reinterpret_cast<char*>(pHdrData), sizeHeader);
   if (os.fail()) {
       sys_error (ERR_FATAL, "Error writing header");
       return false;
@@ -423,7 +436,7 @@ Projections::copyHeader (const char* const filename, ostream& os)
 }
 
 bool
-Projections::write (const string& filename)
+Projections::write (const std::string& filename)
 {
   return write (filename.c_str());
 }
@@ -431,24 +444,13 @@ Projections::write (const string& filename)
 bool
 Projections::write (const char* filename)
 {
-  frnetorderstream fs (filename, ios::out | ios::binary | ios::trunc | ios::ate);
+  frnetorderstream fs (filename, std::ios::out | std::ios::binary | std::ios::trunc | std::ios::ate);
   m_filename = filename;
   if (! fs) {
     sys_error (ERR_SEVERE, "Error opening file %s for output [projections_create]", filename);
     return false;
   }
 
-#ifdef HAVE_TIME
-  time_t t = time(NULL);
-  tm* lt = localtime(&t);
-  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;
-  m_second = lt->tm_sec;
-#endif
-
   if (! headerWrite (fs))
       return false;
 
@@ -591,7 +593,7 @@ Projections::printProjectionData (int startView, int endView)
 }
 
 void 
-Projections::printScanInfo (ostringstream& os) const
+Projections::printScanInfo (std::ostringstream& os) const
 {
   os << "Number of detectors: " << m_nDet << "\n";
   os << "    Number of views: " << m_nView<< "\n";