projects
/
ctsim.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
r269: Improved sort statistics
[ctsim.git]
/
libctsim
/
array2dfile.cpp
diff --git
a/libctsim/array2dfile.cpp
b/libctsim/array2dfile.cpp
index 19234bfb48c42ac0a9e29e9697356f1cb02f3800..6c400ad77f35ebae4c1a5ab5f1dddc368433c743 100644
(file)
--- 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
**
** This is part of the CTSim program
** Copyright (C) 1983-2000 Kevin Rosenberg
**
-** $Id: array2dfile.cpp,v 1.
9 2000/12/04 03:09:00
kevin Exp $
+** $Id: array2dfile.cpp,v 1.
21 2000/12/16 06:12:47
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
**
** 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,12
+26,13
@@
******************************************************************************/
#include "array2dfile.h"
******************************************************************************/
#include "array2dfile.h"
-#include <ctime>
-#include <sstream>
+#include <ctime>
\r
+#ifdef MSVC
\r
+typedef long off_t;
\r
+#endif
-using namespace std;
-Array2dFile::m_signature = ('I'*256+'F');
+
const kuint16
Array2dFile::m_signature = ('I'*256+'F');
///////////////////////////////////////////////////////////////////////////
// CLASS IMPLEMENTATION
///////////////////////////////////////////////////////////////////////////
// CLASS IMPLEMENTATION
@@
-60,7
+61,7
@@
Array2dFileLabel::Array2dFileLabel()
init();
}
init();
}
-Array2dFileLabel::Array2dFileLabel(const char* const str, double ctime
= 0.
)
+Array2dFileLabel::Array2dFileLabel(const char* const str, double ctime)
: m_strLabel (str)
{
init();
: m_strLabel (str)
{
init();
@@
-69,7
+70,7
@@
Array2dFileLabel::Array2dFileLabel(const char* const str, double ctime = 0.)
m_calcTime = ctime;
}
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();
: m_strLabel (str)
{
init();
@@
-104,12
+105,13
@@
Array2dFileLabel::getDateTime (int& year, int& month, int& day, int& hour, int&
second = m_second;
}
second = m_second;
}
-const string&
+const st
d::st
ring&
Array2dFileLabel::getDateString (void) const
{
Array2dFileLabel::getDateString (void) const
{
- ostringstream oss;
- 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();
+ char szDate [128];
\r
+ snprintf (szDate, sizeof(szDate), "%2d/%02d/%4d %02d:%02d:%02d",
\r
+ m_month + 1, m_day, m_year + 1900, m_hour, m_minute, m_second);
+ m_strDate = szDate;
return m_strDate;
}
return m_strDate;
}
@@
-136,19
+138,19
@@
Array2dFileLabel::operator= (const Array2dFileLabel& rhs)
}
void
}
void
-Array2dFileLabel::print (ostream& os) const
+Array2dFileLabel::print (
std::
ostream& os) const
{
if (m_labelType == L_HISTORY) {
{
if (m_labelType == L_HISTORY) {
-
os << "History: " <<
endl;
- os << " " << m_strLabel << endl;
- os << " calc time = " << m_calcTime << " secs" << endl;
- os << " Timestamp = " << getDateString() << endl;
+
os << "History: " << std::
endl;
+ os << " " << m_strLabel <<
std::
endl;
+ os << " calc time = " << m_calcTime << " secs" <<
std::
endl;
+ os << " Timestamp = " << getDateString() <<
std::
endl;
} else if (m_labelType == L_USER) {
} else if (m_labelType == L_USER) {
- os << "Note: " << m_strLabel << endl;
- os << " Timestamp = %s" << getDateString() << endl;
+ os << "Note: " << m_strLabel <<
std::
endl;
+ os << " Timestamp = %s" << getDateString() <<
std::
endl;
} else {
} else {
- os << "Unknown (" << m_labelType << "): " << m_strLabel << endl;
- os << " Timestamp = %s" << getDateString() << endl;
+ os << "Unknown (" << m_labelType << "): " << m_strLabel <<
std::
endl;
+ os << " Timestamp = %s" << getDateString() <<
std::
endl;
}
}
}
}
@@
-239,7
+241,7
@@
Array2dFile::freeArray (void)
}
bool
}
bool
-Array2dFile::fileWrite (const string& filename)
+Array2dFile::fileWrite (const st
d::st
ring& filename)
{
return fileWrite (filename.c_str());
}
{
return fileWrite (filename.c_str());
}
@@
-249,7
+251,7
@@
Array2dFile::fileWrite (const char* const filename)
{
m_filename = filename;
{
m_filename = filename;
- frnetorderstream fs (m_filename.c_str(),
ios::out | ios::in | ios::trunc |
ios::binary);
+ frnetorderstream fs (m_filename.c_str(),
std::ios::out | std::ios::in | std::ios::trunc | std::
ios::binary);
if (fs.fail()) {
sys_error (ERR_WARNING, "Error opening file %s for writing [fileCreate]", m_filename.c_str());
return false;
if (fs.fail()) {
sys_error (ERR_WARNING, "Error opening file %s for writing [fileCreate]", m_filename.c_str());
return false;
@@
-267,7
+269,7
@@
Array2dFile::fileWrite (const char* const filename)
}
bool
}
bool
-Array2dFile::fileRead (const string& filename)
+Array2dFile::fileRead (const st
d::st
ring& filename)
{
return fileRead (filename.c_str());
}
{
return fileRead (filename.c_str());
}
@@
-277,7
+279,11
@@
Array2dFile::fileRead (const char* const filename)
{
m_filename = filename;
{
m_filename = filename;
- frnetorderstream fs (m_filename.c_str(), ios::out | ios::in | ios::binary | ios::nocreate);
+#ifdef MSVC
\r
+ frnetorderstream fs (m_filename.c_str(), std::ios::out | std::ios::in | std::ios::binary);
\r
+#else
\r
+ frnetorderstream fs (m_filename.c_str(), std::ios::out | std::ios::in | std::ios::binary | std::ios::nocreate);
\r
+#endif
\r
if (fs.fail()) {
sys_error (ERR_WARNING, "Unable to open file %s [fileRead]", m_filename.c_str());
return false;
if (fs.fail()) {
sys_error (ERR_WARNING, "Unable to open file %s [fileRead]", m_filename.c_str());
return false;
@@
-387,7
+393,7
@@
Array2dFile::headerWrite (frnetorderstream& fs)
fs.writeFloat64 (m_offsetPV);
fs.writeFloat64 (m_scalePV);
fs.writeFloat64 (m_offsetPV);
fs.writeFloat64 (m_scalePV);
- m_headersize =
fs.tellp(
);
+ m_headersize =
static_cast<kuint16>(fs.tellp()
);
fs.seekp (0);
fs.writeInt16 (m_headersize);
fs.seekp (0);
fs.writeInt16 (m_headersize);
@@
-413,11
+419,11
@@
Array2dFile::arrayDataWrite (frnetorderstream& fs)
if (NativeBigEndian()) {
for (unsigned int iy = 0; iy < m_ny; iy++) {
ConvertReverseNetworkOrder (ptrColumn, m_pixelSize);
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
ptrColumn += m_pixelSize;
}
} else
- fs.write (
ptrColumn
, columnSize);
+ fs.write (
reinterpret_cast<const char*>(ptrColumn)
, columnSize);
}
return true;
}
return true;
@@
-441,12
+447,12
@@
Array2dFile::arrayDataRead (frnetorderstream& fs)
unsigned char* ptrColumn = m_arrayData[ix];
if (NativeBigEndian()) {
for (unsigned int iy = 0; iy < m_ny; iy++) {
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
ConvertReverseNetworkOrder (ptrColumn, m_pixelSize);
ptrColumn += m_pixelSize;
}
} else
- fs.read (
ptrColumn
, columnSize);
+ fs.read (
reinterpret_cast<char*>(ptrColumn)
, columnSize);
}
return true;
}
return true;
@@
-475,13
+481,15
@@
Array2dFile::labelsRead (frnetorderstream& fs)
kuint16 strLength;
fs.readInt16 (strLength);
kuint16 strLength;
fs.readInt16 (strLength);
- char
labelSt
r [strLength+1];
- fs.read (
l
abelStr, strLength);
-
l
abelStr[strLength] = 0;
+ char
* pszLabelStr = new cha
r [strLength+1];
+ fs.read (
pszL
abelStr, strLength);
+
pszL
abelStr[strLength] = 0;
- Array2dFileLabel* pLabel = new Array2dFileLabel(labelType, labelStr, calcTime);
+ Array2dFileLabel* pLabel = new Array2dFileLabel (labelType, pszLabelStr, calcTime);
+ delete pszLabelStr;
\r
+
\r
pLabel->setDateTime (year, month, day, hour, minute, second);
pLabel->setDateTime (year, month, day, hour, minute, second);
- m_labels.push_back (pLabel);
+ m_labels.push_back (pLabel);
\r
}
return true;
}
return true;
@@
-522,14
+530,14
@@
Array2dFile::labelsWrite (frnetorderstream& fs)
}
void
}
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
{
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);
{
Array2dFileLabel label (type, lstr, calc_time);
@@
-546,13
+554,15
@@
Array2dFile::labelAdd (const Array2dFileLabel& label)
}
void
}
void
-Array2dFile::labelsCopy (Array2dFile& copyFile, const char* const
idStr
)
+Array2dFile::labelsCopy (Array2dFile& copyFile, const char* const
pszId
)
{
{
- string id = idStr;
+ std::string id;
+ if (pszId)
+ id = pszId;
for (unsigned 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 = id
Str
+ lstr;
+
std::
string lstr = l.getLabelString();
+ lstr = id + lstr;
l.setLabelString (lstr);
labelAdd (l);
}
l.setLabelString (lstr);
labelAdd (l);
}
@@
-569,13
+579,13
@@
Array2dFile::arrayDataClear (void)
}
void
}
void
-Array2dFile::printLabels (ostream& os) const
+Array2dFile::printLabels (
std::
ostream& os) const
{
for (constLabelIterator l = m_labels.begin(); l != m_labels.end(); l++) {
const Array2dFileLabel& label = **l;
label.print (os);
{
for (constLabelIterator l = m_labels.begin(); l != m_labels.end(); l++) {
const Array2dFileLabel& label = **l;
label.print (os);
- os << endl;
+ os <<
std::
endl;
}
}
}
}