clear all,clc
addpath D:\pruis\XBeach\MatlabScripts\benodigd
addpath D:\pruis\XBeach\MatlabScripts\benodigd\Visualisation
addpath ([cd, '\jonswap_files'])

load('CollectedData')


t=100;
regime=1;
rows=4;
columns=4;

alpha_array=1;
Beta_array=[0,0.001, 0.005,0.01 0.05, 0.1,0.5,1];
T_array=[0.01, 1, 6, 100];
sealevelchangerate_array=[0.29, 0.64, 0.99];
% add_sediment_array=[0,0.3, 3, 6, 10];
add_sediment_array=[-10,-6,-3,-0.3,0,0.3, 3, 6, 10];


alphaON=0;
betaON=1;
TON=1;
SeaON=1;
SedON=1;



for k=1:length(alpha_array)
    for l=1:length(Beta_array)
        for m=1:length(T_array)
            for n=1:length(sealevelchangerate_array)
                for o=1:length(add_sediment_array)
                    ajitter=jitter([alpha_array(k)-0.05,alpha_array(k),alpha_array(k)+0.05],1);
                    alpha(k,l,m,n,o) = alpha_array(k);
                    alphaj(k,l,m,n,o) = abs(ajitter(1,2));
                    bjitter=jitter([Beta_array(l)+0.01,Beta_array(l),Beta_array(l)+0.05],1);
                    beta(k,l,m,n,o) = Beta_array(l);
                    betaj(k,l,m,n,o) = abs(bjitter(1,2));
                    tjitter=jitter([T_array(m)+0.01,T_array(m),T_array(m)+0.05],1);
                    theta(k,l,m,n,o) = T_array(m);
                    thetaj(k,l,m,n,o) = abs(tjitter(1,2));
                    seajitter=jitter([sealevelchangerate_array(n)-0.05,sealevelchangerate_array(n),sealevelchangerate_array(n)+0.05],1);
                    sealevel(k,l,m,n,o)=sealevelchangerate_array(n);
                    sealevelj(k,l,m,n,o) = abs(seajitter(1,2));
                    if add_sediment_array(o)>0
                        sedimentjitter=jitter([add_sediment_array(o)-0.05,add_sediment_array(o),add_sediment_array(o)+0.05],1);
                        sedimentj(k,l,m,n,o) = abs(sedimentjitter(1,2));
                    else
                        sedimentj(k,l,m,n,o) = add_sediment_array(o);
                    end
                    sediment(k,l,m,n,o) = add_sediment_array(o);
                    
                end
            end
        end
    end
end



d1 = squeeze(CollectedData(regime,:,:,:,:,:,5,t));
d2 = squeeze(CollectedData(regime,:,:,:,:,:,2,t));
d3 = squeeze(CollectedData(regime,:,:,:,:,:,3,t));
d4 = squeeze(CollectedData(regime,:,:,:,:,:,4,t));



figure;
% ALPHA
if alphaON==1
    for k=alphaON*1:alphaON*4
        subplot(rows,columns,k); 
        for j=1:length(alpha_array)
            temp1=(alpha(:)==alpha_array(j));
            AlphaGroup(:,j)=alpha(temp1>0);
            if k==alphaON*1
            ALPHA(:,j)=d1(temp1>0);
            plot(alphaj(:),d1(:),'.','MarkerSize',1),hold on;
            xlabel('alpha')
            ylabel('max island height')
            else
                if k==alphaON*2
                    ALPHA(:,j)=d2(temp1>0);
                    plot(alphaj(:),d2(:),'.','MarkerSize',1),hold on;
                    xlabel('alpha')
                    ylabel('island width')
                else
                    if k==alphaON*3
                        ALPHA(:,j)=d3(temp1>0);
                        plot(alphaj(:),d3(:),'.','MarkerSize',1),hold on;
                        xlabel('alpha')
                        ylabel('island volume')
                    else
                        if k==alphaON*4
                            ALPHA(:,j)=d4(temp1>0);
                            plot(alphaj(:),d4(:),'.','MarkerSize',1),hold on;
                            xlabel('alpha')
                            ylabel('roll back distance')
                        end
                    end
                end
            end
            std_Alpha(j)=std(ALPHA(:,j));
            errorbar(AlphaGroup(1,j),mean(ALPHA(:,j)),std_Alpha(1,j),'Color','r');
        end
    end
end

% BETA
if betaON==1
    for k=alphaON*4+betaON*1:alphaON*4+betaON*4
        subplot(rows,columns,k); 
        for j=1:length(Beta_array)
            temp1=(beta(:)==Beta_array(j));
            BetaGroup(:,j)=beta(temp1>0);
            if k==alphaON*4+betaON*1
                BETA(:,j)=d1(temp1>0);
                semilogx(betaj(:),d1(:),'.','MarkerSize',1),hold on;
                xlabel('beta')
                ylabel('max island height')
            else
                if k==alphaON*4+betaON*2
                    BETA(:,j)=d2(temp1>0);
                    semilogx(betaj(:),d2(:),'.','MarkerSize',1),hold on;
                    xlabel('beta')
                    ylabel('island width')
                else
                    if k==alphaON*4+betaON*3
                        BETA(:,j)=d3(temp1>0);
                        semilogx(betaj(:),d3(:),'.','MarkerSize',1),hold on;
                        xlabel('beta')
                        ylabel('island volume')
                    else
                        if k==alphaON*4+betaON*4
                            BETA(:,j)=d4(temp1>0);
                            semilogx(betaj(:),d4(:),'.','MarkerSize',1),hold on;
                            xlabel('beta')
                            ylabel('roll back distance')
                        else
                        end
                    end
                end
            end
            std_Beta(j)=std(BETA(:,j));
            errorbar(BetaGroup(1,j),mean(BETA(:,j)),std_Beta(1,j),'Color','r','LineWidth',2);
        end
    end
