1 //==============================================================================
2 //
3 //  This file is part of GPSTk, the GPS Toolkit.
4 //
5 //  The GPSTk 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 GPSTk 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 GPSTk; 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-2020, 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 
39 /**
40  * @file DCBDataReader.cpp
41  * Class to read DCB data from CODE.
42  */
43 
44 #include "DCBDataReader.hpp"
45 
46 using namespace std;
47 
48 namespace gpstk
49 {
50 
51       // Method to store load ocean tide harmonics data in this class'
52       // data map
loadData()53    void DCBDataReader::loadData()
54    {
55 
56       try
57       {
58          allDCB.satDCB.clear();
59          allDCB.gpsDCB.clear();
60          allDCB.glonassDCB.clear();
61 
62             // a buffer
63          string line;
64 
65             // read first line
66          formattedGetLine(line, true);
67 
68             // Let's skip 6 lines
69          for(int i=0; i<6; i++) formattedGetLine(line, true);
70 
71 
72             // Now, let's read data
73          while(1)
74          {
75             formattedGetLine(line, true);
76 
77             if(line.length() < 46) continue;
78 
79             string sysFlag = line.substr(0,1);
80 
81             int satPRN = StringUtils::asInt(line.substr(1,2));
82 
83             string station = StringUtils::strip(line.substr(6,4));
84 
85             const double dcbVal = StringUtils::asDouble(line.substr(26,9));
86             //const double dcbRms = StringUtils::asDouble(line.substr(38,9));
87 
88             if(station.length() < 4)       // this is satellite DCB data
89             {
90 
91                SatID sat;
92                if(sysFlag == "G")
93                {
94                   sat = SatID(satPRN,SatelliteSystem::GPS);
95                }
96                else if(sysFlag == "R")
97                {
98                   sat = SatID(satPRN,SatelliteSystem::Glonass);
99                }
100                else
101                {
102                   // Unexpected and we do nothing here
103 
104 
105                }
106 
107                allDCB.satDCB[sat] = dcbVal;
108 
109             }
110             else                           // this is receiver DCB data
111             {
112                if(sysFlag == "G")
113                {
114                   allDCB.gpsDCB[station] = dcbVal;
115                }
116                else if(sysFlag == "R")
117                {
118                   allDCB.glonassDCB[station] = dcbVal;
119                }
120                else
121                {
122                   // Unexpected and we do nothing here
123 
124                }
125             }
126 
127          }  // End of 'while(1)'
128 
129       }  // End of try block
130       catch (EndOfFile& e)
131       {
132 
133             // We should close this data stream before returning
134          (*this).close();
135 
136          return;
137       }
138       catch (...)
139       {
140 
141          // We should close this data stream before returning
142          (*this).close();
143 
144          return;
145 
146       }
147 
148 
149    }  // End of 'DCBDataReader::loadData()'
150 
151 
152 
153       // Method to open AND load DCB data file.
open(const char * fn)154    void DCBDataReader::open(const char* fn)
155    {
156 
157       // We need to be sure current data stream is closed
158       (*this).close();
159 
160       // Open data stream
161       FFTextStream::open(fn, std::ios::in);
162       loadData();
163 
164       return;
165 
166    }  // End of method 'DCBDataReader::open()'
167 
168 
169 
170       // Method to open AND load DCB data file. It doesn't
171       // clear data previously loaded.
open(const string & fn)172    void DCBDataReader::open(const string& fn)
173    {
174 
175       // We need to be sure current data stream is closed
176       (*this).close();
177 
178       // Open data stream
179       FFTextStream::open(fn.c_str(), std::ios::in);
180       loadData();
181 
182       return;
183    }  // End of method 'DCBDataReader::open()'
184 
185       // return P1-P2 or P1-C1 depend what you have loaded
getDCB(const SatID & sat)186    double DCBDataReader::getDCB(const SatID& sat)
187    {
188       return allDCB.satDCB[sat];
189    }
190 
191       // Get DCB data of a satellite
192       // return P1-P2 or P1-C1 depend what you have loaded
getDCB(const int & prn,const SatelliteSystem & system)193    double DCBDataReader::getDCB(const int& prn,
194       const SatelliteSystem& system)
195    {
196       SatID sat(prn,system);
197       return allDCB.satDCB[sat];
198    }
199 
200       // Get DCB data of aReceiver
201       // it return P1-P2
getDCB(const string & station,const SatelliteSystem & system)202    double DCBDataReader::getDCB(const string& station,
203       const SatelliteSystem& system)
204    {
205 
206       if(system == SatelliteSystem::GPS)
207       {
208          return allDCB.gpsDCB[station];
209       }
210       else if(system == SatelliteSystem::Glonass)
211       {
212          return allDCB.glonassDCB[station];
213       }
214       else
215       {
216             // Unexpected and return 0
217          return 0.0;
218       }
219 
220    }  // End of 'double DCBDataReader::getDCB(const string& station...'
221 
222 
223 
224 }  // End of namespace gpstk
225