function oxy = read_oxy(in_file)
% READ_OXY - load *.oxy files from the AOML Winkler titration system. 
%
% USAGE:
%  oxy = read_oxy(filename);
%
% INPUT:
%     in_file: string containing path and name of input file
%
% OUTPUT:
%   oxy: struct with fields
%     date: time and data of titration (usually wrong on AOML computer)
%     station: string indicating station/cast
%     depth: depth field in the titration computer, frequently Niskin
%			bottle Rosette position
%     sample_bottle: label of the sample bottle in which the titration
% 			was done.
%     thio_vol: solume of Thiosulphate in the titration.
%     oxygen: oxygen in units of micromoles per liter.  See ox_units
%  			for conversion to other
%       more standard units for analysis. 
%     units: 'mmmperl'
%
% DESCRIPTION:
%
% BUGS:
% 
% NOTE:
%
% TO BE DONE:
%   
%  CALLER: 
%
%  DEPENDENCIES: 
%

% AUTHOR: Derrick Snowden
%         NOAA/AOML/PhOD
%
% 
% VERSION: 
%	$Revision: 1.9 $
%	$Date: 2008/03/14 17:57:23 $
%	$Id: read_oxy.m,v 1.9 2008/03/14 17:57:23 duncombe Exp duncombe $
%
% CHANGELOG:
% 2007/12/17 CMDR 
% 	* Fixed function header
%	* Fixed comments
%  2008/01/09
%	* Station is often a string containing alphanumerics, not always 
%	an integer. Treat it that way and parse it here.
%  2008/03/14 CMDR 
% 	* add cruiseid fieldname to the oxy structure
%

%Read in file 
% [m,d,y,hr,min,station,depth,samp_bot,thio,ox]= ...
%    textread(in_file,'%d/%d/%d %d:%d %d %f %d %f %f','headerlines',9);
%%%%%%%%% CMDR read and parse station as a [:alnum:] string
[m,d,y,hr,min,statstr,depth,samp_bot,thio,ox]= ...
   textread(in_file,'%d/%d/%d %d:%d %s %f %d %f %f','headerlines',9);
%% the station number is often like FS01, where we want an integer. So
%% we treat this simple case by throwing out all alpha characters
station=zeros(length(statstr),1);
for i=1:length(statstr),
	station(i)=str2num(regexprep(statstr{i},'[a-zA-Z]',''));
end;
%%%%%%%%%

dat = datenum(y,m,d,hr,min,0);
oxy = struct('cruiseid',[],'date',dat,'station',station,'depth',depth,...
    'sample_bottle',samp_bot,'thio_vol',thio,'oxygen',ox,'units','mmperl');
% ox is in units of micromole per liter
return;


