C #######################################################
c     --- this subroutine adds a value to a linked list.
      subroutine addlnk(nstart, new, list)
      dimension list(1)

      list(new) = 0
      if (nstart .ne. 0) goto 10
      nstart = new
      goto 999
   10 continue
      n = nstart
   20 continue
      if (list(n) .eq. 0) goto 30
      n = list(n)
      goto 20
   30 continue
      list(n) = new
  999 continue

      return 
      end

C #######################################################
c************************* arg.for ***********************************
c
c function to determine the phase (argument) of a complex number.
c
c*********************************************************************
      function arg(c)
      complex c

      arg = atan2(aimag(c),real(c))

      return 
      end

C #######################################################
      complex function crdotp(cva, vb)
      complex cva(3)
      dimension vb(3)

      crdotp = ((cva(1) * vb(1)) + (cva(2) * vb(2))) + (cva(3) * vb(3))

      return 
      end

C #######################################################
c          kilroy was here
c
c      include 'pscrossp.inc/nolist'
c
      subroutine crossp(x, y, z)
      real x(1), y(1), z(1)
      
      z(1) = (x(2) * y(3)) - (x(3) * y(2))
      z(2) = (x(3) * y(1)) - (x(1) * y(3))
      z(3) = (x(1) * y(2)) - (x(2) * y(1))

      return 
      end

C #######################################################
      function dotp(x, y)
      real x(3), y(3)

      dotp = ((x(1) * y(1)) + (x(2) * y(2))) + (x(3) * y(3))

      return 
      end

C #######################################################
c******************* matvec.for **************************************
c
c purpose: to multiply a (3x3) matrix and a vector.
c
c*********************************************************************
      subroutine matvec(aa, vecin, vecout)     
      dimension aa(3, 3), vecin(3), vecout(3)

      do k = 1, 3
         vecout(k) = ((aa(1,k)*vecin(1)) + (aa(2,k)*vecin(2))) + (aa(3,
     &        k)*vecin(3))

      end do
      return 
      end

C #######################################################
      subroutine normze(x)
      real x(3)
      double precision xl, xx(3)

      do i=1,3
        xx(i) = x(i)
      end do

      xl = ((xx(1) ** 2) + (xx(2) ** 2)) + (xx(3) ** 2)
      xl = dsqrt(xl)

      if(xl .ne. 0.) then
         do j = 1, 3
            x(j) = xx(j) / xl
         end do
      else
         do j=1,3
            x(j) = 0.
         end do
      endif
      
      return 
      end

C #######################################################
      subroutine vecdif(u, v, w)
      dimension u(3), v(3), w(3)

      w(1) = u(1) - v(1)
      w(2) = u(2) - v(2)
      w(3) = u(3) - v(3)

      return 
      end

C #######################################################
      subroutine veclin(a, u, b, v, w)
      dimension u(3), v(3), w(3)

      w(1) = (a * u(1)) + (b * v(1))
      w(2) = (a * u(2)) + (b * v(2))
      w(3) = (a * u(3)) + (b * v(3))

      return 
      end

C #######################################################
c     --- function to compute the magnitude of a 3-dimensional vector
      function vecmag(a)
      dimension a(3)

      vecmag = sqrt( a(1)*a(1) + a(2)*a(2) + a(3)*a(3) )
      
      return
      end

C #######################################################
      subroutine vecscal(c, x, y)
      dimension x(3), y(3)

      y(1) = c * x(1)
      y(2) = c * x(2)
      y(3) = c * x(3)
      
      return 
      end

