source='AT_150_ALL_01032015_1300_osite_sta_00120x1.nc';
%source='AT_38_ALL_01032015_1300_cor_assiette_M02_sta_00120x1.nc';
ncdisp(source)

%        N_DATE_TIME  = 578
%            N_LEVEL      = 85
%            CONST1       = 1
%            DATE_TIME    = 14
%            nbre_station = 4
%            REFERENCE_DATE_TIME
%            StaLat  
%             StaLon   
%             DEPH  
%              VVEL_ADCP  UVEL_ADCP  WVEL_ADCP   
%                ECI  (écho)
time_sadcp = ncread(source,'JULD');
%t0=ncread(source,'REFERENCE_DATE_TIME');
t0=datenum(1950,1,1,0,0,0);
vx=ncread(source,'UVEL_ADCP');
vy=ncread(source,'VVEL_ADCP');
echoo=ncread(source,'ECI');
latt=ncread(source,'StaLat');
lonn=ncread(source,'StaLon');
z=ncread(source,'DEPH');
no_stations=ncread(source,'NUMERO');
i_deb_st=ncread(source,'INDICE');

whos

time=t0+time_sadcp;

figure;
subplot(2,1,1);plot(time,latt,'-*');
subplot(2,1,2);plot(time,lonn,'-*');

%vue gale
figure;
subplot(2,1,1)
pcolor(time,z,vx)
shading interp
caxis([-0.2,0.2])
colorbar
datetick('x')
subplot(2,1,2)
pcolor(time,z,vy)
shading interp
caxis([-0.2,0.2])
colorbar
datetick('x')

%trace par station

for i_st=1:length(no_stations)
    
figure;
subplot(2,1,1)
i_deb=i_deb_st(i_st);
if i_st==length(no_stations)
    i_fin=size(vx,2);
else
i_fin=i_deb_st(i_st+1)-1
end
pcolor(time(i_deb:i_fin),z,vx(:,i_deb:i_fin))
shading interp
caxis([-0.2,0.2])
colorbar
vline(date_vmp,'k--')
datetick('x')
title(['v_x- ' datestr(time(i_deb)) ' - ' datestr(time(i_fin)) ])
xlabel('time');ylabel('depth')
subplot(2,1,2)
pcolor(time(i_deb:i_fin),z,vy(:,i_deb:i_fin))
shading interp
caxis([-0.2,0.2])
colorbar
vline(date_vmp,'k--')
datetick('x')
title(['v_y- ' datestr(time(i_deb)) ' - ' datestr(time(i_fin)) ])
xlabel('time');ylabel('depth')
end

figure;
subplot(2,1,1)
i_deb=i_deb_st(i_st);
if i_st==length(no_stations)
    i_fin=size(vx,2);
else
i_fin=i_deb_st(i_st+1)-1
end
mod_v=vx-vx;phase_v=mod_v;
mod_v(:,i_deb:i_fin)=(vx(:,i_deb:i_fin).^2+vy(:,i_deb:i_fin).^2).^0.5;
phase_v(:,i_deb:i_fin)=angle(complex(vx(:,i_deb:i_fin),vy(:,i_deb:i_fin)));
pcolor(time(i_deb:i_fin),z,mod_v(:,i_deb:i_fin))
shading interp
caxis([0.,0.4])
colorbar
vline(date_vmp,'k--')
datetick('x')
title(['v_x- ' datestr(time(i_deb)) ' - ' datestr(time(i_fin)) ])
xlabel('time');ylabel('depth')
subplot(2,1,2)
pcolor(time(i_deb:i_fin),z,phase_v(:,i_deb:i_fin))
shading interp
caxis([-pi,pi])
colorbar
vline(date_vmp,'k--')
datetick('x')
title(['v_y- ' datestr(time(i_deb)) ' - ' datestr(time(i_fin)) ])
xlabel('time');ylabel('depth')
