clear
start

load auxmat.mat

%----------------------


%test01
%minlonreg=14;
%maxlonreg=16;
%minlatreg=35.4;
%maxlatreg=37.6;


  %Alboran
  %minlonreg=-4.7; 
  %maxlonreg=-1.9; 
  %minlatreg=36.1; 
  %maxlatreg=37.4; 

years=yearini:yearfin; %years you include in the database
% ---------
      
    
    


    
 disp(' ')
 %disp('Loading previous settings...')
 
 
 eval(['load allvar_',experiment,'_database',int2str(yearini),'to',int2str(yearfin),'.mat'])
 %disp(['load allvar_',experiment,'_database',int2str(yearini),'to',int2str(yearfin),'.mat'])
  
 
  %--------
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
%----Compute free_physalia for many ROI
%---Define your big basin







%-----

days=1:366;

% compute #arrivals each year in free_physalia
%compute the mean numeric value (for all years within the database) of arrivals to our ROI
clear free_physalia,clear mean_free,clear certainty_free_fract,clear encounter_risk
[free_physalia,mean_free,certainty_free_fract,encounter_risk]=PhysaliaSIM_mean_free_fun(minlonreg,maxlonreg,minlatreg,maxlatreg,data_longitude_free,data_latitude_free);



%-------------

xt1=(0:30.5:350);
xt={ 'Jan' ; 'Feb' ; 'Mar'; 'Apr' ; 'May' ; 'Jun'; 'Jul'; 'Aug' ; 'Sep'; 'Oct' ; 'Nov' ; 'Dec' } ;


%figure
%subplot(311),
%plot(mean_free,'r'),legend('Mean value'),hold on
%plot(free_physalia','color',[.4 .4 .4])
%title('# of Predicted Physalia colonies in the Region Of Interest','fontsize',15,'color','r')
%hold on
%plot(mean_free,'r')
%xlim([0 360]),grid on
%set(gca,'xtick',xt1);
%set(gca,'xticklabel',xt,'fontsize',15);
%posgd
%----------------------
clear miinidia,clear miinimes,[miinidia,miinimes]=quefecha_fun(inicio,2010); %myyear);
clear mifindia,clear mifinmes,[mifindia,mifinmes]=quefecha_fun(fin,2010); %myyear);
namemonth={ 'Jan' ; 'Feb' ; 'Mar'; 'Apr' ; 'May' ; 'Jun'; 'Jul'; 'Aug' ; 'Sep'; 'Oct' ; 'Nov' ; 'Dec' } ;
%{}
tit0=['Your Region of Interest:  '];
tit1=['Physalia entering MedSea  from  ',int2str(miinidia),char(namemonth(miinimes)),'  to  ',...
int2str(mifindia),char(namemonth(mifinmes))];

figure(3),
[AX,H1,H2]=plotyy((1:366),certainty_free_fract,(1:366),mean_free,'bar','plot');%set(H1,'FaceColor',[0.7 0.7 0.7],'EdgeColor',[0.7 0.7 0.7])
set(H2,'Color','r','LineWidth',2)
xlim(AX(2), [0 360])
xlim(AX(1), [0 360])
ylim(AX(1), [0 1])
set(AX,{'ycolor'},{'k';'r'})
set(get(AX(1),'Ylabel'),'String','Presence  PROBABILITY','fontsize',20)
set(get(AX(2),'Ylabel'),'String','# of Physalia colonies','Color','r','fontsize',20)
legend([H2],'Mean value')
micolor=[.5 0 0];

xlim(AX(2), [0 360])
xlim(AX(1), [0 360])
set(AX(1),'xtick',xt1);
set(AX(1),'xticklabel',xt,'fontsize',20);
set(AX(2),'xtick',xt1);
set(AX(2),'xticklabel',xt,'fontsize',20);
%ax = gca;
%%ax.XGrid = 'on';
set(gca,'XGrid','on')
%%ax.YGrid = 'off';
set(gca,'YGrid','off')
title([tit0,' ',tit1],'FontSize',18,'color',micolor)

phys_poseb


%-------encounter_risk
lim1=6; %threshold to determine 'high' RER
lim2=2; %threshold to determine 'medium' RER

high=find(encounter_risk>=lim1);
med=find(encounter_risk>=lim2&encounter_risk<lim1);
low=find(encounter_risk<=lim2);



  
figure(4)
days=1:366;
if length(high)>0
bar(days(high),encounter_risk(high),'FaceColor',[1, 0, 0],'EdgeColor',[1, 0, 0])
else
  bar(0,0,'FaceColor',[1, 0, 0],'EdgeColor',[1, 0, 0])%Para que aparezca legend
end
hold on

if length(med)>0
bar(days(med),encounter_risk(med),'FaceColor',[0.9290, 0.6940, 0.1250],'EdgeColor',[0.9290, 0.6940, 0.1250])
else
  bar(0,0,'FaceColor',[0.9290, 0.6940, 0.1250],'EdgeColor',[0.9290, 0.6940, 0.1250])%Para que aparezca legend
end
if length(low)>0
bar(days(low),encounter_risk(low),'FaceColor',[0.4660, 0.6740, 0.1880],'EdgeColor',[0.4660, 0.6740, 0.1880])
else
  bar(0,0,'FaceColor',[0.4660, 0.6740, 0.1880],'EdgeColor',[0.4660, 0.6740, 0.1880])%Para que aparezca legend
end
xlim([0 360])
ylim([0 10])
set(gca,'xtick',xt1);
set(gca,'xticklabel',xt,'fontsize',20);
ax = gca;
set(gca,'XGrid','on')
set(gca,'YGrid','off')
set(gca,'YColor','b')
legend('High','Medium','Low')
ylabel('Relative  ENCOUNTER  RISK','fontsize',20,'color','b')
title([tit0,' ',tit1],'FontSize',18,'color',micolor)
%xlabel({tit1},'FontSize',20,'color',micolor)
phys_posdb
%"pause dib",pause
%icomp






