clear;close all

map_MVP_satellite
Read_CTD;

LATEXtools_param
LATEXtools_cruise
MVP_cruise_params;

g=9.81;

transect_over_altika = [3 11 7];

badprofile=[30:32];
badprofile=[];
%badprofile=[5 23 24];

arbitrary=0.3
arbitrary=0.2

for itrans=2%1:length(transect_over_altika)


transchoice=transect_over_altika(itrans);
transectname=[Transect_Names{transchoice}];

[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;

%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]

svan_CTD=sw_svan(CTD_sal,CTD_temp,CTD_pres);

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


h_CTD=(1/g)*nansum(1e4*svan_CTD.*presDelta);

%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=(hh(i-1)-hh(i+1));
    v(i)=g/coriolis*dh/dx;
end

figure(2)

subplot(3,1,1)

plot(MVP_dist(:,1),hh)
axis([-0.5 round(max(MVP_dist(:,1)))+0.5 min(hh)-0.05 max(hh)+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]')


% Sat pass 429

if transchoice==3
    Lat_Altika=ncread('./OSCAHR/SaralAltika/Residus_1Hz_AL_C28_T429_DT2014_sansEO.nc','Latitudes');
    Lon_Altika=ncread('./OSCAHR/SaralAltika/Residus_1Hz_AL_C28_T429_DT2014_sansEO.nc','Longitudes');
    SLA_Altika=ncread('./OSCAHR/SaralAltika/Residus_1Hz_AL_C28_T429_DT2014_sansEO.nc','SLA');


   figure(1); hold on;
m_plot(Lon_Altika,Lat_Altika,'r*');


    ii=find(Lat_Altika>43 & Lat_Altika <43.45 & Lon_Altika>6.5 & Lon_Altika<7.5);

   figure(1)
   hold on; m_plot(Lon_Altika(ii),Lat_Altika(ii),'b*');


    figure(3); hold on;
    plot(Lat_Altika(ii),SLA_Altika(ii),'-o')
    plot(MVP_lat, hh+arbitrary, '-*g')
    legend('H\_Altika-LR',['H\_MVP +',num2str(arbitrary)])
ylabel('Steric Height [m]')
xlabel('Latitude')
    
end

% Sat pass 674
if transchoice==11 || transchoice==7
    
    Lat_Altika=ncread('./OSCAHR/SaralAltika/Residus_1Hz_AL_C28_T674_DT2014_sansEO.nc','Latitudes');
    Lon_Altika=ncread('./OSCAHR/SaralAltika/Residus_1Hz_AL_C28_T674_DT2014_sansEO.nc','Longitudes');
    SLA_Altika=ncread('./OSCAHR/SaralAltika/Residus_1Hz_AL_C28_T674_DT2014_sansEO.nc','SLA');



figure(1)
    hold on;m_plot(Lon_Altika,Lat_Altika,'r*');


    ii=find(Lat_Altika>43.5 & Lat_Altika <44.03 & Lon_Altika>8 & Lon_Altika<9);

 m_plot(Lon_Altika(ii),Lat_Altika(ii),'b*');


    figure(3); hold on;
    plot(Lat_Altika(ii),SLA_Altika(ii),'-o')
    plot(MVP_lat, hh+arbitrary, '-*g')
    legend('H\_Altika-LR',['H\_MVP +',num2str(arbitrary)])
ylabel('Steric Height [m]')
xlabel('Latitude')

end

print(1,'tmp1','-dpng','-r200')
print(2,'tmp2','-dpng','-r200')
print(3,'tmp3','-dpng','-r200')


clear MVP_lon MVP_lat MVP_dist MVP_pres MVP_temp MVP_sal MVP_dens  hh
end
