hurricane='fran';
threshold=3;
edges_lambda=200:25:2000;
RO=3;%2 if RO=100 and 3 if RO = 150
load(['C:\Documents and Settings\sylvie lorsolo\My Documents\research\programs\ratio.mat']);
rep='wavelength analysis';
files=dir(['C:\Documents and Settings\sylvie lorsolo\My Documents\research\',hurricane,'\data\',rep,'\*.mat']); 
for fil=2%:length(files)
    load(['C:\Documents and Settings\sylvie lorsolo\My Documents\research\',hurricane,'\data\',rep,'\',files(fil).name]);
    [li,col]=size(lambda(1).z_data);
    
    for i=1:length(lambda)
        p_to_t=[];
        
        for j=1:col
            data=lambda(i).z_data(:,j);
            u_NaN=find(~isnan(data));
            if length(u_NaN)<20
                data(u_NaN)=NaN;
            end
            %data_copy=data;
            
            
            x=lambda(i).plan_axis2(1,:);
      
            
            
            
            extrema=[];
            amplit=[];
            for k=2:length(data)-1
                if data(k)>data(k+1) & data(k)> data(k-1)
                    
                    extrema=[extrema;x(k)];
                    amplit=[amplit;data(k)];
                elseif data(k)<data(k+1) & data(k)< data(k-1)
                    
                    extrema=[extrema;x(k)];
                    amplit=[amplit;data(k)];
%                 elseif isnan(data(k))==1 | isnan(data(k+1))==1 | isnan(data(k-1))==1
%                     
%                     extrema=[extrema;NaN];
%                     amplit=[amplit;NaN];
                end
                
            end
            if length(extrema)<=1
                extrema=[extrema;NaN;NaN];
            end
            if length(amplit)<=1
                amplit=[amplit;NaN;NaN];
            end
            
            diff_ext=2*abs(extrema(2:length(extrema))-extrema(1:length(extrema)-1));
            
            diff_ext2=diff_ext;
            diff_amplit=abs(amplit(2:length(amplit))-amplit(1:length(amplit)-1));
          
            
            %             %%%%---------------------THERSHOLDING-----------%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
            clear('diff_ext2');
            u_threshold=find(abs(diff_amplit) >= threshold);
            diff_ext2=diff_ext(u_threshold);
            
            
                                    %%%%%%-------------END THRESHOLDING------------%%%
            
            
            
            
            [m,n]=size(p_to_t);
            
            if length(diff_ext2) < m
                add=abs(length(diff_ext2)-m);
                add=NaN*ones(add,1);
                diff_ext2=[diff_ext2;add];
                p_to_t=[p_to_t diff_ext2];
                
                
            elseif length(diff_ext2) > m
                add=abs(length(diff_ext2)-m);
                add=NaN*ones(add,n);
                p_to_t=[p_to_t;add];
                p_to_t=[p_to_t diff_ext2];
                
                
            elseif length(diff_ext2) == m
                p_to_t=[p_to_t diff_ext2];
            end
            
            
        end
        
        
        wave(i).p_to_t=p_to_t;
        
    end
    save(['C:\Documents and Settings\sylvie lorsolo\My Documents\research\',hurricane,'\data\',rep,'\extrem\ess_',files(fil).name],'wave');
    
     clear('wave');
end