MATLAB--读取广播星历的导航文件

导航文件头部分

在这里插入图片描述
上图为导航文件头,最右侧英文数据为每行数据说明。
我们需要读取文件版本,即第一行的2.10;
读取第三行和第四行的ION ALPHA和ION BETA。
其余数据不需要读取。

文件头以 END of HEADER为结束标志,故当我们读取到字符串END of HEADER 表示文件头部分已经读取完毕。

上一篇博客已经介绍了读取卫星星历文件所需要的关键函数,本问不再赘述,请自行查阅链接: MATLAB–读取2.11版本卫星观测值文件

首先使用fopen打开文件。

%打开文件
Navifile=fopen(NaviFilePath);
%判断文件是否读取成功
if Navifile<0
    error('文件读取失败。');
end

读取文件头部分
由于卫星星历文件的每个数据所占字符都是特定的,所以将每行数据读入字符串中,从字符串中截取特定位置的数据即可获得所需数据。

同时还可以发现,卫星星历文件中的科学计数法使用的是D而不是e,但是matlab只能识别e,所以我们需要使用sttrep将D替换为e再转换为浮点型数据

%文件行数
line=0;
%读取文件头
IonAlpha=zeros(4,1);
IonBeta=zeros(4,1);
str='';
while ~contains(str,'END OF HEADER') %读取到END OF HEADER结束文件头读取
    str=fgetl(Navifile);
    line=line+1;
    if contains(str,'RINEX VERSION / TYPE')
        type=str2double(str(6:9));
    end
    
    if contains(str,'ION ALPHA')
        str=strrep(str,'D','e');  %将D替换为e
        IonAlpha(1)=str2double(str(5:14));
        IonAlpha(2)=str2double(str(17:26));
        IonAlpha(3)=str2double(str(28:38));
        IonAlpha(4)=str2double(str(40:50));
    end
    
    if contains(str,'ION BETA')
        str=strrep(str,'D','e');
        IonBeta(1)=str2double(str(5:15));
        IonBeta(2)=str2double(str(17:27));
        IonBeta(3)=str2double(str(28:39));
        IonBeta(4)=str2double(str(40:51));
    end
end

读取文件数据

在这里插入图片描述
上图为截取的部分数据,其中第8行到15行、16行到23行为一组数据。每组数据占8行。下图为上述每组数据的详细描述。读者也可以查阅RINEX2.11版本数据格式说明。
在这里插入图片描述
使用结构体将每种数据存入到结构体下的字段里,便于管理。
读取数据

%读取数据
i=1;%卫星数量
while ~feof(Navifile)
    str=fgetl(Navifile);
    str=strrep(str,'D','e');
    line=line+1;
    if mod(line,8)==0
        satellite(i).PRN=str2double(strrep(str(1:2),' ',''));
        satellite(i).Year=str2double(str(4:5));
        satellite(i).Month=str2double(str(7:8));
        satellite(i).Day=str2double(str(10:11));
        satellite(i).Hour=str2double(str(13:14));
        satellite(i).Minute=str2double(str(16:17));
        satellite(i).Second=str2double(strrep(str(19:22),' ',''));
        satellite(i).ClockBias=str2double(strrep(str(23:41),' ',''));
        satellite(i).ClockDirft=str2double(strrep(str(42:60),' ',''));
        satellite(i).ClockDirftRate=str2double(strrep(str(61:79),' ',''));
    end
    if mod(line,8)==1
        satellite(i).IodeIssueofData=str2double(strrep(str(4:22),' ',''));
        satellite(i).Crs=str2double(strrep(str(23:41),' ',''));
        satellite(i).Delta_n=str2double(strrep(str(42:60),' ',''));
        satellite(i).M0=str2double(strrep(str(61:79),' ',''));
    end
    if mod(line,8)==2
        satellite(i).Cuc=str2double(strrep(str(4:22),' ',''));
        satellite(i).e=str2double(strrep(str(23:41),' ',''));
        satellite(i).Cus=str2double(strrep(str(42:60),' ',''));
        satellite(i).sqrt_A=str2double(strrep(str(61:79),' ',''));
    end
    if mod(line,8)==3
        satellite(i).toe=str2double(strrep(str(4:22),' ',''));
        satellite(i).Cic=str2double(strrep(str(23:41),' ',''));
        satellite(i).OMEGA=str2double(strrep(str(42:60),' ',''));
        satellite(i).Cis=str2double(strrep(str(61:79),' ',''));
    end
    if mod(line,8)==4
        satellite(i).i0=str2double(strrep(str(4:22),' ',''));
        satellite(i).Crc=str2double(strrep(str(23:41),' ',''));
        satellite(i).omega=str2double(strrep(str(42:60),' ',''));
        satellite(i).OMEGADOT=str2double(strrep(str(61:79),' ',''));
    end
    if mod(line,8)==5
        satellite(i).IDOT=str2double(strrep(str(4:22),' ',''));
        satellite(i).CodesOnL2Channel=str2double(strrep(str(23:41),' ',''));
        satellite(i).GPSWeek=str2double(strrep(str(42:60),' ',''));
        satellite(i).L2_p_data_flag=str2double(strrep(str(61:79),' ',''));
    end
    if mod(line,8)==6
        satellite(i).SV_accuracy=str2double(strrep(str(4:22),' ',''));
        satellite(i).SV_health=str2double(strrep(str(23:41),' ',''));
        satellite(i).TGD=str2double(strrep(str(42:60),' ',''));
        satellite(i).IODC_Issue_of_Data=str2double(strrep(str(61:79),' ',''));
    end
    if mod(line,8)==7
        satellite(i).Transmission_time_of_message=str2double(strrep(str(4:22),' ',''));
        satellite(i).Fit_interval=str2double(strrep(str(23:41),' ',''));
        i=i+1;
    end
