source: ntrip/trunk/BNC/src/pppCrdFile.cpp@ 11096

Last change on this file since 11096 was 11096, checked in by stuerze, 21 hours ago

minor changes

File size: 6.0 KB
Line 
1
2// Part of BNC, a utility for retrieving decoding and
3// converting GNSS data streams from NTRIP broadcasters.
4//
5// Copyright (C) 2007
6// German Federal Agency for Cartography and Geodesy (BKG)
7// http://bkg.bund.de
8// Czech Technical University Prague, Department of Geodesy
9// http://www.fsv.cvut.cz
10//
11// Email: euref-ip@bkg.bund.de
12//
13// This program is free software; you can redistribute it and/or
14// modify it under the terms of the GNU General Public License
15// as published by the Free Software Foundation, version 2.
16//
17// This program is distributed in the hope that it will be useful,
18// but WITHOUT ANY WARRANTY; without even the implied warranty of
19// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20// GNU General Public License for more details.
21//
22// You should have received a copy of the GNU General Public License
23// along with this program; if not, write to the Free Software
24// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25
26/* -------------------------------------------------------------------------
27 * BKG NTRIP Client
28 * -------------------------------------------------------------------------
29 *
30 * Class: t_pppCrdFile
31 *
32 * Purpose: Read a priori coordinate file
33 *
34 * Author: L. Mervart
35 *
36 * Created: 29-Jul-2014
37 *
38 * Changes:
39 *
40 * -----------------------------------------------------------------------*/
41
42#include <cmath>
43#include <cstdlib>
44#include <fstream>
45#include <locale>
46#include <sstream>
47#include "pppCrdFile.h"
48#include "bncutils.h"
49
50using namespace std;
51using namespace BNC_PPP;
52
53// Convert a 'D,M,S' (degrees, minutes, seconds) token into decimal degrees;
54// the sign of D carries the hemisphere (negative == South/West).
55//////////////////////////////////////////////////////////////////////////////
56static double dmsToDeg(const string& dms) {
57 string str = dms;
58 for (string::iterator it = str.begin(); it != str.end(); ++it) {
59 if (*it == ',') *it = ' ';
60 }
61 istringstream in(str);
62 double d = 0.0, m = 0.0, s = 0.0;
63 in >> d >> m >> s;
64 double sign = (d < 0.0) ? -1.0 : 1.0;
65 return sign * (fabs(d) + m / 60.0 + s / 3600.0);
66}
67
68// Convert a number token independent of the process locale: atof() follows
69// LC_NUMERIC, which Qt sets from the environment, so with e.g. a German
70// locale "123.7785" would be read as 123.
71//////////////////////////////////////////////////////////////////////////////
72static double toDouble(const string& str) {
73 istringstream in(str);
74 in.imbue(locale::classic());
75 double value = 0.0;
76 in >> value;
77 return value;
78}
79
80//
81//////////////////////////////////////////////////////////////////////////////
82void t_pppCrdFile::readCrdFile(const string& fileName, vector<t_staInfo>& staInfoVec) {
83
84 staInfoVec.clear();
85
86 ifstream inFile(fileName.c_str());
87 while (inFile.good()) {
88 string line; getline(inFile,line);
89 stripWhiteSpace(line);
90 if ( line.empty() || line[0] == '#'|| line[0] == '!') {
91 continue;
92 }
93
94 istringstream in;
95
96 t_staInfo staInfo;
97
98 size_t q1 = line.find('"');
99 if (q1 != string::npos) {
100 size_t q2 = line.find('"', q1+1);
101 if (q2 == string::npos) {
102 continue;
103 }
104 staInfo._name = line.substr(q1+1, q2-q1-1);
105 in.str(line.substr(q2+1));
106 }
107 else {
108 in.str(line);
109 in >> staInfo._name;
110 }
111
112 // The a priori coordinate is given either as plain Cartesian 'X Y Z', or,
113 // if the line's first coordinate token is 'LAT:<D,M,S>', as geodetic
114 // 'LAT:<D,M,S> LON:<D,M,S> H:<height>' (converted to XYZ below).
115 streampos posBeforeCoord = in.tellg();
116 string firstCoordTok;
117 bool geodetic = false;
118 if (in >> firstCoordTok) {
119 geodetic = (firstCoordTok.compare(0, 4, "LAT:") == 0);
120 in.seekg(posBeforeCoord);
121 }
122 if (!geodetic) {
123 in >> staInfo._xyz(1) >> staInfo._xyz(2) >> staInfo._xyz(3);
124 }
125
126 // Optional keyword tokens, may appear in any order before the antenna
127 // eccentricity / name fields:
128 // - 'LAT:<D,M,S>', 'LON:<D,M,S>', 'H:<height>' (geodetic a priori coordinate)
129 // - 'EPOCH:<decimalYear>' (ITRF reference epoch of the coordinate)
130 // - 'VEL:<vx>,<vy>,<vz>' (ITRF velocity [m/year] of the coordinate)
131 double lat = 0.0, lon = 0.0, hgt = 0.0;
132 bool haveLat = false, haveLon = false, haveHgt = false;
133 while (!in.eof()) {
134 streampos posBeforeToken = in.tellg();
135 string token;
136 if (!(in >> token)) {
137 break;
138 }
139 if (token.compare(0, 4, "LAT:") == 0) {
140 lat = dmsToDeg(token.substr(4));
141 haveLat = true;
142 }
143 else if (token.compare(0, 4, "LON:") == 0) {
144 lon = dmsToDeg(token.substr(4));
145 haveLon = true;
146 }
147 else if (token.compare(0, 2, "H:") == 0) {
148 hgt = toDouble(token.substr(2));
149 haveHgt = true;
150 }
151 else if (token.compare(0, 6, "EPOCH:") == 0) {
152 staInfo._epoch = toDouble(token.substr(6));
153 }
154 else if (token.compare(0, 4, "VEL:") == 0) {
155 string velStr = token.substr(4);
156 for (string::iterator it = velStr.begin(); it != velStr.end(); ++it) {
157 if (*it == ',') *it = ' ';
158 }
159 istringstream velIn(velStr);
160 velIn >> staInfo._velocity(1) >> staInfo._velocity(2) >> staInfo._velocity(3);
161 }
162 else {
163 in.seekg(posBeforeToken);
164 break;
165 }
166 }
167
168 if (geodetic && haveLat && haveLon && haveHgt) {
169 double Ell[3] = { lat * M_PI / 180.0, lon * M_PI / 180.0, hgt };
170 double XYZ[3];
171 ell2xyz(Ell, XYZ);
172 staInfo._xyz(1) = XYZ[0];
173 staInfo._xyz(2) = XYZ[1];
174 staInfo._xyz(3) = XYZ[2];
175 }
176
177 if (!in.eof()) {
178 in >> staInfo._neuAnt(1) >> staInfo._neuAnt(2) >> staInfo._neuAnt(3);
179 }
180
181 if (!in.eof()) {
182 std::string hlp;
183 getline(in, hlp);
184 stripWhiteSpace(hlp);
185 staInfo._antenna.assign( hlp.substr(0,20));
186 hlp = hlp.erase(0, 20);
187 if (hlp.length()) {
188 stripWhiteSpace(hlp);
189 staInfo._receiver = hlp;
190 }
191 }
192
193 staInfoVec.push_back(staInfo);
194 }
195}
Note: See TracBrowser for help on using the repository browser.