      program K1nm ! BB Apr 5 2012..
C 1D Knm matrix of the scalar field. Rothe p.30.
      include '../../Libs/Fortran/implicit.sta'
      include '../../Libs/Fortran/constants.par'
      parameter(iuo=6,nx=6,nxm1=nx-1,dkx=tpi/nx)
      parameter(xm=half) ! xm Mass.
      dimension XKnm(nx,nx),XKInm(nx,nx),XI(nx,nx),B(nx)
      ltest=.true.
      ltest=.false.
      if(ltest) stop "K1nm: ltest."
      write(iuo,'(/," 1D case Knm matrix Rothe p.30",/)') 
      write(iuo,'(" Direct use of delta functions:",/)') 
      do n=1,nx
        np1=n+1
        nm1=n-1
        if(np1.gt.nx) np1=1 ! Periodic BC.
        if(nm1.lt.1) nm1=nx ! Periodic BC.
        do m=1,nx
          XKnm(n,m)=two*del(n,m)-del(np1,m)-del(nm1,m)+xm**2*del(n,m)
          XKInm(n,m)=XKnm(n,m)
        enddo
        write(iuo,'(7F10.6)') (XKnm(n,m),m=1,nx)
      enddo
C Inverse matrix:
      write(iuo,'(/," Inverse matrix:",/)') 
      call mat_gau(XKInm,nx,B,izero)
      do n=1,nx
        write(iuo,'(7F10.6)') (XKInm(n,m),m=1,nx)
      enddo
      write(iuo,'(/," Test of inverse matrix:",/)') 
      do n=1,nx
        do m=1,nx
          XI(n,m)=zero
          do i=1,nx
            XI(n,m)=XI(n,m)+XKInm(n,i)*XKnm(i,m)
          enddo   
        enddo
        write(iuo,'(7F10.6)') (XI(n,m),m=1,nx)
      enddo
      write(iuo,'(/," All done.",/)') 
      stop
      end

      function del(n,m)
      include '../../Libs/Fortran/implicit.sta'
      include '../../Libs/Fortran/constants.par'
      del=zero
      if(n.eq.m) del=one
      return
      end

      include '../../Libs/Fortran/mat_gau.f'

