%% hytgrid1.m produces the required lookup arrays for use
%% by hytgrid#.m. The arrays are new L-shell values, the
%% new MLT values and the new volume ratio. It also returns
%% the Kp vector of the lookup arrays. 
%%
%% 29/12/2001 - modify to allow user to select use of original McIllwain scaling
%%            factor, or new approach based on Liemohn et al. In the latter 
%%            case the plasmaspause formation is not used (irrespective of pvs).
%%            
%% 25/1/2002 - remove plasmapause formation velocity.
%%

function [lsht,mltt,ratt,kpt]=hytgrid1(lshv,mltv,dts,sfs)

% lshv = L-shell value vector 
% mltv = magnetic local time vector (fractional hours)
% dts = time step in seconds to advance points of interest (must be divideable by 50 seconds)
% sfs = E-field scaling factor switch (0 = original McIllwain, 1 = Liemohn) (scalar)
%
% lsht = L-shell lookup table array
% mltt = MLT lookup table array
% ratt = volume ratio lookup table array
% kpt = Kp vector for table lookup arrays

lshv=lshv(:);                      %convert L-shell vector to column vector
mltv=mltv(:);                      %convert MLT vector to column vector
nop1=length(lshv);                 %number of L-shell values
nop2=length(mltv);                 %number of MLT values
sv1=ones(nop1,1);
sv2=ones(1,nop2);
lshm=lshv*sv2;                     %L-shell matrix
mltm=sv1*mltv';                    %MLT matrix

kpt=0:0.25:9;                      %Kp values at which to determine arrays
nop3=length(kpt);                  %number of Kp points
lsht=zeros(nop1,nop2,nop3);        %L-shell lookup table array
mltt=lsht;                         %MLT lookup table array
ratt=lsht;                         %volume ratio lookup table array

for i=1:nop3
 [i nop3]
 [lshi,mlti,rati]=ftdiff(lshm,mltm,kpt(i),dts,sfs);         %calculate new L-shell, MLT and ratio of final area to original area
 lsht(:,:,i)=lshi;                                          %i'th new L-shell values
 mltt(:,:,i)=mlti;                                          %i'th new MLT
 ratt(:,:,i)=rati;                                          %i'th new ratio
end 

