BLQDataReader.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 "BLQDataReader.hpp"
45 
46 
47 
48 namespace gnsstk
49 {
50 
51  // Method to store load ocean tide harmonics data in this class'
52  // data map
54  {
55 
56  // Counter of valid data lines
57  int row(0);
58 
59  // We will store here the station name
60  std::string nameString("");
61 
62  // Declare structure to store tide harmonics data
64 
65  // Do this until end-of-file reached or something else happens
66  while(1)
67  {
68 
69  try
70  {
71 
72  if(row>6)
73  {
74  // If row>6, all station harmonics are already read,
75  // so let's store tide data in data map
76  setData(nameString, data);
77 
78  // Clear harmonics data
79  data.harmonics.resize(6,11,0.0);
80 
81  // Reset counter to get data from an additional station
82  row = 0;
83  }
84 
85  std::string line;
86 
87  formattedGetLine(line, true);
88 
89  // If line is too long, we throw an exception
90  if (line.size()>255)
91  {
92  FFStreamError e("Line too long");
93  GNSSTK_THROW(e);
94  }
95 
96  // Let's find and strip comments, wherever they are
97  if( StringUtils::firstWord(line)[0] == '$' )
98  {
99  formattedGetLine(line, true);
100  }
101 
102  std::string::size_type idx = line.find('$');
103  if( !(idx == std::string::npos) )
104  {
105  line = line.substr(0, idx);
106  }
107 
108  // Remove trailing and leading blanks
109  line = StringUtils::strip(line);
110 
111  // Skip blank lines
112  if (line.size()==0)
113  {
114  continue;
115  }
116 
117  // Let's start to get data out of file
118  // If this is the first valid line, it contains station name
119  if (row==0)
120  {
121 
122  nameString =
124 
125  ++row;
126 
127  continue;
128 
129  }
130  else
131  {
132 
133  // 2nd to 7th valid lines contains tide harmonics
134  if ( (row>0) && (row<=6) )
135  {
136  for(int col=0; col<11; col++)
137  {
138  std::string value(StringUtils::stripFirstWord(line));
139  data.harmonics((row-1),col) = StringUtils::asDouble(value);
140  }
141  ++row;
142  continue;
143  }
144  }
145 
146  } // End of try block
147  catch (EndOfFile& e)
148  {
149 
150  // We should close this data stream before returning
151  (*this).close();
152 
153  return;
154  }
155  catch (...)
156  {
157 
158  // We should close this data stream before returning
159  (*this).close();
160 
161  return;
162 
163  }
164 
165  } // End of 'while(1)...'
166 
167  } // End of method 'BLQDataReader::loadData()'
168 
169 
170 
171  // Method to open AND load ocean tide harmonics data file. It doesn't
172  // clear data previously loaded.
173  void BLQDataReader::open(const char* fn)
174  {
175 
176  // We need to be sure current data stream is closed
177  (*this).close();
178 
179  // Open data stream
180  FFTextStream::open(fn, std::ios::in);
181  loadData();
182 
183  return;
184  } // End of method 'BLQDataReader::open()'
185 
186 
187 
188  // Method to open AND load ocean tide harmonics data file. It doesn't
189  // clear data previously loaded.
190  void BLQDataReader::open(const std::string& fn)
191  {
192 
193  // We need to be sure current data stream is closed
194  (*this).close();
195 
196  // Open data stream
197  FFTextStream::open(fn.c_str(), std::ios::in);
198  loadData();
199 
200  return;
201  } // End of method 'BLQDataReader::open()'
202 
203 
204 
205  /* Method to get the ocean tide harmonics corresponding to a
206  * given station.
207  *
208  * @param station Station name (case is NOT relevant).
209  *
210  * @return A Matrix<double> of siw rows and eleven columns
211  * containing tide harmonics M2, S2, N2, K2, K1, O1, P1, Q1, MF,
212  * MM and SSA for amplitudes (radial, west, south, in meters) and
213  * phases (radial, west, south, in degrees). If station is
214  * not found, this method will return a matrix full of zeros.
215  */
217  {
218 
219  // First, look if such station exist in data map
220  tideDataIt iter( OceanTidesData.find( StringUtils::upperCase(station) ) );
221  if ( iter != OceanTidesData.end() )
222  {
223  // if found, return corresponding harmonics matrix
224  return (*iter).second.harmonics;
225  }
226  else
227  {
228  // If not, return an empty harmonics matrix
229  Matrix<double> dummy(6,11,0.0);
230  return dummy;
231  };
232 
233  } // End of method 'BLQDataReader::getTideHarmonics()'
234 
235 
236 
237 } // End of namespace gnsstk
gnsstk::BLQDataReader::getTideHarmonics
virtual Matrix< double > getTideHarmonics(const std::string &station)
Definition: BLQDataReader.cpp:216
gnsstk::StringUtils::upperCase
std::string & upperCase(std::string &s)
Definition: StringUtils.hpp:2117
gnsstk::BLQDataReader::tideData
A structure used to store ocean tide harmonics data.
Definition: BLQDataReader.hpp:174
BLQDataReader.hpp
gnsstk::FFTextStream::formattedGetLine
void formattedGetLine(std::string &line, const bool expectEOF=false)
Definition: FFTextStream.cpp:149
gnsstk
For Sinex::InputHistory.
Definition: BasicFramework.cpp:50
gnsstk::BLQDataReader::tideDataIt
std::map< std::string, tideData >::const_iterator tideDataIt
Handy iterator type.
Definition: BLQDataReader.hpp:184
gnsstk::Matrix< double >
gnsstk::BLQDataReader::OceanTidesData
std::map< std::string, tideData > OceanTidesData
Map holding the information regarding ocean tide harmonics.
Definition: BLQDataReader.hpp:188
gnsstk::BLQDataReader::open
virtual void open(const char *fn)
Definition: BLQDataReader.cpp:173
gnsstk::StringUtils::stripFirstWord
std::string stripFirstWord(std::string &s, const char delimiter=' ')
Definition: StringUtils.hpp:2253
gnsstk::StringUtils::asDouble
double asDouble(const std::string &s)
Definition: StringUtils.hpp:705
example3.data
data
Definition: example3.py:22
gnsstk::StringUtils::firstWord
std::string firstWord(const std::string &s, const char delimiter=' ')
Definition: StringUtils.hpp:2138
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::FFTextStream::open
virtual void open(const char *fn, std::ios::openmode mode)
Overrides open to reset the line number.
Definition: FFTextStream.cpp:80
GNSSTK_THROW
#define GNSSTK_THROW(exc)
Definition: Exception.hpp:366
example5.fn
string fn
Definition: example5.py:10
gnsstk::BLQDataReader::setData
void setData(const std::string &stationName, const tideData &data)
Definition: BLQDataReader.hpp:197
gnsstk::BLQDataReader::loadData
virtual void loadData(void)
Definition: BLQDataReader.cpp:53


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