function makevideo_z(frames, filename)
% Created by Yuandong Tian, Oct. 5, 2009
% Email: yuandong@andrew.cmu.edu
% make video of water heights, using mencoder (please install one if you don't have it)

tmpfile = 'tmp.xxoo.avi';
aviobj = avifile(tmpfile);

frames = frames(1:3:end, 1:3:end, :);

[m, n, nFrame] = size(frames);
maxz = max(frames(:));
minz = min(frames(:));
    
for i = 1:nFrame
    surf(frames(:, :, i), 'FaceColor','interp','EdgeColor','none');
    axis([1, n, 1, m, minz, maxz]);
    camlight left; 
    camorbit(45, 45);
    lighting phong;
    alpha(.8);
    axis off;
    
    frame = getframe(gca);
    aviobj = addframe(aviobj, frame);
end;
aviobj = close(aviobj);
% use mencoder to transfer video format
eval(['! mencoder -o ' filename ' -ovc lavc -lavcopts vcodec=wmv2 ' tmpfile ' >/dev/null']);
eval(['! rm ' tmpfile]);