function X = sal2cond(sal)
%X = sal2cond(sal)
%
% This function will compute the conductivity (in units of mmho/cm =
% 10^-5 /ohm/m = 10^-5 S/m) of a water sample given its salinity (no
% units).  This equaion is valid for salinities between 2 and 42.  The
% equation is taken from Perkin and Lewis 1980.
% 
%USAGE:
%  sal (scalar): salinity of the fluid (no units)
%
% See also: condfsalt, saltfcond, wghts

if sal < 2
    disp('Error in sal2cond: Salinity too low');
    
elseif sal > 42
    disp('Error in sal2cond: Salinity too high');
    
else
    a0 = 0.0080;
    a1 = -0.1692;
    a2 = 25.3851;
    a3 = 14.0941;
    a4 = -7.0261;
    a5 = 2.7081;
    refcond = 42.9235;

    X = fminsearch(['abs(',num2str(sal),' - ',num2str(a0),' - ',num2str(a1),'*x^0.5 - ',num2str(a2),'*x - ',num2str(a3),...
        '*x^1.5 - ',num2str(a4),'*x^1.5 - ',num2str(a5),'*x^2.5)'],1)*refcond;
end