% nbp1201_plot_merged_UW_navigation.m
%
% INPUT: RVDAS UW/Navigation merged data (mat files)
% PLOT data locations and values in colormap,
% one day data from days [361:365 1:36].

clear;
t0 = clock;


% Data path - part 1.
path_part_1_uw='/data2/antarctic_data2/nbp1201/underway/rvdas/uw/';

% ---- Convert to a real units.
dataConvert=f_menu_of_strings('Data Convert',strvcat('yes','no'));
if isempty(dataConvert), return; end
%dataConvert='yes';
%dataConvert='no';
%******************
% C O N S T A N T S
%******************
% Font size.
fnt_axis=10;
fnt_lbl=10;
fnt_title=10;
fnt_text=8;
fnt_name='helvetica';
marker_size=2;
marker_size_time=9;
fig_pos=[360.00        460.00        599.00        461.00];
crName='NBP1201';
%@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
%@@@@@@@@  UNDERWAY merded columns:  @@@@@@@@
%@@@@ Date/Time/Location - same for all @@@@@
%@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
colYear_M=1;
colDay_M=2;
colHour_M=3;
colMin_M=4;
colSec_M=5;
colLat_M=6;
colLon_M=7;
%@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
%@@@@@@@@@@@@@  DATA NAMES   @@@@@@@@@@@@@@@@
%@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
mwx1_channels=strvcat('MET','SUS','PUS');
PCOD_channels=strvcat('GLL','GGA');
channel_name_list_nav=strvcat('seap GGA: seapath GPS - GGA',...
    'PCOD GLL: Trimble (PCOD) GPS',...
    'PCOD GGA:  Trimble (PCOD) GPS');
channel_name_list=strvcat('eng1: Engineering',...
    'gen1: Micro-TSG #2',...
    'hdas: Hydro-DAS',...
    'knud: Knudsen',...
    'mtsg: Micro-TSG',...
    'mwx1: Meteorology',...
    'oxyg: Oxygen data',...
    'pco2: PCO2',...
    'pguv: GUV Data',...
    'rtmp: Remote Temperature',...
    'svp1: Sound Velosity Probe');
day_list_string=strvcat('361: Dec 27,2011',...
    '362: Dec 28, 2011',...
    '363: Dec 29, 2011',...
    '364: Dec 30, 2011',...
    '365: Dec 31, 2011',...
    '001: Jan 1, 2012',...
    '002: Jan 2, 2012',...
    '003: Jan 3, 2012',...
    '004: Jan 4, 2012',...
    '005: Jan 5, 2012',...
    '006: Jan 6, 2012',...
    '007: Jan 7, 2012',...
    '008: Jan 8, 2012',...
    '009: Jan 9, 2012',...
    '010: Jan 10, 2012',...
    '011: Jan 11, 2012',...
    '012: Jan 12, 2012',...
    '013: Jan 13, 2012',...
    '014: Jan 14, 2012',...
    '015: Jan 15, 2012',...
    '016: Jan 16, 2012',...
    '017: Jan 17, 2012',...
    '018: Jan 18, 2012',...
    '019: Jan 19, 2012',...
    '020: Jan 20, 2012',...
    '021: Jan 21, 2012',...
    '022: Jan 22, 2012',...
    '023: Jan 23, 2012',...
    '024: Jan 24, 2012',...
    '025: Jan 25, 2012',...
    '026: Jan 26, 2012',...
    '027: Jan 27, 2012',...
    '028: Jan 28, 2012',...
    '029: Jan 29, 2012',...
    '030: Jan 30, 2012',...
    '031: Jan 31, 2012',...
    '032: Feb 1, 2012',...
    '033: Feb 2, 2012',...
    '034: Feb 3, 2012',...
    '035: Feb 4, 2012',...
    '036: Feb 5, 2012');
