%% distfl.m calculates the distance
%% a point is along the given field line.
%%

function dfl=distfl(th,th0,r0)

% th = magnetic latitude of point of interest
% th0 = magnetic field line point of interest on
% r0 = base radial height of field line
% dfl = distance from base (height r0) to point of interest

th=abs(th);
th0=abs(th0);
y=sqrt(3)*sin(th);
y0=sqrt(3)*sin(th0);
s1=log(y+sqrt(1+y.^2))+y.*sqrt(1+y.^2);
sm=log(y0+sqrt(1+y0.^2))+y0.*sqrt(1+y0.^2);

dfl=(r0./(2*sqrt(3)*cos(th0).^2)).*(sm-s1);


