function eval_calibration_cond(cruiseid)
% compare_cond -  Diagnostics plots to compare conductivity values between CTD and bottle samples.
%
% CTD Calibration toolbox.
%
% USAGE:
% compare_cond(cruiseid);
%
%INPUT: cruiseid: Cruise identification name.
%   
% OUTPUT: A series of plots to compare conductivity values between
% CTD and bottle samples.
%          
% DESCRIPTION: This function uses the summary conductivity calibration file created by  
% make_cond_sumfile and does a series of diagnostics plots to compare
% conductivity values between CTD and bottle sample to evaluate the quality of the data
% that we are collecting, as well, any potential problems with
% niskin/sample bottles and/or sensors.
%
% AUTHORS:Carlos Fonseca 
%         UM/CIMAS
%         Derrick Snowden
%         NOAA/AOML/PhOD
%         Tue May 11 11:23:37 EDT 2004
%
% CHANGELOG: 
%   23-Jul-2004, Version 1.0
%		* Initial version.

% Retrieve the necessary preferences for this cruise

%%%
close all;
%%%
group = group_name(cruiseid);

% cruise_dir is the main calibration data directory 
if ispref(group,'cal_data_dir')
	cruise_dir=getpref(group,'cal_data_dir');
else
	error(['The cal_data_dir preference was not set for cruise: ' cruiseid '.  Run register_cruise.m']);
end

% Load data from the cruise database
db_file = fullfile(cruise_dir,[cruiseid '_db.mat']);
if exist(db_file)==2
ld_file=(['load ',db_file,' cond_match_cal cond_match']);
eval(ld_file)
else
	error(['The cruise data base file was not found on the path.  ' db_file]);
end
n=who('cond_match_cal');
 if isempty(n)==1
 error(['cond_match_cal not found. Run make_cal_sumfile.m ']);
 return;
 end
disp('****************************************** ')
disp('PRELIMINARY COMPARISONS')
disp('****************************************** ')
disp('The data found in cond_match_cal goes from') 
disp(['the station ',num2str(min(cond_match_cal.stnnbr)),' to the station ',num2str(max(cond_match_cal.stnnbr)),'.'] ) 
disp('****************************************** ')
%
staa=input('Input first station: ');
stab=input('Input last station: ');

%%%%%%%%
%
disp(' 1 = use the primary sensor (DEFAULT)' )
disp(' 2 = use the secondary sensor' )
pri_sec=input('Do the calibration was applied to the primary or to the secondary sensor: ');
while (isempty(pri_sec)==1 | pri_sec<=0 | pri_sec>2)
	disp('Please answer 0 (zero) for primary or  1(one) for secondary ')
	pri_sec=input('Do the calibration was applied to the primary or to the secondary sensor ');
end

disp('You have an option to color code the output selecting a depth')
disp('This depth will be also used in the criteria to quality control the data' )
col_code=input('Do you want select a depth? (0=no 1=yes)');
while (isempty(col_code)==1 | col_code<0 | col_code>1)
	disp('Please answer 0 (zero) for no or  1(one) for yes')
	col_code=input('Do you want select a depth? (0=no 1=yes)');
end
if col_code==0
	hcolor=0;
end

if col_code==1
	hcolor=input('Enter the depth for color coding the output:');
end

s_index=find(cond_match_cal.stnnbr >= staa & cond_match_cal.stnnbr  <= stab...
    & cond_match_cal.quality1 == 2);% & cond_match_cal.quality2 == 2);

disp(['Number of good data points found: ',num2str(length(s_index))])
aux_gd=find( cond_match_cal.stnnbr>= staa & cond_match_cal.stnnbr  <= stab & cond_match_cal.quality1 ~= 9);
per_gd=(length(s_index)/length(aux_gd))*100;
disp(['This represents ', num2str(per_gd),'% of the data']); 
%
 station_num=cond_match_cal.stnnbr(s_index);
 bottle_sal=cond_match_cal.btlsal(s_index);
 ctd_sal_1=cond_match_cal.ctdsal(s_index);
 niskin_num=cond_match_cal.niskinbtlpos(s_index);
 sample_bottle_num=cond_match_cal.sampnbr(s_index);
 ctd_pressure=cond_match_cal.ctdprs(s_index);
