YumaData.cpp
Go to the documentation of this file.
1 //==============================================================================
2 //
3 // This file is part of GNSSTk, the ARL:UT GNSS Toolkit.
4 //
5 // The GNSSTk is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU Lesser General Public License as published
7 // by the Free Software Foundation; either version 3.0 of the License, or
8 // any later version.
9 //
10 // The GNSSTk is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with GNSSTk; if not, write to the Free Software Foundation,
17 // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
18 //
19 // This software was developed by Applied Research Laboratories at the
20 // University of Texas at Austin.
21 // Copyright 2004-2022, The Board of Regents of The University of Texas System
22 //
23 //==============================================================================
24 
25 //==============================================================================
26 //
27 // This software was developed by Applied Research Laboratories at the
28 // University of Texas at Austin, under contract to an agency or agencies
29 // within the U.S. Department of Defense. The U.S. Government retains all
30 // rights to use, duplicate, distribute, disclose, or release this software.
31 //
32 // Pursuant to DoD Directive 523024
33 //
34 // DISTRIBUTION STATEMENT A: This software has been approved for public
35 // release, distribution is unlimited.
36 //
37 //==============================================================================
38 
44 #include "StringUtils.hpp"
45 #include "GNSSconstants.hpp"
46 
47 #include "YumaData.hpp"
48 #include "YumaStream.hpp"
49 
50 
51 using namespace gnsstk::StringUtils;
52 using namespace std;
53 
54 namespace gnsstk
55 {
56  short YumaData::nearFullWeek = 0;
57 
58  const std::string YumaData::sID = "ID:";
59  const std::string YumaData::sHlth = "Health:";
60  const std::string YumaData::sEcc = "Eccentricity:";
61  const std::string YumaData::sTOA = "Time of Applicability(s):";
62  const std::string YumaData::sOrbI = "Orbital Inclination(rad):";
63  const std::string YumaData::sRRA = "Rate of Right Ascen(r/s):";
64  const std::string YumaData::sSqrA = "SQRT(A) (m 1/2):";
65  const std::string YumaData::sRtAs = "Right Ascen at Week(rad):";
66  const std::string YumaData::sArgP = "Argument of Perigee(rad):";
67  const std::string YumaData::sMnAn = "Mean Anom(rad):";
68  const std::string YumaData::sAf0 = "Af0(s):";
69  const std::string YumaData::sAf1 = "Af1(s/s):";
70  const std::string YumaData::sweek = "week:";
71 
72  // NOTE: It is impractical to EXACTLY produce the ICD-GPS-240
73  // Yuma almanac format in C++. The format includes scientific
74  // format feature that work in FORTRAN but are not supported by
75  // the C++ standard. Specifically,
76  // 1.) three-digit exponents when they are not required, and
77  // 2.) the leading character is always zero
78  // (i.e., the value is always beween -1 and +1).
79  // The following will produce a something "very close" to the
80  // Yuma format that will be successfully read by the reallyGetRecord
81  // parser.
83  {
84  YumaStream& strm = dynamic_cast<YumaStream&>(ffs);
85 
86  const int width=27;
87  strm.setf(ios::fixed, ios::floatfield);
88  strm.precision(0);
89  strm << right
90  << "******** Week" << setw(5) << (week % 1024)
91  << " almanac for PRN-" << setfill('0') << setw(2) << PRN << setfill(' ')
92  << " ********" << endl;
93 
94  strm << left
95  << setw(width) << sID << " "
96  << right
97  << setfill('0') << setw(2) << PRN
98  << setfill(' ') << endl;
99 
100  strm << left
101  << setw(width) << sHlth << " "
102  << right
103  << setfill('0') << setw(3) << SV_health
104  << setfill(' ') << endl;
105 
106  strm.setf(ios::scientific, ios::floatfield);
107  strm.setf(ios_base::uppercase);
108  strm.precision(10);
109  strm << left
110  << setw(width) << sEcc
111  << right
112  << setw(19) << ecc << endl;
113 
114  strm.setf(ios::fixed, ios::floatfield);
115  strm.precision(6);
116  strm << left
117  << setw(width) << sTOA << " "
118  << setw(6) << Toa << endl;
119 
120  strm.setf(ios::scientific, ios::floatfield);
121  strm.precision(10);
122  strm << left << setw(width) << sOrbI << right << setw(19) << i_total << endl;
123  strm << left << setw(width) << sRRA << right << setw(19) << OMEGAdot << endl;
124 
125  strm.setf(ios::fixed, ios::floatfield);
126  strm.precision(6);
127  strm << left << setw(width) << sSqrA << " "
128  << setw(11) << Ahalf << endl;
129 
130  strm.setf(ios::scientific, ios::floatfield);
131  strm.precision(10);
132  strm << left << setw(width) << sRtAs << right << setw(19) << OMEGA0 << endl;
133 
134  strm.setf(ios::fixed, ios::floatfield);
135  strm.precision(9);
136  strm << left << setw(width) << sArgP << " "
137  << right
138  << setw(12) << w << endl;
139 
140  strm.setf(ios::scientific, ios::floatfield);
141  strm.precision(10);
142  strm << left << setw(width) << sMnAn << right << setw(19) << M0 << endl;
143  strm << left << setw(width) << sAf0 << right << setw(19) << AF0 << endl;
144  strm << left << setw(width) << sAf1 << right << setw(19) << AF1 << endl;
145 
146  strm.setf(ios::fixed, ios::floatfield);
147  strm.precision(4);
148  strm << left << setw(width) << sweek << " "
149  << setw(4) << week << endl;
150  strm << endl;
151  } // end YumaData::reallyPutRecord
152 
153 
154  string YumaData::lineParser(const string& line, const string& s) const
155  {
156  const int i = line.find_first_of(":");
157 
158  // Gotta have a colon or the format is wrong
159  if (i == (int)string::npos)
160  GNSSTK_THROW(FFStreamError("Format error in YumaData"));
161 
162  // Only compare the first five characters since some files differ after that
163  const int w = std::min(5, std::min(i, (int)s.size()));
164  if (line.substr(0,w) != s.substr(0,w))
165  GNSSTK_THROW(FFStreamError("Format error in YumaData"));
166 
167  return stripLeading(line.substr(i+1), " ");
168  }
169 
170 
172  {
173  YumaStream& strm = dynamic_cast<YumaStream&>(ffs);
174 
175  string line;
176 
177  xmit_time = 0;
178  // Find next header line.
179  // We don't need the header line as we will get all the information from the others
180  bool found = false;
181  unsigned lineCount = 0;
182  while (!found)
183  {
184  strm.formattedGetLine(line, true);
185  if (line.substr(0,2).compare("**")==0) found = true;
186  lineCount++;
187  // If we don't find a header within 14 lines (which is the length
188  // of a Yuma record) assume we will not find one.
189  if (!found && lineCount>14)
190  {
191  FFStreamError exc("Could not find Yuma record.");
192  GNSSTK_THROW(exc);
193  }
194  }
195 
196  //Second Line - PRN
197  strm.formattedGetLine(line, true);
198  PRN = asInt(lineParser(line, sID));
199 
200  //Third Line - Satellite Health
201  strm.formattedGetLine(line, true);
202  SV_health = asInt(lineParser(line, sHlth));
203 
204  //Fourth Line - Eccentricity
205  strm.formattedGetLine(line, true);
206  ecc = asDouble(lineParser(line, sEcc));
207 
208  //Fifth Line - Time of Applicability
209  strm.formattedGetLine(line, true);
210  Toa = (long) asDouble(lineParser(line, sTOA));
211 
212  //Sixth Line - Orbital Inclination
213  strm.formattedGetLine(line, true);
214  i_total = asDouble(lineParser(line, sOrbI));
215  i_offset = i_total - 54.0 * (gnsstk::PI / 180.0);
216 
217  //Seventh Line - Rate of Right Ascen
218  strm.formattedGetLine(line, true);
219  OMEGAdot = asDouble(lineParser(line, sRRA));
220 
221  //Eigth Line - SqrtA
222  strm.formattedGetLine(line, true);
223  Ahalf = asDouble(lineParser(line, sSqrA));
224 
225  //Ninth Line - Right Ascen at Week
226  strm.formattedGetLine(line, true);
227  OMEGA0 = asDouble(lineParser(line, sRtAs));
228 
229  //Tenth Line - Argument of Perigee
230  strm.formattedGetLine(line, true);
231  w = asDouble(lineParser(line, sArgP));
232 
233  //Eleventh Line - Mean Anomaly
234  strm.formattedGetLine(line, true);
235  M0 = asDouble(lineParser(line, sMnAn));
236 
237  //Twelfth Line - Af0
238  strm.formattedGetLine(line, true);
239  AF0 = asDouble(lineParser(line, sAf0));
240 
241  //Thirteenth Line - Af1
242  strm.formattedGetLine(line, true);
243  AF1 = asDouble(lineParser(line, sAf1));
244 
245  //Fourteenth Line - week
246  // Its unclear whether this is a full week or week % 1024
247  strm.formattedGetLine(line, true);
248  week = asInt(lineParser(line, sweek));
249 
250  if (nearFullWeek > 0)
251  {
252  // In case a full week is provided.
253  week %= 1024;
254  week += (nearFullWeek / 1024) * 1024;
255  short diff = nearFullWeek - week;
256  if (diff > 512)
257  week += 512;
258  else if(diff < -512)
259  week -= 512;
260  }
261 
262  } // end of reallyGetRecord()
263 
264  void YumaData::dump(ostream& s) const
265  {
266  cout << "PRN = " << PRN << endl;
267  cout << "week = " << week << endl;
268  cout << "SV_health = " << SV_health << endl;
269  cout << "ecc = " << ecc << endl;
270  cout << "Toa = " << Toa << endl;
271  cout << "i_offset = " << i_offset << endl;
272  cout << "OMEGAdot = " << OMEGAdot << endl;
273  cout << "Ahalf = " << Ahalf << endl;
274  cout << "OMEGA0 = " << OMEGA0 << endl;
275  cout << "w = " << w << endl;
276  cout << "M0 = " << M0 << endl;
277  cout << "AF0 = " << AF0 << endl;
278  cout << "AF1 = " << AF1 << endl;
279  cout << "xmit_time = " << xmit_time << endl;
280 
281  } // end of dump()
282 
283  YumaData::operator AlmOrbit() const
284  {
285  AlmOrbit ao(PRN, ecc,i_offset, OMEGAdot, Ahalf, OMEGA0,
286  w, M0, AF0, AF1, Toa, xmit_time, week, SV_health);
287 
288  return ao;
289 
290  } // end of AlmOrbit()
291 
292 
293 } // namespace
gnsstk::YumaData::sHlth
static const GNSSTK_EXPORT std::string sHlth
Definition: YumaData.hpp:86
gnsstk::StringUtils::asInt
long asInt(const std::string &s)
Definition: StringUtils.hpp:713
gnsstk::YumaData::sAf0
static const GNSSTK_EXPORT std::string sAf0
Definition: YumaData.hpp:95
gnsstk::YumaData::sRRA
static const GNSSTK_EXPORT std::string sRRA
Definition: YumaData.hpp:90
gnsstk::FFStream
Definition: FFStream.hpp:119
StringUtils.hpp
gnsstk::YumaData::sMnAn
static const GNSSTK_EXPORT std::string sMnAn
Definition: YumaData.hpp:94
gnsstk::FFTextStream::formattedGetLine
void formattedGetLine(std::string &line, const bool expectEOF=false)
Definition: FFTextStream.cpp:149
gnsstk::YumaData::sOrbI
static const GNSSTK_EXPORT std::string sOrbI
Definition: YumaData.hpp:89
gnsstk::PI
const double PI
GPS value of PI; also specified by GAL.
Definition: GNSSconstants.hpp:62
gnsstk::YumaData::dump
virtual void dump(std::ostream &s) const
Definition: YumaData.cpp:264
GNSSconstants.hpp
gnsstk::YumaData::nearFullWeek
static GNSSTK_EXPORT short nearFullWeek
Definition: YumaData.hpp:83
gnsstk
For Sinex::InputHistory.
Definition: BasicFramework.cpp:50
gnsstk::StringUtils::stripLeading
std::string & stripLeading(std::string &s, const std::string &aString, std::string::size_type num=std::string::npos)
Definition: StringUtils.hpp:1426
YumaData.hpp
gnsstk::YumaData::lineParser
std::string lineParser(const std::string &line, const std::string &s) const
Definition: YumaData.cpp:154
gnsstk::YumaData::sweek
static const GNSSTK_EXPORT std::string sweek
Definition: YumaData.hpp:97
YumaStream.hpp
gnsstk::YumaData::reallyPutRecord
void reallyPutRecord(FFStream &s) const
Definition: YumaData.cpp:82
gnsstk::YumaData::sRtAs
static const GNSSTK_EXPORT std::string sRtAs
Definition: YumaData.hpp:92
gnsstk::min
T min(const SparseMatrix< T > &SM)
Maximum element - return 0 if empty.
Definition: SparseMatrix.hpp:858
gnsstk::YumaData::sEcc
static const GNSSTK_EXPORT std::string sEcc
Definition: YumaData.hpp:87
gnsstk::StringUtils::asDouble
double asDouble(const std::string &s)
Definition: StringUtils.hpp:705
gnsstk::YumaStream
Definition: YumaStream.hpp:65
gnsstk::StringUtils
Definition: IonexStoreStrategy.cpp:44
gnsstk::YumaData::sID
static const GNSSTK_EXPORT std::string sID
Definition: YumaData.hpp:85
gnsstk::YumaData::sSqrA
static const GNSSTK_EXPORT std::string sSqrA
Definition: YumaData.hpp:91
std
Definition: Angle.hpp:142
gnsstk::YumaData::reallyGetRecord
virtual void reallyGetRecord(FFStream &s)
Definition: YumaData.cpp:171
gnsstk::YumaData::sArgP
static const GNSSTK_EXPORT std::string sArgP
Definition: YumaData.hpp:93
gnsstk::YumaData::sTOA
static const GNSSTK_EXPORT std::string sTOA
Definition: YumaData.hpp:88
GNSSTK_THROW
#define GNSSTK_THROW(exc)
Definition: Exception.hpp:366
gnsstk::YumaData::sAf1
static const GNSSTK_EXPORT std::string sAf1
Definition: YumaData.hpp:96
gnsstk::AlmOrbit
Definition: AlmOrbit.hpp:59


gnsstk
Author(s):
autogenerated on Wed Oct 25 2023 02:40:42