C23456789012345678901234567890123456789012345678901234567890123456789012
C
C         Recurrences using the loopraking method (Fortran version)
C         Marco Zagha (marcoz@cs.cmu.edu)
C         Started 3/16/93
C         Updated 11/29/93 
C
C         Note that this stuff only works for exact multiples of the stride
C23456789012345678901234567890123456789012345678901234567890123456789012

      real function raker1last(d,sum,s,nrows,ncols)
      integer nrows,ncols
      real d(nrows,ncols),s(nrows,ncols),sum(ncols)
      integer i,j
      real total
      
      do i = 1,ncols
         sum(i) = 0.0
      end do

      do i = 1,nrows-7,8
         do j = 1,ncols
            sum(j) = sum(j) 
     $           + s(i  ,j) + s(i+1,j) + s(i+2,j) + s(i+3,j)
     $           + s(i+4,j) + s(i+5,j) + s(i+6,j) + s(i+7,j)
         end do
      end do
      do i = nrows-mod(nrows,8)+1,nrows
         do j = 1,ncols
            sum(j) = sum(j) + s(i,j)
         end do
      end do

      total = 0.0
      do j = 1,ncols
         total = total + sum(j)
      end do

      raker1last = total
      
      return
      end



      subroutine raker1all(d,sum,s,nrows,ncols)
      integer nrows,ncols
      real d(nrows,ncols),s(nrows,ncols),sum(ncols)
      integer i,j
      real total, elt
      
      do i = 1,ncols
         sum(i) = 0.0
      end do

      do i = 1,nrows-7,8
         do j = 1,ncols
            sum(j) = sum(j) 
     $           + s(i  ,j) + s(i+1,j) + s(i+2,j) + s(i+3,j)
     $           + s(i+4,j) + s(i+5,j) + s(i+6,j) + s(i+7,j)
         end do
      end do
      do i = nrows-mod(nrows,8)+1,nrows
         do j = 1,ncols
            sum(j) = sum(j) + s(i,j)
         end do
      end do

      total = 0.0
      do j = 1,ncols
         elt = sum(j)
         sum(j) = total
         total = total + elt
      end do

      do i = 1,nrows-7,8
         do j = 1,ncols
            d(i,j) = sum(j)
            d(i+1,j) = d(i  ,j) + s(i  ,j)
            d(i+2,j) = d(i+1,j) + s(i+1,j)
            d(i+3,j) = d(i+2,j) + s(i+2,j)
            d(i+4,j) = d(i+3,j) + s(i+3,j)
            d(i+5,j) = d(i+4,j) + s(i+4,j)
            d(i+6,j) = d(i+5,j) + s(i+5,j)
            d(i+7,j) = d(i+6,j) + s(i+6,j)
            sum(j) =   d(i+7,j) + s(i+7,j)
         end do
      end do
      do i = nrows-mod(nrows,8)+1,nrows
         do j = 1,ncols
            d(i,j) = sum(j)
            sum(j) = sum(j) + s(i,j)
         end do
      end do
      
      return
      end

C23456789012345678901234567890123456789012345678901234567890123456789012

      subroutine raker1Call(d,sum,prod,s,b,nrows,ncols)
      integer nrows,ncols
      real d(nrows,ncols),s(nrows,ncols),b(nrows,ncols)
      real sum(ncols),prod(ncols)
      integer i,j
      real sumelt, prodelt, sprod, ssum
      
      do i = 1,ncols
         sum(i) = 0.0
         prod(i) = 1.0
      end do

      do i = 1,nrows-1,2
         do j = 1,ncols
            sum(j) = (sum(j) * s(i,j) + b(i,j)) * s(i+1,j) + b(i+1,j)
            prod(j) = prod(j) * s(i,j) * s(i+1,j)
         end do
      end do
      do i = nrows-mod(nrows,2)+1,nrows
         do j = 1,ncols
            sum(j) = sum(j) * s(i,j) + b(i,j)
            prod(j) = prod(j) * s(i,j)
         end do
      end do

      sprod = 1.0
      ssum = 0.0
      do j = 1,ncols
         prodelt = prod(j)
         sprod = sprod * prodelt
         sumelt = sum(j)
         sum(j) = ssum
         ssum = ssum * prodelt + sumelt
      end do

      do i = 1,nrows-3,4
         do j = 1,ncols
            d(i,j) = sum(j) 
            d(i+1,j) = d(i  ,j) * s(i  ,j) + b(i  ,j)
            d(i+2,j) = d(i+1,j) * s(i+1,j) + b(i+1,j)
            d(i+3,j) = d(i+2,j) * s(i+2,j) + b(i+2,j)
            sum(j) =   d(i+3,j) * s(i+3,j) + b(i+3,j)
         end do
      end do
      do i = nrows-mod(nrows,4)+1,nrows
         do j = 1,ncols
            d(i,j) = sum(j) 
            sum(j) = sum(j) * s(i,j) + b(i,j)
         end do
      end do
      
      return
      end

