X-Git-Url: http://git.kpe.io/?p=ctsim.git;a=blobdiff_plain;f=libctsim%2Farray2dfile.cpp;h=e35a14982056cbb5f414b8fb73402ebe58a1c4a8;hp=0ed6354454b0a2386cbd9142fd9e64a6834c3968;hb=55426f4170ed9dc777c3cec3741e4a59e6eebd38;hpb=6850134e4711a842cc7c0a306a9e4243df06b952 diff --git a/libctsim/array2dfile.cpp b/libctsim/array2dfile.cpp index 0ed6354..e35a149 100644 --- a/libctsim/array2dfile.cpp +++ b/libctsim/array2dfile.cpp @@ -9,7 +9,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: array2dfile.cpp,v 1.5 2000/07/09 08:16:17 kevin Exp $ +** $Id: array2dfile.cpp,v 1.16 2000/12/06 15:17:51 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 @@ -26,11 +26,14 @@ ******************************************************************************/ #include "array2dfile.h" -#include -#include +#include +#ifdef MSVC +typedef long off_t; +#endif using namespace std; +const kuint16 Array2dFile::m_signature = ('I'*256+'F'); /////////////////////////////////////////////////////////////////////////// // CLASS IMPLEMENTATION @@ -59,7 +62,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 +71,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(); @@ -106,9 +109,10 @@ Array2dFileLabel::getDateTime (int& year, int& month, int& day, int& hour, int& const string& Array2dFileLabel::getDateString (void) const { - ostringstream oss; - oss << m_month + 1 <<"/"<< m_day <<"/"<< m_year + 1900 << " " << m_hour <<":"<< m_minute <<":"<< m_second; - m_strDate = oss.str(); + 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_strDate = szDate; return m_strDate; } @@ -170,7 +174,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 +203,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 +226,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,7 +234,7 @@ 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; @@ -279,7 +280,11 @@ Array2dFile::fileRead (const char* const filename) { m_filename = filename; - frnetorderstream fs (m_filename.c_str(), ios::out | ios::in | ios::binary | ios::nocreate); +#ifdef MSVC + frnetorderstream fs (m_filename.c_str(), ios::out | ios::in | ios::binary); +#else + frnetorderstream fs (m_filename.c_str(), ios::out | ios::in | ios::binary | ios::nocreate); +#endif if (fs.fail()) { sys_error (ERR_WARNING, "Unable to open file %s [fileRead]", m_filename.c_str()); return false; @@ -389,7 +394,7 @@ Array2dFile::headerWrite (frnetorderstream& fs) fs.writeFloat64 (m_offsetPV); fs.writeFloat64 (m_scalePV); - m_headersize = fs.tellp(); + m_headersize = static_cast(fs.tellp()); fs.seekp (0); fs.writeInt16 (m_headersize); @@ -415,11 +420,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(ptrColumn), m_pixelSize); ptrColumn += m_pixelSize; } } else - fs.write (ptrColumn, columnSize); + fs.write (reinterpret_cast(ptrColumn), columnSize); } return true; @@ -439,16 +444,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(ptrColumn), m_pixelSize); ConvertReverseNetworkOrder (ptrColumn, m_pixelSize); ptrColumn += m_pixelSize; } } else - fs.read (ptrColumn, columnSize); + fs.read (reinterpret_cast(ptrColumn), columnSize); } return true; @@ -477,13 +482,15 @@ Array2dFile::labelsRead (frnetorderstream& fs) kuint16 strLength; fs.readInt16 (strLength); - char labelStr [strLength+1]; - fs.read (labelStr, strLength); - labelStr[strLength] = 0; + char* pszLabelStr = new char [strLength+1]; + fs.read (pszLabelStr, strLength); + pszLabelStr[strLength] = 0; - Array2dFileLabel* pLabel = new Array2dFileLabel(labelType, labelStr, calcTime); + Array2dFileLabel* pLabel = new Array2dFileLabel (labelType, pszLabelStr, calcTime); + delete pszLabelStr; + pLabel->setDateTime (year, month, day, hour, minute, second); - m_labels.push_back (pLabel); + m_labels.push_back (pLabel); } return true; @@ -524,14 +531,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); @@ -551,7 +558,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; @@ -565,7 +572,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); } } @@ -573,8 +580,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;