function NavDataMatrix = ReadNavFile(filename)
filename1=uigetfile('*.txt','打开RINEX.N格式广播星历文件');
fid = fopen(filename, 'r');
LineNum = 0;
while (~feof(fid))
CurLine = textscan(fid,'%s',1,'delimiter','\n');
LineNum = LineNum + 1;
end
frewind(fid);
EphemerisNum = fix(LineNum/8)-1; %计算历元个数
%--------------------------------------------------------------------------
% 导航数据文件-文件头描述
% (文件头共8行,行与行之间使用'\n'隔开)
%+------------------+-----------------------------------------+-----------+
%| 信息标识(61-80列) | 说明 | 格式 |
%+------------------+-----------------------------------------+-----------+
%|RINEX VERSION/TYPE| - 版本 (2) | I6,14X |
%| | - 文件类型 ('N'表示导航数据) | A1,19X |
%+------------------+-----------------------------------------+-----------+
%|PGM/RUN BY/DATE | - 创建当前导航文件的程序名称 | A20 |
%| | - 创建当前导航文件的单位名称 | A20 |
%| | - 文件创建日期 | A20 |
%+------------------+-----------------------------------------+-----------+
%|COMMENT | - 导航文件注释行 | A60 |
%+------------------+-----------------------------------------+-----------+
%|ION ALPHA | - 星历中的电离层参数A0-A3 | 2X,4D12.4 |
%| | (第4子帧第18页) | |
%+------------------+-----------------------------------------+-----------+
%|ION BETA | - 星历中的电离层参数B0-B3 | 2X,4D12.4 |
%+------------------+-----------------------------------------+-----------+
%|DELTA-UTC: A0,A1, | - 计算UTC时间的星历参数 | 3X,2D19. |
%| T,W | (第4子帧第18页) | 12,2I9 |
%| | A0,A1: 多项式系数 | |
%| | T : UTC数据的参考时间 | |
%| | W : UTC参考周数 | |
%+------------------+-----------------------------------------+-----------+
%|LEAP SECONDS | - 跳秒 | I6 |
%+------------------+-----------------------------------------+-----------+
%|END OF HEADER | - 文件头结尾 | 60X |
%+------------------+-----------------------------------------+-----------+
HeaderLines=textscan(fid,'%s',8,'delimiter','\n'); %读文件头
NavDataMatrix = zeros(EphemerisNum,38); %定义矩阵
for i = 1:EphemerisNum
%----------------------------------------------------------------------
% 读取一个参考历元
%----------------------------------------------------------------------
CurLine = fgetl(fid); %参考历元第1行
% Prn 年 月 日 时 分 秒 卫星时钟偏差 卫星时钟漂移 卫星时钟漂移率
NavDataMatrix(i, 1) = str2num(CurLine(1:2));
if (str2num(CurLine(3:4)) > 80)
NavDataMatrix(i, 2) = 1900 + str2num(CurLine(4:5));
else
NavDataMatrix(i, 2) = 2000 + str2num(CurLine(5:5));
end
NavDataMatrix(i, 3) = str2num(CurLine(7:8));
NavDataMatrix(i, 4) = str2num(CurLine(10:11));
NavDataMatrix(i, 5) = str2num(CurLine(13:14));
NavDataMatrix(i, 6) = str2num(CurLine(16:17));
NavDataMatrix(i, 7) = str2double(CurLine(19:22));
tmpNumber = textscan(CurLine(23:41),'%f'); NavDataMatrix(i, 8) = tmpNumber{1};
tmpNumber = textscan(CurLine(42:60),'%f'); NavDataMatrix(i, 9) = tmpNumber{1};
tmpNumber = textscan(CurLine(61:79),'%f'); NavDataMatrix(i, 10) = tmpNumber{1};
CurLine=fgetl(fid); %参考历元第2行
tmpNumber = textscan(CurLine(1:22),'%f'); NavDataMatrix(i, 11) = tmpNumber{1};
tmpNumber = textscan(CurLine(23:41),'%f'); NavDataMatrix(i, 12) = tmpNumber{1};
tmpNumber = textscan(CurLine(42:60),'%f'); NavDataMatrix(i, 13) = tmpNumber{1};
tmpNumber = textscan(CurLine(61:79),'%f'); NavDataMatrix(i, 14) = tmpNumber{1};
CurLine=fgetl(fid); %参考历元第3行
tmpNumber = textscan(CurLine(1:22),'%f'); NavDataMatrix(i, 15) = tmpNumber{1};
tmpNumber = textscan(CurLine(23:41),'%f'); NavDataMatrix(i, 16) = tmpNumber{1};
tmpNumber = textscan(CurLine(42:60),'%f'); NavDataMatrix(i, 17) = tmpNumber{1};
tmpNumber = textscan(CurLine(61:79),'%f'); NavDataMatrix(i, 18) = tmpNumber{1};
CurLine=fgetl(fid); %参考历元第4行
tmpNumber = textscan(CurLine(1:22),'%f'); NavDataMatrix(i, 19) = tmpNumber{1};
tmpNumber = textscan(CurLine(23:41),'%f'); NavDataMatrix(i, 20) = tmpNumber{1};
tmpNumber = textscan(CurLine(42:60),'%f'); NavDataMatrix(i, 21) = tmpNumber{1};
tmpNumber = textscan(CurLine(61:79),'%f'); NavDataMatrix(i, 22) = tmpNumber{1};
CurLine=fgetl(fid); %参考历元第5行
tmpNumber = textscan(CurLine(1:22),'%f'); NavDataMatrix(i, 23) = tmpNumber{1};
tmpNumber = textscan(CurLine(23:41),'%f'); NavDataMatrix(i, 24) = tmpNumber{1};
tmpNumber = textscan(CurLine(42:60),'%f'); NavDataMatrix(i, 25) = tmpNumber{1};
tmpNumber = textscan(CurLine(61:79),'%f'); NavDataMatrix(i, 26) = tmpNumber{1};
CurLine=fgetl(fid); %参考历元第6行
tmpNumber = textscan(CurLine(1:22),'%f'); NavDataMatrix(i, 27) = tmpNumber{1};
tmpNumber = textscan(CurLine(23:41),'%f'); NavDataMatrix(i, 28) = tmpNumber{1};
tmpNumber = textscan(CurLine(42:60),'%f'); NavDataMatrix(i, 29) = tmpNumber{1};
tmpNumber = textscan(CurLine(61:79),'%f'); NavDataMatrix(i, 30) = tmpNumber{1};
CurLine=fgetl(fid); %参考历元第7行
tmpNumber = textscan(CurLine(1:22),'%f'); NavDataMatrix(i, 31) = tmpNumber{1};
tmpNumber = textscan(CurLine(23:41),'%f'); NavDataMatrix(i, 32) = tmpNumber{1};
tmpNumber = textscan(CurLine(42:60),'%f'); NavDataMatrix(i, 33) = tmpNumber{1};
tmpNumber = textscan(CurLine(61:79),'%f'); NavDataMatrix(i, 34) = tmpNumber{1};
CurLine=fgetl(fid); %参考历元第8行
tmpNumber = textscan(CurLine(1:22),'%f'); NavDataMatrix(i, 35) = tmpNumber{1};
tmpNumber = textscan(CurLine(23:41),'%f'); NavDataMatrix(i, 36) = tmpNumber{1};
tmpNumber = textscan(CurLine(42:60),'%f'); NavDataMatrix(i, 37) = tmpNumber{1};
tmpNumber = textscan(CurLine(61:79),'%f'); NavDataMatrix(i, 38) = tmpNumber{1};
%----------------------------------------------------------------------
% 结束读取一个参考历元
%----------------------------------------------------------------------
end
clear HeaderLines;
fclose(fid);