
clear all
close all
clc

rtk_dir = 'D:\werf_je\Werk\1.201.819-Proefsuppletie_Galgeplaat_2e_evaluatie\Data\RTK';
i = 0;

%Data controleren!!!
datum = {'13-03-2009','24-06-2009','22-12-2009'};

for file = dir(fullfile(rtk_dir,'*.txt'))',
    %clear data
    clear noc nor xorg yorg grid_res x y z
    i = i + 1;
    
    fid = fopen(fullfile(rtk_dir,file.name));

    fscanf(fid,'%s',1);
    noc = fscanf(fid,'%f',1);
    
    fscanf(fid,'%s',1);
    nor = fscanf(fid,'%f',1);
    
    fscanf(fid,'%s',1);
    xorg = fscanf(fid,'%f',1);
    
    fscanf(fid,'%s',1);
    yorg = fscanf(fid,'%f',1);
    
    fscanf(fid,'%s',1);
    grid_res = str2num(fscanf(fid,'%s',1));

    x = xorg:grid_res:xorg+grid_res*(noc-1);
    y = yorg+grid_res*(nor-1):-grid_res:yorg;
    
    fgetl(fid);
    fgetl(fid);

    z = fscanf(fid,'%f',[noc nor]);
    fclose(fid);
    z = z';
    z(find(z == -9999)) = NaN;
    z = 0.01*z;
    rtk_data.datum(i) = {datenum(datum(i),'dd-mm-yyyy')};
    rtk_data.naam(i) = {strrep(file.name,'.txt','')};
    rtk_data.x(i) = {x};
    rtk_data.y(i) = {y};
    rtk_data.z(i) = {z};   
    
    h = figure;
    contourf(rtk_data.x{i},rtk_data.y{i},rtk_data.z{i},9)
    hold on
    xlabel('xRD (m)')
    ylabel('yRD (m)')
    axis equal   
    axis([0.545 0.565 3.97 3.99]*1e5)
    title(datestr(rtk_data.datum{i}))
    caxis([-1.5 0.75])
    h2 = colorbar;
    set(h2,'YTick',[-1.5:0.25:0.75])
    pause
    close(h);
end

save MAT\rtk_data rtk_data