      FUNCTION PLFACT(STH,P,KDT)
C***  LP FACTOR FOR GUINIER, INCLUDING ABSORPTION TERMS
      DIMENSION P(3)
C***  PRELIMINARY ANGLE CALCULATIONS
      S=STH**2
      CTH=SQRT(1.0-S)
      IF(KDT.GT.1) GO TO 70
      TH=ATAN(STH/CTH)
      PHI=0.523598775
      CHI=2.0*TH-PHI
      CP=COS(PHI)
      CC=COS(CHI)
C***  GEOMETRICAL TERMS
      PLFACT=(1.0+0.8*(1.0-2.0*S)**2)/(1.8*S*CTH*CC)
C***  SPECIMEN ABSORPTION
      IF(ABS(P(1)).LT.0.001) GO TO 30
      XN=P(1)*(1.0-1.0/CP)
      X=P(1)*(1.0/CC - 1.0/CP)
      IF(ABS(CP-CC).LT.0.001)  GO TO 10
      A=XN*(1.0-EXP(-X))/(X*(1.0-EXP(-XN)))
      GO TO 20
   10 A=XN/(1.0-EXP(-XN))
   20 PLFACT=PLFACT*A
   30 CONTINUE
C***  SCREEN ABSORPTION
      IF(P(2).LT.0.001)  GO TO 40
      PLFACT=PLFACT*EXP(-P(2)/CC)
   40 CONTINUE
C***  FILM ABSORPTION
      IF(P(3).LT.0.001)  GO TO 50
      PLFACT=PLFACT*(1.0-EXP(-P(3)/CC))/(1.0-EXP(-P(3)))
      GO TO 60
   50 PLFACT=PLFACT/CC
   60 CONTINUE
      GO TO 100
C***  LP FACTOR FOR NEUTRONS
   70 PLFACT=1.0/(S*CTH)
  100 RETURN
      END
      FUNCTION WEIGHT(IW,P,YO,WO,SINANG,KDT)
      DIMENSION P(3,2)
      WEIGHT=P(2,KDT)/(P(1,KDT)+YO)
      IF(P(3,KDT).GT.0.0) WEIGHT=WEIGHT/SINANG**P(3,KDT)
      IF(IW.EQ.2) WEIGHT=WEIGHT*WO
      RETURN
      END
      SUBROUTINE PATCH(TT,HT,I)
      DIMENSION HT(3)
      IF(I.GT.4) GO TO 20
      HT(1)=HT(1)+HT(2)+HT(3)
      HT(2)=0.0
      HT(3)=0.0
   20 RETURN
      END
      SUBROUTINE RESETX(AI,X)
      DIMENSION X(3,1),AI(1)
      X(2,1)=X(1,1)
      X(3,1)=X(1,1)
      X(2,2)=X(1,2)
      X(3,2)=X(1,2)
      X(2,3)=X(1,3)
      X(3,3)=X(1,3)
      X(2,4)=X(1,4)
      X(3,4)=X(1,4)
      RETURN
      END