%@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
%@@@@@@@@@@@@@@@  MENUS   @@@@@@@@@@@@@@@@@@@
%@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
%------------------------------------------------
% ---------- MENU (1): Underway channel ---------
%------------------------------------------------
channel_id_name=f_menu_of_strings('UNDERWAY channel',channel_name_list);
if isempty(channel_id_name), return; end
pause(0.001);
channel_id=channel_id_name(1:4);
channel_name=deblank(channel_id_name(7:end));
if strcmp(channel_id,'mwx1')
    %------------------------------------------------
    %---------  MENU (2): Meteorology subchannel ----
    %------------------------------------------------
    sub_channel_id=f_menu_of_strings('Meteorology mwx1 data',strvcat('MET','PUS','SUS'));
    if isempty(sub_channel_id), return; end
    %------------------------------------------------
    sub_channel_id=deblank(sub_channel_id);
    sub_channel_id_str=['_' sub_channel_id];
    sub_channel_id_text=['\_' sub_channel_id];
    pause(0.001);
else
    sub_channel_id='';
    sub_channel_id_str='';
    sub_channel_id_text='';
end
%------------------------------------------------
%------ MENU (3): Day of the year: Date  --------
%------------------------------------------------
day_name=f_menu_of_strings('The day of year: Date',day_list_string);
if isempty(day_name), return; end
%-----------------------------------------------
%day_name='002: Jan 2, 2012';
day=str2num(day_name(1:3));
% gen1 - no data file for day #22.
if strcmp(channel_id,'gen1') & day==22
    disp('gen1 day 22: data is not avalable');
    return;
end
day_date=deblank(day_name(6:end));
if day<10
    day_str=['d00' num2str(day)];
elseif day>=10 & day<100
    day_str=['d0' num2str(day)];
else
    day_str=['d' num2str(day)];
end
if day>=361
    year=2011;
else
    year=2012;
end
% Month of the day.
date_num=datenum([year-1 12 31 24 0 0])+(day-1);
date_vec=datevec(date_num);
month=date_vec(1,2);
clear date_num date_vec;
%$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
%$$$$$$$$$$$$$$$$  LOAD UNDERWAY merged data  $$$$$$$$$$$$
%$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
path_name_uw=[path_part_1_uw channel_id '/process/'];
fname_uw=['NBP1201_uw_' channel_id sub_channel_id_str '_' day_str];
fname_uw_text=['NBP1201\_uw\_' channel_id sub_channel_id_text '\_' day_str];
fname_ext_uw='mat';
p=['load ' path_name_uw fname_uw '.' fname_ext_uw ';'];
eval(p);
p=['d_uw=' fname_uw ';'];
eval(p);
%*********************************************
% C O N S T A N T S depending on CHANNEL name.
%*********************************************
par_note='';
if strcmp(channel_id,'eng1')
    par_list=strvcat('08 Power Supply Voltage V',...
        '09 Internal Case Temperature degC',...
        '10 Pump #1 flow rate L/min',...
        '11 Pump #2 flow rate L/min',...
        '12 Pump #3 flow rate L/min',...
        '13 Seismic air pressure Lbs/sq-in',...
        '14 PIR case resistance (not currently hooked up, data is irrelevant Kohm)',...
        '15 PIR case ratiometric output (not currently hooked up, data is irrelevant) mV',...
        '16 Freezer #1 temperature degC',...
        '17 Freezer #2 temperature degC',...
        '18 Freezer #3 temperature degC',...
        '19 ?????');
elseif strcmp(channel_id,'gen1')
    % Day #22 is not available - exclude from the list.
    no_day=22;
    if day==no_day
        disp('!!! gen1: Micro-TSG #2 - NO data file from the day #22');
        return;
    end
    par_list=strvcat('08 Internal Temperature degC',...
        '09 Conductivity s/m',...
        '10 Salinity PSU',...
        '11 Sound velocity m/s');
elseif strcmp(channel_id,'hdas')
    par_list=strvcat('08 Supply voltage V',...
        '09 Panel temperature degC',...
        '10 Fluorometer mV',...
        '11 Transmissometer mV',...
        '12 Sea Water Valve (-1 = stern thruster valve, 0 = moon pool valve)',...
        '13 Flow meter 1 frequency Hz',...
        '14 Flow meter 2 frequency Hz',...
        '15 Flow meter 3 frequency Hz',...
        '16 Flow meter 4 frequency Hz');
elseif strcmp(channel_id,'knud')
    par_list=strvcat('08 High frequency depth meters',...
        '09 Low frequency depth meters');
