AntexHeader.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 
40 
41 #include "AntexHeader.hpp"
42 #include "AntexStream.hpp"
43 #include "StringUtils.hpp"
44 
45 using namespace std;
46 using namespace gnsstk::StringUtils;
47 
48 namespace gnsstk
49 {
50  const string AntexHeader::versionString = "ANTEX VERSION / SYST";
51  const string AntexHeader::pcvTypeString = "PCV TYPE / REFANT";
52  const string AntexHeader::headerCommentString = "COMMENT";
53  const string AntexHeader::endOfHeaderString = "END OF HEADER";
54 
55  void AntexHeader::reallyPutRecord(FFStream& ffs) const
56  {
57  AntexStream &strm = dynamic_cast<AntexStream &>(ffs);
58 
59  strm.header = *this;
60 
61  unsigned long allValid;
62  if (version == 1.3 || version == 1.4)
63  {
64  allValid = allValid13;
65  }
66  else
67  {
68  FFStreamError err("Unknown Antex version: " + asString(version, 2));
69  err.addText("Make sure to set the version correctly.");
71  }
72 
73  if ((valid & allValid) != allValid)
74  {
75  FFStreamError err("Incomplete or invalid header.");
76  err.addText(
77  "Set all header valid bits for all of the available data.");
79  }
80 
81  try
82  {
83  WriteHeaderRecords(strm);
84  }
85  catch (FFStreamError& e)
86  {
87  GNSSTK_RETHROW(e);
88  }
89  catch (StringException& e)
90  {
91  GNSSTK_RETHROW(e);
92  }
93 
94  } // end AntexHeader::reallyPutRecord
95 
96  // this function writes all valid header records
97  void AntexHeader::WriteHeaderRecords(FFStream& ffs) const
98  {
99  AntexStream &strm = dynamic_cast<AntexStream &>(ffs);
100  string line;
101 
102  if ((valid & versionValid) | systemValid)
103  {
104  line = rightJustify(asString(version, 1), 8);
105  line += string(12, ' ');
106  line += system;
107  line = leftJustify(line, 60);
108  line += versionString;
109  strm << leftJustify(line, 80) << endl;
110  strm.lineNumber++;
111  }
112  if (valid & pcvTypeValid)
113  {
114  line = pcvType;
115  line += string(19, ' ');
116  line += leftJustify(refAntType, 20);
117  line += leftJustify(refAntSerNum, 20);
118  line += pcvTypeString;
119  strm << leftJustify(line, 80) << endl;
120  strm.lineNumber++;
121  }
122  if (valid & commentValid)
123  {
124  vector<string>::const_iterator itr = commentList.begin();
125  while (itr != commentList.end())
126  {
127  line = leftJustify((*itr), 60);
128  line += headerCommentString;
129  strm << leftJustify(line, 80) << endl;
130  strm.lineNumber++;
131  itr++;
132  }
133  }
134  if (valid & endValid)
135  {
136  line = string(60, ' ');
137  line += endOfHeaderString;
138  strm << leftJustify(line, 80) << endl;
139  strm.lineNumber++;
140  }
141  } // end AntexHeader::WriteHeaderRecords()
142 
143  // this function parses a single header record
144  void AntexHeader::ParseHeaderRecord(string& line)
145  {
146  string label(line, 60, 20);
147 
148  if (label == versionString)
149  {
150  version = asDouble(line.substr(0, 8));
151  system = line[20];
152  if (system != ' ' && system != 'G' && system != 'R' && system != 'E' &&
153  system != 'C' && system != 'M')
154  {
155  stringstream os;
156  os >> system;
157  FFStreamError e("Satellite system is invalid: " + os.str());
158  GNSSTK_THROW(e);
159  }
160  valid |= versionValid;
161  valid |= systemValid;
162  }
163  else if (label == pcvTypeString)
164  {
165  pcvType = line[0];
166  if (pcvType != 'A' && pcvType != 'R')
167  {
168  stringstream os;
169  os >> pcvType;
170  FFStreamError e("PCV type is invalid: " + os.str());
171  GNSSTK_THROW(e);
172  }
173  refAntType = line.substr(20, 20);
174  refAntSerNum = line.substr(40, 20);
175  valid |= pcvTypeValid;
176  }
177  else if (label == headerCommentString)
178  {
179  commentList.push_back(stripTrailing(line.substr(0, 60)));
180  valid |= commentValid;
181  }
182  else if (label == endOfHeaderString)
183  {
184  valid |= endValid;
185  }
186  else
187  {
188  FFStreamError e("Unidentified label: " + label);
189  GNSSTK_THROW(e);
190  }
191  } // end of AntexHeader::ParseHeaderRecord(string& line)
192 
193  // This function parses the entire header from the given stream
194  void AntexHeader::reallyGetRecord(FFStream& ffs)
195  {
196  AntexStream &strm = dynamic_cast<AntexStream &>(ffs);
197 
198  // if already read, just return
199  if (strm.headerRead == true)
200  {
201  return;
202  }
203 
204  /* since we're reading a new header, we need to reinitialize
205  all our list structures. all the other objects should be ok.
206  this also applies if we threw an exception the first time we read
207  the header and are now re-reading it. some of these could be full
208  and we need to empty them. */
209  commentList.clear();
210  valid = 0;
211 
212  string line;
213  while (!(valid & endValid))
214  {
215  strm.formattedGetLine(line);
216  stripTrailing(line);
217 
218  if (line.length() == 0)
219  {
220  continue;
221  }
222  else if (line.length() < 60 || line.length() > 80)
223  {
224  FFStreamError e("Invalid line length");
225  GNSSTK_THROW(e);
226  }
227 
228  try
229  {
230  ParseHeaderRecord(line);
231  }
232  catch (FFStreamError& e)
233  {
234  GNSSTK_RETHROW(e);
235  }
236 
237  } // end while(not end of header)
238 
239  unsigned long allValid;
240  if (version == 1.3 || version == 1.4)
241  {
242  allValid = allValid13;
243  }
244  else
245  {
246  FFStreamError e("Unknown or unsupported Antex version " +
247  asString(version));
248  GNSSTK_THROW(e);
249  }
250 
251  if ((allValid & valid) != allValid)
252  {
253  FFStreamError e("Incomplete or invalid header");
254  GNSSTK_THROW(e);
255  }
256 
257  // If we get here, we should have reached the end of header line
258  strm.header = *this;
259  strm.headerRead = true;
260 
261  } // end of reallyGetRecord()
262 
263  void AntexHeader::dump(ostream& s) const
264  {
265  s << "Dump of AntexHeader, version " << fixed << setprecision(1)
266  << version << " system " << system << endl;
267  s << "These are " << (pcvType == 'A' ? "absolute" : "relative")
268  << " phase center offsets.\n";
269  s << "Reference antenna: type " << refAntType << ", serial no. "
270  << refAntSerNum << endl;
271 
272  for (size_t i = 0; i < commentList.size(); i++)
273  {
274  if (i == 0)
275  {
276  s << "Comments:\n";
277  }
278  s << "Comment " << setw(2) << i + 1 << ": " << commentList[i] << endl;
279  }
280  s << "End of AntexHeader dump" << endl;
281  }
282 
283 } // namespace gnsstk
gnsstk::dump
void dump(vector< SatPass > &SatPassList, ostream &os, bool rev, bool dbug)
Definition: SatPassUtilities.cpp:59
gnsstk::FFStream
Definition: FFStream.hpp:119
StringUtils.hpp
gnsstk::FFTextStream::formattedGetLine
void formattedGetLine(std::string &line, const bool expectEOF=false)
Definition: FFTextStream.cpp:149
gnsstk::FFTextStream::lineNumber
unsigned int lineNumber
Definition: FFTextStream.hpp:98
gnsstk::AntexStream
This class reads an Antex files.
Definition: AntexStream.hpp:57
gnsstk::StringUtils::asString
std::string asString(IonexStoreStrategy e)
Convert a IonexStoreStrategy to a whitespace-free string name.
Definition: IonexStoreStrategy.cpp:46
AntexHeader.hpp
gnsstk
For Sinex::InputHistory.
Definition: BasicFramework.cpp:50
AntexStream.hpp
gnsstk::StringUtils::stripTrailing
std::string & stripTrailing(std::string &s, const std::string &aString, std::string::size_type num=std::string::npos)
Definition: StringUtils.hpp:1453
gnsstk::AntexStream::headerRead
bool headerRead
Whether or not the AntexHeader has been read.
Definition: AntexStream.hpp:85
example4.err
err
Definition: example4.py:126
version
string version(string("2.4 9/23/15 rev"))
example6.valid
valid
Definition: example6.py:20
gnsstk::StringUtils::asDouble
double asDouble(const std::string &s)
Definition: StringUtils.hpp:705
GNSSTK_RETHROW
#define GNSSTK_RETHROW(exc)
Definition: Exception.hpp:369
gnsstk::StringUtils
Definition: IonexStoreStrategy.cpp:44
gnsstk::StringUtils::rightJustify
std::string & rightJustify(std::string &s, const std::string::size_type length, const char pad=' ')
Definition: StringUtils.hpp:1557
std
Definition: Angle.hpp:142
gnsstk::StringUtils::leftJustify
std::string & leftJustify(std::string &s, const std::string::size_type length, const char pad=' ')
Definition: StringUtils.hpp:1582
GNSSTK_THROW
#define GNSSTK_THROW(exc)
Definition: Exception.hpp:366
gnsstk::AntexStream::header
AntexHeader header
The header for this file.
Definition: AntexStream.hpp:88


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