SatDataReader.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 "SatDataReader.hpp"
45 #include "TimeString.hpp"
46 
47 using namespace std;
48 
49 namespace gnsstk
50 {
51 
52  // Method to store satellite data in this class' data map
53  void SatDataReader::loadData(void)
54  {
55 
56  // Do this until end-of-file reached or something else happens
57  while(1)
58  {
59  try
60  {
61  std::string line;
62 
63  formattedGetLine(line, true);
64 
65  // If line is too long, we throw an exception
66  if (line.size()>255)
67  {
68  FFStreamError e("Line too long");
69  GNSSTK_THROW(e);
70  }
71 
72  // Let's find and strip comments, wherever they are
73  if( StringUtils::firstWord(line)[0] == '#' )
74  {
75  formattedGetLine(line, true);
76  }
77 
78  std::string::size_type idx = line.find('#');
79  if( !(idx == std::string::npos) )
80  {
81  line = line.substr(0, idx);
82  }
83 
84  // We erase the header (first line)
85  if( StringUtils::firstWord(line) == "Launch" )
86  {
87  formattedGetLine(line, true);
88  }
89 
90  // Remove trailing and leading blanks
91  line = StringUtils::strip(line);
92 
93  // Skip blank lines
94  if (line.size()==0)
95  {
96  continue;
97  }
98 
99  // Let's start to get data out of file
100  // Launch date
101  string ldate(StringUtils::stripFirstWord(line));
102  // Deactivation date
103  string ddate(StringUtils::stripFirstWord(line));
104  // GPS number
105  string gnumber(StringUtils::stripFirstWord(line));
106  // PRN number
107  string prn(StringUtils::stripFirstWord(line));
108  // Block tipe
109  string block(StringUtils::upperCase(
111 
112  // Get satellite id. If it doesn't fit GPS or Glonass, it is
113  // marked as unknown
114  SatID sat(StringUtils::asInt(prn),SatelliteSystem::Unknown);
115  // Let's identify satellite system
116  if(block[0] == 'I')
117  {
118  sat.system = SatelliteSystem::GPS;
119  }
120  else
121  {
122  if (block.substr(0, 3) == "GLO")
123  {
124  sat.system = SatelliteSystem::Glonass;
125  }
126  }
127 
128  // Declare the structure to store data
130 
131  data.block = block;
132  data.gpsNumber = StringUtils::asInt(gnumber);
133 
134  // Get launch date in a proper format
135  if(ldate[0] != '0')
136  {
137  ldate = StringUtils::translate(ldate, "-", " ");
138  scanTime(data.launchDate, ldate, "%Y %m %d");
139  }
140 
141  // Get deactivation date in a proper format
142  if(ddate[0] != '0')
143  {
144  ddate = StringUtils::translate(ddate, "-", " ");
145  scanTime(data.deactivationDate, ddate, "%Y %m %d");
146  }
147 
148  // It's not a good way!!!
149  data.launchDate.setTimeSystem(TimeSystem::Any);
150  data.deactivationDate.setTimeSystem(TimeSystem::Any);
151 
152  // Insert data in data map
153  setData(sat, data);
154 
155  } // End of try block
156  catch (EndOfFile& e)
157  {
158  // Close this data stream
159  (*this).close();
160 
161  return;
162  }
163  catch (...)
164  {
165  // Close this data stream
166  (*this).close();
167 
168  return;
169  }
170 
171  } // End of while(1)
172 
173  } // End of method 'SatDataReader::loadData()'
174 
175 
176 
177  // Method to open AND load satellite data file.
178  void SatDataReader::open(const char* fn)
179  {
180 
181  // We need to be sure current data stream is closed
182  (*this).close();
183 
184  // Open data stream
185  FFTextStream::open(fn, std::ios::in);
186 
187  // Load data
188  loadData();
189 
190  return;
191 
192  } // End of method 'SatDataReader::open()'
193 
194 
195  // Method to open AND load satellite data file.
196  void SatDataReader::open(const std::string& fn)
197  {
198 
199  // We need to be sure current data stream is closed
200  (*this).close();
201 
202  // Open data stream
203  FFTextStream::open(fn.c_str(), std::ios::in);
204 
205  // Load data
206  loadData();
207 
208  return;
209 
210  } // End of method 'SatDataReader::open()'
211 
212 
213 
214  /* Method to get the block type of a given SV at a given epoch.
215  *
216  * @param sat Satellite ID.
217  * @param epoch Epoch of interest.
218  *
219  * @return String containing satellite's block. If satellite is
220  * not found or epoch is out of proper launch/deactivation bounds,
221  * this method will return an empty string.
222  */
223  string SatDataReader::getBlock(const SatID& sat,
224  const CommonTime& epoch) const
225  {
226 
227  // Create a pair of range belonging to this SatID
228  pair<satDataIt, satDataIt> range = SatelliteData.equal_range(sat);
229 
230  // If SatID is not found, an empty string is returned
231  if(range.first == range.second)
232  {
233  return "";
234  }
235 
236  // Declare an iterator to travel in this range
237  satDataIt iter(range.first);
238 
239  // If this epoch is before launch date, return an empty string
240  if( (*iter).second.launchDate > epoch )
241  {
242  return "";
243  }
244 
245  // Increment iterator "iter" if we are not yet at proper epoch range
246  while( (*iter).second.deactivationDate < epoch )
247  {
248  ++iter;
249  }
250 
251  // Test if epoch is after corresponding launch date
252  if( (*iter).second.launchDate > epoch )
253  {
254  return "";
255  }
256 
257 
258  return ((*iter).second.block);
259 
260  } // End of method 'SatDataReader::getBlock()'
261 
262 
263 
264  /* Method to get the GPS number of a given SV at a given epoch.
265  *
266  * @param sat Satellite ID.
267  * @param epoch Epoch of interest.
268  *
269  * @return Integer containing satellite's block. If satellite is
270  * not found or epoch is out of proper launch/deactivation bounds,
271  * this method will return -1.
272  */
273  int SatDataReader::getGPSNumber(const SatID& sat,
274  const CommonTime& epoch) const
275  {
276 
277  // Create a pair of range belonging to this SatID
278  pair<satDataIt, satDataIt> range = SatelliteData.equal_range(sat);
279 
280  // If SatID is not found, -1 is returned
281  if(range.first == range.second)
282  {
283  return -1;
284  }
285 
286  // Declare an iterator to travel in this range
287  satDataIt iter(range.first);
288 
289  // If this epoch is before launch date, return -1
290  if( (*iter).second.launchDate > epoch )
291  {
292  return -1;
293  }
294 
295  // Increment iterator "iter" if we are not yet at proper epoch range
296  while( (*iter).second.deactivationDate < epoch )
297  {
298  ++iter;
299  }
300 
301  // Test if epoch is after corresponding launch date
302  if( (*iter).second.launchDate > epoch )
303  {
304  return -1;
305  }
306 
307 
308  return ((*iter).second.gpsNumber);
309 
310  } // End of method 'SatDataReader::getGPSNumber()'
311 
312 
313 
314  /* Method to get the launch date of a given SV.
315  *
316  * @param sat Satellite ID.
317  * @param epoch Epoch of interest.
318  *
319  * @return CommonTime object containing satellite's launch date. If
320  * satellite is not found or epoch is out of proper launch/deactivation
321  * bounds, this method will return CommonTime::END_OF_TIME.
322  */
323  CommonTime SatDataReader::getLaunchDate(const SatID& sat,
324  const CommonTime& epoch) const
325  {
326 
327  // Create a pair of range belonging to this SatID
328  pair<satDataIt, satDataIt> range = SatelliteData.equal_range(sat);
329 
330  // If SatID is not found, CommonTime::END_OF_TIME is returned
331  if(range.first == range.second)
332  {
334  }
335 
336  // Declare an iterator to travel in this range
337  satDataIt iter(range.first);
338 
339  // If this epoch is before launch date, return CommonTime::END_OF_TIME
340  if( (*iter).second.launchDate > epoch )
341  {
343  }
344 
345  // Increment iterator "iter" if we are not yet at proper epoch range
346  while( (*iter).second.deactivationDate < epoch )
347  {
348  ++iter;
349  }
350 
351  // Test if epoch is after corresponding launch date
352  if( (*iter).second.launchDate > epoch )
353  {
355  }
356 
357  return ((*iter).second.launchDate);
358 
359  } // End of method 'SatDataReader::getLaunchDate()'
360 
361 
362 
363  /* Method to get the deactivation date of a given SV.
364  *
365  * @param sat Satellite ID.
366  * @param epoch Epoch of interest.
367  *
368  * @return CommonTime object containing satellite's deactivation date. If
369  * satellite is not found, epoch is out of proper launch/deactivation
370  * bounds or satellite is still active, this method will return
371  * CommonTime::BEGINNING_OF_TIME.
372  */
373  CommonTime SatDataReader::getDeactivationDate(const SatID& sat,
374  const CommonTime& epoch) const
375  {
376 
377  // Create a pair of range belonging to this SatID
378  pair<satDataIt, satDataIt> range = SatelliteData.equal_range(sat);
379 
380  // If SatID is not found, CommonTime::BEGINNING_OF_TIME is returned
381  if(range.first == range.second)
382  {
384  }
385 
386  // Declare an iterator to travel in this range
387  satDataIt iter(range.first);
388 
389  // If this epoch is before launch date, return BEGINNING_OF_TIME
390  if( (*iter).second.launchDate > epoch )
391  {
393  }
394 
395  // Increment iterator "iter" if we are not yet at proper epoch range
396  while( (*iter).second.deactivationDate < epoch )
397  {
398  ++iter;
399  }
400 
401  // Test if epoch is after corresponding launch date
402  if( (*iter).second.launchDate > epoch )
403  {
405  }
406 
407  return ((*iter).second.deactivationDate);
408 
409  } // End of method 'SatDataReader::getDeactivationDate()'
410 
411 
412 
413 } // End of namespace gnsstk
gnsstk::StringUtils::upperCase
std::string & upperCase(std::string &s)
Definition: StringUtils.hpp:2117
gnsstk::StringUtils::asInt
long asInt(const std::string &s)
Definition: StringUtils.hpp:713
gnsstk::scanTime
void scanTime(TimeTag &btime, const string &str, const string &fmt)
Definition: TimeString.cpp:93
gnsstk::BEGINNING_OF_TIME
const Epoch BEGINNING_OF_TIME(CommonTime::BEGINNING_OF_TIME)
Earliest representable Epoch.
gnsstk::SatID
Definition: SatID.hpp:89
gnsstk
For Sinex::InputHistory.
Definition: BasicFramework.cpp:50
SatDataReader.hpp
gnsstk::CommonTime
Definition: CommonTime.hpp:84
example5.epoch
epoch
Definition: example5.py:24
gnsstk::StringUtils::stripFirstWord
std::string stripFirstWord(std::string &s, const char delimiter=' ')
Definition: StringUtils.hpp:2253
gnsstk::END_OF_TIME
const Epoch END_OF_TIME(CommonTime::END_OF_TIME)
Latest Representable Epoch.
gnsstk::SatDataReader::satDataIt
std::multimap< SatID, svData >::const_iterator satDataIt
Handy iterator type.
Definition: SatDataReader.hpp:214
gnsstk::SatID::system
SatelliteSystem system
System for this satellite.
Definition: SatID.hpp:156
example3.data
data
Definition: example3.py:22
std
Definition: Angle.hpp:142
gnsstk::StringUtils::firstWord
std::string firstWord(const std::string &s, const char delimiter=' ')
Definition: StringUtils.hpp:2138
gnsstk::range
double range(const Position &A, const Position &B)
Definition: Position.cpp:1273
gnsstk::StringUtils::strip
std::string & strip(std::string &s, const std::string &aString, std::string::size_type num=std::string::npos)
Definition: StringUtils.hpp:1482
GNSSTK_THROW
#define GNSSTK_THROW(exc)
Definition: Exception.hpp:366
gnsstk::SatDataReader::svData
A structure used to store satellite data.
Definition: SatDataReader.hpp:198
example5.fn
string fn
Definition: example5.py:10
TimeString.hpp
gnsstk::StringUtils::translate
std::string translate(const std::string &aString, const std::string &inputChars, const std::string &outputChars, const char pad=' ')
Definition: StringUtils.hpp:1491


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