%% temppaw31.m is the first part (with temppaw32.m, temppaw33.m and 
%% temppaw34.m and temppaw35.m) of a heavily modified version of 
%% temppaw.m. temppaw31 calculates the initial base electron 
%% temperatures and gradients for the required L-shells. These are 
%% the basic values that are independent of local conditions including 
%% seasonal and daily F10.7 solar flux (temmpaw32.m), Kp (temmpaw33.m), 
%% and local time (temmpaw34.m). It is designed to be called by 
%% plasimod.m and should probably not be called otherwise as it requires 
%% a specific input format.
%%
%% Author: Phillip A. Webb
%% Last updated: April 3 2003 
%%
 
function [t0d,t0n,g0d,g0n,sl,bh,dhr]=temppaw31(lsh,dismat,latmatm)

% lsh = L-shell vector for one magnetic longitude
% dismat = radial distances along field lines (km)
% latmatm = magnetic latitudes along field lines (rads)
%
% t0d = day base temperature (K)
% t0n = night base temperature (K)
% g0d = day gradient temperature (K/km)
% g0n = night gradient temperature (K/km)
% sl = sl parameter
% bh = bh parameter
% dhr = dhr parameter

re=6371;                                               %Earth radi (km)
svx=ones(1,size(dismat,2));
lsl=length(lsh);                                       %number of L-shells at each magnetic longitude
latmb=latmatm(1:lsl,1);                                %magnetic latitude at base of field lines at one magnetic longitude       
altmat=dismat(1:lsl,:)-re;                             %altitude of points of interest at one magnetic longitude

sl=1-((re+300)./(re+350)).*cos(latmb).^2;              %sl parameter
  
%Calculate required G0 and T0 values.
[t0d,t0n,g0d,g0n]=temppawt0g0(sl);                     
 
%Determine bh and dhr parameters.
r0=1+400/re;
rh=1+altmat/re;
hlog=log10(altmat/400);
bh=(0.05./(2*lsh*svx-r0)).*(88+hlog.*(10.5-hlog));
dhr=((lsh*svx-1)*re-400)./r0^2-((lsh*svx-1)*re-altmat)./rh.^2;



