function argos_interp(dt_start,dt_end)
% argos_interp  interpolate the Argos postions for SeaHorse to one-hour spacing
% =========================================================================
% argos_interp  Version 1.0 09-Sep-2005
%
% Usage:
%   argos_interp(dt_start,dt_end)
%
% Description:
%   This function loads position from the Argos transmitters on SeaHorse
%   and uses interp1 to interpolate the results onto a one-hour spacing
%   corresponding to the SeaHorse profiles
%
%
% Input:
%   dt_start - (string) start date and time (format '03-Sep-2005 13:34:34')
%   dt_end - (string) end date and time (format '03-Sep-2005 13:34:34')
%
% Output:
%   ASCII file with time, lat and lon of SeaHorse hourly positions
%
% Called by:
%   n/a
%
% Calls:
%   n/a
%
% Author:
%   Blair Greenan
%   Bedford Institute of Oceanography
%   Matlab 7
%   greenanb@mar.dfo-mpo.gc.ca
% =========================================================================
%

% History
% Version 1.0 09-Sep-2005


%%%%%%%%%%%%%%%% Load Argos Position Data %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% center determined by subjective analysis of ADCP data display on Dennis' computer
[date, tme, lat, lon] = textread('SeaHorse.dat','%s %d %f %f','headerlines',1);
dtnum = datenum(date)+(tme/2400);


%%%%%%%%%%%%%%% Generate time series with one-hour spacing %%%%%%%%%%%%%%%%%%%%%%%%%
 
dtnum_interp = datenum(dt_start):1/24:datenum(dt_end); % increments date/time by 1/24th of a day

%{
%%%%%%%%%%%%%%%%%%%%% Get rid of duplicate times for interp1 %%%%%%%%%%%%%%%%%%%%%%

[b, m, n] = unique(dtnum);
dtnum = b;
lat = lat(m);
lon = lon(m);

%%%%%%%%%%%%%%%%%%%%% Interpolate Data %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

lat_interp = interp1(dtnum, lat, dtnum_interp);
lon_interp = interp1(dtnum, lon, dtnum_interp);
%}

%%%%%%% Find the Data which is within 0.5 hours on each side of dtnum_interp %%%%%%%
length(dtnum_interp)

for ii = 1:length(dtnum_interp)
    indx = find((dtnum >= dtnum_interp(ii)-(1/4)) & (dtnum < dtnum_interp(ii)+(1/4)));
    lat_med(ii) = median(lat(indx));
    lon_med(ii) = median(lon(indx));
end


%%%%%%%%%%%%%%%%%%%% Save results and Plot %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

save Argos_interp.mat dtnum_interp lat_med lon_med
figure
plot(lon_med,lat_med,'.-')
xlabel('Longitude')
ylabel('Latitude')

figure
plot(lon_med,'.-')

figure
plot(lat_med,'.-')





