function[z_deriv_1, x_deriv_1]=repeat_steps(z_deriv1, x_deriv1, z_prof2, x2, locs, yy, x1, x, profile, testing_profile, z_mean_high, loc_land, height_of_peaks, thresholdFlatDuration, thresholdZderiv1)
%%
%   --------------------------------------------------------------------
% input:
%
% z_deriv1                =   vertical values of the derivative
% x_deriv1                =   cross shore location of the derivative 
% z_prof2                 =   vertical values for the area of interest 
% x2                      =   cross shore values for the area of interest
% locs                    =   location of the peaks
% yy                      =   year of measurement
% x1                      =   cross shore values
% testing_profile         =   altitude values 
% z_mean_high             =   vertical value for mean high water level 
% loc_land                =   location of the landward boundary
% height_of_peaks         =   height of peaks which will be considered as
%                             dune peaks
% thresholdFlatDuration   =   if there are flat stretches longer than this
%                             threshold, the profil more seaward than that is deleted
% thresholdZderiv1

%
% output:
%
% z_deriv_1               =   updated vertical values of the derivative
% x_deriv_1               =   updated values for the cross shore distance

%   --------------------------------------------------------------------
% $Id: $
% $Date: $
% $Author: $
% $Revision: $
% $HeadURL: $
% $Keywords: $
%%
if isempty(locs)
    z_deriv_1   =   z_deriv1;
    x_deriv_1   =   x_deriv1;
    return
end

end_point       =   length(z_deriv1)+locs(end)+ loc_land-1;
z_prof3         =   testing_profile(1:end_point);
x3              =   x1(1:end_point);

[pks_new, locs_new, ~, ~]  =  findpeaks(z_prof3,'MinPeakProminence',height_of_peaks,'Annotate','extents'); 

if isempty(locs_new)
    z_deriv_1   =    z_deriv1;
    x_deriv_1   =    x_deriv1;
    return
end

if locs_new(end)==locs(end)
    z_deriv_1   =    z_deriv1;
    x_deriv_1   =    x_deriv1;
else
    [z_prof1,x1] =   version1(yy, z_prof3, x3, z_mean_high, height_of_peaks);
    [z_deriv1, x_deriv1]    =  derivative(z_prof1,x1);                             
    z_deriv1(abs(z_deriv1)  <  thresholdZderiv1) = 0;                

    degree = 1;
    [z_deriv_1, x_deriv_1]  =  filter_slope(thresholdFlatDuration, z_deriv1, x_deriv1, degree);

end


