function entropy_part = gsw_entropy_part(SA,t,p)

%gsw_entropy_part    entropy minus the terms that are a function of only SA
%==========================================================================
% This function calculates entropy, except that it does not evaluate any 
% terms that are functions of Absolute Salinity alone.  By not calculating 
% these terms, which are a function only of Absolute Salinity, several 
% unnecessary computations are avoided (including saving the computation 
% of a natural logarithm).  These terms are a necessary part of entropy, 
% but are not needed when calculating potential temperature from in-situ 
% temperature.  
%
% VERSION NUMBER: 3.06.12 (25th May, 2020)
%
%==========================================================================

% This line ensures that SA is non-negative.
SA(SA < 0) = 0;

sfac = 0.0248826675584615;                % sfac = 1/(40*(35.16504/35));

x2 = sfac.*SA;
x = sqrt(x2);
y = t.*0.025;
z = p.*1e-4;

g03 = z.*(-270.983805184062 + ...
    z.*(776.153611613101 + z.*(-196.51255088122 + (28.9796526294175 - 2.13290083518327.*z).*z))) + ...
    y.*(-24715.571866078 + z.*(2910.0729080936 + ...
    z.*(-1513.116771538718 + z.*(546.959324647056 + z.*(-111.1208127634436 + 8.68841343834394.*z)))) + ...
    y.*(2210.2236124548363 + z.*(-2017.52334943521 + ...
    z.*(1498.081172457456 + z.*(-718.6359919632359 + (146.4037555781616 - 4.9892131862671505.*z).*z))) + ...
    y.*(-592.743745734632 + z.*(1591.873781627888 + ...
    z.*(-1207.261522487504 + (608.785486935364 - 105.4993508931208.*z).*z)) + ...
    y.*(290.12956292128547 + z.*(-973.091553087975 + ...
    z.*(602.603274510125 + z.*(-276.361526170076 + 32.40953340386105.*z))) + ...
    y.*(-113.90630790850321 + y.*(21.35571525415769 - 67.41756835751434.*z) + ...
    z.*(381.06836198507096 + z.*(-133.7383902842754 + 49.023632509086724.*z)))))));

g08 = x2.*(z.*(729.116529735046 + ...
    z.*(-343.956902961561 + z.*(124.687671116248 + z.*(-31.656964386073 + 7.04658803315449.*z)))) + ...
    x.*( x.*(y.*(-137.1145018408982 + y.*(148.10030845687618 + y.*(-68.5590309679152 + 12.4848504784754.*y))) - ...
    22.6683558512829.*z) + z.*(-175.292041186547 + (83.1923927801819 - 29.483064349429.*z).*z) + ...
    y.*(-86.1329351956084 + z.*(766.116132004952 + z.*(-108.3834525034224 + 51.2796974779828.*z)) + ...
    y.*(-30.0682112585625 - 1380.9597954037708.*z + y.*(3.50240264723578 + 938.26075044542.*z)))) + ...
    y.*(1760.062705994408 + y.*(-675.802947790203 + ...
    y.*(365.7041791005036 + y.*(-108.30162043765552 + 12.78101825083098.*y) + ...
    z.*(-1190.914967948748 + (298.904564555024 - 145.9491676006352.*z).*z)) + ...
    z.*(2082.7344423998043 + z.*(-614.668925894709 + (340.685093521782 - 33.3848202979239.*z).*z))) + ...
    z.*(-1721.528607567954 + z.*(674.819060538734 + ...
    z.*(-356.629112415276 + (88.4080716616 - 15.84003094423364.*z).*z)))));

entropy_part = -(g03 + g08).*0.025d0;

end
