readobs.m is a MATLAB script that reads in GNSS observation data in RINEX format. RINEX (Receiver Independent Exchange Format) is a standard file format used for storing GNSS data, and can be generated by many different GNSS receivers.
Here is an example implementation of readobs.m:
function [obs, ant] = readobs(filename)
% Open the RINEX file for reading
fid = fopen(filename,'r');
% Read in the header information
obs = readheader(fid);
% Read in the observation data
obs.data = readdata(fid);
% Read in the antenna information
ant = readant(fid);
% Close the file
fclose(fid);
end
function header = readheader(fid)
% Read in the RINEX version and file type
line = fgetl(fid);
header.version = str2double(line(1:9));
header.filetype = line(21:40);
% Read in the observation type information
line = fgetl(fid);
num_obs = str2double(line(5:6));
header.obs_types = cell(num_obs,1);
for i = 1:num_obs
header.obs_types{i} = line(10+6*(i-1):15+6*(i-1));
end
% Read in the antenna marker information
line = fgetl(fid);
header.ant_marker = line(2:21);
% Read in the receiver and file information
line = fgetl(fid);
header.receiver = line(2:21);
header.file_time = line(33:49);
% Skip over the leap seconds and other header information
for i = 1:5
fgetl(fid);
end
end
function data = readdata(fid)
% Initialize the observation data structure
data = struct('time',[],'sat',[],'obs',[],'lli',[],'sig',[]);
% Read in the first line of data
line = fgetl(fid);
% Keep reading in data until the end of the file is reached
while ischar(line)
if line(1) == '>'
% If a new epoch has been reached, extract the epoch time
data.time(end+1,:) = sscanf(line,'%*1s %4d %2d %2d %2d %2d %11f');
% Read in the next line of data
line = fgetl(fid);
else
% Otherwise, extract the satellite and observation data
[sat,obs,ll,sig] = readobsline(line);
data.sat(end+1) = sat;
data.obs(end+1,:) = obs;
data.lli(end+1,:) = ll;
data.sig(end+1,:) = sig;
% Read in the next line of data
line = fgetl(fid);
end
end
end
function [sat,obs,lli,sig] = readobsline(line)
% Extract the satellite and observation information from the data line
sat = sscanf(line(1:3),'%d');
obs = sscanf(line(4:59),'%14f');
lli = sscanf(line(60:68),'%1d%1d%1d%1d');
sig = sscanf(line(69:end),'%1d%1d%1d%1d');
end
function ant = readant(fid)
% Skip over the antenna and receiver information
for i = 1:14
fgetl(fid);
end
% Read in the antenna offset information
line = fgetl(fid);
ant.offset = sscanf(line(2:29),'%14f%14f%14f');
ant.type = line(32:end);
end
The function readobs takes a filename as input, and returns two structures (obs and ant) that contain the observation data and antenna information, respectively.
The function readheader reads in the header information from the RINEX file, including the RINEX version, file type, observation types, antenna marker information, and receiver and file information.
The function readdata reads in the observation data from the RINEX file, including the time of each epoch, the satellite and observation data for each observation, and any loss of lock indicator (LLI) or signal strength indicator (SSI) information.
The function readobsline extracts the satellite and observation information from a single line of observation data, taking into account the varying lengths of the observation fields.
The function readant reads in the antenna information from the RINEX file, including the antenna offset and type.