|
| 1 | +% This script animates the height field and the vorticity produced by |
| 2 | +% a shallow water model. It should be called only after shallow_water_model |
| 3 | +% has been run. |
| 4 | + |
| 5 | +% Set the size of the figure |
| 6 | +set(gcf,'units','inches'); |
| 7 | +pos=get(gcf,'position'); |
| 8 | +pos([3 4]) = [10.5 5]; |
| 9 | +set(gcf,'position',pos) |
| 10 | + |
| 11 | +% Set other figure properties and draw now |
| 12 | +set(gcf,'defaultaxesfontsize',12,... |
| 13 | + 'paperpositionmode','auto','color','w'); |
| 14 | +drawnow |
| 15 | + |
| 16 | +% Axis units are thousands of kilometers (x and y are in metres) |
| 17 | +x_1000km = x.*1e-6; |
| 18 | +y_1000km = y.*1e-6; |
| 19 | + |
| 20 | +% Set colormap to have 64 entries |
| 21 | +ncol=64; |
| 22 | +colormap(jet(ncol)); |
| 23 | +% colormap(hclmultseq01); |
| 24 | +% colormap(flipud(cbrewer('div','RdBu',32))) |
| 25 | + |
| 26 | +% Interval between arrows in the velocity vector plot |
| 27 | +interval = 6; |
| 28 | + |
| 29 | +% Set this to "true" to save each frame as a png file |
| 30 | +plot_frames = false; |
| 31 | + |
| 32 | +% Decide whether to show height in metres or km |
| 33 | +if mean(plot_height_range) > 1000 |
| 34 | + height_scale = 0.001; |
| 35 | + height_title = 'Height (km)'; |
| 36 | +else |
| 37 | + height_scale = 1; |
| 38 | + height_title = 'Height (m)'; |
| 39 | +end |
| 40 | + |
| 41 | +disp(['Maximum orography height = ' num2str(max(H(:))) ' m']); |
| 42 | + |
| 43 | +% Loop through the frames of the animation |
| 44 | +for it = 1:noutput |
| 45 | + clf |
| 46 | + |
| 47 | + % Extract the height and velocity components for this frame |
| 48 | + h = squeeze(h_save(:,:,it)); |
| 49 | + u = squeeze(u_save(:,:,it)); |
| 50 | + v = squeeze(v_save(:,:,it)); |
| 51 | + |
| 52 | + % First plot the height field |
| 53 | + subplot(2,1,1); |
| 54 | + |
| 55 | + % Plot the height field |
| 56 | + handle = image(x_1000km, y_1000km, (h'+H').*height_scale); |
| 57 | + set(handle,'CDataMapping','scaled'); |
| 58 | + set(gca,'ydir','normal'); |
| 59 | + caxis(plot_height_range.*height_scale); |
| 60 | + |
| 61 | + % Plot the orography as black contours every 1000 m |
| 62 | + hold on |
| 63 | + warning off |
| 64 | + contour(x_1000km, y_1000km, H',[1:1000:8001],'k'); |
| 65 | + warning on |
| 66 | + |
| 67 | + % Plot the velocity vectors |
| 68 | + quiver(x_1000km(3:interval:end), y_1000km(3:interval:end), ... |
| 69 | + u(3:interval:end, 3:interval:end)',... |
| 70 | + v(3:interval:end, 3:interval:end)','k','linewidth',0.2); |
| 71 | + |
| 72 | + % Write the axis labels, title and time of the frame |
| 73 | + xlabel('X distance (1000s of km)'); |
| 74 | + ylabel('Y distance (1000s of km)'); |
| 75 | + title(['\bf' height_title]); |
| 76 | + text(0, max(y_1000km), ['Time = ' num2str(t_save(it)./3600) ' hours'],... |
| 77 | + 'verticalalignment','bottom','fontsize',12); |
| 78 | + |
| 79 | + % Set other axes properties and plot a colorbar |
| 80 | + daspect([1 1 1]); |
| 81 | + axis([0 max(x_1000km) 0 max(y_1000km)]); |
| 82 | + colorbar |
| 83 | + |
| 84 | + % Compute the vorticity |
| 85 | + vorticity = zeros(size(u)); |
| 86 | + vorticity(2:end-1,2:end-1) = (1/dy).*(u(2:end-1,1:end-2)-u(2:end-1,3:end)) ... |
| 87 | + + (1/dx).*(v(3:end,2:end-1)-v(1:end-2,2:end-1)); |
| 88 | + |
| 89 | + % Now plot the vorticity |
| 90 | + subplot(2,1,2); |
| 91 | + handle = image(x_1000km, y_1000km, vorticity'); |
| 92 | + set(handle,'CDataMapping','scaled'); |
| 93 | + set(gca,'ydir','normal'); |
| 94 | + caxis([-3 3].*1e-4); |
| 95 | + |
| 96 | + % Axis labels and title |
| 97 | + xlabel('X distance (1000s of km)'); |
| 98 | + ylabel('Y distance (1000s of km)'); |
| 99 | + title('\bfRelative vorticity (s^{-1})'); |
| 100 | + |
| 101 | + % Other axes properties and plot a colorbar |
| 102 | + daspect([1 1 1]); |
| 103 | + axis([0 max(x_1000km) 0 max(y_1000km)]); |
| 104 | + colorbar |
| 105 | + |
| 106 | + % Now render this frame |
| 107 | + warning off |
| 108 | + drawnow |
| 109 | + warning on |
| 110 | + |
| 111 | + % To make an animation we can save the frames as a |
| 112 | + % sequence of images |
| 113 | + if plot_frames |
| 114 | + eval(['print -dpng frame',num2str(it,'%03d'),'.png']); |
| 115 | +% imwrite(frame2im(getframe(gcf)),... |
| 116 | +% ['frame' num2str(it,'%03d') '.png']); |
| 117 | + end |
| 118 | + pause(0.05); |
| 119 | +end |
0 commit comments