
% Function plot_transect.m
%
% This file takes L2 transect data and produces the following plots:
%
% 4-part plot:
% [a b]
% [c d]
% a: Transect Lon/Lat on the left. First point in blue, last
% in red. 
% b: Transect's temperature
% c: Transect's salinity
% d: Transect's density
%
% Warning: this function uses m_idist from the m_map toolbox!

function MVP_plot_transect(pathL2,transectname,color_axes)

load([pathL2 filesep transectname '.mat'])

numprofs = length(data);
numbins = length(data(1).pres.value);

MVP_dist = zeros(numprofs,numbins);
MVP_temp = NaN(numprofs,numbins);
MVP_sal  = NaN(numprofs,numbins);
MVP_dens = NaN(numprofs,numbins);
MVP_pres = NaN(numprofs,numbins);

MVP_lon = zeros(1,numprofs);
MVP_lat = zeros(1,numprofs);
% extract all the data...
for iProf = 1:numprofs
    MVP_lon(iProf)  = metadata(iProf).lon.value;
    MVP_lat(iProf)  = metadata(iProf).lat.value;
    MVP_temp(iProf,:) = data(iProf).temp.value;
    MVP_sal(iProf,:)  = data(iProf).psal.value;
    MVP_dens(iProf,:) = data(iProf).dens.value;
    MVP_pres(iProf,:) = data(iProf).pres.value;
end

% Calculate the distance in km...
dist_vec = zeros(1,numprofs);
dist_vec(2:end) = m_idist(MVP_lon(1:end-1),MVP_lat(1:end-1),MVP_lon(2:end),MVP_lat(2:end))./1000;
dist_vec = cumsum(dist_vec);

for idum = 1:numprofs
    MVP_dist(idum,:) = dist_vec(idum);
end

ii = find(~isnan(MVP_temp(:)));

subplot(2,2,1) % Plot the profile positions...
plot(MVP_lon(1),MVP_lat(1),'bx','markersize',10,'linewidth',2); hold on
plot(MVP_lon(2:end-1),MVP_lat(2:end-1),'mx');
plot(MVP_lon(end),MVP_lat(end),'rx','markersize',10,'linewidth',2);
xlabel('Longitude '); ylabel('Latitude ');
title(sprintf('%s Positions',transectname));
set(gca,'dataaspectratio',[1 cos(pi/180*(nanmean(MVP_lat))) 1]);

subplot(2,2,2) % Plot the temperature...
scatter(MVP_dist(ii),MVP_pres(ii),30,MVP_temp(ii),'filled');
xlabel('Distance (km) '); ylabel('Pressure (dBar) '); title(sprintf('Temperature'));
colorbar; axis ij;
caxis([color_axes(1,1) color_axes(1,2)]);

subplot(2,2,3) % Plot the salinity...
scatter(MVP_dist(ii),MVP_pres(ii),30,MVP_sal(ii),'filled');
xlabel('Distance (km) '); ylabel('Pressure (dBar) '); title(sprintf('Practical Salinity'));
colorbar; axis ij;
caxis([color_axes(2,1) color_axes(2,2)]);

subplot(2,2,4) % Plot the density...
scatter(MVP_dist(ii),MVP_pres(ii),30,MVP_dens(ii),'filled');
xlabel('Distance (km) '); ylabel('Pressure (dBar) '); title(sprintf('Density'));
colorbar; axis ij;
caxis([color_axes(3,1) color_axes(3,2)]);
