% рисование часовых данных обсерваторий ИКИР

% load YSS_1957-1988_hourly_WDC_20180614 Tyss Xyss Yyss Hyss Dyss Zyss
% load KHB_2012-2016_hourly_WDC_20180614 Tkhb Xkhb Ykhb Hkhb Dkhb Zkhb
% load PET_1969-2016_hourly_WDC_20180614 Tpet Xpet Ypet Hpet Dpet Zpet
% load MGD_1966-2017_hourly_WDC_20180614 Tmgd Xmgd Ymgd Hmgd Dmgd Zmgd
% load CPS_hourly_2015-2016 T H D Z F
% Tcps=T; Hcps=H; Dcps=D; Zcps=Z; Fcps=F;

FF=50000;

load KHB_2012_2019_hourly_WDC_Edinburgh.mat Tkhb Ckhb Elements
Ele_khb=Elements;
load khb_hourly_2011-2021.mat
Ta_khb=Thkhb; Fa_khb=total_field(Xhkhb,Yhkhb,Zhkhb);

load YSS_1957_1989_hourly_WDC_Edinburgh.mat Tyss Cyss Elements
Ele_yss=Elements;
Ta_yss=Tyss; Fa_yss=total_field(Cyss(:,1),Cyss(:,5));

load MGD_1966_2019_hourly_WDC_Edinburgh.mat Tmgd Cmgd Elements
Ele_mgd=Elements;
load mgd_hourly_2012-2020.mat
k=Tmgd<datenum(2007,1,1);
Ta_mgd=[Tmgd(k); Thmgd]; 
Fa_mgd=[total_field(Cmgd(k,1),Cmgd(k,5)); total_field(Xhmgd,Yhmgd,Zhmgd)];

load PET_1968_2020_hourly_WDC_Edinburgh.mat Tpet Cpet Elements
Ele_pet=Elements;
load pet_hourly_2001-2023.mat % Intermagnet
k=Tpet<datenum(2001,1,1);
Ta_pet=[Tpet(k); Thpet]; 
Fa_pet=[total_field(Cpet(k,1),Cpet(k,5)); total_field(Xhpet,Yhpet,Zhpet)];
k0=find(Ta_pet==datenum('31-Dec-2001 23:30:00')); Fa_pet(k0)=NaN;

load CPS_2018_2023_hourly.mat Thcps Fhcps
Ta_cps=Thcps; Fa_cps=Fhcps;


figure(1)
plot(Ta_pet,Fa_pet-FF,'b',...
     Ta_mgd,Fa_mgd-FF,'r',...
     Ta_khb,Fa_khb-FF,'g',...
     Ta_cps,Fa_cps-FF,'y',...
     Ta_yss,Fa_yss-FF+1000,'m')

% plot(Tpet,Fpet-FF,'b',Tmgd,Fmgd-FF,'r',...
%      Tkhb,Fkhb-FF,'g',Tyss,Fyss-FF,'k',...
%      Tcps,Fcps-FF,'y',...
%      Thpet,Fhpet-FF,'b')
datetick('x','yyyy'), ylabel('F-50000, nT')
legend('PET','MGD','KHB','CPS','YSS+1000nT','Location','NorthWest')
title('Magnetic data (hourly values) from WDC (Edinburg + Moscow) and INTERMAGNET')
% маркировка кривых
text(Ta_pet(1)-365*2,800,'PET','Color','b','FontWeight','Bold')
text(Ta_mgd(1)-365*3,6000,'MGD','Color','r','FontWeight','Bold')
text(Ta_khb(1)-365*3,Fa_khb(1)-FF,'KHB','Color','g','FontWeight','Bold')
text(Ta_cps(1)-365*3,Fa_cps(1)-FF,'CPS','Color',[0.6 0.6 0.6],'FontWeight','Bold')
text(max(Ta_yss)+365*5,2600,'YSS','Color','m','FontWeight','Bold')

% маркировка данных
% PET (photo & digit)
% T1=datenum(1998,1,1); T2=datenum(2005,12,31); H1=1600; H2=1750;
% patch([T1 T1 T2 T2],[H1 H2 H2 H1],[0.5 1 1],'FaceAlpha',0.3)
T1=datenum(2000,12,01); T2=datenum(2003,12,31); F1=1000; F2=1500;
patch([T1 T1 T2 T2],[F1 F2 F2 F1],[1 0.2 1],'FaceAlpha',0.15)

% MGD (photo & digit)
T1=datenum(1998,1,1); T2=datenum(2005,12,31); F1=5200; F2=6200;
patch([T1 T1 T2 T2],[F1 F2 F2 F1],[0.5 1 1],'FaceAlpha',0.15)
text(datenum(2000,1,1),6500,'Analogue')
T1=datenum(2005,5,1); T2=datenum(2011,12,31); 
patch([T1 T1 T2 T2],[F1 F2 F2 F1],[1 0.2 1],'FaceAlpha',0.15)
text(datenum(2007,6,1),6500,'Digital')
% KHB (digit)
T1=datenum(2005,1,1); T2=datenum(2011,12,31); F1=4200; F2=4800;
patch([T1 T1 T2 T2],[F1 F2 F2 F1],[1 0.2 1],'FaceAlpha',0.15)
% YSS (digit)
T1=datenum(2005,11,1); T2=datenum(2007,10,31); F1=2450; F2=2650;
patch([T1 T1 T2 T2],[F1 F2 F2 F1],[1 0.2 1],'FaceAlpha',0.15)

% 
% 
% % figure(3)
% % plot(Tpet,Zpet,Tmgd,Zmgd,Tkhb,Zkhb,Tyss,Zyss)
% % datetick('x','yyyy')
% % 
% % figure(1)
