      SUBROUTINE gratio(a,x,qans)
      IMPLICIT NONE
      DOUBLE PRECISION a,x,rtx,ans,qans,c,t,sum,rtpi,z
      DOUBLE PRECISION erf1,erfc1
      INTEGER i, n
      DATA rtpi/1.77245385090552D0/
C
C             FINITE SUMS FOR Q WHEN A .GE. 1
C                 AND 2*A IS AN INTEGER
C
      rtx = sqrt(x)
      i = int(a+a)/2
C
      IF (a.EQ.dble(i)) THEN
        t = exp(-x)
        sum = t
        n = 1
        c = 0.0D0
        z = 0.0D0
      ELSE
        t = exp(-x)/(rtpi*rtx)
        sum = 0.0d0
        n = 0
        c = -0.5D0
        z = erfc1(0,rtx)
      END IF
C
  230 IF (n.EQ.i) GO TO 240
      n = n + 1
      c = c + 1.0D0
      t = (x*t)/c
      sum = sum + t
      GO TO 230

  240 qans = sum + z
      RETURN
      END

