% Read FLOATS.nc data 
clear all; close all; clc;
start
%====================================================================%
lc=load('coastline_l_mask.mat'); lcx=lc.lon; lcy=lc.lat;
floatsd='floats.nc';  nc=netcdf(floatsd,'nowrite'); 
lon=nc{'lon'}(:); lat=nc{'lat'}(:); vel=nc{'vel'}(:); tem=nc{'temp'}(:);
salt=nc{'salt'}(:);

figure('position',[680 77 812 885],'color','w'); 
m_proj('mercator','long',[2 22],'lat',[-38 -26],'w');


axes('position',[0.2845    0.7130    0.3879    0.2538])
% Velocidades!
magvect=linspace(0,0.7,8);    v_color=jet(length(magvect)-1);
for ndrif=1:size(lon,2)
   drif_v=vel(:,ndrif); lon_v=lon(:,ndrif); lat_v=lat(:,ndrif);
   for int=1:size(magvect,2)-1
       ind=find(drif_v>magvect(int) & drif_v<magvect(int+1)); 
       m_plot(lon_v(ind),lat_v(ind),'.','markeredgecolor',v_color(int,:),'markersize',3.); hold on; %'linewidth',0.51
   end
end
m_coast('patch',[.85 .85 .85],'edgecolor',[0.1 0.1 0.1],'linewidth',0.6);hold on;
m_grid('box','fancy'); 
axes('position',[0.7377    0.7559    0.0123    0.1859]);
for j=1:length(v_color)
    fill([0 1 1 0 0],[magvect(j) magvect(j) magvect(j+1) magvect(j+1) magvect(j)],v_color(j,:),'edgecolor','none');hold on
end
set(gca,'ytick',linspace(0.0,0.7,8),'yticklabel',linspace(0.0,0.7,8),'xticklabel',[],'YAxisLocation','right');
xlabel ('Rapidez m s^{-1}')
axis([0 1 0 0.7]); 



axes('position',[0.2845    0.4056    0.3879    0.2538])
%%% Temperatura!
temp=linspace(15,22,16);    v_color=jet(length(temp)-1);
for ndrif=1:size(lon,2)
   drif_T=tem(:,ndrif); lon_T=lon(:,ndrif); lat_T=lat(:,ndrif);
   for int=1:size(temp,2)-1
       ind=find(drif_T>temp(int) & drif_T<temp(int+1)); 
       m_plot(lon_T(ind),lat_T(ind),'.','markeredgecolor',v_color(int,:),'markersize',3); hold on;
   end
end
m_coast('patch',[.85 .85 .85],'edgecolor',[0.1 0.1 0.1],'linewidth',0.6);hold on;
m_grid('box','fancy'); 

axes('position',[0.7377    0.4486    0.0123    0.1859]);
for j=1:length(v_color)
    fill([0 1 1 0 0],[temp(j) temp(j) temp(j+1) temp(j+1) temp(j)],v_color(j,:),'edgecolor','none');hold on
end
set(gca,'ytick',linspace(15.0,22.0,7),'yticklabel',linspace(15.0,22.0,7),'xticklabel',[],'YAxisLocation','right');
xlabel ('Temperatura °C')
axis([0 1 15.0 22.0]); 


axes('position',[0.2845    0.1006    0.3879    0.2538])
% Salinidad!
sal=linspace(35.0,35.6,11);    v_color=jet(length(sal)-1);
for ndrif=1:size(lon,2)
   drif_S=salt(:,ndrif); lon_S=lon(:,ndrif); lat_S=lat(:,ndrif);
   for int=1:size(sal,2)-1
       ind=find(drif_S>sal(int) & drif_S<sal(int+1)); 
       m_plot(lon_S(ind),lat_S(ind),'.','markeredgecolor',v_color(int,:),'markersize',3); hold on;
   end
end
m_coast('patch',[.85 .85 .85],'edgecolor',[0.1 0.1 0.1],'linewidth',0.6);hold on;
m_grid('box','fancy');

axes('position',[0.7377    0.1469    0.0123    0.1859]);
for j=1:length(v_color)
    fill([0 1 1 0 0],[sal(j) sal(j) sal(j+1) sal(j+1) sal(j)],v_color(j,:),'edgecolor','none');hold on
end
set(gca,'ytick',linspace(35.0,35.6,7),'yticklabel',linspace(35.0,35.6,7),'xticklabel',[],'YAxisLocation','right');
xlabel ('Salinidad')
axis([0 1 35.0 35.6]); 

print('-r300','-djpeg99','floats_tracks.png')
