Home > ctdcal > make_cond_sum.m

make_cond_sum

PURPOSE ^

MAKE_COND_SUM - Makes conductivity bottle/ctd comparison summary file.

SYNOPSIS ^

function cond_cal = make_cond_sum(cruiseid)

DESCRIPTION ^

 MAKE_COND_SUM -  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.

 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_sum(cruiseid)
0002 % MAKE_COND_SUM -  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 % CHANGELOG:
0027 %   23-Jul-2004, Version 1.0
0028 %        * Initial version.
0029 %
0030 % DEPENDENCIES: SW package.
0031 %               load_salts
0032 %               load_btl
0033 %               load_bl
0034 %               load_cnv
0035 %
0036 %
0037 % Flags for the temperature scale conversion (t90 to t68)
0038 flag_conv1=0;
0039 flag_conv2=0;
0040 flag_message1=0;
0041 flag_message2=0;
0042 %
0043 cruise_dir=cruiseid;
0044 sd=['cd ',cruise_dir];
0045 eval(sd);
0046 fname=[cruiseid,'_db.mat'];
0047    if exist(fname)==0
0048    error([fname,' not found. Run load_btl.m and load_oxy.m ']);
0049    return;
0050    end
0051 ld_file=(['load ',fname]);
0052 eval(ld_file);
0053    n=who('btl');
0054    if isempty(n)==1
0055    error(['btl not found. Run load_btl.m ']);
0056    return;
0057    end
0058    n=who('oxy');
0059    if isempty(n)==1
0060    error(['oxy not found. Run load_oxy.m ']);
0061    return;
0062    end
0063    n=who('bl');
0064    if isempty(n)==1
0065    error(['bl not found. Run load_bl.m ']);
0066    return;
0067    end
0068 %
0069 cd ..
0070 cond_cal=cond_struct;
0071 %disp(' 0 = use the upcast profile (btl file) to do the calibration (DEFAULT)' )
0072 %disp(' 1 = use the downcast profile (cnv file) to do the calibration' )
0073 %up_down=input('Do you want to use the downcast (cnv) or the upcast profile (btl): ');
0074 %if (isempty(up_down)==1);
0075    % up_down=0;
0076     %end
0077 cond_cal.cruiseid=cruiseid;
0078 %
0079 %information from .salt files
0080     stations= unique(vertcat(cond.station));
0081     cond_cal.stnnbr=vertcat(cond.station);
0082     cond_cal.castnbr=vertcat(cond.station);
0083     cond_cal.sampnbr=vertcat(cond.sample_bottle);
0084     cond_cal.btlnbr=vertcat(cond.niskin_bottle);
0085     cond_cal.niskinbtlpos=vertcat(cond.niskin_bottle); 
0086     cond_cal.btlsal=vertcat(cond.salinity);   
0087 %
0088 % extracting the fire order from the .bl file
0089      for i=1:1:length(cond_cal.btlnbr)
0090       if (cond_cal.stnnbr(i)==0)
0091       cond_cal.fireorder(i,1)=NaN;
0092       else
0093       fire_index=find(bl(cond_cal.stnnbr(i)).niskinnumber==cond_cal.btlnbr(i));   
0094       cond_cal.fireorder(i,1)=bl(cond_cal.stnnbr(i)).fireorder(fire_index);
0095       end
0096      end 
0097 %
0098 % keeping only the valid data
0099     jj_nan=find(isnan(cond_cal.fireorder)==0);
0100     cond_cal.fireorder=cond_cal.fireorder(jj_nan);
0101     cond_cal.stnnbr=cond_cal.stnnbr(jj_nan);
0102     cond_cal.castnbr=cond_cal.castnbr(jj_nan);
0103     cond_cal.sampnbr=cond_cal.sampnbr(jj_nan);
0104     cond_cal.btlnbr=cond_cal.btlnbr(jj_nan);
0105     cond_cal.niskinbtlpos=cond_cal.niskinbtlpos(jj_nan);
0106     cond_cal.btlsal=cond_cal.btlsal(jj_nan);
0107   %
0108   % information from .btl files
0109    for i=1:length(cond_cal.btlsal)
0110       sta_idx=cond_cal.stnnbr(i);
0111       fire_idx=cond_cal.fireorder(i);
0112       % extracting the indexes for the .btl files;
0113       for j=1:length(btl(sta_idx).names);
0114        if strncmp(btl(sta_idx).names(j),'pressure',8);
0115        pr_idx=j;
0116        end
0117        if strncmp(btl(sta_idx).names(j),'con_pri',7);
0118        ctd_c1_idx=j;
0119        end
0120        if strncmp(btl(sta_idx).names(j),'con_sec',7);
0121        ctd_c2_idx=j;
0122        end
0123        if strncmp(btl(sta_idx).names(j),'t68_pri',7);
0124        ctd_t1_idx=j;
0125        end
0126        if strncmp(btl(sta_idx).names(j),'t68_sec',7);
0127        ctd_t2_idx=j;
0128        end
0129        if strncmp(btl(sta_idx).names(j),'sal_pri_pri',11);
0130        ctd_sal1_idx=j;
0131        end
0132        if strncmp(btl(sta_idx).names(j),'sal_sec_sec',11);
0133        ctd_sal2_idx=j;
0134        end
0135        if strncmp(btl(sta_idx).names(j),'t90_pri',7);
0136        ctd_t1_idx=j;
0137        flag_conv1=1;
0138         if flag_message1==0
0139         disp('Primary temperatures are given in T90.')
0140         disp('This program will convert to T68 to make the necessary calculations')
0141         flag_message1=1;
0142         end
0143        end
0144        if strncmp(btl(sta_idx).names(j),'t90_sec',7);
0145        ctd_t2_idx=j;
0146        flag_conv2=1;
0147         if flag_message2==0
0148         disp('Secondary temperatures are given in T90.')
0149         disp('This program will convert to T68 to make the necessary calculations')
0150         flag_message2=1;
0151         end  
0152        end
0153       end
0154       cond_cal.ctdprs(i,1)=btl(sta_idx).data(fire_idx,pr_idx);
0155       cond_cal.ctdcon1(i,1)=10*btl(sta_idx).data(fire_idx,ctd_c1_idx);
0156       cond_cal.ctdcon2(i,1)=10*btl(sta_idx).data(fire_idx,ctd_c2_idx);
0157       cond_cal.ctdsal1(i,1)=btl(sta_idx).data(fire_idx,ctd_sal1_idx);
0158       cond_cal.ctdsal2(i,1)=btl(sta_idx).data(fire_idx,ctd_sal2_idx);
0159       cond_cal.ctdtmp1(i,1)=btl(sta_idx).data(fire_idx,ctd_t1_idx);
0160        if flag_conv1==1;
0161        cond_cal.ctdtmp1(i,1)=t90tot68(cond_cal.ctdtmp1(i,1));   
0162        end
0163       cond_cal.ctdtmp2(i,1)=btl(sta_idx).data(fire_idx,ctd_t2_idx);
0164        if flag_conv2==1;
0165        cond_cal.ctdtmp2(i,1)=t90tot68(cond_cal.ctdtmp2(i,1));   
0166        end    
0167   % estimating dcdp term from the .cnv files
0168   %
0169   % extracting the indexes for the .cnv files;
0170       for j=1:length(cnv(sta_idx).names);
0171         if strncmp(cnv(sta_idx).names(j),'prDM',4);
0172         cnv_pr_idx=j;
0173         end
0174         if strncmp(cnv(sta_idx).names(j),'c0S/m',5);
0175         cnv_c1_idx=j;
0176         end
0177         if strncmp(cnv(sta_idx).names(j),'c1S/m',5);
0178         cnv_c2_idx=j;
0179         end
0180       end     
0181      pressure=cnv(sta_idx).data(:,cnv_pr_idx);
0182      max_pressure_idx=find(pressure(:)==max(pressure));
0183      conductivity1=10*cnv(sta_idx).data(:,cnv_c1_idx);
0184      conductivity2=10*cnv(sta_idx).data(:,cnv_c2_idx); 
0185      pressure=pressure(1:max_pressure_idx);
0186      conductivity1=conductivity1(1:max_pressure_idx);
0187      conductivity2=conductivity2(1:max_pressure_idx);
0188      aux_dcdp1=weim(21,'hann',gradient(conductivity1))';
0189      aux_dcdp2=weim(21,'hann',gradient(conductivity2))';
0190      new_dcdp1=interp1(pressure,aux_dcdp1,cond_cal.ctdprs(i),'spline',NaN);
0191      new_dcdp2=interp1(pressure,aux_dcdp2,cond_cal.ctdprs(i),'spline',NaN);
0192        if isnan(new_dcdp1)==1
0193        cond_cal.dcdp1(i,1)=mean(aux_dcdp1);
0194        else
0195        cond_cal.dcdp1(i,1)=new_dcdp1;    
0196        end
0197        if isnan(new_dcdp2)==1
0198        cond_cal.dcdp2(i,1)=mean(aux_dcdp2);
0199        else
0200        cond_cal.dcdp2(i,1)=new_dcdp2;    
0201        end
0202    end
0203    cond_cal.btlcon1=sw_C3515*sw_cndr(cond_cal.btlsal,cond_cal.ctdtmp1,cond_cal.ctdprs);
0204    cond_cal.btlcon2=sw_C3515*sw_cndr(cond_cal.btlsal,cond_cal.ctdtmp2,cond_cal.ctdprs);
0205    sd=['cd ',cruise_dir];
0206    eval(sd);
0207    fname=[cruise_dir,'_db.mat'];
0208    savefile=['save ',fname,' cond_cal -append'];
0209    eval(savefile);
0210    cd .. 
0211    return

Generated on Thu 16-Sep-2004 12:19:09 by m2html © 2003