function oxy=load_oxy_gomecc(cruiseid)
% LOAD_OXY_GOMECC - load the oxygen samples into the cruise database ( New
% O2 titration system)
% 
% CTD Calibration toolbox
%
% USAGE
%	oxy=load_oxy_gomecc(cruiseid)
% 
% INPUT
%	cruiseid	character array containing the cruise id.
%
% OUTPUT
% 	oxy		oxygen data and sample numbers
%
% DESCRIPTION
% This file reads the salinity samples inside a file with a specific
% format:
%
% 1st column - 	Station Number
% 2nd column - Cast Number
%  3rd -	 	Niskin Bottle Number
% 5th column - 	Sample bottle Number
% 8th- 		Dissolved oxygen ml/l 
% 5th column - 	Salinity
%
% We assume that this data was already corrected for eventual drifts of
% the salinometer. The database is updated with the results.  Eventually
% it will become more cruise independent.
% 

% AUTHOR: 
%			Carlos Fonseca
%			CIMAS/UM
%			Fri Oct 01 18:32:14 EDT 2004
%
% 
% VERSION: 
%	$Revision: 1.12 $
%	$Date: 2008/04/29 23:36:59 $
% 	$Id: load_salts.m,v 1.12 2008/04/29 23:36:59 duncombe Exp duncombe $
%
% CHANGELOG: 
%   08-Jul-2004, Version 1.0
%		* Initial version.
%
% 2007/12/13 CMDR 
%	* read cruise id from the file in the current directory
%	(see also load_btl and load_bl)
%  2008/02/05
%	* help text
%  2008/02/18 CMDR
%	* comments and style
%  2008/03/14 CMDR
%	* add fieldname cruiseid to the salts structure
%  2008/04/29 CMDR
%	* dont display popup boxes. if you wnat popup boxes edit the code again.
%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Check for correct number of inputs.
% error(nargchk(1,1,nargin))
%%%%%%%%%%%% CMDR
if nargin==0, cruiseid=getcruiseid; end;
%%%%%%%%%%%%

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

% btl_dir is the calibration data directory 
if ispref(group,'cal_oxy_dir')
	cal_oxy_dir=getpref(group,'cal_oxy_dir');
else
%   errordlg(['The cal_autosal_dir preference was not set for cruise: ' ...
%	cruiseid '.  Run register_cruise.m'])
    error(['The cal_oxy_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
%   errordlg(['The cal_data_dir preference was not set for cruise: ' ...
% 	cruiseid '.  Run register_cruise.m']);
    error(['The cal_data_dir preference was not set for cruise: ' ...
	cruiseid '.  Run register_cruise.m']);
end

oxy_files = dir(fullfile(cal_oxy_dir,'*.dat'));
oxy_names=oxy_files;
% msgbox('Loading the salinity samples','Loading Data')
% disp('Loading the salinity samples','Loading Data');
% The files are there, retrieve the data.

for i=1:length(oxy_names),
    tmp = load(fullfile(cal_oxy_dir,oxy_names(i).name));
    oxy(i).cruiseid=cruiseid;
    oxy(i).station=tmp(:,1);
    oxy(i).depth=tmp(:,3);
    oxy(i).sample_bottle=tmp(:,5);
    oxy(i).oxygen=tmp(:,8);
    oxy(i).units='mlperl';
end;

% The cruise database.  Don't edit this line.
db_file = fullfile(cruise_dir,[cruiseid '_db.mat']);
% Open the output file
if exist(db_file)==2
	save(db_file,'oxy','-append');
else
	save(db_file,'oxy');
end;

station_list=unique(vertcat(oxy.station));
% msgbox(['Loaded salinity samples from station ', ...
% 	num2str(min(station_list)),' to ', ...
% 	num2str(max(station_list))],'Loaded!','warn');
disp(['Loaded oxygen samples from station ',num2str(min(station_list)), ...
	' to ',num2str(max(station_list))]);

if nargout==0
	assignin('caller','ans',oxy);
else
    varargout{1}=oxy;
end;

return;

