function ecluse
% Animation vidange ou remplissage d'un canal
% O. Thual, 26/08/03
clear all
close all
disp('Vidange ou remplissage d''canal')
ndemdef=1;
while 1
	ndem=input(' 1: demo (defaut) , 2: manuel, 9: quit ?' )
	ndem
	if isempty(ndem) 
		ndem=ndemdef;
	end
	if ndem==1 
		demo1
	end
	if ndem == 2
		disp('tptp')
		manuel
	end
	if ndem ==9
		disp('Good Bye!')
		return
	end
end
%
% << demo1 >> 
%
function demo1
global dt xmax
% paametre 
dt=.2; xmax=5;
% Parameters to ajust
nlamax=10;
% detente 
hf=.7; gam=1-sqrt(hf);
close all
[mla,nla]=animation(gam,nlamax);
nla
%	movie(mla,5,4)
% choc
nlamax=10;
hf=1.4; gam=1-sqrt(hf);
close all
[mla,nla]=animation(gam,nlamax);
nla
% movie(mla,5,4)
return
% << manuel >> 
%
function manuel
global dt xmax
% paametre 
dt=.2; xmax=5;
% Parameters to ajust
hfdef=4/9;
nlamax=10;
hf=[];
while 1
	leginput=sprintf('ce=c0-gam*t  hf ? defaut :%0.3g, quit :9  ',hfdef);
	hf=input(leginput)
	if isempty(hf)
		hf=hfdef;
	end
	if hf==9
		disp('Good Bye!')
		return
	end
	gam=1-sqrt(hf);
	close all
	[mla,nla]=animation(gam,nlamax);
	nla
	%	movie(mla,5,4)
	hf=9;
end
%
% FUNCTIONS
% << animation >>
function [mla,nla]=animation(gam,nlamax)
global dt
% 
tau=init;
% Caracteristiques
carac(gam)
pause
figure
% Time loop
hold off
nmax=20;
nla=0;
for n=1:nmax
	t=(n-1)*dt;
	ligneau(tau,t,gam);
	% legend
	leg=sprintf('niveau d''eau, ce=c0-(%0.3g)*t',gam);
	title(leg,'FontSize',20,'Color','m')
	ylabel('h','FontSize',20)
	xlabel('x','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,n);
end
% 
% << 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')
% 
% << init >>
%
% initialisation de x 
function tau=init
tauxmax=1; ntau=51; dtau=tauxmax/(ntau-1);
tau=0:dtau:tauxmax;
% 
% << lingneau >>
%
% ligne eau 
function ligneau(tau,t,gam)
global xmax
c0=1;
ce=c0-gam*tau;
lam=-2*c0+3*ce;
x=lam.*(t-tau);
f=ce.^2;
plot(x, f,'LineWidth',2)
s=size(x); nx=s(2);
x1=x(1); xn=x(nx);
he1=ce(1)^2; hen=ce(nx)^2;
hold on
plot([0 xn],[hen hen],'LineWidth',2)
plot([x1 xmax],[he1 he1],'LineWidth',2)
axis([0 xmax 0 2])
hold off
% 
% << carac >>
%
% caract
function carac(gam)
T=10;
c0=1;
xmax=2;
for tau=0:.1:1
	ce=1-gam*tau;
	lam=-2*c0+3*ce;
	X=lam.*(T-tau);
	axis([0 xmax*2 0 xmax*2])
	hold on
	plot([0 X], [tau T])
	leg=sprintf('caracteristiques, ce=c0-(%0.3g)*t',gam);
	title(leg,'FontSize',20,'Color','m')
	ylabel('t','FontSize',20)
	xlabel('x','FontSize',20)
end

















