      subroutine derivwall2 (dudz,dvdz,u,v,zo,u_avg,phi_m)
C calculates deriv at wall as suggested in Moeng '84
      implicit none
      include 'dimen.h'
      integer jx,jy
      real*8 dudz(ld,ny,nz),dvdz(ld,ny,nz),u(ld,ny,nz),v(ld,ny,nz),
     &  zo(nx,ny),ustar(nx,ny),denom,u_avg(nx,ny),
     &  psi_m(nx,ny),phi_m(nx,ny)
      real*8 const

      ustar=u_avg*vonK/(log((0.5*dz)/zo)-psi_m)
! make sure conformable
! watch the 2's!
      do jy=1,ny
        do jx=1,nx
          dudz(jx,jy,1)=ustar(jx,jy)/(0.5*dz*vonK)*phi_m(jx,jy)*
     &      u(jx,jy,1)/u_avg(jx,jy)     !this is as in Moeng 84
C sc: i dont know if this is correct yet
          dvdz(jx,jy,1)=ustar(jx,jy)/(0.5*dz*vonK)*phi_m(jx,jy)*
     &      v(jx,jy,1)/u_avg(jx,jy)    

        end do
      end do
      return
      end
