Skip to content

Commit ba9ea28

Browse files
committed
testing
1 parent ea62e42 commit ba9ea28

13 files changed

+399
-290
lines changed

include/core/sinex_details.hpp

+25
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,31 @@ inline bool parameter_type_exists_impl(const char *ptype, int &index,
157157
return true;
158158
}
159159

160+
/** Copy src to dest, ommiting leading whitespaces (if any)
161+
*
162+
* Copies count chars from the object pointed to by src to the object pointed
163+
* to by dest. Note that we start counting from the first char of src, NOT the
164+
* first non-whitespace character.
165+
* This function actually calls std::memcpy, hence if the objects overlap, the
166+
* behavior is undefined.
167+
* If either dest or src is an invalid or null pointer, the behavior is
168+
* undefined, even if count is zero.
169+
*
170+
* @param[in] dest pointer to the memory location to copy to
171+
* @param[in] src pointer to the memory location to copy from
172+
* @param[in] count number of bytes to copy
173+
* @return pointer to dest
174+
*/
175+
inline const char *ltrim_cpy(char *__restrict__ dest,
176+
const char *__restrict__ src,
177+
int max_chars) noexcept {
178+
const char *c = src;
179+
while (*c && *c == ' ')
180+
++c;
181+
std::memcpy(dest, c, max_chars - (c - src));
182+
return dest;
183+
}
184+
160185
/** @brief Match a given string to any string in parameter_types array
161186
*
162187
* @param[in] ptype String to match (null-terminiated)

include/sinex.hpp

+8-2
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ class Sinex {
163163
* Parse the SITE/ID block of the SINEX file and collect info for given
164164
* sites.
165165
* This function will search through the SITE/ID block, and collect all
166-
* infor for the sites that are included in the sites vector. Matching of
166+
* info for the sites that are included in the sites vector. Matching of
167167
* stations can be parformed in two ways:
168168
* 1. if use_domes is set to false, then only the SITE CODE is checked, i.e.
169169
* each string in the sites vector should contain a 4-char id of the
@@ -206,12 +206,18 @@ class Sinex {
206206
std::vector<sinex::SiteReceiver> &site_vec) noexcept;
207207

208208
/** @brief Parse the whole SITE/ANTENNA Block off from the SINEX instance.
209+
*
209210
* @param[out] site_vec A vector of sinex::SiteAntenna instances, one
210211
* entry for each block line.
211212
* @return Anything other than zero denotes an error
212213
*/
213214
int parse_block_site_antenna(
214-
std::vector<sinex::SiteAntenna> &site_vec) noexcept;
215+
const std::vector<sinex::SiteId> &sites_vec,
216+
std::vector<sinex::SiteAntenna> &out_vec,
217+
const dso::datetime<dso::nanoseconds> from =
218+
dso::datetime<dso::nanoseconds>::min(),
219+
const dso::datetime<dso::nanoseconds> to =
220+
dso::datetime<dso::nanoseconds>::max()) noexcept;
215221

216222
/** @brief Get SOLUTION/ESTIMATE records for given sites.
217223
*

src/parse_site_antenna.cpp

+60-31
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,16 @@
44
constexpr int max_lines_in_block = 10000;
55

66
int dso::Sinex::parse_block_site_antenna(
7-
std::vector<sinex::SiteAntenna> &site_vec) noexcept {
7+
const std::vector<sinex::SiteId> &site_vec,
8+
std::vector<sinex::SiteAntenna> &out_vec,
9+
const dso::datetime<dso::nanoseconds> from,
10+
const dso::datetime<dso::nanoseconds> to) noexcept {
11+
12+
using sinex::details::ltrim_cpy;
13+
814
/* clear the vector */
9-
if (!site_vec.empty())
10-
site_vec.clear();
15+
if (!out_vec.empty())
16+
out_vec.clear();
1117

