Commit d764526c authored by Alexander Lapshin's avatar Alexander Lapshin

.

Merge branch 'master' of https://gitlab.ancprotek.ru/alapshin/common
parents 061ddd28 0969b9b3
#ifndef MAGDATA_H
#define MAGDATA_H
#pragma once
#include "XMLFunctions.h"
#include "json_functions.h"
......@@ -18,6 +17,9 @@ public:
bool HasGeomData() const { return m_hasGeomData; }
void CalcMag(double phase, double range);
void CalcGeomMag(double phase, double range);
double get_std_mag() const { return m_stdmag; }
double get_std_phase() const { return m_stdphase; }
double get_std_range() const { return m_stdrange; }
private:
static double CalcA0g(double stdmag, double stdphase, double stdrange, double sunMag);
static double CalcRealMag(double A0g, double sunMag, double phase, double range);
......@@ -33,5 +35,3 @@ private:
bool m_hasData;
bool m_hasGeomData;
};
#endif
#pragma once
#include <iostream>
#include <sstream>
#include <fstream>
#include <vector>
#include <string>
#include <map>
#include <list>
#include "stdio.h"
#include <iomanip>
#include "Converter.h"
#include "MException.h"
#define SPACES " \t\r\n"
static std::string ToStr(int arg)
{
std::ostringstream ss;
ss << arg;
return ss.str();
}
static std::string ToStr(size_t arg)
{
std::ostringstream ss;
ss << arg;
return ss.str();
}
static std::string ToStr(double arg)
{
std::ostringstream ss;
ss << arg;
return ss.str();
}
static void string_replace(std::string& str, const std::string& from, const std::string& to)
{
if (from.empty())
return;
size_t start_pos = 0;
while ((start_pos = str.find(from, start_pos)) != std::string::npos) {
str.replace(start_pos, from.length(), to);
start_pos += to.length(); // In case 'to' contains 'from', like replacing 'x' with 'yx'
}
}
static std::string ToStr(double value, int precision)
{
std::ostringstream ss;
ss << std::setprecision(precision);
ss << value;
return ss.str();
}
static std::string trim_right(const std::string& s, const std::string& t = SPACES)
{
std::string d(s);
const std::string::size_type i(d.find_last_not_of(t));
if (i == std::string::npos) {
return "";
}
else {
return d.erase(d.find_last_not_of(t) + 1);
}
}
static std::string trim_left(const std::string& s, const std::string& t = SPACES)
{
std::string d(s);
return d.erase(0, s.find_first_not_of(t));
}
template <typename T, typename T2>
bool GetMapItem(const std::map<T, T2>& map, const T& key, T2& ret)
{
typename std::map<T, T2>::const_iterator it = map.find(key);
if (it != map.end()) {
ret = it->second;
return true;
}
else {
return false;
}
}
template <typename T, typename T2>
bool GetMapItem(std::map<T, T2>& map, const T& key, T2*& ret)
{
typename std::map<T, T2>::iterator it = map.find(key);
if (it != map.end()) {
ret = &it->second;
return true;
}
else {
ret = 0;
return false;
}
}
template <typename T, typename T2>
bool GetMapItem(const std::map<T, T2>& map, const T& key, const T2*& ret)
{
typename std::map<T, T2>::const_iterator it = map.find(key);
if (it != map.end()) {
ret = &it->second;
return true;
}
else {
ret = 0;
return false;
}
}
template <typename T, typename T2>
bool GetMapItem(const std::map<T, T2>& map, const T& key)
{
return map.find(key) != map.end();
}
static std::string trim(const std::string& s, const std::string& t = SPACES)
{
return trim_left(trim_right(s, t), t);
}
template <typename ContainerT>
void splitstrf(const std::string& str, ContainerT& tokens, const std::string& delimiters = " ", const bool trimEmpty = false)
{
std::string::size_type lastPos = 0;
while (true) {
std::string::size_type pos = str.find_first_of(delimiters, lastPos);
if (pos == std::string::npos) {
pos = str.length();
if (pos != lastPos || !trimEmpty)
tokens.push_back(typename ContainerT::value_type(str.data() + lastPos, (typename ContainerT::value_type::size_type)pos - lastPos));
break;
}
else {
if (pos != lastPos || !trimEmpty)
tokens.push_back(typename ContainerT::value_type(str.data() + lastPos, (typename ContainerT::value_type::size_type)pos - lastPos));
}
lastPos = pos + 1;
}
};
static std::vector<std::string> splitstr(const std::string& str_i, const char* const delims_i)
{
std::vector<std::string> ret_vect;
if (str_i.empty()) return ret_vect;
splitstrf(str_i, ret_vect, std::string(delims_i));
return ret_vect;
}
static bool ReadFile(const std::string& path, std::vector<std::string>& file)
{
std::string line;
file.clear();
std::ifstream infile(path.c_str(), std::ios::in);
if (infile.is_open()) {
while (getline(infile, line, '\n')) {
file.push_back(line);
}
infile.close();
return true;
}
else {
return false;
}
}
static bool ReadFile(const std::string& path, std::string& str)
{
FILE* fp = fopen(path.c_str(), "rb");
if (!fp) {
return false;
}
fseek(fp, 0, SEEK_END); //go to end
const long len = ftell(fp); //get position at end (length)
fseek(fp, 0, SEEK_SET); //go to beg.
auto* buf = new char[len + 1]; //malloc buffer
buf[len] = 0;
size_t res = fread(buf, len, 1, fp); //read into buffer
fclose(fp);
str = std::string(buf);
delete[] buf;
return res;
}
static bool WriteFile(const std::string& path, const std::string& str)
{
std::string line;
std::ofstream file(path.c_str(), std::ios::out);
if (file.is_open()) {
file << str.c_str();
file.close();
return true;
}
else {
std::cerr << "Error while writing to file [" + path + "]";
return false;
}
}
template <typename T, typename Tid>
void GetAsMap(const std::vector<T>& vec, std::map<Tid, T>& res)
{
for (typename std::vector<T>::const_iterator it = vec.begin(); it != vec.end(); ++it) {
res[(*it).GetId()] = *it;
}
}
static void checkBounds(int value, const int* min, const int* max, bool strict = false)
{
if (!strict && min && value < *min || strict && min && value <= *min) {
throw Exp() << "value [" + ToStr(value) + "] less than " + ToStr(*min);
}
if (!strict && max && value > *max || strict && max && value >= *max) {
throw Exp() << "value [" + ToStr(value) + "] greater than " + ToStr(*max);
}
}
static void checkBounds(double value, const double* min, const double* max, bool strict = false)
{
if (!strict && min && value < *min || strict && min && value <= *min) {
throw Exp() << "value [" + ToStr(value) + "] less than " + ToStr(*min);
}
if (!strict && max && value > *max || strict && max && value >= *max) {
throw Exp() << "value [" + ToStr(value) + "] greater than " + ToStr(*max);
}
}
static void parseStrA(const std::string& data, int pos1, int pos2, int& ret, int* min, int* max, bool strict)
{
std::string part;
if (pos1 == -1 && pos2 == -1) {
part = data;
}
else {
part = pos2 >= 0 ? data.substr(pos1, pos2) : data.substr(pos1);
}
if (!Converter::ToNumber(part, ret)) {
const std::string errstr = pos2 ? (ToStr(pos1) + ":" + ToStr(pos2)) : (ToStr(pos1) + ":-");
throw Exp() << "bad substr format in line [" + data + "] at position" << errstr << " " << part;
}
if (min || max) {
try {
checkBounds(ret, min, max, strict);
}
catch (Exp& e) {
const std::string errstr = pos2 ? (ToStr(pos1) + ":" + ToStr(pos2)) : (ToStr(pos1) + ":-");
throw Exp() << "bad substr format in line [" + data + "] at position" << errstr << " " << part << ". " << e.what();
}
}
}
static void parseStrA(const std::string& data, int pos1, int pos2, double& ret, double* min, double* max, bool strict)
{
std::string part;
if (pos1 == -1 && pos2 == -1) {
part = data;
}
else {
part = pos2 >= 0 ? data.substr(pos1, pos2) : data.substr(pos1);
}
if (!Converter::ToNumber(part, ret)) {
const std::string errstr = pos2 ? (ToStr(pos1) + ":" + ToStr(pos2)) : (ToStr(pos1) + ":-");
throw (Exp() << "bad substr format in line [" + data + "] at position" << errstr << " " << part);
}
if (min || max) {
try {
checkBounds(ret, (double*)min, (double*)max, strict);
}
catch (Exp& e) {
const std::string errstr = pos2 ? (ToStr(pos1) + ":" + ToStr(pos2)) : (ToStr(pos1) + ":-");
throw Exp() << "bad substr format in line [" + data + "] at position" << errstr << " " << part << ". " << e.what();
}
}
}
static void parseStr(const std::string& data, int pos1, int pos2, int& ret, int min, int max, bool strict = false)
{
parseStrA(data, pos1, pos2, ret, &min, &max, strict);
}
static void parseStr(const std::string& data, int pos1, int pos2, double& ret, double min, double max, bool strict = false)
{
parseStrA(data, pos1, pos2, ret, &min, &max, strict);
}
static void parseStr(const std::string& data, int pos1, int pos2, int& ret)
{
parseStrA(data, pos1, pos2, ret, nullptr, nullptr, false);
}
static void parseStr(const std::string& data, int pos1, int pos2, double& ret)
{
parseStrA(data, pos1, pos2, ret, nullptr, nullptr, false);
}
static void parseStr(const std::string& data, int& ret, int min, int max, bool strict = false)
{
parseStrA(data, -1, -1, ret, &min, &max, false);
}
static void parseStr(const std::string& data, double& ret, double min, double max, bool strict = false)
{
parseStrA(data, -1, -1, ret, &min, &max, false);
}
static void parseStr(const std::string& data, int& ret)
{
parseStrA(data, -1, -1, ret, nullptr, nullptr, false);
}
static void parseStr(const std::string& data, double& ret)
{
parseStrA(data, -1, -1, ret, nullptr, nullptr, false);
}
template <typename T, typename T2>
std::vector<T> map_keys(const std::map<T, T2>& map)
{
std::vector<T> result;
for (typename std::map<T, T2>::const_iterator it = map.begin(); it != map.end(); ++it) {
result.push_back(it->first);
}
return result;
}
template <typename T>
std::string implode(std::string delim, const std::vector<T>& vec)
{
std::ostringstream ss;
for (typename std::vector<T>::const_iterator it = vec.begin(); it != vec.end(); ++it) {
ss << *it;
if (it != vec.end() - 1) {
ss << delim;
}
}
return ss.str();
}
template <typename T>
bool in_array(const std::vector<T>& src, T subject)
{
return std::find(std::begin(src), std::end(src), subject) != std::end(src);
}
#pragma once
#include <iostream>
#include <sstream>
#include <fstream>
#include <vector>
#include <string>
#include <map>
#include <list>
#include "stdio.h"
#include <iomanip>
#include "Converter.h"
#include "MException.h"
#define SPACES " \t\r\n"
static std::string ToStr(int arg)
{
std::ostringstream ss;
ss << arg;
return ss.str();
}
static std::string ToStr(size_t arg)
{
std::ostringstream ss;
ss << arg;
return ss.str();
}
static std::string ToStr(double arg)
{
std::ostringstream ss;
ss << arg;
return ss.str();
}
static void string_replace(std::string& str, const std::string& from, const std::string& to)
{
if (from.empty())
return;
size_t start_pos = 0;
while ((start_pos = str.find(from, start_pos)) != std::string::npos) {
str.replace(start_pos, from.length(), to);
start_pos += to.length(); // In case 'to' contains 'from', like replacing 'x' with 'yx'
}
}
static std::string ToStr(double value, int precision)
{
std::ostringstream ss;
ss << std::setprecision(precision);
ss << value;
return ss.str();
}
static std::string trim_right(const std::string& s, const std::string& t = SPACES)
{
std::string d(s);
const std::string::size_type i(d.find_last_not_of(t));
if (i == std::string::npos) {
return "";
}
else {
return d.erase(d.find_last_not_of(t) + 1);
}
}
static std::string trim_left(const std::string& s, const std::string& t = SPACES)
{
std::string d(s);
return d.erase(0, s.find_first_not_of(t));
}
template <typename T, typename T2>
bool GetMapItem(const std::map<T, T2>& map, const T& key, T2& ret)
{
typename std::map<T, T2>::const_iterator it = map.find(key);
if (it != map.end()) {
ret = it->second;
return true;
}
else {
return false;
}
}
template <typename T, typename T2>
bool GetMapItem(std::map<T, T2>& map, const T& key, T2*& ret)
{
typename std::map<T, T2>::iterator it = map.find(key);
if (it != map.end()) {
ret = &it->second;
return true;
}
else {
ret = 0;
return false;
}
}
template <typename T, typename T2>
bool GetMapItem(const std::map<T, T2>& map, const T& key, const T2*& ret)
{
typename std::map<T, T2>::const_iterator it = map.find(key);
if (it != map.end()) {
ret = &it->second;
return true;
}
else {
ret = 0;
return false;
}
}
template <typename T, typename T2>
bool GetMapItem(const std::map<T, T2>& map, const T& key)
{
return map.find(key) != map.end();
}
static std::string trim(const std::string& s, const std::string& t = SPACES)
{
return trim_left(trim_right(s, t), t);
}
template <typename ContainerT>
void splitstrf(const std::string& str, ContainerT& tokens, const std::string& delimiters = " ", const bool trimEmpty = false)
{
std::string::size_type lastPos = 0;
while (true) {
std::string::size_type pos = str.find_first_of(delimiters, lastPos);
if (pos == std::string::npos) {
pos = str.length();
if (pos != lastPos || !trimEmpty)
tokens.push_back(typename ContainerT::value_type(str.data() + lastPos, (typename ContainerT::value_type::size_type)pos - lastPos));
break;
}
else {
if (pos != lastPos || !trimEmpty)
tokens.push_back(typename ContainerT::value_type(str.data() + lastPos, (typename ContainerT::value_type::size_type)pos - lastPos));
}
lastPos = pos + 1;
}
};
static std::vector<std::string> splitstr(const std::string& str_i, const char* const delims_i)
{
std::vector<std::string> ret_vect;
if (str_i.empty()) return ret_vect;
splitstrf(str_i, ret_vect, std::string(delims_i));
return ret_vect;
}
static bool ReadFile(const std::string& path, std::vector<std::string>& file)
{
std::string line;
file.clear();
std::ifstream infile(path.c_str(), std::ios::in);
if (infile.is_open()) {
while (getline(infile, line, '\n')) {
file.push_back(line);
}
infile.close();
return true;
}
else {
return false;
}
}
static bool ReadFile(const std::string& path, std::string& str)
{
FILE* fp = fopen(path.c_str(), "rb");
if (!fp) {
return false;
}
fseek(fp, 0, SEEK_END); //go to end
const long len = ftell(fp); //get position at end (length)
fseek(fp, 0, SEEK_SET); //go to beg.
auto* buf = new char[len + 1]; //malloc buffer
buf[len] = 0;
size_t res = fread(buf, len, 1, fp); //read into buffer
fclose(fp);
str = std::string(buf);
delete[] buf;
return res;
}
static bool WriteFile(const std::string& path, const std::string& str)
{
std::string line;
std::ofstream file(path.c_str(), std::ios::out);
if (file.is_open()) {
file << str.c_str();
file.close();
return true;
}
else {
std::cerr << "Error while writing to file [" + path + "]";
return false;
}
}
template <typename T, typename Tid>
void GetAsMap(const std::vector<T>& vec, std::map<Tid, T>& res)
{
for (typename std::vector<T>::const_iterator it = vec.begin(); it != vec.end(); ++it) {
res[(*it).GetId()] = *it;
}
}
static void checkBounds(int value, const int* min, const int* max, bool strict = false)
{
if (!strict && min && value < *min || strict && min && value <= *min) {
throw Exp() << "value [" + ToStr(value) + "] less than " + ToStr(*min);
}
if (!strict && max && value > *max || strict && max && value >= *max) {
throw Exp() << "value [" + ToStr(value) + "] greater than " + ToStr(*max);
}
}
static void checkBounds(double value, const double* min, const double* max, bool strict = false)
{
if (!strict && min && value < *min || strict && min && value <= *min) {
throw Exp() << "value [" + ToStr(value) + "] less than " + ToStr(*min);
}
if (!strict && max && value > *max || strict && max && value >= *max) {
throw Exp() << "value [" + ToStr(value) + "] greater than " + ToStr(*max);
}
}
static void parseStrA(const std::string& data, int pos1, int pos2, int& ret, int* min, int* max, bool strict)
{
std::string part;
if (pos1 == -1 && pos2 == -1) {
part = data;
}
else {
part = pos2 >= 0 ? data.substr(pos1, pos2) : data.substr(pos1);
}
if (!Converter::ToNumber(part, ret)) {
const std::string errstr = pos2 ? (ToStr(pos1) + ":" + ToStr(pos2)) : (ToStr(pos1) + ":-");
throw Exp() << "bad substr format in line [" + data + "] at position" << errstr << " " << part;
}
if (min || max) {
try {
checkBounds(ret, min, max, strict);
}
catch (Exp& e) {
const std::string errstr = pos2 ? (ToStr(pos1) + ":" + ToStr(pos2)) : (ToStr(pos1) + ":-");
throw Exp() << "bad substr format in line [" + data + "] at position" << errstr << " " << part << ". " << e.what();
}
}
}
static void parseStrA(const std::string& data, int pos1, int pos2, double& ret, double* min, double* max, bool strict)
{
std::string part;
if (pos1 == -1 && pos2 == -1) {
part = data;
}
else {
part = pos2 >= 0 ? data.substr(pos1, pos2) : data.substr(pos1);
}
if (!Converter::ToNumber(part, ret)) {
const std::string errstr = pos2 ? (ToStr(pos1) + ":" + ToStr(pos2)) : (ToStr(pos1) + ":-");
throw (Exp() << "bad substr format in line [" + data + "] at position" << errstr << " " << part);
}
if (min || max) {
try {
checkBounds(ret, (double*)min, (double*)max, strict);
}
catch (Exp& e) {
const std::string errstr = pos2 ? (ToStr(pos1) + ":" + ToStr(pos2)) : (ToStr(pos1) + ":-");
throw Exp() << "bad substr format in line [" + data + "] at position" << errstr << " " << part << ". " << e.what();
}
}
}
static void parseStr(const std::string& data, int pos1, int pos2, int& ret, int min, int max, bool strict = false)
{
parseStrA(data, pos1, pos2, ret, &min, &max, strict);
}
static void parseStr(const std::string& data, int pos1, int pos2, double& ret, double min, double max, bool strict = false)
{
parseStrA(data, pos1, pos2, ret, &min, &max, strict);
}
static void parseStr(const std::string& data, int pos1, int pos2, int& ret)
{
parseStrA(data, pos1, pos2, ret, nullptr, nullptr, false);
}
static void parseStr(const std::string& data, int pos1, int pos2, double& ret)
{
parseStrA(data, pos1, pos2, ret, nullptr, nullptr, false);
}
static void parseStr(const std::string& data, int& ret, int min, int max, bool strict = false)
{
parseStrA(data, -1, -1, ret, &min, &max, false);
}
static void parseStr(const std::string& data, double& ret, double min, double max, bool strict = false)
{
parseStrA(data, -1, -1, ret, &min, &max, false);
}
static void parseStr(const std::string& data, int& ret)
{
parseStrA(data, -1, -1, ret, nullptr, nullptr, false);
}
static void parseStr(const std::string& data, double& ret)
{
parseStrA(data, -1, -1, ret, nullptr, nullptr, false);
}
template <typename T, typename T2>
std::vector<T> map_keys(const std::map<T, T2>& map)
{
std::vector<T> result;
for (typename std::map<T, T2>::const_iterator it = map.begin(); it != map.end(); ++it) {
result.push_back(it->first);
}
return result;
}
template <typename T>
std::string implode(std::string delim, const std::vector<T>& vec)
{
std::ostringstream ss;
for (typename std::vector<T>::const_iterator it = vec.begin(); it != vec.end(); ++it) {
ss << *it;
if (it != vec.end() - 1) {
ss << delim;
}
}
return ss.str();
}
template <typename T>
bool in_array(const std::vector<T>& src, T subject)
{
return std::find(std::begin(src), std::end(src), subject) != std::end(src);
}
......@@ -48,13 +48,18 @@ OrbBlock::~OrbBlock()
delete m_ip;
}
void OrbBlock::interpolate(const TimeJD& beg, const TimeJD& end)
void OrbBlock::init_by_orbit()
{
m_ip = new XInterpolator(m_orbit, beg, end);
m_ip = new XInterpolator(m_orbit, get_beg(), get_end());
}
void OrbBlock::init_by_data()
{
m_ip = new XInterpolator(m_data.get_vecs());
}
void OrbBlock::load(const jsonval& parent)
{
m_data.load(parent);
m_data.load(parent);
}
......@@ -18,7 +18,8 @@ public:
const SInitOrbit& get_orbit() const { return m_orbit; }
double get_min_distance() const { return get_data().get_min_distance(); }
std::string get_next_orbitid() const { return get_data().get_next_orbitid(); }
void interpolate(const TimeJD& beg, const TimeJD& end);
void init_by_orbit();
void init_by_data();
const XInterpolator* get_interpolator() const { return m_ip; }
void load(const jsonval& parent);
const orb_block_data& get_data() const { return m_data; }
......
......@@ -33,8 +33,9 @@ void OrbBlocksStore::init(
if (interpolate) {
for (auto& m_block : m_blocks) {
m_block.interpolate(m_block.get_beg(), m_block.get_end());
m_block.init_by_orbit();
}
m_initiated = true;
}
}
......@@ -49,6 +50,15 @@ void OrbBlocksStore::init(
init(orbits, &beg, &end, filter_orbits, min_dist_forced, interpolate);
}
void OrbBlocksStore::init()
{
for (auto& m_block : m_blocks) {
m_block.init_by_data();
}
m_initiated = true;
}
SInitOrbits OrbBlocksStore::filter(const SInitOrbits& orbits) const
{
SInitOrbits result;
......@@ -244,11 +254,11 @@ void OrbBlocksStore::calc_min_dist(const SInitOrbit& orb1, const SInitOrbit& orb
result_dist = eval.calc(shift);
}
Vect6 OrbBlocksStore::get_pos(const TimeJD& date) const
Vect6 OrbBlocksStore::get_pos(const TimeJD& date, const bool tks) const
{
for (const auto& block : m_blocks) {
if (date >= block.get_beg() && date <= block.get_end()) {
return block.get_interpolator()->get_pos(date);
return block.get_interpolator()->get_pos(date, tks);
}
}
......@@ -269,7 +279,7 @@ const SInitOrbit& OrbBlocksStore::get_orbit(const TimeJD& date) const
std::vector<orb_block_data> OrbBlocksStore::get_orb_data() const
{
std::vector<orb_block_data> result;
for(const auto& el: m_blocks) {
for (const auto& el : m_blocks) {
result.emplace_back(el.get_data());
}
return result;
......
......@@ -8,14 +8,14 @@
typedef std::vector<OrbBlock> OrbBlocks;
class OrbBlocksStore
{
class OrbBlocksStore {
public:
OrbBlocksStore();
void init(const SInitOrbits& orbits, const TimeJD* beg, const TimeJD* end, bool filter_orbits, bool min_dist_forced, bool interpolate);
void init(const SInitOrbits& orbits, const TimeJD& beg, const TimeJD& end, bool filter_orbits, bool min_dist_forced, bool interpolate);
void init();
SInitOrbits calc_orbits(std::vector<TimeJD> dates, bool variates) const;
Vect6 get_pos(const TimeJD& date) const;
Vect6 get_pos(const TimeJD& date, bool tks = false) const;
const SInitOrbit& get_orbit(const TimeJD& date) const;
const OrbBlocks& get_blocks() const { return m_blocks; }
std::vector<orb_block_data> get_orb_data() const;
......@@ -23,6 +23,7 @@ public:
const TimeJD& get_beg_before_filter() const { return m_beg_before_filter; }
const TimeJD& get_end_before_filter() const { return m_end_before_filter; }
void load(const jsonval& parent);
bool is_initiated() const { return m_initiated; }
private:
void init_min_dist(const SInitOrbits& orbits, const TimeJD& beg, const TimeJD& end, bool forced);
void calc_min_dist(const SInitOrbit& orb1, const SInitOrbit& orb2, const TimeJD& beg, const TimeJD& end, TimeJD& result_jd, double& result_dist) const;
......@@ -30,4 +31,5 @@ private:
OrbBlocks m_blocks;
TimeJD m_beg_before_filter;
TimeJD m_end_before_filter;
bool m_initiated{false};
};
......@@ -41,4 +41,38 @@ void orb_block_data::load(const jsonval& parent)
loadjson(parent, "beg", m_beg);
loadjson(parent, "end", m_end);
loadjson(parent, "mind_km", m_mind, false);
std::string vecs;
loadjson(parent, "vecs", vecs);
std::vector<std::string> parts;
splitstrf(vecs, parts, ",");
for (size_t i = 0; i < parts.size(); i += 8) {
int days;
Converter::ToNumber(parts[i], days);
double fraction;
Converter::ToNumber(parts[i + 1], fraction);
double x;
Converter::ToNumber(parts[i + 2], x);
double y;
Converter::ToNumber(parts[i + 3], y);
double z;
Converter::ToNumber(parts[i + 4], z);
double vx;
Converter::ToNumber(parts[i + 5], vx);
double vy;
Converter::ToNumber(parts[i + 6], vy);
double vz;
Converter::ToNumber(parts[i + 7], vz);
m_vecs.emplace_back(Vect6(x, y, z, vx, vy, vz), TimeJD(days, fraction), 0, "");
}
}
......@@ -2,21 +2,22 @@
#include "TM.h"
#include "json_functions.h"
#include "ires.h"
class orb_block_data {
public:
orb_block_data() = default;
orb_block_data(
std::string orbitid,
const TimeJD& date,
const TimeJD& beg,
std::string orbitid,
const TimeJD& date,
const TimeJD& beg,
const TimeJD& end);
orb_block_data(
std::string orbitid,
const TimeJD& date,
const TimeJD& beg,
const TimeJD& end,
double mind,
std::string orbitid,
const TimeJD& date,
const TimeJD& beg,
const TimeJD& end,
double mind,
std::string next_orbitid);
void load(const jsonval& parent);
TimeJD get_date() const { return m_date; }
......@@ -25,6 +26,7 @@ public:
const std::string& get_orbitid() const { return m_orbitid; }
const std::string& get_next_orbitid() const { return m_next_orbitid; }
double get_min_distance() const { return m_mind; }
const std::vector<IRes>& get_vecs() const { return m_vecs; }
private:
std::string m_orbitid;
std::string m_next_orbitid;
......@@ -32,5 +34,5 @@ private:
TimeJD m_beg;
TimeJD m_end;
double m_mind;
std::vector<IRes> m_vecs;
};
#include "orb_date.h"
#include "Propagator.h"
#include <algorithm>
std::vector<TimeJD> generate_dates(const TimeJD& sdate, const TimeJD& edate, double step_sec)
{
std::vector<TimeJD> result;
result.push_back(sdate);
if (sdate >= edate) {
return result;
}
// old style check, need future analysis to choose right comparison
//if (fabs(DaysInterval(sdate, edate)) * 86400 < 0.001) {
// return result;
//}
const int n = (int)(DaysInterval(sdate, edate) * 86400 / step_sec);
for (int i = 0; i < n; ++i) {
result.emplace_back(ShiftDateX(sdate, step_sec * (i + 1)));
}
if (result.back() != edate) {
result.push_back(edate);
}
// old style check, need future analysis to choose right comparison
//if (fabs(DaysInterval(result.back(), edate)) * 86400 > 0.001) {
// result.push_back(edate);
//}
return result;
}
void propagate_date(Propagator& prop, const TimeJD& date, IRes& result)
{
PhasePoint6D pos;
prop.Propagate(date, pos);
result = IRes(pos.CoordsVel, date, DaysInterval(prop.GetInitOrbit().GetDate(), date), prop.GetInitOrbit().GetId());
}
void propagate_date(Propagator& prop, const TimeJD& date, SInitOrbit& result)
{
SInitOrbit orbit;
prop.Propagate(date, result);
result.SetBaseOrbitId(prop.GetInitOrbit().GetId());
}
template <typename T>
void propagate_dir_prop(Propagator& prop, const std::vector<TimeJD>& dates, int dir, std::vector<T>& result)
{
if (dir > 0) {
for (const auto& date : dates) {
T item;
propagate_date(prop, date, item);
result.push_back(item);
}
}
else if (dir < 0) {
for (auto it = dates.rbegin(); it != dates.rend(); ++it) {
T item;
propagate_date(prop, *it, item);
result.push_back(item);
}
}
}
void propagate_dir(const SInitOrbit& orbit, const std::vector<TimeJD>& dates, int dir, bool variates, std::vector<IRes>& result)
{
Propagator prop(orbit, variates);
propagate_dir_prop(prop, dates, dir, result);
}
void propagate_dir(const SInitOrbit& orbit, const std::vector<TimeJD>& dates, int dir, bool variates, std::vector<SInitOrbit>& result)
{
Propagator prop(orbit, variates);
propagate_dir_prop(prop, dates, dir, result);
}
void split_dates(const std::vector<TimeJD>& dates, const TimeJD& date, std::vector<TimeJD>& dates_left, std::vector<TimeJD>& dates_right)
{
for (const auto& it : dates) {
if (it < date) {
dates_left.push_back(it);
}
else {
dates_right.push_back(it);
}
}
}
template <typename T>
void calc_orbit_on_dates(const SInitOrbit& orbit, std::vector<TimeJD> dates, bool variates, std::vector<T>& result)
{
if (dates.empty()) {
return;
}
std::sort(dates.begin(), dates.end(), [](const TimeJD& a, const TimeJD& b) {
return a < b;
});
const TimeJD& beg_ext = dates.front();
const TimeJD& end_ext = dates.back();
if (orbit.GetDate() <= beg_ext) {
propagate_dir(orbit, dates, 1, variates, result);
}
else if (orbit.GetDate() >= end_ext) {
propagate_dir(orbit, dates, -1, variates, result);
}
else {
std::vector<TimeJD> dates_left, dates_right;
split_dates(dates, orbit.GetDate(), dates_left, dates_right);
propagate_dir(orbit, dates_left, -1, variates, result);
propagate_dir(orbit, dates_right, +1, variates, result);
}
}
std::vector<IRes> calc_positions_on_dates(const SInitOrbit& orbit, const TimeJD& beg, const TimeJD& end, double step_sec)
{
return calc_positions_on_dates(orbit, generate_dates(beg, end, step_sec));
}
std::vector<SInitOrbit> calc_orbits_on_dates(const SInitOrbit& orbit, const TimeJD& beg, const TimeJD& end, double step_sec, bool variates)
{
return calc_orbits_on_dates(orbit, generate_dates(beg, end, step_sec), variates);
}
double calc_age(const SInitOrbit& orbit, const TimeJD& date)
{
const TimeJD orbit_beg = ShiftDate(orbit.GetDate(), -orbit.GetInterval() * 86400);
const TimeJD& orbit_end = orbit.GetDate();
double age_days = 0;
if (date < orbit_beg) {
age_days = DaysInterval(orbit_beg, date);
}
else if (date > orbit_end) {
age_days = DaysInterval(date, orbit_end);
}
return age_days;
}
std::vector<IRes> calc_positions_on_dates(const SInitOrbit& orbit, const std::vector<TimeJD>& dates)
{
std::vector<IRes> result;
calc_orbit_on_dates(orbit, dates, false, result);
std::sort(result.begin(), result.end(), [](const IRes& a, const IRes& b) {
return a.get_date() < b.get_date();
});
return result;
}
std::vector<SInitOrbit> calc_orbits_on_dates(const SInitOrbit& orbit, const std::vector<TimeJD>& dates, bool variates)
{
std::vector<SInitOrbit> result;
calc_orbit_on_dates(orbit, dates, variates, result);
std::sort(result.begin(), result.end(), [](const SInitOrbit& a, const SInitOrbit& b) {
return a.GetDate() < b.GetDate();
});
return result;
}
#include "orb_date.h"
#include "Propagator.h"
#include <algorithm>
std::vector<TimeJD> generate_dates(const TimeJD& sdate, const TimeJD& edate, double step_sec)
{
std::vector<TimeJD> result;
result.push_back(sdate);
if (sdate >= edate) {
return result;
}
// old style check, need future analysis to choose right comparison
//if (fabs(DaysInterval(sdate, edate)) * 86400 < 0.001) {
// return result;
//}
const auto n = (int)(DaysInterval(sdate, edate) * 86400 / step_sec);
for (int i = 0; i < n; ++i) {
result.emplace_back(ShiftDate(sdate, step_sec * (i + 1)));
}
if (result.back() != edate) {
result.push_back(edate);
}
// old style check, need future analysis to choose right comparison
//if (fabs(DaysInterval(result.back(), edate)) * 86400 > 0.001) {
// result.push_back(edate);
//}
return result;
}
void propagate_date(Propagator& prop, const TimeJD& date, IRes& result)
{
PhasePoint6D pos;
prop.Propagate(date, pos);
result = IRes(pos.CoordsVel, date, DaysInterval(prop.GetInitOrbit().GetDate(), date), prop.GetInitOrbit().GetId());
}
void propagate_date(Propagator& prop, const TimeJD& date, SInitOrbit& result)
{
SInitOrbit orbit;
prop.Propagate(date, result);
result.SetBaseOrbitId(prop.GetInitOrbit().GetId());
}
template <typename T>
void propagate_dir_prop(Propagator& prop, const std::vector<TimeJD>& dates, int dir, std::vector<T>& result)
{
if (dir > 0) {
for (const auto& date : dates) {
T item;
propagate_date(prop, date, item);
result.push_back(item);
}
}
else if (dir < 0) {
for (auto it = dates.rbegin(); it != dates.rend(); ++it) {
T item;
propagate_date(prop, *it, item);
result.push_back(item);
}
}
}
void propagate_dir(const SInitOrbit& orbit, const std::vector<TimeJD>& dates, int dir, bool variates, std::vector<IRes>& result)
{
Propagator prop(orbit, variates);
propagate_dir_prop(prop, dates, dir, result);
}
void propagate_dir(const SInitOrbit& orbit, const std::vector<TimeJD>& dates, int dir, bool variates, std::vector<SInitOrbit>& result)
{
Propagator prop(orbit, variates);
propagate_dir_prop(prop, dates, dir, result);
}
void split_dates(const std::vector<TimeJD>& dates, const TimeJD& date, std::vector<TimeJD>& dates_left, std::vector<TimeJD>& dates_right)
{
for (const auto& it : dates) {
if (it < date) {
dates_left.push_back(it);
}
else {
dates_right.push_back(it);
}
}
}
template <typename T>
void calc_orbit_on_dates(const SInitOrbit& orbit, std::vector<TimeJD> dates, bool variates, std::vector<T>& result)
{
if (dates.empty()) {
return;
}
std::sort(dates.begin(), dates.end(), [](const TimeJD& a, const TimeJD& b) {
return a < b;
});
const TimeJD& beg_ext = dates.front();
const TimeJD& end_ext = dates.back();
if (orbit.GetDate() <= beg_ext) {
propagate_dir(orbit, dates, 1, variates, result);
}
else if (orbit.GetDate() >= end_ext) {
propagate_dir(orbit, dates, -1, variates, result);
}
else {
std::vector<TimeJD> dates_left, dates_right;
split_dates(dates, orbit.GetDate(), dates_left, dates_right);
propagate_dir(orbit, dates_left, -1, variates, result);
propagate_dir(orbit, dates_right, +1, variates, result);
}
}
std::vector<IRes> calc_positions_on_dates(const SInitOrbit& orbit, const TimeJD& beg, const TimeJD& end, double step_sec)
{
return calc_positions_on_dates(orbit, generate_dates(beg, end, step_sec));
}
std::vector<SInitOrbit> calc_orbits_on_dates(const SInitOrbit& orbit, const TimeJD& beg, const TimeJD& end, double step_sec, bool variates)
{
return calc_orbits_on_dates(orbit, generate_dates(beg, end, step_sec), variates);
}
double calc_age(const SInitOrbit& orbit, const TimeJD& date)
{
const TimeJD orbit_beg = ShiftDate(orbit.GetDate(), -orbit.GetInterval() * 86400);
const TimeJD& orbit_end = orbit.GetDate();
double age_days = 0;
if (date < orbit_beg) {
age_days = DaysInterval(orbit_beg, date);
}
else if (date > orbit_end) {
age_days = DaysInterval(date, orbit_end);
}
return age_days;
}
std::vector<IRes> calc_positions_on_dates(const SInitOrbit& orbit, const std::vector<TimeJD>& dates)
{
std::vector<IRes> result;
calc_orbit_on_dates(orbit, dates, false, result);
std::sort(result.begin(), result.end(), [](const IRes& a, const IRes& b) {
return a.get_date() < b.get_date();
});
return result;
}
std::vector<SInitOrbit> calc_orbits_on_dates(const SInitOrbit& orbit, const std::vector<TimeJD>& dates, bool variates)
{
std::vector<SInitOrbit> result;
calc_orbit_on_dates(orbit, dates, variates, result);
std::sort(result.begin(), result.end(), [](const SInitOrbit& a, const SInitOrbit& b) {
return a.GetDate() < b.GetDate();
});
return result;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment