%
clear all
close all

OPT.xls = 'supp-holland-metnourishtypes_new.xls';

D = xls2struct(OPT.xls)

[D.x_eind2 ,D.y_eind2 ] = xRSP2xyRD(0,D.kustvak,D.eindraai *100);
[D.x_begin2,D.y_begin2] = xRSP2xyRD(0,D.kustvak,D.beginraai*100);

%for i=1:length(D.kustvak);
%[D.x_begin2(i),D.y_begin2(i)] = xRSP2xyRD(0,D.kustvak(i),D.eindraai(i)*100);
%end
struct2xls('tst',D)

D.r = sqrt((D.x_begin2 - D.x_begin).^2 + (D.y_begin2 - D.y_begin).^2);

%%
figure('name','scatter')
plot  (D.x_begin,D.x_begin2,'b.','displayname','x_{begin}')
hold   on
plot  (D.x_eind ,D.x_eind2 ,'bx','displayname','x_{eind}')
plot  (D.y_begin,D.y_begin2,'r.','displayname','y_{begin}')
plot  (D.y_eind ,D.y_eind2 ,'rx','displayname','y_{eind}')
xlabel(OPT.xls)
ylabel('xRSP2xyRD(0,D.kustvak(i),D.eindraai(i)*100)')

legend show
grid on
plot([0 7e5],[0 7e5],'k')
axis equal
print2screensize('xRSP2xyRD_scatter')

%%
figure('name','hist')
hist(D.r(D.r > 0),50)
xlabel('error [m]')
ylabel('#')
grid on
title({['error = 0: ',num2str(length(find(D.r==0      )))],...
       ['error > 0: ',num2str(length(find(D.r>0       )))],....
       ['undefined: ',num2str(length(find(isnan(D.r  ))))],....
       })
%set(gca,'xscale','log')
print2screensize('xRSP2xyRD_hist')

%%
figure('name','planview')
plot(D.x_begin,D.y_begin,'k.','displayname','original')
hold on
plot(D.x_begin2,D.y_begin2,'ko','displayname','recalculate')
legend show
caxis([0 5e3])
plotc(D.x_begin2,D.y_begin2,D.r)
colorbar

%sub = find(~isnan(D.x_begin) & ~isnan(D.x_begin2))
%plot(D.x_begin2(sub),D.y_begin2(sub),'ro','displayname','recalculate')
axis equal

grid on
print2screensize('xRSP2xyRD_planview')
