clear all
close all
clc

load('MAT\rtk_data');
load('MAT\sb25m_data');
load('MAT\sb50m_data');
load('MAT\set_data');

%Meetonnaukeurigheden in [m]
rtk_nau = 0.03;
sb_nau = 0.10;

for i = 1:length(rtk_data.datum)
    for j = 1:length(set_data.naam)
        if ~isnan(set_data.x(j))
            rtk_set(i,j) = interp2(rtk_data.x{i},rtk_data.y{i},rtk_data.z{i},set_data.x(j),set_data.y(j));
        else
            rtk_set(i,j) = NaN;
        end
    end
end

for i = 1:length(sb25m_data.datum)
    for j = 1:length(set_data.naam)
        if ~isnan(set_data.x(j))
            sb25m_set(i,j) = interp2(sb25m_data.x{i},sb25m_data.y{i},sb25m_data.z{i},set_data.x(j),set_data.y(j));
        else
            sb25m_set(i,j) = NaN;
        end
    end
end

for i = 1:length(sb50m_data.datum)
    for j = 1:length(set_data.naam)
        if ~isnan(set_data.x(j))
            sb50m_set(i,j) = interp2(sb50m_data.x{i},sb50m_data.y{i},sb50m_data.z{i},set_data.x(j),set_data.y(j));
        else
            sb50m_set(i,j) = NaN;
        end
    end
end

%Start SET loop
h = figure;
j = 0;
f = 1;
for i = 1:length(set_data.naam)
    j = j + 1;
    subplot(2,2,j)
    plot(set_data.datum{i},set_data.z{i},'kx','MarkerSize',9)
    grid on
    hold on
    for jj = 1:length(rtk_data.datum)
        plot([rtk_data.datum{jj} rtk_data.datum{jj}],[rtk_set(jj,i)-rtk_nau rtk_set(jj,i)+rtk_nau],'r-')
    end
    plot([rtk_data.datum{:}],rtk_set(:,i),'r^','MarkerFaceColor','r')
    %%%
    for jj = 1:length(sb25m_data.datum)
        plot([sb25m_data.datum{jj} sb25m_data.datum{jj}],[sb25m_set(jj,i)-sb_nau sb25m_set(jj,i)+sb_nau],'b-')
    end    
    plot([sb25m_data.datum{:}],sb25m_set(:,i),'bo','MarkerFaceColor','w')
    %%%
    for jj = 1:length(sb50m_data.datum)
        plot([sb50m_data.datum{jj} sb50m_data.datum{jj}],[sb50m_set(jj,i)-sb_nau sb50m_set(jj,i)+sb_nau],'b-')
    end    
    plot([sb50m_data.datum{:}],sb50m_set(:,i),'bo','MarkerFaceColor','b')
%     startDate = datenum('10-01-2008');
%     endDate = datenum('12-31-2009');
%     xData = linspace(startDate,endDate,16);
    set(gca,'XTick',[datenum('10-01-2008'),datenum('11-01-2008'),datenum('12-01-2008'),datenum('01-01-2009'),datenum('02-01-2009'),....
                    datenum('03-01-2009'),datenum('04-01-2009'),datenum('05-01-2009'),datenum('06-01-2009'),datenum('07-01-2009'),...
                    datenum('08-01-2009'),datenum('09-01-2009'),datenum('10-01-2009'),datenum('11-01-2009'),datenum('12-01-2009'),...
                    datenum('01-01-2010')]);
    datetick('x','mm','keepticks')
    title(['SET ',set_data.naam{i}])
    if j == 1           
        ylabel('bodemligging (m NAP)')       
    elseif j == 2 
    elseif j == 3
        xlabel('datum')              
        ylabel('bodemligging (m NAP)')               
    elseif j == 4
        xlabel('datum')                      
    end
    if i == 4 || i == 7 || i == 11 || i == 14
        saveas(gcf,['EPS\rtk_sb_set',num2str(f,'%02.0f'),'.eps'],'psc2')
        saveas(gcf,['PNG\rtk_sb_set',num2str(f,'%02.0f'),'.png'])
        pause
        close(h);
        if i ~= 14
            h = figure;        
            j = 0;
            f = f + 1;
        end
    end    
end

 

 