function [adat2,cdat2] = tscorr(tmp,sal,adat,cdat,caltmp)
%
%  Used to perform temperature and salinity corrections of AC-9 data.
%
%  Coefficients courtesy of W. Scott Pegau.
%
%  This routine assumes that
%  tmp(1,:)=temperature
%  sal(1,:)=salinity
%  adat(1:9,:)= a @ 412, 440, 488, 510, 532,
%     555, 650, 676, 715
%  cdat(1:9,:)= c @ 412, 440, 488, 510, 532,
%     555, 650, 676, 715
%  caltmp=scalar, calibration temperature
%
%  WRITTEN BY:  Andrew H. Barnard July 12, 1996.
%
%  REFERENCE:
%   Pegau, W. S., D. Gray, and J. R. V. Zaneveld.  1997.  
%    Absorption and attenuation of visible and near-infrared 
%    light in water:  The dependence on temperature and salinity.  
%    Applied Optics, in press.

%
%  find size of input data
%
info=size(adat);
num=info(2);
%
%  set up output arrays
%
adat2=adat;
cdat2=cdat;
%
%  Temperature and salinity correction coefficients
%
phitsw=[0.0003 .0002 .0001 .0003 .0001 .0002 -.0001 -.0001 .0027];
phisa=[.00018 .00008 .00008 .00009 .00004 .00008 .0001 .00007 -.00018];
phisc=[.00007 -.00007 -.00007 -.00007 -.00008 -.00008 -.00005 -.00007 -.00032];
%
%  Loop for a and c T/S corrections
%
for i=1:9
 for j=1:num

  adat2(i,j)=adat(i,j)-(phitsw(1,i)*(tmp(1,j)-caltmp)+phisa(1,i)*(sal(1,j)));
  cdat2(i,j)=cdat(i,j)-(phitsw(1,i)*(tmp(1,j)-caltmp)+phisc(1,i)*(sal(1,j)));

 end

end
