%% ----------------------------------------
%% EPS131: Intro to Physical Oceanography
%% HW-10: ex. 3
%% Phase velocity in 2D
%% Laure Zanna
%% ----------------------------------------
clear all; close all;

% specify wave numbers:
l=0.1; k=5*l; 
% initial time and gravity:
t_0=1; g=9.81; 
% omega from the dispersion relation for deep gravity waves:
K=(k^2+l^2)^0.5;
omega=(g*K)^0.5; 
% time increment; waves are ploted at t_0 and t_0+dt:
dt=0.02*2*pi/omega;

% setup the grid 
[x,y]=meshgrid(1:0.01:2,0:0.01:6);

% calculate sea surface elevation at t_0:
eta=cos(k*x+l*y-omega*t_0);
% contour in red only one elevation of the wave:
[C,h] =contour(x,y,eta,[1 0.1],'r'); clabel(C,h)

% calculate and contour in blue sea surface elevation at later
% time:
clear eta
eta=cos(k*x+l*y-omega*(t_0+dt));
hold on; 
[C,h] =contour(x,y,eta,[1 0.1],'b'); clabel(C,h)

h1=legend('t_0','t_0+dt');
h2=title('propagation of a cos(kx+ly-\omega t) deep gravity wave');
h3=xlabel('x');
h4=ylabel('y');
h5=gca;
set([h1,h2,h3,h4,h5] ...
    ,'FontName','Helvetica','FontWeight','bold','FontSize',12);

if 0
  %% save as pdf:
  set(gcf, 'PaperUnits', 'inches'); set(gcf, 'PaperSize', [4 4]);
  set(gcf, 'PaperPosition', [0 0 4 4]); % [left, bottom, width, height];
  saveas(gcf,sprintf('phase_velocity_2d.pdf'));
end
