X-Git-Url: http://git.kpe.io/?p=ctsim.git;a=blobdiff_plain;f=libctsim%2Farray2dfile.cpp;h=b3dc43263beaf1a54e01455126a907a31a614960;hp=f918471f54e7278a5789f5095efddaae9f091231;hb=6afa21de8aa00b405de47584efe108c71df33e1b;hpb=baba40afccf75bd75d612980fee023ff22c40952 diff --git a/libctsim/array2dfile.cpp b/libctsim/array2dfile.cpp index f918471..b3dc432 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.13 2000/12/04 04:15:48 kevin Exp $ +** $Id: array2dfile.cpp,v 1.20 2000/12/16 02:44:26 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,9 +26,10 @@ ******************************************************************************/ #include "array2dfile.h" -#include -#include - +#include +#ifdef MSVC +typedef long off_t; +#endif using namespace std; @@ -108,9 +109,10 @@ Array2dFileLabel::getDateTime (int& year, int& month, int& day, int& hour, int& const string& Array2dFileLabel::getDateString (void) const { - ostringstream oss; - oss << static_cast(m_month + 1) <<"/"<< static_cast(m_day) <<"/"<< static_cast(m_year + 1900) << " " << static_cast(m_hour) <<":"<< static_cast(m_minute) <<":"<< static_cast(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; } @@ -137,7 +139,7 @@ Array2dFileLabel::operator= (const Array2dFileLabel& rhs) } void -Array2dFileLabel::print (ostream& os) const +Array2dFileLabel::print (std::ostream& os) const { if (m_labelType == L_HISTORY) { os << "History: " << endl; @@ -278,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; @@ -388,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); @@ -476,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; @@ -547,13 +555,15 @@ Array2dFile::labelAdd (const Array2dFileLabel& label) } void -Array2dFile::labelsCopy (Array2dFile& copyFile, const char* const idStr) +Array2dFile::labelsCopy (Array2dFile& copyFile, const char* const pszId) { - string id = idStr; + 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; + lstr = id + lstr; l.setLabelString (lstr); labelAdd (l); }