%% modca.m is the empirical equatorial electron density model of 
%% Carpenter and Anderson that was published in JGR Feb 1992
%% (p1097 vol 97 A2). Also calculated is the plasmatrough density 
%% for MLT=0.

function [eden,edenpt]=modca(lsh,year,month,day,timmat)

% lsh = L-shell of point of interest
% timmat = UT time
% day = day matrix
% month = month matrix
% year = year matrix
% eden = electron density (cm^-3)
% edenpt = 0 MLT plasma trough density

eden=zeros(size(lsh));                                      %electron density matrix
edenpt=eden;                                                %electron trough density matrix

dno=daynum(day,month,year);                                 %day number
ssno=sunspn(timmat,dno,year);                               %sunspot number  
x1=-0.3145*lsh+3.9043;                                      %base component
x2=0.15*cos(2*pi*(dno+9)/365).*exp(-(lsh-2)/1.5);           %annual term
x3=-0.075*cos(4*pi*(dno+9)/365).*exp(-(lsh-2)/1.5);         %semi-annual term
x4=(0.00127*ssno-0.0635).*exp(-(lsh-2)/1.5);                %solar term
eden=10.^(x1+x2+x3+x4);                                     %electron density
edenpt=5800*lsh.^(-4.5)+(1-exp(-(lsh-2)/10));               %0 MLT plasma trough density

 
