|
|
|
#pragma once
|
|
|
|
#include "BFileW.h"
|
|
|
|
#include "GPL.h"
|
|
|
|
#include "NEMO.h"
|
|
|
|
#include "tindexes.h"
|
|
|
|
|
|
|
|
using michlib::BFileW;
|
|
|
|
using michlib::errmessage;
|
|
|
|
using michlib::GPL;
|
|
|
|
using michlib::message;
|
|
|
|
using michlib::SList;
|
|
|
|
|
|
|
|
using DataVariants = std::variant<NEMOData>;
|
|
|
|
using CLArgs = std::map<MString, MString>;
|
|
|
|
|
|
|
|
class Data: public DataVariants
|
|
|
|
{
|
|
|
|
template<class D> static bool WriteData(BFileW& fw, const D& data)
|
|
|
|
{
|
|
|
|
for(size_t i = 0; i < data.N(); i++)
|
|
|
|
{
|
|
|
|
fw.Write(data.Lon(i));
|
|
|
|
fw.Write(data.Lat(i));
|
|
|
|
fw.Write(data(i) == data.Fillval() ? NAN : data(i));
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
Data() = default;
|
|
|
|
|
|
|
|
Data(DataVariants&& d): DataVariants(std::move(d)) {}
|
|
|
|
|
|
|
|
auto Time(size_t it) const
|
|
|
|
{
|
|
|
|
return std::visit(
|
|
|
|
[it = it](const auto& arg) -> auto{ return arg.Time(it); }, *this);
|
|
|
|
}
|
|
|
|
auto NTimes() const
|
|
|
|
{
|
|
|
|
return std::visit(
|
|
|
|
[](const auto& arg) -> auto{ return arg.NTimes(); }, *this);
|
|
|
|
}
|
|
|
|
auto Info() const
|
|
|
|
{
|
|
|
|
return std::visit(
|
|
|
|
[](const auto& arg) -> auto{ return arg.Info(); }, *this);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Write(BFileW& fw, VarType vt, const std::vector<size_t>& tindexes) const
|
|
|
|
{
|
|
|
|
return std::visit(
|
|
|
|
[&fw = fw, vt = vt, &ti = tindexes](const auto& d) -> bool
|
|
|
|
{
|
|
|
|
using T = std::decay_t<decltype(d)>;
|
|
|
|
|
|
|
|
return std::visit(
|
|
|
|
[&fw = fw, &ti = ti, &d = d](auto v) -> bool
|
|
|
|
{
|
|
|
|
constexpr auto cvt = decltype(v)::vt;
|
|
|
|
if constexpr(isDataSupported<T, cvt>)
|
|
|
|
return WriteData(fw, d.template Read<cvt>(ti));
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
vt);
|
|
|
|
},
|
|
|
|
*this);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
CLArgs ParseArgs(int argc, char** argv);
|
|
|
|
|
|
|
|
int actioninfo(const CLArgs& args);
|
|
|
|
int actiontsc(const CLArgs& args);
|
|
|
|
|
|
|
|
inline NEMOData NEMOOpen(const CLArgs& args)
|
|
|
|
{
|
|
|
|
NEMOData ndata;
|
|
|
|
|
|
|
|
MString oldprefix = GPL.UsePrefix("AVISO");
|
|
|
|
MString dataset = args.contains("dataset") ? args.at("dataset") : "DT";
|
|
|
|
MString cred = GPL.ParameterSValue("COPERNICUS_USER", "");
|
|
|
|
MString proxy = GPL.ParameterSValue("COPERNICUS_PROXY", "");
|
|
|
|
|
|
|
|
GPL.UsePrefix(oldprefix);
|
|
|
|
ndata.Open(dataset, cred, proxy);
|
|
|
|
return ndata;
|
|
|
|
}
|