function ads_pos(inputFile)
% ads_pos  load and process Argos positions for SeaHorse
% =========================================================================
% ads_pos  Version 1.0 31-Aug-2005
%
% Usage: 
%   ads_pos(inputFile)
%
% Description:
%   This function loads an Argos position file as distributed by the
%   the automated distribution system (ADS).  The latitudes and longitudes
%   are stripped from the data file and written to the seahorse.dat positions
%   file that is used to plot the mooring position in the ADCP plotting 
%   program used for the Sargasso EDDIES program
%
% Input:
%   inputFile is a character string containing the name of the ADS data
%   file.
%
% Output:
%   Data appended to the seahorse.dat file
%
% 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 31-Aug-2005

% Open the ADS position file
eval(['fid1 = fopen(''', inputFile,''');'])

% Open the position file for the ADCP plotting program
fid2 = fopen('seahorse.dat','a');

ii = 1;

while 1
    tline = fgetl(fid1);
    if ~ischar(tline)
        break
    end  % break out if end of file
    
    if length(tline) == 76 % complete line of data
        if strcmpi(tline(1:5),'00076')
            year = tline(24:27);
            mnth = tline(29:30);
            if str2num(mnth) == 8
                month = 'Aug';
            else
                month = 'Sep';
            end
            day = tline(32:33);
            hour = tline(35:36);
            minute = tline(38:39);
            second = tline(41:42);
            lat = tline(45:50);
            lon = tline(53:59);
            lon = str2num(lon) - 360;
            lon = num2str(lon);
            dtnum(ii) = datenum(str2num(year),str2num(mnth),str2num(day),str2num(hour),str2num(minute),str2num(second));
            % compile a string to write to the positions file
            out_str{ii} = [day '-' month '-' year char(9) hour minute char(9) lat char(9) lon];
            ii = ii + 1;
        end
    end
end


% sort the data by time prior to printing it out
[B,XI] = sort(dtnum);

for jj = 1:ii-1
    out_str2{jj} = out_str{XI(jj)};
    fprintf(fid2,'%s\n',out_str2{jj});
end

fclose(fid1);
fclose(fid2);

% copy file onto network drive
!copy seahorse.dat P:\oc415_4\adcp\positions\seahorse.dat




