# Re: [ferret_users] how to calculate the streamfunction and velocity potential

```Hi Billy and Hanh,

| ! compute the horizontal streamfunction from vertically integrated u
| ! and v fields
| ! note that u and v must occur on the same spatial points (B-grid)
| ! arg1=variable name for u
| ! arg2=variable name for v
| ! arg1=x0 (must be on a gridpoint or set mode interp)
| ! arg2=y0 (likewise)
| ! psi=int(y0,y)u(x,y)dy - int(x0,x)v(x,y0)dx
| ! u=d(psi)/dy, v=-d(psi)/dx

I guess this gives you a correct streamfunction only
when du/dx + dv/dy = 0, right?  (There's no function satisfying
both u=d(psi)/dy and v=-d(psi)/dx when du/dx + dv/dy is nonzero.)

Hanh mentioned velocity potential, which suggests that a Helmholz
decomposition is required:

To obtain phi(x,y) and psi(x,y), you need to solve these Poisson equations

with some (probably arbitrary) boundary conditions.

I myself haven't done this, but a colleague of mine uses the method
described by:

Watterson, I., 2001. Decomposition of global ocean currents using a
simple iterative method. J. Atmos. Oceanic Tech., 18, 691–703.

Hope this helps,
Ryo

```