%%%%%%%%%% adesc_findextr.m %%%%%%%%%%
function [fmax]=adesc_findextr(error,indx_edges,epsilon)
% 
% returns indices of the extremals in "fmax".
%
error = error(:);
indx_edges = indx_edges(:);
Ngrid = length(error);
abs_e = abs(error);
abs_e = [abs_e(2); abs_e; abs_e(Ngrid-1)];
fmax = find( (abs_e(2:Ngrid+1) >= abs_e(1:Ngrid)) & ...
             (abs_e(2:Ngrid+1) > abs_e(3:Ngrid+2)) ); 
fmax = fmax(:);
fmax = sort([fmax; indx_edges]);
abs_e([1;Ngrid+2]) = [];
fmax(find(~(fmax(1:length(fmax)-1)-fmax(2:length(fmax)))))=[];
if (length(fmax) > 1)
  fmax(find(abs_e(fmax)/max(abs_e) < epsilon)) = []; 
end;
%%%%%%%%%% End adesc_findextr.m %%%%%%%%%%%
