function hrs = time2station(sog, nowlat, nowlon, stalat, stalon);
% hrs = time2station(sog, nowlat, nowlon, stalat, stalon);
% positions are is [deg min 1 (or -1)]
% if only 3 args, use default station location in code

if (nargin == 3)
   stalon = [107 0 -1];
   stalat = [16 0 1];
%   stalon = [118 0 -1];
%   stalat = [18 0 1];
elseif (nargin ~= 5)
   fprintf('insufficient number of arguments\n')
   help tts
   return
end

try
   pos = [nowlon(:)';nowlat(:)';stalon(:)'; stalat(:)'];
catch
   fprintf('exiting: all positions must be vectors of length 3\n')
   help tts
   return
end

if (abs(prod(pos(:,3))) ~= 1)
   fprintf('exiting: signs must be either +1 or -1\n')
   return
end
   

% currently
lon0 = nowlon(3)*(nowlon(1) + nowlon(2)/60);
lat0 = nowlat(3)*(nowlat(1) + nowlat(2)/60);


% station
lon1 = stalon(3)*(stalon(1) + stalon(2)/60);
lat1 = stalat(3)*(stalat(1) + stalat(2)/60);


% distance:
[mps, x, y] = ll2mps([0 1], [lon0 lon1], [lat0, lat1]);
meters = abs(diff(x) + i*diff(y));


%convert sog to mps
sog_mps = sog*(111110/60)*(1/3660);
seconds = meters/sog_mps;

hrs = seconds/3600;

fprintf('from  [lat,   lon]   to [lon,   lat]  \n');
fprintf('      [%5.2f, %5.2f] to [%5.2f, %5.2f] \n',...
        lat0, lon0, lat1, lon1)
fprintf('is about %dnm , in about  %3.1f hrs\n', ...
        floor(meters*60/111110), hrs);



