z_contour = 5;

% read jarkus transects
tr = jarkus_transects(...
    'year', 2010,...
    'output', {'id', 'time', 'x', 'y', 'lon', 'lat', 'cross_shore', 'altitude'});

%% calculate curvature
[curvatures radii relativeAngle distances x y cross_shore] = jarkus_curvature(tr,...
    'method', 'circle',...
    'z', z_contour,...
    'christmas', true);

[lat lon] = deal(nan(size(tr.id)));
for i = 1:length(tr.id)
    lon(i) = interp1(tr.cross_shore, tr.lon(i,:), cross_shore(i));
    lat(i) = interp1(tr.cross_shore, tr.lat(i,:), cross_shore(i));
end

%% kml
locname = cellfun(@(x,y) sprintf('%i; r=%im', x,y), num2cell(tr.id), num2cell(radii), 'uniformoutput', false);
% html = cellfun(@(x,y,z) sprintf('mean D50: %.0f &mu;m</br>sigma D50: %.0f &mu;m</br>calculation D50: %.0f &mu;m', x, y, z),...
%     num2cell(meanD50*1e6), num2cell(sigmaD50*1e6), num2cell(calcD50*1e6), 'uniformoutput', false);

path_kml = cd;
kmlfile = fullfile(path_kml, 'coastal_curvature.kml');
mkpath(path_kml)
idx = radii>0 & radii < max(radii);
KMLscatter(lat(idx), lon(idx), radii(idx),...
    'fileName', kmlfile,...
    'name',locname(idx),...
...    'snippets', snippets,...
...    'html', html,...
    'scalenormalState',.5,...
    'scalehighlightState',1.5)
