Code: Select all

```
cff=g/rho0
DO k=N(ng),1,-1
DO i=Istr,Iend
ke2d(i,j)=ke2d(i,j)+ &
& Hz(i,j,k)*(rho(i,j,k)+1000.0_r8)* &
& 0.5_r8*(u(i ,j,k,nstp)*u(i,j,k,nstp)+ &
& u(i+1,j,k,nstp)*u(i+1,j,k,nstp)+ &
& v(i,j ,k,nstp)*v(i,j ,k,nstp)+ &
& v(i,j+1,k,nstp)*v(i,j+1,k,nstp))
pe2d(i,j)=pe2d(i,j)+ &
& cff*Hz(i,j,k)*(rho(i,j,k)+1000.0_r8)* &
& (z_r(i,j,k)-z_w(i,j,0))
END DO
END DO
```