function WENMinMaxPrognoz(infile,prognozfile,entrfile);
% Прогнозирование волн вейвлет-энтропии средствами синус-трендов
Y=dlmread(infile);
N=length(Y);
%if length(Y)>2000
%    Y=Y(length(Y)-2000:length(Y));
%    fprintf(1,'Time series are cutted: last 2000 points are used.\n');
%end
wtype=3;
wetype=2;
plotOn=0;
nend=12200;
nbeg=nend-2000;
%N=700;
%nend=N-100;
%nbeg=100;

Y1=Y(nbeg:nend);
[SWT,POWER,Pj]=waventropy(Y1,wtype,wetype,plotOn,0,0);
[n,m]=size(POWER);
scale=n;
dlmwrite(entrfile,POWER(scale,:),'\n');
entrfile2=strrep(entrfile,'.txt','_cut.txt');
timediff=40;
Y2=Y(nbeg-timediff:nend-timediff);
figure;
plot(Y2);
[SWT,POWER,Pj]=waventropy(Y2,wtype,wetype,plotOn,0,0);
[n,m]=size(POWER);
dlmwrite(entrfile2,POWER(scale,1:m),'\n');
niter=1;
outfile_remains=strrep(entrfile,'.txt','_predict.txt');
outfile_remains2=strrep(entrfile2,'.txt','_predict2.txt');
[rr,times, extrems]=MinMaxPredict(entrfile,outfile_remains,80);
[rr2,times2, extrems2]=MinMaxPredict(entrfile2,outfile_remains2,80);

mintime=min(length(times),length(times2));
diftimes=abs(times(1:mintime)+ones(1,mintime)*timediff-times2(1:mintime)) %ones(1,mintime)*timediff
minotklon=find(diftimes>0);
minotklon=min(minotklon);
avgotklon=mean(diftimes(minotklon:mintime));
fprintf(1,'Avegage min/max diviation is %d days, max diviation is %d days.\n',avgotklon,max(diftimes));
y_pred1=dlmread(entrfile);
y_pred2=dlmread(outfile_remains2);
y_pred3=dlmread(entrfile2);
figure;
plot([ones(timediff,1)*y_pred1(1);y_pred1]);
%plot(y_pred1);
hold on;
plot(y_pred2,'r');
plot(y_pred3,'k');
legend('real','predicted','learning');
title ('test prediction');
