function sigma_theta = potden80(s,t,p,refp)

%function sigma_theta = potden80(s,t,p, [refp])
%
%-----------------------------------------------------------------------------
%     Potential density from Salinity, Temperature, Pressure,
%
%     Input:
%            s  -  Salinity      [PSU-78]
%            t  -  Temperature   [IPTS-68]
%            p  -  Pressure      [decibar]
%            refp - Reference Pressure (Optional, default =0)
%
%     Output:
%            sigma_theta - Potenial Density  [m^3/kg]
%
%
%     References:
%                   spvol = eos80(refp,potemp80(s,t,p,refp),s);
%                   sigma_theta = 1/spvol
%
%     Checkvalues:
%
%---------------------------------------------------------------------
%
%
%  S. Chiswell 1991

[ns,ms] = size(p);

 if nargin <4, refp = 0;end
 p = p(:);
 t = t(:);
 s = s(:);
% sv = eos80(refp,potemp80(s,t,p,refp),s);
 sv = eos80(s,potemp80(s,t,p,refp),refp);

 if length(sv)==1
    sigma_theta = ones(1,length(sv))./sv-1000;
 else
    sigma_theta = ones(size(sv))./sv-1000;
 end

sigma_theta = reshape(sigma_theta,ns,ms);
