Home > ctdcal > apply_calibration.m

apply_calibration

PURPOSE ^

APPLY_CALIBRATION - Apply oxygen and conductivity calibration .

SYNOPSIS ^

function ctd_cal=apply_calibration(cruiseid,coeff)

DESCRIPTION ^

 APPLY_CALIBRATION - Apply oxygen and conductivity calibration .

 CTD Calibration toolbox.

 USAGE:
 cond_cal=apply_calibration(cruiseid);

 INPUT: cruiseid: Cruise identification name.
        coeff: matrix with coefficients from conductivity calibration
   
 OUTPUT: .... 
          
 DESCRIPTION: ...  
 
 AUTHORS:
            Carlos Fonseca 
         UM/CIMAS
         Derrick Snowden
         NOAA/AOML/PhOD
         Tue May 11 11:23:37 EDT 2004

 CHANGELOG: 
   07-Oct-2004, Version 1.0
        * Initial version. 

 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function ctd_cal=apply_calibration(cruiseid,coeff)
0002 % APPLY_CALIBRATION - Apply oxygen and conductivity calibration .
0003 %
0004 % CTD Calibration toolbox.
0005 %
0006 % USAGE:
0007 % cond_cal=apply_calibration(cruiseid);
0008 %
0009 % INPUT: cruiseid: Cruise identification name.
0010 %        coeff: matrix with coefficients from conductivity calibration
0011 %
0012 % OUTPUT: ....
0013 %
0014 % DESCRIPTION: ...
0015 %
0016 % AUTHORS:
0017 %            Carlos Fonseca
0018 %         UM/CIMAS
0019 %         Derrick Snowden
0020 %         NOAA/AOML/PhOD
0021 %         Tue May 11 11:23:37 EDT 2004
0022 %
0023 % CHANGELOG:
0024 %   07-Oct-2004, Version 1.0
0025 %        * Initial version.
0026 %
0027 %
0028 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0029 tcor = 0.0015947; 
0030 pcor =  0.00010485;
0031 Boc=0.11712;
0032 Soc=0.38874; 
0033 Voffset=-0.79912;
0034 cal=0;
0035 gama=0;
0036 po1=0.0004513;
0037 po2=0;
0038 po3=0;
0039 po4=0;
0040 po5=0;
0041 po6=0;
0042 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0043 load_model_types;
0044 %
0045 flag_message1=0;
0046 flag_message2=0;
0047 %
0048 % Retrieve the necessary preferences for this cruise
0049 group = group_name(cruiseid);
0050 
0051 % cruise_dir is the main calibration data directory
0052 
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 n=who('cnv');
0067 
0068 if isempty(n)==1
0069     error(['cnv not found. Run load_cnv.m ']);
0070     return;
0071 end
0072 disp('**************************************************************************************')
0073 disp('This is the program that applies the calibration coefficients to the .cnv data.')
0074 disp('Edit the values for the oxygen coefficients in the begining of this m-file.')
0075 disp('Rename and save in your cruise folder.')
0076 disp('**************************************************************************************')
0077 
0078 disp('**************************************************************************************')
0079 disp(' 0 = use the primary sensor (DEFAULT)' )
0080 disp(' 1 = use the secondary sensor' )
0081 pri_sec=input('Do you want apply the calibration to the primary or to the secondary sensor: ');
0082 while (isempty(pri_sec)==1 | pri_sec<0 | pri_sec>1)
0083     disp('Please answer 0 (zero) for no or  1(one) for yes ')
0084     pri_sec=input('Do you want to use the primary or the secondary sensor: ');
0085 end
0086 disp('***************************************************************************')
0087 fit_choice=input('Enter the number of the conductivity fit that you want to use: ');
0088 disp(' 0 = none (Seabird Equation)' )
0089 disp(' 1 = exponential' )
0090 disp(' 2 = polynomial')
0091 oxy_choice=input('What method did you choose for the oxygen calibration? ');
0092 while (isempty(oxy_choice)==1 | oxy_choice<0 | oxy_choice>3)
0093     disp('Invalid oxygen method')
0094     oxy_choice=input('What method did you choose for the oxygen calibration? ');
0095 end
0096 %%%%%%%%%%%%%%%%%%%%
0097 %max_cnv=max(size(cnv));
0098 %for i=1:max_cnv;
0099 for i=1:6;
0100     sta_idx=i;
0101     for j=1:length(cnv(sta_idx).names);
0102         if strncmp(cnv(sta_idx).names(j),'timeS',5);
0103         time_idx=j;
0104         end
0105         if strncmp(cnv(sta_idx).names(j),'prDM',4);
0106         pr_idx=j;
0107         end
0108         if (pri_sec==0) 
0109           if strncmp(cnv(sta_idx).names(j),'c0S/m',5);
0110           cond_idx=j;
0111           elseif strncmp(cnv(sta_idx).names(j),'t068C',5);
0112           temp_idx=j;
0113           elseif strncmp(cnv(sta_idx).names(j),'t090C',5);
0114           temp_idx=j;
0115           flag_conv1=1;
0116            if flag_message1==0
0117            disp('Primary temperatures are given in T90.')
0118            disp('This program will convert to T68 to make the necessary calculations')
0119            flag_message1=1;
0120            end
0121           elseif strncmp(cnv(sta_idx).names(j),'sbeox0V',7);
0122           oxv1_idx=j;
0123           end
0124         else
0125           if strncmp(cnv(sta_idx).names(j),'c1S/m',5);
0126           cond_idx=j;
0127           elseif strncmp(cnv(sta_idx).names(j),'t168C',5);
0128           temp_idx=j;
0129           elseif strncmp(cnv(sta_idx).names(j),'t190C',5);
0130           temp_idx=j;
0131           flag_conv2=1;
0132           if flag_message2==0
0133           disp('Primary temperatures are given in T90.')
0134           disp('This program will convert to T68 to make the necessary calculations')
0135           flag_message2=1;
0136           end
0137           elseif strncmp(cnv(sta_idx).names(j),'sbeox1V',7);
0138           oxv1_idx=j;
0139           end
0140         end
0141     end
0142     press_aux=cnv(sta_idx).data(:,pr_idx);
0143     oxyvolt_aux=cnv(sta_idx).data(:,oxv1_idx);
0144     temp_aux=cnv(sta_idx).data(:,temp_idx);
0145       if (flag_conv1==1 | flag_conv2==1)
0146       temp_aux=t90tot68(temp_aux);
0147       end
0148     cond_aux=cnv(sta_idx).data(:,cond_idx)*10;
0149     aux_dcdp=gradient(cond_aux);
0150   
0151   % correcting the conductivity
0152         if (fit_choice<8)
0153          ldx=['X=s',num2str(fit_choice-1),'(cond_aux,repmat(sta_idx,length(cond_aux),1),press_aux,aux_dcdp);'];
0154         elseif(i>7 &i<15)
0155          ldx=['X=p',num2str(fit_choice-8),'(cond_aux,repmat(sta_idx,length(cond_aux),1),press_aux,aux_dcdp);'];  
0156         elseif(i>14 & i<22)
0157          ldx=['X=dcdp',num2str(fit_choice-15),'(cond_aux,repmat(sta_idx,length(cond_aux),1),press_aux,aux_dcdp);'];
0158         else
0159          ldx=['X=pdcdp',num2str(fit_choice-22),'(cond_aux,repmat(sta_idx,length(cond_aux),1),press_aux,aux_dcdp);'];  
0160         end
0161         eval(ldx);
0162         c=coeff(fit_choice,2:1+length(X(1,:)));
0163         condc=X*c';
0164       %condc=weim(11,'hann',cond_cor)';
0165         sal_aux=sw_salt(condc/sw_c3515,temp_aux,press_aux); 
0166    
0167    % correcting the oxygen (oxy fit 3.01 std dev)
0168    % calculating oxygen saturation
0169    %constants for oxsat calculation
0170    A1 = -173.4292;
0171    A2 = 249.6339;
0172    A3 = 143.3438;
0173    A4 = -21.8492;
0174    B1 = -0.033096;
0175    B2 = 0.014259;
0176    B3 = -0.00170;
0177    T  = temp_aux + 273.15;
0178    oxsat = exp(A1 + A2*(100./T) + A3*log(T./100)...
0179            + A4*(T./100) + sal_aux .* (B1+B2*(T./100)+ B3*(T./100).*(T./100)));
0180    % calibration coefficients for the oxygen
0181   sta=repmat(sta_idx,length(oxyvolt_aux),1); 
0182   if (oxy_choice==0)
0183      new_oxy=((Soc.*(oxyvolt_aux+Voffset))+Boc.*exp(-0.03.*temp_aux)+...
0184            (cal.*sta_idx)).*exp(tcor.*temp_aux).*oxsat.*exp(pcor.*press_aux);
0185   end
0186   if (oxy_choice==1)
0187     new_oxy=((Soc.*(oxyvolt_aux+Voffset))+Boc.*exp(-0.03.*temp_aux)+cal.*exp(gama*sta))...
0188              .*exp(tcor.*temp_aux).*oxsat.*exp(pcor.*press_aux);  
0189       
0190   end
0191   if (oxy_choice==2)
0192   new_oxy=((Soc*(oxyvolt_aux+Voffset))+Boc*exp(-0.03.*temp_aux)+(po1*sta+(po2*sta.^2)+...
0193            po3*sta.^3)+(po4*sta.^4)+(po5*sta.^5)+(po6*sta.^6))...
0194            .*exp(tcor.*temp_aux).*oxsat.*exp(pcor.*press_aux);
0195   end     
0196   % saving the variables
0197   ctd_cal(i).pressure(:,1)=press_aux;
0198   ctd_cal(i).depth(:,1)=sw_dpth(press_aux,cnv(i).lat);
0199   ctd_cal(i).temp(:,1)=temp_aux;
0200   ctd_cal(i).pottemp(:,1)=sw_ptmp(sal_aux,temp_aux,press_aux,0);
0201   ctd_cal(i).salt(:,1)=sal_aux;
0202   ctd_cal(i).cond(:,1)=condc;
0203   % converting the oxygen to micromol/kg
0204   oxy_aux=ox_units(new_oxy,sal_aux,sw_ptmp(sal_aux,temp_aux,press_aux,0),'mll2mmk');
0205   ctd_cal(i).oxyumol(:,1)=oxy_aux;
0206   ctd_cal(i).oxymll(:,1)=new_oxy;
0207   % calculating the dynamic height
0208   svan = sw_svan(sal_aux,temp_aux,press_aux);
0209   clear dh
0210   for k=1:length(svan); 
0211     dh(k)=sum(svan(1:k))*1000;
0212   end
0213   ctd_cal(i).dynheight(:,1)=dh;     
0214   % calculating sigma-theta
0215   pden = sw_pden(sal_aux,temp_aux,press_aux,0)-1000;
0216   ctd_cal(i).sigma0(:,1)=pden; 
0217 end
0218

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