⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 reado.cpp

📁 利用广播星历计算卫星轨道坐标
💻 CPP
字号:
#include"myStruct.h"
#include<fstream>
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<iomanip>
using namespace std;
void readNfile(vector<nav_sat>& vn,char *p)
{
	time_gps GregToGps(time_calendar tc);//声明时间转换
	/*char *p, name[20];
	p=name;
	cout<<"Enter N file name:";
    scanf("%s",p);
	
	ifstream infile1(p,ios::in);
	*/
	ifstream infile1(p,ios::in);
	   if(! infile1)
	   {
		cerr<<"open error!"<<endl;
		exit(1);//打开文件失败
	   }
////////////////////////////////////////////////////////
	string strs;//not good declared,暂时轮换存放取得的字符
	do
	{
		getline(infile1,strs);//没有读文件头	    
	} while(strs.substr(60,3)!="END");	
//go on reading...
int prn0=1,prn=0;//设置要读的卫星号prn0
//while(!infile1.eof())//当不是文件末尾的时候,一直读[!infile1.eof()//before]
double toeB=200;
do
{
		pare_s_clock paresclk;//卫星钟差三参数&TOC
		time_calendar tc1;//TOC
		time_gps tg1;
		
		double toeC=toeB;
	getline(infile1,strs);//读一行
	if(atoi(strs.c_str())==0)
	{break;}

nav_sat navsat;//定义结构:代表一颗卫星的导航数据		
string str2=strs.substr(2,3);//提取3个字符--year
	    tc1.year=atoi(str2.c_str());//字符转数值
        str2=strs.substr(5,3);//提取--month
	    tc1.month=atoi(str2.c_str());    
        str2=strs.substr(8,3);//提取--day
	    tc1.day=atoi(str2.c_str());
	    str2=strs.substr(11,3);//提取--hour
	    tc1.hour=atoi(str2.c_str());
	    str2=strs.substr(14,3);//提取--minute
	    tc1.minute=atoi(str2.c_str());
	    str2=strs.substr(17,5);//提取--second
	    tc1.second=atoi(str2.c_str());
	        tg1=GregToGps(tc1);//转换为GPS时间		
	    paresclk.TOC.num_week=tg1.num_week ;
        paresclk.TOC.num_sec=tg1.num_sec;
        str2=strs.substr(22,19);//卫星钟的偏差
        paresclk.a0=atof(str2.c_str());	
		str2=strs.substr(41,19);//卫星钟的漂移
		paresclk.a1=atof(str2.c_str());		
		str2=strs.substr(60,19);//卫星钟的漂移速度
		paresclk.a2=atof(str2.c_str());	
	    str2=strs.substr(0,2);//提取--卫星号
	    navsat.PRN=atoi(str2.c_str());
		prn=atoi(str2.c_str());
		navsat.pare_clock=paresclk;//单个卫星数据组第一行读完
  //from now 1广播轨道
  getline(infile1,strs);//读一行
		str2=strs.substr(3,19);//IODE部份
		navsat.IODE=atof(str2.c_str());
		str2=strs.substr(22,19);//Crs部份
		navsat.Crs=atof(str2.c_str());
		str2=strs.substr(41,19);//delta_n部份
		navsat.delta_n=atof(str2.c_str());
		str2=strs.substr(60,19);//M0部份
		navsat.M0=atof(str2.c_str());
	//2
	getline(infile1,strs);
		str2=strs.substr(3,19);//Cuc部份
		navsat.Cuc=atof(str2.c_str());
		str2=strs.substr(22,19);//e部份
		navsat.e=atof(str2.c_str());
		str2=strs.substr(41,19);//Cus部份
		navsat.Cus=atof(str2.c_str());
		str2=strs.substr(60,19);//.sqrtA部份
		navsat.sqrtA=atof(str2.c_str());
	//3
	getline(infile1,strs);
		str2=strs.substr(3,19);//TOE.num_sec部份
		navsat.TOE.num_sec=atof(str2.c_str());
		str2=strs.substr(22,19);//Cic部份
		navsat.Cic=atof(str2.c_str());
		str2=strs.substr(41,19);//OMEGA部份
		navsat.OMEGA=atof(str2.c_str());
		str2=strs.substr(60,19);//Cis部份
		navsat.Cis=atof(str2.c_str());
	//4
	getline(infile1,strs);
		str2=strs.substr(3,19);//i0部份
		navsat.i0=atof(str2.c_str());
		str2=strs.substr(22,19);//.Crc部份
		navsat.Crc=atof(str2.c_str());
		str2=strs.substr(41,19);//.w部份
		navsat.w=atof(str2.c_str());
		str2=strs.substr(60,19);//
	navsat.OMEGA_DOT=atof(str2.c_str());str2=strs.substr(76,3);
	//5
	getline(infile1,strs);
		str2=strs.substr(3,19);//
		navsat.i_DOT=atof(str2.c_str());
		str2=strs.substr(22,19);//
		navsat.code_L2=atof(str2.c_str());
		str2=strs.substr(41,19);//
		navsat.TOE.num_week=atof(str2.c_str());
		str2=strs.substr(60,19);//
		navsat.mark_code_L2=atof(str2.c_str());
	//6
	getline(infile1,strs);
		str2=strs.substr(3,19);//
		navsat.pre_sat=atof(str2.c_str());
		str2=strs.substr(22,19);//
		navsat.hel_sat=atof(str2.c_str());
		str2=strs.substr(41,19);//
		navsat.TGD=atof(str2.c_str());
		str2=strs.substr(60,19);//
		navsat.IODC=atof(str2.c_str());
	//7
	getline(infile1,strs);
		str2=strs.substr(3,19);//
		navsat.time_sig_send=atof(str2.c_str());

		toeB=navsat.TOE.num_sec;//一些防范措施
		double ds=abs(toeC-navsat.TOE.num_sec);

		//vector<nav_sat>::iterator itr = vn.begin()+vn.size(); 
		
		if(prn==prn0 )
		{
		   vn.push_back(navsat);
		   if(ds<100||abs(ds-604800)<100)
		   {
			   vn.erase(vn.end()-2);
			   cout<<"erase"<<endl;
		   }
		}//读完一组放到容器里
			    
} while(!infile1.eof());
infile1.close();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -