clear all
close all
clc

sb25m_dir = 'D:\werf_je\Werk\1.201.819-Proefsuppletie_Galgeplaat_2e_evaluatie\Data\SB25m';
i = 0;
datum = {'07-05-2008','18-10-2008','30-10-2008','14-11-2008','14-12-2008','12-01-2009',...
         '09-02-2009','14-03-2009','22-07-2009','21-09-2009'};

for file = dir(fullfile(sb25m_dir,'*.txt'))',
    clear noc nor xorg yorg grid_res x y z
    i = i + 1;
    
    fid = fopen(fullfile(sb25m_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;
    sb25m_data.datum(i) = {datenum(datum(i),'dd-mm-yyyy')};
    sb25m_data.naam(i) = {strrep(file.name,'.txt','')};
    sb25m_data.x(i) = {x};
    sb25m_data.y(i) = {y};
    sb25m_data.z(i) = {z};   
    
    h = figure;
    contourf(sb25m_data.x{i},sb25m_data.y{i},sb25m_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(sb25m_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\sb25m_data sb25m_data