From ef8658b099b963118271bfd0c26689f8250fdf25 Mon Sep 17 00:00:00 2001 From: Donald Johnson Date: Wed, 27 Mar 2024 22:38:59 +0000 Subject: [PATCH] Bug fixes from debuggin unit tests. --- include/output/NetcdfOutputWriter.hpp | 20 +++++++++++++------- test/netcdf/Netcdf_Output_Test.cpp | 3 ++- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/include/output/NetcdfOutputWriter.hpp b/include/output/NetcdfOutputWriter.hpp index ffac556e30..cd03d76335 100644 --- a/include/output/NetcdfOutputWriter.hpp +++ b/include/output/NetcdfOutputWriter.hpp @@ -224,7 +224,12 @@ namespace data_output /** \brief Bind a writer object and variable name to create the helper object. */ - NetcdfOutputWriterHelper(NetcdfOutputWriter& w, const std::string s) : writer(w), var(s) + NetcdfOutputWriterHelper(NetcdfOutputWriter& w, const std::string s) : writer(&w), var(s) + { + + } + + NetcdfOutputWriterHelper(const NetcdfOutputWriterHelper& src) : writer(src.writer), var(src.var) { } @@ -252,7 +257,7 @@ namespace data_output template NetcdfOutputWriterHelper& operator<<(const T* d) { - writer.netcdfVars[var].putVar(offset, stride, d); + writer->netcdfVars[var].putVar(offset, stride, d); return *this; } @@ -262,15 +267,15 @@ namespace data_output template NetcdfOutputWriterHelper& operator<<(std::vector& d) { - writer.netcdfVars[var].putVar(offset, stride, &d[0]); + writer->netcdfVars[var].putVar(offset, stride, &d[0]); return *this; } private: - NetcdfOutputWriter& writer; //!< the writer object - const std::string& var; //!< the variable where data will be written + NetcdfOutputWriter* writer; //!< the writer object + const std::string var; //!< the variable where data will be written std::vector offset; //!< the current offset to be used durring writing std::vector stride; //!< the current stride for the next data write }; @@ -280,9 +285,10 @@ namespace data_output /** \brief construct a helper object to access the requested variable */ - NetcdfOutputWriterHelper operator[](const std::string var) + NetcdfOutputWriterHelper operator[](const std::string& var) { - return NetcdfOutputWriterHelper(*this,var); + NetcdfOutputWriterHelper helper(*this,var); + return helper; } protected: diff --git a/test/netcdf/Netcdf_Output_Test.cpp b/test/netcdf/Netcdf_Output_Test.cpp index b024d9ee71..da3b75064f 100644 --- a/test/netcdf/Netcdf_Output_Test.cpp +++ b/test/netcdf/Netcdf_Output_Test.cpp @@ -119,7 +119,8 @@ TEST_F(NetcdfOuputTest, TestNetcdfWrite) { data_vec[i] = i * 0.1f; } - output_file["output2"] << nc_offset(0,0) << nc_stride(1,1000) << data_vec; + auto s = output_file["output2"]; + s << nc_offset(0,0) << nc_stride(1,1000) << data_vec; SUCCEED(); }