
      SUBROUTINE LOS
C     SUBROUTINE TO COMPUTE LINE OF SIGHT ATTENUATION
C
      COMMON /M/F,D,NS,A,DH,DHS,S,E,POL,KM
      COMMON /NR/ JZ,W,SW3,SW4,SA3,SA4,SAFO
      COMMON /MP/ H1E,H2E,H1G,H2G,DLS1,DLS2,DL1,DL2,DL,DLS,TE1,TE2,TE,KL
      COMMON /MLDS/ AG,AD,AS,ACR,AED,MD,AH50,AH5,D5,MS,AES,DX,H5
      COMMON /ML/ D0,D1,D01,D02,A0,A1,K1,K2,AL,ALS,A0G
      REAL NS,MD,MDO,MS,MSS,MDS,K1,K2,K3,K4,MM
C      REAL NS,MD,MDO,MS,MSS,MDS,K1,K2,K3,K4,M
      KM=2
      CALL DIFF
      KM=0
C
C     CALCULATION OF TWO RAY THEORY
C
      D01=.00004*H1E*H2E*F
      D02=AMIN1((-AED/MD),(DL-2.))
      IF (AED .GE. 0.) D0=AMIN1(D01,(.5*DL))
      IF (AED .LT. 0.) D0=.5*DL
      IF (AED .LT. 0. .AND. D02 .GE. D0) D0=D02
      D1=D0+.25*(DL-D0)
      IF (D1 .LE. D0) D1=D0+.25*(DLS-D0)
      J=0
      DS=D
      IF (J.EQ. 0) D=D0
22    DIV=1.
      PSI=ATAN((H1E+H2E)/(1000.*D))
2     DHD=DH*(1.-.8 *EXP(-.02*D))
      SH=.78*DHD*EXP(-.5*DHD**.25)
      SP=SIN(PSI)
      X=18000.*S/F
      P2=(SQRT((E-COS(PSI)*COS(PSI))**2+X*X)+E-COS(PSI)*COS(PSI))/2
     C.
      P=SQRT(P2)
      Q=X/(2.*P)
      IF (POL .EQ. 1.)B=(E*E+X*X)/(P2+Q*Q)
      IF(POL .EQ. -1.)B=1./(P2+Q*Q)
      IF (POL .EQ. 1.)MM=2.*(P*E+Q*X)/(P2+Q*Q)
      IF (POL .EQ. -1.)MM=2.*P/(P2+Q*Q)
      R2=(1.+B*SP*SP-MM*SP)/(1.+B*SP*SP+MM*SP)
      RE=SQRT(SP)
      SQEXF=SQRT(R2)*EXP(-.0209584473*F*SH*SP)*DIV
      IF (SQEXF .GT. .5 .AND. SQEXF .GT. RE)  RE=SQEXF
      C=ATAN(Q/(P+SP))-ATAN(Q/(P-SP))
      IF (POL .EQ. -1.)GO TO 40
      Y1=(X*SP+Q)/(E*SP+P)
      Y2=(X*SP-Q)/(E*SP-P)
      IF (E*SP .GE. P) C=ATAN(Y1)-ATAN(Y2)+3.141592654
      IF (E*SP .LT. P .AND. P*SP .GT. .5) C=ATAN(Y1)+ATAN(Y2)
      IF (E*SP .LT. P .AND. P*SP .LE. .5) C=ATAN(Y1)-ATAN(Y2)
40    IF (J .EQ. 0)
     CA0=-10.*ALOG10(1.+RE*RE-2.*RE*COS(.000041917*F*H1E*H2E/D0-C))
      IF (J .EQ. 1) GO TO 3
      D=D1
      J=1
      GO TO 22
3     CONTINUE
      D=DS
      IF (J .EQ. 1)
     CA1=-10.*ALOG10(1.+RE*RE-2.*RE*COS(.000041917*F*H1E*H2E/D1-C))
C
C    COMBINATION OF TWO RAY THEORY AND DIFFRACTION
C
      ALS=AED+MD*DLS
      AL=AED+MD*DL
      DED0=AED+MD*D0
      DED1=AED+MD*D1
      SA0=A0
      SA1=A1
C!!!  W=(AMIN1(H1E,H2E)/AMAX1(H1E,H2E))/(1.+F*DH*.0001)
      W=1./(1.+F*DH*.0001)
      A0=AMIN1((W*A0+(1.-W)*DED0),DED0)
      A1=AMIN1((W*A1+(1.-W)*DED1),DED1)
10    K2=((ALS-A0)*(D1-D0)-(A1-A0)*(DLS-D0))/((D1-D0)*ALOG10(DLS/D0)-
     C(DLS-D0)*ALOG10(D1/D0))
      K2=AMAX1(K2,0.)
      K1=((ALS-A0)-K2*ALOG10(DLS/D0))/(DLS-D0)
      IF (K1 .GE. 0.) GO TO 50
      K1=0.
      K2=(ALS-A0)/(ALOG10(DLS/D0))
50    AG=A0+K1*(D-D0)+K2*ALOG10(D/D0)
      IF (AG .LT. 0.) AG=0.
51    A0G=A0
53    ACR=AG
      MM=1.
      RETURN
      END
C
C	END
C	END
C	END

