function [pippo]= MVP_dynheight_function_MM(pathL2,transectname)

%%%%%%09/04/2016 AndreaD : modified for compatibility wit MVP tools and LATEXtools
%from original script by Alice Pietri
% needs ixingOceanographicToolbox_EM-APEX

%clear;close all;
LATEXtools_param
LATEXtools_cruise
MVP_cruise_params;

%transectname=[Transect_Names{transchoice}];%'Transect_03_qc_2'; 

[MVP_lon,MVP_lat,MVP_dist,MVP_pres,MVP_temp,MVP_sal,MVP_dens]=load_MVPtransect(pathL2,transectname);


dist=MVP_dist(:,1);%AD[0 cumsum(whdist(MVP_lat,MVP_lon))]./1000;
g=9.81;

%badprofile=[5 23 24];

%Marco Comment 02_06
badprofile=[];


% ADDED MARCO selezione della pressione massima da considerare per il cast
ii = find(MVP_pres(1,:)<260);

svan=sw_svan(MVP_sal(:,ii),MVP_temp(:,ii),MVP_pres(:,ii)); %%% Specific Volume Anomaly  [m^3 kg^-1]

% steric height (m)
for i=1:size(svan,1) %%%AD cycle on profiles
    h(i)=(1/g)*nansum(1e4*svan(i,1:end).*presDelta);
end
h(badprofile)=NaN;

%geo current (m/s)
coriolis=1.04e-4 %2omegasinphi %s^-1
v=nan(size(dist,1),1);
for i=3:size(dist,1)-1;
    dx=(dist(i-1)-dist(i+1))*1000; %[m]
    dh=(h(i-1)-h(i+1));
    v(i)=g/coriolis*dh/dx;
end

figure

subplot(3,1,1)

plot(MVP_dist(:,1),h)
axis([-0.5 round(max(MVP_dist(:,1)))+0.5 min(h)-0.05 max(h)+0.05])
grid on
title([transectname],'interpreter','none');
ylabel('steric height [m]')
%(,'geostrophic current [m/s]')
xlabel('distance [km]')



subplot(3,1,2)

plot(MVP_dist(:,1),v)
%axis([-0.5 round(max(MVP_dist(:,1)))+0.5 min(h)-0.05 max(h)+0.05])
grid on
title([transectname],'interpreter','none');
ylabel('geostrophic current [m/s]')
%(,'geostrophic current [m/s]')
xlabel('distance [km]')




subplot(3,1,3);hold on

contourf(MVP_dist,MVP_pres,MVP_dens);
plot(MVP_dist,MVP_pres,'m.');
axis([-0.5 round(max(MVP_dist(:,1)))+0.5 presMin presMax])
axis ij
title([transectname,'   density'],'interpreter','none');
ylabel('pressure [dBar]')
xlabel('distance [km]')