%
%%%%%%%%%%%%%%%
%Start Ploting%
%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%
% Primary Sensor %
%%%%%%%%%%%%%%%%%%%%
clean_idx=find(cond_match.quality1==2);% & cond_match.quality2==2);
%[quality]=make_plots_report(bottle_sal,ctd_sal_1,station_num,ctd_pressure,niskin_num,sample_bottle_num,hcolor,'Calibrated','Salinity','psu');

if pri_sec==2
[quality]=make_plots_report(cond_match.btlsal(clean_idx),cond_match.ctdsal2(clean_idx),cond_match.stnnbr(clean_idx),cond_match.ctdprs(clean_idx),cond_match.niskinbtlpos(clean_idx),cond_match.sampnbr(clean_idx),hcolor,'Uncalibrated','Secondary','Salinity','psu');
else
[quality]=make_plots_report(cond_match.btlsal(clean_idx),cond_match.ctdsal1(clean_idx),cond_match.stnnbr(clean_idx),cond_match.ctdprs(clean_idx),cond_match.niskinbtlpos(clean_idx),cond_match.sampnbr(clean_idx),hcolor,'Uncalibrated','Primary','Salinity','psu');    
end

if pri_sec==2
[trash]=make_plots_report(cond_match_cal.btlsal(clean_idx),cond_match_cal.ctdsal(clean_idx),cond_match_cal.stnnbr(clean_idx),cond_match_cal.ctdprs(clean_idx),cond_match_cal.niskinbtlpos(clean_idx),cond_match_cal.sampnbr(clean_idx),hcolor,'Calibrated','Secondary','Salinity','psu');
else
[trash]=make_plots_report(cond_match_cal.btlsal(clean_idx),cond_match_cal.ctdsal(clean_idx),cond_match_cal.stnnbr(clean_idx),cond_match_cal.ctdprs(clean_idx),cond_match_cal.niskinbtlpos(clean_idx),cond_match_cal.sampnbr(clean_idx),hcolor,'Calibrated','Primary','Salinity','psu');    
end;

%Report Plot
if pri_sec==2
report_plots(cond_match.btlsal(clean_idx),cond_match.ctdsal2(clean_idx),cond_match.stnnbr(clean_idx),cond_match.ctdprs(clean_idx),cond_match.niskinbtlpos(clean_idx),cond_match.sampnbr(clean_idx),hcolor,'Uncalibrated','Secondary','Salinity','psu');
report_plots(bottle_sal,ctd_sal_1,station_num,ctd_pressure,niskin_num,sample_bottle_num,hcolor,'Calibrated','Secondary','Salinity','psu');
else
report_plots(cond_match.btlsal(clean_idx),cond_match.ctdsal1(clean_idx),cond_match.stnnbr(clean_idx),cond_match.ctdprs(clean_idx),cond_match.niskinbtlpos(clean_idx),cond_match.sampnbr(clean_idx),hcolor,'Uncalibrated','Primary','Salinity','psu');    
report_plots(bottle_sal,ctd_sal_1,station_num,ctd_pressure,niskin_num,sample_bottle_num,hcolor,'Calibrated','Primary','Salinity','psu');
end;

%save_plots(bottle_sal,ctd_sal_1,ctd_sal_2,station_num,ctd_pressure,niskin_num,sample_bottle_num,hcolor,'Salinity','psu');
%%%%%%%%%%%
%Save the conductivity summary structure.
%%%
%if quality_flag==0
% save(db_file,'cond_match','-append');
%end
%if nargout==0
% assignin('caller','ans',cond_match);
%else
% varargout{1}=cond_match;
%end
return