function gps = read_gps_atm(gps_fn,param)
% gps = read_gps_atm(gps_fn,param)
%
% Created for the Antarctica 2010 OIB campaign to read in ASCII trajectory 
% files produced by John Sonntag of the ATM group.
% 
% Fields in the ASCII text file are as follows:
% 10  310   39936.00  -53.00402200  289.15366500   211.978    1.7    0.0
%
% 1: Skip, Year?
% 2: Day of year
% 3: GPS seconds of day
% 4: Latitude
% 5: Longitude
% 6: Elevation
% 7: Skip
% 8: Skip
%
% Seconds of day are given in GPS time with a 2 Hz update rate.
%
%  gps_fn = input filename (string)
%  param = 
%   .year = year
%   .time_reference = 'gps' or 'utc'
%
% Output Args:
% gps = output structure with fields
%  .time = GPS time in seconds since Jan 1, 1970 epoch (sec)
%  .lat = latitude (deg)
%  .lon = longitude (deg)
%  .elev = elevation (m)
%  .roll = roll (rad)
%  .pitch = pitch (rad)
%  .heading = true heading (rad)
% 
% Authors: Ben Panzer, John Paden
%
% See also read_gps_applanix, read_gps_atm, read_gps_nmea,
%   read_gps_novatel, read_gps_reveal, plot_gps

% Read in data
[day_of_year,gps_sod,gps.lat,gps.lon,gps.elev] = ...
    textread(gps_fn,'%*f %f %f %f %f %f %*f %*f','delimiter',' ','headerlines',0);

gps.gps_time = datenum(param.year, 1, day_of_year, 0, 0, gps_sod);
gps.gps_time = datenum_to_epoch(gps.gps_time);

% NaN removal
good_idxs = find(isfinite(gps.lat) & isfinite(gps.lon) & isfinite(gps.elev));
gps.gps_time = gps.gps_time(good_idxs);
gps.lat = gps.lat(good_idxs);
gps.lon = gps.lon(good_idxs);
gps.elev = gps.elev(good_idxs);

if strcmpi(param.time_reference,'utc')
  % UTC time stored in file, so need to add leap seconds back in
  gps.gps_time = gps.gps_time + utc_leap_seconds(gps.gps_time(1));
end

gps.roll = zeros(size(gps.lat));
gps.pitch = zeros(size(gps.lat));
gps.heading = zeros(size(gps.lat));

return
