function alphas = soundabs(f, Z, T, S, pH)

% function alpha = soundabs(f, Z, T, S, pH)
%
% alpha is attenuation of sound in db/m based on the simplified
% formula of Ainslie and McColm (1998)
%
%     f is frequency in kHz
%     Z is depth in m  (default is 0)
%     T is temperature in deg-C  (default is 0)
%     S is salinity in PSU       (default is 35)
%     pH is pH (default is 8, a typical value in for seawater)
%
%     f can be a vector if all other parameters are scalars, or
%     vectors of the same dimension; or  f can be a scalar, any of
%     the other parameters can be scalars or vectors so long as all
%     vectors have the same dimensions.  This is not checked by the
%     program at present.
%
% 99/06/15  J. Walter and E. Firing
%

% Reference: Ainslie, M.A. and J. G. McColm, 1998. A simplified
% formula for viscous and chemical absorption in sea water.
% Journal of the Acoustical Society of America, 103, 1671-72.


if nargin < 5, pH = 8; end
if nargin < 4, S = 35; end
if nargin < 3, T = 0; end
if nargin < 2, Z = 0; end
if nargin < 1,
   help('soundabs');
   error(' At least one argument (the frequency) is needed.');
end

f1 = 0.78 * sqrt(S/35) .* exp(T/26);
f2 = 42 * exp(T/17);

fsq = f.*f;

alpha1 = 0.106 * exp((pH-8)/0.56) .* f1 ./(fsq + f1.^2);
alpha2 = 0.52 * (1+T/43) .* (S/35) .* exp(-Z/6000) .* f2 ./ (fsq + f2.^2);
alpha3 = 0.00049 * exp(-(T/27 + Z/17000));

alphas = fsq .* (alpha1+alpha2+alpha3)/1000;