elseif strcmp(channel_id,'mtsg')
    par_list=strvcat('08 Internal Temperature degC',...
        '09 Conductivity s/m',...
        '10 Salinity PSU',...
        '11 Sound velocity m/s');
elseif strcmp(channel_id,'mwx1')
    if strcmp(sub_channel_id,'MET')
        par_list=strvcat('08 Power Supply Voltage V',...
            '09 Enclosure Relative Humidity %',...
            '10 Air temperature degC ',...
            '11 Air Relative Humidity %',...
            '12 PAR (photosynthetically available radiation)* mV',...
            '13 PSP (short wave radiation)* mV',...
            '14 PIR Thermopile (long wave radiation)* mV',...
            '15 PIR Case Temperature degKelvin',...
            '16 PIR Dome Temperature degKelvin',...
            '17 Barometer mBar');
    elseif strcmp(sub_channel_id,'PUS')
        par_list=strvcat('08 A (unit identification, A=1)',...
            '09 Port Wind direction relative deg',...
            '10 Port Wind speed relative m/s',...
            '11 Units (M=1)',...
            '12 Sound Speed m/s',...
            '13 Sonic Temperature degC',...
            '14 Unit Status (00 or 60 are good, any other value indicates fault)');
    elseif strcmp(sub_channel_id,'SUS')
        par_list=strvcat('08 A (unit identification, A=1)',...
            '09 Starboard Wind direction relative deg',...
            '10 Starboard Wind speed relative m/s',...
            '11 Units (M=1)',...
            '12 Sound Speed m/s',...
            '13 Sonic Temperature degC',...
            '14 Unit Status (00 or 60 are good, any other value indicates fault)');
    else
        return;
    end
elseif strcmp(channel_id,'oxyg')
    par_list=strvcat('08 Measurement ID: Model Number',...
        '09 Measurement ID: Serial Number',...
        '10 Oxygen Reading MkM',...
        '11 Saturation Reading %',...
        '12 Water Temperature degC',...
        '13 Dphase Raw numeric',...
        '14 Bphase Raw numeric',...
        '15 Rphase Raw numeric',...
        '16 Bamp Raw numeric',...
        '17 Bpot Raw numeric',...
        '18 Ramp Raw numeric',...
        '19 RawTemp');
elseif strcmp(channel_id,'pco2')
    par_list=strvcat('08 pCO2 time tag (decimal is fractional time of day yyyyddd.tt)',...
        '09 Raw voltage (IR) mV',...
        '10 Cell temperature degC',...
        '11 Barometer MBar',...
        '12 Concentration ppm',...
        '13 Equilibrated temperature degC',...
        '14 pCO2 pressure microAtm',...
        '15 Flow rate ml/min',...
        '16 Source ID #  1 or 2 digits',...
        '17 Valve position 1 or 2 digits',...
        '18 Flow source (Equil = pCO2 measurement) 1 or 2 digits');
    par_list_2=strvcat('Flow source code and name:',...
        '01 Equil',...
        '02 Atmos',...
        '03 Nitrogen',...
        '04 CA06630',...
        '05 CA06632',...
        '06 CA06636',...
        '07 CA06661',...
        '08 CA07206',...
        'ALL Flow sources');
elseif strcmp(channel_id,'pguv')
    %'08 Date mmddyy',...
    %'09 Time hhmmss',...
    par_list=strvcat('10 Ed0Gnd V',...
        '11 Ed0320 uW (cm^2 nm)',...
        '12 Ed0340 uW (cm^2 nm)',...
        '13 Ed0313 uW (cm^2 nm)',...
        '14 Ed0305 uW (cm^2 nm)',...
        '15 Ed0380 uW (cm^2 nm)',...
        '16 Ed0PAR uW (cm^2 nm)',...
        '17 Ed0395 uW (cm^2 nm)',...
        '18 Ed0Temp degC',...
        '19 Ed0Vin V');
elseif strcmp(channel_id,'rtmp')
    par_list=strvcat('08 Temperature at seawater intake degC');
elseif strcmp(channel_id,'svp1')
    par_list=strvcat('08 Sound velocity in ADCP sonar well m/s');
else
    return;
