clear all
close all
clc

grid_res = 2.5;
load('MAT\rtk_data');
load('MAT\sb25m_data');
load('D:\werf_je\Werk\1.201.819-Proefsuppletie_Galgeplaat_2e_evaluatie\Data_analyse\Cirkel_bestek\cb_data');
titlenum = {'a','b','c','d','a','b','c','d','a','b','c','d','a','b','c','d'};

%Gecombineerde set maken
len1 = length(rtk_data.datum);
len2 = length(sb25m_data.datum);
%
rtk_sb25m_data.datum(1:len1) = rtk_data.datum;
rtk_sb25m_data.datum(len1+1:len1+len2) = sb25m_data.datum;
%
rtk_sb25m_data.naam(1:len1) = rtk_data.naam;
rtk_sb25m_data.naam(len1+1:len1+len2) = sb25m_data.naam;
%
rtk_sb25m_data.x(1:len1) = rtk_data.x;
rtk_sb25m_data.x(len1+1:len1+len2) = sb25m_data.x;
%
rtk_sb25m_data.y(1:len1) = rtk_data.y;
rtk_sb25m_data.y(len1+1:len1+len2) = sb25m_data.y;
%
rtk_sb25m_data.z(1:len1) = rtk_data.z;
rtk_sb25m_data.z(len1+1:len1+len2) = sb25m_data.z;
%
rtk_sb25m_data.type(1:len1) = {'RTK'};
rtk_sb25m_data.type(len1+1) = {'singlebeam 25 m'};
rtk_sb25m_data.type(len1+2:len1+4) = {'gecombineerde meting'};
rtk_sb25m_data.type(len1+5:len1+len2) = {'singlebeam 25 m'};

%Even sorten op datum
[hm ind] = sort([rtk_sb25m_data.datum{:}]);
rtk_sb25m_data.datum = rtk_sb25m_data.datum(ind);
rtk_sb25m_data.naam = rtk_sb25m_data.naam(ind);
rtk_sb25m_data.x = rtk_sb25m_data.x(ind);
rtk_sb25m_data.y = rtk_sb25m_data.y(ind);
rtk_sb25m_data.z = rtk_sb25m_data.z(ind);
rtk_sb25m_data.type= rtk_sb25m_data.type(ind);

for i = length(rtk_sb25m_data.naam)
    if i >= 2
      clear X Y Z X1 Y1 Z1 Zint
      if i~=9
        [X,Y] = meshgrid(rtk_sb25m_data.x{2},rtk_sb25m_data.y{2});
        Z = rtk_sb25m_data.z{2};
      else
        [X,Y] = meshgrid(rtk_sb25m_data.x{i-2},rtk_sb25m_data.y{i-2});
        Z = rtk_sb25m_data.z{i-2};
      end
      [X1,Y1] = meshgrid(rtk_sb25m_data.x{i},rtk_sb25m_data.y{i});
      Z1 = rtk_sb25m_data.z{i};
      Zint = interp2(X1,Y1,Z1,X,Y);
    figure
    [C,h] = contourf(X,Y,Zint-Z);
    hold on
    axis equal
    if i == 2
        noc = 24;
        set(h,'LevelList',[-1.2:0.2:1.2])
    else 
        noc = 8;
        set(h,'LevelList',[-0.4:0.1:0.4])        
    end
%     colormap(erosed(noc));    
    cmap = colormap;
    %axis([0.548 0.564 3.972 3.988]*1e5)
    axis([0.552 0.560 3.976 3.984]*1e5)
    plot(cb_data.x,cb_data.y,'k-','LineWidth',1.0)
    xlabel('xRD (m)')
    ylabel('yRD (m)') 

    title(['cumulatieve sedimentatie/erosie [m], ',datestr(rtk_sb25m_data.datum{i}),', ',rtk_sb25m_data.type{i}])
    if i == 2
        caxis([-1.2 1.2])
        hcb = colorbar;
        set(hcb,'ytick',[-1.2:0.2:1.2])
    else
       caxis([-0.4 0.4])
       hcb = colorbar;
       set(hcb,'ytick',[-0.4:0.1:0.4])        
    end
    saveas(gcf,['PNG\cum_sedero_',num2str(i-1,'%02.0f'),'.png'])
    saveas(gcf,['EPS\cum_sedero_',num2str(i-1,'%02.0f'),'.eps'],'psc2')
    end
end

% for i = 1:length(rtk_sb25m_data.naam)
%     if i >= 2
%       clear X Y Z X1 Y1 Z1 Zint
%       if i~=9
%         [X,Y] = meshgrid(rtk_sb25m_data.x{i-1},rtk_sb25m_data.y{i-1});
%         Z = rtk_sb25m_data.z{i-1};
%       else
%         [X,Y] = meshgrid(rtk_sb25m_data.x{i-2},rtk_sb25m_data.y{i-2});
%         Z = rtk_sb25m_data.z{i-2};
%       end
%       [X1,Y1] = meshgrid(rtk_sb25m_data.x{i},rtk_sb25m_data.y{i});
%       Z1 = rtk_sb25m_data.z{i};
%       Zint = interp2(X1,Y1,Z1,X,Y);
%     figure
%     [C,h] = contourf(X,Y,Zint-Z);
%     hold on
%     axis equal
%     if i == 2
%         noc = 24;
%         set(h,'LevelList',[-1.2:0.2:1.2])
%     else 
%         noc = 12;
%         set(h,'LevelList',[-0.3:0.1:0.3])        
%     end
%     colormap(erosed(noc));    
%     cmap = colormap;
%     axis([0.548 0.564 3.972 3.988]*1e5)
%     plot(cb_data.x,cb_data.y,'k-','LineWidth',1.0)
%     xlabel('xRD (m)')
%     ylabel('yRD (m)') 
% 
%     title(['(',titlenum{i-1},') sedimentatie/erosie [m], ',datestr(rtk_sb25m_data.datum{i}),', ',rtk_sb25m_data.type{i}])
%     if i == 2
%         caxis([-1.2 1.2])
%         hcb = colorbar;
%         set(hcb,'ytick',[-1.2:0.2:1.2])
%     else
%         caxis([-0.3 0.3])
%         hcb = colorbar;
%         set(hcb,'ytick',[-0.3:0.1:0.3])        
%     end
%     saveas(gcf,['PNG\sedero_',num2str(i-1,'%02.0f'),'.png'])
%     saveas(gcf,['EPS\sedero_',num2str(i-1,'%02.0f'),'.eps'],'psc2')
%     end
% end