Home > ctdcal > load_bl.m

load_bl

PURPOSE ^

load_bl: Read and save the SeaBird ASCII .BL file format

SYNOPSIS ^

function varargout = load_bl(cruiseid)

DESCRIPTION ^

 load_bl: Read  and save the SeaBird ASCII .BL file format

 CTD Calibration toolbox.

 INPUT: cruiseid: Cruise identification name. 

 USAGE: 
 load_bl(cruiseid): read the SeaBird ASCII .BL files and save in
                     the database file of the cruise.This file will
                     be named "cruiseid"_db.mat 
                     
 bl=load_bl(cruiseid) : Additionally, it will save the  .BL files 
                          in the workspace

 AUTHORS:Carlos Fonseca 
         UM/CIMAS
         Derrick Snowden
         NOAA/AOML/PhOD
         Tue May 11 11:23:37 EDT 2004

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function varargout  = load_bl(cruiseid)
0002 % load_bl: Read  and save the SeaBird ASCII .BL file format
0003 %
0004 % CTD Calibration toolbox.
0005 %
0006 % INPUT: cruiseid: Cruise identification name.
0007 %
0008 % USAGE:
0009 % load_bl(cruiseid): read the SeaBird ASCII .BL files and save in
0010 %                     the database file of the cruise.This file will
0011 %                     be named "cruiseid"_db.mat
0012 %
0013 % bl=load_bl(cruiseid) : Additionally, it will save the  .BL files
0014 %                          in the workspace
0015 %
0016 % AUTHORS:Carlos Fonseca
0017 %         UM/CIMAS
0018 %         Derrick Snowden
0019 %         NOAA/AOML/PhOD
0020 %         Tue May 11 11:23:37 EDT 2004
0021 
0022 % CHANGELOG:
0023 %   23-Jul-2004, Version 1.0
0024 %        * Initial version.
0025 %   01-Oct-2004  Derrick Snowden
0026 %        * load_bl (load_bl): Removed dependence on directory structure in favor of
0027 %             register_cruise
0028 %        * load_bl (load_bl): Fixed some logic errors that missed empty directories.
0029 %            e.g. size(dir()) doesn't work.
0030 
0031 
0032 % Check for correct number of inputs.
0033 error(nargchk(1,1,nargin))
0034 
0035 % Retrieve the necessary preferences for this cruise
0036 group = group_name(cruiseid);
0037 
0038 % bl_dir is the calibration data directory
0039 if ispref(group,'cal_bl_dir')
0040     bl_dir=getpref(group,'cal_bl_dir');
0041 else
0042     error(['The cal_bl_dir preference was not set for cruise: ' cruiseid '.  Run register_cruise.m']);
0043 end
0044 
0045 % cruise_dir is the calibration data directory
0046 if ispref(group,'cal_data_dir')
0047     cruise_dir=getpref(group,'cal_data_dir');
0048 else
0049     error(['The cal_data_dir preference was not set for cruise: ' cruiseid '.  Run register_cruise.m']);
0050 end
0051 
0052 % Check that the bl files are in the given directory.
0053 % TODO: Make use of the upper case/lower case preference.
0054 lc_bl = dir(fullfile(bl_dir,'*.bl')); 
0055 uc_bl = dir(fullfile(bl_dir,'*.BL'));
0056 
0057 if isempty(lc_bl) & isempty(uc_bl)
0058     error(['No *.bl or *.BL files were found in ', bl_dir]);
0059 end
0060 if isequal(lc_bl,uc_bl)
0061     bl_names = lc_bl;
0062 else
0063     if ~isempty(lc_bl) & ~isempty(uc_bl)
0064         error(['The *.bl files in ', bl_dir...
0065         ,' are named in both upper and lower case.  Pick one and rename before running ',mfilename]);
0066     elseif isempty(lc_bl) & ~isempty(uc_bl)
0067         bl_names = uc_bl;
0068     elseif ~isempty(lc_bl) & isempty(uc_bl)
0069         bl_names = lc_bl;
0070     else
0071         error(['No *.bl or *.BL files were found in ', bl_dir]);
0072     end
0073 end
0074 
0075 % The files are there, retrieve the data.
0076 for i=1:length(bl_names)
0077     tmp = read_sbebl(fullfile(bl_dir,bl_names(i).name));
0078     if ~isempty(tmp)
0079         bl(i)=tmp;
0080     else
0081         %bl(i)=
0082     end
0083 end
0084 
0085 % Should never get here but make sure.
0086 if ~exist('bl','var') | isempty(bl)
0087     error('The bl output structure does not exist or is empty.')
0088 end
0089 
0090 % Open the output file
0091 db_file = fullfile(cruise_dir,[cruiseid '_db.mat']);
0092 if exist(db_file)==2
0093     save(db_file,'bl','-append');
0094 else
0095     save(db_file,'bl');
0096 end
0097 if nargout==0
0098     assignin('caller','ans',bl);
0099     return
0100 else
0101     varargout{1}=bl;
0102     return
0103 end
0104 %
0105 
0106

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