#include <iostream>
#include <iomanip>
#include <sstream>
#include "RinexNavfile.h"
#include<windows.h>
#include<math.h>
using namespace std;
/** RinexNavfile 构造函数 初始化
* --------------------------*/
rinexNavHeader::rinexNavHeader()
{
VersionType = 0;
}
/** file类 构造函数
* 此方法构造直接进行文件读取
* 读取过程中存在异常情况会进行捕捉
* ---------------------------*/
RinexNavfile::RinexNavfile(const string & fileName, e_inpOut inpOut)
{
this->_fileName = fileName;
this->_inpOut = inpOut;
_flgPowerFail = false;
if (_inpOut == input)
{
openRead(_fileName);
}
if (_inpOut == output)
{
openWrite(_fileName);
}
}
/** RinexNavfile 析构函数
* --------------------------*/
RinexNavfile::~RinexNavfile()
{
/*
//this->_inpOut = 0;
this->GPSData.clear();
this->GPSData.~vector();
this->GalData.clear();
this->GalData.~vector();
this->BDSData.clear();
this->BDSData.~vector();
this->GLOData.clear();
this->GLOData.~vector();
this->_header.~rinexNavHeader();
if (_file)
{
free(_file); _file = 0;
}*/
}
/** RinexNavfile 文件打开与读取函数
* --------------------------*/
bool RinexNavfile::openRead(string & fileName)
{
infile.open(_fileName, ios::in);
if (!infile.is_open())
{
cout << "N文件读取打开失败!!!" << endl;
Sleep(5000);//程序挂起5s
return false;
}
//读取头文件 不分版本号
try {
readHeader();
}
catch (exception e) {
cout << "N文件头文件读取失败!!!" << endl;
Sleep(5000);//程序挂起5s
return false;
}
//读取数据体部分
try {
ReadNav();
}
catch (exception e) {
cout << "N文件观测数据读取失败!!! version= " << _header.VersionType << endl;
Sleep(5000);//程序挂起5s
return false;
}
return true;
}
/** Rinex N 文件输出
* --------------------------*/
bool RinexNavfile::openWrite(string & fileName)
{
return true;
}
/** Rinex N 头文件读取
* --------------------------*/
void RinexNavfile::readHeader()
{
string str;
getline(infile, str);
//第一行获取版本号
_header.VersionType = atof(str.substr(5, 1).c_str());
if (str.substr(20, 15) == "NAVIGATION DATA")
{
if (str.substr(40, 1) == " ")
{
_header.SatType = "G";
}
//_header.SatType = str.substr(40, 1);
}
if ((str.substr(23, 7) == "GLONASS") || (str.substr(20, 7) == "GLONASS"))
{
_header.SatType = "R";
}
if ((str.substr(23, 3) == "GPS") || (str.substr(20, 3) == "GPS"))
{
_header.SatType = "G";
}
if ((str.substr(23, 7) == "BDS") || (str.substr(20, 7) == "COMPASS"))
{
_header.SatType = "C";
}
if ((str.substr(23, 7) == "GALILEO") || (str.substr(20, 7) == "GALILEO"))
{
_header.SatType = "E";
}
do
{
getline(infile, str); //从标准输入读入整行数据,并存为字符数组 遇回车截止
} while ((str.substr(60, 13)) != "END OF HEADER"); //循环到文件结束
}
/** Rinex N 数据部分读取
* --------------------------*/
bool RinexNavfile::ReadNav()
{
GPSData.clear(); //删除nData中的所有指针储存所占用的内存
GalData.clear(); //删除nData中的所有指针储存所占用的内存
BDSData.clear(); //删除nData中的所有指针储存所占用的内存
GLOData.clear(); //删除nData中的所有指针储存所占用的内存
NavData1 Nrecorddata1; //临时的一颗卫星在某一历元下的数据
NavData2 Nrecorddata2; //临时的一颗卫星在某一历元下的数据
memset(&Nrecorddata1, 0, sizeof(Nrecorddata1));
memset(&Nrecorddata2, 0, sizeof(Nrecorddata2));
string str;
string str1;
if (_header.VersionType == 2) //如果是版本2
{
if (_header.SatType != "R") //如果不是GLONASS卫星
{
while (getline(infile, str)) //循环用于不断的取下一行
{
if (str.length() == 0) continue;
if (str.length() == 32) continue;
if (str.find("COMMENT") != string::npos) continue;
//读取第一行
int year = atoi(str.substr(3, 2).c_str());
int month = atoi(str.substr(6, 2).c_str());
int day = atoi(str.substr(9, 2).c_str());
int hour = atoi(str.substr(12, 2).c_str());
int minute = atoi(str.substr(15, 2).c_str());
double sec = atof(str.substr(18, 4).c_str());
//年份处理
if (year < 80) {
year += 2000;
}
else if (year < 100) {
year += 1900;
}
str1 = str.substr(0, 2); Nrecorddata1.PRN = atoi(str1.c_str()); //卫星编号
Nrecorddata1.NTime.set(year, month, day, hour, minute, sec); //历元时间
str1 = str.substr(22, 19); Nrecorddata1.deviation = atof(str1.c_str());//钟差
str1 = str.substr(41, 19); Nrecorddata1.drift = atof(str1.c_str()); //钟漂
str1 = str.substr(60, 19); Nrecorddata1.driftv = atof(str1.c_str()); //钟速
getline(infile, str);
str1 = str.substr(3, 19); Nrecorddata1.IODE = atof(str1.c_str());
str1 = str.substr(22, 19); Nrecorddata1.Crs = atof(str1.c_str());
str1 = str.substr(41, 19); Nrecorddata1.DeltN = atof(str1.c_str());
str1 = str.substr(60, 19); Nrecorddata1.M0 = atof(str1.c_str());
getline(infile, str);
str1 = str.substr(3, 19); Nrecorddata1.Cuc = atof(str1.c_str());
str1 = str.substr(22, 19); Nrecorddata1.e = atof(str1.c_str());
str1 = str.substr(41, 19); Nrecorddata1.Cus = atof(str1.c_str());
str1 = str.substr(60, 19); Nrecorddata1.sqrtA = atof(str1.c_str());
getline(infile, str);
str1 = str.substr(3, 19); Nrecorddata1.TOETime = atof(str1.c_str());
str1 = str.substr(22, 19); Nrecorddata1.Cic = atof(str1.c_str());
str1 = str.substr(41, 19); Nrecorddata1.Omega = atof(str1.c_str());
str1 = str.substr(60, 19); Nrecorddata1.Cis = atof(str1.c_str());
getline(infile, str);
str1 = str.substr(3, 19); Nrecorddata1.i0 = atof(str1.c_str());
str1 = str.substr(22, 19); Nrecorddata1.Crc = atof(str1.c_str());
str1 = str.substr(41, 19); Nrecorddata1.Om = atof(str1.c_str());
str1 = str.substr(60, 19); Nrecorddata1.OmegaDot = atof(str1.c_str());
getline(infile, str);
str1 = str.substr(3, 19); Nrecorddata1.i = atof(str1.c_str());
str1 = str.substr(22, 19); Nrecorddata1.L2Num = atof(str1.c_str());
str1 = str.substr(41, 19); Nrecorddata1.GPSWeek = atof(str1.c_str());
str1 = str.substr(60, 19); Nrecorddata1.L2P = atof(str1.c_str());
getline(infile, str);
str1 = str.substr(3, 19); Nrecorddata1.SatAccuracy = atof(str1.c_str());
str1 = str.substr(22, 19); Nrecorddata1.SatStatus = atof(str1.c_str());
str1 = str.substr(41, 19); Nrecorddata1.TGD = atof(str1.c_str());
str1 = str.substr(60, 19); Nrecorddata1.IODC = atof(str1.c_str());
getline(infile, str);
int line = str.length();
if (line > 60)
{
str1 = str.substr(3, 19); Nrecorddata1.TransmitTime = atof(str1.c_str());
str1 = str.substr(22, 19); Nrecorddata1.Interval = atof(str1.c_str());
str1 = str.substr(41, 19); Nrecorddata1.Spare1 = atof(str1.c_str());
str1 = str.substr(60, 19); Nrecorddata1.Spare2 = atof(str1.c_str());
}
if (line > 40 && line<61)
{
str1 = str.substr(3, 19); Nrecorddata1.TransmitTime = atof(str1.c_str());
str1 = str.substr(22, 19); Nrecorddata1.Interval = atof(str1.c_str());
str1 = str.substr(41, 19); Nrecorddata1.Spare1 = atof(str1.c_str());
}
if (line > 22 && line<42)
{
str1 = str.substr(3, 19); Nrecorddata1.TransmitTime = atof(str1.c_str());
str1 = str.substr(22, 19); Nrecorddata1.Interval = atof(str1.c_str());
}
if (line > 4 && line<23)
{
str1 = str.substr(3, 19); Nrecorddata1.TransmitTime = atof(str1.c_str());
}
if (_header.SatType == "G"){
GPSData.push_back(Nrecorddata1);
}
if (_header.SatType == "E"){
GalData.push_back(Nrecorddata1);
}
if (_header.SatType == "C"){
BDSData.push_back(Nrecorddata1);
}
memset(&Nrecorddata1, 0, sizeof(Nrecorddata1));
}
}
if (_header.SatType == "R") //如果是GLONASS卫星
{
while (getline(infile, str)) //循环用于不断的取下一行
读取rinex文件(spp)
3星 · 超过75%的资源 需积分: 49 139 浏览量
2018-09-17
20:08:11
上传
评论 8
收藏 11KB RAR 举报
sinat_28603181
- 粉丝: 3
- 资源: 4