You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
75 lines
1.9 KiB
75 lines
1.9 KiB
#pragma once |
|
#include "basedata.h" |
|
|
|
class Simple2DData: public BaseData |
|
{ |
|
real x0 = 0.0, y0 = 0.0; |
|
size_t nx = 0, ny = 0; |
|
|
|
public: |
|
Simple2DData() = default; |
|
|
|
Simple2DData(size_t nx_, size_t ny_, real x0_, real y0_): BaseData(nx_ * ny_), x0(x0_), y0(y0_), nx(nx_), ny(ny_) {} |
|
|
|
const real& V(size_t i) const { return BaseData::V(i); } |
|
real& V(size_t i) { return BaseData::V(i); } |
|
|
|
const real& operator()(size_t i) const { return BaseData::V(i); } |
|
real& operator()(size_t i) { return BaseData::V(i); } |
|
|
|
const real& V(size_t ix, size_t iy) const { return V(iy * nx + ix); } |
|
real& V(size_t ix, size_t iy) { return V(iy * nx + ix); } |
|
|
|
const real& operator()(size_t ix, size_t iy) const { return V(iy * nx + ix); } |
|
real& operator()(size_t ix, size_t iy) { return V(iy * nx + ix); } |
|
|
|
size_t Nx() const { return nx; } |
|
size_t Ny() const { return ny; } |
|
|
|
real Lon(size_t ix, size_t iy) const { return x0 + ix / 12.0; } |
|
real Lat(size_t ix, size_t iy) const { return y0 + iy / 12.0; } |
|
|
|
real Lon(size_t i) const { return Lon(i % nx, i / nx); } |
|
real Lat(size_t i) const { return Lat(i % nx, i / nx); } |
|
|
|
void InitCount(std::vector<size_t>& count) const |
|
{ |
|
count.resize(data.size()); |
|
for(size_t i = 0; i < N(); i++) count[i] = (V(i) == fillval) ? 0 : 1; |
|
} |
|
|
|
Simple2DData& Add(const Simple2DData& d, std::vector<size_t>& count) |
|
{ |
|
if(!d) return *this; |
|
if(!*this) |
|
{ |
|
*this = d; |
|
InitCount(count); |
|
} |
|
|
|
if(N() != d.N() || N() != count.size()) return *this; |
|
for(size_t i = 0; i < N(); i++) |
|
if(d.V(i) != fillval) |
|
{ |
|
if(V(i) == fillval) |
|
{ |
|
V(i) = d(i); |
|
count[i] = 1; |
|
} |
|
else |
|
{ |
|
V(i) += d(i); |
|
count[i]++; |
|
} |
|
} |
|
return *this; |
|
} |
|
|
|
Simple2DData& Div(const std::vector<size_t>& count) |
|
{ |
|
if(N() != count.size()) return *this; |
|
for(size_t i = 0; i < N(); i++) |
|
if(count[i] != 0) V(i) /= count[i]; |
|
return *this; |
|
} |
|
};
|
|
|