subroutine cxparam(jbe,jba,ngc_2,xzid)
  use nbi_com
  use nbi_random_pll
  use logmod
  implicit none
  ! convert indices jbe,jba,ngc_2 and nzoneid to  vion, xksid, xion, th (mc poloidal angle)
  ! includes some zone rows beyond the plasma boundary
  integer, intent(in) :: jbe,jba,ngc_2
  real(fp), intent(in) :: xzid ! zone id, if nxskpb=1 xzid = 1/2
                             ! else changes [1,nxskpb]. it was found in nbi_distrsample.f90
                             ! using snbx1d 
  integer :: i,nth,ith
  ! poloidal angles thbdy0, thbdy1 
  integer :: ngc_x,ng_c
  vion=sqrt(efbm(jbe,lsbeam)/v2toev)
  xksid= -1.0_fp + (jba-0.5_fp)*2.0_fp/(nznbma)


  do i=1,nznbmr
     if((nthzsm(lcentr+i-2)+1.le.0).or.(nthzsm(lcentr+i-1).gt.nfbzns)) cycle
     if(ngc_2.ge.nthzsm(lcentr+i-2)+1.and.ngc_2.le.nthzsm(lcentr+i-1)) then
        xion=(i-1)*nxskpb*dxi(lcentr,2)+xzid*dxi(lcentr,2)
        ngc_x=int(lcentr+xion*nzones)
        ng_c=min(lep1,ngc_x)
        nth=nthzsm(lcentr+i-1)-nthzsm(lcentr+i-2)
        ith = ngc_2 - nthzsm(lcentr+i-2)
        th=thbdy0+(ith-0.5_fp)*(thbdy1-thbdy0)/nth !thbdy0, thbdy1 defined in nbi_com (depend on nlsym2b)
        exit
     endif
  enddo

end subroutine cxparam