1218
/* go to SITE/ANTENNA block */
1319
if (goto_block("SITE/ANTENNA"))
@@ -32,34 +38,57 @@ int dso::Sinex::parse_block_site_antenna(
3238
if (!std::strncmp(line, "-SITE/ANTENNA", 14))
3339
break;
3440
if (*line != '*') { /* non-comment line */
35-
site_vec.emplace_back(sinex::SiteAntenna{});
36-
auto vecit = site_vec.end() - 1;
37-
38-
std::memcpy(vecit->site_code(), line + 1, 4);
39-
std::memcpy(vecit->point_code(), line + 6, 2);
40-
std::memcpy(vecit->soln_id(), line + 9, 4);
41-
try {
42-
vecit->m_obscode = dso::sinex::char_to_SinexObservationCode(line[14]);
43-
} catch (std::exception &) {
44-
fprintf(
45-
stderr,
46-
"[ERROR] Erronuous SINEX Observation Code \'%c\' (traceback: %s)\n",
47-
line[14], __func__);
48-
++error;
49-
}
50-
51-
error += sinex::parse_sinex_date(line + 16, m_data_start, vecit->m_start);
52-
error += sinex::parse_sinex_date(line + 29, m_data_stop, vecit->m_stop);
53-
if (error) {
54-
fprintf(
55-
stderr,
56-
"[ERROR] Failed to parse date from line: \"%s\" (traceback: %s)\n",
57-
line, __func__);
58-
}
59-
60-
std::memcpy(vecit->ant_type(), line + 42, 20);
61-
std::memcpy(vecit->ant_serial(), line + 63, 5);
62-
}
41+
42+
/* first check site name */
43+
auto it = std::find_if(
44+
site_vec.cbegin(), site_vec.cend(), [&](const sinex::SiteId &site) {
45+
return !std::strncmp(site.site_code(), line + 1, 4) &&
46+
!std::strncmp(site.point_code(), line + 6, 2);
47+
});
48+
49+
/* the station is in the list */
50+
if (it != site_vec.cend()) {
51+
52+
/* second, resolve time interval */
53+
dso::datetime<dso::nanoseconds> intrv_start, intrv_stop;
54+
error += sinex::parse_sinex_date(line + 16, m_data_start, intrv_start);
55+
error += sinex::parse_sinex_date(line + 29, m_data_stop, intrv_stop);
56+
if (error) {
57+
fprintf(stderr,
58+
"[ERROR] Failed to parse date from line: \"%s\" (traceback: "
59+
"%s)\n",
60+
line, __func__);
61+
}
62+
63+
/* if validity interval and antenna interval overlap */
64+
if (dso::intervals_overlap<
65+
dso::nanoseconds, dso::datetime_ranges::OverlapComparissonType::
66+
AllowEdgesOverlap>(
67+
intrv_start, intrv_stop, from, to)) {
68+
69+
out_vec.emplace_back(sinex::SiteAntenna{});
70+
auto vecit = out_vec.end() - 1;
71+
72+
ltrim_cpy(vecit->site_code(), line + 1, 4);
73+
ltrim_cpy(vecit->point_code(), line + 6, 2);
74+
ltrim_cpy(vecit->soln_id(), line + 9, 4);
75+
try {
76+
vecit->m_obscode =
77+
dso::sinex::char_to_SinexObservationCode(line[14]);
78+
} catch (std::exception &) {
79+
fprintf(
80+
stderr,
81+
"[ERROR] Erronuous SINEX Observation Code \'%c\' (traceback: "
82+
"%s)\n",
83+
line[14], __func__);
84+
++error;
85+
}
86+
87+
ltrim_cpy(vecit->ant_type(), line + 42, 20);
88+
ltrim_cpy(vecit->ant_serial(), line + 63, 5);
89+
} /* intervals overlap */
90+
} /* station in the list */
91+
} /* non-comment line */
6392
} /* end parsing block */
6493

6594
/* check for infinite loop */

test/CMakeLists.txt

+18
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,21 @@ target_link_libraries(test_site_eccentricity PRIVATE sinex)
2222
find_program(site_eccentricity.sh NAMES bash REQUIRED)
2323
add_test(NAME site_eccentricity
2424
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/site_eccentricity.sh $<TARGET_FILE:test_site_eccentricity> ${SNX})
25+
26+
add_executable(test_site_id_ndomes test_site_id_ndomes.cpp)
27+
target_link_libraries(test_site_id_ndomes PRIVATE sinex)
28+
find_program(site_id_ndomes.sh NAMES bash REQUIRED)
29+
add_test(NAME site_id_ndomes
30+
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/site_id_ndomes.sh $<TARGET_FILE:test_site_id_ndomes> ${SNX})
31+
32+
add_executable(test_site_id_wdomes test_site_id_wdomes.cpp)
33+
target_link_libraries(test_site_id_wdomes PRIVATE sinex)
34+
find_program(site_id_wdomes.sh NAMES bash REQUIRED)
35+
add_test(NAME site_id_wdomes
36+
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/site_id_wdomes.sh $<TARGET_FILE:test_site_id_ndomes> ${SNX})
37+
38+
add_executable(test_site_antenna test_site_antenna.cpp)
39+
target_link_libraries(test_site_antenna PRIVATE sinex)
40+
find_program(site_antenna.sh NAMES bash REQUIRED)
41+
add_test(NAME site_antenna
42+
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/site_antenna.sh $<TARGET_FILE:test_site_antenna> ${SNX})

0 commit comments

Comments
 (0)