%% Generates comparison to RPI electron density pass from Jan 18 2001 given
%% by Bob

clear all
close all

timrpi=[233.5 237.5 241.5 245.5 249.5];  
timrpi2=[250 252 254 256 258 300 302 306 308 310];
tim=timcon(timrpi);
tim2=timcon(timrpi2);
fp=1e3*[59 63 67 76 87];
fp2=1e3*[92 119 160 195 229 221 219 257 278 290];
edenrpi=fp.^2/80.6;
edenrpi2=fp2.^2/80.6;

re=6371;

utv=2.5:0.1:3;

dat1=[234   4.21  16.34  28.81];
dat2=[238   4.10  16.37  27.14];
dat3=[242   3.98  16.39  25.44];
dat4=[246   3.86  16.42  23.66];
dat5=[250   3.74  16.45  21.82];
dat6=[254   3.62  16.48  19.86];
dat7=[258   3.49  16.52  17.67];
dat8=[302   3.36  16.55  15.52];
dat9=[306   3.24  16.59  13.03];
dat10=[310  3.10  16.63  10.39];

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

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

timmat=linspace(timmati(1),timmati(10),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

lshi=interp1(timmat,lsh,timcon(timrpi));
lshi(1)=lsh(1);
lshi2=interp1(timmat,lsh,timcon(timrpi2));

lshv=[lshi lshi2];
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)
semilogy(timcon(timrpi),edenrpi,'o-',timcon(timrpi2),edenrpi2,'o-',timmat,eden,'-')
grid 

figure(2)
semilogy(timcon(timrpi),fp,'o-',timmat,sqrt(80.6*eden),'^-')
grid

figure(3)
plot(timcon(timrpi),fp,'o-',timmat,sqrt(80.6*eden),'^-')
grid

figure(4)
plot(lshi,fp,'o-',lsh,sqrt(80.6*eden),'^-')
grid

figure(5)
h5=semilogy(lshv,[edenrpi edenrpi2],'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 2.34-3.10UT Jan 18 2001','fontsize',18,'fontweight','bold')
