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.
54 lines
1.4 KiB
54 lines
1.4 KiB
#pragma once |
|
#include "actions.h" |
|
|
|
template<class D> struct DoAction_<D, ActionID::TSC> |
|
{ |
|
static MString DoAction(const CLArgs& args, D& data); |
|
}; |
|
|
|
template<class D> MString DoAction_<D, ActionID::TSC>::DoAction(const CLArgs& args, D& ds) |
|
{ |
|
michlib_internal::ParameterListEx pars; |
|
pars.UsePrefix(""); |
|
pars.SetParameter("source", args.at("source")); |
|
|
|
auto [tindexes, err] = GetTIndexes(ds, args, pars); |
|
if(err.Exist()) return err; |
|
|
|
if(!args.contains("var")) return "Variable not specified"; |
|
MString vname = args.at("var"); |
|
if(!ds.CheckVar(vname)) return "Variable " + vname + " not exists in this dataset"; |
|
pars.SetParameter("variable", vname); |
|
|
|
std::unique_ptr<const BaseParameters> sourcepars; |
|
if constexpr(ParametersSupported<D>) |
|
{ |
|
auto [p, err] = ds.Parameters(pars, args); |
|
if(err.Exist()) return err; |
|
sourcepars.reset(p); |
|
} |
|
auto p = sourcepars.get(); |
|
|
|
auto data = Read(ds, vname, p, tindexes); |
|
if(!data) return "Can't read data"; |
|
|
|
BFileW fw; |
|
MString name = args.contains("out") ? args.at("out") : ""; |
|
if(!name.Exist()) name = "out.bin"; |
|
|
|
fw.Create(name, 3); |
|
fw.SetColumnName(1, "Longitude"); |
|
fw.SetColumnName(2, "Latitude"); |
|
fw.SetColumnName(3, vname); |
|
fw.SetParameters(pars); |
|
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)); |
|
} |
|
fw.Finalize(); |
|
fw.Close(); |
|
|
|
return ""; |
|
};
|
|
|