function [adat2,cdat2] = tscorr(wl,temp,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(1);
wlnum = info(2);
%
% set up output arrays
%
adat2=adat;
cdat2=cdat;
%
% Temperature and salinity correction coefficients
%
tmp = xlsread('Sullivan_etal_2006_instrumentspecific.xls');
phitsw=interp1(tmp(:,1),tmp(:,2),wl,'linear');
phisc=interp1(tmp(:,1),tmp(:,4),wl,'linear');
phisa=interp1(tmp(:,1),tmp(:,6),wl,'linear');

%phitsw=[0.0003 .0002 .0001 .0003 .0001 .0002 -.0001 -.0001 .0027];
%phisa=[0.00018 0.00008 0.00008 0.00009 0.00004 0.00008 0.0001 0.00007 -0.00018];
%phisc=[0.00007 -0.00007 -0.00007 -0.00007 -0.00008 -0.00008 -0.00005 -0.00007 -0.00032];
%
% Loop for a and c T/S corrections
%
for i=1:num
for j=1:wlnum

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

end

end