end
%------------------------------------------------
%-------------------- MENU (4): QUANTITY --------
%------------------------------------------------
colNum_name=f_menu_of_strings('QUANTITY Column: Name',par_list);
if isempty(colNum_name), return; end
pause(0.001);
%-----------------------------------------------
colNum=str2num(colNum_name(1:2));
q_name=deblank(colNum_name(4:end));
if  strcmp(channel_id,'pco2')
    %------------------------------------------------
    %------------ MENU (5): pco2 Flow source --------
    %------------------------------------------------
    flowCode_flowName=f_menu_of_strings('Flow source: Equil is pco2 MEASUREMENT',par_list_2(2:end,:));
    if isempty(flowCode_flowName), return; end
    %pause(0.001);
    %-----------------------------------------------
    if strcmp(flowCode_flowName,'ALL Flow sources')
        flowCode=[];
        flowName=deblank(flowCode_flowName);
    else
        flowCode=str2num(flowCode_flowName(1:2));
        flowName=deblank(flowCode_flowName(4:end));
    end
end
q_name_print=q_name;
if strcmp(dataConvert,'yes')
    if strcmp(channel_id,'hdas') & strcmp(q_name,'Fluorometer mV')
        Dark=0.0701; % from instrument.coeff
        SF=11.0782;  % from instrument.coeff
        %Fluor=(Vmeasured-Dark)*SF;
        q_name_print='Fluorescence \mug/L'; % !!! name changed
    elseif strcmp(channel_id,'hdas') & strcmp(q_name,'Transmissometer mV')
        Vdark=0.059; % from instrument.coeff
        Vref=4.804;  % from instrument.coeff
        %Tr=(Vsig-Vdark)/(Vref-Vdark);
        q_name_print='Transmition %'; % !!! name changed to real units
    elseif strcmp(channel_id,'mwx1') & strcmp(sub_channel_id,'MET') & strcmp(q_name(1:3),'PAR')
        %parc1=0.17;
        %parcv=-0.0001; % V
        parc1=0.1568; % from instrument.coeff
        parcv=0.0007; % V % from instrument.coeff
        %parCalc=(par-parcv) * parc1 * 10000; % muEinstiens/m^2sec
        %d_uw(:,colNum)=(d_uw(:,colNum)/1000-parcv) * parc1 * 10000; % muEinstiens/m^2sec
        q_name_print=[q_name(1:end-2) '\muEinstiens/m^2sec']; % !!! name changed to real units
    elseif strcmp(channel_id,'mwx1') & strcmp(sub_channel_id,'MET') & strcmp(q_name(1:3),'PSP')
        pspCoeff=7.87;
        %calibration_scale=pspCoeff*10^-6;      % V/(W/m^2)
        %pspCalc=psp/(pspCoeff*10^-6*1000);     % W/m^2
        q_name_print=[q_name(1:end-2) 'W/m^2']; % !!! name changed to real units
    elseif strcmp(channel_id,'mwx1') & strcmp(sub_channel_id,'MET') & strcmp(q_name(1:3),'PIR')
        % Constants.
        Sigma_pir=5.6704e-8;
        % PIR coefficient.
        pirCoeff=4.11;
        %calibration_scale=pirCoeff*10^-6;      % V/(W/m^2)
        %pirCalc=pir/(pirCoeff*10^-6*1000);     % W/m^2
        q_name_print=[q_name(1:end-2) 'W/m^2']; % !!! name changed to real units
    end
end % For if strcmp(dataConvert,'yes')
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%  Make West Lon positive %%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Make W Lon positive - all E lon
r_w=find(d_uw(:,colLon_M)<0);
d_uw(r_w,colLon_M)=d_uw(r_w,colLon_M)+360;
clear r_w;
subname_str='';
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%   pco2 vs FLOW SOURCE   %%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if strcmp(channel_id,'pco2')
    if ~isempty(flowCode);
        r_use=find(d_uw(:,18)==flowCode);
        d_uw=d_uw(r_use,:);
    end
    if strcmp(flowName,'Equil')
        subname_str=['(Flow Source: ' flowName ' - pco2 MEASUREMENT)'];
    else
        subname_str=['(Flow Source: ' flowName ')'];
    end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%  E X C L U D E  NaN data  %%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
r_nan=find(isnan(d_uw(:,colNum)));
d_uw(r_nan,:)=[];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%   C O R R E C T I O N   %%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% ------ C O R R E C T I O N  - svp1 (Sound velocity), pco2 NEGATIVES ---------
q_note='';
if strcmp(channel_id,'svp1') | (strcmp(channel_id,'pco2') & strcmp(flowName,'Equil') )
    r_minus=find(d_uw(:,colNum)<0);
    if ~isempty(r_minus)
        d_uw(r_minus,:)=[];
        q_note=strvcat('NOTE:',q_name,[num2str(length(r_minus)) ' NEGATIVES have been removed']);
    end
elseif strcmp(channel_id,'knud') & strcmp(q_name,'Low frequency depth meters')
    r_minus=find(d_uw(:,colNum)<=0);
    if ~isempty(r_minus)
        d_uw(r_minus,:)=[];
        q_note=strvcat('NOTE:',q_name,[num2str(length(r_minus)) ' points have been removed - ZERO or NEGATIVE']);
    end
end
% ------ C O R R E C T I O N  -  svp1 (Sound velocity), pco2 NEGATIVES END ---
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%  DATA %%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if isempty(d_uw)
    disp(['Day #' num2str(day) ': ' channel_id  ' ' q_name ' ' subname_str ': no data'])
    return;
else % For if isempty(d_uw)
    %@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
    %@@@@@@@@@@@@@       DATA Conversion       @@@@@@@@@@@@@
    %@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
    if strcmp(dataConvert,'yes')
        % ---- convert to physical units.
        if strcmp(channel_id,'hdas')
            if strcmp(q_name,'Fluorometer mV')
                mi_ma_before= [mi_ma_before;min(d_uw(:,colNum)) max(d_uw(:,colNum))];
                d_uw(:,colNum)=(d_uw(:,colNum)/1000-Dark)*SF;
                mi_ma_after= [mi_ma_after;min(d_uw(:,colNum)) max(d_uw(:,colNum))];
                r_minus=find(d_uw(:,colNum)<0);
                if ~isempty(r_minus)
                    d_uw(r_minus,colNum)=0;
                    q_note=strvcat('NOTE:',q_name,[num2str(length(r_minus)) ' NEGATIVES have been replaced with zero']);
                end
            elseif strcmp(q_name,'Transmissometer mV')
                mi_ma_before= [mi_ma_before;min(d_uw(:,colNum)) max(d_uw(:,colNum))];
                d_uw(:,colNum)=( (d_uw(:,colNum)/1000-Vdark)/(Vref-Vdark) ) *100;
                mi_ma_after= [mi_ma_after;min(d_uw(:,colNum)) max(d_uw(:,colNum))];
                r_minus=find(d_uw(:,colNum)<0);
                if ~isempty(r_minus)
                    d_uw(r_minus,:)=[];
                    q_note=strvcat('NOTE:',q_name,[num2str(length(r_minus)) ' NEGATIVES removed']);
                end
            end
        elseif strcmp(channel_id,'mwx1') & strcmp(sub_channel_id,'MET')
            if strcmp(q_name(1:3),'PAR')
                % Convert mV to muEinstiens/m^2sec.
                %parCalc=(par-parcv) * parc1 * 10000; % muEinstiens/m^2sec
                d_uw(:,colNum)=(d_uw(:,colNum)/1000-parcv) * parc1 * 10000; % muEinstiens/m^2sec
            elseif strcmp(q_name(1:3),'PSP')
                % Convert mV to W/m^2.
                %pspCalc=psp/(pspCoeff*10^-6*1000);     % W/m^2
                d_uw(:,colNum)=(d_uw(:,colNum)*1000) / pspCoeff;
            elseif strcmp(q_name(1:3),'PIR')
                % (1) ---- Convert mV to W/m^2.
                %pirCalc=pir/(pirCoeff*10^-6*1000);     % W/m^2
                %%%%pirCalc=(d_uw(:,colNum)*1000) / pirCoeff;
                pirCalc=(-d_uw(:,colNum)*1000) / pirCoeff;
                % (2) ---- Correct for case temperature.
                pir_case=d_uw(:,15);
                pirCalc_plus=Sigma_pir * pir_case;
                % (3) ---- Correct for dome temperature.
                % dome constant =3.5;
                pir_dome=d_uw(:,16);
                pirCalc_minus=3.5 * Sigma_pir * (pir_dome-pir_case);
                pirCalc=pirCalc + pirCalc_plus - pirCalc_minus;
                d_uw(:,colNum)=pirCalc;
            end
        end % For if strcmp(channel_id,'hdas')
    end % For if strcmp(dataConvert,'yes')
    %@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
    % Decimal hour.
    h_dec_N=d_uw(:,colHour_M) + ( d_uw(:,colMin_M) + d_uw(:,colSec_M)/60 )/60;
    % Quantity and location.
    q_uw=d_uw(:,colNum);
    lat_uw=d_uw(:,colLat_M);
    lon_uw=d_uw(:,colLon_M);
    % Data min, max.
    data_min_max=[min(q_uw) max(q_uw)];
    %#############################################
    %############   Map limits  ##################
    %#############################################
    lonmin_d = min(lon_uw);
    lonmax_d = max(lon_uw);
    latmin_d = min(lat_uw);
    latmax_d = max(lat_uw);
    klat=0.05;
    klon=0.05;
    if day==361 | day==362 | day==3 | day==4 | day==6
        klat=0.15;
    elseif day==19  | day==25  | day==35
        klat=1.3;
    elseif day==33
        klon=1.3;
    end
    d_lon=range([lonmin_d lonmax_d])*klon;
    d_lat=range([latmin_d latmax_d])*klat;
    lonmin=lonmin_d-d_lon;
    lonmax=lonmax_d+d_lon;
    latmin=latmin_d-d_lat;
    latmax=latmax_d+d_lat;
    lon_int=1;
    lat_int=0.5;
    % --------  Calculate relation relyx = axisy/axisx (for PlotBoxAspectRatio)
    weg = 111*cos(pi*(latmin+(latmax-latmin)/2)/180);% Weight of one degree longitude
    xc = (lonmax-lonmin)*weg;                        % Longitude, km
    yc = (latmax-latmin)*111;                        % Latitude, km
    relyx = yc/xc;
    %#############################################
    %######## X,Y ticks, tickLabels ##############
    %#############################################
    % ---- X-ticks.
    x_tick=floor(lonmin):lon_int:lonmax;
    x_tick_label='';
    for ii=1:length(x_tick)
        if x_tick(ii)<180
            x_tick_str=[num2str(x_tick(ii)) 'E'];
        else
            x_tick_str=[num2str(360-x_tick(ii)) 'W'];
        end

        if ii==length(x_tick)
            delim='';
        else
            delim='|';
        end
        x_tick_label=[x_tick_label x_tick_str delim];
    end
    clear ii;
    % ---- Y-ticks.
    y_tick=floor(latmin):lat_int:latmax;
    y_tick_label='';
    for ii=1:length(y_tick)
        if ii==length(y_tick)
            delim='';
        else
            delim='|';
        end
        y_tick_label=[y_tick_label num2str(-y_tick(ii)) 'S' delim];
    end
    clear ii;
    %#############################################
    %############  COLORMAP data  ################
    %#############################################
    % Load Colormap.
    load palet_13_ant;
    cmap=palet_13_ant;
    n_bands=size(cmap,1);
    n_dec_chars=2;
    cval=1:size(cmap,1)+1;
    % Quantity min, max.
    q_min_d = data_min_max(1,1);
    q_max_d = data_min_max(1,2);
    %***********************************************************
    %************  Set figure, axes properties  ****************
    %***********************************************************
    figure;
    set(gcf,'position',fig_pos,'color',[1 1 1],...
        'paperPositionMode','auto');
    %***********************************************************
    %*****************  PLOT TIME Markers    *******************
    %***********************************************************
    d_hour=[0 4 8 12 16 20 23];
    %date_format='yyyy-mm-dd HH:MM:SS';
    %date_format='mm/dd/yyyy HH:MM:SS';
    %date_format='mm/dd';
    %date_format='yyyy/mm/dd HH:MM';
    date_format='HH:MM';
    hold on;
    for nn=1:length(d_hour)
        if strcmp(channel_id,'pco2') % time interval is 2-3 minutes
            r_h=find(d_uw(:,colHour_M)==d_hour(nn) & d_uw(:,colMin_M)>=0 & d_uw(:,colMin_M)<=3);
        else
            r_h=find(d_uw(:,colHour_M)==d_hour(nn) & d_uw(:,colMin_M)==0);
        end
        if ~isempty(r_h)
            % use the point with min HOUR time.
            [mi,rmi]=min(h_dec_N(r_h,1));
            lat=lat_uw(r_h(rmi),1);
            lon=lon_uw(r_h(rmi),1);
            dnum_n=datenum([year month day d_hour(nn) d_uw(r_h(rmi),colMin_M) 0]);
            text(lon,lat-range([latmin latmax])*0.06,['  ' datestr(dnum_n,date_format)],...
                'fontsize',fnt_text,'fontname',fnt_name,'horizontalAlignment','left','color',[1 0 0]);
            plot(lon,lat,'k+','markersize',marker_size_time,'markerEdgeColor',[1 0 0]);
        end
    end
    hold off;
    if q_min_d==q_max_d
        %***********************************************************
        %*******************       MIN=MAX      ********************
        %***************   PLOT locations only  ********************
        %***********************************************************
        hold on;
        plot(lon_uw,lat_uw,'o','color',[0 0 1],'markersize',marker_size);
        hold off;
    else % For if q_min_d==q_max_d
        % Calculate colormap vector.
        vv=f_colormap_vector(q_min_d,q_max_d,n_bands,n_dec_chars);
        if isempty(vv)
            disp(strvcat('Data range is too small to calculate the colormap vector',...
                'Try to increase the number of decimal points (function f_colormap_vector input variable n_dec_chars'));
            return;
        end
        colormap(cmap);
        %@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
        %@@@@@@  PLOT markers in COLORMAP color @@@@@@@@@@@@
        %@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
        hold on;
        D=[];
        for jj=1:size(q_uw,1)
            q_j=q_uw(jj,1);
            lat=lat_uw(jj,1);
            lon=lon_uw(jj,1);
            countSearch=0;
            for ii=1:length(vv)-1
                countSearch=countSearch+1;
                if q_j<=vv(1)
                    color_j=cmap(1,:);
                elseif q_j>=vv(end)
                    color_j=cmap(end,:);
                elseif q_j>=vv(ii) & q_j<vv(ii+1)
                    color_j=cmap(ii,:);
                else
                    color_j=[];
                end
                if ~isempty(color_j), break; end
            end
            if ~isempty(color_j)
                % Check.
                D=[D;q_j ii cmap(ii,:)];
                % Plot marker in colormap color.
                plot(lon,lat,'o','markersize',marker_size,...
                    'markeredgecolor',color_j,'markerfacecolor',color_j,...
                    'linewidth',0.3);
            else % For if ~isempty(color_j)
                disp(['Color not found for the point: #' num2str(jj) ', value=' num2str(q_j)]);
                return;
            end % For  if ~isempty(color_j)
        end
        hold off;
        %***********************************************************
        %***********************   COLORBAR   **********************
        %***********************************************************
        cb_ticklabel=vv;
        caxis([min(cval) max(cval)]);
        h1 = colorbar;
        aPos = get(h1,'Position');
        set(h1,'Position',[aPos(1,1)+aPos(1,3)*1.25 aPos(1,2)+aPos(1,4)*0.05 aPos(1,3)*0.5 aPos(1,4)*0.9]);
        set(h1,'ytick',cval,'yticklabel',cb_ticklabel,'yLim',[min(cval) max(cval)],...
            'Fontsize',fnt_axis,'ticklength',get(h1,'ticklength')*2.6,...
            'xcolor',[0 0 0],'ycolor',[0 0 0],'fontname',fnt_name);
    end % For if q_min_d==q_max_d
    %***********************************************************
    %*****************  Set Axes Properties  *******************
    %***********************************************************
    axPos = get(gca,'Position');
    kk=1.0;
    set(gca,'position',[axPos(1)+axPos(3)*(-0.04) axPos(2)+axPos(4)*0.03 axPos(3)*kk axPos(4)*kk]);
    axis([lonmin lonmax latmin latmax]);
    set(gca,'PlotBoxAspectRatio',[1 relyx*1 1],...
        'tickdir','out',...
        'ticklength',(get(gca,'ticklength')*0.6),...
        'xtick',x_tick,'xticklabel',x_tick_label,...
        'ytick',y_tick,'yticklabel',y_tick_label,...
        'fontname',fnt_name,'Fontsize',fnt_axis,...
        'box','on');
    xlabel('Longitude','fontname',fnt_name,...
        'Fontsize',fnt_lbl);
    ylabel('Latitude','fontname',fnt_name,...
        'Fontsize',fnt_lbl);
    title([crName ' rvdas/UW ' day_date ' (day #' num2str(day) '):  ' channel_id ' ' q_name_print ' ' subname_str],...
        'fontname',fnt_name,...
        'Fontsize',fnt_title,'color',[0 0 0]);
    %***********************************************************
    %********************   PLOT Min/Max   *********************
    %***********************************************************
    str_mi_ma(1)={['Min = ' num2str(data_min_max(1,1))]};
    str_mi_ma(2)={['Max = ' num2str(data_min_max(1,2))]};
    text(lonmin+range([lonmin lonmax])*0.1,latmin+range([latmin latmax])*0.85,str_mi_ma,...
        'fontsize',fnt_text,'fontname',fnt_name,'horizontalAlignment','left');
    %***********************************************************
    %*************  Find measurements interval *****************
    %***********************************************************
    % --- choose one hour which have max data points to compute measurements interval.
    h_n=[];
    for h_i=[0:23]
        rr=find(d_uw(:,colHour_M)==h_i);
        if ~isempty(rr), h_n=[h_n;h_i length(rr)]; end
    end
    if min(h_n(:,2))==max(h_n(:,2)) & min(h_n(:,2))==1 & sum(h_n(:,2))==24
        time_int_str=[ ', Time interval = 1hour'];
    elseif min(h_n(:,2))==max(h_n(:,2)) & sum(h_n(:,2))<24
        time_int_str='';
    else
        [ma,ma_r]=max(h_n(:,2));
        hour_use_for_interval=h_n(ma_r,1);
        rrr=find(d_uw(:,colHour_M)==hour_use_for_interval);
        % --- time interval in seconds.
        time_dif=diff(h_dec_N(rrr,1));
        % --- exclude max to cosider missing data.
        [mad,madr]=max(time_dif);
        time_dif(madr)=[];
        % --- average time interval.
        time_int_sec=mean(time_dif)*3600;
        if time_int_sec>60
            % --- time interval string - in minutes.
            time_int_str=[ ', Time interval =~ ' num2str(time_int_sec/60,'%2.2f') ' minute(s)'];
        else
            % --- time interval string - in seconds.
            time_int_str=[ ', Time interval =~ ' num2str(time_int_sec,'%2.2f') ' second(s)'];
        end
    end % For if min(h_n(:,2))==max(h_n(:,2)) & sum(h_n(:,2))==24
    %***********************************************************
    %*************   PLOT Text - file info   *******************
    %***********************************************************
    % --- control text position depending on plot box aspect ratio.
    kx_text=0.05;
    if relyx>=2.4
        ky_text=0.14;
        kx_text=0.7;
    elseif relyx>=1.69
        ky_text=0.14;
        kx_text=0.4;
    elseif relyx>=0.87
        ky_text=0.14;
        kx_text=0.1;
    elseif relyx>=0.82
        ky_text=0.14;
    elseif relyx>=0.67
        ky_text=0.16;
    elseif relyx<=0.195
        ky_text=0.6;
    elseif relyx<=0.32
        ky_text=0.4;
    else
        ky_text=0.3;
    end
    % --- plot text.
    str_t(1)={['File name: ' fname_uw_text '.' fname_ext_uw ' (column #'  num2str(colNum) ')' time_int_str]};
    text(lonmin-range([lonmin lonmax])*kx_text,latmin-range([latmin latmax])*ky_text,str_t,...
        'fontsize',fnt_text,'fontname',fnt_name,...
        'horizontalAlignment','left','fontAngle','it','color',[0 0 1]);
    %******************
    % Display note - negative data found.
    %******************
    if ~isempty(q_note),disp(q_note); end
end % For if isempty(d_uw)
estimated_time_minutes=etime(clock,t0)/60
