function theResult  = load_salts(cruiseid)
% load_salts: Load the autosal samples into the cruise database.
% 
% CTD Calibration toolbox
% 
% INPUT: 
%   cruiseid: character array containing the cruise id.
%
% OUTPUT:
%   theSalts: Combined salinity structure
%
% DESCRIPTION:	
%
%
% 
% AUTHOR: 
%			Derrick Snowden
%			NOAA/AOML/PhOD
%			Fri Oct 01 18:32:14 EDT 2004
%
% CHANGELOG: 
%   08-Jul-2004, Version 1.0
%		* Initial version.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Check for correct number of inputs.
error(nargchk(1,1,nargin))

% Retrieve the necessary preferences for this cruise
group = group_name(cruiseid);

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

% cruise_dir is the 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

% This file will contain the summary information 
% It is currently buggy and may not work.  Nevertheless, it is intended
% to be different for each cruise EDIT
sumfile =  fullfile(cal_autosal_dir,'ab0409_salinity_summary.txt');

% EDIT
year = 2004;


% EDIT  If you have more than one batch of standard water per cruise you may 
% need to include this in the loop below and change it for each autosal file.
nominal_std_conductivity = 1.99987; % This is fake for testing only....

% The cruise database.  Don't edit this line.
db_file = fullfile(cruise_dir,[cruiseid '_db.mat']);

% EDIT Maybe.  The following two lines should be pretty standard on the Brown.
dat_files = dir(fullfile(cal_autosal_dir,'*.dat'));
raw_files = dir(fullfile(cal_autosal_dir,'*.raw'));

for idx_file = 1:length(dat_files)
	[pathstr,namestr,ext,vers] = fileparts(dat_files(idx_file).name);
	% EDIT  The file naming convention I have encountered is MMDDHH or 2 dgit monthe
	% two digit day and two digit gmt hour at which the autosal analysis was performed.
	[mnth,day,gmthr] = strread(namestr,'%02d%02d%02d');
	this_dat = fullfile(cal_autosal_dir,dat_files(idx_file).name);
	this_raw = fullfile(cal_autosal_dir,raw_files(idx_file).name);
	% EDIT The raw files are pretty standard and should not need to be edited often.
	raw = read_autosal_raw(this_raw);
	% EDIT The dat files are likely different on each cruise.  
	% Take an example read_autosal_dat_*.m and edit it according to your current configuration
	% then include it in the line below.  NOTE it MUST have the same input/output syntax as 
	% examples.
	salts = read_autosal_dat_wward3(this_dat); % specialized for your cruise
	% If you've done the read_autosal_dat correctly, the followind two lines will work.
	autosal=match_autosal_raw_dat(salts,raw,sumfile,[year mnth day])
	cond(idx_file) = correct_autosal_drift(nominal_std_conductivity,autosal,sumfile);
	%keyboard
	% Everything works to here for stc02.
	% 1. Concatentate the samples together so that they don't overwrite each other when
	%     saved to the db_file.
	% 2. Verify that the autosal struct above is what carlos needs for the make_cond_sumfile.
	%
end


% Open the output file
db_file = fullfile(cruise_dir,[cruiseid '_db.mat']);
if exist(db_file)==2
	save(db_file,'cond','-append');
else
	save(db_file,'cond');
end
if nargout==0
	assignin('caller','ans',cond);
    return
else
    varargout{1}=cond;
    return
end
%

