      subroutine lat2b_init(iuo,my_id,ns,nd,ipf,ipb,nla,ix) 
C Bernd Berg Jun 05 2008.  For nlat=2 and lat2=.true. only: 
C Couples boundaries of lattice 1 and 2. 
      include '../../Libs/Fortran/implicit.sta'
      include 'mpif.h'
c     parameter(nd2=3,ns2=16) ! For test only. Delete!
c     dimension iwf(nd2,ns2),iwb(nd2,ns2) ! For test only. Delete!
      dimension ipf(nd,2*ns),ipb(nd,2*ns),nla(nd),ix(nd)
      ltest=.true.
      ltest=.false.
      if(ltest.and.my_id.eq.0) write(iuo,'("lat2b_init entered")') 
C
      if(ns.ne.nsfun(nla,nd)) then 
        if(my_id.eq.0) write(iuo,'("nd,ns,nla:",6I10)') nd,ns,nla
        if(my_id.eq.0) write(iuo,'("lat2b_init: ns-nla mismatch.")') 
        call mpi_finalize(ierr)
      stop
      end if
      if(ltest.and.my_id.eq.0) then
        write(iuo,'(/,"lat2b_init with ltest=.true.:")')
        write(iuo,'(/,2X,"nd,ns,nla:",6I6)') nd,ns,nla
c       write(iuo,'(/,2X,"entry pointers backed up on iwf and iwb")')
c       write(iuo,'(/,2X,"is isl",4X,"ix, iwf, iwb, ipf, ipb:",/)')
      endif
C
C  Test out the pointers:
c     do is=1,2*ns
c       do id=1,nd
c         iwf(id,is)=ipf(id,is)
c         iwb(id,is)=ipb(id,is)
c         itest=ipb(id,ipf(id,is))
c         if(itest.ne.is) then
c           if(my_id.eq.0) write(iuo,'("1. itest,is =",2I10)') itest,is
c           if(my_id.eq.0) write(iuo,'("lat2b_init: itest.ne.is.")') 
c           call mpi_finalize(ierr)
c         stop
c         end if
c       enddo
c     enddo
C 
      do is=1,ns
        iis=is+ns
        call ixcor(ix,nla,is,nd)
        do id=1,nd
          if(ix(id).eq.nla(id)-1) then
            ipf(id,iis)=ipf(id,is)
            ipf(id,is)=ipf(id,iis)+ns
          endif
          if(ix(id).eq.0) then
            ipb(id,iis)=ipb(id,is)
            ipb(id,is)=ipb(id,iis)+ns
          endif
        enddo
      enddo
C  Test out the pointers:
      do is=1,2*ns
        islat=1+mod(is-1,ns)
        call ixcor(ix,nla,islat,nd)
        do id=1,nd
          itest=ipb(id,ipf(id,is))
          if(itest.ne.is) then
            if(my_id.eq.0) write(iuo,'("2. itest,is =",2I10)') itest,is
            if(my_id.eq.0) write(iuo,'("lat2b_init: itest.ne.is.")') 
            call mpi_finalize(ierr)
          stop
          end if
        enddo
c       if(ltest.and.my_id.eq.0) write(iuo,'(I4,I3,3X,20I3)') is,islat,
c    &    ix,(iwf(id,is),id=1,nd),(iwb(id,is),id=1,nd),
c    &       (ipf(id,is),id=1,nd),(ipb(id,is),id=1,nd)
      enddo
C 
      if(ltest.and.my_id.eq.0) write(iuo,'(/,"lat2b_init done.",/)')
      if(ltest) then
        if(my_id.eq.0) write(iuo,'("lat2b_init stop: ltest.")')
        call mpi_finalize(ierr)
      stop
      endif
C
      return
      end