end
% THETA
if TON==1
    for k=alphaON*4+betaON*4+TON*1:alphaON*4+betaON*4+TON*4
        subplot(rows,columns,k); 
        for j=1:length(T_array)
            temp1=(theta(:)==T_array(j));
            ThetaGroup(:,j)=theta(temp1>0);
            if k==alphaON*4+betaON*4+TON*1
                THETA(:,j)=d1(temp1>0);
                semilogx(thetaj(:),d1(:),'.','MarkerSize',1),hold on;
                xlabel('T')
                ylabel('max island height')
            else
                if k==alphaON*4+betaON*4+TON*2
                THETA(:,j)=d2(temp1>0);
                semilogx(thetaj(:),d2(:),'.','MarkerSize',1),hold on;
                xlabel('T')
                ylabel('island width')
                else
                    if k==alphaON*4+betaON*4+TON*3
                    THETA(:,j)=d3(temp1>0);
                    semilogx(thetaj(:),d3(:),'.','MarkerSize',1),hold on;
                    xlabel('T')
                    ylabel('island volume')
                    else
                        if k==alphaON*4+betaON*4+TON*4
                        THETA(:,j)=d4(temp1>0);
                        semilogx(thetaj(:),d4(:),'.','MarkerSize',1),hold on;
                        xlabel('T')
                        ylabel('roll back distance')
                        end
                    end
                end
            end        
            std_Theta(j)=std(THETA(:,j));
            errorbar(ThetaGroup(1,j),mean(THETA(:,j)),std_Theta(1,j),'Color','r','LineWidth',2);
        end
    end
end

% SEALEVEL
if SeaON==1
    for k=alphaON*4+betaON*4+TON*4+SeaON*1:alphaON*4+betaON*4+TON*4+SeaON*4
        subplot(rows,columns,k); 
        for j=1:length(sealevelchangerate_array)
            temp1=(sealevel(:)==sealevelchangerate_array(j));
            SealevelGroup(:,j)=sealevel(temp1>0);
            if k==alphaON*4+betaON*4+TON*4+SeaON*1
                SEALEVEL(:,j)=d1(temp1>0);
                plot(sealevelj(:),d1(:),'.','MarkerSize',1),hold on;
                xlabel('Sealevelchange')
                ylabel('max island height')
            else
                if k==alphaON*4+betaON*4+TON*4+SeaON*2
                    SEALEVEL(:,j)=d2(temp1>0);
                    plot(sealevelj(:),d2(:),'.','MarkerSize',1),hold on;
                    xlabel('Sealevelchange')
                    ylabel('island width')
                else
                    if k==alphaON*4+betaON*4+TON*4+SeaON*3
                        SEALEVEL(:,j)=d3(temp1>0);
                        plot(sealevelj(:),d3(:),'.','MarkerSize',1),hold on;
                        xlabel('Sealevelchange')
                        ylabel('island volume')
                    else
                        if k==alphaON*4+betaON*4+TON*4+SeaON*4
                            SEALEVEL(:,j)=d4(temp1>0);
                            plot(sealevelj(:),d4(:),'.','MarkerSize',1),hold on;
                            xlabel('Sealevelchange')
                            ylabel('roll back distance')
                        end
                    end
                end
            end
            std_Sealevel(j)=std(SEALEVEL(:,j));
            errorbar(SealevelGroup(1,j),mean(SEALEVEL(:,j)),std_Sealevel(1,j),'Color','r','LineWidth',2);
        end
    end
end

% SEDIMENT
if SedON==1
    for k=alphaON*4+betaON*4+TON*4+SeaON*4+SedON*1:alphaON*4+betaON*4+TON*4+SeaON*4+SedON*4
        subplot(rows,columns,k); 
        for j=1:length(add_sediment_array);
        temp1=(sediment(:)==add_sediment_array(j));
        SedimentGroup(:,j)=sediment(temp1>0);
          if k==alphaON*4+betaON*4+TON*4+SeaON*4+SedON*1
              SEDIMENT(:,j)=d1(temp1>0);
              plot(sedimentj(:),d1(:),'.','MarkerSize',1),hold on;
              xlabel('added Sediment')
              ylabel('max island height')
          else
              if k==alphaON*4+betaON*4+TON*4+SeaON*4+SedON*2
                  SEDIMENT(:,j)=d2(temp1>0);
                  plot(sedimentj(:),d2(:),'.','MarkerSize',1),hold on;
                  xlabel('added Sediment')
                  ylabel('island width') 
              else
                  if k==alphaON*4+betaON*4+TON*4+SeaON*4+SedON*3
                      SEDIMENT(:,j)=d3(temp1>0);
                      plot(sedimentj(:),d3(:),'.','MarkerSize',1),hold on;
                      xlabel('added Sediment')
                      ylabel('island volume')
                  else
                      if k==alphaON*4+betaON*4+TON*4+SeaON*4+SedON*4
                          SEDIMENT(:,j)=d4(temp1>0);
                          plot(sedimentj(:),d4(:),'.','MarkerSize',1),hold on;
                          xlabel('added Sediment')
                          ylabel('roll back distance')
                      end
                  end
              end
          end
        std_Sediment(j)=std(SEDIMENT(:,j));
        errorbar(SedimentGroup(1,j),mean(SEDIMENT(:,j)),std_Sediment(1,j),'Color','r','LineWidth',2);
        end
    end
end