Home > ctdcal > make_oxy_sumfile_shallow.m

make_oxy_sumfile_shallow

PURPOSE ^

MAKE_OXY_SUMFILE_SHALLOW - Makes oxygen bottle/ctd comparison summary file.

SYNOPSIS ^

function oxy_cal = make_oxy_sumfile_shallow(cruiseid)

DESCRIPTION ^

 MAKE_OXY_SUMFILE_SHALLOW -  Makes oxygen bottle/ctd comparison summary file.

 CTD Calibration toolbox.

 USAGE:
  [oxy_struct] = make_oxy_sumfile(cruiseid);

 INPUT: cruiseid: Cruise identification name. 
   
 OUTPUT:  Automatically writes two files  
          basically with the same fields in *.mat and *.asc formats
          oxy_struct: contains a structure with the same information
               contained in the *.mat file

 DESCRIPTION:  This function tries to merge the *.btl files from the Seabird 
  and the *.oxy files from the AOML titration system
  and create a summary file containing coincident measurements from both
  systems.  The data for a whole cruise is processed at once so if you want
  less data you'll have to subset afterwards.

 BUGS:  1. Not really a bug but it's based on the AOML *.oxy files.  These files
  can vary slightly in terms of what each field means, based on operator preference.
  The results of read_oxy contain a field called depth which is usu. either
  the niskin bottle position on the rosette or the firing order.  Position is
  preferrable if you think about it at the beginning of the cruise.
 

 AUTHORS:Carlos Fonseca 
         UM/CIMAS
         Derrick Snowden
         NOAA/AOML/PhOD
         Tue May 11 11:23:37 EDT 2004
 CHANGELOG: 
   23-Jul-2004, Version 1.0
        * Initial version.

 DEPENDENCIES: SW package.
               load_oxy
               load_btl
               load_bl
               load_cnv

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function oxy_cal = make_oxy_sumfile_shallow(cruiseid)
0002 % MAKE_OXY_SUMFILE_SHALLOW -  Makes oxygen bottle/ctd comparison summary file.
0003 %
0004 % CTD Calibration toolbox.
0005 %
0006 % USAGE:
0007 %  [oxy_struct] = make_oxy_sumfile(cruiseid);
0008 %
0009 % INPUT: cruiseid: Cruise identification name.
0010 %
0011 % OUTPUT:  Automatically writes two files
0012 %          basically with the same fields in *.mat and *.asc formats
0013 %          oxy_struct: contains a structure with the same information
0014 %               contained in the *.mat file
0015 %
0016 % DESCRIPTION:  This function tries to merge the *.btl files from the Seabird
0017 %  and the *.oxy files from the AOML titration system
0018 %  and create a summary file containing coincident measurements from both
0019 %  systems.  The data for a whole cruise is processed at once so if you want
0020 %  less data you'll have to subset afterwards.
0021 %
0022 % BUGS:  1. Not really a bug but it's based on the AOML *.oxy files.  These files
0023 %  can vary slightly in terms of what each field means, based on operator preference.
0024 %  The results of read_oxy contain a field called depth which is usu. either
0025 %  the niskin bottle position on the rosette or the firing order.  Position is
0026 %  preferrable if you think about it at the beginning of the cruise.
0027 %
0028 %
0029 % AUTHORS:Carlos Fonseca
0030 %         UM/CIMAS
0031 %         Derrick Snowden
0032 %         NOAA/AOML/PhOD
0033 %         Tue May 11 11:23:37 EDT 2004
0034 % CHANGELOG:
0035 %   23-Jul-2004, Version 1.0
0036 %        * Initial version.
0037 %
0038 % DEPENDENCIES: SW package.
0039 %               load_oxy
0040 %               load_btl
0041 %               load_bl
0042 %               load_cnv
0043 %
0044 %
0045 flag_message1=0;
0046 flag_message2=0;
0047 flag_conv1=0;
0048 flag_conv2=0;
0049 % Retrieve the necessary preferences for this cruise
0050 group = group_name(cruiseid);
0051 
0052 % cruise_dir is the main calibration data directory
0053 if ispref(group,'cal_data_dir')
0054     cruise_dir=getpref(group,'cal_data_dir');
0055 else
0056     error(['The cal_data_dir preference was not set for cruise: ' cruiseid '.  Run register_cruise.m']);
0057 end
0058 
0059 % Load data from the cruise database
0060 db_file = fullfile(cruise_dir,[cruiseid '_db.mat']);
0061 if exist(db_file)==2
0062     load(db_file);
0063 else
0064     error(['The cruise data base file was not found on the path.  ' db_file]);
0065 end
0066 
0067 % Check for the necessary variables in the cruise database.
0068 n=who('btl');
0069 if isempty(n)==1
0070     error(['btl variable not found in the cruise database. Run load_btl.m ']);
0071     return;
0072 end
0073 n=who('bl');
0074 if isempty(n)==1
0075     error(['bl variable not found in the cruise database. Run load_bl.m ']);
0076     return;
0077 end
0078 n=who('oxy');
0079 if isempty(n)==1
0080     error(['oxy variable not found in the cruise database. Run load_oxy.m ']);
0081     return;
0082 end
0083 %
0084 oxy_cal.cruiseid=cruiseid;
0085 %information from .oxy files
0086     stations= unique(vertcat(oxy.station));
0087     oxy_cal.stnnbr=vertcat(oxy.station);
0088     oxy_cal.castnbr=vertcat(oxy.station);
0089     oxy_cal.sampnbr=vertcat(oxy.sample_bottle);
0090     oxy_cal.btlnbr=vertcat(oxy.depth);
0091     oxy_cal.niskinbtlpos=vertcat(oxy.depth);    
0092 % extracting the fire order from the .bl file
0093     for i=1:1:length(oxy_cal.btlnbr)
0094      oxy_cal.stnnbr(i);
0095      if (oxy_cal.stnnbr(i)==0)
0096      oxy_cal.fireorder(i,1)=NaN;
0097      else
0098      fire_index=find(bl(oxy_cal.stnnbr(i)).niskinnumber==oxy_cal.btlnbr(i));   
0099      oxy_cal.fireorder(i,1)=bl(oxy_cal.stnnbr(i)).fireorder(fire_index);
0100      end
0101     end
0102  % converting the oxygen values to ml/l
0103     oxy_cal.btloxy=vertcat(oxy.oxygen)*0.02239;  
0104   
0105  % keeping only the valid data
0106     jj_nan=find(isnan(oxy_cal.fireorder)==0);
0107     oxy_cal.fireorder=oxy_cal.fireorder(jj_nan);
0108     oxy_cal.stnnbr=oxy_cal.stnnbr(jj_nan);
0109     oxy_cal.castnbr=oxy_cal.castnbr(jj_nan);
0110     oxy_cal.sampnbr=oxy_cal.sampnbr(jj_nan);
0111     oxy_cal.btlnbr=oxy_cal.btlnbr(jj_nan);
0112     oxy_cal.niskinbtlpos=oxy_cal.niskinbtlpos(jj_nan);
0113     oxy_cal.btloxy=oxy_cal.btloxy(jj_nan);
0114   %
0115 % information from .btl files
0116  disp('**************************************');
0117  disp('Extracting information from .btl files');
0118  disp('**************************************');
0119    for i=1:length(oxy_cal.btloxy)
0120       sta_idx=oxy_cal.stnnbr(i);
0121       fire_idx=oxy_cal.fireorder(i);
0122       % extracting the indexes for the .btl files;
0123       for j=1:length(btl(sta_idx).names);
0124        if strncmp(btl(sta_idx).names(j),'pressure',8);
0125        pr_idx=j;
0126        end
0127        if strncmp(btl(sta_idx).names(j),'con_pri',7);
0128        ctd_c1_idx=j;
0129        end
0130        if strncmp(btl(sta_idx).names(j),'con_sec',7);
0131        ctd_c2_idx=j;
0132        end
0133        if strncmp(btl(sta_idx).names(j),'sbedo2_mll_pri',14);
0134        ctd_oxy1_idx=j;
0135        end
0136        if strncmp(btl(sta_idx).names(j),'sbedo2_mll_sec',14);
0137        ctd_oxy2_idx=j;
0138        end
0139        if strncmp(btl(sta_idx).names(j),'sbeox_volt_pri',14);
0140        ctd_oxv1_idx=j;
0141        end
0142        if strncmp(btl(sta_idx).names(j),'sbeox_volt_sec',14);
0143        ctd_oxv2_idx=j;
0144        end
0145        if strncmp(btl(sta_idx).names(j),'sbeox_dOCdt_pri',15);
0146        ctd_dvdt1_idx=j;
0147        end
0148        if strncmp(btl(sta_idx).names(j),'sbeox_dOCdt_sec',15);
0149        ctd_dvdt2_idx=j;
0150        end
0151        if strncmp(btl(sta_idx).names(j),'t68_pri',7);
0152        ctd_t1_idx=j;
0153        end
0154        if strncmp(btl(sta_idx).names(j),'t68_sec',7);
0155        ctd_t2_idx=j;
0156        end
0157        if strncmp(btl(sta_idx).names(j),'t90_pri',7);
0158        ctd_t1_idx=j;
0159        flag_conv1=1;
0160         if flag_message1==0
0161         disp('Primary temperatures are given in T90.')
0162         disp('This program will convert to T68 to make the necessary calculations')
0163         flag_message1=1;
0164         end
0165        end
0166        if strncmp(btl(sta_idx).names(j),'t90_sec',7);
0167        ctd_t2_idx=j;
0168        flag_conv2=1;
0169         if flag_message2==0
0170         disp('Secondary temperatures are given in T90.')
0171         disp('This program will convert to T68 to make the necessary calculations')
0172         flag_message2=1;
0173         end  
0174        end
0175       end
0176       oxy_cal.ctdprs(i,1)=btl(sta_idx).data(fire_idx,pr_idx);
0177       oxy_cal.ctdcon1(i,1)=10*btl(sta_idx).data(fire_idx,ctd_c1_idx);
0178       oxy_cal.ctdcon2(i,1)=10*btl(sta_idx).data(fire_idx,ctd_c2_idx);
0179       oxy_cal.ctdoxy1(i,1)=btl(sta_idx).data(fire_idx,ctd_oxy1_idx);
0180       oxy_cal.ctdoxy2(i,1)=btl(sta_idx).data(fire_idx,ctd_oxy2_idx);
0181       oxy_cal.ctdoxv1(i,1)=btl(sta_idx).data(fire_idx,ctd_oxv1_idx);
0182       oxy_cal.ctdoxv2(i,1)=btl(sta_idx).data(fire_idx,ctd_oxv2_idx);
0183 %      oxy_cal.ctddvdt1(i,1)=btl(sta_idx).data(fire_idx,ctd_dvdt1_idx);
0184 %      oxy_cal.ctddvdt2(i,1)=btl(sta_idx).data(fire_idx,ctd_dvdt2_idx);
0185       % getting the dcdp values
0186  %     dcdp_idx=find(cond_cal.stnnbr==sta_idx & cond_cal.fireorder==fire_idx);
0187  %       if length(dcdp_idx)>1
0188  %         dcdp_idx=dcdp_idx(1);
0189  %       end
0190  %     if isempty(dcdp_idx)
0191  %     oxy_cal.dcdp1(i,1)=oxy_cal.dcdp1(i-1,1);
0192  %     oxy_cal.dcdp2(i,1)=oxy_cal.dcdp2(i-1,1);
0193  %else
0194 %      oxy_cal.dcdp1(i,1)=cond_cal.dcdp1(dcdp_idx);
0195 %      oxy_cal.dcdp2(i,1)=cond_cal.dcdp2(dcdp_idx);
0196 %     end
0197       
0198       %
0199       oxy_cal.ctdtmp1(i,1)=btl(sta_idx).data(fire_idx,ctd_t1_idx);
0200       if flag_conv1==1;
0201       oxy_cal.ctdtmp1(i,1)=t90tot68(oxy_cal.ctdtmp1(i,1));   
0202       end
0203       oxy_cal.ctdtmp2(i,1)=btl(sta_idx).data(fire_idx,ctd_t2_idx);
0204       if flag_conv2==1;
0205       oxy_cal.ctdtmp2(i,1)=t90tot68(oxy_cal.ctdtmp2(i,1));   
0206       end 
0207     end
0208      disp('*****************************************');
0209      disp('Matching .btl information with .oxy files')
0210      disp('*****************************************');
0211      oxy_cal.ctdsal1=sw_salt(oxy_cal.ctdcon1/sw_c3515,oxy_cal.ctdtmp1,oxy_cal.ctdprs);
0212      oxy_cal.ctdsigflu1=sw_pden(oxy_cal.ctdsal1,oxy_cal.ctdtmp1,oxy_cal.ctdprs,oxy_cal.ctdprs)-1000;
0213      oxy_cal.ctdsal2=sw_salt(oxy_cal.ctdcon1/sw_c3515,oxy_cal.ctdtmp1,oxy_cal.ctdprs);
0214      oxy_cal.ctdsigflu2=sw_pden(oxy_cal.ctdsal2,oxy_cal.ctdtmp2,oxy_cal.ctdprs,oxy_cal.ctdprs)-1000;   
0215     
0216 % Save the oxygen summary structure.
0217 save(db_file,'oxy_cal','-append');
0218 
0219 if nargout==0
0220     assignin('caller','ans',oxy_cal);
0221     return
0222 else
0223     varargout{1}=oxy_cal;
0224     return
0225 end
0226  return
0227       
0228       
0229       
0230       
0231       
0232       
0233 
0234      
0235      
0236      
0237      
0238

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