%% plot jarkus profile
jarkus_file = 'http://opendap.deltares.nl:8080/thredds/dodsC/opendap/rijkswaterstaat/jarkus/profiles/transect.nc';
profile = 1427;
profile_count = 1;
time = 43; % for 2008
load surveylines

%RD coordinates of profile
X_rd = nc_varget(jarkus_file,'x',[profile 0],[profile_count -1]);
Y_rd = nc_varget(jarkus_file,'y',[profile 0],[profile_count -1]);
Z_rd = nc_varget(jarkus_file,'altitude',[time profile 0],[1 profile_count -1]);
jarkus_angle = nc_varget(jarkus_file,'angle',profile,1);

% Determine angle between lines
angle_between_lines = Surveylines{1}.angle_surveyline-jarkus_angle;

%%% Substract beachpole position
%%% Using the beachpole position is not axactly right because the intersection is not exactly on the pole 
Xnorm = X_rd - Surveylines{7}.beachpole_position(1);
Ynorm = Y_rd - Surveylines{7}.beachpole_position(2);

dist = sqrt(Ynorm.^2+Xnorm.^2).*(Ynorm./abs(Ynorm));
transect = -dist*cosd(angle_between_lines);


% discard nan's

figure(8)
plot(transect(~isnan(Z_rd)),Z_rd(~isnan(Z_rd)),'b','linewidth',2,'Color',[0.6 0.2 0]);

hold on

xlabel('Cross shore distance from reference line')
set(gcf,'position',[130 584 911 318])
% plot([-500 2000],[0 0],'-c')
xlim([-300 1300])
%% plot survey profile august 2009

 [survey.cross_shore,survey.altitude] = combine_surveys(2009,8,7);

plot(survey.cross_shore, survey.altitude,'linewidth',2,'Color',[0.749 0.749 0]);


% plot([-500 2000],[0 0],'--','Color',[0.702 0.7804 1])

title('Jarkus profile 11535')
xlabel('Cross shore distance from reference line')
ylabel('Elevation relative to NAP [m]')

% legend('old (2008) profile','new (august 2009) profile')

%% plot survey profile November 2010
 [survey.cross_shore,survey.altitude] = combine_surveys(2010,11,7);
 plot(survey.cross_shore, survey.altitude,'linewidth',2,'Color',[0.0784 0.1686 0.5490]);


plot([-500 2000],[0 0],'--','Color',[0.702 0.7804 1])

title('Jarkus profile 11535')
xlabel('Cross shore distance from reference line')
ylabel('Elevation relative to NAP [m]')

legend('old (2008) profile','new (august 2009) profile','latest (november 2010) profile')

