%function [ output_args ] = wlegandr( input_args )
%WLEGANDR Summary of this function goes here
%  Detailed explanation goes here
win=500; step=1; sn=2;
[rw,cw]=size(data);
wdata=zeros(win,(rw-win));
for ii=1:step:rw-win;
    wdata(1:win,ii)=data(ii:ii+win-1,sn);
end
 jj=1; [rw,cw]=size(wdata);
for ii=1:cw
   if wdata(1,ii)~=0
      wdata1(1:rw,jj)=wdata(1:rw,ii);
        jj=jj+1;
    end
end
wdata=wdata1; %wdata2=wdata3;
clear ii jj rw cw wdata1
[rw,cw]=size(wdata);
xxx=zeros(1,cw); xxy=zeros(50,cw); xxz=zeros(50,cw);
for ii=1:cw
    clear xy xz f_alpha1 alpha1
    x=wdata(:,ii);
N = length(x) ;
Nscale = max(2,round(log2(N/16))) ; 
[wt,scale] = contwtmir(x,2^(-Nscale),2^(-1),2*Nscale,8*i) ;
Q = linspace(-4,4,50) ;
[alpha,f_alpha] = contwtspec(wt,scale,Q,1,0);
xy=length(alpha); alpha1(1:(50-xy))=alpha(xy); alpha=[alpha alpha1]; 
xz=length(f_alpha); f_alpha1(1:(50-xz))=f_alpha(xz); f_alpha=[f_alpha f_alpha1];
xxy(1:length(alpha),ii)=alpha(:);
xxz(1:length(f_alpha),ii)=f_alpha(:);
xxx(1,ii)=ii;
end
xxx=repmat(xxx,50,1);

clear xy xz f_alpha1 alpha1 N Nscale Q f_alpha alpha scale
clear wdata x xy xz wt ii


[rw,cw]=size(data);
wdata=zeros(win,(rw-win));
wdata2=zeros(win,(rw-win));
for ii=1:step:rw-win;
    wdata(1:win,ii)=data(ii:ii+win-1,sn);
    wdata2(1:win,ii)=data(ii:ii+win-1,1);
end
 jj=1; [rw,cw]=size(wdata);
for ii=1:cw
   if wdata(1,ii)~=0
      wdata1(1:rw,jj)=wdata(1:rw,ii);
      wdata3(1:rw,jj)=wdata2(1:rw,ii);
      jj=jj+1;
    end
end
wdata=wdata1; wdata2=wdata3;
clear ii jj rw cw step wdata1 

wdata2=max(wdata2); wdata31=wdata2; [rw,cw]=size(wdata2);
wdata2=wdata2(1,2:fix(cw/10):cw); wdata2=wdata2';
xxt=num2str(wdata2); figure(2)
subplot(2,1,1); surf(xxx,xxy,xxz);
XMIN=min(min(xxx)); YMIN=min(min(xxy)); ZMIN=min(min(xxz));
XMAX=max(max(xxx)); YMAX=max(max(xxz)); ZMAX=max(max(xxz));
axis([XMIN XMAX YMIN YMAX ZMIN ZMAX]) 
%shading interp;
set(gca,'XTickLabel',xxt)
title(textdata(1,sn),'FontSize',16,'FontName','Times New Roman');
ylabel('\alpha','FontSize',14,'FontName','Times New Roman');
zlabel('f(\alpha)','FontSize',14,'FontName','Times New Roman');
subplot(2,1,2); 
contourf(xxx,xxy,xxz);colorbar;grid on
set(gca,'XTickLabel',xxt)
xlabel('Time, years','FontSize',14,'FontName','Times New Roman');
ylabel('\alpha','FontSize',14,'FontName','Times New Roman');
zlabel('f(\alpha)','FontSize',14,'FontName','Times New Roman');
clear XMIN XMAX YMIN YMAX ZMIN ZMAX