-
Notifications
You must be signed in to change notification settings - Fork 52
/
sp3.cc
100 lines (88 loc) · 2.27 KB
/
sp3.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include "sp3.hh"
#include <string>
#include <string.h>
#include <stdexcept>
#include <sstream>
#include <iostream>
using namespace std;
SP3Reader::SP3Reader(std::string_view fname)
{
d_fp = fopen(&fname[0], "r");
if(!d_fp)
throw runtime_error("Unable to open "+(string)fname+": "+strerror(errno));
}
SP3Reader::~SP3Reader()
{
if(d_fp)
fclose(d_fp);
}
bool SP3Reader::get(SP3Entry& entry)
{
char line[80];
struct tm tm;
while(fgets(line, sizeof(line), d_fp)) {
if(line[0]=='*') {
//0 1 2 3 4 5 6
//* 2019 9 17 1 0 0.00000000
std::stringstream ss(line);
std::string token;
int num = 0;
memset(&tm, 0, sizeof(tm));
while (std::getline(ss, token, ' ')) {
if(token.empty())
continue;
int val = atoi(token.c_str());
if(num == 1)
tm.tm_year = val - 1900;
else if(num==2)
tm.tm_mon = val - 1;
else if(num == 3)
tm.tm_mday = val;
else if(num == 4)
tm.tm_hour = val;
else if(num == 5)
tm.tm_min = val;
else if(num==6)
tm.tm_sec = val;
num++;
// cout<<"Token: "<<token<<endl;
}
d_time = timegm(&tm) - 18; // XXX leap second
}
else if(line[0]=='P') {
// 0 1 2 3 4
// PG01 -18824.158694 -8701.019206 16573.078969 -131.247183
std::stringstream ss(line);
std::string token;
int num = 0;
while (std::getline(ss, token, ' ')) {
if(token.empty())
continue;
if(!num) {
if(token[1]=='G')
entry.gnss = 0;
else if(token[1]=='E')
entry.gnss = 2;
else if(token[1]=='C')
entry.gnss = 3;
else
continue;
entry.sv = atoi(token.c_str()+2);
}
double val = atof(token.c_str());
if(num == 1)
entry.x = 1000.0*val;
if(num == 2)
entry.y = 1000.0*val;
if(num == 3)
entry.z = 1000.0*val;
if(num == 4)
entry.clockBias = 1000.0*val; // want nanoseconds
num++;
}
entry.t = d_time;
return true;
}
}
return false;
}