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 DataOutput.cpp
41  * Output intermediate data to files for program DDBase.
42  */
43 
44 //------------------------------------------------------------------------------------
45 // TD DataOutput.cpp error msg for failure to open output files
46 // TD DataOutput.cpp add clock polynomial Evaluate(tt) to CLK output
47 
48 //------------------------------------------------------------------------------------
49 // includes
50 // system
51 #include <fstream>
52 
53 // GPSTk
54 
55 // DDBase
56 #include "DDBase.hpp"
57 #include "CommandInput.hpp"
58 #include "format.hpp"
59 #include "TimeString.hpp"
60 
61 //------------------------------------------------------------------------------------
62 using namespace std;
63 using namespace gpstk;
64 
65 //------------------------------------------------------------------------------------
66 // prototypes -- this module only
67 
68 //------------------------------------------------------------------------------------
69 // called from DDBase.cpp
OutputRawData(void)70 int OutputRawData(void)
71 {
72 try {
73    if(CI.Verbose) oflog << "BEGIN OutputRawData()" << endl;
74 
75    if(CI.OutputRawFile.empty()) return 0;
76 
77    size_t i;
78    CommonTime tt;
79    map<string,Station>::const_iterator it;
80    map<GSatID,RawData>::const_iterator jt;
81    format f133(13,3),f52(5,2);
82 
83       // open an output file for RAW data
84    ofstream rawofs;
85    rawofs.open(CI.OutputRawFile.c_str(),ios::out);
86    if(rawofs.is_open()) {
87       oflog << "Opened file " << CI.OutputRawFile << " for raw data output.." << endl;
88       rawofs << "# " << Title << endl;
89       rawofs << "RAW site sat week   sec_wk   count    L1_cyc        L2_cyc"
90          << "          P1_m          P2_m          ER_m      EL    AZ\n";
91    }
92    else {
93       // TD error msg
94       return -1;
95    }
96 
97       // loop over stations
98    for(it=Stations.begin(); it != Stations.end(); it++) {
99 
100          // loop over satellites
101       for(jt=it->second.RawDataBuffers.begin();
102           jt != it->second.RawDataBuffers.end(); jt++) {
103 
104             // loop over epochs
105          for(i=0; i<jt->second.count.size(); i++) {
106 
107             tt = FirstEpoch + jt->second.count[i]*CI.DataInterval;
108 
109             rawofs << "RAW " << it->first << " " << jt->first << " "
110                << printTime(tt,"%4F %10.3g")
111                << " " << setw(5) << jt->second.count[i]
112                << " " << f133 << jt->second.L1[i]
113                << " " << f133 << jt->second.L2[i]
114                << " " << f133 << jt->second.P1[i]
115                << " " << f133 << jt->second.P2[i]
116                << " " << f133 << jt->second.ER[i]
117                << " " << f52 << jt->second.elev[i]
118                << " " << f52 << jt->second.az[i]
119                << endl;
120 
121          }  // end loop over epochs
122 
123       }  // loop over satellites
124 
125    }  // loop over stations
126 
127       // close output file
128    rawofs.close();
129 
130    return 0;
131 }
132 catch(Exception& e) { GPSTK_RETHROW(e); }
133 catch(std::exception& e) { Exception E("std except: "+string(e.what())); GPSTK_THROW(E); }
134 catch(...) { Exception e("Unknown exception"); GPSTK_THROW(e); }
135 }   // end OutputRawData()
136 
137 //------------------------------------------------------------------------------------
138 // called from EditDDs.cpp
OutputRawDData(const DDid & ddid,const DDData & dddata,const vector<int> & mark)139 int OutputRawDData(const DDid& ddid, const DDData& dddata, const vector<int>& mark)
140 {
141 try {
142    bool TripleOut=true;                      // output triple differences as well
143    if(CI.OutputRawDDFile.empty()) return 0;
144 
145    static ofstream rddofs;
146 
147       // allow caller to close the file...
148    if(mark.size() == 0) {
149       if(rddofs.is_open()) rddofs.close();
150       return 0;
151    }
152 
153    if(!rddofs.is_open()) {           // first call : open the file
154       if(CI.Verbose) oflog << "BEGIN OutputRawDData()" << endl;
155       rddofs.open(CI.OutputRawDDFile.c_str(),ios::out);
156       if(rddofs.is_open()) {
157          oflog << "Opened file " << CI.OutputRawDDFile
158             << " for raw DD data output." << endl;
159          rddofs << "# " << Title << endl;
160          rddofs << "RDD sit1 sit2 sat ref week  sec_wk     flag      DDL1_m"
161             << "           "
162             << "DDL2_m           DDER_m            resL1_m          resL2_m";
163          if(CI.Frequency == 3) rddofs << "          WLbias_m";
164          rddofs << endl;
165          if(TripleOut) rddofs
166             << "RTD sit1 sit2 sat ref week  sec_wk     flag      TDL1_m"
167             << "           TDL2_m           TDER_m" << endl;
168       }
169       else {
170          // TD error msg
171          return -1;
172       }
173    }
174 
175    size_t i;
176    double wlb;
177    CommonTime tt;
178    format f166(16,6);
179 
180       // loop over epochs
181    for(i=0; i<dddata.count.size(); i++) {
182 
183       tt = FirstEpoch + dddata.count[i]*CI.DataInterval;
184 
185       if(CI.Frequency == 3)
186          wlb =   wl1p * dddata.DDL1[i]      // wide lane range minus phase
187                + wl2p * dddata.DDL2[i]      // = WL phase - NL range
188                - wl1r * dddata.DDP1[i]
189                - wl2r * dddata.DDP2[i];
190 
191       rddofs << "RDD " << ddid << " " << printTime(tt,"%4F %10.3g")
192          << " " << setw(2) << mark[i]
193          << " " << f166 << dddata.DDL1[i]
194          << " " << f166 << dddata.DDL2[i]
195          << " " << f166 << dddata.DDER[i]
196          << " " << f166 << dddata.DDL1[i] - dddata.DDER[i]
197          << " " << f166 << dddata.DDL2[i] - dddata.DDER[i];
198       if(CI.Frequency == 3) rddofs << " " << f166 << wlb;
199       rddofs << endl;
200 
201       if(TripleOut && i>0) {
202          // wlb is a dummy here, = delta time for this triple diff
203          wlb = (dddata.count[i]-dddata.count[i-1])*CI.DataInterval;
204          rddofs << "RTD " << ddid << " " << printTime(tt,"%4F %10.3g")
205             << " " << setw(2) << 10*mark[i]+mark[i-1]
206             << " " << f166 << (dddata.DDL1[i]-dddata.DDL1[i-1])/wlb
207             << " " << f166 << (dddata.DDL2[i]-dddata.DDL2[i-1])/wlb
208             << " " << f166 << (dddata.DDER[i]-dddata.DDER[i-1])/wlb
209             << endl;
210       }
211    }
212 
213    return 0;
214 }
215 catch(Exception& e) { GPSTK_RETHROW(e); }
216 catch(std::exception& e) { Exception E("std except: "+string(e.what())); GPSTK_THROW(E); }
217 catch(...) { Exception e("Unknown exception"); GPSTK_THROW(e); }
218 }   // end OutputRawDData()
219 
220 //------------------------------------------------------------------------------------
OutputDDData(void)221 int OutputDDData(void)
222 {
223 try {
224    if(CI.Verbose) oflog << "BEGIN OutputDDData()" << endl;
225 
226    if(CI.OutputDDDFile.empty()) return 0;
227 
228    size_t i;
229    double wlb;
230    CommonTime tt;
231    map<DDid,DDData>::const_iterator it;
232    format f166(16,6);
233 
234       // open an output file for DDD data
235    ofstream dddofs;
236    dddofs.open(CI.OutputDDDFile.c_str(),ios::out);
237    if(dddofs.is_open()) {
238       oflog << "Opened file " << CI.OutputDDDFile << " for DD data output." << endl;
239       dddofs << "# " << Title << endl;
240       dddofs << "DDD sit1 sit2 sat ref week  sec_wk           DDL1_m           "
241          << "DDL2_m           DDER_m            resL1_m          resL2_m";
242       if(CI.Frequency == 3) dddofs << "          WLbias_m";
243       dddofs << endl;
244    }
245    else {
246       // TD error msg
247       return -1;
248    }
249 
250       // loop over DDids
251    for(it=DDDataMap.begin(); it != DDDataMap.end(); it++) {
252 
253          // loop over epochs
254       for(i=0; i<it->second.count.size(); i++) {
255 
256          tt = FirstEpoch + it->second.count[i]*CI.DataInterval;
257 
258          if(CI.Frequency == 3)
259             wlb =   wl1p * it->second.DDL1[i]      // wide lane range minus phase
260                   + wl2p * it->second.DDL2[i]      // = WL phase - NL range
261                   - wl1r * it->second.DDP1[i]
262                   - wl2r * it->second.DDP2[i];
263 
264          dddofs << "DDD " << it->first << " " << printTime(tt,"%4F %10.3g")
265             << " " << f166 << it->second.DDL1[i]
266             << " " << f166 << it->second.DDL2[i]
267             << " " << f166 << it->second.DDER[i]
268             << " " << f166 << it->second.DDL1[i] - it->second.DDER[i]
269             << " " << f166 << it->second.DDL2[i] - it->second.DDER[i];
270          if(CI.Frequency == 3) dddofs << " " << f166 << wlb;
271          dddofs << endl;
272       }
273 
274    }
275 
276    dddofs.close();
277 
278    return 0;
279 }
280 catch(Exception& e) { GPSTK_RETHROW(e); }
281 catch(std::exception& e) { Exception E("std except: "+string(e.what())); GPSTK_THROW(E); }
282 catch(...) { Exception e("Unknown exception"); GPSTK_THROW(e); }
283 }   // end OutputDDData()
284 
285 //------------------------------------------------------------------------------------
OutputClockData(void)286 int OutputClockData(void)
287 {
288 try {
289    if(CI.Verbose) oflog << "BEGIN OutputClockData()" << endl;
290 
291    if(CI.OutputClkFile.empty()) return 0;
292 
293    size_t i;
294    CommonTime tt;
295    map<string,Station>::const_iterator it;
296    format f166(16,6),f92(9,2,2),f96(9,6);
297 
298       // open an output file for Clk data
299    ofstream clkofs;
300    clkofs.open(CI.OutputClkFile.c_str(),ios::out);
301    if(clkofs.is_open()) {
302       oflog << "Opened file " << CI.OutputClkFile << " for DD data output." << endl;
303       clkofs << "# " << Title << endl;
304       clkofs << "CLK site week  sec_wk   Rx_clk_bias(m)   Sig(m)   TT_off(s)\n";
305    }
306    else {
307       // TD error msg
308       return -1;
309    }
310 
311 
312       // loop over stations
313    for(it=Stations.begin(); it != Stations.end(); it++) {
314 
315          // loop over epochs
316       for(i=0; i<it->second.ClockBuffer.size(); i++) {
317 
318          tt = FirstEpoch + it->second.CountBuffer[i]*CI.DataInterval;
319 
320          clkofs << "CLK " << it->first << " " << printTime(tt,"%4F %10.3g")
321             << " " << f166 << it->second.ClockBuffer[i]
322             << " " << f92 << it->second.ClkSigBuffer[i]
323             // TD add clock polynomial Evaluate(tt)
324             << " " << f92 << it->second.RxTimeOffset[i]
325             << endl;
326 
327       }  // loop over epochs
328 
329    }  // loop over stations
330 
331    clkofs.close();
332 
333    return 0;
334 }
335 catch(Exception& e) { GPSTK_RETHROW(e); }
336 catch(std::exception& e) { Exception E("std except: "+string(e.what())); GPSTK_THROW(E); }
337 catch(...) { Exception e("Unknown exception"); GPSTK_THROW(e); }
338 }   // end OutputClockData()
339 
340 //------------------------------------------------------------------------------------
341 //------------------------------------------------------------------------------------
342