function [bl_struct]=bl2mat(bl_file);
% BTL2MAT Reads the SeaBird ASCII .BL file format
%
%  Usage:   [bl_struct]=bl2mat(bl_file);
%
%     Input:  bl_file = name of .BL file  (e.g. 'cast002.bl')
%
%     Output:bl_struct with fields:
%         station = station number
%    niskinnumber = niskin bottle number      
%       fireorder = fire order
%
%  CALLER: user
%
%  DEPENDENCIES:
%
%  AUTHOR: 18 Aug 2004 Carlos Fonseca (Carlos.Fonseca@noaa.gov)
%    based on cnv2mat by Rich Signell.  
%  4-8-98  Rich Signell (rsignell@usgs.gov)  
%     incorporates ideas from code by Derek Fong & Peter Brickley
%

% Open the .bl file as read-only text
%
fid=fopen(bl_file,'rt');
if fid < 0 
    disp(['WARNING: bl2mat could not open ',bl_file]);
    bl=[];
    return
end
count=1;
while ~feof(fid)
     str=fgetl(fid);
    if (strncmp(str,'C:',2))
       is=findstr(str,'.');
       isub=is-3:1:is;
        sta=sscanf(str(isub),'%d',3);
    elseif(strncmp(str,'RESET',5))
    else
       is=findstr(str,',');
       isub=1:is(1)-1;
       fire(count,1)=sscanf(str(isub),'%d',3);
       isub=is(1)+1:is(2)-1;
       niskin(count,1)=sscanf(str(isub),'%d',3);
       count=count+1;
   end
end
bl_struct.station = sta;
bl_struct.niskinnumber = niskin;
bl_struct.fireorder = fire;
return;