function retreat = compute_retreat2(x, z0, zend, dxmin, elevation_to_check_propagation_front)
%     dxmin = min(abs(diff(x)));

    if ~exist('elevation_to_check_propagation_front', 'var')
        elevation_to_check_propagation_front = max(z0)-dxmin*1.5;
    end
    
    % X at t0
    iF = find(z0>elevation_to_check_propagation_front,1,'first');
    x_initial_XBeach = interp1(z0(iF-1:iF), x(iF-1:iF),elevation_to_check_propagation_front);
    
    % X at tend
    try
        iF = find(zend>elevation_to_check_propagation_front,1,'first');
        x_final_XBeach = interp1(zend(iF-1:iF),x(iF-1:iF),elevation_to_check_propagation_front);
        retreat = x_final_XBeach-x_initial_XBeach;
    catch
        retreat = NaN;
    end    
end