%AD 12/5/2016
%chose time interval added
%changed variable date in .mat file with mytime
%in new .mat files deph doesnot exist
%change sahpe of u and v matric betweeen seaquest and oscahr...

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%                    LATEXtools                         %%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%  This  file  is  free software ;  it  is distributed  in  %
%%  the hope that  it  will  be  useful,  but  without  any  %
%%  warranty.  You  can  redistribute  it and/or modify  it  %
%%  under  the  terms  of  the  GNU  General Public License  %
%%  as  published  by  the   Free  Software  Foundation  at  %
%%       http://www.gnu.org/copyleft/gpl.html                %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% function [time,lon,lat,u,v]=plot_ADCP(dirin,fname,interval,mydepth,...
%%                                       myopt,myscale,legend_unit,legend_lon,legend_lat)
%%
%% Plots the current vector from ADCP data
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% 24/06/13 : andrea.doglioli@univ-amu.fr : first official release
%%
%% Credits: A. Petrenko,J. Gatti, Z.Hu, A.Doglioli
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function [h1,mytime,mydepth]=plot_ADCP(dirin,fname,time_interval,myscale,mycolor,legend_unit,legend_lon,legend_lat,chosen_depth)


load([dirin,fname]);

ii=find(mytime>time_interval(1) & mytime<time_interval(2));

lon = double(lon(ii)); lat = double(lat(ii)); u = double(u(ii,:)); v = double(v(ii,:));


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% UNCOMMENT IF YOU WANT TO Ask user to choose depth
% chosen_yet = 0; choose_depth = 0;
% dep_round = round(deph);
% 
% while ~chosen_yet
%     choose_depth = input('Do you want to choose the depth? y/n (Default is surface): ','s');
%     switch choose_depth
%         case 'y'
%             indexz = [];
%             chosen_yet = 1;
%             while isempty(indexz)==1
%                 disp('Please, choose one of the following available depths : (Make sure input has a negative sign!)');
%                 disp(num2str(floor(dep_round')));
%                 mydepth = input(': ','s'); mydepth = str2num(mydepth);
%                 mydepth = floor(mydepth);
%                 indexz = find(dep_round == mydepth);
%             end
%         case 'n'
%             indexz = 1;
%             mydepth=floor(round(deph(1)));
%             chosen_yet = 1;
%         otherwise
%             disp('Make a valid choice (y/n)... ');
%     end
% end  
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% UNCOMMENT IF YOU WANT TO ENTER CHOSEN_DEPTH IN MAP_ADCP
dep_round = round(depth);
mydepth=floor(chosen_depth);
indexz=find(dep_round == mydepth);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%% u,v for chosen depth
u=u(:,indexz);
v=v(:,indexz);

%%% to have a scaled vector with respect the legend
u=u.*myscale;
v=v.*myscale;

skip=2;

h1=m_quiver(lon(1:skip:end),lat(1:skip:end),u(1:skip:end),v(1:skip:end),0,'color',mycolor,'Linewidth',1);
m_plot(lon,lat,'k.-');
m_plot(lon(1),lat(1),'ko');
m_plot(lon(end),lat(end),'k^');

  
% Arrow scale
add_my_arrow(legend_lon,legend_lat,legend_unit,myscale,'[ms^{-1}]','k');

 
return
