Home > ctdcal > make_cond_sumfile.m

make_cond_sumfile

PURPOSE ^

make_cond_sumfile - Makes conductivity bottle/ctd comparison summary file.

SYNOPSIS ^

function cond_cal = make_cond_sumfile(cruiseid)

DESCRIPTION ^

 make_cond_sumfile -  Makes conductivity bottle/ctd comparison summary file.

 CTD Calibration toolbox.

 USAGE:
  [cond_struct] = make_cond_sumfile(cruiseid);

 INPUT: cruiseid: Cruise identification name. 
   
 OUTPUT:  Automatically writes the summary file in the cruise database file.  
          cond_cal: 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 conductivity files from the  salinity samples
  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.

 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.
    27-Sep-2004  DPS 
        *  (sample_struct): Merged the cond_struct and sample_struct functions into one.
    
 DEPENDENCIES: SW package.
               load_salts
               load_btl
               load_bl
               load_cnv

 Flags for the temperature scale conversion (t90 to t68)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function cond_cal = make_cond_sumfile(cruiseid)
0002 % make_cond_sumfile -  Makes conductivity bottle/ctd comparison summary file.
0003 %
0004 % CTD Calibration toolbox.
0005 %
0006 % USAGE:
0007 %  [cond_struct] = make_cond_sumfile(cruiseid);
0008 %
0009 % INPUT: cruiseid: Cruise identification name.
0010 %
0011 % OUTPUT:  Automatically writes the summary file in the cruise database file.
0012 %          cond_cal: contains a structure with the same information
0013 %               contained in the *.mat file
0014 %
0015 % DESCRIPTION:  This function tries to merge the *.btl files from the Seabird
0016 %  and the conductivity files from the  salinity samples
0017 %  and create a summary file containing coincident measurements from both
0018 %  systems.  The data for a whole cruise is processed at once so if you want
0019 %  less data you'll have to subset afterwards.
0020 %
0021 % AUTHORS:Carlos Fonseca
0022 %         UM/CIMAS
0023 %         Derrick Snowden
0024 %         NOAA/AOML/PhOD
0025 %         Tue May 11 11:23:37 EDT 2004
0026 %
0027 % CHANGELOG:
0028 %   23-Jul-2004, Version 1.0
0029 %        * Initial version.
0030 %    27-Sep-2004  DPS
0031 %        *  (sample_struct): Merged the cond_struct and sample_struct functions into one.
0032 %
0033 % DEPENDENCIES: SW package.
0034 %               load_salts
0035 %               load_btl
0036 %               load_bl
0037 %               load_cnv
0038 %
0039 % Flags for the temperature scale conversion (t90 to t68)
0040 flag_conv1=0;
0041 flag_conv2=0;
0042 flag_message1=0;
0043 flag_message2=0;
0044 %
0045 
0046 % Retrieve the necessary preferences for this cruise
0047 group = group_name(cruiseid);
0048 
0049 % cruise_dir is the main calibration data directory
0050 if ispref(group,'cal_data_dir')
0051     cruise_dir=getpref(group,'cal_data_dir');
0052 else
0053     error(['The cal_data_dir preference was not set for cruise: ' cruiseid '.  Run register_cruise.m']);
0054 end
0055 
0056 % Load data from the cruise database
0057 db_file = fullfile(cruise_dir,[cruiseid '_db.mat']);
0058 if exist(db_file)==2
0059     load(db_file);
0060 else
0061     error(['The cruise data base file was not found on the path.  ' db_file]);
0062 end
0063 
0064 % Check for the necessary variables in the cruise database.
0065 n=who('btl');
0066 if isempty(n)==1
0067     error(['btl variable not found in the cruise database. Run load_btl.m ']);
0068     return;
0069 end
0070 n=who('bl');
0071 if isempty(n)==1
0072     error(['bl variable not found in the cruise database. Run load_bl.m ']);
0073     return;
0074 end
0075 n=who('cnv');
0076 if isempty(n)==1
0077     error(['cnv variable not found in the cruise database. Run load_cnv.m ']);
0078     return;
0079 end
0080 n=who('cond');
0081 if isempty(n)==1
0082     error(['cond variable not found in the cruise database. Run load_salts.m ']);
0083     return;
0084 end
0085 
0086 % Initialize an empty bottle sample data structure.
0087 cond_cal = sample_struct;
0088 cond_cal.cruiseid=cruiseid;
0089 
0090 % We are trying to match the slinity bottle samples with the corresponding ctd
0091 % data.  Loop through the good samples and find the matching cnv/btl/bl data as
0092 % appropriate.
0093 % Information from salt files.  Currently this is a kluge for testing.
0094 stations= unique(vertcat(cond.station));
0095 cond_cal.stnnbr=vertcat(cond.station);
0096 cond_cal.castnbr=vertcat(cond.station);
0097 cond_cal.sampnbr=vertcat(cond.sample_bottle);
0098 cond_cal.btlnbr=vertcat(cond.niskin_bottle);
0099 cond_cal.niskinbtlpos=vertcat(cond.niskin_bottle); 
0100 cond_cal.btlsal=vertcat(cond.salinity);   
0101 
0102 % extracting the fire order from the bl  structure
0103 for i=1:1:length(cond_cal.btlnbr)
0104     if (cond_cal.stnnbr(i)==0)
0105         cond_cal.fireorder(i,1)=NaN;
0106     else
0107         fire_index=find(bl(cond_cal.stnnbr(i)).niskinnumber==cond_cal.btlnbr(i));   
0108         if isempty(fire_index)
0109             warning('No matching bl entry for the current sample.  Likely, no confirmation bit.')
0110         else
0111             % TODO: The autosal analysis may be done even if bottle trips were not confirmed by the fish. How do we handle this.  Alter subsequent programs accordingly.
0112             cond_cal.fireorder(i,1)=bl(cond_cal.stnnbr(i)).fireorder(fire_index);
0113         end
0114     end
0115 end 
0116  
0117 % keeping only the valid data
0118 jj_nan=find(isnan(cond_cal.fireorder)==0);
0119 cond_cal.fireorder=cond_cal.fireorder(jj_nan);
0120 cond_cal.stnnbr=cond_cal.stnnbr(jj_nan);
0121 cond_cal.castnbr=cond_cal.castnbr(jj_nan);
0122 cond_cal.sampnbr=cond_cal.sampnbr(jj_nan);
0123 cond_cal.btlnbr=cond_cal.btlnbr(jj_nan);
0124 cond_cal.niskinbtlpos=cond_cal.niskinbtlpos(jj_nan);
0125 cond_cal.btlsal=cond_cal.btlsal(jj_nan);
0126   
0127 % information from .btl files
0128 for i=1:length(cond_cal.btlsal)
0129     sta_idx=cond_cal.stnnbr(i);
0130     fire_idx=cond_cal.fireorder(i);
0131     % extracting the indexes for the .btl files;
0132     for j=1:length(btl(sta_idx).names);
0133         if strncmp(btl(sta_idx).names(j),'pressure',8);
0134             pr_idx=j;
0135         end
0136         if strncmp(btl(sta_idx).names(j),'con_pri',7);
0137             ctd_c1_idx=j;
0138         end
0139         if strncmp(btl(sta_idx).names(j),'con_sec',7);
0140             ctd_c2_idx=j;
0141         end
0142         if strncmp(btl(sta_idx).names(j),'t68_pri',7);
0143             ctd_t1_idx=j;
0144         end
0145         if strncmp(btl(sta_idx).names(j),'t68_sec',7);
0146             ctd_t2_idx=j;
0147         end
0148         if strncmp(btl(sta_idx).names(j),'sal_pri_pri',11);
0149             ctd_sal1_idx=j;
0150         end
0151         if strncmp(btl(sta_idx).names(j),'sal_sec_sec',11);
0152             ctd_sal2_idx=j;
0153         end
0154         if strncmp(btl(sta_idx).names(j),'t90_pri',7);
0155             ctd_t1_idx=j;
0156             flag_conv1=1;
0157             if flag_message1==0
0158                 disp('Primary temperatures are given in T90.')
0159                 disp('This program will convert to T68 to make the necessary calculations')
0160                 flag_message1=1;
0161             end
0162         end
0163         if strncmp(btl(sta_idx).names(j),'t90_sec',7);
0164             ctd_t2_idx=j;
0165             flag_conv2=1;
0166             if flag_message2==0
0167                 disp('Secondary temperatures are given in T90.')
0168                 disp('This program will convert to T68 to make the necessary calculations')
0169                 flag_message2=1;
0170             end  
0171         end
0172     end % j loop
0173     cond_cal.ctdprs(i,1)=btl(sta_idx).data(fire_idx,pr_idx);
0174     cond_cal.ctdcon1(i,1)=10*btl(sta_idx).data(fire_idx,ctd_c1_idx);
0175     cond_cal.ctdcon2(i,1)=10*btl(sta_idx).data(fire_idx,ctd_c2_idx);
0176     cond_cal.ctdsal1(i,1)=btl(sta_idx).data(fire_idx,ctd_sal1_idx);
0177     cond_cal.ctdsal2(i,1)=btl(sta_idx).data(fire_idx,ctd_sal2_idx);
0178     cond_cal.ctdtmp1(i,1)=btl(sta_idx).data(fire_idx,ctd_t1_idx);
0179     if flag_conv1==1;
0180         cond_cal.ctdtmp1(i,1)=t90tot68(cond_cal.ctdtmp1(i,1));   
0181     end
0182     cond_cal.ctdtmp2(i,1)=btl(sta_idx).data(fire_idx,ctd_t2_idx);
0183     if flag_conv2==1;
0184         cond_cal.ctdtmp2(i,1)=t90tot68(cond_cal.ctdtmp2(i,1));   
0185     end    
0186 % estimating dcdp term from the .cnv files
0187 %
0188 % extracting the indexes for the .cnv files;
0189     for j=1:length(cnv(sta_idx).names);
0190             if strncmp(cnv(sta_idx).names(j),'pr',2) 
0191                 cnv_pr_idx=j;
0192             end
0193             if strncmp(cnv(sta_idx).names(j),'c0S/m',5);
0194                 cnv_c1_idx=j;
0195             end
0196             if strncmp(cnv(sta_idx).names(j),'c1S/m',5);
0197                 cnv_c2_idx=j;
0198             end
0199     end     
0200     pressure=cnv(sta_idx).data(:,cnv_pr_idx);
0201     max_pressure_idx=find(pressure(:)==max(pressure));
0202     
0203     % There is an assumption about units here.  What is it???
0204     % Converting from S/m to mS/cm
0205     conductivity1=10*cnv(sta_idx).data(:,cnv_c1_idx);
0206     conductivity2=10*cnv(sta_idx).data(:,cnv_c2_idx); 
0207     pressure=pressure(1:max_pressure_idx);
0208     conductivity1=conductivity1(1:max_pressure_idx);
0209     conductivity2=conductivity2(1:max_pressure_idx);
0210     aux_dcdp1=weim(21,'hann',gradient(conductivity1))';
0211     aux_dcdp2=weim(21,'hann',gradient(conductivity2))';
0212     new_dcdp1=interp1(pressure,aux_dcdp1,cond_cal.ctdprs(i),'spline',NaN);
0213     new_dcdp2=interp1(pressure,aux_dcdp2,cond_cal.ctdprs(i),'spline',NaN);
0214     if isnan(new_dcdp1)==1
0215         cond_cal.dcdp1(i,1)=mean(aux_dcdp1);
0216     else
0217         cond_cal.dcdp1(i,1)=new_dcdp1;    
0218     end
0219     if isnan(new_dcdp2)==1
0220         cond_cal.dcdp2(i,1)=mean(aux_dcdp2);
0221     else
0222         cond_cal.dcdp2(i,1)=new_dcdp2;    
0223     end
0224 end % i loop
0225 cond_cal.btlcon1=sw_C3515*sw_cndr(cond_cal.btlsal,cond_cal.ctdtmp1,cond_cal.ctdprs);
0226 cond_cal.btlcon2=sw_C3515*sw_cndr(cond_cal.btlsal,cond_cal.ctdtmp2,cond_cal.ctdprs);
0227 
0228 % Save the conductivity summary structure.
0229 save(db_file,'cond_cal','-append');
0230 
0231 if nargout==0
0232     assignin('caller','ans',cond_cal);
0233     return
0234 else
0235     varargout{1}=cond_cal;
0236     return
0237 end
0238 
0239 return

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