From 610862b3a703790e6a5546b97fdb3b11efe09233 Mon Sep 17 00:00:00 2001 From: "Timur A. Fatkhullin" Date: Sat, 8 Mar 2025 10:50:18 +0300 Subject: [PATCH] ... --- cxx/mount_astrom.h | 60 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 58 insertions(+), 2 deletions(-) diff --git a/cxx/mount_astrom.h b/cxx/mount_astrom.h index 497e130..67bc35a 100644 --- a/cxx/mount_astrom.h +++ b/cxx/mount_astrom.h @@ -185,7 +185,11 @@ struct earth_orient_db_elem_t { }; -typedef std::vector earth_orient_db_t; +// typedef std::vector earth_orient_db_t; +struct earth_orient_db_t { + std::chrono::system_clock::time_point bulletinDate{}; + std::vector db{}; +}; // init to some known state static leapsecond_db_t CURRENT_LEAPSECONDS_DB = { @@ -202,8 +206,30 @@ static leapsecond_db_t CURRENT_LEAPSECONDS_DB = { }; + +static earth_orient_db_t CURRENT_EARTH_ORIENT_DB; + bool mcc_parse_bulletinA(std::derived_from> auto& stream, char comment_sym = '*') { + const std::regex bull_date_rx{ + "^ *[0-9]{1,2} +(January|Febraury|March|April|May|June|July|August|September|October|November|December) " + "+[0-9]{4,} + Vol\\.[XMLCDVI]+ +No\\. +[0-9]+ *$"}; + + const std::regex bull_tab_title_rx{"^ *MJD +x\\(arcsec\\) +y\\(arcsec\\) +UT1-UTC\\(sec\\) *$"}; + + // 2025 3 7 60741 0.0663 0.3341 0.04348 + const std::regex bull_tab_vals_rx{ + "^ *[0-9]{4,} +[0-9]{1,2} +[0-9]{1,2} +[0-9]{5,} +[0-9]+\\.[0-9]+ +[0-9]+\\.[0-9]+ +[0-9]+\\.[0-9]+ *$"}; + + earth_orient_db_t db; + enum { TAB_STATE_SEEK, TAB_STATE_START }; + int tab_state = TAB_STATE_SEEK; + + int year; + unsigned month, day; + double mjd, x, y, dut1; + std::istringstream is; + for (std::string line; std::getline(stream, line);) { if (line.empty()) { continue; @@ -215,11 +241,41 @@ bool mcc_parse_bulletinA(std::derived_from> auto& strea if (sv[0] == comment_sym) { // comment string continue; } - } else { + + if (tab_state == TAB_STATE_START) { + if (std::regex_match(sv.begin(), sv.end(), bull_tab_vals_rx)) { + is.str({sv.begin(), sv.end()}); + is >> year >> month >> day >> mjd >> x >> y >> dut1; + db.db.emplace_back(year, month, day, mjd, x, y, dut1); + } else { // end of the table - just stop parsing + break; + } + + continue; + } + + if (std::regex_match(sv.begin(), sv.end(), bull_date_rx)) { + is.str({sv.begin(), sv.end()}); + is >> std::chrono::parse("%d %B %Y", db.bulletinDate); + continue; + } + + if (std::regex_match(sv.begin(), sv.end(), bull_tab_title_rx)) { + tab_state = TAB_STATE_START; + continue; + } + + } else { // empty string (only spaces) continue; } } + if (db.db.empty()) { + return false; + } + + CURRENT_EARTH_ORIENT_DB = std::move(db); + return true; }