function Ri_mavs_ctd
% Ri_mavs_ctd  compute gradient Richardson number from MAVS & CTD data
% =========================================================================
% Ri_mavs_ctd  Version 1.0 29-Jul-2005
%
% Usage: 
%   Ri_mavs_ctd
%
% Description:
%   This function loads a MAVS shear data file computed from the raw data 
%   logged on the SeaHorse profiler as well as the CTD data and computed
%   buoyancy frequency.  These properties are combined to estimate the
%   gradient Richardson number (Ri = N^2/S^2)
%
% Input:
%   n/a
%
% Output:
%   n/a
%
% Called by:
%   n/a
%
% Calls:
%   n/a
%
% Author:
%   Blair Greenan
%   Bedford Institute of Oceanography
%   Matlab 7
%   greenanb@mar.dfo-mpo.gc.ca
% =========================================================================
%

% History
% Version 1.0 29-Jul-2005


% load the CTD data
load sh_ctd_bf.mat

% load the MAVS shear estimates
load shear2m.mat

% find the pressure bins that match for each data set
for ii = 1:length(shear_bin_depth)
    findp(ii) = find(Pres(:,1) == shear_bin_depth(ii));
end

new_N = Nsqrd(findp,:);
shear_sqrd = shear2m.^2;
%xxx = new_N./(2*pi);
Ri1 = new_N./shear_sqrd;
%Ri2 = xxx./shear_sqrd;

figure
pcolor(dt,shear_bin_depth,Ri1); shading flat; set(gca,'ydir','rev')
set(gca,'Clim',[0 1])
title('Gradient Richardson Number')
colorbar

%{
figure
pcolor(dt,shear_bin_depth,Ri2); shading flat; set(gca,'ydir','rev')
set(gca,'Clim',[0 50])
title('Gradient Richardson Number')
colorbar
%}

figure
pcolor(dt,shear_bin_depth,new_N); shading flat; set(gca,'ydir','rev')
%set(gca,'Clim',[0 1])
title('Buoyancy Frequency Squared (rad^2/s^2)')
colorbar


figure
pcolor(dt,shear_bin_depth,shear_sqrd); shading flat; set(gca,'ydir','rev')
set(gca,'Clim',[0 0.03])
title('Shear Squared (s^{-2})')
colorbar

median_shear_sqrd = nanmedian(shear_sqrd');
median_new_N = nanmedian(new_N');
median_Ri = median_new_N./median_shear_sqrd;

figure
plot(median_new_N,shear_bin_depth,'.-')
xlabel('Buoyancy Frequency Squared (rad^2/s^2)')
ylabel('Depth (m)')
set(gca,'ydir','rev')

figure
plot(median_shear_sqrd,shear_bin_depth,'.-')
set(gca,'ydir','rev')
xlabel('Shear Squared (s^{-2})')
ylabel('Depth (m)')

figure
plot(median_Ri,shear_bin_depth,'.-')
set(gca,'ydir','rev')
xlabel('Gradient Richardson Number')
ylabel('Depth (m)')


%keyboard