end

完整代码

%读取导航电文文件

function [IonAlpha,IonBeta,satellite]=ReadNaviFiles(NaviFilePath)
%打开文件
Navifile=fopen(NaviFilePath);
%判断文件是否读取成功
if Navifile<0
    error('文件读取失败。');
end

%文件行数
line=0;
%读取文件头
IonAlpha=zeros(4,1);
IonBeta=zeros(4,1);
str='';
while ~contains(str,'END OF HEADER')
    str=fgetl(Navifile);
    line=line+1;
    if contains(str,'RINEX VERSION / TYPE')
        type=str2double(str(6:9));
    end
    
    if contains(str,'ION ALPHA')
        str=strrep(str,'D','e');
        IonAlpha(1)=str2double(str(5:14));
        IonAlpha(2)=str2double(str(17:26));
        IonAlpha(3)=str2double(str(28:38));
        IonAlpha(4)=str2double(str(40:50));
    end
    
    if contains(str,'ION BETA')
        str=strrep(str,'D','e');
        IonBeta(1)=str2double(str(5:15));
        IonBeta(2)=str2double(str(17:27));
        IonBeta(3)=str2double(str(28:39));
        IonBeta(4)=str2double(str(40:51));
    end
end
%读取数据
i=1;
while ~feof(Navifile)
    str=fgetl(Navifile);
    str=strrep(str,'D','e');
    line=line+1;
    if mod(line,8)==0
        satellite(i).PRN=str2double(strrep(str(1:2),' ',''));
        satellite(i).Year=str2double(str(4:5));
        satellite(i).Month=str2double(str(7:8));
        satellite(i).Day=str2double(str(10:11));
        satellite(i).Hour=str2double(str(13:14));
        satellite(i).Minute=str2double(str(16:17));
        satellite(i).Second=str2double(strrep(str(19:22),' ',''));
        satellite(i).ClockBias=str2double(strrep(str(23:41),' ',''));
        satellite(i).ClockDirft=str2double(strrep(str(42:60),' ',''));
        satellite(i).ClockDirftRate=str2double(strrep(str(61:79),' ',''));
    end
    if mod(line,8)==1
        satellite(i).IodeIssueofData=str2double(strrep(str(4:22),' ',''));
        satellite(i).Crs=str2double(strrep(str(23:41),' ',''));
        satellite(i).Delta_n=str2double(strrep(str(42:60),' ',''));
        satellite(i).M0=str2double(strrep(str(61:79),' ',''));
    end
    if mod(line,8)==2
        satellite(i).Cuc=str2double(strrep(str(4:22),' ',''));
        satellite(i).e=str2double(strrep(str(23:41),' ',''));
        satellite(i).Cus=str2double(strrep(str(42:60),' ',''));
        satellite(i).sqrt_A=str2double(strrep(str(61:79),' ',''));
    end
    if mod(line,8)==3
        satellite(i).toe=str2double(strrep(str(4:22),' ',''));
        satellite(i).Cic=str2double(strrep(str(23:41),' ',''));
        satellite(i).OMEGA=str2double(strrep(str(42:60),' ',''));
        satellite(i).Cis=str2double(strrep(str(61:79),' ',''));
    end
    if mod(line,8)==4
        satellite(i).i0=str2double(strrep(str(4:22),' ',''));
        satellite(i).Crc=str2double(strrep(str(23:41),' ',''));
        satellite(i).omega=str2double(strrep(str(42:60),' ',''));
        satellite(i).OMEGADOT=str2double(strrep(str(61:79),' ',''));
    end
    if mod(line,8)==5
        satellite(i).IDOT=str2double(strrep(str(4:22),' ',''));
        satellite(i).CodesOnL2Channel=str2double(strrep(str(23:41),' ',''));
        satellite(i).GPSWeek=str2double(strrep(str(42:60),' ',''));
        satellite(i).L2_p_data_flag=str2double(strrep(str(61:79),' ',''));
    end
    if mod(line,8)==6
        satellite(i).SV_accuracy=str2double(strrep(str(4:22),' ',''));
        satellite(i).SV_health=str2double(strrep(str(23:41),' ',''));
        satellite(i).TGD=str2double(strrep(str(42:60),' ',''));
        satellite(i).IODC_Issue_of_Data=str2double(strrep(str(61:79),' ',''));
    end
    if mod(line,8)==7
        satellite(i).Transmission_time_of_message=str2double(strrep(str(4:22),' ',''));
        satellite(i).Fit_interval=str2double(strrep(str(23:41),' ',''));
        i=i+1;
    end
end
end
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值