      FUNCTION CIN(X)
C
C     WRITTEN BY D.E. AMOS AND S.L. DANIEL, NOVEMBER, 1975.
C     MODIFIED BY A.H. MORRIS
C
C     REFERENCES
C         SAND76-0062
C         THE SPECIAL FUNCTIONS AND THEIR APPROXIMATIONS, VOL. II, BY
C         Y.L. LUKE. ACADEMIC PRESS, NEW YORK, 1969.
C
C     ABSTRACT
C         CIN COMPUTES THE INTEGRAL OF (1-COS(T))/T ON (0,X) BY MEANS
C         OF CHEBYSHEV EXPANSIONS ON (0,5) AND (5,INFINITY).
C
C     DESCRIPTION OF ARGUMENTS
C
C         INPUT
C           X      - LIMIT OF INTEGRATION, UNRESTRICTED
C
C         OUTPUT
C           CIN    - VALUE OF THE INTEGRAL
C
C
      DIMENSION BB(16),CC(46)
C     -------------------
      DATA N1,N2,M1,M2     / 16, 46, 14, 21 /
      DATA ECON            / 5.77215664901533E-01/
C     -------------------
      DATA BB(1) / 1.82820351064538E-01/, BB(2) /-8.23768704567135E-02/,
     1     BB(3) /-1.03468764544958E-02/, BB(4) / 5.05085201960312E-03/,
     2     BB(5) / 5.73772812356328E-05/, BB(6) /-1.42717916181096E-04/,
     3     BB(7) / 2.89263664732599E-06/, BB(8) / 2.43068098304909E-06/,
     4     BB(9) /-7.90337487433443E-08/, BB(10)/-2.80205535437371E-08/,
     5     BB(11)/ 1.05488738052065E-09/, BB(12)/ 2.34186901801115E-10/,
     6     BB(13)/-9.27762554764014E-12/, BB(14)/-1.48682586858284E-12/,
     7     BB(15)/ 5.95210263082868E-14/, BB(16)/ 7.42057835287916E-15/
C     -------------------
      DATA CC(1) / 9.76155271128712E-01/, CC(2) / 8.96845854916423E-02/,
     1     CC(3) /-3.04656658030696E-02/, CC(4) / 8.50892472922945E-02/,
     2     CC(5) /-5.78073683148386E-03/, CC(6) /-5.07182677775691E-03/,
     3     CC(7) / 8.38643256650893E-04/, CC(8) /-3.34223415981738E-04/,
     4     CC(9) /-2.15746207281216E-05/, CC(10)/ 1.28560650086065E-04/,
     5     CC(11)/-1.56456413510232E-05/, CC(12)/-1.52025513597262E-05/,
     6     CC(13)/ 4.04001013843204E-06/, CC(14)/-5.95896122752160E-07/,
     7     CC(15)/-4.34985305974340E-07/, CC(16)/ 7.13472533530840E-07/,
     8     CC(17)/-5.34302186061100E-08/, CC(18)/-1.76003581156610E-07/,
     9     CC(19)/ 3.85028855125900E-08/, CC(20)/ 1.92576544441700E-08/,
     1     CC(21)/-1.00735358217200E-08/, CC(22)/ 3.36359194377000E-09/,
     2     CC(23)/ 1.28049619406000E-09/, CC(24)/-2.42546870827000E-09/,
     3     CC(25)/ 1.86917288950000E-10/, CC(26)/ 7.13431298340000E-10/,
     4     CC(27)/-1.70673483710000E-10/, CC(28)/-1.14604070350000E-10/,
     5     CC(29)/ 5.88004411500000E-11/, CC(30)/-6.78417843000000E-12/,
     6     CC(31)/-1.21572380900000E-11/, CC(32)/ 1.26561248700000E-11/,
     7     CC(33)/ 4.74814180000000E-13/, CC(34)/-5.32309477000000E-12/,
     8     CC(35)/ 9.05903810000000E-13/, CC(36)/ 1.40046450000000E-12/,
     9     CC(37)/-5.00968320000000E-13/, CC(38)/-1.80458040000000E-13/
      DATA CC(39)/ 1.66162910000000E-13/, CC(40)/-5.02616400000000E-14/,
     1     CC(41)/-3.48453600000000E-14/, CC(42)/ 4.60056600000000E-14/,
     2     CC(43)/ 5.74000000000000E-16/, CC(44)/-1.95310700000000E-14/,
     3     CC(45)/ 3.68837000000000E-15/, CC(46)/ 5.62862000000000E-15/
C     -------------------
C     ****** AMAX IS A MACHINE DEPENDENT CONSTANT. IT IS ASSUMED THAT
C            SIN(X) AND COS(X) ARE DEFINED FOR  ABS(X) .LE. AMAX, AND
C            THAT ECON + LN(X) - (1 + 1/X)/X = ECON + LN(X)
C            FOR X .GT. AMAX.
C
      AMAX = 0.1/SPMPAR(1)
C
C
      AX = ABS(X)
      IF (AX.GT.5.0) GO TO 20
      J=N1
      BX=0.40*AX-1.0
      TX=BX+BX
      B1=BB(J)
      B2=0.
      DO 10 I=1,M1
      J=J-1
      TEMP=B1
      B1=TX*B1-B2+BB(J)
   10 B2=TEMP
      CIN=X*X*(BX*B1-B2+BB(1))
      RETURN
C
   20 IF (AX.GT.AMAX) GO TO 50
      BX=10./AX-1.0
      TX=BX+BX
      J=N2
      B1=CC(J)
      B2=0.0
      DO 30 I=1,M2
      J=J-2
      TEMP=B1
      B1=TX*B1-B2+CC(J)
   30 B2=TEMP
      AIC=BX*B1-B2+CC(2)
C
      J=N2-1
      B1=CC(J)
      B2=0.0
      DO 40 I=1,M2
      J=J-2
      TEMP=B1
      B1=TX*B1-B2+CC(J)
   40 B2=TEMP
      RC=BX*B1-B2+CC(1)
C
      CIN=(RC*SIN(AX)-AIC*COS(AX))/AX
      CIN=(ECON-CIN)+ALOG(AX)
      RETURN
C
   50 CIN=ECON+ALOG(AX)
      RETURN
      END
