function [adat2,reff] = ascatcr3(adat,cdat,met);
%
%  Scatter correction of a data user input method
%	function [adat2,reff] = ascatcr3(adat,cdat,met);
%  INPUT
%
%  adat(1:9,:)=a data to correct @ 412,440,488,510,532,555,650,676,715
%  cdat(1:9,:)=corresponding c data
%  met = 1  apd=apd-apd715
%  met = 2  apd=apd-0.14*(cm-apd)  (no temperature/salinity correction needed)
%  met = 3  apd=apd-(apd715/(cm715-apd715))*(cm-apd)
%  met = 4  same as 3 but each data stream median filtered first.
%  met = 5  same as 1 but corrects the 715 channel for fluorescent leakage into
%              the 715 channel by  apd=apd-(apd715-0.04*apd676)
%
%  ASSUMPTIONS OF EACH METHOD
%
%    Method 1:  Reference wavelength
%
%       - Reference wavlength (715) particulate and dissolved absorption = 0
%          so that the measurement at this wavelength is due to scattering. 
%       - The shape and magnitude of the volume scattering function is 
%          independent of wavelength.
%
%    Method 2:  Fixed scattering correction
%
%       - Scattering correction 14% where biological particles dominate,
%          18% where sediments dominate.
%       - The shape of the volume scattering function is independent of 
%          wavelength and type of material.  Scattering correction is
%          independent of wavelength.
%       - No reference wavelength used, thus no temperature and salinity
%          correction is needed in the visible region.
%
%    Method 3:  Reference wavelength and variable scattering correction
%   
%       - Reference wavlength (715) particulate and dissolved absorption = 0
%          so that the measurement at this wavelength is due to scattering. 
%       - Shape of the volume scattering function independent of wavelength.
%
%
%    Method 4:  Smoothed version of Method 3
%
%       - Same as Method 3.
%       - Performs a 40 point median filter on the scattering correction 
%          reference wavelength data before applying the correction.  Assumes
%          a gradual change in scattering.
%
%    Method 5:
%
%       - Reference wavlength (715) particulate and dissolved absorption = 0
%          so that the measurement at this wavelength is due to scattering,
%          but first correct 715 for fluorescent leakage from the 676 channel
%          by assuming a 4% leakage from 676. 
%       - The shape and magnitude of the volume scattering function is 
%          independent of wavelength.
%
%
%  OUTPUT
%
%  adat2(1:8,:)=scattering corrected a data @ 412,440,488,510,532,555,650,676
%  reff(1,:)=scattering correction of reference wavelength (a715/b715).
%
%  WRITTEN BY:  Andrew H. Barnard,  July 13, 1996.
%   Reference:  Zaneveld, Kitchen, and Moore.  Scattering error correction of 
%     reflecting tube absorption meters.  Ocean Optics XII, S. Ackleson (Ed.),
%     Proc. SPIEm
%
%    Now uses the signal processing routine called medfilta.m
%
%  find size of input a data
%
info=size(adat);
num=info(2);
reff=zeros(1,num);
%
%  set up output array
%
adat2=zeros(info(1)-1,num);
%
%  scatter correction of a data only
%
if met == 4
  sadat=adat;
  scdat=cdat;
  for i=1:9
     sadat(i,:)=medfilta(sadat(i,:),40);
    scdat(i,:)=medfilta(scdat(i,:),40);
  end

  for i=1:8
    for j=1:num
      reff(1,j)=sadat(9,j)/(scdat(9,j)-sadat(9,j)); 
    end
  end
  reff=medfilta(reff,40);
  for i=1:8
    for j=1:num
      reff(1,j)=sadat(9,j)/(scdat(9,j)-sadat(9,j)); 
      adat2(i,j)=adat(i,j)-reff(1,j)*(scdat(i,j)-sadat(i,j));
    end
  end
end

if met == 2
  sadat=adat;
  scdat=cdat;
  for i=1:9
    sadat(i,:)=medfilta(sadat(i,:),40);
    scdat(i,:)=medfilta(scdat(i,:),40);
  end
 for i=1:8
  for j=1:num
    adat2(i,j)=adat(i,j)-(0.14)*(cdat(i,j)-adat(i,j));
  end
 end

end

if met ~= 2 & met ~= 4
 for i=1:8
  for j=1:num
 
   if met == 1 | met == 5
    if met == 1
     adat2(i,j)=adat(i,j)-adat(9,j);
    else
       adat2(i,j)=adat(i,j)-(adat(9,j)-adat(8,j)*0.04);
    end
   else
    reff(1,j)=adat(9,j)/(cdat(9,j)-adat(9,j));
    adat2(i,j)=adat(i,j)-reff(1,j)*(cdat(i,j)-adat(i,j));
   end

  end

 end
end
