Home > ctdcal > old > btl2mat_ab.m

btl2mat_ab

PURPOSE ^

BTL2MAT Reads the SeaBird ASCII .BTL file format

SYNOPSIS ^

function [btl_struct]=btl2mat(btl_file);

DESCRIPTION ^

 BTL2MAT Reads the SeaBird ASCII .BTL file format

  Usage:   [lat,lon,gtime,data,names,sensors]=btl2mat(btl_file);

     Input:  btl_file = name of .BTL file  (e.g. 'cast002.btl')

     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: How lon,lat and time are written to the header of the .BTL
        file may vary with CTD setup.  For our .BTL files collected on 
        the 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 ws logged in local time
  or gmt or utc.  The assumption here is that the system startup time is logged 
  in local EST and the NMEA time is in GMT.  Watch out.

  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.

 BUGS:  1. 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.  
   2. Does not account for the fact that a quantity can be output in several different units.
   i.e. if conductivity is output in S/m and mS/cm then the data in the matlab structure for 
   conductivity is the last conductivity colummn encountered.

  CALLER: user

  DEPENDENCIES:

  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:

SOURCE CODE ^

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

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