%% example of geostrophy in the presence of stratification and sea
%% level changes.
%% Eli, EPS 131, 2012
function geostrophy_stratified_example

p=set_parameters;
T_plot=zeros(p.nx,p.nz);
v_plot=zeros(p.nx,p.nz);
k=0;
for z=p.z_range
  k=k+1;
  i=0;
  for x=p.x_range
    i=i+1;
    T_plot(i,k)=Temperature(x,z,p);
    v_plot(i,k)=Velocity(x,z,p);
  end
end

figure(1); clf
set(0,'defaulttextfontsize',14); set(0,'defaultaxesfontsize',14);

[c,hc]=contourf(p.x_range/1000,p.z_range,T_plot'); 
colorbar;
set(hc,'EdgeColor','none');
vc=caxis;
hold on
v_levels_max=round(max(v_plot(:))*10)/10;
v_levels_min=round(min(v_plot(:))*10)/10;
dv=(v_levels_max-v_levels_min)/10;
v_levels=[v_levels_min:dv:v_levels_max];
[c1,hc1]=contour(p.x_range/1000,p.z_range,v_plot',v_levels,'k');
caxis(vc);
clabel(c1,hc1);
xlabel('x (km)')
ylabel('z (m)')
title('T (shading), v (contours)')

%% save as pdf:
set(gcf, 'PaperUnits', 'inches'); set(gcf, 'PaperSize', [5 4]);
set(gcf, 'PaperPosition', [0 0 5 4]); % [left, bottom, width, height];
saveas(gcf,sprintf('Output/stratified-geostrophy-example.pdf'));



function p=set_parameters
p.L=50e3;
p.H=1000;
p.a=1;
p.g=10;
p.f=1.e-4;
p.alpha=1668e-7;
p.Delta_T=10;
p.delta=0.5;
p.T_0=3;
p.dx=p.L/50;
p.dz=p.H/50;
p.x_range=0:p.dx:p.L;
p.z_range=-p.H*3:p.dz:0;
p.nx=length(p.x_range);
p.nz=length(p.z_range);

fprintf(1,'level of no motion is: %g \n', -p.a/(p.alpha*p.Delta_T*p.delta))


function T=Temperature(x,z,p)
T=p.T_0+p.Delta_T*(exp(z/p.H)+p.delta*x/p.L);


function v=Velocity(x,z,p)
v=p.a*p.g/(p.L*p.f) ...
  +(p.g*p.alpha*p.Delta_T*p.delta)*z/(p.L*p.f);

