%% Generates the 2nd comparison to RPI electron density pass from Jan 18 2001.

clear all
close all

timrpi=[430 432 436 438 440 442 446 448 452:2:456 500:2:516];  
tim=timcon(timrpi);
fp=1e3*[615 568 546 515 475 439 360 340 290 252 224 177 119 119 106 80 67 61 55 51];
edenrpi=fp.^2/80.6;

re=6371;

utv=2.5:0.1:3;

dat1=[430   1.66   4.75  -6.58];
dat2=[434   1.80   4.88   1.91];
dat3=[438   1.94   4.97   8.89];
dat4=[442   2.09   5.06  15.23];
dat5=[446   2.25   5.14  20.59];
dat6=[450   2.38   5.21  25.33];
dat7=[454   2.54   5.29  29.51];
dat8=[458   2.69   5.35  33.42];
dat9=[502   2.83   5.42  36.72];
dat10=[506   2.96   5.49  39.93];
dat11=[510   3.10   5.55  42.70];
dat12=[514   3.23   5.61  45.35];
dat13=[518   3.37   5.68  47.67];

dat=[dat1;dat2;dat3;dat4;dat5;dat6;dat7;dat8;dat9;dat10;dat11;dat12;dat13];

disvi=dat(:,2);
timmati=timcon(dat(:,1));
timmlti=timcon(100*dat(:,3));
latmatmi=deg2rad(dat(:,4));

timmat=linspace(timmati(1),max(timmati),20);
disv=interp1(timmati,disvi,timmat);
timmlt=interp1(timmati,timmlti,timmat);
latmatm=interp1(timmati,latmatmi,timmat);

sv=ones(size(disv));
nop=50;
iricf=1;
day=18;
month=1;
year=2001;
dno=daynum(day,month,year);

lonmatm=timml2lon(timmat,timmlt,dno*sv);
[lonmat,latmat]=mag2geo3(lonmatm,latmatm);
altmat=(disv-1)*re;

lsh=lshpar(-sv,latmatm,altmat+re);

eden=zeros(size(lonmat));
for i=1:length(lonmat)
 eden(i)=plasipt1(lonmat(i),latmat(i),altmat(i),timmat(i),day,month,year,nop,iricf);
end

lshv=interp1(timmat,lsh,timcon(timrpi));
svv=ones(size(lshv));
edgal=modgall2(lshv,year*svv,month*svv,day*svv,timmat);
[edca,edca2]=modca(lshv,year*svv,month*svv,day*svv,timmat);
  
figure(1)
h5=semilogy(lshv,edenrpi,'k^',lsh,eden,'r-',lshv,1e6*edca,'g-',lshv,1e6*edca2,'b-',lshv,1e6*edgal,'-m');
set(h5(1),'markerfacecolor','k','markersize',12)
set(h5(2),'linewidth',2)
set(h5(3:4),'linewidth',2)
set(h5(5),'linewidth',2)
grid 
set(gca,'fontsize',12,'fontweight','bold')
xlabel('L-shell','fontsize',12,'fontweight','bold')
ylabel('Electron density (m^{-3}) ','fontsize',12,'fontweight','bold')
legend(h5,'RPI derived','GPID','C&A','C&A - plasmatrough','G2000')
title('RPI derived local electron densities 4.30-5.16UT Jan 18 2001','fontsize',18,'fontweight','bold')
