clear all

load('DataFullr0Master.mat','chngpars','parnames','par0values','OutData'); 
%load('DataWoutPrdtr.mat','chngpars','parnames','par0values','OutData'); 
%load('DataPartialr0.mat','chngpars','parnames','par0values','OutData'); 
%load('Data.mat','chngpars','parnames','par0values','OutData'); 

%load('DataPartialRegularr0.mat','chngpars','parnames','par0values','OutData'); 

%load('DataFullr02.mat','chngpars','parnames','par0values','OutData'); 

level=1;
popthrhd=[1e-4, 1e-2, 1e-1, 1e-0, 1e+1, 1e+2];
popthrhdnmbr=length(popthrhd);
%rows=[1:5,5+(level:popthrhdnmbr:6*popthrhdnmbr)];

pta0=min(OutData(:,2))-1e-4;
pta1=max(OutData(:,2))+1e-4;
ptb=min(OutData(:,3));
ptc=max(OutData(:,4));
indx=(OutData(:,1)<=50 & OutData(:,2)>pta0 & OutData(:,2)<pta1 ...
    & OutData(:,3)<ptb+1e-4 & OutData(:,3)>ptb-1e-4...
    & OutData(:,4)<ptc+1e-4 & OutData(:,4)>ptc-1e-4); 
%plotOutData=OutData(indx,rows);
plotOutData=OutData(indx,:);

nmbrofruns=0;
r0length=sum((plotOutData(:,1)==plotOutData(1,1) & plotOutData(:,3)==plotOutData(1,3) & plotOutData(:,4)==plotOutData(1,4)));
idinit=max(floor(plotOutData(end,1)*rand(1))-nmbrofruns,0)*r0length;
indx=idinit+1:idinit+min(plotOutData(end,1),nmbrofruns)*r0length;
rn=floor(rand(1)*plotOutData(end,1));
rn=rn-1;
indx1=(OutData(:,1)==rn & plotOutData(:,3)==plotOutData(1,3) & plotOutData(:,4)==plotOutData(1,4));

stdon=1; % binary.

bmscale=20;
Binsize=(7-(-1))/30;

xaxis=2;

figinr0ndvmass

%%
figure(3)
subplot(2,1,1)
    hold off
    plot([-8],[0],'ks',[-8],[0],'ko',[-8],[0],'k^')
legend('Plant','Herbivore','Carnivore','location','nw')
%pbms=log(pbms)/log(10);hbms=log(hbms)/log(10);cbms=log(cbms)/log(10);
%pstd=log(pstd)/log(10);hstd=log(hstd)/log(10);cstd=log(cstd)/log(10);
hold on
    plot(yBmsBins+yBinsize/2,pbms,'ks',...
        yBmsBins+yBinsize/2,pbms,'g-s',...
        yBmsBins+yBinsize/2,hbms,'ko',...
        yBmsBins+yBinsize/2,hbms,'b-',...
        yBmsBins+yBinsize/2,cbms,'ks',...
        yBmsBins+yBinsize/2,cbms,'r-', 'linewidth', 2.5)
    if stdon==1
    for j=1:length(yBmsBins)
        plot([yBmsBins(j)+yBinsize/2 yBmsBins(j)+yBinsize/2],...
            [pbms(j)+pstd(j) pbms(j)-pstd(j)], 'g-',...
            [yBmsBins(j)+yBinsize/2 yBmsBins(j)+yBinsize/2],...
            [hbms(j)+hstd(j) hbms(j)-hstd(j)], 'b-',...
            [yBmsBins(j)+yBinsize/2 yBmsBins(j)+yBinsize/2],...
            [cbms(j)+cstd(j) cbms(j)-cstd(j)], 'r-','linewidth',1.5)
    end
    end

%xlabel('log(r_0)','fontsize',16)
ylabel('Biomass','fontsize',16)
axis([-1 7 0 10])

%%
%figure(4)
subplot(2,1,2)
    hold off
%    plot([-8],[0],'ks',[-8],[0],'ko',[-8],[0],'k^')
%legend('Plant','Herbivore','Carnivore','location','nw')
pbms=log(pbms+1e-6)/log(10);hbms=log(hbms+1e-6)/log(10);cbms=log(cbms+1e-6)/log(10);
%pstd=log(pstd)/log(10);hstd=log(hstd)/log(10);cstd=log(cstd)/log(10);
hold on
    plot(yBmsBins+yBinsize/2,pbms,'ks',...
        yBmsBins+yBinsize/2,pbms,'g-s',...
        yBmsBins+yBinsize/2,hbms,'ko',...
        yBmsBins+yBinsize/2,hbms,'b-',...
        yBmsBins+yBinsize/2,cbms,'ks',...
        yBmsBins+yBinsize/2,cbms,'r-', 'linewidth', 2.5)
    if stdon==5
    for j=1:length(yBmsBins)
        plot([yBmsBins(j)+yBinsize/2 yBmsBins(j)+yBinsize/2],...
            [pbms(j)+pstd(j) pbms(j)-pstd(j)], 'g-',...
            [yBmsBins(j)+yBinsize/2 yBmsBins(j)+yBinsize/2],...
            [hbms(j)+hstd(j) hbms(j)-hstd(j)], 'b-',...
            [yBmsBins(j)+yBinsize/2 yBmsBins(j)+yBinsize/2],...
            [cbms(j)+cstd(j) cbms(j)-cstd(j)], 'r-','linewidth',1.5)
    end
    end

xlabel('log(r_0)','fontsize',16)
ylabel('log(Biomass)','fontsize',16)
axis([-1 7 -6 6])

return
%% 

xaxis=5;
bmscale=20;
Binsize=(7-(-1))/60;


figinr0ndvmass



return

indx=(OutData(:,2)==OutData(end,2));
endbmm=min(OutData(indx,5)+OutData(indx,6)+OutData(indx,7))

indx=(OutData(:,2)==OutData(1,2));
inibmM=max(OutData(indx,5)+OutData(indx,6)+OutData(indx,7))
