Home > ctdcal > correct_autosal_drift.m

correct_autosal_drift

PURPOSE ^

correct_autosal_drift: Correct for autosal drift with pre/post standard water analyses

SYNOPSIS ^

function theResult = correct_autosal_drift(nominal_std,salts2cor,outfile)

DESCRIPTION ^

 correct_autosal_drift: Correct for autosal drift with pre/post standard water analyses
 
 CTD Calibration toolbox
 
 INPUT: 
   nominal_cond_standard_water: scalar representing the nominal value for
            standard water twice conductivity ratio.  This number changes for each 
             batch of standard seawater.
  salts: structure obtained as output from match_autosal_raw_dat or a similar program.
  outfile: path and name of the output file which will contain the corrected averaged
                bottle sample salinity.

 OUTPUT:
   theResult: the data structure of corrected values.  This is essentially a duplicate of
                   the information in the outfile.

 DESCRIPTION:    
     This function is specific to the autosal configuration found on the Ron Brown during the 
 2004 field season.  Modifications may be necessary, but please rename accordingly.

 SEE ALSO:
        read_autosal_raw
         read_autosal_dat

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function theResult  = correct_autosal_drift(nominal_std,salts2cor,outfile)
0002 % correct_autosal_drift: Correct for autosal drift with pre/post standard water analyses
0003 %
0004 % CTD Calibration toolbox
0005 %
0006 % INPUT:
0007 %   nominal_cond_standard_water: scalar representing the nominal value for
0008 %            standard water twice conductivity ratio.  This number changes for each
0009 %             batch of standard seawater.
0010 %  salts: structure obtained as output from match_autosal_raw_dat or a similar program.
0011 %  outfile: path and name of the output file which will contain the corrected averaged
0012 %                bottle sample salinity.
0013 %
0014 % OUTPUT:
0015 %   theResult: the data structure of corrected values.  This is essentially a duplicate of
0016 %                   the information in the outfile.
0017 %
0018 % DESCRIPTION:
0019 %     This function is specific to the autosal configuration found on the Ron Brown during the
0020 % 2004 field season.  Modifications may be necessary, but please rename accordingly.
0021 %
0022 % SEE ALSO:
0023 %        read_autosal_raw
0024 %         read_autosal_dat
0025 %
0026 
0027 
0028 % CHANGELOG:
0029 %   08-Jul-2004, Version 1.0
0030 %        * Initial version.
0031 %
0032 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0033 
0034 error(nargchk(3,3,nargin))
0035 warning off MATLAB:divideByZero
0036 date_cond = datenum(salts2cor.year,salts2cor.month,salts2cor.day,salts2cor.hours,salts2cor.minutes,salts2cor.seconds);
0037 %date_cond_stds = datenum(, , ,standards.hours,standards.minutes,standards.seconds);
0038 %date_cond=datenum(aux_out(:,7),aux_out(:,8),aux_out(:,9),aux_out(:,10),aux_out(:,11),aux_out(:,12));
0039 
0040 % Figure out where the standards start and stop relative to the bottle samples
0041 standard1_idx=find(salts2cor.samp_nbr==1000);
0042 standard2_idx=find(salts2cor.samp_nbr==1001);
0043 figure
0044 subplot(2,1,1) 
0045 plot(date_cond(standard1_idx,1),salts2cor.cond_ratio(standard1_idx),'ok')
0046 hold on
0047 plot(date_cond(standard2_idx,1),salts2cor.cond_ratio(standard2_idx),'ok')
0048 datetick('x','HH:MM')
0049 x1=date_cond(standard1_idx,1);
0050 x2=date_cond(standard2_idx,1);
0051 y1=salts2cor.cond_ratio(standard1_idx);
0052 y2=salts2cor.cond_ratio(standard2_idx);
0053 beta=nominal_std-y1;
0054 if isempty(y2) | isempty(x2)
0055     alfa = 0;
0056     warning('Autosal analysis does not contain a post calibration for drift correction.  No drift correction applied.')
0057 else
0058     alfa=(y2-y1)/(x2-x1);
0059 end
0060 adjust0=(alfa*(date_cond(standard1_idx,1)-x1))+y1;
0061 adjust=(alfa*(date_cond(standard2_idx,1)-x1))+y1;
0062 subplot(2,1,2)
0063 plot(date_cond(standard1_idx,1),(salts2cor.cond_ratio(standard1_idx)-1.999)*100000,'ok')
0064 hold on
0065 plot(date_cond(standard2_idx,1),(salts2cor.cond_ratio(standard2_idx)-1.999)*100000,'ok')
0066 plot(x1,(y1-1.999)*100000,'*k')
0067 plot(x2,(y2-1.999)*100000,'*k')
0068 plot([x1 x2],[(adjust0-1.999)*100000 (adjust-1.999)*100000],'k--')
0069 datetick('x','HH:MM')
0070 title(['Standard alfa = ',num2str(alfa),  'beta = ',num2str(beta)])
0071 saida(1,1)=alfa;
0072 saida(1,2)=beta;
0073 coeff=saida;
0074 t0=date_cond(standard1_idx,1);
0075 aux_date=date_cond-t0;
0076 figure
0077 for j=1:length(aux_date)
0078   correction=(coeff(1)*aux_date(j))+coeff(2);
0079   plot(aux_date(j),correction,'ok')
0080   datetick('x','HH:MM')
0081   hold on
0082   cond_ratio2_correct(j,1)=salts2cor.cond_ratio(j)-correction;
0083   plot(aux_date(j),cond_ratio2_correct(j,1)-salts2cor.cond_ratio(j),'or')
0084 end
0085 out_idx_cor=find(salts2cor.samp_nbr(:)<1000);
0086 output_correct=[salts2cor.station_id(out_idx_cor), salts2cor.samp_nbr(out_idx_cor), cond_ratio2_correct(out_idx_cor,1),...
0087         sw_sals(cond_ratio2_correct(out_idx_cor,1)/2,salts2cor.tank_temp(out_idx_cor))];
0088 fid=fopen(outfile,'w');
0089 fprintf(fid,'Station\t Bottle\t 2*Cond. Ratio Corrected Salinity\n');
0090 fprintf(fid,'%d\t %d\t %1.5f %2f5\n',output_correct');
0091 fclose(fid);
0092 
0093 theResult.station=output_correct(:,1);
0094 theResult.sample_bottle=output_correct(:,2);
0095 theResult.cond_ratio=output_correct(:,3);
0096 theResult.tank_temp=salts2cor.tank_temp(out_idx_cor);
0097 theResult.niskin_bottle=salts2cor.niskin_bottle(out_idx_cor);
0098 theResult.year=salts2cor.year(out_idx_cor);
0099 theResult.month=salts2cor.month(out_idx_cor);
0100 theResult.day=salts2cor.day(out_idx_cor);
0101 theResult.hours=salts2cor.hours(out_idx_cor);
0102 theResult.minutes=salts2cor.minutes(out_idx_cor);
0103 theResult.seconds=salts2cor.seconds(out_idx_cor);
0104 theResult.salinity=output_correct(:,4);
0105 return

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