% function newbb_data=bb6cor_BOSS(beta140_data,sal_data,lambdas)
% Correct Hydroscatt6 bb data according to "E. Boss Method" as follow:
% for each wavelength:
% bb=1.18(Beta(140deg)-Beta_salt_water(140deg))+bb_salt_water
% data arrays format is (line,sample)
%
% inputs:- beta140_data(1 to 6,1 to n_sample) : beta(140) data from Hydroscatt6
%		   - sal_data(1 to n_sample) : salinity data in PSU
%        - lambdas(1 to 6) : wavelength channels ex:[442 488 532 555 620 676]  
% (order of wavelengths channel must be the same is beta140_data and lambdas)
%
% output: - new_bb_data(1 to 6,1 to n_sample)
%
% Francois Baratange OSU 2001

function new_bbdata=bb6cor_BOSS(beta140_data,sal_data,lambdas)

%init array
betasw_140=struct(['ch_' num2str(lambdas(1))],0,['ch_' num2str(lambdas(2))],0,...
           ['ch_' num2str(lambdas(3))],0,['ch_' num2str(lambdas(4))]...
           ,0,['ch_' num2str(lambdas(5))],0,['ch_' num2str(lambdas(6))],0);
bbsw=struct(['ch_' num2str(lambdas(1))],0,['ch_' num2str(lambdas(2))],0,...
           ['ch_' num2str(lambdas(3))],0,['ch_' num2str(lambdas(4))]...
           ,0,['ch_' num2str(lambdas(5))],0,['ch_' num2str(lambdas(6))],0);
        
n_sample=size(sal_data,2);

%compute beta(140) salt water at specifies wavelengths
%compute bb salt water at specifies wavelengths
%compute new bb
for i=1:6
  for j=1:n_sample 
   eval(['betasw_140.ch_' num2str(lambdas(i)) '=1.38*(lambdas(i)/500)^(-4.32)*(1+0.3*sal_data(j)/37)*((1+(cos((14/18)*pi))^2)*(1-0.09)/(1+0.09))*10^(-4);']);
   eval(['bbsw.ch_' num2str(lambdas(i)) '=1.38*(lambdas(i)/500)^(-4.32)*(1+0.3*sal_data(j)/37)*2*pi*(1+(1-0.09)/(3*(1+0.09)))*10^(-4);']);
   eval(['new_bbdata(i,j)=1.18*(beta140_data(i,j)-betasw_140.ch_' num2str(lambdas(i)) ')+bbsw.ch_' num2str(lambdas(i)) ';'] );
	end
end

return

