|
|
|
#pragma once
|
|
|
|
#include "basedata.h"
|
|
|
|
|
|
|
|
using michlib::Floor;
|
|
|
|
|
|
|
|
class Simple2DData: public BaseData
|
|
|
|
{
|
|
|
|
real x0 = 0.0, y0 = 0.0;
|
|
|
|
size_t nx = 0, ny = 0;
|
|
|
|
real xstep = 0.0, ystep = 0.0;
|
|
|
|
|
|
|
|
public:
|
|
|
|
using BaseData::IsFill;
|
|
|
|
using BaseData::V;
|
|
|
|
using BaseData::operator();
|
|
|
|
Simple2DData() = default;
|
|
|
|
|
|
|
|
Simple2DData(size_t nx_, size_t ny_, real x0_, real y0_, real xs_, real ys_, MString&& unit = ""):
|
|
|
|
BaseData(nx_ * ny_, std::move(unit)), x0(x0_), y0(y0_), nx(nx_), ny(ny_), xstep(xs_), ystep(ys_)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Simple2DData CopyGrid() const { return {nx, ny, x0, y0, xstep, ystep}; }
|
|
|
|
|
|
|
|
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; }
|
|
|
|
|
|
|
|
bool IsFill(size_t ix, size_t iy) const { return IsFill(iy * nx + ix); }
|
|
|
|
|
|
|
|
real Lon(size_t ix, [[maybe_unused]] size_t iy) const { return x0 + ix * xstep; }
|
|
|
|
real Lat([[maybe_unused]] size_t ix, size_t iy) const { return y0 + iy * ystep; }
|
|
|
|
|
|
|
|
real Lon(size_t i) const { return Lon(i % nx, i / nx); }
|
|
|
|
real Lat(size_t i) const { return Lat(i % nx, i / nx); }
|
|
|
|
|
|
|
|
real Ix2Lon(size_t ix) const { return x0 + ix * xstep; }
|
|
|
|
real Iy2Lat(size_t iy) const { return y0 + iy * ystep; }
|
|
|
|
|
|
|
|
real XStep() const { return xstep; }
|
|
|
|
real YStep() const { return ystep; }
|
|
|
|
|
|
|
|
auto GridPoint(real lon, real lat) const
|
|
|
|
{
|
|
|
|
struct GridPointLocation loc;
|
|
|
|
loc.ix = static_cast<size_t>(Floor((lon - x0) / xstep));
|
|
|
|
loc.iy = static_cast<size_t>(Floor((lat - y0) / ystep));
|
|
|
|
loc.x = lon - x0 - loc.ix * xstep;
|
|
|
|
loc.y = lat - y0 - loc.iy * ystep;
|
|
|
|
return loc;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class Rect2DData: public BaseData
|
|
|
|
{
|
|
|
|
std::vector<real> lon, lat;
|
|
|
|
|
|
|
|
public:
|
|
|
|
using BaseData::IsFill;
|
|
|
|
using BaseData::V;
|
|
|
|
using BaseData::operator();
|
|
|
|
Rect2DData() = default;
|
|
|
|
|
|
|
|
Rect2DData(const std::vector<real>& lons, const std::vector<real>& lats, MString&& unit = ""): BaseData(lons.size() * lats.size(), std::move(unit)), lon(lons), lat(lats) {}
|
|
|
|
|
|
|
|
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 lon.size(); }
|
|
|
|
size_t Ny() const { return lat.size(); }
|
|
|
|
|
|
|
|
bool IsFill(size_t ix, size_t iy) const { return IsFill(iy * Nx() + ix); }
|
|
|
|
|
|
|
|
real Lon(size_t ix, [[maybe_unused]] size_t iy) const { return lon[ix]; }
|
|
|
|
real Lat([[maybe_unused]] size_t ix, size_t iy) const { return lat[iy]; }
|
|
|
|
|
|
|
|
real Lon(size_t i) const { return Lon(i % Nx(), i / Nx()); }
|
|
|
|
real Lat(size_t i) const { return Lat(i % Nx(), i / Nx()); }
|
|
|
|
|
|
|
|
real Ix2Lon(size_t ix) const { return lon[ix]; }
|
|
|
|
real Iy2Lat(size_t iy) const { return lat[iy]; }
|
|
|
|
};
|