?? readnfile.cpp
字號(hào):
#include"myStruct.h"
#include<fstream>
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<iomanip>
using namespace std;
void readNfile(vector<nav_sat>& vn)
{
time_gps GregToGps(time_calendar tc);//聲明時(shí)間轉(zhuǎn)換
char *p, name[20];
p=name;
cout<<"Enter N file name:";
scanf("%s",p);
ifstream infile1(p,ios::in);
if(! infile1)
{
cerr<<"open error!"<<endl;
exit(1);//打開(kāi)文件失敗
}
////////////////////////////////////////////////////////
string strs;//not good declared,暫時(shí)輪換存放取得的字符
do
{
getline(infile1,strs);//沒(méi)有讀文件頭
} while(strs.substr(60,3)!="END");
//go on reading...
while(!infile1.eof())//當(dāng)不是文件末尾的時(shí)候,一直讀
{
pare_s_clock paresclk;//衛(wèi)星鐘差三參數(shù)&TOC
time_calendar tc1;//TOC
time_gps tg1;
getline(infile1,strs);//讀一行
nav_sat navsat;//定義結(jié)構(gòu):代表一顆衛(wèi)星的導(dǎo)航數(shù)據(jù)
string str2=strs.substr(2,3);//提取3個(gè)字符--year
tc1.year=atoi(str2.c_str());//字符轉(zhuǎn)數(shù)值
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);//轉(zhuǎn)換為GPS時(shí)間
paresclk.TOC.num_week=tg1.num_week ;
paresclk.TOC.num_sec=tg1.num_sec;
str2=strs.substr(22,19);//衛(wèi)星鐘的偏差
paresclk.a0=atof(str2.c_str());
str2=strs.substr(41,19);//衛(wèi)星鐘的漂移
paresclk.a1=atof(str2.c_str());
str2=strs.substr(60,19);//衛(wèi)星鐘的漂移速度
paresclk.a2=atof(str2.c_str());
str2=strs.substr(0,2);//提取--衛(wèi)星號(hào)
navsat.PRN=atoi(str2.c_str());
navsat.pare_clock=paresclk;//單個(gè)衛(wèi)星數(shù)據(jù)組第一行讀完
//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());
vn.push_back(navsat);//讀完一組放到容器里
}
infile1.close();
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -