function a=doit(printdir,filename,file,j,q)

BEGIN=1
WIN=40
Q=q;
J=j;
T=2^(j/q);
clf
beginindex=BEGIN
windowsnb=WIN
[Y,ff]=wavread(filename);
Y=Y/norm(Y);
TT=floor(length(Y)/(2^15+windowsnb*2^15))
SC111=[];
SC121=[];
printdir=printdir(1:30)
mkdir(['/NAS3/SABIOD/public_data/' printdir '/']);
II=0;
energietotale11=0;
for JJJ=1:TT

II=II+1;
j
j
j
j
endindex=beginindex+2^15+2^15*windowsnb

YY=Y(beginindex:(beginindex+2^15+windowsnb*2^15));
[SC11,begintime,endtime,enersc11]=humpbackw2(1,j,q,YY);
SC11=flipud(SC11);
MEAN=mean(SC11(1,:));
%for JJ=1:length(SC11)
%if SC11(1,JJ)>1.1*MEAN
%SC11(:,JJ)=0;
%JJ
%end
%end
SC11=SC11(1:end-1,:);
SC11(:,1)=0;
SC11(:,end)=0;
MAX=(median(sum(SC11(10:end-25,:))))*1.35;
b=find(sum(SC11(10:end-25,:))>MAX);
y=zeros(1,length(SC11));
x=1:length(SC11);
energies=zeros(1,length(SC11));
for i=1:length(y)
if sum(SC11(10:end-25,i))>(MAX)
[n,m]=max(SC11(10:end-26,i));
y(i)=m+26;
energies(i)=n;
end
end
y(1)=0;
y(end)=0;
EE=energies;
seconds=length(YY)/ff;
seconds=seconds/length(SC11);

xticksd=x(find(diff(y>0.0)==1));
%bon=sum(SC11(2:4,xticksd))<mean(SC11(2:4,xticksd));
%xticksd=xticksd(bon);
xticksf=x(find(diff(y>0.0)==-1));
%a=find(diff(sum(SC11(:,:))>(MAX))==1)
%xtickf=xticksf(bon);
m=y(xticksd+1);
energies=energies(xticksd+1);
binpos=xticksd;
xticksd=seconds.*xticksd;
xticksf=seconds.*xticksf;
%xticksf=xticksf(2:end);
%xticksd=xticksd(m>4|m<70);
%xticksf=xticksf(m>4|m<70);
%energies=energies(m>4|m<70);
%length(m)
%m=m(m>4|m<70);


for i=1:length(b)
SC11(:,b(i))=SC11(:,b(i))/max(SC11(:,b(i)));
end
%y=zeros(1,length(SC11));
%x=1:length(SC11);
%energies=zeros(1,length(SC11));
%for i=1:length(y)
%if sum(SC11(:,i))>(MAX)
%[n,m]=max(SC11(end,i))
%y(i)=n;
%energies(i)=m;
%end
%end
y(1)=0;
y(end)=0;
%x=x(y>0);
%y=y(y>0);
SC111=[SC111 SC11];
energietotale11=energietotale11+enersc11;
totaltime=length(YY);

figure()
subplot(5,1,1)
hold on
plot(10*YY)
xlim([1 length(YY)]);
title({['BALESTRIERO R. & GLOTIN H.  SABIOD.ORG - MI CNRS - Univ. Toulon  Scalogram representation on bioacoustic data [ScatNet] using a Gabor mother wavelet on file : ' file ' Start at : ' num2str(beginindex)];'   ';'Waveform representation'},'fontsize',25,'Interpreter','none')

seconds=length(YY)/ff
seconds=seconds/length(SC11)
subplot(5,1,3)
hold on
xticks=x(find(diff(sum(SC11)>(MAX))==1));
xtickss=seconds.*xticks;
s=size(SC11);
YYY=zeros(1,s(1));
YYY(1)=ff/2;
for k=1:9
ou=k*q-1;
cb=ff/2^(k+1);
if ou<j
YYY(ou)=cb;
end
end
YYY(79)=8926;
YYY=fliplr(YYY)
size(SC11)
set(gca,'XTickLabel',sprintf('%3.2f|',xtickss));
set(gca,'YTick',find(YYY>0))
set(gca,'YTickLabel',sprintf('%3.2f|',YYY(YYY>0)));
imagesc(SC11);
ylabel('Frequency Hz')
%set(gca,'YDir','normal');
xlim([1 length(sum(abs(SC11(2:end-2,:))))]);
set(gca,'XTick',xticks);
title(['Complete scalogram and formant tracker, T' num2str(T) ', Q' num2str(q) ', J' num2str(j) ],'fontsize',25)

subplot(5,1,5)
hold on
plot(x,EE,'r','linewidth',2)
ylabel('Wavelet coefficient')
xlim([1 length(x)])
%set(gca,'XTickLabel',sprintf('%3.2f|',xtickss));
%set(gca,'XTick',xticks);
title(['Energy of the formants'])


subplot(5,1,4)
hold on
set(gca,'YTick',find(YYY>0))
set(gca,'YTickLabel',sprintf('%3.2f|',YYY(YYY>0)))
plot(x,y,'r','linewidth',2)
xlim([1 length(x)])
ylabel('Frequency Hz')
grid on;
title(['Position of the formants' ],'fontsize',25)


subplot(5,1,2)
specgram(YY,128,ff,[],64);
title(['Spectrogram coeffs (specgram func): window=128, noverlap=64'],'fontsize',25)
a=13
if windowsnb>1
a=2*windowsnb*3.5
end
set(gcf,'PaperUnits','inches','PaperPosition',[0 0 a 36])

%xticksd=x(find(diff(sum(SC11(2:end-1,:))>(MAX))==1));
%xticksf=x(find(diff(sum(SC11(2:end-1,:))>(MAX))==-1));
%m=y(xticksd+1);
%energies=energies(xticksd+1);
%xticksd=seconds.*xticksd;
%xticksf=seconds.*xticksf;
%xticksf=xticksf(2:end);
%xticksd=xticksd(m>4|m<70);
%xticksf=xticksf(m>4|m<70);
%energies=energies(m>4|m<70);
%m=m(m>4|m<70);
length(energies)
length(xticksd)
length(xticksf)
length(m)
r=[binpos',xticksd',xticksf',m',energies'];
save(['/NAS3/SABIOD/public_data/' printdir '/' file '_README_part'  num2str(JJJ) '.txt'],'r','-ascii')
print(['/NAS3/SABIOD/public_data/' printdir '/' file '_part'  num2str(JJJ) '.png'],'-dpng','-r100')
beginindex=endindex;
wavwrite(YY,ff,['/NAS3/SABIOD/public_data/' printdir '/' file '_part' num2str(JJJ) '.wav'])
save(['/NAS3/SABIOD/public_data/' printdir '/' file '_part' num2str(JJJ) '.txt'],'SC11','-ascii')


end
end

