Home > wafo > wsim > seamovie.m

seamovie

PURPOSE ^

Makes a movie of a 2D (x,t) or 3D (x,y,t) simulated sea

SYNOPSIS ^

Mv=seamovie(Y,s)

DESCRIPTION ^

  SEAMOVIE Makes a movie of a 2D (x,t) or 3D (x,y,t) simulated sea 
   
  CALL:   Mv = seamovie(Y,s)
   
          Mv = movie
          Y = struct with 2d or 3d simulation (from seasim)
          s = type of plot if 3d: if s=1 then surf-plot, if s=2 contour,
              else gray-scale overview with troughs dark and crests light
              (default 1)
  
  The recording is not very fast, each frame must be plotted and then saved
  using getframe. This may take a couple of seconds per frame.
  After the recording the movie is run, the number of frames per second is
  intended to be the true number as given by the time scale in input, but
  the resulting rate may vary depending on computer and network.
   
  NB! Users with older Matlab than 5.3 may need to do some changes to the
  routine, see >> help getframe.  
   
  Example: Y=seasim(demospec('dir'),2^8,1,20,10,[],.5,2);
           Mv=seamovie(Y);
   
  See also  seasim, movie, getframe

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

001 function Mv=seamovie(Y,s)
002 % SEAMOVIE Makes a movie of a 2D (x,t) or 3D (x,y,t) simulated sea 
003 %  
004 % CALL:   Mv = seamovie(Y,s)
005 %  
006 %         Mv = movie
007 %         Y = struct with 2d or 3d simulation (from seasim)
008 %         s = type of plot if 3d: if s=1 then surf-plot, if s=2 contour,
009 %             else gray-scale overview with troughs dark and crests light
010 %             (default 1)
011 % 
012 % The recording is not very fast, each frame must be plotted and then saved
013 % using getframe. This may take a couple of seconds per frame.
014 % After the recording the movie is run, the number of frames per second is
015 % intended to be the true number as given by the time scale in input, but
016 % the resulting rate may vary depending on computer and network.
017 %  
018 % NB! Users with older Matlab than 5.3 may need to do some changes to the
019 % routine, see >> help getframe.  
020 %  
021 % Example: Y=seasim(demospec('dir'),2^8,1,20,10,[],.5,2);
022 %          Mv=seamovie(Y);
023 %  
024 % See also  seasim, movie, getframe
025   
026 % Tested on Matlab 5.3 
027 % revised pab June 2005
028 % -fixed a bug: in matlab7: "Mv =[]; Mv(j) = getframe;" does not work, now
029 % fixed.
030 % revised es 20.06.00 if wrong dimension then message and return, not error
031 % Revised by es 13.06.00 more dimension checks  
032 % By es 23.05.00
033 
034 figure(gcf)  
035 if nargin<2|isempty(s)
036   s=1;
037 end
038 Mv=[];
039 disp('  Plotting frame by frame to record the movie...')
040 if ndims(Y.Z)>2
041   [Ny,Nx,Nt]=size(Y.Z);
042   if s==1
043     for j=1:Nt
044       colormap('winter')
045       surfl(Y.x,Y.y,Y.Z(:,:,j),[-30, 45]);
046       shading interp
047       view(-37.5,20)
048       axis([Y.x(1) Y.x(end) Y.y(1) Y.y(end) 7*min(Y.Z(:)) 7*max(Y.Z(:))])
049       set(gca,'xtick',[])   
050       set(gca,'ytick',[])
051       axis('square')
052       axis('off')
053       if isempty(Mv)
054         Mv = getframe;
055       else
056         Mv(j)=getframe;
057       end
058     end
059   elseif s==2
060     for j=1:Nt
061       contour(Y.x,Y.y,Y.Z(:,:,j),[0 0],'b')
062       axis square
063       xlabel('[m]')
064       ylabel('[m]')
065       if isempty(Mv)
066         Mv = getframe;
067       else
068         Mv(j)=getframe;
069       end
070       
071     end
072   else
073     colormap('gray')
074     miz=min(Y.Z(:));
075     maz=max(Y.Z(:));
076     for j=1:Nt
077       pcolor(Y.Z(:,:,j))
078       caxis([miz maz])
079       xlabel('[m]')
080       ylabel('[m]')
081       shading interp
082       axis square %equal
083       if isempty(Mv)
084         Mv = getframe;
085       else
086         Mv(j)=getframe;
087       end
088       
089     end
090   end    
091 elseif ndims(Y.Z)>1 & isfield(Y,'t')
092   [Nx,Nt]=size(Y.Z);
093   for j=1:Nt
094     plot(Y.x,Y.Z(:,j))
095     hold on
096     plot([Y.x(1) Y.x(end)],[0 0],':')
097     hold off
098     xlabel('[m]')
099     ylabel('[m]')
100     axis([Y.x(1) Y.x(end),min(Y.Z(:))*2,max(Y.Z(:))*2])
101     if isempty(Mv)
102         Mv = getframe;
103       else
104         Mv(j)=getframe;
105     end
106   end
107 else
108   if ~isfield(Y,'t')
109     disp(...
110 'Can not make a movie without time variable, field .t must exist in input')
111     return
112   else
113     disp('Wrong dimension of input. Can not make a movie')  
114     return
115   end
116 end
117 disp('  Running the movie')
118 movie(Mv,0,Y.t(2)-Y.t(1))
119   
120

Mathematical Statistics
Centre for Mathematical Sciences
Lund University with Lund Institute of Technology

Comments or corrections to the WAFO group


Generated on Thu 06-Oct-2005 02:21:16 for WAFO by m2html © 2003