c++读取和显示Rinex O文件和Rinex N文件,头文件,源函数,主函数
时间: 2023-06-19 12:08:12 浏览: 163
以下是读取和显示Rinex O文件和Rinex N文件的C++代码示例,包括头文件、源函数和主函数。
头文件:
```c++
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
using namespace std;
// Rinex O文件头部信息结构体
struct RinexOHeader {
string markerName; // 接收机标识
string observerName; // 观测者/测站名
string markerNumber; // 接收机编号
string observerAgency; // 观测者/测站代理
string receiverNumber; // 接收机编号
string receiverType; // 接收机类型
string antennaNumber; // 天线编号
string antennaType; // 天线类型
double approxPos[3]; // 大地坐标系下的近似位置
double antennaDelta[3]; // 天线相对于接收机的偏差
string systemType; // 定位系统类型
string signalType; // 信号类型
double interval; // 观测时间间隔
int numOfSatellites; // 卫星数目
};
// Rinex N文件头部信息结构体
struct RinexNHeader {
string markerName; // 站名
string markerNumber; // 站号
string observerName; // 观测员名字
string observerAgency; // 观测员机构
double approxPos[3]; // 大地坐标系下的近似位置
double antennaDelta[3]; // 天线相对于接收机的偏差
string receiverType; // 接收机类型
string antennaType; // 天线类型
string recSerialNumber; // 接收机序列号
string antSerialNumber; // 天线序列号
string systemType; // 定位系统类型
string signalType; // 信号类型
double interval; // 观测时间间隔
int numOfSatellites; // 卫星数目
vector<string> satellitePRN; // 卫星PRN号
};
```
源函数:
```c++
// 读取Rinex O文件头部信息
void readRinexOHeader(ifstream& rinexFile, RinexOHeader& header) {
string line;
while (getline(rinexFile, line)) {
// 接收机标识
if (line.find("MARKER NAME") != string::npos) {
header.markerName = line.substr(0, 20);
}
// 观测者/测站名
if (line.find("OBSERVER / AGENCY") != string::npos) {
header.observerName = line.substr(0, 20);
header.observerAgency = line.substr(20, 40);
}
// 接收机编号
if (line.find("REC # / TYPE / VERS") != string::npos) {
header.receiverNumber = line.substr(0, 20);
header.receiverType = line.substr(20, 20);
}
// 天线编号
if (line.find("ANT # / TYPE") != string::npos) {
header.antennaNumber = line.substr(0, 20);
header.antennaType = line.substr(20, 20);
}
// 大地坐标系下的近似位置
if (line.find("APPROX POSITION XYZ") != string::npos) {
header.approxPos[0] = stod(line.substr(0, 14));
header.approxPos[1] = stod(line.substr(14, 14));
header.approxPos[2] = stod(line.substr(28, 14));
}
// 天线相对于接收机的偏差
if (line.find("ANTENNA: DELTA H/E/N") != string::npos) {
header.antennaDelta[0] = stod(line.substr(0, 14));
header.antennaDelta[1] = stod(line.substr(14, 14));
header.antennaDelta[2] = stod(line.substr(28, 14));
}
// 定位系统类型
if (line.find("SYS / # / OBS TYPES") != string::npos) {
header.systemType = line.substr(0, 3);
header.signalType = line.substr(40, 20);
}
// 观测时间间隔
if (line.find("INTERVAL") != string::npos) {
header.interval = stod(line.substr(0, 10));
}
// 卫星数目
if (line.find("# OF SATELLITES") != string::npos) {
header.numOfSatellites = stoi(line.substr(0, 6));
break;
}
}
}
// 读取Rinex N文件头部信息
void readRinexNHeader(ifstream& rinexFile, RinexNHeader& header) {
string line;
while (getline(rinexFile, line)) {
// 站名
if (line.find("MARKER NAME") != string::npos) {
header.markerName = line.substr(0, 20);
}
// 站号
if (line.find("MARKER NUMBER") != string::npos) {
header.markerNumber = line.substr(0, 20);
}
// 观测员名字
if (line.find("OBSERVER / AGENCY") != string::npos) {
header.observerName = line.substr(0, 20);
header.observerAgency = line.substr(20, 40);
}
// 大地坐标系下的近似位置
if (line.find("APPROX POSITION XYZ") != string::npos) {
header.approxPos[0] = stod(line.substr(0, 14));
header.approxPos[1] = stod(line.substr(14, 14));
header.approxPos[2] = stod(line.substr(28, 14));
}
// 天线相对于接收机的偏差
if (line.find("ANTENNA: DELTA H/E/N") != string::npos) {
header.antennaDelta[0] = stod(line.substr(0, 14));
header.antennaDelta[1] = stod(line.substr(14, 14));
header.antennaDelta[2] = stod(line.substr(28, 14));
}
// 接收机类型
if (line.find("REC # / TYPE / VERS") != string::npos) {
header.receiverType = line.substr(20, 20);
header.recSerialNumber = line.substr(40, 20);
}
// 天线类型
if (line.find("ANT # / TYPE") != string::npos) {
header.antennaType = line.substr(20, 20);
header.antSerialNumber = line.substr(40, 20);
}
// 定位系统类型
if (line.find("SYS / # / OBS TYPES") != string::npos) {
header.systemType = line.substr(0, 3);
header.signalType = line.substr(40, 20);
}
// 观测时间间隔
if (line.find("INTERVAL") != string::npos) {
header.interval = stod(line.substr(0, 10));
}
// 卫星数目
if (line.find("# OF SATELLITES") != string::npos) {
header.numOfSatellites = stoi(line.substr(0, 6));
break;
}
}
}
// 读取Rinex O文件数据
void readRinexOData(ifstream& rinexFile, vector<double>& data) {
string line;
while (getline(rinexFile, line)) {
if (line.find(">") != string::npos) {
continue;
} else {
data.push_back(stod(line.substr(0, 14)));
}
}
}
// 读取Rinex N文件数据
void readRinexNData(ifstream& rinexFile, vector<string>& data) {
string line;
while (getline(rinexFile, line)) {
if (line.find(">") != string::npos) {
continue;
} else {
data.push_back(line.substr(0, 3));
}
}
}
// 显示Rinex O文件头部信息
void showRinexOHeader(RinexOHeader& header) {
cout << "Marker Name: " << header.markerName << endl;
cout << "Observer Name: " << header.observerName << endl;
cout << "Receiver Number: " << header.receiverNumber << endl;
cout << "Receiver Type: " << header.receiverType << endl;
cout << "Antenna Number: " << header.antennaNumber << endl;
cout << "Antenna Type: " << header.antennaType << endl;
cout << "Approximate Position (X, Y, Z): "
<< "(" << header.approxPos[0] << ", "
<< header.approxPos[1] << ", "
<< header.approxPos[2] << ")" << endl;
cout << "Antenna Delta (H, E, N): "
<< "(" << header.antennaDelta[0] << ", "
<< header.antennaDelta[1] << ", "
<< header.antennaDelta[2] << ")" << endl;
cout << "System Type: " << header.systemType << endl;
cout << "Signal Type: " << header.signalType << endl;
cout << "Interval: " << header.interval << endl;
cout << "Number of Satellites: " << header.numOfSatellites << endl;
}
// 显示Rinex N文件头部信息
void showRinexNHeader(RinexNHeader& header) {
cout << "Marker Name: " << header.markerName << endl;
cout << "Marker Number: " << header.markerNumber << endl;
cout << "Observer Name: " << header.observerName << endl;
cout << "Approximate Position (X, Y, Z): "
<< "(" << header.approxPos[0] << ", "
<< header.approxPos[1] << ", "
<< header.approxPos[2] << ")" << endl;
cout << "Antenna Delta (H, E, N): "
<< "(" << header.antennaDelta[0] << ", "
<< header.antennaDelta[1] << ", "
<< header.antennaDelta[2] << ")" << endl;
cout << "Receiver Type: " << header.receiverType << endl;
cout << "Antenna Type: " << header.antennaType << endl;
cout << "Receiver Serial Number: " << header.recSerialNumber << endl;
cout << "Antenna Serial Number: " << header.antSerialNumber << endl;
cout << "System Type: " << header.systemType << endl;
cout << "Signal Type: " << header.signalType << endl;
cout << "Interval: " << header.interval << endl;
cout << "Number of Satellites: " << header.numOfSatellites << endl;
cout << "Satellite PRN: ";
for (string prn : header.satellitePRN) {
cout << prn << " ";
}
cout << endl;
}
// 显示Rinex O文件数据
void showRinexOData(vector<double>& data) {
for (double d : data) {
cout << d << " ";
}
cout << endl;
}
// 显示Rinex N文件数据
void showRinexNData(vector<string>& data) {
for (string s : data) {
cout << s << " ";
}
cout << endl;
}
```
主函数:
```c++
int main() {
// 读取Rinex O文件
string rinexOFilePath = "rinexO.20o";
ifstream rinexOFile(rinexOFilePath);
if (!rinexOFile) {
cout << "Failed to open Rinex O file!" << endl;
return 1;
}
RinexOHeader rinexOHeader;
readRinexOHeader(rinexOFile, rinexOHeader);
vector<double> rinexOData;
readRinexOData(rinexOFile, rinexOData);
rinexOFile.close();
// 显示Rinex O文件头部信息
showRinexOHeader(rinexOHeader);
// 显示Rinex O文件数据
showRinexOData(rinexOData);
// 读取Rinex N文件
string rinexNFilePath = "rinexN.20n";
ifstream rinexNFile(rinexNFilePath);
if (!rinexNFile) {
cout << "Failed to open Rinex N file!" << endl;
return 1;
}
RinexNHeader rinexNHeader;
readRinexNHeader(rinexNFile, rinexNHeader);
vector<string> rinexNData;
readRinexNData(rinexNFile, rinexNData);
rinexNFile.close();
// 显示Rinex N文件头部信息
showRinexNHeader(rinexNHeader);
// 显示Rinex N文件数据
showRinexNData(rinexNData);
return 0;
}
```
阅读全文