      subroutine las2gsubkk( N1, N2, numran )
      parameter( MXM = 9, MXK = 256, NGS = 6912 )
      external dlavx2, dlsep2, dlspx2, dlafr2, dlsfr2
      common/dparam/ dvar, dpb, dthx, dthy, dthz
      data ifirst/1/, zero/0.0/, four/4.0/
      integer numran

   k1 = N1
   k2 = N2
   do m = 0, MXM
         kk = k1*k2
         if( kk .le. MXK ) exit
         j1 = k1/2
         j2 = k2/2
         if( 2*j1 .ne. k1 .or. 2*j2 .ne. k2 ) write(*,*)'error'
         k1 = j1
         k2 = j2
   enddo

   NN = N1*N2

!-------------------------------------- generate realization -----------------
      if( mod(M,2) .eq. 0 ) then
         iz = 0
         jz = NN
      else
         iz = NN
         jz = 0
      endif
!					generate stage 0 field
      numran=kk

!					generate stage 1, 2, ..., M sub-fields
      jx = k1
      jy = k2
      nm = 1
      if( (k1.eq.1 .or. k2.eq.1) .and. M .gt. 0 ) then
         jq = max0(k1,k2)
         numran=numran+3*jq
         it = jz
         jz = iz
         iz = it
         ix = 2*k1
         iy = 2
         if( k1 .eq. 1 ) iy = 4
         jx = 2*k1
         jy = 2*k2
         nm = 2
      endif

      do 80 i = nm, M
!						swap current and prev fields
         it = jz
         jz = iz
         iz = it
!						new field dimensions
         ix = 2*jx
         iy = 2*jy
         numran=numran+3*jx
         do 60 ks = 1, jy-2
            numran=numran+3*jx
  60     continue
         numran=numran+3*jx
         jx = ix
         jy = iy
  80  continue
      return
      end