	subroutine add_prof(uv,nx,ny,nv,u,ix,xflg,nymin,nydim)
c
c	adds one rd profile to matrix array
c
	dimension uv(nx,ny,nv),u(nydim,4),xflg(nv)
	logical lu
      COMMON /log_uv/ lu(6)
	iv=0
	do jv=1,6
	if(lu(jv)) then
	iv=iv+1
	do iy=1,ny
	jy=iy+nymin-1
	if(jv.le.4.and.u(jy,iv).ne.xflg(iv)) uv(ix,iy,iv)=u(jy,jv)
	if(jv.eq.5.and.u(jy,1).ne.xflg(1).and.u(jy,2).ne.xflg(2)) 
     1	uv(ix,iy,iv)=uv2spd(u(jy,1),u(jy,2))
	if(jv.eq.6.and.u(jy,1).ne.xflg(1).and.u(jy,2).ne.xflg(2)) 
     1	uv(ix,iy,iv)=uv2dir(u(jy,1),u(jy,2))
	end do
	endif
	end do
	return
	end

      function uv2spd(U,V) 
C 
C     speed CALCULATED FROM U AND V
C 
	uv2spd = SQRT(U**2+V**2) 
	return
	end
      function uv2dir(U,V) 
C 
C     direction CALCULATED FROM U AND V
C 
      AAA=180./3.14159
      IF (V) 200,210,200
200   DIR = ATAN2 (U,V)*AAA 
      IF (DIR.LT.0.0) DIR = DIR + 360.
      GO TO 230 
210   IF (U) 211,212,213
211   DIR = 270.
      GO TO 230 
212   DIR = 0.0 
      GO TO 230 
213   DIR = 90. 
230   uv2dir = DIR 
      RETURN
	end
