function D=depth(p,lat);
% DEPTH calculates depth (meters) from pressure (dbar)
%
%	depth(p,lat) calculates depth (meters) from pressure (dbar)
%	and latitude, using Saunders and Fofonoff's method.
%	Formula Refitted for 1980 Equation of State.
%
%	USAGE:		d=depth(p,lat);
%	UNITS:
%	Pressure	p	decibars
%	Latitude	lat	degrees
%	depth		d	meters
%
%	Check Values:
%	depth=9712.653 m, for p=10000 decibars, latitude=30 degrees
%	(for standard ocean: T=0 deg C, Salinity=35 (PSS-78)
%

% Saunders, P.M.; Fofonoff, N.P.  1976.  Conversion of pressure to depth
% in the ocean.  Deep-Sea Res., 23, p 109-111.

% Saunders, Peter M. 1981.  Practical Coversion of Pressure to Depth.
% J. Phys. Oceanogr., 11, 573-574.

p=p(:);

X=sin(lat/57.29578);
X=X.^2;
X=X*ones(size(p));

% gr = gravity variation with latitude: Anon (1970) Bulletin Geodesique
gr=9.780318*(1+(5.2788e-3+2.36e-5.*X).*X)+1.092e-6.*p;

D=(((-1.82e-15.*p+2.279e-10).*p-2.2512e-5).*p+9.72659).*p;

D=D./gr;
