导航文件头部分


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

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

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

首先使用fopen打开文件。

%打开文件
Navifile=fopen(NaviFilePath);
%判断文件是否读取成功
if Navifile<0error('文件读取失败。');
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));endif contains(str,'ION ALPHA')str=strrep(str,'D','e');  %将D替换为eIonAlpha(1)=str2double(str(5:14));IonAlpha(2)=str2double(str(17:26));IonAlpha(3)=str2double(str(28:38));IonAlpha(4)=str2double(str(40:50));endif 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)==0satellite(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),' ',''));endif mod(line,8)==1satellite(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),' ',''));endif mod(line,8)==2satellite(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),' ',''));endif mod(line,8)==3satellite(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),' ',''));endif mod(line,8)==4satellite(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),' ',''));endif mod(line,8)==5satellite(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),' ',''));endif mod(line,8)==6satellite(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),' ',''));endif mod(line,8)==7satellite(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<0error('文件读取失败。');
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));endif 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));endif 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)==0satellite(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),' ',''));endif mod(line,8)==1satellite(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),' ',''));endif mod(line,8)==2satellite(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),' ',''));endif mod(line,8)==3satellite(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),' ',''));endif mod(line,8)==4satellite(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),' ',''));endif mod(line,8)==5satellite(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),' ',''));endif mod(line,8)==6satellite(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),' ',''));endif mod(line,8)==7satellite(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

MATLAB--读取广播星历的导航文件相关推荐

  1. Matlab 读取 gprmax 的 out 文件详细解释

    Matlab 读取 gprmax 的 out 文件规律详细解释. out 文件是hdf5格式的文件,普通软件无法读取.out 文件有一定的规律,在matlab平台上简单操作一下,就可以深刻理解 out ...

  2. Matlab读取并输出stl文件

    *#利用matlab读取stl文件后,将其中三角形片数据×2后,保存到另一个stl文件,利用3D软件打开观察图形是否变为两倍.那么应该怎么做呢? 首先了解一下stl文件 STL(Stereo lith ...

  3. matlab读取其他位置,将文件的数据读取到matlab中,进行编辑,然后将其保存到其他位置...

    将文件的数据读取到matlab中,进行编辑,然后将其保存到其他位置 我有一个名为EXP1_SQ1_Template.txt的文件.这是一个简单的文本文件,包含以下8行: LOAD BOX 1 SUBJ ...

  4. MATLAB读取和写入Excel文件

    1. 读取Excel文件 (a) 命令方式xlsread:  读取命令:[data,text]  = xlsread(FileName, SheetName, Range); data保存的是数据单元 ...

  5. matlab分析gnss数据,Matlab读取GNSS 观测值o文件代码示例

    一.准备工作 观测值数据读取是进行数据处理的前提,通常,观测值的数据格式有rtcm.ubx.rinex,各家厂商还有自定义的格式.数据读取是最简单的工作,掌握了数据组织格式即掌握了数据读取策略,简言之 ...

  6. matlab读数据写入excel文件路径,MATLAB读取和写入Excel文件

    clc; clear all; [numeric_data text_data rawdata] = xlsread('aaa.xls'); headings = rawdata(1,:)  % ge ...

  7. .flo 文件转换为.png 文件 ; matlab 读取 .ppm 和 .flo 文件

    使用光流场过程中,会用到图像的.ppm格式和光流场.flo格式. 1. ppm文件,直接拖动到matlab的workspace即可读取 2. flo文件,需要先下载并编译imageLib工具包.下载地 ...

  8. MATLAB读取结构体mat文件报错已损坏

    遇到一个挺奇怪的事情,用MATLAB R2021a保存下来的.mat文件,里面是一个结构体:结果在MATLAB R2018b中load这个mat文件,提示"无法读取,改文件可能已损坏&quo ...

  9. matlab读取.fdt和.set文件转为.mat

    .fdt这种文件一般都是用EEGLAB读取的脑电信号,那么这个工具箱里面肯定有读.fdt文件的函数啊, 这个函数就是pop_loadset.m,可以搞出来单独使用,像这样就能把它读到你的工作区成为ma ...

  10. matlab读取指定路径excel文件,MATLAB读取Excel文件

    调试了好几个小时,点击名字成绩就是出不来,以为是玄学,后来终于发现,哪有什么玄学,其实就是无知,丢了一句guidata(hObject, handles); 1.guidata - 存储或检索 UI ...

最新文章

  1. Linux C++写日志
  2. 如何在云服务器上安装vim(bash: vim :command not found)
  3. x265与SVT-HEVC现已合二为一
  4. LDAP命令介绍---dsreplication
  5. 即将到来的“分布式云”(DPaaS):分布式计算+ DB +存储即服务
  6. 设计一个媒体类,其中包含:书,CD及磁带3个子类。按照类的设计模式,完成他们的插入、删除和查找功能。
  7. 实战CSS:静态百度首页实现
  8. IOS-Tom猫小游戏实现
  9. 服装免费收银系统哪个好-云上铺会员管理软件
  10. 解决win10+Ubuntu20.0.4双系统,win10时间错误问题
  11. LeetCode刷题小技巧-错题记录本-C++版本
  12. this的理解 转https://www.cnblogs.com/pssp/p/5216085.html#!comments
  13. Python MySQLdb 模块使用方法
  14. 计算机中专实训方案,中职学校计算机专业实训模式初探
  15. 软件开发实训(720科技)水库大坝安全监测监控平台
  16. 外企做开发,爽吗?(HSBC篇)
  17. Python灰帽子环境配置
  18. JAVA SE知识整合(暂时完结 五万七字)后续分点详解
  19. 防网络广告作弊(点击欺诈)的八种方法
  20. 公交车到站预测2----数据后处理

热门文章

  1. Win10正式版怎么卸载IE浏览器?
  2. 软件设计师之朴素的模式匹配算法
  3. python——基础应用:顺丰快递分拣小程序的实现
  4. Amy Cuddy: Your body language shapes who you are
  5. asp.net发邮件
  6. video sematic segmentation视频语义分割方向相关论文罗列+数据集下载链接
  7. 多尺度特征的融合操作
  8. 创建型模式大全(Java讲解)
  9. VGA高速PCB布局布线设计指南
  10. line划线计算机图像学,计算机图形学DDA画线法+中点画线法+Bresenham画线法(示例代码)...