function val=blug_eval(h,cp1,cp2,g,beta,z)
%
% Call val=blug_eval(h,cp1,cp2,g,beta,z);
%
% All-purpose function for evaluation blug parameters given the other
% parameters or evaluating the blug sound speed profile itself.
%
% INPUTS:
% h		= layer thickness in m;
% cp1	= sound speed at top of layer in m/s;
% cp2	= sound speed at bottom of layer in m/s (set to -999 to compute);
% g		= gradient at top of layer in 1/s (set to -999 to compute);
% beta	= curvature parameter (set to -999 to compute);
% z		= depth at which to compute cp(z);
%
% OUTPUTS:
% val	= cp2 (when cp2=-999), g (when g=-999), beta (when beta=-999), 
%		  c otherwise
%
if cp2==-999,
% Compute cp2:
	val=sqrt(cp1^2*(1+beta)^2 + 2*g*cp1*(1+beta)*h) - beta*cp1;
elseif g==-999,
	dcp=cp2 - cp1;
% Compute g:
	val=dcp/h * (1 + dcp/(2*cp1*(1+beta)));
elseif beta==-999,
	dcp=cp2 - cp1;
% Compute beta:
	val=(dcp^2)/(2*cp1*(g*h-dcp)) - 1;
else
% Compute c(z):
	val=sqrt((cp1*(1+beta))^2 + 2*g*cp1*(1+beta)*z) - beta*cp1;
end
%
% COPYRIGHT (c) 2008
% 
% Applied Research Laboratories, The University of Texas at Austin
% (ARL:UT)
% All rights reserved.
% 
% This material may be reproduced by or for the U.S. Government
% only. This notice must appear in all copies of this file and its
% derivatives. Further distribution outside the U.S. Government is
% prohibited without the explicit written authorization from the
% Director of the Environmental Sciences Laboratory, ARL:UT.
% 
% THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
% EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO THE
% IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
% PURPOSE, OR NONINFRINGEMENT.
% 
% IN NO EVENT WILL ARL:UT BE LIABLE FOR ANY DAMAGES WHATSOEVER ARISING
% OUT OF THE USE OR INABILITY TO USE THIS SOFTWARE, EVEN IF ARL:UT HAS
% BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
