%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%                    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                %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Script for draw a geographical map with 
%%% measured current vectors
%%%
%%% INPUT : coastline .mat file
%%%
%%% OUTPUT: m_map figure of ADCP current
%%%
%%% ALGORITHM: calcuate de projection and
%%%            plot the current vectors
%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% 09/04/16 : LR: add options to plot every files in fname_ADCP on same plot
%%            with plot_ADCP; remove all questions asked to user for a better
%%            use during campaign
%% 24/06/13 : andrea.doglioli@univ-amu.fr : first official release
%%
%% Credits: A. Petrenko,J. Gatti, Z.Hu, F.Nencioli, M.Kersale, A.Doglioli, L.Rousselet
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
help map_ADCP
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear;close all;
%%

LATEXtools_param
LATEXtools_cruise
%
% filename
%dirin_ADCP='SEAQUEST/ADCP/mat/';
fname_ADCP='ADCP_STA_30pgood';
%
Transect_Names = {'transect1-Tstart-T0' 'transect2-T0-T1'       'transect3-T1-T3'     'transect4-T3-T5'      'transect5-T5-T0'       'transect6-T0-T13'     'transect7-T13-T14'    'transect8-T14-T15'    'transect9-T15-T7'     'transect10-T7-T14'    'transect11-T14-T16'   'transect12-T16-T17'   'transect13-T17-T9'    'transect14-T9-T15'    'transect15-T15-T18'   'transect16-T18-T19'   'transect17-T19-T20'   'transect6-7-8-9'};

Transect_Start = {'30-Oct-2015 00:00:00' '30-Oct-2015 09:50:00' '30-Oct-2015 14:31:19' '30-Oct-2015 23:49:11' '31-Oct-2015 06:26:39' '03-Nov-2015 06:55:00' '03-Nov-2015 16:22:47' '03-Nov-2015 20:31:25' '03-Nov-2015 23:21:47' '04-Nov-2015 02:52:04' '04-Nov-2015 08:52:09' '04-Nov-2015 15:30:00' '04-Nov-2015 20:07:07' '04-Nov-2015 23:30:00' '05-Nov-2015 07:40:00' '05-Nov-2015 17:26:00' '05-Nov-2015 20:30:00' '03-Nov-2015 06:55:00'};

Transect_Stop =  {'30-Oct-2015 05:44:00' '30-Oct-2015 12:05:00' '30-Oct-2015 23:22:06' '31-Oct-2015 05:59:18' '31-Oct-2015 11:34:54' '03-Nov-2015 15:17:00' '03-Nov-2015 18:05:16' '03-Nov-2015 23:02:43' '04-Nov-2015 02:25:04' '04-Nov-2015 06:23:39' '04-Nov-2015 11:16:51' '04-Nov-2015 16:45:00' '04-Nov-2015 22:55:40' '05-Nov-2015 05:00:00' '05-Nov-2015 09:30:00' '05-Nov-2015 19:34:00' '06-Nov-2015 01:46:00' '04-Nov-2015 02:25:04'};

for transchoice=18

time_interval=[datenum(Transect_Start(transchoice)) datenum(Transect_Stop(transchoice))];
%- Options
mycolor=['r';'b';'k';'m'];
%chosen_depth=-18;
myscale=0.3;
legend_unit=0.2;
legend_lon=7.2;
legend_lat=44;
%
%- Geographic projection for m_map -%
projection = 'mercator';
%
%- User coast in dirin -%
UserCoast='GOL.mat'; % in "sub_functions" directory
%
h1=figure;
plot_ADCPsection(dirin_ADCP,fname_ADCP,time_interval,Transect_Names{transchoice});

print(h1,[figdir,'ADCP_',Transect_Names{transchoice},'_verticalsection'],'-dpng','-r200')

%figure; hold on;
h=figure; hold on
m_proj('mercator','lon',[lonmin lonmax],'lat',[latmin latmax]);

%- User's High Resolution Coastline -%
m_usercoast(UserCoast,'patch',[.7 .7 .7],'edgecolor','k');
%
%- Geographical Axis -%
m_grid('box','fancy','tickdir','in');
xlabel('Longtitude');
ylabel('Latitude');
%
j=1;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
        %mycolor = input('Which color do you want for the arrows ? (k,m,g,b,r...): ','s');
[h1,time,mydepth]=plot_ADCP(dirin_ADCP,fname_ADCP,time_interval,myscale,'r',legend_unit,legend_lon,legend_lat,-18);

[h1,time,mydepth]=plot_ADCP(dirin_ADCP,fname_ADCP,time_interval,myscale,'b',legend_unit,legend_lon,legend_lat,-34);
        

title ([Transect_Names{transchoice}, '\newline ADCP velocity [red -18m; blue -34m]'])

        %legend output from plot ADCP
        legend_arrow(j,1)=h1;
        legend_time_1(j,1)=time(1);
        legend_time_end(j,1)=time(end);
        legend_depth(j,1)=mydepth;
        
        %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        %% UNCOMMENT this if you want to Process same file to superimpose
        %% another depth whit choose depth in plot_ADCP
        %change_file = input('Do you want to process this file again (max 2 depths) ?(n=no, y=yes): ','s');
        %  switch change_file
        %      case 'y'
        %          %mycolor = input('Which color do you want for the arrows ? (k,m,g,b,r...): ','s');
        %          [h1,time,mydepth]=plot_ADCP(dirin_ADCP,fname_ADCP(i,:),myscale,mycolor(i),legend_unit,legend_lon,legend_lat,chosen_depth(i));
        %          j=j+1;
        %          legend_arrow(j,1)=h1;
        %          legend_time_1(j,1)=datestr(time(1),'dd/mm HH:MM');
        %          legend_time_end(j,1)=datestr(time(end),'dd/mm HH:MM');
        %          legend_depth(j,1)=mydepth;
        %     case 'n'
        %         disp('Continue to next file...') 
        % end    
        %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        
 % Legend
%legend(legend_arrow,[datestr(legend_time_1,'dd/mm HH:MM - '),datestr(legend_time_end,'dd/mm HH:MM ; '),num2str(legend_depth,'%3d m')])

%- Figure Printing -%
%print(1,[figdir,'map_ADCP_from_',datestr(legend_time_1(1),'yyyy-dd-mm-HH-MM'),'_to_',datestr(legend_time_end(end),'yyyy-dd-mm-HH-MM'),'_',num2str(legend_depth(1),'%3dm'),'.png'],'-dpng','-r200');
%
print(h,[figdir,'ADCP_',Transect_Names{transchoice}],'-dpng','-r200')
close all
end%for transchoice
disp(' ');
disp('----- END ---')
