?? readofile.cpp
字號(hào):
#include"myStruct.h"
#include<fstream>
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<iomanip>
using namespace std;
void readOfile(vector<epoch_set>& v,double& apx,double& apy,double& apz )
{
time_gps GregToGps(time_calendar tc);//聲明時(shí)間轉(zhuǎn)換函數(shù)
char *p, name[20];
p=name;
cout<<"Enter O file name:";
scanf("%s",p);
ifstream infile(p,ios::in);
if(! infile)
{
cerr<<"open error!"<<endl;
exit(1);//打開(kāi)文件失敗
}
////////////////////////////////////////////////////////
string str,str1,str3;//not good declared,暫時(shí)輪換存放取得的字符
int pos,pos1,pos2,pos3,pos_CA,pos_L1,pos_L2;//CA/L1/L2碼位置
int obsNum,n=0,e=0;//觀測(cè)值類型總數(shù),文件閱讀的行數(shù)
ofstream outfile("歷元對(duì)應(yīng)行數(shù).txt",ios::out);
//這里的do開(kāi)始讀頭文件---------------------------------------------------------------
do
{
getline(infile,str);
pos=str.find("C1",0);//在讀的過(guò)程順便找C1所在的位置
pos1=str.find("L1",0);//L1所在的位置
pos2=str.find("L2",0);//L2所在的位置
pos3=str.find("APPROX",0);//近似坐標(biāo)所在位置
if(pos3!=-1)//如果找到APPROX,獲取近似坐標(biāo)
{ //success return pos,else return npos=-1;
str1=str.substr(0,14);apx=atof(str1.c_str());
str1=str.substr(15,28);apy=atof(str1.c_str());
str1=str.substr(29,42);apz=atof(str1.c_str());
}
if (pos!=-1) //如果找到C1
{
str3=str.substr(0,6);//從第0個(gè)字符開(kāi)始讀6個(gè)字符,取得觀測(cè)值類型總數(shù)
obsNum=atoi(str3.c_str());//字符轉(zhuǎn)換為整數(shù)
pos_CA=(pos-10)/6;//位置從0,1,2,3...
pos_L1=(pos1-10)/6;
pos_L2=(pos2-10)/6;
}
n++;
} while(str.substr(60,3)!="END");//這個(gè)do是讀到文件頭結(jié)束END OF HEAD的地方停止
//cout<<"-------------o file header line is--"<<n<<"--hang------------"<<endl;
//cycle------------an li yuan da cycle---vector???
epoch_set es;//定義結(jié)構(gòu):一個(gè)歷元的所有數(shù)據(jù)
while(!infile.eof())//當(dāng)不是文件末尾時(shí)
{
//讀一個(gè)歷元的數(shù)據(jù)
epoch_HedMesg eh1;//開(kāi)始讀歷元頭:歷元,歷元標(biāo)志,衛(wèi)星總數(shù),PRN列表(String),接收機(jī)偏差
time_calendar tc1;//讀取日歷時(shí)間后再轉(zhuǎn)換,現(xiàn)在還沒(méi)轉(zhuǎn)
getline(infile,str1);//-------------------讀取了一行
string str2=str1.substr(0,3);//提取3個(gè)字符--year
tc1.year=atoi(str2.c_str());//字符轉(zhuǎn)數(shù)值
str2=str1.substr(3,3);//提取--month
tc1.month=atoi(str2.c_str());
str2=str1.substr(6,3);//提取--day
tc1.day=atoi(str2.c_str());
str2=str1.substr(9,3);//提取--hour
tc1.hour=atoi(str2.c_str());
str2=str1.substr(12,3);//提取--minute
tc1.minute=atoi(str2.c_str());
str2=str1.substr(15,3);//提取--second
tc1.second=atoi(str2.c_str());
str2=str1.substr(27,3);//提取--flag歷元標(biāo)志:0正常,1電源故障...
eh1.flag=atoi(str2.c_str());
time_gps tg1;
tg1=GregToGps(tc1);
es.gps_sat=tg1;//讀取了觀測(cè)歷元時(shí)刻
str2=str1.substr(30,3);//提取目前歷元--satNum衛(wèi)星總數(shù)
eh1.satNum=atoi(str2.c_str());//兩個(gè)地方都用
es.num_sat=atoi(str2.c_str());
int widthnum=eh1.satNum*3;//一顆衛(wèi)星3個(gè)字符,衛(wèi)星數(shù)*3=字符寬度
str2=str1.substr(33,widthnum);//提取--satList
eh1.satList=str2;//list還只是一個(gè)字符串
es.list_sat=str2;
n++;e++;
outfile<<"歷元"<<e<<"=>"<<n<<endl;
//接收機(jī)鐘差沒(méi)讀
//--------------------------歷元頭數(shù)據(jù)讀完---------------
//----------------------- 開(kāi)始讀觀測(cè)值數(shù)據(jù)--------------
complex_obs cplxobs_temp;//暫時(shí)存放
my_obs mobs;
int k=0;
for(int j=0;j<eh1.satNum;j++)//從0到衛(wèi)星數(shù)<8=0:7
{
string tempstr;//存放2次讀的字符
if(obsNum>5)//如果觀測(cè)值數(shù)大于5,要占兩行
{
getline(infile,str1);//一次有2行
getline(infile,str);
tempstr=str1+str;//一顆衛(wèi)星的數(shù)據(jù)放在了一行
n+=2;//計(jì)算讀了多少行,一共3個(gè)地方
}
else {getline(infile,tempstr); n++;}
//cout<<"------------last str="<<tempstr<<endl;
//下面根據(jù)C1 L1 L2的存放順序讀取
str2=tempstr.substr(pos_CA*16,14);//提取--pseudo_obs只有觀測(cè)值,暫無(wú)LLi,intension
cplxobs_temp.pseudo_obs.value=atof(str2.c_str());
if(cplxobs_temp.pseudo_obs.value==0) mobs.flag="C1";//判斷觀測(cè)值的缺失
str2=tempstr.substr(pos_L1*16,14);//提取--phrase1
cplxobs_temp.phrase1_obs.value=atof(str2.c_str());
if (cplxobs_temp.phrase1_obs.value==0) mobs.flag="L1";//判斷觀測(cè)值的缺失
str2=tempstr.substr(pos_L2*16,14);//提取--phrase2
cplxobs_temp.phrase2_obs.value=atof(str2.c_str());
if (cplxobs_temp.phrase2_obs.value==0) mobs.flag="L2";//判斷觀測(cè)值的缺失
//...................先提取這3種C1 L1 L2觀測(cè)值
string listtemp=eh1.satList.substr(k,2);//從頭里面,k用來(lái)表示步長(zhǎng)
mobs.sat_num=atof(listtemp.c_str());//提取--對(duì)應(yīng)衛(wèi)星號(hào)
k+=3;//3個(gè)字符遞增0,3,6,9...
mobs.set_obs=cplxobs_temp;//above give to my_obs
mobs.tgps=GregToGps(tc1);//??????????????????????????
es.array_sat[j]=mobs;//give above j=0,1,2,3.... <24
}
v.push_back(es);//根據(jù)衛(wèi)星的個(gè)數(shù)每讀一次,推進(jìn)一次。防范空行????if flag=2??
}
cout<<"文件行數(shù)n="<<n<<"歷元數(shù)e="<<e<<endl;
infile.close();
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -