Skip to content

Commit

Permalink
Bug fixes from debuggin unit tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
donaldwj committed Mar 27, 2024
1 parent c690da7 commit ef8658b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
20 changes: 13 additions & 7 deletions include/output/NetcdfOutputWriter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{

}
Expand Down Expand Up @@ -252,7 +257,7 @@ namespace data_output
template <class T> NetcdfOutputWriterHelper& operator<<(const T* d)
{

writer.netcdfVars[var].putVar(offset, stride, d);
writer->netcdfVars[var].putVar(offset, stride, d);

return *this;
}
Expand All @@ -262,15 +267,15 @@ namespace data_output
template <class T> NetcdfOutputWriterHelper& operator<<(std::vector<T>& 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<std::size_t> offset; //!< the current offset to be used durring writing
std::vector<std::size_t> stride; //!< the current stride for the next data write
};
Expand All @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion test/netcdf/Netcdf_Output_Test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down

0 comments on commit ef8658b

Please sign in to comment.