function distkm = dist(lat,lon)
%
%function distkm = dist(lat,lon)
%
% Function to calculate absolute distance along a ship track
%    relative to the first point.
% DOES NOT   Assume Lat & Lon are in decimal degrees and are limited
%    to less than 100 or so miles.  If over that limit
%    distorsions may exist due to sphere to plane projection.
%
% Jim Manning 12/92 .. conversion of Fortran Code "Distan.for"
%

% lat & lon converted to decimal degrees if needed
if lat(1)>100;
  [lat,lon]=dm2dd(lat,lon);
end;

pi=3.1415926;
pid180=pi/180.;
alat=lat(1)*pid180;
alon=lon(1)*pid180;
for i=1:length(lat)
blat=lat(i)*pid180;
blon=lon(i)*pid180;
ci=cos(alat)*cos(blat)*cos(alon-blon)+sin(alat)*sin(blat);
distkm(i)=6371*tan(sqrt(abs(1-ci*ci)/ci));
end;

