      subroutine sf_box_init(iuo,nsfcomp,nsfbox,ndimsf,nsfmax)
c alexei bazavov and bernd berg jan 25 2006.
c initialize component array for sfbox.
      include '../../libs/fortran/implicit.sta'
c     include '../../libs/fortran_par/sf.par'
c array with components of \vec{n}
c with nsfcomp(...,0)=n_1^2+n_2^2+...+n_ndimsf^2
      dimension nsfcomp(nsfbox,0:ndimsf)
c
      write(iuo,'(/,"sf_box_init: structure factors initialized:")')
      write(iuo,'(4x,"ndimsf =",i6)') ndimsf
      write(iuo,'(4x,"nsfmax =",i6)') nsfmax
      write(iuo,'(4x,"nsfbox =",i6)') nsfbox
c
c populate components
      do i=1,nsfbox
        nsfcomp(i,0)=0 ! decompose index into components:
        k=nsfbox
        iq=i-1
        do j=1,ndimsf
          k=k/(nsfmax+1)
          nsfcomp(i,j)=iq/k
          iq=mod(iq,k) ! calculate absolute value squared:
          nsfcomp(i,0)=nsfcomp(i,0)+nsfcomp(i,j)*nsfcomp(i,j)
        end do
      end do
c      
      write(iuo,'("integer vectors generated:")')
      write(iuo,'("      #    n^2      components....")')
      do i=1,nsfbox
        write(iuo,'(10i7)') i,(nsfcomp(i,j),j=0,ndimsf)
      end do
      write(iuo,'("sf_box_init done.",/)')
c      
      return
      end
