Skip to content

Commit 3ab68e7

Browse files
committed
minor
1 parent 6e4283b commit 3ab68e7

15 files changed

Lines changed: 312 additions & 147 deletions

include/core/sinex_details.hpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ namespace dso::sinex {
1818
/** @brief Max characters in a SINEX line */
1919
constexpr int max_sinex_chars = 128;
2020

21-
/** @brief Number of characters in a DOMES (no null-terminating char
21+
/** @brief Number of characters in a DOMES (no null-terminating char
2222
* included), see
2323
* https://itrf.ign.fr/en/network/domes/description
2424
*/
@@ -165,22 +165,21 @@ inline bool parameter_type_exists_impl(const char *ptype, int &index,
165165

166166
/** Copy src to dest, ommiting leading whitespaces (if any)
167167
*
168-
* Copies count chars from the object pointed to by src to the object pointed
168+
* Copies count chars from the object pointed to by src to the object pointed
169169
* to by dest. Note that we start counting from the first char of src, NOT the
170170
* first non-whitespace character.
171-
* This function actually calls std::memcpy, hence if the objects overlap, the
171+
* This function actually calls std::memcpy, hence if the objects overlap, the
172172
* behavior is undefined.
173-
* If either dest or src is an invalid or null pointer, the behavior is
174-
* undefined, even if count is zero.
173+
* If either dest or src is an invalid or null pointer, the behavior is
174+
* undefined, even if count is zero.
175175
*
176-
* @param[in] dest pointer to the memory location to copy to
177-
* @param[in] src pointer to the memory location to copy from
178-
* @param[in] count number of bytes to copy
176+
* @param[in] dest pointer to the memory location to copy to
177+
* @param[in] src pointer to the memory location to copy from
178+
* @param[in] count number of bytes to copy
179179
* @return pointer to dest
180180
*/
181181
inline const char *ltrim_cpy(char *__restrict__ dest,
182-
const char *__restrict__ src,
183-
int count) noexcept {
182+
const char *__restrict__ src, int count) noexcept {
184183
const char *c = src;
185184
while (*c && *c == ' ')
186185
++c;

include/dpod.hpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
11
/** @file
2-
* Utilities for dpod file (SINEX, psd and harmonics) provided by the IDS.
2+
* Utilities for dpod file (SINEX, psd and harmonics) provided by the IDS.
33
* Mostly used for DORIS beacons/sites.
44
*
55
* To date, a dpod realization include:
66
* 1. A SINEX file which can be handled by the respective dso::Sinex class,
7-
* 2. A dpod*_freq_corr.txt file, providing anual and semi-anual cartesian
7+
* 2. A dpod*_freq_corr.txt file, providing anual and semi-anual cartesian
88
* corrections, and
9-
* 3. A dpod*_psd_corr.txt file, providing PSD corrections in the form of
9+
* 3. A dpod*_psd_corr.txt file, providing PSD corrections in the form of
1010
* time-tagged offsets.
1111
*/
1212

1313
#ifndef __DSO_IDS_DPOP_HPP__
1414
#define __DSO_IDS_DPOP_HPP__
1515

16-
#include "sinex.hpp"
1716
#include "real_harmonics.hpp"
17+
#include "sinex.hpp"
1818
#include <cstring>
1919

2020
namespace dso {
21-
int parse_dpod_freq_corr(const char *fn,
22-
const std::vector<sinex::SiteId> &sites_vec,
23-
std::vector<SiteRealHarmonics> &harm) noexcept;
21+
int apply_dpod_freq_corr(
22+
const char *fn,
23+
const dso::datetime<dso::nanoseconds> &t,
24+
const std::vector<Sinex::SiteCoordinateResults> &sites_crd) noexcept;
2425
} /* namespace dso */
2526

2627
#endif

include/real_harmonics.hpp

Lines changed: 82 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#include <cmath>
1111
#include <cstdlib>
1212
#include <cstring>
13+
#include <cctype>
14+
#include <stdexcept>
1315

1416
namespace dso {
1517

@@ -75,27 +77,25 @@ class RealHarmonics {
7577
}
7678

7779
int num_harmonics() const noexcept { return m_num_harmonics; }
78-
80+
7981
const double *operator()(int i) const noexcept {
8082
return m_mem + i * DBLS_IN_TERM;
8183
}
8284
double *operator()(int i) noexcept { return m_mem + i * DBLS_IN_TERM; }
8385

8486
/** @brief Construct instance given the number of harmonics. */
85-
RealHarmonics(int num_harmonics = 0) noexcept
87+
explicit RealHarmonics(int num_harmonics = 0) noexcept
8688
: m_num_harmonics(num_harmonics),
8789
m_capacity(num_harmonics > MIN_HARMONIC_TERMS ? num_harmonics
8890
: MIN_HARMONIC_TERMS),
8991
m_mem((double *)std::malloc(m_capacity * DBLS_IN_TERM *
9092
sizeof(double))) {};
9193

9294
/** @brief Construct instance given a harmonic. */
93-
RealHarmonics(double freq, double amp_sin,
94-
double amp_cos) noexcept
95-
: m_num_harmonics(1)
96-
, m_capacity(MIN_HARMONIC_TERMS)
97-
, m_mem((double*)std::malloc(m_capacity * DBLS_IN_TERM * sizeof(double)))
98-
{
95+
explicit RealHarmonics(double freq, double amp_sin, double amp_cos) noexcept
96+
: m_num_harmonics(1), m_capacity(MIN_HARMONIC_TERMS),
97+
m_mem(
98+
(double *)std::malloc(m_capacity * DBLS_IN_TERM * sizeof(double))) {
9999
m_mem[0] = freq;
100100
m_mem[1] = amp_sin;
101101
m_mem[2] = amp_cos;
@@ -172,30 +172,89 @@ class RealHarmonics {
172172
* id (code) to mark the site name.
173173
*/
174174
class SiteRealHarmonics {
175-
RealHarmonics mhr;
176-
char msite[5]={'\0'};
175+
/* harmonics for X or N component */
176+
RealHarmonics mhr_xn;
177+
/* harmonics for Y or E component */
178+
RealHarmonics mhr_ye;
179+
/* harmonics for Z or U component */
180+
RealHarmonics mhr_zu;
181+
/* site 4-char id */
182+
char msite[5] = {'\0'};
183+
/* ref. system: can be either cartesian 'C' or topocentric 'T' */
184+
char mrsys = 'C';
185+
177186
public:
178-
SiteRealHarmonics(const char *name = nullptr) noexcept : mhr() {
179-
if (name) std::strncpy(msite, name, 4);
187+
explicit SiteRealHarmonics(const char *name = nullptr) noexcept : mhr_xn(), mhr_ye(), mhr_zu() {
188+
if (name)
189+
std::strncpy(msite, name, 4);
180190
}
181-
SiteRealHarmonics(const char* name, double freq, double Asin, double Acos) noexcept
182-
: mhr(freq, Asin, Acos)
183-
{
191+
explicit SiteRealHarmonics(char sys_ct, const char *name = nullptr) :
192+
mhr_xn(), mhr_ye(), mhr_zu(), mrsys(std::toupper(sys_ct)) {
193+
if (mrsys != 'C' && mrsys != 'T') {
194+
std::string errmsg = "[ERROR] Invalid harmonic component " + std::string{sys_ct} + "; can either be \'C\' for cartesian or \'T\' for neu/topocentric (traceback: " + std::string(__func__) + ")\n";
195+
throw std::runtime_error(errmsg);
196+
}
197+
if (name)
198+
std::strncpy(msite, name, 4);
199+
}
200+
SiteRealHarmonics(const char *name, int num_freqs) noexcept
201+
: mhr_xn(num_freqs), mhr_ye(num_freqs), mhr_zu(num_freqs) {
184202
#pragma GCC diagnostic push
185203
#pragma GCC diagnostic ignored "-Wstringop-truncation"
186204
if (name)
187205
std::strncpy(msite, name, 4);
188206
#pragma GCC diagnostic pop
189207
}
190-
const char *site_name() const noexcept {return msite;}
191-
char *site_name() noexcept {return msite;}
192-
const RealHarmonics &harmonics() const noexcept {return mhr;}
193-
RealHarmonics &harmonics() noexcept {return mhr;}
194-
int add_harmonic(double freq, double amp_sin = 0e0,
195-
double amp_cos = 0e0) noexcept
196-
{
197-
return mhr.add_harmonic(freq, amp_sin, amp_cos);
208+
const char *site_name() const noexcept { return msite; }
209+
char *site_name() noexcept { return msite; }
210+
const RealHarmonics &harmonics(char rcmp) const {
211+
char cmp =
212+
static_cast<char>(std::tolower(static_cast<unsigned char>(rcmp)));
213+
switch (mrsys) {
214+
case 'C':
215+
switch (cmp) {
216+
case 'x': return mhr_xn;
217+
case 'y': return mhr_ye;
218+
case 'z': return mhr_zu;
219+
}
220+
break;
221+
case 'T':
222+
switch (cmp) {
223+
case 'n': return mhr_xn;
224+
case 'e': return mhr_ye;
225+
case 'u': return mhr_zu;
226+
}
227+
break;
228+
}
229+
std::string errmsg = "[ERROR] Invalid harmonic component " + std::string{rcmp} + " for harmonics of type " + std::string{mrsys} + " (traceback: " + std::string(__func__) + ")\n";
230+
throw std::runtime_error(errmsg);
231+
}
232+
RealHarmonics &harmonics(char rcmp) {
233+
char cmp =
234+
static_cast<char>(std::tolower(static_cast<unsigned char>(rcmp)));
235+
switch (mrsys) {
236+
case 'C':
237+
switch (cmp) {
238+
case 'x': return mhr_xn;
239+
case 'y': return mhr_ye;
240+
case 'z': return mhr_zu;
241+
}
242+
break;
243+
case 'T':
244+
switch (cmp) {
245+
case 'n': return mhr_xn;
246+
case 'e': return mhr_ye;
247+
case 'u': return mhr_zu;
248+
}
249+
break;
250+
}
251+
std::string errmsg = "[ERROR] Invalid harmonic component " + std::string{rcmp} + " for harmonics of type " + std::string{mrsys} + " (traceback: " + std::string(__func__) + ")\n";
252+
throw std::runtime_error(errmsg);
198253
}
254+
//int add_harmonic(double freq, double amp_sin = 0e0,
255+
// double amp_cos = 0e0) noexcept {
256+
// return mhr.add_harmonic(freq, amp_sin, amp_cos);
257+
//}
199258
}; /* class SiteRealHarmonics */
200259

201260
} /* namespace dso */

include/sinex.hpp

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -322,18 +322,18 @@ class Sinex {
322322
* We will be matching records according to SITE CODE and
323323
* POINT CODE.
324324
* @param[in] t The time at which we want the eccentricities. If later
325-
* than the instance's DATA STOP time, then we will act according
325+
* than the instance's DATA STOP time, then we will act according
326326
* to the allow_extrapolation variable. If set to false, then no
327-
* extrapolation is performed and if t is later than the record's
327+
* extrapolation is performed and if t is later than the record's
328328
* Data End field, the record will not be collected.
329-
* If set to true, we will be assuming that the validity
329+
* If set to true, we will be assuming that the validity
330330
* intervals that end later than (DATA_STOP-allowed_offset) are
331-
* valid internaly in the future.
331+
* valid internaly in the future.
332332
* @param[out] out_vec A vector of sinex::SiteEccentricity for some or all
333333
* of the sites contained in site_vec, valid for the time given
334334
* (ie t)
335-
* @param[in] allow_extrapolation Allow extrapolation of eccentricity after
336-
* DATA_STOP, in case a record is valid up to
335+
* @param[in] allow_extrapolation Allow extrapolation of eccentricity after
336+
* DATA_STOP, in case a record is valid up to
337337
* (DATA_STOP-allowed_offset). See \t t.
338338
* @param[in] allowed_offset See \t t and \t allow_extrapolation
339339
* @return Anything other than 0 denotes an error
@@ -381,10 +381,18 @@ class Sinex {
381381

382382
struct SiteCoordinateResults {
383383
sinex::SiteId msite;
384-
double x, y, z; /* coordinates in [m] in [X,Y,Z] components */
385-
SiteCoordinateResults(const sinex::SiteId &s, double mx, double my,
384+
/* null-terminated string of solution id, with size 4+1 characters. this
385+
* should correspond to the solution/estimate solution id that this
386+
* instance was constructed from.
387+
*/
388+
char msolnid[5] = {'\0'};
389+
/* coordinates in [m] in [X,Y,Z] components */
390+
double x, y, z;
391+
SiteCoordinateResults(const sinex::SiteId &s, const char *solnid, double mx, double my,
386392
double mz) noexcept
387-
: msite(s), x(mx), y(my), z(mz){};
393+
: msite(s), x(mx), y(my), z(mz) {
394+
std::strcpy(msolnid,solnid);
395+
}
388396
}; /* SiteCoordinateResults */
389397

390398
/** @brief Extrpolate coordinate estimates for a given epoch.

include/sinex_blocks.hpp

Lines changed: 58 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* line of the SINEX block SITE/ID.
77
*
88
* References:
9-
* [1] SINEX - Solution (Software/technique) INdependent EXchange Format
9+
* [1] SINEX - Solution (Software/technique) INdependent EXchange Format
1010
* Version 2.02 (December 01, 2006)
1111
*/
1212

@@ -25,7 +25,7 @@ namespace sinex {
2525
struct SinexBlockPosition {
2626
std::ifstream::pos_type mpos; /* position from file begining */
2727
const char *mtype; /* block description */
28-
}; /* SinexBlockPosition */
28+
}; /* SinexBlockPosition */
2929

3030
/** Enum class to hold SINEX Observation Codes.
3131
* Within SINEX files, this is a single character indicating the technique(s)
@@ -59,7 +59,62 @@ SinexObservationCode char_to_SinexObservationCode(char c);
5959
/** @brief char to SinexConstraintCode (may throw) */
6060
SinexConstraintCode char_to_SinexConstraintCode(char c);
6161

62-
/** @class Hold information stored (per line) in an SITE/ID Block */
62+
/** @class Hold information stored (per line) in an SITE/ID Block
63+
*
64+
* Example snippet:
65+
+SITE/ID
66+
*CODE PT __DOMES__ T _STATION DESCRIPTION__ APPROX_LON_ APPROX_LAT_ _APP_H_
67+
ADEA A 91501S001 D TERRE ADELIE, ANTARCTI 140 00 05.2 -66 39 45.6 1.8
68+
ADEB A 91501S002 D TERRE ADELIE, ANTARCTI 140 00 07.3 -66 39 54.7 -0.0
69+
*
70+
*
71+
* see https://ivscc.gsfc.nasa.gov/products-data/sinex_v202.pdf
72+
*
73+
* |_________________S_I_T_E___I_D___D_A_T_A___L_I_N_E_________________|
74+
* | | | |
75+
* |__Field_________|______Description__________________|___Format_____|
76+
* | | | |
77+
* | [Site Code] | Call sign for a site. | 1X,A4 |
78+
* |________________|___________________________________|______________|
79+
* | | | |
80+
* | [Point Code] | Physical monument used at a site | 1X,A2 |
81+
* |________________|___________________________________|______________|
82+
* | | | |
83+
* | Unique Monument| Unique alpha-nummeric monument | 1X,A9 |
84+
* | Identification | identification. For ITRF purposes,| |
85+
* | | it is a nine character DOMES/DOMEX| |
86+
* | | number (five/six digits, followed | |
87+
* | | by the single letter 'M' or 'S', | |
88+
* | | followed by four/three digits) | |
89+
* |________________|___________________________________|______________|
90+
* | | | |
91+
* | [Observation | Observation technique(s) used. | 1X,A1 |
92+
* | Code] | | |
93+
* |________________|___________________________________|______________|
94+
* | | | |
95+
* | Station | Free-format description of the | 1X,A22 |
96+
* | Description | site, typically the town and/or | |
97+
* | | country. | |
98+
* |________________|___________________________________|______________|
99+
* | | | |
100+
* | Approximate | Approximate longitude of the site | 1X,I3, |
101+
* | Longitude | in degrees(E/+), minutes and | 1X,I2, |
102+
* | | seconds. | 1X,F4.1 |
103+
* |________________|___________________________________|______________|
104+
* | | | |
105+
* | Approximate | Approximate latitude of the site | 1X,I3, |
106+
* | Latitude | in degrees(NS/+-), minutes and | 1X,I2, |
107+
* | | seconds. | 1X,F4.1 |
108+
* |________________|___________________________________|______________|
109+
* | | | |
110+
* | Approximate | Approximate height of the site in | 1X,F7.1 |
111+
* | Height | metres. | |
112+
* |________________|___________________________________|______________|
113+
* | |
114+
* | 75 |
115+
* |______________|
116+
*
117+
*/
63118
class SiteId {
64119
private:
65120
static constexpr const int site_code_at = 0; /* [0,4] including NULL */

0 commit comments

Comments
 (0)