C23456789012345678901234567890123456789012345678901234567890123456789012

      real function raker1Clast(d,sum,prod,s,b,nrows,ncols)
      integer nrows,ncols
      real d(nrows,ncols),s(nrows,ncols),b(nrows,ncols)
      real sum(ncols),prod(ncols)
      integer i,j
      real sumelt, prodelt, sprod, ssum
      
      do i = 1,ncols
         sum(i) = 0.0
         prod(i) = 1.0
      end do

      do i = 1,nrows-1,2
         do j = 1,ncols
            sum(j) = (sum(j) * s(i,j) + b(i,j)) * s(i+1,j) + b(i+1,j)
            prod(j) = prod(j) * s(i,j) * s(i+1,j)
         end do
      end do
      do i = nrows-mod(nrows,2)+1,nrows
         do j = 1,ncols
            sum(j) = sum(j) * s(i,j) + b(i,j)
            prod(j) = prod(j) * s(i,j)
         end do
      end do

      sprod = 1.0
      ssum = 0.0
      do j = 1,ncols
         prodelt = prod(j)
         sprod = sprod * prodelt
         sumelt = sum(j)
         ssum = ssum * prodelt + sumelt
      end do

      raker1Clast = ssum

      return
      end


C23456789012345678901234567890123456789012345678901234567890123456789012

      real function raker2last(d,v11,v22,v21,v12,s,b,nrows,ncols)
      integer nrows,ncols
      real d(nrows,ncols)
      real s(nrows,ncols),b(nrows,ncols)
      real v11(ncols),v22(ncols),v21(ncols),v12(ncols)
      real temp
      real sx1, sx2, snewx1
      integer i,j
      
      do j = 1,ncols
         v11(j)    = 1.0
         v22(j)    = 1.0
         v21(j)    = 0.0
         v12(j)    = 0.0
      end do
      
      do i = 1,nrows-3,4
         do j = 1,ncols
            v12(j) = v11(j) * s(i,j) + v12(j) * b(i,j)
            v22(j) = v21(j) * s(i,j) + v22(j) * b(i,j)
            v11(j) = v12(j) * s(i+1,j) + v11(j) * b(i+1,j)
            v21(j) = v22(j) * s(i+1,j) + v21(j) * b(i+1,j)

            v12(j) = v11(j) * s(i+2,j) + v12(j) * b(i+2,j)
            v22(j) = v21(j) * s(i+2,j) + v22(j) * b(i+2,j)
            v11(j) = v12(j) * s(i+3,j) + v11(j) * b(i+3,j)
            v21(j) = v22(j) * s(i+3,j) + v21(j) * b(i+3,j)
         end do
      end do
      do i = nrows-mod(nrows,4)+1,nrows
         do j = 1,ncols
            v12(j) = v11(j) * s(i,j) + v12(j) * b(i,j)
            v22(j) = v21(j) * s(i,j) + v22(j) * b(i,j)
            temp = v12(j)
            v12(j) = v11(j) 
            v11(j) = temp
            temp = v22(j)
            v22(j) = v21(j) 
            v21(j) = temp
         end do
      end do


      sx1 = 1.0
      sx2 = 1.0
      do j = 1,ncols
         snewx1 = sx1 * v11(j) + sx2 * v21(j)
         sx2 = sx1 * v12(j) + sx2 * v22(j)
         sx1 = snewx1
      end do
      raker2last = sx1
      return
      end

