?? gpsdoc.cpp
字號:
// GPSDoc.cpp : implementation of the CGPSDoc class
//
#include "stdafx.h"
#include "GPS.h"
#include "GPSDoc.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CGPSDoc
IMPLEMENT_DYNCREATE(CGPSDoc, CDocument)
BEGIN_MESSAGE_MAP(CGPSDoc, CDocument)
//{{AFX_MSG_MAP(CGPSDoc)
ON_COMMAND(ID_NAVIGATION, OnNavigation)
ON_COMMAND(ID_OBSERVE, OnObserve)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CGPSDoc construction/destruction
CGPSDoc::CGPSDoc()
{
// TODO: add one-time construction code here
}
CGPSDoc::~CGPSDoc()
{
}
BOOL CGPSDoc::OnNewDocument()
{
if (!CDocument::OnNewDocument())
return FALSE;
// TODO: add reinitialization code here
// (SDI documents will reuse this document)
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CGPSDoc serialization
void CGPSDoc::Serialize(CArchive& ar)
{
if (ar.IsStoring())
{
// TODO: add storing code here
}
else
{
// TODO: add loading code here
}
}
/////////////////////////////////////////////////////////////////////////////
// CGPSDoc diagnostics
#ifdef _DEBUG
void CGPSDoc::AssertValid() const
{
CDocument::AssertValid();
}
void CGPSDoc::Dump(CDumpContext& dc) const
{
CDocument::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CGPSDoc commands
void CGPSDoc::OnNavigation()
{
// TODO: Add your command handler code here
Open();
}
void CGPSDoc::OnObserve()
{
// TODO: Add your command handler code here
Open_Observe();
}
void CGPSDoc::Open()
{
char *szFilter="Text Files(*.txt)|*.txt|All Files(*.*)|*.*|GPS Files(*.dat)|*.dat|";
CFileDialog fo(true,"*.*",TEXT("gpsdata.txt") ,OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,szFilter);
fo.DoModal();
CString path=fo.GetPathName();
if(path=="GPSfile")
return;
CString data;
if(!gpsFile.Open(path,CFile::modeRead))
{
AfxMessageBox("Can't open file!");
return;
}
//begin to read
int PRN;
int year=0,month=0,day=0;
int hour=0,minute=0,second=0;
double a0=0,a1=0,a2=0;
int a=0,b=0;
double D[4];
CNavigationFile temp;
gpsFile.ReadString(data);
data.TrimLeft();
data.TrimRight();
CString str1;
while(data!="END OF HEADER")
{
gpsFile.ReadString(data);
data.TrimRight();
data.TrimLeft();
}
m_count=0;
gpsFile.ReadString (data);
data.TrimLeft ();
data.TrimRight ();
///begint to read zhe zero line
while(!data.IsEmpty())
{
a=data.Find(" ");
PRN=atoi(data.Mid(0,a));
temp.SetPRN(PRN);
year=atoi(data.Mid(a+1,2))+2000;
a=data.Find(" ",a+1);
month=atoi(data.Mid(a+1,2));
a=data.Find(" ",a+1);
day=atoi(data.Mid(a+1,2));
a=data.Find(" ",a+1);
hour =atoi(data.Mid (a+1,2));
a=data.Find(" ",a+1);
minute =atoi(data.Mid (a+1,2));
a=data.Find(" ",a+1);
second =atoi(data.Mid (a+1,3));
temp.SetTime(year,month,day,hour,minute,second);
a=data.Find("."); //秒的小數(shù)點
a=data.Find(".",a+1);
str1=data.Mid (a-2,19);
a0=atof(str1);
a=data.Find(".",a+1);
str1=data.Mid (a-2,19);
a1=atof(str1);
a=data.Find(".",a+1);
str1=data.Mid (a-2,19);
a2=atof(str1);
temp.SetAAA (a0,a1,a2);
//////read the first line
gpsFile.ReadString (data);
data.TrimLeft ();
data.TrimRight ();
a=data.Find(".");
b=data.Find ("e");
str1=data.Mid (0,b+5);
D[0]=atof(str1);
a=data.Find(".",a+1);
str1=data.Mid (a-2,19);
D[1]=atof(str1);
a=data.Find(".",a+1);
str1=data.Mid (a-2,19);
D[2]=atof(str1);
a=data.Find(".",a+1);
str1=data.Mid (a-2,19);
D[3]=atof(str1);
temp.SetFirstLine(D[0],D[1],D[2],D[3]);
//讀取第二行數(shù)據(jù)
gpsFile.ReadString (data);
data.TrimLeft ();
data.TrimRight ();
a=data.Find(".");
b=data.Find ("e");
str1=data.Mid (0,b+5);
D[0]=atof(str1);
a=data.Find(".",a+1);
str1=data.Mid (a-2,19);
D[1]=atof(str1);
a=data.Find(".",a+1);
str1=data.Mid (a-2,19);
D[2]=atof(str1);
a=data.Find(".",a+1);
str1=data.Mid (a-2,19);
D[3]=atof(str1);
temp.SetSecondLine(D[0],D[1],D[2],D[3]); //設(shè)置第二行數(shù)據(jù)
//讀取第三行數(shù)據(jù)
gpsFile.ReadString (data);
data.TrimLeft ();
data.TrimRight ();
a=data.Find(".");
b=data.Find ("e");
str1=data.Mid (0,b+5);
D[0]=atof(str1);
a=data.Find(".",a+1);
str1=data.Mid (a-2,19);
D[1]=atof(str1);
a=data.Find(".",a+1);
str1=data.Mid (a-2,19);
D[2]=atof(str1);
a=data.Find(".",a+1);
str1=data.Mid (a-2,19);
D[3]=atof(str1);
temp.SetThirdLine(D[0],D[1],D[2],D[3]); //設(shè)置第三行數(shù)據(jù)
//讀取第四行數(shù)據(jù)
gpsFile.ReadString (data);
data.TrimLeft ();
data.TrimRight ();
a=data.Find(".");
b=data.Find ("e");
str1=data.Mid (0,b+5);
D[0]=atof(str1);
a=data.Find(".",a+1);
str1=data.Mid (a-2,19);
D[1]=atof(str1);
a=data.Find(".",a+1);
str1=data.Mid (a-2,19);
D[2]=atof(str1);
a=data.Find(".",a+1);
str1=data.Mid (a-2,19);
D[3]=atof(str1);
temp.SetForthLine (D[0],D[1],D[2],D[3]); //設(shè)置第四行數(shù)據(jù)
//讀取第五行數(shù)據(jù)
gpsFile.ReadString (data);
data.TrimLeft ();
data.TrimRight ();
a=data.Find(".");
b=data.Find ("e");
str1=data.Mid (0,b+5);
D[0]=atof(str1);
a=data.Find(".",a+1);
str1=data.Mid (a-2,19);
D[1]=atof(str1);
a=data.Find(".",a+1);
str1=data.Mid (a-2,19);
D[2]=atof(str1);
a=data.Find(".",a+1);
str1=data.Mid (a-2,19);
D[3]=atof(str1);
temp.SetFiveLine(D[0],D[1],D[2],D[3]); //設(shè)置第五行數(shù)據(jù)
//讀取第六行數(shù)據(jù)
gpsFile.ReadString (data);
data.TrimLeft ();
data.TrimRight ();
a=data.Find(".");
b=data.Find ("e");
str1=data.Mid (0,b+5);
D[0]=atof(str1);
a=data.Find(".",a+1);
str1=data.Mid (a-2,19);
D[1]=atof(str1);
a=data.Find(".",a+1);
str1=data.Mid (a-2,19);
D[2]=atof(str1);
a=data.Find(".",a+1);
str1=data.Mid (a-2,19);
D[3]=atof(str1);
temp.SetSixLine(D[0],D[1],D[2],D[3]); //設(shè)置第六行數(shù)據(jù)
//讀取第七行數(shù)據(jù)
gpsFile.ReadString (data);
data.TrimLeft ();
data.TrimRight ();
a=data.Find(".");
b=data.Find ("e");
str1=data.Mid (0,b+5);
D[0]=atof(str1);
a=data.Find(".",a+1);
str1=data.Mid (a-2,19);
D[1]=atof(str1);
a=data.Find(".",a+1);
str1=data.Mid (a-2,19);
D[2]=atof(str1);
a=data.Find(".",a+1);
str1=data.Mid (a-2,19);
D[3]=atof(str1);
temp.SetSevenLine(D[0]);
temp.GetGPSSeconds (year,month,day,hour,minute,second);
temp.CaculateCOR ();
m_gpsArray.Add (temp);
m_count++;
gpsFile.ReadString (data);
data.TrimLeft ();
data.TrimRight ();
}
gpsFile.Close ();
/////////////////以下顯示所求的衛(wèi)星坐標(biāo)
CString string1=" ";
CString str;
str.Format("\t");
/////
CString str_1,str_2,str_3,str_4,str_5;
str_1="衛(wèi)星號";
str_2="時間(y-m-d-h-m-s)";
str_3="坐標(biāo)(X)";
str_4="坐標(biāo)(Y)";
str_5="坐標(biāo)(Z)";
CString m_temp;
m_temp=str_1+" "+str_2+" "+str+str_3+str+" "+str+str_4+""+str+str+" "+str_5;
CString strPRN,strTimeZ;
CNavigationFile k;
CString string=" ";
for(int i=0;i<m_count ;i++)
{
k=m_gpsArray.GetAt (i);
PRN=k.GetPRN ();
strPRN.Format ("%d",PRN);
if(PRN<10)
{
strPRN=strPRN+" ";
}
//strTime.Format ("",);
string.Format ("\n %s %s %f %f %f ",strPRN,k.GetUCTTime (),k.GetX(),k.GetY(),k.GetZ());
string1+=string;
}
string1=m_temp+string1;
AfxMessageBox(string1);
}
void CGPSDoc::Open_Observe()
{
int i;
char *szFilter="Text Files(*.txt)|*txt|All Files(*.*)|*.*|GPS Files(*.dat)|*.dat||";
CFileDialog fo (true,"*.*",TEXT("gpsdata.txt") ,OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,szFilter);
fo.DoModal();
CString path=fo.GetPathName();
if(path=="gpsdata")
return;
//AfxMessageBox(path);
CString data;
if( !gpsFile.Open( path, CFile::modeRead ))
{
AfxMessageBox("文件打開失敗!");
return;
}
//讀取數(shù)據(jù)
int surveyCount;
int PRNS[20];
int year=0,month=0,day=0;
int hour=0,minute=0,second=0;
double L1[20],L2[20],P2[20],C1[20];
CString strPRNS;
CObserveFile temp;
gpsFile.ReadString (data);
data.TrimLeft ();
data.TrimRight ();
//跳過文件頭
while(data!="END OF HEADER")
{
gpsFile.ReadString (data);
data.TrimLeft ();
data.TrimRight ();
}
m_surveyCount=0;
int a=0;
gpsFile.ReadString (data);
data.TrimLeft ();
data.TrimRight ();
while(!data.IsEmpty ())
{
a=data.Find(" ");
year =atoi(data.Mid (0,a))+2000;
month =atoi(data.Mid (a+1,2));
a=data.Find(" ",a+1);
day =atoi(data.Mid (a+1,2));
a=data.Find(" ",a+1);
hour =atoi(data.Mid (a+1,2));
a=data.Find(" ",a+1);
minute =atoi(data.Mid (a+1,2));
a=data.Find(" ",a+1);
second =atoi(data.Mid (a+1,10));
a=data.Find(" ",a+3);
surveyCount=atoi(data.Mid (a+3,3));
temp.SetSurveyTime (CTime(year,month,day,hour,minute,second));
temp.SetSurveyCount (surveyCount);
strPRNS=data.Right(data.GetLength()-31);
strPRNS.TrimLeft ();
strPRNS.TrimRight ();
a=0;
for(i=0;i<surveyCount;i++)
{
PRNS[i]=atoi(strPRNS.Mid (a,2));
a=strPRNS.Find(" ",a+1)+1;
}
temp.SetPRNS (PRNS,surveyCount);
for(i=0;i<surveyCount;i++)
{
gpsFile.ReadString(data);
data=data.Mid (1,data.GetLength ()-2);
L1[i]=atof(data.Mid (0,15));
L2[i]=atof(data.Mid (17,15));
P2[i]=atof(data.Mid (33,15));
C1[i]=atof(data.Right(15));
}
temp.SetL1(L1,surveyCount);
temp.SetL2(L1,surveyCount);
temp.SetP2(P2,surveyCount);
temp.SetC1(C1,surveyCount);
m_gpsObserve.Add(temp);
m_surveyCount++;
gpsFile.ReadString (data);
data.TrimLeft ();
data.TrimRight ();
}
gpsFile.Close();
//檢查是否有導(dǎo)航文件
if(m_gpsArray.GetSize ()==0)
{
AfxMessageBox("您還沒有選擇導(dǎo)航文件");
Open();
}
//獲得衛(wèi)星坐標(biāo)及相應(yīng)鐘差
CObserveFile station;
CNavigationFile salite;
int isFind=0;
int isAllFind=1;
int isCan=0;
for(i=0;i<m_gpsObserve.GetSize();i++)
{
station=m_gpsObserve.GetAt (i);
isAllFind=1;
for(int j=0;j<station.GetSurveyCount ();j++)
{
isFind=0;
for(int k=0;m_gpsArray.GetSize ();k++)
{
salite=m_gpsArray.GetAt (k);
if (salite.GetPRN()==station.PRNS [j])
{
station.Salite [j]=salite;
isCan=1;
isFind=1;
break;
}
}
if(isFind==0)
{
//AfxMessageBox("不能在導(dǎo)航文件中找到所有觀測衛(wèi)星!");
isAllFind=0;
break;
}
}
if(isAllFind==1)
{
station.Salite[j] =salite;
m_gpsStation=station;
break;
}
}//數(shù)據(jù)完好衛(wèi)星查找完畢
if(isCan==1)
{
m_gpsStation.CaculateCor();
//ShowStationCor();
}
else
AfxMessageBox("數(shù)據(jù)不足,無法計算!");
////
CString str_2,str_3,str_4,str_5;
CString str="\t";
//CObserveFile k;
//str_1="衛(wèi)星號";
str_2="坐標(biāo)(X)";
str_3="坐標(biāo)(Y)";
str_4="坐標(biāo)(Z)";
str_5="坐標(biāo)(T)";
CString m_temp;
m_temp=" "+str_2+str+str+str_3+str+" "+str+str_4+str+" "+str_5;
CString string;
string.Format(" \n%f %f %f %f",m_gpsStation.GetX_O(),m_gpsStation.GetY_O(),m_gpsStation.GetZC(),m_gpsStation.GetZC());
AfxMessageBox(m_temp+string);
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -