Example: Reading and Writing a RINEX Observation File
This example demonstrates the basic I/O processing of RINEX files.
1 #include <iostream>
2 #include <iomanip>
3 #include "RinexObsBase.hpp"
4 #include "RinexObsHeader.hpp"
5 #include "RinexObsData.hpp"
6 #include "RinexObsStream.hpp"
7 using namespace std;
8 using namespace gpstk;
9 int main(void)
10 {
11 // Create the input file stream
12 RinexObsStream rin("bahr1620.04o");
13 // Create the output file stream
14 RinexObsStream rout("bahr1620.04o.new", ios::out|ios::trunc);
15 // Read the RINEX header
16 RinexObsHeader head; //RINEX header object
17 rin >> head;
18 rout.header = rin.header;
19 rout << rout.header;
20 // Loop over all data epochs
21 RinexObsData data; //RINEX data object
22 while (rin >> data) {
23 rout << data;
24 }
25 exit(0);
26 }
Lines 1 and 2 enable the following code to use the standard output stream: cout, cerr, etc.
Lines 3 through 6 declare the classes used later in main().
Lines 7 and 8 adds namespaces that the compiler searches in order to identify classes. Note that in addition to the standard namespace::std, the GPSTk has defined the namespace gpstk.
Line 12 and 14 instantiate RinexObsStream object, for input and output, respectively. Note by example that the simpler constructor defaults to input-only behavior. All of the complexity of reading and writing RINEX observation classes has been
encapsulated by the RinexObsStream class.
Lines 15 through 19 demonstrate reading and writing of the RINEX observation file header. Note that the GPSTk uses
overloaded operators. In this case the standard streaming operators, >> and << have been overloaded.
The observations are read into a RinexObsData object, epoch by epoch in lines 20 through 24. The streaming operators have been overloaded for these classes as well. Note that the streaming operator serves as a loop control variable as well as a method of "filling" a RinexObsData object. The RinexObsData class contains the epoch time stamp, and a map of satellites to observations. The
next example demonstrates how observations are extracted from the RinexObsData class.