function [nav]=readnav(filename) % ----------------------------------------------------------------------------- % Purpose: Read GPS RINEX Navigation File % % Input: filname - GPS navigation file name % Output: nav(i,1) - PRN Nr % nav(i,2) - GPS week % nav(i,3) - GPS seconds % nav(i,4:34) - nav messages % % size (nav,1): number of message blocks % % Remark: The function buffers the content of the file. If called a second % time using the same filename it simply returns the content of % the buffer. % % Author: Urs Hugentobler, FESG % Date : 19-10-2006 % Changes: 05-10-2007, PS: Handling of empty spare fields % 06-10-2007, PS: Reading of BRDC files % 06-10-2007, PS: Bugfix for year < 2000 % 06-10-2007, PS: Use strcmp for check if file was already read % ----------------------------------------------------------------------------- persistent fileold; persistent data; % if file was already read read = 1; if ~isempty(fileold) if strcmp(filename,fileold); read = 0; end; end; if read == 1 % open file fid = fopen (filename, 'r'); s=' '; % skip header while ~feof(fid); s = fgetl (fid); if size(findstr(s,'END OF HEADER'),1) == 1, break, end; end; % read data records n=0; while ~feof(fid); % read first line s = fgetl (fid); s = strrep(s,'D','e'); % replace D in exponent by e s = strrep(s,'E','e'); % replace E in exponent by e % formatted read does not work properly for V6 (but for V7) % [line,c,e] = sscanf (s,'%2d %2d %2d %2d %2d %2d %4f%19f%19f%19f'); % add space before negative numbers s = strrep(s,'e-','em'); s=strrep(s,'-',' -'); s=strrep(s,'em','e-'); [line,c,e] = sscanf(s,'%d %d %d %d %d %d %f %f %f %f'); if (~isempty(e)) error(e); end; n=n+1; % PRN number data(n,1)=line(1); % convert date to GPS week and second y=line(2);m=line(3);d=line(4);h=line(5);min=line(6);sec=line(7); if (y < 80); y=y+2000; else; y=y+1900; end; [data(n,2),data(n,3)]=gpstime(y,m,d,h,min,sec); data(n,4)=line(8); data(n,5)=line(9); data(n,6)=line(10); % read remaining data lines for i=1:7; s = fgetl (fid); s = strrep(s,'D','e'); s = strrep(s,'E','e'); % formatted read does not work properly for V6 (but for V7) % line = sscanf (s,' %19f%19f%19f%19f'); s = strrep(s,'e-','em'); s=strrep(s,'-',' -'); s=strrep(s,'em','e-'); line = sscanf (s,'%f %f %f %f'); data(n,i*4+3)=line(1); data(n,i*4+4)=line(2); % Extra handling of files with empty spare fields try data(n,i*4+5)=line(3); data(n,i*4+6)=line(4); catch data(n,i*4+5)=NaN; data(n,i*4+6)=NaN; end end; end; % close file and return fclose (fid); end; nav = data; fileold = filename;