C23456789012345678901234567890123456789012345678901234567890123456789012

      subroutine raker2all(d,v11,v22,v21,v12,s,b,nrows,ncols)
      integer nrows,ncols
      real d(nrows,ncols)
      real s(nrows,ncols),b(nrows,ncols)
      real v11(ncols),v22(ncols),v21(ncols),v12(ncols)
      real temp, sa, sb
      real sx1, sx2, snewx1
      integer i,j
      
      do j = 1,ncols
         v11(j)    = 1.0
         v22(j)    = 1.0
         v21(j)    = 0.0
         v12(j)    = 0.0
      end do
      
      do i = 1,nrows-3,4
         do j = 1,ncols
            v12(j) = v11(j) * s(i,j) + v12(j) * b(i,j)
            v22(j) = v21(j) * s(i,j) + v22(j) * b(i,j)
            v11(j) = v12(j) * s(i+1,j) + v11(j) * b(i+1,j)
            v21(j) = v22(j) * s(i+1,j) + v21(j) * b(i+1,j)

            v12(j) = v11(j) * s(i+2,j) + v12(j) * b(i+2,j)
            v22(j) = v21(j) * s(i+2,j) + v22(j) * b(i+2,j)
            v11(j) = v12(j) * s(i+3,j) + v11(j) * b(i+3,j)
            v21(j) = v22(j) * s(i+3,j) + v21(j) * b(i+3,j)
         end do
      end do
      do i = nrows-mod(nrows,4)+1,nrows
         do j = 1,ncols
            v12(j) = v11(j) * s(i,j) + v12(j) * b(i,j)
            v22(j) = v21(j) * s(i,j) + v22(j) * b(i,j)
            temp = v12(j)
            v12(j) = v11(j) 
            v11(j) = temp
            temp = v22(j)
            v22(j) = v21(j) 
            v21(j) = temp
         end do
      end do

      sx1 = 1.0
      sx2 = 1.0
      do j = 1,ncols
         sa = v11(j)
         v11(j) = sx1
         sb = v21(j)
         v21(j) = sx2
         snewx1 = sx1 * sa + sx2 * sb
         sx2 = sx1 * v12(j) + sx2 * v22(j)
         sx1 = snewx1
      end do
      do i = 1,nrows-7,8
         do j = 1,ncols
            v21(j) = v11(j) * s(i,j) + v21(j) * b(i,j)
            d(i,j) = v21(j)
            v11(j) = v21(j) * s(i+1,j) + v11(j) * b(i+1,j)
            d(i+1,j) = v11(j)
            v21(j) = v11(j) * s(i+2,j) + v21(j) * b(i+2,j)
            d(i+2,j) = v21(j)
            v11(j) = v21(j) * s(i+3,j) + v11(j) * b(i+3,j)
            d(i+3,j) = v11(j)

            v21(j) = v11(j) * s(i+4,j) + v21(j) * b(i+4,j)
            d(i+4,j) = v21(j)
            v11(j) = v21(j) * s(i+5,j) + v11(j) * b(i+5,j)
            d(i+5,j) = v11(j)
            v21(j) = v11(j) * s(i+6,j) + v21(j) * b(i+6,j)
            d(i+6,j) = v21(j)
            v11(j) = v21(j) * s(i+7,j) + v11(j) * b(i+7,j)
            d(i+7,j) = v11(j)
         end do
      end do
      do i = nrows-mod(nrows,8)+1,nrows
         do j = 1,ncols
            v21(j) = v11(j) * s(i,j) + v21(j) * b(i,j)
            d(i,j) = v21(j)
            temp = v21(j)
            v21(j) = v11(j)
            v11(j) = temp
         end do
      end do

      return
      end

