movie=0;
% XB=getdimensions;
% load('allequilibriumprofiles.txt')
% load('checkcontinuity')

modeltrain_number=11;

inputdir = fullfile(fileparts(which(mfilename)),'..','InputData','Grids');
x= load(fullfile(inputdir,'x.grd'));
xas=x(1,:);
load(fullfile(fileparts(which(mfilename)),'..','Output',['Modeltrain_number_',num2str(modeltrain_number,'%02i')],'Analyses'))

nr_hurricanes=size(Analyses,2);
for j=1:nr_hurricanes
    zb_simpl=squeeze(Analyses{1,j}.XBeach.hydro.zb(:,2,:))';
    zs_simpl=squeeze(Analyses{1,j}.XBeach.hydro.zs(:,2,:))';
    H_simpl=squeeze(Analyses{1,j}.XBeach.hydro.H(:,2,:))'/2;
    
    recoveryphase=Analyses{1,j}.recovery.profiles;
    allequilibriumprofiles(j,:)=Analyses{1,j}.equilibriumprofile;
    
    
    blanco=zeros(size(Analyses{1,j}.recovery.profiles,1),size(Analyses{1,j}.recovery.profiles,2));
    
    profile=[zb_simpl; recoveryphase];
    wave=[H_simpl; blanco];
    surface=[zs_simpl; blanco];
    
    Matrix{1,j}=profile;
    WaveM{1,j}=wave;
    SurfaceM{1,j}=surface;
    
    j+1;
end
if movie==0
    figure()
end
%j is nummer of hurricane
%r is row number
if movie==1
    fig=figure;
    MAP=colormap;
    aviobj=avifile('9timesOverwash.avi','compression','none','fps',5,'COLORMAP',MAP,'quality',100);
end
for j=1:nr_hurricanes
    for r=1:size(Matrix{1,j},1)
        plot(xas,(SurfaceM{1,j}(r,:)+WaveM{1,j}(r,:)),'b','LineWidth',2);hold on
        set(gca,'layer','top');
%         harea=area(xas,[(SurfaceM{1,j}(r,:)'+WaveM{1,j}(r,:)'),Matrix{1,j}(r,:)'])
        hulpMatrix=(0-Matrix{1,j}(r,:));
%         hulpMatrix(Matrix{1,j}(r,:)>=0)=0;
        nieuweMatrix=[Matrix{1,j}(r,:)',hulpMatrix'+(SurfaceM{1,j}(r,:)'+WaveM{1,j}(r,:)')];
        harea=area(xas,nieuweMatrix);
        set(harea(1),'FaceColor',[255/255 255/255 255/255]);
        set(harea(2),'FaceColor',[215/255 240/255 255/255]);
        fill([xas,xas(end)+0.1],[Matrix{1,j}(r,:),Matrix{1,j}(r,1)],[255/255 255/255 210/255]);
        plot(xas,Matrix{1,j}(r,:),'k','LineWidth',2); 
%         plot(xas,SurfaceM{1,j}(r,:),'r');
        plot(xas,Matrix{1,1}(1,:),'--r','LineWidth',2);
        if r>size(zb_simpl,1)
            plot(xas,allequilibriumprofiles(j,:),':k','LineWidth',2);
        end
%         if r<=size(H_simpl,1)
%             title(['hurricane ',num2str(j),'-',num2str(r)]);
%         end
%         if r>size(H_simpl,1)
%             title(['recovery ',num2str(j),'-',num2str(r-size(H_simpl,1))])
%         end
        if r<=size(H_simpl,1)
            text(2850,7,['hurricane ',num2str(j,'%02i'),'-',num2str(r)],'FontSize',14,'FontWeight','bold');
        end
        if r>size(H_simpl,1)
            text(2850,7,[' recovery ',num2str(j,'%02i'),'-',num2str(r-size(H_simpl,1))],'FontSize',14,'FontWeight','bold');
        end
        
%         text(3000,-7.2,['continuity XBeach phase      ',num2str(Analyses{1,j}.XBeach.Volumes.continuity)],'FontSize',11);
%         text(3000,-8,['continuity recovery phase   ',num2str(Analyses{1,j}.recovery.continuity)],'FontSize',11);
%         if r>size(H_simpl,1)
%         text(3000,-8.8,['width of the island recovery phase   ',num2str(Analyses{1,j}.recovery.islandwidth(1,r-size(H_simpl,1)))],'FontSize',11);
%         end
        axis([0000 7500 -10 10]);
%         axis([3500 5000 0.35 0.37]);
        pause(0.1), hold off
%         mkdir('afbeeldingen')
%         cd([cd,'\afbeeldingen'])
%         teller=([num2str(j,'%02i'),'-',num2str(r,'%02i'),'.png']);
%         saveas(gcf,teller)
%         cd ..

            
        if movie==1
            F=getframe(fig);
            aviobj=addframe(aviobj,F);

        end
    end
end
if movie==1;
    close(fig);
    aviobj=close(aviobj);
end


