function distkm = dist(lat1,lon1,lat2,lon2)

%

%function distkm = dist(lat1,lon1,lat2,lon2)

%

% Function to calculate cumulative distance along a ship track

%    relative to the first point.

%    Assumes 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"

%

pi=3.1415926;

pid180=pi/180.;

alat=lat1*pid180;

alon=lon1*pid180;

blat=lat2*pid180;

blon=lon2*pid180;

ci=cos(alat)*cos(blat)*cos(alon-blon)+sin(alat)*sin(blat)

distkm=6371*tan(sqrt(abs(1-ci*ci)/ci))





