      program cisc320
      integer*4 tm(3)
      integer i, k, n, m, a(9500)
      double precision t, c, d, e, rt
      double precision ansort
      d = 250102.85
      call itime(tm)
      i = rand ( tm(1) + tm(2) + tm(3) )
      do n = 12, 17
        m = 1000 + 500 * n
        t = 0.0
        do k = 1, 20
          do i = 1, m
            a(i) = rand(0) * 32768
c     uncomment this to make sure rand is working:
c           print *, n, m, k, i, a(i)
          end do
          rt = ansort(a,m)
          t = t + rt
        end do
        c = 0.05 * t
        print *, m, ' elem, ', c, ' ops'
        if (n.eq.0) then
          d = c
        else
          if (n.eq.16) then
            e = c
          endif
        endif
      end do
      d = c + ( c - d ) / 17.0
      e = c + c - e
      print *, 'for 10K elem, affine: ', d, ', extrap: ', e
      end

      function ansort(a,n)
      double precision c, ansort
      integer i, j, v, a(9500), n
      c = 0.0
      do i = 2, n
        v = a(i)
        c = c + 1.0
        j = i - 1
1       if (j.lt.1) then
          go to 3
        endif
        if (a(j).gt.v) then
          go to 2
        else
          go to 3
        endif
2       a(j+1) = a(j)
        j = j - 1
        c = c + 1.0
        go to 1
3       a(j+1) = v
      end do
      ansort = c
      return
      end

