Browse Source

Removed copy constructor from BaseData to prevent unnecessary copying of data

interpolate
Michael Uleysky 1 year ago
parent
commit
c85dc28858
  1. 6
      include/actiondep.h
  2. 8
      include/basedata.h
  3. 11
      sources/AVISOLOCAL.cpp
  4. 11
      sources/BINFILE.cpp
  5. 4
      sources/MODISBINLOCAL.cpp
  6. 46
      src/layereddata.cpp

6
include/actiondep.h

@ -133,11 +133,11 @@ template<class D> ReadType<D> Read(const D& data, const MString& vname, const Ba
else if constexpr(ReadSupported<D>) else if constexpr(ReadSupported<D>)
dat = data.Read(vname, ind); dat = data.Read(vname, ind);
if(dat) if(dat)
out.Add(dat); out.Add(std::move(dat));
else else
ok = false; ok = false;
} }
if(ok) return out.Div(); if(ok) return std::move(out.Div());
} }
return RT(); return RT();
} }
@ -191,7 +191,7 @@ template<class D> UVData<ReadType<D>> ReadUV(const D& data, const BaseParameters
} }
UV dat(u, v); UV dat(u, v);
if(dat) if(dat)
out.Add(dat); out.Add(std::move(dat));
else else
ok = false; ok = false;
} }

8
include/basedata.h

@ -26,6 +26,10 @@ class BaseData
public: public:
BaseData() = default; BaseData() = default;
BaseData(const BaseData&) = delete;
BaseData(BaseData&&) = default;
BaseData& operator=(BaseData&&) = default;
const real& V(size_t i) const { return data[i]; } const real& V(size_t i) const { return data[i]; }
real& V(size_t i) { return data[i]; } real& V(size_t i) { return data[i]; }
@ -86,12 +90,12 @@ template<class Data> class DefaultAverager: public Data
} }
public: public:
void Add(const Data& d) void Add(Data&& d)
{ {
if(!d) return; if(!d) return;
if(!*this) if(!*this)
{ {
*static_cast<Data*>(this) = d; *static_cast<Data*>(this) = std::move(d);
count.resize(Data::N()); count.resize(Data::N());
for(size_t i = 0; i < Data::N(); i++) count[i] = DataOk(this, i) ? 1 : 0; for(size_t i = 0; i < Data::N(); i++) count[i] = DataOk(this, i) ? 1 : 0;
return; return;

11
sources/AVISOLOCAL.cpp

@ -122,16 +122,15 @@ AVISOLOCALData::Data AVISOLOCALData::Read(const MString& vname, const BaseParame
auto u = Read("u", ip, i); auto u = Read("u", ip, i);
auto v = Read("v", ip, i); auto v = Read("v", ip, i);
if(!(u && v)) return Data(); if(!(u && v)) return Data();
auto out = u; if(square && u.Unit().Exist()) u.SetUnit("(" + u.Unit() + ")2");
out.SetUnit(square ? ("(" + u.Unit() + ")2") : u.Unit()); for(size_t ind = 0; ind < u.N(); ind++)
for(size_t ind = 0; ind < out.N(); ind++)
{ {
if(u.IsFill(ind) || v.IsFill(ind)) if(u.IsFill(ind) || v.IsFill(ind))
out.V(ind) = out.Fillval(); u.V(ind) = u.Fillval();
else else
out.V(ind) = square ? (u(ind) * u(ind) + v(ind) * v(ind)) : michlib::Hypot(u(ind), v(ind)); u.V(ind) = square ? (u(ind) * u(ind) + v(ind) * v(ind)) : michlib::Hypot(u(ind), v(ind));
} }
return out; return u;
} }
return Data(); return Data();
} }

11
sources/BINFILE.cpp

@ -69,16 +69,15 @@ BINFILEData::Data BINFILEData::Read(const MString& vname, size_t i) const
auto u = Read("u", i); auto u = Read("u", i);
auto v = Read("v", i); auto v = Read("v", i);
if(!(u && v)) return Data(); if(!(u && v)) return Data();
auto out = u; if(square && u.Unit().Exist()) u.SetUnit("(" + u.Unit() + ")2");
out.SetUnit(square ? ("(" + u.Unit() + ")2") : u.Unit()); for(size_t ind = 0; ind < u.N(); ind++)
for(size_t ind = 0; ind < out.N(); ind++)
{ {
if(u.IsFill(ind) || v.IsFill(ind)) if(u.IsFill(ind) || v.IsFill(ind))
out.V(ind) = out.Fillval(); u.V(ind) = u.Fillval();
else else
out.V(ind) = square ? (u(ind) * u(ind) + v(ind) * v(ind)) : michlib::Hypot(u(ind), v(ind)); u.V(ind) = square ? (u(ind) * u(ind) + v(ind) * v(ind)) : michlib::Hypot(u(ind), v(ind));
} }
return out; return u;
} }
if(vname == "u" || vname == "v") if(vname == "u" || vname == "v")

4
sources/MODISBINLOCAL.cpp

@ -92,9 +92,9 @@ MODISBINLOCALData::Data MODISBINLOCALData::Read(const MString& var, const BasePa
for(const auto& suf: dataset) for(const auto& suf: dataset)
{ {
Data dat = ReadFile(suf, p, tind); Data dat = ReadFile(suf, p, tind);
if(dat) out.Add(dat); if(dat) out.Add(std::move(dat));
} }
return out.Div(); return std::move(out.Div());
} }
MODISBINLOCALData::Data MODISBINLOCALData::ReadFile(const MString& suf, const struct MODISBINLOCALData::Parameters* p, size_t tind) const MODISBINLOCALData::Data MODISBINLOCALData::ReadFile(const MString& suf, const struct MODISBINLOCALData::Parameters* p, size_t tind) const

