Home > ctdcal > read_sbebl.m

read_sbebl

PURPOSE ^

read_sbebl - Reads the SeaBird ASCII .BL file format

SYNOPSIS ^

function [bl_struct]=read_sbebl(bl_file);

DESCRIPTION ^

 read_sbebl - Reads the SeaBird ASCII .BL file format

  Usage:   [bl_struct]=read_sbebl(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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function [bl_struct]=read_sbebl(bl_file);
0002 % read_sbebl - Reads the SeaBird ASCII .BL file format
0003 %
0004 %  Usage:   [bl_struct]=read_sbebl(bl_file);
0005 %
0006 %     Input:  bl_file = name of .BL file  (e.g. 'cast002.bl')
0007 %
0008 %     Output:bl_struct with fields:
0009 %         station = station number
0010 %    niskinnumber = niskin bottle number
0011 %       fireorder = fire order
0012 %
0013 %  CALLER: user
0014 %
0015 %  DEPENDENCIES:
0016 %
0017 %  AUTHOR: 18 Aug 2004 Carlos Fonseca (Carlos.Fonseca@noaa.gov)
0018 %    based on cnv2mat by Rich Signell.
0019 %  4-8-98  Rich Signell (rsignell@usgs.gov)
0020 %     incorporates ideas from code by Derek Fong & Peter Brickley
0021 %
0022 
0023 % TODO: Add calling syntax for no input args to return complete struct w/ nan fields.
0024 % TODO: How to handle the not-quite-empty bl files generated when no bottles were tripped?
0025 
0026 % Open the .bl file as read-only text
0027 %
0028 fid=fopen(bl_file,'rt');
0029 if fid < 0 
0030     disp(['WARNING: read_sbebl could not open ',bl_file]);
0031     bl=[];
0032     return
0033 end
0034 count=1;
0035 sta = [];
0036 niskin = [];
0037 fire = [];
0038 while ~feof(fid)
0039      str=fgetl(fid);
0040      % Check to see if this is a placeholder file with no contents.
0041      if isjunk(str)
0042         bl_struct.station = NaN;
0043         bl_struct.niskinnumber = NaN;
0044         bl_struct.fireorder = NaN;    
0045         fclose(fid);
0046         return
0047     end
0048          
0049     if (strncmp(str,'C:',2))
0050        is=findstr(str,'.');
0051        isub=is-3:1:is;
0052        sta=sscanf(str(isub),'%d',3);
0053     elseif(strncmp(str,'RESET',5))
0054         
0055     else
0056        is=findstr(str,',');
0057        isub=1:is(1)-1;
0058        fire(count,1)=sscanf(str(isub),'%d',3);
0059        isub=is(1)+1:is(2)-1;
0060        niskin(count,1)=sscanf(str(isub),'%d',3);
0061        count=count+1;
0062    end
0063 end
0064 if isempty(sta) | isempty(niskin) | isempty(fire)
0065     bl_struct.station = NaN;
0066     bl_struct.niskinnumber = NaN;
0067     bl_struct.fireorder = NaN;
0068     
0069     return
0070 else
0071     bl_struct.station = sta;
0072     bl_struct.niskinnumber = niskin;
0073     bl_struct.fireorder = fire;
0074 end
0075 return;
0076 
0077 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0078 function junk  = isjunk(str)
0079 % isjunk: test to see if the file contains only null characers.
0080 %
0081 % The sbe system seems to log a bl file even if no bottles were fired, if the
0082 % prelimnary steps include rossum or bottlesum.  This checks to see
0083 % if the current file is garbage.
0084 junk = false;
0085 cmp = char(zeros(size(str))); % string of N null characters.
0086 if strncmp(char(double(str)),cmp,length(cmp))
0087     junk = true;
0088 end
0089 
0090 return
0091

Generated on Fri 08-Oct-2004 11:57:17 by m2html © 2003