!-----------------------------------------------------------------------
!  map12 -- map 1d profile onto 2d beam code grid
!
subroutine map12(zin1d,zout2d,itype)
  !
  use nbi_com
  !
  !============
  implicit none
  integer :: inumi,jz2,iz2,izr,jz1,iz1,j,iz
  !============
  real(fp) :: zvol,zsumin
  !============
  real(fp) :: zin1d(mj)	      ! input 1d profile
  real(fp) :: zout2d(mimxbz)   ! output 2d profile on beam grid
  !
  integer :: itype	      ! mapping options
  !
  !  itype=0 -- input is /cm3, output is not; i.e units out = cm3 * units
  !              in
  !  itype=1 --
  !
  !  itype=2 --
  !
  !-------------------------------------------------------
  !
  !  loop over beam radial zone rows that are inside the plasma
  !
  inumi=nznbmr-nxtbzn
  !
  jz2=lcm1
  iz2=nthzsm(lcm1)
  !
  do izr=1,inumi
  !
  !  transp 1d zones covered by row of beam 2d zones:
  !  typically nxskpb=2, i.e. each row of beam zones vs. theta covers
  !  two transp 1d flux zones, but has theta variation allowed.
  !
     jz1=jz2+1
     jz2=jz1+nxskpb-1
  !
  !  range of indices of 2d zones that define the radial row of zones
  !
     iz1=iz2+1
     iz2=nthzsm(izr+lcm1)
  !
     zvol=0.0_fp
     zsumin=0.0_fp
  !
  !  sum up profile input within beam zone row's range
  !  .. future itype dependence ? ..
  !
     do j=jz1,jz2
        zvol=zvol+dvolzc(j)
        zsumin=zsumin+zin1d(j)*dvolzc(j)
        
     end do
  !
  !  distribute the sum in the output array
  !  .. future itype dependence ? ..
  !
     do iz=iz1,iz2
        if(itype.eq.0) then
           zout2d(iz)=zsumin*bmvol(iz)/zvol
        else if(itype.eq.1) then
           zout2d(iz)=zsumin/zvol
        else
           write(nonlin,*) '?map12.for -- illegal argument "itype"'
           zout2d(iz)=0.0_fp
        end if

     end do
  !

  end do
!
  return
end subroutine map12
