
global MyMovie 

H=allu+sin(alltheta)*l;

M=max(max(H))+1e-10;
m=min(min(H))-1e-10;
Lx1=min(min(allx));
Lx2=max(max(allx));
Ly1=-l;
Ly2= l;
ax=([Lx1 Lx2 Ly1 Ly2 m M]);
pos=[L*0.8,l*0.8,M];

plottop=0;
savejpgs=0;
savempeg=0;
playmovie=0;
savemovie=0;
saveavi=0;


fs=16;
ft=16;
fl=18;
iti=1;
itf=length(allt);
%itf=11
dit=1;
dt=1e-10;
cropwindow=[10 10 520 390]; % tight
cropwindow=[15 0 520 420]; % not that tight

Mt=0;
mt=100;
Mn=0;
mn=100;
frame=0;
alltxt=[];
allname=[];

if(savemovie|savempeg|playmovie)
 savemovie=1;
 MyMovie = moviein(1+floor(itf-iti)/dit);
end

if(saveavi)
 avi = avifile('draft.avi','FPS',4);
end

for it=iti:dit:itf
 t=allt(it);
 txt=[ num2str(allt(it)) ];
 name=[ num2str(it-1) ];
 if(length(txt)>Mt) Mt=length(txt);end
 if(length(txt)<mt) mt=length(txt);end
 if(length(name)>Mn) Mn=length(name);end
 if(length(name)<mn) mn=length(name);end
end

for it=iti:dit:itf
 t=allt(it);
 txt=[ num2str(allt(it)) ];
 name=[ num2str(it-1) ];
 if(length(txt)==Mt-1) txt=[txt,'.'];end
 if(length(txt)==Mt-2) txt=[txt,'.0'];end
 if(length(txt)==Mt-3) txt=[txt,'.00'];end
 if(length(txt)==Mt-4) txt=[txt,'.000'];end
 alltxt=[alltxt;['t = ',txt,' (/' num2str(allt(itf)) ')']];
 if(length(name)==Mn-1) name=['0',name];end
 if(length(name)==Mn-2) name=['00',name];end
 if(length(name)==Mn-3) name=['000',name];end
 if(length(name)==Mn-4) name=['0000',name];end
 if(length(name)==Mn-1) name=['0',name];end
 if(length(name)<3) name=['0',name];end
 if(length(name)<3) name=['0',name];end
 if(length(name)<3) name=['0',name];end
 allname=[allname;['frames/frame.',name,'.jpg']];
end

%alltxt
%allname

%M=M/2
for it=iti:dit:itf
 t=allt(it);
 u=allu(it,:);
 v=allv(it,:);
 theta=alltheta(it,:);
 omega=allomega(it,:);
 bridgeplot(allx,u,v,theta,omega,N,0); 
 mytext=['T=(' num2str(t) ')/(' num2str(tf) ')'];
 axis(ax)
 text(pos(1),pos(2),pos(3),mytext)

 if(savejpgs)
  status=mkdir('frames');
  name=allname(it,:);
  fprintf('%s\n',name);
  print('-djpeg80','-r100',name)
 end
 if(savemovie)
  frame=frame+1;
  MyMovie(:,frame) = getframe(gcf,cropwindow);
 end
 if(saveavi)
  F=getframe(gcf,cropwindow);
  avi = addframe(avi,F);
 end
 pause(0.001)
end

if(playmovie)
 movie(MyMovie,1,2);
end

if(savempeg)
 mpgwrite(MyMovie,'default','draft.mpeg')
end

if(saveavi)
 avi = close(avi);
end


