%% flpar.m (field line parameters) determines the arrays 
%% describing the co-ordinates of the given field lines.
%% Note that at very large L-shells (say L>35, ~80 degrees)
%% that the results obtained will be in error, the more so
%% the closer to 90 degrees.

function [lonmat,lonmatc,latmat,latmatc,latmatm,dismat,dflm]=flpar(lsh,lonlsh,r0,nop)

% lsh = L-shell of field lines 
% lonlsh = magnetic longitude of field lines (rads)
% r0 = base radial distance (km)
% nop = number of points along each field line
%
% lonmat = geographic longitude of points of interest (rads)
% lonmatc = conjugate geographic longitude of points of interest (rads)
% latmat = geographic latitude of points of interest (rads)
% latmatc = conjugate geographic latitude of points of interest (rads)
% latmatm = magnetic latitude of points of interest (rads)
% dismat = distance from center of Earth of points of interest (km)
% dflm = distance along the field line from base (km)

%convert input to column vectors
lsh=lsh(:);
lonlsh=lonlsh(:);

sv1=ones(length(lsh),1);
sv2=ones(1,nop);
latmb=lshpar(lsh,-1*sv1,r0*sv1);                       %magnetic latitude of base of field line
dflt=distfleq(latmb,lsh);                              %length of the field line from the equator to r0
dv=logspace(-2,0,(nop-1));                             %fractional vector to break field line up into
dv=[dv-dv(1) 1];                                       %final version of corrected field line fractional vector
dflm=dflt*dv;                                          %required distant along field line of points of interest
latmatm=dis2th(dflm,latmb*sv2,r0);                     %magnetic latitude of points of interest
dismat=lshpar(lsh*sv2,latmatm,-sv1*sv2);               %radial displacement of points of interest
dismat(:,1)=r0;                                        %reset base value to r0 exactly
[lonmat,latmat]=mag2geo3(lonlsh*sv2,latmatm);          %geographic co-ordinates of points of interest
[lonmatc,latmatc]=mag2geo3(lonlsh*sv2,-latmatm);       %conjugate geographic co-ordinates of points of interest
