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

Hi Hanh - try the script pasted below for the streamfunction. I haven't done the velocity potential. Billy K
```
On 8Aug 2007, at 2:57 PM, nguyen@xxxxxxxxxx wrote:

```
```Hi ferreters

```
I need to calculate the streamfunction and the velocity potential from u
```and v fields, do someone have an idea?

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
set mode interp
! find y0 and x0
let y1a=y[g=\$2,j=1]
def sym y1 `y1a`
def sym y0 `\$4`
let x1a=x[g=\$1,i=1]
def sym x1 `x1a`
def sym x0 `\$3`
! ferret has a problem with blanks and @iin
let ub=if \$1 then \$1 else 0
let vb=if \$2 then \$2 else 0
! second term
```
let t2=vb[z=@din,l=@ave,y=(\$y0),x=@iin]-vb[z=@din,l=@ave,y=(\$y0),x= (\$x1):(\$x0)@din]
```! first term
let t1=ub[z=@din,l=@ave,y=@iin]-ub[k=@din,l=@ave,y=(\$y1):(\$y0)@din]
!! streamfunction
let strmfnxy=t1-t2
let usf=strmfnxy[y=@ddc]
let vsf=strmfnxy[x=@ddc]*(-1)
say x0=`(\$x0)`  y0=`(\$y0)`

```

• Follow-Ups: