Home > ctdcal > read_sbebtl.m

read_sbebtl

PURPOSE ^

read_sbebtl - Reads the SeaBird ASCII .BTL file format

SYNOPSIS ^

function [btl_struct]=read_sbebtl(btl_file,varargin);

DESCRIPTION ^

 read_sbebtl - Reads the SeaBird ASCII .BTL file format

 Usage:   [btl_struct]=read_sbebtl(btl_file);

 Input:  
 btl_file = path/and/name of .BTL file  
        (e.g. 'cast002.btl', '/data/cruises/oc365/seabird/cast002.btl')
 time_offset = optional offset to be added to the System UpLoad time
                       if the data is logged in a time zone other than UTC.  If it is 
                         not passed in the calling syntax, it is assumed to be zero.
          
 Output:
 btl_struct with fields:
 lon = longitude in decimal degrees, West negative
 lat = latitude in decimal degrees, North positive
 gtime = Gregorian time vector in UTC
 data = matrix containing all the columns of data in the .BTL file
 names = cell of string matrix containing the names of the columns
 sensors = string matrix containing the names of the sensors

  NOTE: The format of lon,lat and time in the header of the .BTL
        file may vary with CTD setup.  
    For example,  .BTL files collected on 
        the R/V Oceanus, the lat, lon & time info look like this:

    * System UpLoad Time = Mar 30 1998 18:48:42
    * NMEA Latitude = 42 32.15 N
    * NMEA Longitude = 069 28.69 W
    * NMEA UTC (Time) = 23:50:36

  Modify the lat,lon and date string handling if your .BTL files are different.
  Also, There are several possibilities for the way time is stored.  Modify the 
  time and gtime calculations based on whether or not the data as logged in local time
  or gmt/utc. 

  I do not store anything about the standard deviations.  If you feel like tackling
  that I'd love to see what you come up with.

 BUG:
    1. There is a problem with the interpretation of time.  Currently the System UpLoad 
    date is used and the NMEA UTC time, if it exists.  If the NMEA time is greater than the time
     zone difference between system upload time and utc, then the date may be wrong.

  2. I have by no means encountered every possible variation in the way rossum
  stores data.  If something is wrong with the output check first that the variables
  stored in your btl file are all accounted for below.  I use only three cruises on 
  three different ships as templates for creating this program.  

  3. Does not account for the fact that a quantity can be output in several different units.
  i.e. if conductivity is output in both S/m and mS/cm then the data in the output  for 
  conductivity will be the last conductivity colummn encountered.:

  AUTHOR: 
 18 Oct 2001 Derrick Snowden (Derrick.Snowden@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 [btl_struct]=read_sbebtl(btl_file,varargin);
0002 % read_sbebtl - Reads the SeaBird ASCII .BTL file format
0003 %
0004 % Usage:   [btl_struct]=read_sbebtl(btl_file);
0005 %
0006 % Input:
0007 % btl_file = path/and/name of .BTL file
0008 %        (e.g. 'cast002.btl', '/data/cruises/oc365/seabird/cast002.btl')
0009 % time_offset = optional offset to be added to the System UpLoad time
0010 %                       if the data is logged in a time zone other than UTC.  If it is
0011 %                         not passed in the calling syntax, it is assumed to be zero.
0012 %
0013 % Output:
0014 % btl_struct with fields:
0015 % lon = longitude in decimal degrees, West negative
0016 % lat = latitude in decimal degrees, North positive
0017 % gtime = Gregorian time vector in UTC
0018 % data = matrix containing all the columns of data in the .BTL file
0019 % names = cell of string matrix containing the names of the columns
0020 % sensors = string matrix containing the names of the sensors
0021 %
0022 %  NOTE: The format of lon,lat and time in the header of the .BTL
0023 %        file may vary with CTD setup.
0024 %    For example,  .BTL files collected on
0025 %        the R/V Oceanus, the lat, lon & time info look like this:
0026 %
0027 %    * System UpLoad Time = Mar 30 1998 18:48:42
0028 %    * NMEA Latitude = 42 32.15 N
0029 %    * NMEA Longitude = 069 28.69 W
0030 %    * NMEA UTC (Time) = 23:50:36
0031 %
0032 %  Modify the lat,lon and date string handling if your .BTL files are different.
0033 %  Also, There are several possibilities for the way time is stored.  Modify the
0034 %  time and gtime calculations based on whether or not the data as logged in local time
0035 %  or gmt/utc.
0036 %
0037 %  I do not store anything about the standard deviations.  If you feel like tackling
0038 %  that I'd love to see what you come up with.
0039 %
0040 % BUG:
0041 %    1. There is a problem with the interpretation of time.  Currently the System UpLoad
0042 %    date is used and the NMEA UTC time, if it exists.  If the NMEA time is greater than the time
0043 %     zone difference between system upload time and utc, then the date may be wrong.
0044 %
0045 %  2. I have by no means encountered every possible variation in the way rossum
0046 %  stores data.  If something is wrong with the output check first that the variables
0047 %  stored in your btl file are all accounted for below.  I use only three cruises on
0048 %  three different ships as templates for creating this program.
0049 %
0050 %  3. Does not account for the fact that a quantity can be output in several different units.
0051 %  i.e. if conductivity is output in both S/m and mS/cm then the data in the output  for
0052 %  conductivity will be the last conductivity colummn encountered.:
0053 %
0054 %  AUTHOR:
0055 % 18 Oct 2001 Derrick Snowden (Derrick.Snowden@noaa.gov)
0056 %    based on cnv2mat by Rich Signell.
0057 %  4-8-98  Rich Signell (rsignell@usgs.gov)
0058 %     incorporates ideas from code by Derek Fong & Peter Brickley
0059 %
0060 
0061 % TODO: Handle units better.  The variables are renamed and the units information is lost.
0062 
0063 if nargin == 2
0064     time_offset = varargin{1};
0065 else
0066     time_offset = 0;
0067 end
0068 
0069 % Open the .btl file as read-only text
0070 %
0071 fid=fopen(btl_file,'rt');
0072 if fid < 0 
0073     disp(['WARNING: read_sbebtl could not open ',btl_file]);
0074     btl=[];
0075     return
0076 end
0077 %
0078 % Read the header.
0079 % Start reading header lines of .BTL file,
0080 % Stop at line that starts with '*END*'
0081 %
0082 % Pull out NMEA lat & lon along the way and look
0083 % at the '# name' fields to see how many variables we have.
0084 %
0085 str='*START*';
0086 
0087 % This may change in different configurations.  I suppose it depends on your
0088 % shipboard processing scripts/procedures.  look through your files for
0089 %something that denotes the end of the header but not the line containing the names ofthe columns.
0090 %while (~strncmp(str,'*END*',5));
0091 choose_nmea = 0;
0092 % We assume that each line of the header information is preceded by a * or a #
0093 while (strncmp(str,'#',1) | strncmp(str,'*',1));
0094     str=remove233(fgetl(fid));
0095     %-----------------------------------
0096     %
0097     %    Read the NMEA latitude string.  This may vary with CTD setup.
0098     %
0099     if (strncmp(str,'* NMEA Lat',10))
0100         choose_nmea = 1;
0101         is=findstr(str,'=');
0102         isub=is+1:length(str);
0103         dm=sscanf(str(isub),'%f',2);
0104         if(findstr(str(isub),'N'));
0105             lat=dm(1)+dm(2)/60;
0106         else  
0107             lat=-(dm(1)+dm(2)/60); 
0108         end
0109         %-------------------------------
0110         %
0111         %    Read the NMEA longitude string.  This may vary with CTD setup.
0112         %
0113     elseif (strncmp(str,'* NMEA Lon',10))
0114         choose_nmea = 1;
0115         is=findstr(str,'=');
0116         isub=is+1:length(str);
0117         dm=sscanf(str(isub),'%f',2);
0118         if(findstr(str(isub),'E'));
0119             lon=dm(1)+dm(2)/60;
0120         else  
0121             lon=-(dm(1)+dm(2)/60); 
0122         end
0123         %-----------------------------------
0124         %
0125         %    Read the NON NMEA latitude string.  This may vary with CTD setup.
0126         %
0127     elseif (strncmp(str,'** Lat',6))
0128         if choose_nmea == 0
0129             is=findstr(str,':');
0130             isub=is+1:length(str);
0131             dm=sscanf(str(isub),'%f',2);
0132             if(findstr(str(isub),'N'));
0133                 if length(dm) == 2
0134                     lat=dm(1)+dm(2)/60;
0135                 else
0136                     lat = dm(1); % assume they have used decimal degrees
0137                 end
0138             else 
0139                 if length(dm) == 2
0140                     lat=-(dm(1)+dm(2)/60);
0141                 else
0142                     lat = -(dm(1)); % assume they have used decimal degrees
0143                 end
0144                 
0145             end
0146         end
0147         %-------------------------------
0148         %
0149         %    Read the NON NMEA longitude string.  This may vary with CTD setup.
0150         %
0151     elseif (strncmp(str,'** Lon',6))
0152         if choose_nmea == 0
0153             is=findstr(str,':');
0154             isub=is+1:length(str);
0155             dm=sscanf(str(isub),'%f',2);
0156             if(findstr(str(isub),'E'));
0157                  if length(dm) == 2
0158                     lon =dm(1)+dm(2)/60;
0159                 else
0160                     lon = dm(1); % assume they have used decimal degrees
0161                 end
0162             else 
0163                 if length(dm) == 2
0164                     lon=-(dm(1)+dm(2)/60);
0165                 else
0166                     lon = -(dm(1)); % assume they have used decimal degrees
0167                 end
0168                 
0169            end
0170         end
0171         %------------------------
0172         %
0173         %    Read the 'System upload time' to get the date.
0174         %           This may vary with CTD setup.
0175         %
0176         %
0177     elseif (strncmp(str,'* System UpLoad',15))
0178         is=findstr(str,'=');
0179         %    pick apart date string and reassemble in DATEFORM type 0 form
0180         datstr=[str(is+6:is+7) '-' str(is+2:is+4) '-' str(is+9:is+12)];
0181         datstr=[datstr ' ' str(is+14:is+21)];
0182         %    convert datstr to Julian time, add time_offset if System time is logged in local time.
0183         n=datenum(datstr)+time_offset/24;
0184         gtime=datevec(n);
0185         %----------------------------
0186         %
0187         %    Read the NMEA TIME string.  This may vary with CTD setup.
0188         %
0189         %      replace the System upload time with the NMEA time
0190     elseif (strncmp(str,'* NMEA UTC',10))
0191         is=findstr(str,':');
0192         isub=is(1)-2:length(str);
0193         gtime([4:6])=sscanf(str(isub),'%2d:%2d:%2d');
0194         %------------------------------
0195         %
0196         %    Read the variable names & units into a cell array
0197         %
0198     elseif (strncmp(str,'# name',6))  
0199         var=sscanf(str(7:10),'%d',1);
0200         var=var+1;  % .BTL file counts from 0, Matlab counts from 1
0201         %      stuff variable names into cell array
0202         names{var}=str;
0203         %------------------------------
0204         %
0205         %    Read the sensor names into a cell array
0206         %
0207     elseif (strncmp(str,'# sensor',8))  
0208         sens=sscanf(str(10:11),'%d',1);
0209         sens=sens+1;  % .BTL file counts from 0, Matlab counts from 1
0210         %      stuff sensor names into cell array
0211         sensors{sens}=str;
0212         %
0213         %  pick up bad flag value
0214     elseif (strncmp(str,'# bad_flag',10))  
0215         isub=13:length(str);
0216         bad_flag=sscanf(str(isub),'%g',1);
0217     end
0218 end
0219 %==============================================
0220 %
0221 %  Done reading header.  Now read the data!
0222 %
0223 %nvars=var;  %number of variables
0224 
0225 %==============================================
0226 %
0227 %  Start off with the column headings. which should occupy two lines.
0228 %
0229 %col_headings = remove233(fgetl(fid));
0230 col_headings = str;
0231 column_names1 = strread(col_headings,'%s','delimiter',' ');
0232 col_headings = remove233(fgetl(fid));
0233 column_names2 = strread(col_headings,'%s','delimiter',' ');
0234 % warn the user if there is not a Nbf column
0235 Nbf_flag=strmatch('Nbf',column_names1)|strmatch('Nbf',column_names2);
0236 %
0237 %if ~strmatch('Nbf',column_names1) | ~strmatch('Nbf',column_names2)
0238     if isempty(Nbf_flag)
0239     msg = sprintf('\n');
0240     msg = [msg sprintf([' WARNING read_sbebtl: There is no Nbf column in file:  ',btl_file,' \n'])];
0241     msg = [msg sprintf(['  Rerun rossum and configure to print number of bottles fired.\n'])];
0242     msg = [msg sprintf(['  Trying to continue anyway...\n'])];
0243     msg = [msg sprintf('\n')];
0244     disp(msg);
0245 end
0246 %==============
0247 % Going to need to do some looping but I don't know exactly how yet.
0248 % Maybe mark the spot here then count lines and come back here?
0249 %
0250 count = 1;
0251 while ~feof(fid)
0252     str = remove233(fgetl(fid));
0253     avgcell{count} = strread(str,'%s' ,'delimiter',' ');
0254     % remove the string '(avg)'
0255     tmp = avgcell{count};
0256     tmp{end} = [];
0257     avgcell{count} = tmp;
0258     str = remove233(fgetl(fid));
0259     stdcell{count} = strread(str,'%s' ,'delimiter',' ');
0260     % remove the string '(avg)'
0261     tmp = stdcell{count};
0262     tmp{end} = [];
0263     stdcell{count} = tmp;
0264     count = count+1;
0265 end
0266 
0267 %  I'm going to exclude the std information for now DPS 19Oct2001
0268 % Assume that the date string will occupy 3 columns
0269 % Try to find the indices of the major known fields
0270 offset = 0;
0271 column_count = 0;
0272 for i = 1:length(column_names1)
0273     if strncmp('Bottle',column_names1{i},6); 
0274         column_count = column_count + 1;
0275         btl_pos_idx = column_count + offset; 
0276     end;
0277     if strncmp('Date',column_names1{i},4); 
0278         column_count = column_count + 1;
0279         date_idx = column_count; 
0280         offset = 2;
0281     end;
0282     if strncmp('Density00',column_names1{i},9); 
0283         column_count = column_count + 1;
0284         pri_pri_dens_idx = column_count + offset; 
0285     end;
0286     if strncmp('Density11',column_names1{i},9); 
0287         column_count = column_count + 1;
0288         sec_sec_dens_idx = column_count + offset; 
0289     end;
0290     if strncmp('Density01',column_names1{i},9); 
0291         column_count = column_count + 1;
0292         pri_sec_dens_idx = column_count + offset; 
0293     end;
0294     if strncmp('Density10',column_names1{i},9); 
0295         column_count = column_count + 1;
0296         sec_pri_dens_idx = column_count + offset; 
0297     end;
0298     if strncmp('Sigma-',column_names1{i},6); 
0299         %Parse the sigma into individual ascii representation
0300         %in order to compare non standard characters.
0301         % integer code 233 represents the e' in the column Skip it.
0302         sig = column_names1{i};
0303         if strncmp('00',sig(end-1:end),2)
0304             column_count = column_count + 1;
0305             pri_pri_sig_idx = column_count + offset;
0306         elseif strncmp('11',sig(end-1:end),2)
0307             column_count = column_count + 1;
0308             sec_sec_sig_idx = column_count + offset;
0309         elseif strncmp('10',sig(end-1:end),2)
0310             column_count = column_count + 1;
0311             sec_pri_sig_idx = column_count + offset;
0312         elseif strncmp('01',sig(end-1:end),2)
0313             column_count = column_count + 1;
0314             pri_sec_sig_idx = column_count + offset; 
0315         end
0316     end;
0317     
0318     if strncmp('pr',lower(column_names1{i}),2); 
0319         column_count = column_count + 1;
0320         pr_idx = column_count + offset; 
0321     end;
0322     if strncmp('T068',column_names1{i},4); 
0323         column_count = column_count + 1;
0324         pri_t68_idx = column_count + offset; 
0325     end;
0326     if strncmp('T168',column_names1{i},4); 
0327         column_count = column_count + 1;
0328         sec_t68_idx = column_count + offset; 
0329     end;
0330     if strncmp('T090',column_names1{i},4); 
0331         column_count = column_count + 1;
0332         pri_t90_idx = column_count + offset; 
0333     end;
0334     if strncmp('T190',column_names1{i},4); 
0335         column_count = column_count + 1;
0336         sec_t90_idx = column_count + offset; 
0337     end;
0338     if strncmp('Sal00',column_names1{i},5); 
0339         column_count = column_count + 1;
0340         pri_pri_sal_idx = column_count + offset; 
0341     end;
0342     if strncmp('Sal11',column_names1{i},5); 
0343         column_count = column_count + 1;
0344         sec_sec_sal_idx = column_count + offset; 
0345     end;
0346     if strncmp('Sal01',column_names1{i},5); 
0347         column_count = column_count + 1;
0348         pri_sec_sal_idx = column_count + offset; 
0349     end;
0350     if strncmp('Sal10',column_names1{i},5); 
0351         column_count = column_count + 1;
0352         sec_pri_sal_idx = column_count + offset; 
0353     end;
0354     if strncmp('C0S/m',column_names1{i},5); 
0355         column_count = column_count + 1;
0356         pri_con_idx = column_count + offset; 
0357     end;
0358     if strncmp('C1S/m',column_names1{i},5); 
0359         column_count = column_count + 1;
0360         sec_con_idx = column_count + offset; 
0361     end;
0362     if strncmp('C0mS/cm',column_names1{i},5); 
0363         column_count = column_count + 1;
0364         pri_con_idx = column_count + offset; 
0365     end;
0366     if strncmp('C1mS/cm',column_names1{i},5); 
0367         column_count = column_count + 1;
0368         sec_con_idx = column_count + offset; 
0369     end;
0370     if strncmp('OxC',column_names1{i},3); 
0371         column_count = column_count + 1;
0372         pri_oxc_idx = column_count + offset; 
0373     end;
0374     if strncmp('OxsC',column_names1{i},4); 
0375         column_count = column_count + 1;
0376         sec_oxc_idx = column_count + offset; 
0377     end;
0378     if strncmp('OxT',column_names1{i},3); 
0379         column_count = column_count + 1;
0380         pri_oxt_idx = column_count + offset; 
0381     end;
0382     if strncmp('OxsT',column_names1{i},4); 
0383         column_count = column_count + 1;
0384         sec_oxt_idx = column_count + offset; 
0385     end;
0386     if strncmp('OxMm/Kg',column_names1{i},7); 
0387         column_count = column_count + 1;
0388         pri_do2_mmkg_idx = column_count + offset; 
0389     end;
0390     if strncmp('OxsMm/Kg',column_names1{i},8); 
0391         column_count = column_count + 1;
0392         sec_do2_mmkg_idx = column_count + offset; 
0393     end;
0394     if strncmp('Sbeox0Mm/Kg',column_names1{i},11); 
0395         column_count = column_count + 1;
0396         pri_sbedo2_mmkg_idx = column_count + offset; 
0397     end;
0398     if strncmp('Sbeox1Mm/Kg',column_names1{i},11); 
0399         column_count = column_count + 1;
0400         sec_sbedo2_mmkg_idx = column_count + offset; 
0401     end;
0402     if strncmp('OxdOC/dT',column_names1{i},8); 
0403         column_count = column_count + 1;
0404         pri_odocdt_idx = column_count + offset; 
0405     end;
0406     if strncmp('OxsdOC/dT',column_names1{i},9); 
0407         column_count = column_count + 1;
0408         sec_odocdt_idx = column_count + offset; 
0409     end;
0410     if strncmp('Sbeox0ML/L',column_names1{i},10); 
0411         column_count = column_count + 1;
0412         pri_sbedo2_mll_idx = column_count + offset; 
0413     end;
0414     if strncmp('Sbeox1ML/L',column_names1{i},10); 
0415         column_count = column_count + 1;
0416         sec_sbedo2_mll_idx = column_count + offset; 
0417     end;
0418     if strncmp('OxML/L',column_names1{i},6); 
0419         column_count = column_count + 1;
0420         pri_do2_mll_idx = column_count + offset; 
0421     end;
0422     if strncmp('OxsML/L',column_names1{i},7); 
0423         column_count = column_count + 1;
0424         sec_do2_mll_idx = column_count + offset; 
0425     end;
0426     if strncmp('Nbf',column_names1{i},3); 
0427         column_count = column_count + 1;
0428         btl_fired_idx = column_count + offset; 
0429     end;
0430  % CAF
0431        if strncmp('Potemp090C',column_names1{i},10); 
0432         column_count = column_count + 1;
0433         pot_temp_pri_idx = column_count + offset; 
0434        end;
0435        if strncmp('Potemp190C',column_names1{i},10); 
0436         column_count = column_count + 1;
0437         pot_temp_sec_idx = column_count + offset; 
0438        end;
0439        if strncmp('Sbeox0PS',column_names1{i},8); 
0440         column_count = column_count + 1;
0441         sbeox_pct_sat_pri_idx = column_count + offset; 
0442        end;
0443        if strncmp('Sbeox1PS',column_names1{i},8); 
0444         column_count = column_count + 1;
0445         sbeox_pct_sat_sec_idx = column_count + offset; 
0446        end;
0447        if strncmp('Sbeox0dOC/dT',column_names1{i},12); 
0448         column_count = column_count + 1;
0449         pri_sbedOC_dt_idx = column_count + offset; 
0450        end; 
0451        if strncmp('Sbeox1dOC/dT',column_names1{i},12); 
0452         column_count = column_count + 1;
0453         sec_sbedOC_dt_idx = column_count + offset; 
0454        end;
0455        if strncmp('Sbeox0V',column_names1{i},7); 
0456         column_count = column_count + 1;
0457         pri_sbeox_volt_idx = column_count + offset; 
0458        end;
0459        if strncmp('Sbeox1V',column_names1{i},7); 
0460         column_count = column_count + 1;
0461         sec_sbeox_volt_idx = column_count + offset; 
0462        end;
0463        if strncmp('Scan',column_names1{i},4); 
0464         column_count = column_count + 1;
0465         scan_idx = column_count + offset; 
0466        end;
0467        if strncmp('OxPS',column_names1{i},4); 
0468         column_count = column_count + 1;
0469         pct_sat_idx = column_count + offset; 
0470        end;
0471         if strncmp('OxsPS',column_names1{i},4); 
0472         column_count = column_count + 1;
0473         pct_sat_sec_idx = column_count + offset; 
0474        end;
0475        %CAF
0476     % repeat the above construct as you discover more parameters which rossum outputs.
0477 end
0478 column_count2 = 0;
0479 for i = 1:length(column_names2);
0480     if strncmp('Position',column_names2{i},8)
0481         %  This is redundant compared with Bottle above
0482     elseif strncmp('Time',column_names2{i},4)
0483         column_count2 = column_count2 + 1;
0484         time_idx = column_count2;
0485     end
0486 end
0487 
0488 % Begin to assemble the output matrix/structure.
0489 num_rows = length(avgcell);
0490 if ~isempty(date_idx)
0491     % date is parsed as a 3 column vector but we will combine into one.
0492     offset = 2;
0493 else
0494     offset = 0;
0495 end
0496 data = NaN.* ones(num_rows,(column_count-offset));
0497 for i = 1:num_rows
0498     if exist('btl_pos_idx','var') == 1
0499         data(i,btl_pos_idx) = str2num(avgcell{i}{btl_pos_idx});
0500         names{btl_pos_idx} = 'bottle_ros_position';
0501     end
0502     if exist('date_idx','var') == 1
0503         mnth = avgcell{i}{date_idx};
0504         day = avgcell{i}{date_idx + 1};
0505         yr = avgcell{i}{date_idx+2};
0506         if exist('time_idx','var') == 1
0507             timestr = stdcell{i}{time_idx};
0508             % dateform=0 == 'dd-mmm-yyyy HH:MM:SS'
0509             datestr = sprintf('%s',[day,'-',mnth,'-',yr,' ',timestr]);
0510         else
0511             datestr = sprintf('%s',[day,'-',mnth,'-',yr]);
0512         end
0513         data(i,date_idx) = datenum(datestr);
0514         names{date_idx} = 'date';
0515     end;
0516     if exist('pri_pri_dens_idx','var') == 1
0517         data(i,pri_pri_dens_idx) = str2num(avgcell{i}{pri_pri_dens_idx});
0518         names{pri_pri_dens_idx} = 'density_pri_pri';
0519     end;
0520     if exist('sec_sec_dens_idx','var') == 1
0521         data(i,sec_sec_dens_idx) = str2num(avgcell{i}{sec_sec_dens_idx});
0522         names{sec_sec_dens_idx} = 'density_sec_sec';
0523     end;
0524     if exist('pri_sec_dens_idx','var') == 1
0525         data(i,pri_sec_dens_idx) = str2num(avgcell{i}{pri_sec_dens_idx});
0526         names{pri_sec_dens_idx} = 'density_pri_sec';
0527     end;
0528     if exist('sec_pri_dens_idx','var') == 1
0529         data(i,sec_pri_dens_idx) = str2num(avgcell{i}{sec_pri_dens_idx});
0530         names{sec_pri_dens_idx} = 'density_sec_pri';
0531     end;
0532     if exist('pri_pri_sig_idx','var') == 1
0533         data(i,pri_pri_sig_idx) = str2num(avgcell{i}{pri_pri_sig_idx});
0534         names{pri_pri_sig_idx} = 'sigma_pri_pri';
0535     end;
0536     if exist('sec_sec_sig_idx','var') == 1
0537         data(i,sec_sec_sig_idx) = str2num(avgcell{i}{sec_sec_sig_idx});
0538         names{sec_sec_sig_idx} = 'sigma_sec_sec';
0539     end;
0540     if exist('pri_sec_sig_idx','var') == 1
0541         data(i,pri_sec_sig_idx) = str2num(avgcell{i}{pri_sec_sig_idx});
0542         names{pri_sec_sig_idx} = 'sigma_pri_sec';
0543     end;
0544     if exist('sec_pri_sig_idx','var') == 1
0545         data(i,sec_pri_sig_idx) = str2num(avgcell{i}{sec_pri_sig_idx});
0546         names{sec_pri_sig_idx} = 'sigma_sec_pri';
0547     end;
0548     if exist('pr_idx','var') == 1
0549         data(i,pr_idx) = str2num(avgcell{i}{pr_idx});
0550         names{pr_idx}='pressure';
0551     end;
0552     if exist('pri_t68_idx','var') == 1
0553         data(i,pri_t68_idx) = str2num(avgcell{i}{pri_t68_idx});
0554         names{pri_t68_idx} = 't68_pri';
0555     end;
0556     if exist('sec_t68_idx','var') == 1
0557         data(i,sec_t68_idx) = str2num(avgcell{i}{sec_t68_idx});
0558         names{sec_t68_idx} = 't68_sec';
0559     end;
0560     if exist('pri_t90_idx','var') == 1 
0561         data(i,pri_t90_idx) = str2num(avgcell{i}{pri_t90_idx});
0562         names{pri_t90_idx} = 't90_pri';
0563     end;
0564     if exist('sec_t90_idx','var') == 1
0565         data(i,sec_t90_idx) = str2num(avgcell{i}{sec_t90_idx});
0566         names{sec_t90_idx} = 't90_sec' ;
0567     end;
0568     if exist('pri_pri_sal_idx','var') == 1
0569         data(i,pri_pri_sal_idx) = str2num(avgcell{i}{pri_pri_sal_idx});
0570         names{pri_pri_sal_idx} = 'sal_pri_pri';
0571     end;
0572     if exist('sec_sec_sal_idx','var') == 1
0573         data(i,sec_sec_sal_idx) = str2num(avgcell{i}{sec_sec_sal_idx});
0574         names{sec_sec_sal_idx} = 'sal_sec_sec';
0575     end;
0576     if exist('pri_sec_sal_idx','var') == 1 
0577         data(i,pri_sec_sal_idx) = str2num(avgcell{i}{pri_sec_sal_idx});
0578         names{pri_sec_sal_idx} = 'sal_pri_sec';
0579     end;
0580     if exist('sec_pri_sal_idx','var') == 1
0581         data(i,sec_pri_sal_idx) = str2num(avgcell{i}{sec_pri_sal_idx});
0582         names{sec_pri_sal_idx} = 'sal_sec_pri';        
0583     end;
0584     if exist('pri_con_idx','var') == 1
0585         data(i,pri_con_idx) = str2num(avgcell{i}{pri_con_idx});
0586         names{pri_con_idx} = 'con_pri';                
0587     end;
0588     if exist('sec_con_idx','var') == 1
0589         data(i,sec_con_idx) = str2num(avgcell{i}{sec_con_idx});
0590         names{sec_con_idx} = 'con_sec';                
0591     end;
0592     if exist('pri_oxc_idx','var') == 1 
0593         data(i,pri_oxc_idx) = str2num(avgcell{i}{pri_oxc_idx});
0594         names{pri_oxc_idx} = 'oxc_pri';                
0595     end;
0596     if exist('sec_oxc_idx','var') == 1
0597         data(i,sec_oxc_idx) = str2num(avgcell{i}{sec_oxc_idx});
0598         names{sec_oxc_idx} = 'oxc_sec';                
0599     end;
0600     if exist('pri_oxt_idx','var') == 1
0601         data(i,pri_oxt_idx) = str2num(avgcell{i}{pri_oxt_idx});
0602         names{pri_oxt_idx} = 'oxt_pri';                
0603     end;
0604     if exist('sec_oxt_idx','var') == 1
0605         data(i,sec_oxt_idx) = str2num(avgcell{i}{sec_oxt_idx});
0606         names{sec_oxt_idx} = 'oxt_sec';                
0607     end;
0608     if exist('pri_do2_mmkg_idx','var') == 1 
0609         data(i,pri_do2_mmkg_idx) = str2num(avgcell{i}{pri_do2_mmkg_idx});
0610         names{pri_do2_mmkg_idx} = 'do2_pri';                
0611     end;
0612     if exist('sec_do2_mmkg_idx','var') == 1 
0613         data(i,sec_do2_mmkg_idx) = str2num(avgcell{i}{sec_do2_mmkg_idx});
0614         names{sec_do2_mmkg_idx} = 'do2_sec';                
0615     end;
0616     if exist('pri_do2_mll_idx','var') == 1
0617         data(i,pri_do2_mll_idx) = str2num(avgcell{i}{pri_do2_mll_idx});
0618         names{pri_do2_mll_idx} = 'do2_pri';                       
0619     end;
0620     if exist('sec_do2_mll_idx','var') == 1
0621         data(i,sec_do2_mll_idx) = str2num(avgcell{i}{sec_do2_mll_idx});
0622         names{sec_do2_mll_idx} = 'do2_sec';                               
0623     end;
0624     if exist('btl_fired_idx','var') == 1
0625         data(i,btl_fired_idx) = str2num(avgcell{i}{btl_fired_idx});
0626         names{btl_fired_idx} = 'bottle_fired_count';                                       
0627     end;
0628     if exist('scan_idx','var') == 1
0629         data(i,scan_idx) = str2num(avgcell{i}{scan_idx});
0630         names{scan_idx} = 'scan';                                       
0631     end;
0632     if exist('pri_odocdt_idx','var') == 1
0633         data(i,pri_odocdt_idx) = str2num(avgcell{i}{pri_odocdt_idx});
0634         names{pri_odocdt_idx} = 'odocdt_pri';                                       
0635     end;
0636     if exist('sec_odocdt_idx','var') == 1
0637         data(i,sec_odocdt_idx) = str2num(avgcell{i}{sec_odocdt_idx});
0638         names{sec_odocdt_idx} = 'odocdt_sec';                                       
0639     end;
0640     if exist('pri_sbedo2_mll_idx','var') == 1
0641         data(i,pri_sbedo2_mll_idx) = str2num(avgcell{i}{pri_sbedo2_mll_idx});
0642         names{pri_sbedo2_mll_idx} = 'sbedo2_mll_pri';                       
0643     end;
0644     if exist('sec_sbedo2_mll_idx','var') == 1
0645         data(i,sec_sbedo2_mll_idx) = str2num(avgcell{i}{sec_sbedo2_mll_idx});
0646         names{sec_sbedo2_mll_idx} = 'sbedo2_mll_sec';                               
0647     end;
0648     if exist('pri_sbedo2_mmkg_idx','var') == 1
0649         data(i,pri_sbedo2_mmkg_idx) = str2num(avgcell{i}{pri_sbedo2_mmkg_idx});
0650         names{pri_sbedo2_mmkg_idx} = 'sbedo2_mmkg_pri';                       
0651     end;
0652     if exist('sec_sbedo2_mmkg_idx','var') == 1
0653         data(i,sec_sbedo2_mmkg_idx) = str2num(avgcell{i}{sec_sbedo2_mmkg_idx});
0654         names{sec_sbedo2_mmkg_idx} = 'sbedo2_mmkg_sec';                               
0655     end;
0656    %CAF
0657    if exist('pot_temp_pri_idx','var') == 1
0658         data(i,pot_temp_pri_idx) = str2num(avgcell{i}{pot_temp_pri_idx});
0659         names{pot_temp_pri_idx} = 'pot_temp_pri';                               
0660     end;
0661     if exist('pot_temp_sec_idx','var') == 1
0662         data(i,pot_temp_sec_idx) = str2num(avgcell{i}{pot_temp_sec_idx});
0663         names{pot_temp_sec_idx} = 'pot_temp_sec';                               
0664     end;
0665     if exist('sbeox_pct_sat_pri_idx','var') == 1
0666         data(i,sbeox_pct_sat_pri_idx) = str2num(avgcell{i}{sbeox_pct_sat_pri_idx});
0667         names{sbeox_pct_sat_pri_idx} = 'sbeox_pct_sat_pri';                               
0668     end;
0669     if exist('sbeox_pct_sat_sec_idx','var') == 1
0670         data(i,sbeox_pct_sat_sec_idx) = str2num(avgcell{i}{sbeox_pct_sat_sec_idx});
0671         names{sbeox_pct_sat_sec_idx} = 'sbeox_pct_sat_sec';                               
0672     end;
0673     if exist('pri_sbedOC_dt_idx','var') == 1
0674         data(i,pri_sbedOC_dt_idx) = str2num(avgcell{i}{pri_sbedOC_dt_idx});
0675         names{pri_sbedOC_dt_idx} = 'sbeox_dOCdt_pri';                               
0676     end;
0677     if exist('sec_sbedOC_dt_idx','var') == 1
0678         data(i,sec_sbedOC_dt_idx) = str2num(avgcell{i}{sec_sbedOC_dt_idx});
0679         names{sec_sbedOC_dt_idx} = 'sbeox_dOCdt_sec';                               
0680     end;
0681     if exist('pri_sbeox_volt_idx','var') == 1
0682         data(i,pri_sbeox_volt_idx) = str2num(avgcell{i}{pri_sbeox_volt_idx});
0683         names{pri_sbeox_volt_idx} = 'sbeox_volt_pri';                               
0684     end;
0685     if exist('sec_sbeox_volt_idx','var') == 1
0686         data(i,sec_sbeox_volt_idx) = str2num(avgcell{i}{sec_sbeox_volt_idx});
0687         names{sec_sbeox_volt_idx} = 'sbeox_volt_sec';                               
0688     end;
0689      if exist('pct_sat_idx','var') == 1
0690         data(i,pct_sat_idx) = str2num(avgcell{i}{pct_sat_idx});
0691         names{pct_sat_idx} = 'pct_sat';                               
0692     end;
0693      if exist('pct_sat_sec_idx','var') == 1
0694         data(i,pct_sat_sec_idx) = str2num(avgcell{i}{pct_sat_sec_idx});
0695         names{pct_sat_sec_idx} = 'pct_sat_sec';                               
0696     end;
0697     %CAF
0698   % repeat the above construct as you discover more parameters which rossum outputs.
0699 end
0700 
0701 % Remove the empty cells from the names cell array
0702 % and the data matrix if the date_idx exists.
0703 offset = 0;
0704 if exist('date_idx','var') == 1
0705     data(:,[date_idx+1:date_idx+2]) = [];
0706     count = 1;
0707     for i = 1:(length(names))
0708         if ~isempty(names{i})
0709             tmp{count} = names{i};
0710             count = count + 1;
0711         end
0712     end
0713     names = tmp;
0714 end
0715     
0716 
0717 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0718 %
0719 % Flag bad values with nan
0720 %
0721 if exist('bad_flag','var') == 1
0722     ind=find(data==bad_flag);
0723     data(ind)=data(ind)*nan;
0724 end
0725 
0726 
0727 btl_struct.lat = lat;
0728 btl_struct.lon = lon;
0729 btl_struct.gtime = gtime;
0730 btl_struct.sensors = char(sensors');
0731 % remove the spaces in the names cell
0732 for i = 1:length(names)
0733     str = names{i};
0734     idxspc = isspace(str);
0735     str(idxspc) = [];
0736     names{i} = str;
0737 end
0738 btl_struct.names = names;
0739 btl_struct.data = data;
0740 disp([btl_file,' loaded'])
0741 
0742 return % End of read_sbebtl
0743 
0744 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0745 function outStr = remove233(inStr);
0746 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0747 %
0748 % remove the ascii character 233 and replace with a space.
0749 %
0750 strDbl = double(inStr);
0751 idxStr = find(strDbl==233);
0752 if ~isempty(idxStr)
0753     strDbl(idxStr) = 32;
0754     outStr = char(strDbl);
0755 else
0756     outStr = inStr;
0757 end
0758 
0759 return
0760

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