 function salt=calsal(P,T,R)
% function salt=calsal(P,T,C)
% P, T, C can be arrays
% Salinity from pressure (dbar), temperature (C), conductivity (S/m)
% * Please refer to IEEE Journal of Oceanic Engineering,
%   vol OE-5, NO. 1, Jan. 1980, pp. 9-16. for the formulas.
%
%
      R0 = 4.2914;
      TK = 0.0162;
      A  = [ 2.070D-5,-6.370D-10, 3.989D-15];
      B  = [ 3.426D-2, 4.464D-4, 4.215D-1,-3.107D-3];
      AA = [ 0.0080,-0.1692,25.3851,14.0941,-7.0261, 2.7081];
      BB = [0.0005,-0.0056,-0.0066,-0.0375, 0.0636,-0.0144];
      CC = [6.766097D-1,2.00564D-2,1.104259D-4,-6.9698D-7,1.0031D-9];
%
      RT = CC(1) + CC(2)*T + CC(3)*T.*T + CC(4)*T.*T.*T + CC(5)*T.*T.*T.*T;
%
      RP = P.* (A(1) + A(2)*P + A(3)*P.*P);
      RP = 1 + RP./ (1 + B(1)*T + B(2)*T.*T + B(3)*R/R0 + B(4)*R/R0.*T);
%
      RT = R./ (R0*RP.*RT);
%
      ART = AA(1);
      BRT = BB(1);
      for j = 2: 6,
        RP = RT.^((j-1.0)/2.0);
        ART = ART + AA(j).*RP;
        BRT = BRT + BB(j).*RP;
      end
      RT = T - 15.0;
      salt = ART + (RT./(1+TK.*RT)).*BRT;

