(一)基于MATLAB读取RINEX3.02格式的接收机观测数据和卫星导航数据

基于MATLAB读取RINEX3.02格式的接收机观测数据和卫星导航数据
1.观测文件(.o)读取

%打开O文件
[filename,pathname] = uigetfile('*.??O','打开O文件');   
fid = fopen(strcat(pathname,filename),'rt');           

%读取头文件
while (1)                 
    line = fgets(fid);    
    if (line == -1)       
    end
    
    if (strfind(line,'APPROX POSITION XYZ')~= 0)      %读取测站近似坐标 ,存入结构体以备之后使用
        appro_x = str2double(line(1:14));               
        appro_y = str2double(line(15:28));            
        approx_z = str2double(line(29:42));
     end
    if (strfind(line,'DELTA H/E/N')~= 0)                %读取天线参数:高,东向、北向的偏心
        ant_h = str2double(line(1:14));
        ant_e = str2double(line(15:28));
        ant_n = str2double(line(29:42));
    end
    
    end
    if (strfind(line,'INTERVAL')~= 0)                  
        interval = str2double(line(1:11));
    end
    
    if (strfind(line,'TIME OF FIRST OBS')~= 0)        
        year(1,1) = str2double(line(1:6));           
        month(1,1) = str2double(line(7:12));
        day(1,1) = str2double(line(13:18));
        hour(1,1) = str2double(line(19:24));
        minute(1,1) = str2double(line(25:30));
        second(1,1) = str2double(line(31:43));
    end
    
    if (strfind(line,'END OF HEADER')~= 0)   
        break;
    end
end
%% 读取观测数据  
EPROCH_num = 0;                                          
while feof(fid)~= 1                                    
        EPROCH_num = EPROCH_num+1;                      %历元计数
        tline = fgetl(fid);                            
        chartline = char(tline) ;                       
        SatNum = str2double(chartline(34:35));          
        dline =  fgetl(fid); 
        %GPS
        NumPRN1 = 0 ;                                 
        for Nr = 1:SatNum                               
            chartline = char(fgetl(fid));               
            if (strfind(chartline,'G')~= 0)           
                NumPRN1 = NumPRN1 + 1 ;               
                GPS_Constellation = 1;                
                str2double(chartline(2:3)) ;    
                Obs(EPROCH_num).GPS( NumPRN1) .PRN= str2double(chartline(2:3)) ; 
                Obs(EPROCH_num).GPS( NumPRN1) .PseudoRange = str2double(chartline(6:17)); %伪距
                Obs(EPROCH_num).GPS( NumPRN1) .phase = str2double(chartline(21:33));      %载波相位
            end
end

2.导航文件(.n)读取

function [Nav,NavHead]=readGPSDATA3_02_n()
%% 打开文件
[filename,pathname] = uigetfile('*.??n','打开n文件');   
fid = fopen(strcat(pathname,filename),'rt');
%读取头文件
while(1)
  line=fgetl(fid);
  if (line == -1)       
        break;        
  end
  if (strfind(line(1:4),'GPSA')~=0)        %读GPS的α0-α3(电离层延时校正参数 Alpha0- Alpha3)
      NavHead.alpha(1) = str2num(line(9:17));  
      NavHead.alpha(2)= str2num(line(21:29));
      NavHead.alpha(3) = str2num(line(32:41));
      NavHead.alpha(4) = str2num(line(44:53));
  end                                    
  
  if (strfind(line(1:4),'GPSB')~=0 )       %读GPS的β0-β3(电离层延时校正参数 Beta0- Beta3)
      NavHead.beta(1)= str2num(line(9:17));
      NavHead.beta(2)= str2num(line(21:29));
      NavHead.beta(3)= str2num(line(32:41));
      NavHead.beta(4) = str2num(line(44:53));
  end
  
  if (strfind(line(1:4),'GPUT')~=0)      %读GPS到UTC时的转换数据,CORR=a0+a1*deltat
      NavHead.utc(1) = str2num(line(8:22));   %a0
      NavHead.utc(2) = str2num(line(25:38));  %a1
      NavHead.utc(3) = str2num(line(40:45));  %T,UTC数据参考时刻
      NavHead.utc(4) = str2num(line(47:50));  %W,UTC参考周数
  end
  
  if (strfind(line(61:72),'LEAP SECONDS')~=0)   %由于跳秒产生的时间差
      NavHead.leap=str2num(line(1:6));
  end
  
    if (strfind(line,'END OF HEADER')~= 0)     
        break;
    end
end

%% 读导航电文星历数据
   i=0;
 while feof(fid)==0
   i=i+1;
   line = fgetl(fid);%0
   Nav(i).prn=str2num(line(2:3));
   year =str2num(line(5:8));
   month = str2num(line(10:11));
   day = str2num(line(13:14));
   hour = str2num(line(16:17));
   minute = str2num(line(19:20));
   second =str2num(line(22:23));
   cal=[year,month,day,hour,minute,second];
   Nav(i).toe=cal2gps(cal);                               %参考时间toe
   Nav(i).bias= str2num(line(25:42));                     %卫星钟偏差 (s) af0
   Nav(i).drift = str2num(line(44:61));                   %卫星钟漂移 (s/s) af1
   Nav(i).rate = str2num(line(64:80));                    %卫星钟漂移速度 (s/s^2) af2
   line = fgetl(fid);%1
   Nav(i).iode = str2num(line(5:23));                      
   Nav(i).crs =str2num(line(25:42));                      
   Nav(i).dn = str2num(line(44:61));                      %平均角速度校正值
   Nav(i).M0 = str2num(line(63:80));                      %平近点角
    line = fgetl(fid);%2
   Nav(i).cuc =str2num(line(5:23));                      
   Nav(i).ec = str2num(line(25:42));                      %椭圆轨道偏心率
   Nav(i).cus = str2num(line(44:61));
   Nav(i).sqrtA = str2num(line(63:80));                   %椭圆长半轴平方根
    line = fgetl(fid);%3
   Nav(i).toe = str2num(line(7:23));
   Nav(i).cic = str2num(line(25:42));
   Nav(i).OMEGA0 = str2num(line(44:61));
   Nav(i).cis = str2num(line(63:80));
    line = fgetl(fid);%4
   Nav(i).i0 = str2num(line(5:23));                       %toe时刻轨道倾角
   Nav(i).crc = str2num(line(25:42));
   Nav(i).omega =str2num(line(44:61));                    %轨道近地角距
   Nav(i).OMEGAdot = str2num(line(63:80));
    line = fgetl(fid);%5
   Nav(i).idt = str2num(line(5:23));                      %轨道倾角对时间的变化率
   Nav(i).cflgl2 = str2num(line(25:42));
   Nav(i).weekno = str2num(line(44:61));
   Nav(i).pflgl2 = str2num(line(63:80));
    line = fgetl(fid);%6
   Nav(i).svacc = str2num(line(5:23));
   Nav(i).svhlth = str2num(line(25:42));
   Nav(i).tgd = str2num(line(43:61));                    %卫星群延迟时间参数,表征卫星不同频率信号通道之间的延迟偏差
   Nav(i).iodc =str2num(line(63:80));
    line = fgetl(fid);%7
   Nav(i).transmit =str2num(line(5:23));
   Nav(i).fitint = str2num(line(25:42));  
 end

你可能感兴趣的:(伪距单点定位,matlab,gnss)