function ondesurfdemo
clear all
close all
% flag=1 impulsion  2 paquet 
while 1 
	flag=input('1: impulsion (defaut),  2: paquet , 9:quit ? ');
	if isempty(flag)
		flag=1
	end
	if flag==9
		return
	end
	L=2*pi;
	ko=2*pi/L;
	N=2^10
	dx=L/N;
	XA=0:dx:N/2*dx;
	XB=-N/2*dx:dx:-dx;
	KA=0:ko:(N/2-1)*ko;
	KB=-(N/2-1)*ko:ko:-ko;
	K=[KA 0 KB];
	% Choix impulsion ou paquet
	% dissipation (lam=0.000001, lam=0.0000005)
	if flag==1
		FZERO=[0*KA+1 0 0*KB];
		lam=0.0000005
	end
	if flag==2
		k0=50*ko; 
		k0=100*ko; 
		dk0=50*ko^2;
		FZERO=15*exp(-(K-k0).^2/dk0);
		lam=0.00000;
	end
	% relation de dispersion water waves
	OMA=disper_water(KA);
	OMB=disper_water(KB);
	KD=[KB KA];
	OMEGA=[OMA 0 OMB];
	OMEG=[OMB OMA];
	% Parametre de la simulation temporelle
	M=80; dt=1;
%	M=20; dt=4;
	% umax pour plots
	um=0.2;
	%boucle sur le temps
	Mmax=M*dt;
	Mmaxh=Mmax/2;
	nla=0;
	nlamax=21;
	for t=0:dt:Mmax
		% t
		U=FZERO.*exp(-i*OMEGA*t).*exp(-lam*K.^2*t);
		U(N/2+1)=0;
		V=ifft(U,N);
		RV=real(V);
		YA=RV(1:N/2+1);
		YB=RV(N/2+1:N);
		X=[XB XA];
		Y=[YB YA];
		plot(X,Y)
		axis([-L/10 L/2 -um um])
		if t==0 
			xlabel('\it{x}','FontSize',30)
			ylabel('\eta','FontSize',30)
			pause
		end
		if t==Mmaxh
			xlabel('\it{x}','FontSize',30)
			ylabel('\eta','FontSize',30)
			%title(chain,'FontSize',20)
			pause
		else
			pause(0)
		end
		%xlabel('\it{x}','FontSize',30)
		%ylabel('\eta','FontSize',30)
		%title(chain,'FontSize',20)
		if nla==0 
			%disp(' You can change the window size now !')
			pause
			Mla=moviein(nlamax);
		end
		nla=nla+1;
		%Mla(:,nla)=getframe; 
		%filew(gcf,nla);
	end
	xlabel('\it{x}','FontSize',30)
	ylabel('\eta','FontSize',30)
	pause
	close all
end
%
% <<  Fonctions >>
%
function om=disper(K)
om=disper_water(K);
%om=disper_kdv(K);
function om=disper_kdv(K)
alpha=0.05;
beta=0.0000001;
om=alpha*K-beta*K.^3;
function om=disper_water(K)
alpha=0.1;
beta=0.01;
om=sqrt(alpha*abs(K).*tanh(abs(K)*beta));
% dt=1 alpha=1 beta=0.1 M=100
% inutiles
function om=dispera(K)
om=disper(K);
function om=disperb(K)
om=-disper(K);
% 
% << filew >>
%
% writing image on  files 
function filew(gcf,n)
[a,map]=capture(gcf);
filename=sprintf('image%2.2d.jpg',n)
imwrite(a,map,filename,'jpg')

