From afcfebb543dc21f77a61bee68796c8cc27c44ac8 Mon Sep 17 00:00:00 2001
From: Matthias <github@mpuchner.de>
Date: Fri, 4 Dec 2020 15:55:58 +0100
Subject: [PATCH] applied requested changes

rm obsolete code; correct declare->define; rm 1-liner-braces; rm unnecessary else statements; precision hardcoded; static methods
---
 .../InputOutput/OutputDataReadReflectometry.h  |  2 +-
 Device/InputOutput/OutputDataReadWriteINT.cpp  | 13 +++----------
 Device/InputOutput/OutputDataReadWriteINT.h    | 10 ++++------
 .../OutputDataReadWriteNumpyTXT.cpp            | 18 +++++++++---------
 .../InputOutput/OutputDataReadWriteNumpyTXT.h  | 10 ++++------
 Device/InputOutput/OutputDataReadWriteTiff.cpp |  4 ++--
 Device/InputOutput/OutputDataReadWriteTiff.h   |  2 +-
 7 files changed, 24 insertions(+), 35 deletions(-)

diff --git a/Device/InputOutput/OutputDataReadReflectometry.h b/Device/InputOutput/OutputDataReadReflectometry.h
index 0405b7fdc7c..ff50874fb22 100644
--- a/Device/InputOutput/OutputDataReadReflectometry.h
+++ b/Device/InputOutput/OutputDataReadReflectometry.h
@@ -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)
diff --git a/Device/InputOutput/OutputDataReadWriteINT.cpp b/Device/InputOutput/OutputDataReadWriteINT.cpp
index 09ddb0bd8fd..1879cd56c20 100644
--- a/Device/InputOutput/OutputDataReadWriteINT.cpp
+++ b/Device/InputOutput/OutputDataReadWriteINT.cpp
@@ -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;
 }
diff --git a/Device/InputOutput/OutputDataReadWriteINT.h b/Device/InputOutput/OutputDataReadWriteINT.h
index 5d5aabeec5f..4c256096e86 100644
--- a/Device/InputOutput/OutputDataReadWriteINT.h
+++ b/Device/InputOutput/OutputDataReadWriteINT.h
@@ -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
diff --git a/Device/InputOutput/OutputDataReadWriteNumpyTXT.cpp b/Device/InputOutput/OutputDataReadWriteNumpyTXT.cpp
index fbb2734ee10..0e500d9d356 100644
--- a/Device/InputOutput/OutputDataReadWriteNumpyTXT.cpp
+++ b/Device/InputOutput/OutputDataReadWriteNumpyTXT.cpp
@@ -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;
 }
diff --git a/Device/InputOutput/OutputDataReadWriteNumpyTXT.h b/Device/InputOutput/OutputDataReadWriteNumpyTXT.h
index 9fc605c1537..121eb5e0185 100644
--- a/Device/InputOutput/OutputDataReadWriteNumpyTXT.h
+++ b/Device/InputOutput/OutputDataReadWriteNumpyTXT.h
@@ -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
diff --git a/Device/InputOutput/OutputDataReadWriteTiff.cpp b/Device/InputOutput/OutputDataReadWriteTiff.cpp
index 0da9acb6f62..041738ddd5b 100644
--- a/Device/InputOutput/OutputDataReadWriteTiff.cpp
+++ b/Device/InputOutput/OutputDataReadWriteTiff.cpp
@@ -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();
diff --git a/Device/InputOutput/OutputDataReadWriteTiff.h b/Device/InputOutput/OutputDataReadWriteTiff.h
index 034d9991ada..3e4e1cb7c87 100644
--- a/Device/InputOutput/OutputDataReadWriteTiff.h
+++ b/Device/InputOutput/OutputDataReadWriteTiff.h
@@ -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)
-- 
GitLab