# Re: [ferret_users] calculate the density with Pressure

```Hi Dawn et al.,

```
I've looked at the various functions in your script and all appears well, except for some minor problems of roundoff (see below) that may relate to Ferret's use of single precision. One thought came to mind when checking my test results against the table of densities in Adrian Gill's book (Atmosphere-Ocean Dynamics Table A3.1): Is it possible that you compared your results with pressures in BARs rather than DECIbars. Thats what I did at first -- the table gave 50.678 for rho(35,0,500)-1000 where I was expecting something much less at p~500dbar. But the table used BARs so the value for "500" was really for 5000dbar!
```
```
However if the "obviously wrong" values you refer to are much less gross than that, there is the possibility that roundoff is an issue. The formula you supply (involving 1-c1) is based on applying the equation supplied by Saunders in JPO 11:573-574. This paper in Table 2 has corresponding P,Z pairs to test against your Ferret implementation. For me the comparison is not at all good: Z=9712.02m should be associated with P=10000db. Unless I did something wrong, your formulation gives P=9782.23db. Saunders table suggests that the error in using the quadratic formula in this case (rather than the full eqn involving logs) should only be 5.77.
```
```
On a related note, Saunders refers to the earlier paper Saunders & Fofonoff in Deep-Sea Research 23:109-111 (1976). Evaluating Eqn4 of this using Ferret gave exact matches to the tabulated values. Unfortunately this relationship is not as easily inverted as Saunders quadratic one. A possible way around this in Ferret is to use regridding to relate P and Z. Because of the variation of g with latitude, you might have to do this one latitude at a time.
```I did not code up the non-quadratic Saunders formula.

Hope this is some help,
Good luck,
Mick Spillane
------
James Orr wrote:
```
Billy is right. I was thinking that the "temperature" was actually already potential temperature, as in the case of model output that I've worked with. Sorry for the unclear statement.
```
Jim

On Mon, 22 Jan 2007, William S. Kessler wrote:

```
```Hi Jim, Dawn -

```
No, I don't think Jim is correct. If a reference pressure is used, then you must use potential temperature theta instead of temperature. It does not make sense to calculate density at 0 pressure but with temperature at depth (where the pressure affects the temperature). Instead, bring the water parcel adiabatically to the surface by finding theta, then use your reference pressure:
```
```
let theta=theta_fo(salt,temp,z[gz=temp],0) ! potential temperature theta
```let sigma_theta=rho_un(salt,theta,0)-1000

```
See the documentation for the THETA_FO function. For sigma-2, use 2000 instead of zero in the above.
```
```
But I think Dawn is asking something different. Instead of z, she wants to use pressure. Frankly, I don't know the answer to her question ("the results are obviously wrong" doesn't give me much of a clue). However, I think she is on the right track, because I believe the 3rd argument to THETA_FO really should be pressure, not depth (the documentation is unclear on this point). I suggest looking at the reference given under the THETA_FO function (Bryden 1973). Then tell us so the documentation can be fixed if necessary.
```
Billy K

On Jan 22, 2007, at 9:59 AM, James Orr wrote:

```
```Dawn,

```
Your pressure in the 3rd argument of the rho_un function should be the reference pressure:
```
0 for sigma_0
2000 for sigma_2

Cheers,

Jim

On Mon, 22 Jan 2007, ferret ocean wrote:

```
```Dear ferreters,

```
I want to calculate the density with pressure instead of depth (more accuate way), but when I get the pressure with the following scipt to convert the depth to pressure,
```
let x0 = sin(y[g=v]*3.1415926/180);
let c1 = 5.92E-3 + x0*x0 * 5.25E-3;
```
let pres = ((1-c1)-(((1-c1)*(1-c1))-(8.84E-6 * z[g=v]))^0.5) / 4.42E-6;
```
then let rho=rho_un(salt,temp,pres)-1000;

But the results are obviously wrong. Do you have any suggestions?

Dawn
```
```
```
```
```
```
```
```

```