clear all
close all
clc

%Behoeft MCTools
filename={'cirkel_bestek.asc'};

for i=1:length(filename(:,1))
    clear noc nor xorg yorg dumgrid grid x y z
    
    fid=fopen([filename{i}]);

    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;
end
fgetl(fid);
fgetl(fid);

A = fscanf(fid,'%f',[noc nor]);
fclose(fid);
A = A';
[row,col] = find(A == 1);
%A(row,col)

cb_data.opp = length(row)*grid_res^2;

figure
[C,h] = contour(x,y,A,1);
A = get(h,'ContourMatrix');
cb_data.x = A(1,2:end);
cb_data.y = A(2,2:end);
hold on
plot(cb_data.x,cb_data.y,'k.')
axis equal
xlabel('xRD (m)')
ylabel('yRD (m)')
title('Cirkel bestek Galgeplaat suppletie')  

save cb_data cb_data