function [adat2,cdat2,phitswe,phisce,phisae] = tscorr_acs(temp1,temp2,sal,adat,cdat,caltmp,wla)
%
% Used to perform temperature and salinity corrections of AC-S data.
%
% Coefficients courtesy of Sullivan (2006).  NEEDS 
% Sullivan_etal_2006_instrumentspecific.xls TO FUNCTION!!!
%
% This routine assumes that
% temp1=a temperature
% temp2=c temperature
% sal=salinity
% adat(length(wla),:)=absorbance data at wavelengths wla
% cdat(length(wla),:)=attenuation data at wavelengths wla 
% caltmp=calibration temperature
%
% outputs:
% adat2=corrected absorption
% cdat2=corrected attenuation
% phitswe=error for temperature absorption correction
% phisce=error for salinity absorption correction
% phisae=error for salinity attenuation correction
%
% WRITTEN BY: Andrew H. Barnard July 12, 1996.
% EDITED BY: ENA 07/10/2013
%
% 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.

% Sullivan, et. al. (2006)
% Hyperspectral temperature and salt dependencies of absorption by water 
% and heavy water in the 400-750 nm spectral range
% Applied Optics, vol 45, issue 21

%
% find size of input data

%sullivan's paper
tmp = xlsread('Sullivan_etal_2006_instrumentspecific.xls');
phitsw=interp1(tmp(:,1),tmp(:,2),wla,'linear');
phisc=interp1(tmp(:,1),tmp(:,4),wla,'linear');
phisa=interp1(tmp(:,1),tmp(:,6),wla,'linear');
phitswe=interp1(tmp(:,1),tmp(:,3),wla,'linear');
phisce=interp1(tmp(:,1),tmp(:,5),wla,'linear');
phisae=interp1(tmp(:,1),tmp(:,7),wla,'linear');
%
num=size(adat,1);
%
% 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 j=1:length(wla)
for i=1:num

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

end

end