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.
 
 
 

145 lines
3.2 KiB

#pragma once
#include "BFileR.h"
#include "ParseArgs.h"
#include "mdatetime.h"
#include "mregex.h"
#include "simple2ddata.h"
#include <memory>
#include <set>
using michlib::M_PI;
using michlib::MDateTime;
using michlib::real;
using michlib::Round;
class VYLETData
{
std::unique_ptr<michlib::BFileR> vylet;
MDateTime start, end, ref;
bool invtime;
real maxx, maxy;
std::vector<real> lons, lats;
std::vector<real> elon, elat;
MDateTime R2Time(real r) const
{
auto sec = static_cast<time_t>(Round(r * MDateTime::secondsperday));
return ref + (invtime ? -sec : sec);
};
public:
using Data = Rect2DData;
private:
auto Name2ColNum(const MString& name) const
{
auto nc = vylet->Columns();
decltype(nc) i;
for(i = 1; i <= nc; i++)
if(vylet->ColumnName(i) == name) return i;
i = 0;
return i;
}
Data ReadD() const;
Data ReadL() const;
Data ReadT() const;
Data ReadNx() const;
Data ReadNy() const;
Data ReadRx() const;
Data ReadRy() const;
Data ReadEx() const;
Data ReadEy() const;
Data ReadPhip() const;
Data ReadPhim() const;
Data ReadPhit() const;
Data ReaddS() const;
Data ReadAngle() const;
Data ReadLen() const;
Data ReadTmask() const;
public:
static constexpr const char* name = "VYLET";
static constexpr const char* disabledactions = "genintfile uv";
MString DefaultVars() const
{
MString vars = "vylD,vylRx,vylRy,vylEx,vylEy,vylAngle,vylLen";
if(HasLyap()) vars += ",vylL";
if(HasTime()) vars += ",vylT";
return vars;
}
VarPresence CheckVar(const MString& vname) const
{
std::set<MString> vars{"vylD", "vylNx", "vylNy", "vylRx", "vylRy", "vylEx", "vylEy", "vylPhip", "vylPhim", "vylPhit", "vylAngle", "vylLen"};
if(HasLyap()) vars.insert("vylL");
if(HasLyap()) vars.insert("vyldS");
if(HasTime()) vars.insert("vylT");
if(HasTime()) vars.insert("vylTmask");
return vars.contains(vname) ? VarPresence::DERIVED : VarPresence::NONE;
}
bool Read(const MString& vname, std::map<MString, Data>& cache, size_t tind) const;
size_t NTimes() const { return vylet ? 1 : 0; }
MDateTime Time(size_t i) const
{
if(i == 0 && vylet) return start;
return MDateTime();
}
bool HasLyap() const
{
if(!vylet) return false;
vylet->UsePrefix("");
MString method = vylet->ParameterSValue("Method", "");
return method == "BicubicL" || method == "BicubicIL";
}
bool HasCoast() const
{
if(!vylet) return false;
vylet->UsePrefix("");
return vylet->ParameterBValue("checkcoast", true);
}
real Left() const
{
vylet->UsePrefix("");
return vylet->ParameterRValue("xl", -1.0);
}
real Right() const
{
vylet->UsePrefix("");
return vylet->ParameterRValue("xr", maxx + 1.0);
}
real Down() const
{
vylet->UsePrefix("");
return vylet->ParameterRValue("yd", -1.0);
}
real Up() const
{
vylet->UsePrefix("");
return vylet->ParameterRValue("yu", maxy + 1.0);
}
bool HasBorders() const { return Left() >= 0.0 || Right() <= maxx || Down() >= 0.0 || Up() <= maxy; }
bool HasTime() const { return HasCoast() || HasBorders(); }
bool LengthFast() const
{
vylet->UsePrefix("");
return !vylet->ParameterBValue("sisangle", false);
}
MString Info() const;
MString Open(const CLArgs& args);
};