
%
% Plots ADCP data from pre-processed files, including flag removal and
% averaging (5 km), during transects (sec)
%


clear all; clc;

%% Parameters
path38K  = 'Z:\OUTPACE\OUTPACE_SADCP\38K\cible_3\nce';
path150K = 'Z:\OUTPACE\OUTPACE_SADCP\150K\cible_3\nce';

% lonlat_lim = [145 215 -30 -10]; % All region
% % lonlat_lim = [140 220 -30 -10];
% lonlat_lim = [158 172 -25 -15]; % Station A
% lonlat_lim = [159 168 -23.5 -17]; % Station A, zoom1
lonlat_lim = [162 166 -20 -17.5]; % Station A, zoom2
% lonlat_lim = [171 185 -25 -15]; % Station B -> not working because of unique values...
% lonlat_lim = [196 201 -25 -15]; % Station C

use38K150K = 2;   % 1: 38K, 2: 150K

iDepth     = 1; % depth bin to be plotted
nSubSample = 1; % plot one each nSubSample velocities


%% Read data
if use38K150K == 1
    path = path38K;
else
    path = path150K;
end

[fileName, path] = uigetfile([path filesep '*sec*.nc'],'Choose the NetCDF file to be read');

% Date
timeRef = ncread([path filesep fileName],'REFERENCE_DATE_TIME')';
time    = ncread([path filesep fileName],'JULD');
time    = time + datenum(timeRef,'yyyymmddHHMMSS');

% Longitude/latitude
lon = ncread([path filesep fileName],'SecLon');
lat = ncread([path filesep fileName],'SecLat');

val = lon ;

% Current velocity
depth = ncread([path filesep fileName],'DEPH');     % [m]
u = ncread([path filesep fileName],'UVEL_ADCP');    % [m/s]
v = ncread([path filesep fileName],'VVEL_ADCP');
w = ncread([path filesep fileName],'WVEL_ADCP');

% Module et Direction
Dir=uv2dir(u,v);
Mod=speed(u,v);

% Echo intensity
rss = ncread([path filesep fileName],'ECI');


%% Plot
hFig = figure('Units','normalized','Outerposition',[0 0 1 1]); hold on; grid on;
trace_coast_bathy(lonlat_lim,'k','centralpacific',0);
plot(lon,lat,'-k','LineWidth',0.5);
hQuiv = quiverLegend(lon(1:nSubSample:end),lat(1:nSubSample:end), ...
    u(iDepth,(1:nSubSample:end))',v(iDepth,(1:nSubSample:end))',lonlat_lim, ...
    1,0.15,'cm/s','NE','b');
title([num2str(abs(round(depth(iDepth))),'%u') ' m']);

%% Plot
