clear all
close all
clc

rtkprof_dir = 'D:\werf_je\Werk\1.201.819-Proefsuppletie_Galgeplaat_2e_evaluatie\Data\RTK_profielen';
rtkprof_oorsprong = load(fullfile(rtkprof_dir,'rtkprof_oorsprong.txt'));
i = 0;
for file = dir(fullfile(rtkprof_dir,'*.xls'))'
    i = i + 1;
    clear num txt datum xRD yRD X Z
    [num, txt]= xlsread(fullfile(rtkprof_dir,file.name),'Data');
    txt_ind = 2:6:length(txt(1,:));
    datum = txt(7,txt_ind);
    for j = 1:length(datum)
        clear xrd yrd x z
        datum(j) = {strrep(datum{j},'-okt-','-10-')};
        %%%
        xrd = num(4:end,1+(j-1)*6)';
        yrd = num(4:end,2+(j-1)*6)';
        x = num(4:end,3+(j-1)*6)';
        z = num(4:end,4+(j-1)*6)';   
        %%%
        xRD(j) = {xrd(~isnan(xrd))};
        yRD(j) = {yrd(~isnan(yrd))};  
        X(j) = {x(~isnan(x))};
        Z(j) = {z(~isnan(z))};      
    end
    rtkprof_data.datum(i) = {datenum(datum,'dd-mm-yyyy')};
    rtkprof_data.naam(i) = {['RTK profiel ',num2str(i)]};
    rtkprof_data.xRD(i) = {xRD};
    rtkprof_data.yRD(i) = {yRD};
    rtkprof_data.X(i) = {X};
    rtkprof_data.Z(i) = {Z};
    rtkprof_data.X0(i) = rtkprof_oorsprong(i,2);
    rtkprof_data.Y0(i) = rtkprof_oorsprong(i,3);
    rtkprof_data.theta(i) = rtkprof_oorsprong(i,4);
    dum1 = rtkprof_data.X{i};
    dum2 = rtkprof_data.Z{i};
    figure
    plot(dum1{1},dum2{1},'k-')
    hold on
    grid on
    plot(dum1{2},dum2{2},'r-')
    plot(dum1{3},dum2{3},'b-')
    plot(dum1{4},dum2{4},'g-')
    plot(dum1{5},dum2{5},'m-')
    plot(dum1{6},dum2{6},'y-')
    plot(dum1{7},dum2{7},'c-')
    xlabel('x langs raai (m)')
    ylabel('z (m NAP)')
    title(rtkprof_data.naam{i})
    pause
end

save MAT\rtkprof_data rtkprof_data