C------------------------------------------------------------------------------
      SUBROUTINE ULOGZ2
C------------------------------------------------------------------------------
C     LOGARITHMIC WIND VELOCITY PROFILE
C     SINGULARITY IS AVOIDED BY A LINEAR TANGENT UNIQUELY
C     DETERMINED BY CONTINUITY OF VALUE AND SLOPE GOING THROUGH
C     THE ORIGIN.
C     Compile with options /c (compile only) and /4Yb (error tracing)
      implicit double precision (a-h,o-z)
      real*8 K
      EQUIVALENCE (USTAR,W(103)),(K,W(104)),(Z0,W(105))
C
C     COMMON DECK "RKAM" INSERTED HERE
      real*8 KR,KTH,KPH
      COMMON//R,TH,PH,KR,KTH,KPH,RKVARS(14),TPULSE,CSTEP,DRDT(20)
C     COMMON DECK "UU" INSERTED HERE
      real*8 MODU
      COMMON/UU/MODU(4)
     1  ,V  ,PVT  ,PVR  ,PVTH  ,PVPH
     2  ,VR ,PVRT ,PVRR ,PVRTH ,PVRPH
     3  ,VTH,PVTHT,PVTHR,PVTHTH,PVTHPH
     4  ,VPH,PVPHT,PVPHR,PVPHTH,PVPHPH
C     COMMON DECK "WW" INSERTED HERE
      COMMON/WW/dum(10),MAXW,W(1000)
C     WIND        100-124
      EQUIVALENCE (W(100),UMODEL),(W(101),UFORM),(W(102),UID)
C     COMMON DECK "B1" INSERTED HERE
      INTEGER UMX,UNTBL,UITBL,UFRMTBL,IDSU(10)
      COMMON/B1/UMX,UNTBL(10),UITBL(10),UFRMTBL(10),UGP(10)
      EQUIVALENCE (UGP,IDSU)
C
C     COMMON DECK "GG" INSERTED HERE
      real*8 MODG
      COMMON/GG/MODG(4)
      COMMON/GG/G,PGR,PGRR,PGRTH,PGRPH
      COMMON/GG/PGTH,PGPH,PGTHTH,PGPHPH,PGTHPH,GSELECT,GTIME
      INTEGER UPX,UQTBL(10),ULTBL(10),UIRMTBL(10)   
      DATA RECOGU/6.d0/
      DATA UPX/1/
      DATA UQTBL/1,11,8*0/
      DATA ULTBL/1,9*0/
      DATA UIRMTBL/1,9*0/
C
C                              
      ENTRY SETWND
      UMX=UPX
      CALL IMOVE(UNTBL,UQTBL,10)
      CALL IMOVE(UITBL,ULTBL,10)
      CALL IMOVE(UFRMTBL,UIRMTBL,10)
      CALL SETPWN
      RETURN
C
      ENTRY IWINDR
C
      IF(idint(RECOGU) .NE. idint(UMODEL)) 
     1    CALL RERROR('ULOGZ2 ','WRNG MODEL',RECOGU)
C
      MODU(1)=6HULOGZ2
      MODU(2)=UID
C
      Z0E=Z0*dEXP(1.d0)
      C=USTAR/K
      CZ0E=C/Z0E
      CALL IPWINDR
C
      RETURN
C
      ENTRY WINDR
      CALL CLEAR(V,20)
      CALL TOPOG
      Z = G/PGR
      IF(Z.GT.Z0E) GO TO 100
C
      VPH=CZ0E*Z
      PVPHR=CZ0E*PGR
      PVPHTH=CZ0E*PGTH
      PVPHPH=CZ0E*PGPH
      GO TO 120
C
100   VPH=C*dLOG(Z/Z0)
      CZ=C/Z
      PVPHR=CZ*PGR
      PVPHTH=CZ*PGTH
      PVPHPH=CZ*PGPH
C
120   V=dABS(VPH)
      PVR=SIGN(PVPHR,VPH)
C
      CALL PWINDR
      RETURN
      END


