Skip to content
Snippets Groups Projects
Commit afcfebb5 authored by Matthias's avatar Matthias
Browse files

applied requested changes

rm obsolete code; correct declare->define; rm 1-liner-braces; rm unnecessary else statements; precision hardcoded; static methods
parent d50cde11
No related branches found
No related tags found
No related merge requests found
......@@ -3,7 +3,7 @@
// BornAgain: simulate and fit scattering at grazing incidence
//
//! @file Device/InputOutput/OutputDataReadReflectometry.h
//! @brief Declares OutputDataReadReflectometry
//! @brief Defines OutputDataReadReflectometry
//!
//! @homepage http://www.bornagainproject.org
//! @license GNU General Public License v3 or higher (see COPYING)
......
......@@ -17,12 +17,6 @@
#include "Device/InputOutput/DataFormatUtils.h"
#include "Device/Intensity/ArrayUtils.h"
namespace {
inline bool isDoubleStartChar(char c) {
return isdigit(c) || c == '-' || c == '+';
}
} // namespace
OutputData<double>* OutputDataReadWriteINT::readOutputData(std::istream& input_stream) {
OutputData<double>* result = new OutputData<double>;
std::string line;
......@@ -34,9 +28,8 @@ OutputData<double>* OutputDataReadWriteINT::readOutputData(std::istream& input_s
result->addAxis(*axis);
}
if (line.find("data") != std::string::npos) {
if (line.find("data") != std::string::npos)
DataFormatUtils::fillOutputData(result, input_stream);
}
}
return result;
}
......@@ -65,7 +58,7 @@ void OutputDataReadWriteINT::writeOutputDataDoubles(const OutputData<double>& da
OutputData<double>::const_iterator it = data.begin();
output_stream.imbue(std::locale::classic());
output_stream << std::scientific << std::setprecision(m_precision);
output_stream << std::scientific << std::setprecision(12);
size_t ncol(0);
while (it != data.end()) {
ncol++;
......@@ -78,6 +71,6 @@ void OutputDataReadWriteINT::writeOutputDataDoubles(const OutputData<double>& da
}
}
double OutputDataReadWriteINT::ignoreDenormalized(double value) const {
double OutputDataReadWriteINT::ignoreDenormalized(double value) {
return (std::fpclassify(value) == FP_SUBNORMAL) ? 0.0 : value;
}
......@@ -3,7 +3,7 @@
// BornAgain: simulate and fit scattering at grazing incidence
//
//! @file Device/InputOutput/OutputDataReadWriteINT.h
//! @brief Declares OutputDataReadWriteINT
//! @brief Defines OutputDataReadWriteINT
//!
//! @homepage http://www.bornagainproject.org
//! @license GNU General Public License v3 or higher (see COPYING)
......@@ -28,11 +28,9 @@ public:
void writeOutputData(const OutputData<double>& data, std::ostream& output_stream);
private:
void writeOutputDataDoubles(const OutputData<double>& data, std::ostream& output_stream,
size_t n_columns);
double ignoreDenormalized(double value) const;
const int m_precision = 12;
static void writeOutputDataDoubles(const OutputData<double>& data, std::ostream& output_stream,
size_t n_columns);
static double ignoreDenormalized(double value);
};
#endif // BORNAGAIN_DEVICE_INPUTOUTPUT_OUTPUTDATAREADWRITEINT_H
......@@ -59,18 +59,18 @@ OutputData<double>* OutputDataReadWriteNumpyTXT::readOutputData(std::istream& in
"Number of elements is different from row to row.");
}
if (nrows < 2) {
if (nrows < 2)
return ArrayUtils::createData(std::move(data[0])).release();
} else if (ncols < 2) {
if (ncols < 2) {
const size_t size = data.size();
std::vector<double> vector1d(size);
for (size_t i = 0; i < size; ++i) {
for (size_t i = 0; i < size; ++i)
vector1d[i] = data[i][0];
}
return ArrayUtils::createData(std::move(vector1d)).release();
} else {
return ArrayUtils::createData(data).release();
}
return ArrayUtils::createData(data).release();
}
void OutputDataReadWriteNumpyTXT::writeOutputData(const OutputData<double>& data,
......@@ -96,7 +96,7 @@ void OutputDataReadWriteNumpyTXT::write1DRepresentation(const OutputData<double>
std::ostream& output_stream) {
output_stream << "# coordinates intensities" << std::endl;
output_stream.imbue(std::locale::classic());
output_stream << std::scientific << std::setprecision(m_precision);
output_stream << std::scientific << std::setprecision(12);
const std::vector<double> axis_values = data.axis(0).binCenters();
......@@ -114,7 +114,7 @@ void OutputDataReadWriteNumpyTXT::write2DRepresentation(const OutputData<double>
std::vector<std::vector<double>> dataArray = ArrayUtils::createVector2D(data);
output_stream.imbue(std::locale::classic());
output_stream << std::scientific << std::setprecision(m_precision);
output_stream << std::scientific << std::setprecision(12);
for (size_t i = 0; i < nrows; i++) {
for (size_t j = 0; j < ncols; j++) {
......@@ -125,6 +125,6 @@ void OutputDataReadWriteNumpyTXT::write2DRepresentation(const OutputData<double>
}
}
double OutputDataReadWriteNumpyTXT::ignoreDenormalized(double value) const {
double OutputDataReadWriteNumpyTXT::ignoreDenormalized(double value) {
return (std::fpclassify(value) == FP_SUBNORMAL) ? 0.0 : value;
}
......@@ -3,7 +3,7 @@
// BornAgain: simulate and fit scattering at grazing incidence
//
//! @file Device/InputOutput/OutputDataReadWriteNumpyTXT.h
//! @brief Declares OutputDataReadWriteNumpyTXT
//! @brief Defines OutputDataReadWriteNumpyTXT
//!
//! @homepage http://www.bornagainproject.org
//! @license GNU General Public License v3 or higher (see COPYING)
......@@ -29,11 +29,9 @@ public:
void writeOutputData(const OutputData<double>& data, std::ostream& output_stream);
private:
void write1DRepresentation(const OutputData<double>& data, std::ostream& output_stream);
void write2DRepresentation(const OutputData<double>& data, std::ostream& output_stream);
double ignoreDenormalized(double value) const;
const int m_precision = 12;
static void write1DRepresentation(const OutputData<double>& data, std::ostream& output_stream);
static void write2DRepresentation(const OutputData<double>& data, std::ostream& output_stream);
static double ignoreDenormalized(double value);
};
#endif // BORNAGAIN_DEVICE_INPUTOUTPUT_OUTPUTDATAREADWRITENUMPYTXT_H
......@@ -32,9 +32,9 @@ OutputDataReadWriteTiff::~OutputDataReadWriteTiff() {
void OutputDataReadWriteTiff::read(std::istream& input_stream) {
m_tiff = TIFFStreamOpen("MemTIFF", &input_stream);
if (!m_tiff) {
if (!m_tiff)
throw std::runtime_error("OutputDataReadWriteTiff::read() -> Can't open the file.");
}
read_header();
read_data();
close();
......
......@@ -3,7 +3,7 @@
// BornAgain: simulate and fit scattering at grazing incidence
//
//! @file Device/InputOutput/OutputDataReadWriteTiff.h
//! @brief Declares class OutputDataReadWriteTiff
//! @brief Defines class OutputDataReadWriteTiff
//!
//! @homepage http://www.bornagainproject.org
//! @license GNU General Public License v3 or higher (see COPYING)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment