%function fh=compare_tsplot(staa,stab)

% COMPARE_TSPLOT -  makes ts-plots 
%
% CTD Calibration toolbox.
%
% USAGE:
%  compare_tsplot;
%
% LOAD: cruiseid_db.mat (i.e. ab1202_db.mat)
%
% INPUT: Beginning and ending stations 
%   
% OUTPUT:  A series of  ts plots to compare the primary and the secondary
% sensors of the CTD with historical data and/or bottle samples.
%         
% DESCRIPTION:   This function uses the summary file created by make_cond
% _sumfile from the cruise database and plot the ts plots using primary and
% secondary sensor for conductivity and temperature.  In order to have a better
% visualization of the data this function only allows up to 10 different
% stations for a single plot. Bottle samples data and historical data can be
% added to the plots
%
% DEPENDENCIES: SW package (Version 3 using ITS-90 Temperature Scale)
%               load_salts
%               load_btl
%               load_bl
%               load_cnv

%%%%%%%%%%%  Determine what data to use in comparison  %%%%%%%%%%%%%%%%%%%%
plot_type_in = input([ ...
	'Compare_ctd_sensors: select datatype\n' ...
	'    raw data = 0\n' ...
    '    delooped data = 1\n' ...
	'    calibrated data = 2\n' ...
	'Enter type: ' ]);

    plot_type=plot_type_in,

    if plot_type == 2,
        n=who('cnv_cal');
        if isempty(n)==1
            fprintf (1,[ ...
            ['WARNING COMPARE_TSPLOT: N calibrated files found.  \n\n']])  
        
            plot_type_in = input(['Try with\n' ...
              '    raw data = 0\n' ...
              '    delooped data = 1\n\n' ...
              'Enter type: ' ]);
          
            plot_type = plot_type_in;
        else
        cnv_compare = cnv_cal;
        end; %end load cal data
    end;
    
    % Allow to try with raw or delooped
    if 0,
      plot_type_in = input(['Try with\n' ...
              '    raw data = 0\n' ...
              '    delooped data = 1\n\n' ...
              'Enter type: ' ]);
          
    plot_type = plot_type_in;
    end;
    
    if plot_type == 1,       
        n=who('cnv_dlp');
        if isempty(n)==1        
            fprintf (1,[ ...
            ['\nWARNING COMPARE_TSPLOT: No delooped files found.  \n']...
        ['    Trying raw data. \n\n']])
            n=who('cnv_load');
            if isempty(n)== 1
            fprintf (1,[ ...
            ['cnv_load not found.  \n']]) 
            fprintf (1,[['   Load database.  \n'] ])
            return
            else
            cnv_compare = cnv_load;
            end;
        else
            cnv_compare = cnv_dlp;
        end; %end load deloop data
   
   
    elseif plot_type == 0,
        n=who('cnv_load');
        if isempty(n)== 1
            fprintf (1,[ ...
        ['WARNING COMPARE_TSPLOT: Variable cnv_load not found.  \n']]) 
        fprintf (1,[['   Load database.  \n'] ])
        return
        else
        cnv_compare = cnv_load;
        end;
       
    end;
   
%end;
%%%%%%%%%%%%%%%%%%%%%%%%%%%  End Load Data  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
return



%%%%%%%  Determine if Bottle data will be using in comparison  %%%%%%%%%%%%
bottle_samples=input('Do you want to include the bottle samples? (0=no 1=yes): ');
while (isempty(bottle_samples)==1 | bottle_samples<0 | bottle_samples>1)
    disp('Please answer 0 (zero) for no or  1(one) for yes')
    bottle_samples=input( ...
	'Do you want to include the bottle samples? (0=no 1=yes): ');
end
if bottle_samples==1
n=who('cond_match');
 if isempty(n)==1
fprintf(1,['Bottle samples cannot be included ' ...
	'because cond_match was not found.\n'])
fprintf(1,['Run make_cond_sum. The program will continue anyway.\n'])
bottle_samples=0;
% if we are going to continue anyway, then we need to skip this return!
% return;
 end
end
%%%%%%%%%%%%%%%%%%%%%   End Bottle data  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


%%%%%%%%%%  Determine if historical data will be used in comparison  %%%%%%
historical=input('Do you want to include the historical data ? (0=no 1=yes): ');
while (isempty(historical)==1 | historical<0 | historical>1)
	disp('Please answer 0 (zero) for no or  1(one) for yes')
    historical=input('Do you want to include the historical data ? (0=no 1=yes): ');
end %end history while loop


if historical==1
    disp('Enter the name of the file with the historical data.')
    hist_file=input('Ex. abaco_historical.dat: ');
    %Skip loading historical data if it doesn't exist
	if isempty(hist_file), 
		historical=0; 
	else,
    hist=load(hist_file);
	end; %end isempty hist_file	
end %end historical if
%%%%%%%%%%%%%%%%%%%%%%%End Historical data%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%