46
src/layereddata.cpp

@ -193,16 +193,15 @@ LayeredData::Data LayeredData::Read(const MString& vname, const BaseParameters*
auto temp = Read("temp", ip, i); auto temp = Read("temp", ip, i);
auto sal = Read("sal", ip, i); auto sal = Read("sal", ip, i);
if(!(temp && sal)) return Data(); if(!(temp && sal)) return Data();
auto out = temp; temp.SetUnit("degrees_C");
out.SetUnit("degrees_C"); for(size_t ind = 0; ind < temp.N(); ind++)
for(size_t ind = 0; ind < out.N(); ind++)
{ {
if(temp.IsFill(ind) || sal.IsFill(ind)) if(temp.IsFill(ind) || sal.IsFill(ind))
out.V(ind) = out.Fillval(); temp.V(ind) = temp.Fillval();
else else
out.V(ind) = Temp2PTemp(temp.V(ind), sal.V(ind), Depth(p->layer), out.Lon(ind), out.Lat(ind)); temp.V(ind) = Temp2PTemp(temp.V(ind), sal.V(ind), Depth(p->layer), temp.Lon(ind), temp.Lat(ind));
} }
return out; return temp;
} }
// temp from ptemp and sal // temp from ptemp and sal
if(vname == "temp") if(vname == "temp")
@ -210,16 +209,15 @@ LayeredData::Data LayeredData::Read(const MString& vname, const BaseParameters*
auto temp = Read("ptemp", ip, i); auto temp = Read("ptemp", ip, i);
auto sal = Read("sal", ip, i); auto sal = Read("sal", ip, i);
if(!(temp && sal)) return Data(); if(!(temp && sal)) return Data();
auto out = temp; temp.SetUnit("degrees_C");
out.SetUnit("degrees_C"); for(size_t ind = 0; ind < temp.N(); ind++)
for(size_t ind = 0; ind < out.N(); ind++)
{ {
if(temp.IsFill(ind) || sal.IsFill(ind)) if(temp.IsFill(ind) || sal.IsFill(ind))
out.V(ind) = out.Fillval(); temp.V(ind) = temp.Fillval();
else else
out.V(ind) = PTemp2Temp(temp.V(ind), sal.V(ind), Depth(p->layer), out.Lon(ind), out.Lat(ind)); temp.V(ind) = PTemp2Temp(temp.V(ind), sal.V(ind), Depth(p->layer), temp.Lon(ind), temp.Lat(ind));
} }
return out; return temp;
} }
// pdens from temp and sal // pdens from temp and sal
if(vname == "pdens") if(vname == "pdens")
@ -228,17 +226,16 @@ LayeredData::Data LayeredData::Read(const MString& vname, const BaseParameters*
auto temp = Read(tempispot ? "ptemp" : "temp", ip, i); auto temp = Read(tempispot ? "ptemp" : "temp", ip, i);
auto sal = Read("sal", ip, i); auto sal = Read("sal", ip, i);
if(!(temp && sal)) return Data(); if(!(temp && sal)) return Data();
auto out = temp; temp.SetUnit("kg m-3");
out.SetUnit("kg m-3"); for(size_t ind = 0; ind < temp.N(); ind++)
for(size_t ind = 0; ind < out.N(); ind++)
{ {
if(temp.IsFill(ind) || sal.IsFill(ind)) if(temp.IsFill(ind) || sal.IsFill(ind))
out.V(ind) = out.Fillval(); temp.V(ind) = temp.Fillval();
else else
out.V(ind) = tempispot ? PTemp2PDens(temp.V(ind), sal.V(ind), Depth(p->layer), out.Lon(ind), out.Lat(ind)) temp.V(ind) = tempispot ? PTemp2PDens(temp.V(ind), sal.V(ind), Depth(p->layer), temp.Lon(ind), temp.Lat(ind))
: Temp2PDens(temp.V(ind), sal.V(ind), Depth(p->layer), out.Lon(ind), out.Lat(ind)); : Temp2PDens(temp.V(ind), sal.V(ind), Depth(p->layer), temp.Lon(ind), temp.Lat(ind));
} }
return out; return temp;
} }
// U and U2 from u and v // U and U2 from u and v
if(vname == "U" || vname == "U2") if(vname == "U" || vname == "U2")
@ -247,16 +244,15 @@ LayeredData::Data LayeredData::Read(const MString& vname, const BaseParameters*
auto u = Read("u", ip, i); auto u = Read("u", ip, i);
auto v = Read("v", ip, i); auto v = Read("v", ip, i);
if(!(u && v)) return Data(); if(!(u && v)) return Data();
auto out = u; if(square && u.Unit().Exist()) u.SetUnit("(" + u.Unit() + ")2");
out.SetUnit(square ? ("(" + u.Unit() + ")2") : u.Unit()); for(size_t ind = 0; ind < u.N(); ind++)
for(size_t ind = 0; ind < out.N(); ind++)
{ {
if(u.IsFill(ind) || v.IsFill(ind)) if(u.IsFill(ind) || v.IsFill(ind))
out.V(ind) = out.Fillval(); u.V(ind) = u.Fillval();
else else
out.V(ind) = square ? (u(ind) * u(ind) + v(ind) * v(ind)) : michlib::Hypot(u(ind), v(ind)); u.V(ind) = square ? (u(ind) * u(ind) + v(ind) * v(ind)) : michlib::Hypot(u(ind), v(ind));
} }
return out; return u;
} }
return Data(); return Data();
} }

Loading…
Cancel
Save