clear
close all
addpath /data/mgoes/matlab/Seawater
addpath /data/mgoes/matlab/mystuff

%eval('! ls -1 Data/transport/XBT_newsal_goes_noyear_noint/ > files.txt');

lista = importdata('files.txt');


direc = {'Data/transport/XBT_newsal_goes_noyear_noint/'}; 

x_int = -60:.5:20;
ni = length(x_int);
nf = length(lista);
nz = 3000; %length(zmid);

dist = zeros(ni,nf);
v1 = zeros(ni,nz,nf);

for ii=1:nf
    filename = [direc{1},lista{ii}];
    load(filename)
    lon(1:length(lonv),ii) = lonv;
    lat(1:length(lonv),ii) = latv;
    
   [~,oi] = unique(lonv);
   x_int = linspace(lonv(1),lonv(end),161);
   v = interp1(lonv(oi),vel(oi,:),x_int);%F(x,y);
      dist1 = (sw_dist(x_int*0-34.5,x_int,'km'));
      dist(:,ii) = cumsum([0 dist1]'.*double(~isnan(v(:,1))));
    v1(:,:,ii) = v;
end
acha = find(lat==0);
lat(acha) = nan;
lon(acha)  = nan;

%FIND 34.5 locations
acha = find(nanmedian(lat)+35<.5);

load mapa %newdefault.spk
%mapa = interp1(newdefault(:,1),newdefault(:,2:4),0:10:100);
%mapa = interp1(mapa(:,1),mapa(:,2:4),0:10:100);
%mapa=mapa/100;
%%

figure(1),clf
set(gcf,'PaperPosition',[1 1 5 4]); 
set(gcf,'DefaultLineLineWidth',1.5)
wysiwyg;
%contourf(x_int,zmid,nanmean(v1,3)',[-.8:.05:.8],'edgecolor','none')
contourf(x_int,zmid,nanmean(v1(:,:,acha),3)',[-.8:.05:.8],'edgecolor','none')
hold on
contour(x_int,zmid,nanmean(v1(:,:,acha),3)',[0 0],'k')

%shading flat
%caxis([0 .14])
caxis([-0.4 .4])
ylim([0 1000]);xlim([-53 -40])
set(gca,'ydir','reverse','fontsize',12)
col=colorbar;%set(col,'ticks',0:.005:.05,'ticklabels',0:.01:.05)
mycolorbar(col,mapa)
text(-50,750,'d)','backgroundcolor','w','fontsize',18,'fontweight','bold')

