当前位置:首页 > 行业资料 > 交通运输 > 利用MATLAB编制的GPS单点定位程序
functiont=TimetoJD(Y,M,D,h,f,s)if(Y=80)Y=Y+1900;elseY=Y+2000;endifM=2Y=Y-1;M=M+12;endJD=fix(365.25*Y)+fix(30.6001*(M+1))+D+h/24+f/1440+s/24/3600+1720981.5;t=JD-2444244.5;function[head,obs]=ReadObsData%读接收机观测数据文件%HeadODat:astructurestoresheaderinformationifo-file%.ApproXYZ[3];//approximatecoordinate%.interval;//intervalsoftwoadjacentepochs%.SiteName;//pointname%.Ant_H;//antennaheight%.Ant_E;//eastoffsetoftheantennacenter%.Ant_N;//northoffsetofthenantennacenter%.TimeOB;//firstepochtimeinmodifuiedJuliantime%.TimeOE;//lastepochtimeinmodifuiedJuliantime%.SumOType;//numberoftypesofobservables%.SumOO[SumOType];//typeofobservables0-L1,1-L2,2-C1,3-P1,4-P2,5-D1,6-D2,%ObsODat:astructurestoresobservablesbyoneandoneepoch%.TimeOEpp[2];//recievertimeofepoch%.SatSum;//numberofsatellites%.SatCode[SatSum];//satellites'PRN%.Obs_FreL1[SatSum];%.Obs_FreL2[SatSum];%.Obs_RangeC1[SatSum];%.Obs_RangeP1[SatSum];%.Obs_RangeP2[SatSum];globalHeadODat;globalObsODat;[fname,fpath]=uigetfile('*.*','选择一个O文件');O_filename=strcat(fpath,fname);fid1=fopen(O_filename,'rt');if(fid1==-1)msgbox('fileinvalide','warning','warn');return;end%将文件头数据存入结构体HeadODat中t=0;while(t100)s=fgets(fid1);t=t+1;L=size(s,2);ifL81s(L+1:81)='';endinstrS=s(61:81);%测站点近似坐标ifstrncmp(instrS,'APPROXPOSITIONXYZ',19)HeadODat.ApproXYZ=zeros(1,3);HeadODat.ApproXYZ(1,1)=str2num(s(1:14));HeadODat.ApproXYZ(1,2)=str2num(s(15:28));HeadODat.ApproXYZ(1,3)=str2num(s(29:42));%历元间隔;elseifstrncmp(instrS,'INTERVAL',8)HeadODat.interval=str2num(s(5:11));%测站点号elseifstrncmp(instrS,'MARKERNAME',11)HeadODat.SiteName=s(1:4)%天线中心改正elseifstrncmp(instrS,'ANTENNA:DELTAH/E/N',20)HeadODat.Ant_H=str2num(s(1:14));HeadODat.Ant_E=str2num(s(15:28));HeadODat.Ant_N=str2num(s(29:42));%第一个历元时间elseifstrncmp(instrS,'TIMEOFFIRSTOBS',17)year=str2num(s(1:6));month=str2num(s(7:12));day=str2num(s(13:18));hour=str2num(s(19:24));minute=str2num(s(25:30));second=str2num(s(31:42));HeadODat.TimeOB=TimetoJD(year,month,day,hour,minute,second);%最后一个历元时间elseifstrncmp(instrS,'TIMEOFLASTOBS',16)year=str2num(s(1:6));month=str2num(s(7:12));day=str2num(s(13:18));hour=str2num(s(19:24));minute=str2num(s(25:30));second=str2num(s(31:42));HeadODat.TimeOE=TimetoJD(year,month,day,hour,minute,second);%观测值类型elseifstrncmp(instrS,'#/TYPESOFOBSERV',19)HeadODat.SumOType=str2num(s(1:6));HeadODat.SumOO=ones(1,HeadODat.SumOType)*-1;fork=1:HeadODat.SumOTypef=s(k*6+5:k*6+6);ifstrcmp(f,'L1')HeadODat.SumOO(1,k)=0;elseifstrcmp(f,'L2')HeadODat.SumOO(1,k)=1;elseifstrcmp(f,'C1')HeadODat.SumOO(1,k)=2;elseifstrcmp(f,'P1')HeadODat.SumOO(1,k)=3;elseifstrcmp(f,'P2')HeadODat.SumOO(1,k)=4;elseifstrcmp(f,'D1')HeadODat.SumOO(1,k)=5;elseifstrcmp(f,'D2')HeadODat.SumOO(1,k)=6;endend%头文件结束elseifstrncmp(instrS,'ENDOFHEADER',13)break;elsecontinue;endend%观测数据结构体%观测数据结构t=0;while~feof(fid1)%每个历元的第一行数据,时间和观测到的卫星号s=fgets(fid1);t=t+1;year=str2num(s(1:3));month=str2num(s(4:6));day=str2num(s(7:9));hour=str2num(s(10:12));minute=str2num(s(13:15));second=str2num(s(16:26));%历元时间ObsODat(t).TimeOEp=[year,month,day,hour,minute,second];ObsODat(t).TimeOEpp=TimetoJD(year,month,day,hour,minute,second);%该历元观测到的卫星数ObsODat(t).SatSum=str2num(s(30:32));%该历元观测到的卫星号ObsODat(t).SatCode=zeros(1,ObsODat(t).SatSum);ObsODat(t).Obs_FreL1=zeros(1,ObsODat(t).SatSum);ObsODat(t).Obs_FreL2=zeros(1,ObsODat(t).SatSum);ObsODat(t).Obs_RangeC1=zeros(1,ObsODat(t).SatSum);ObsODat(t).Obs_RangeP1=zeros(1,ObsODat(t).SatSum);ObsODat(t).Obs_RangeP2=zeros(1,ObsODat(t).SatSum);fork=1:ObsODat(t).SatSumf=s(31+k*3:32+k*3);ObsODat(t).SatCode(1,k)=str2num(f);end%每个历元的观测数据,按卫星号先后顺序分行存fork=1:ObsODat(t).SatSums=fgets(fid1);%判断一个卫星的观测数据是否分两行存储,如果为两行,则再读入一行ifHeadODat.SumOType5sg=fgets(fid1);s=strcat(s,sg);endL=size(s,2);%补充数据长度ifLHeadODat.SumOType*16s(L+1:HeadODat.SumOType*16)='';end%对观测数据判断其类型,并存储到相应的数组中forj=1:HeadODat.SumOTypestemp=s(j*16-15:j*16);stemp=deblank(stemp);ifisempty(stemp)continue;endstempNum=str2num(stemp);stempLength=size(stempNum,2);ifstempLength1stempNum=stempNum(1,1);endifHeadODat.SumOO(1,j)==0ObsODat(t).Obs_FreL1(1,k)=stempNum;elseifHeadODat.SumOO(1,j)==1ObsODat(t).Obs_FreL2(1,k)=stempNum;elseifHeadODat.SumOO(1,j)==2ObsODat(t).Obs_RangeC1(1,k)=stempNum;elseifHeadODat.SumOO(1,j)==3ObsODat(t).Obs_RangeP1(1,k)=stempNum;elseifHeadODat.SumOO(1,j)==4ObsODat(t).Obs_RangeP2(1,k)=stempNum;elsecontinue;endend%完成一个卫星的所有观测数据存储end%完成一个历元的数据存储end%完成所有历元的数据存储head=HeadODat;obs=ObsODat;returnfunctionEphDat=ReadGpsDataglobalEphDatEphDat=struct;[filename,pathname]=uigetfile('*.**N','读取GPS广播星历文件');fid1=fopen(strcat(pathname,filename),'rt');if(fid1==-1)msgbox('InputFileorPathisnotcorrect','warning','warn');return;endwhile(1)temp=fgetl(fid1);header=findstr(temp,'ENDOFHEADER');if(~isempty(header))break;endendi=1;while(1)temp=fgetl(fid1);if(temp==-1)break;endEphDat(i).PRN=str2double(temp(1:2));year=str2double(temp(3:5));EphDat(i).toc=TimetoJD(year,str2double(temp(6:8)),str2double(temp(9:11)),str2double(temp(12:14)),str2double(temp(15:17)),str2double(temp(18:22)));EphDat(i).a0=str2num(temp(23:41));EphDat(i).a1=str2num(temp(42:60));E
本文标题:利用MATLAB编制的GPS单点定位程序
链接地址:https://www.777doc.com/doc-4883031 .html