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

Last change on this file since 11031 was 11027, checked in by stuerze, 2 weeks ago

Lat/Lon/Height is supperted as well as a priori coordinates

File size: 5.6 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 <sstream>
46#include "pppCrdFile.h"
47#include "bncutils.h"
48
49using namespace std;
50using namespace BNC_PPP;
51
52// Convert a 'D,M,S' (degrees, minutes, seconds) token into decimal degrees;
53// the sign of D carries the hemisphere (negative == South/West).
54//////////////////////////////////////////////////////////////////////////////
55static double dmsToDeg(const string& dms) {
56 string str = dms;
57 for (string::iterator it = str.begin(); it != str.end(); ++it) {
58 if (*it == ',') *it = ' ';
59 }
60 istringstream in(str);
61 double d = 0.0, m = 0.0, s = 0.0;
62 in >> d >> m >> s;
63 double sign = (d < 0.0) ? -1.0 : 1.0;
64 return sign * (fabs(d) + m / 60.0 + s / 3600.0);
65}
66
67//
68//////////////////////////////////////////////////////////////////////////////
69void t_pppCrdFile::readCrdFile(const string& fileName, vector<t_staInfo>& staInfoVec) {
70
71 staInfoVec.clear();
72
73 ifstream inFile(fileName.c_str());
74 while (inFile.good()) {
75 string line; getline(inFile,line);
76 stripWhiteSpace(line);
77 if ( line.empty() || line[0] == '#'|| line[0] == '!') {
78 continue;
79 }
80
81 istringstream in;
82
83 t_staInfo staInfo;
84
85 size_t q1 = line.find('"');
86 if (q1 != string::npos) {
87 size_t q2 = line.find('"', q1+1);
88 if (q2 == string::npos) {
89 continue;
90 }
91 staInfo._name = line.substr(q1+1, q2-q1-1);
92 in.str(line.substr(q2+1));
93 }
94 else {
95 in.str(line);
96 in >> staInfo._name;
97 }
98
99 // The a priori coordinate is given either as plain Cartesian 'X Y Z', or,
100 // if the line's first coordinate token is 'LAT:<D,M,S>', as geodetic
101 // 'LAT:<D,M,S> LON:<D,M,S> H:<height>' (converted to XYZ below).
102 streampos posBeforeCoord = in.tellg();
103 string firstCoordTok;
104 bool geodetic = false;
105 if (in >> firstCoordTok) {
106 geodetic = (firstCoordTok.compare(0, 4, "LAT:") == 0);
107 in.seekg(posBeforeCoord);
108 }
109 if (!geodetic) {
110 in >> staInfo._xyz(1) >> staInfo._xyz(2) >> staInfo._xyz(3);
111 }
112
113 // Optional keyword tokens, may appear in any order before the antenna
114 // eccentricity / name fields:
115 // - 'LAT:<D,M,S>', 'LON:<D,M,S>', 'H:<height>' (geodetic a priori coordinate)
116 // - 'EPOCH:<decimalYear>' (ITRF reference epoch of the coordinate)
117 // - 'VEL:<vx>,<vy>,<vz>' (ITRF velocity [m/year] of the coordinate)
118 double lat = 0.0, lon = 0.0, hgt = 0.0;
119 bool haveLat = false, haveLon = false, haveHgt = false;
120 while (!in.eof()) {
121 streampos posBeforeToken = in.tellg();
122 string token;
123 if (!(in >> token)) {
124 break;
125 }
126 if (token.compare(0, 4, "LAT:") == 0) {
127 lat = dmsToDeg(token.substr(4));
128 haveLat = true;
129 }
130 else if (token.compare(0, 4, "LON:") == 0) {
131 lon = dmsToDeg(token.substr(4));
132 haveLon = true;
133 }
134 else if (token.compare(0, 2, "H:") == 0) {
135 hgt = atof(token.substr(2).c_str());
136 haveHgt = true;
137 }
138 else if (token.compare(0, 6, "EPOCH:") == 0) {
139 staInfo._epoch = atof(token.substr(6).c_str());
140 }
141 else if (token.compare(0, 4, "VEL:") == 0) {
142 string velStr = token.substr(4);
143 for (string::iterator it = velStr.begin(); it != velStr.end(); ++it) {
144 if (*it == ',') *it = ' ';
145 }
146 istringstream velIn(velStr);
147 velIn >> staInfo._velocity(1) >> staInfo._velocity(2) >> staInfo._velocity(3);
148 }
149 else {
150 in.seekg(posBeforeToken);
151 break;
152 }
153 }
154
155 if (geodetic && haveLat && haveLon && haveHgt) {
156 double Ell[3] = { lat * M_PI / 180.0, lon * M_PI / 180.0, hgt };
157 double XYZ[3];
158 ell2xyz(Ell, XYZ);
159 staInfo._xyz(1) = XYZ[0];
160 staInfo._xyz(2) = XYZ[1];
161 staInfo._xyz(3) = XYZ[2];
162 }
163
164 if (!in.eof()) {
165 in >> staInfo._neuAnt(1) >> staInfo._neuAnt(2) >> staInfo._neuAnt(3);
166 }
167
168 if (!in.eof()) {
169 std::string hlp;
170 getline(in, hlp);
171 stripWhiteSpace(hlp);
172 staInfo._antenna.assign( hlp.substr(0,20));
173 hlp = hlp.erase(0, 20);
174 if (hlp.length()) {
175 stripWhiteSpace(hlp);
176 staInfo._receiver = hlp;
177 }
178 }
179
180 staInfoVec.push_back(staInfo);
181 }
182}
Note: See TracBrowser for help on using the repository browser.