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

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