function alpha = compute_absorption(f,T,S,z,pH)
% COMPUTE_ABSORPTION - Compute acoustic absorption of seawater following
%                      Ainsle & McColm (1998)
%
% alpha = compute_absorption(f,T,S,z,pH)
% 
% OUTPUT: alpha in dB/km
% INPUT:
% f: frequency in kHz
% T: temperature in C
% S: salinity in ppt
% z: depth in km
% pH: pH in pH units
% f is required, others are optional and are filled with default values of:
% pH = 8; z = 0; S = 35; T = 0
%
% Reference:
% Michael A. Ainslie and James G. McColm
% A simplified formula for viscous and chemical absorption in sea water
% J. Acoust. Soc. Am. 103 (3), March 1998
% http://dx.doi.org/10.1121/1.421258
%
% 2014-05-30 nowacki@uw.edu

if nargin < 5, pH = 8; end
if nargin < 4, z = 0; end
if nargin < 3, S = 35; end
if nargin < 2, T = 0; end

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

alpha = 0.106 .* (f1 .* f.^2) ./ (f.^2 + f1.^2) .* exp((pH - 8) ./ 0.56) ...
    + 0.52 .* (1 + T ./ 43) .* (S ./ 35) .* (f2 .* f.^2) ./ (f.^2 + f2.^2) .* exp(-z ./ 6) ...
    + 0.00049 .* f.^2 .* exp(-(T ./ 27 + z ./ 17));