subroutine nubeam_xstraln_init(izp1,id_mcgrid,ionlin,iersum)
  use iso_c_binding, only: fp => c_double
  !
  !  update the bilinear inverse map (r,y)-->(xi,theta) for flr, etc.
  !
  use xstraln_calls
  implicit none


  integer, intent(in) :: izp1 ! nubeam radial surface count
  integer, intent(in) :: id_mcgrid ! 2d (xplasma) grid id
  integer, intent(in) :: ionlin ! lun for messages
  integer, intent(out) :: iersum ! error sum (0: no errors)
  !
  !  izp1 = nzones+1
  !
  !---------------------------------------------------
  integer :: ierr
  integer :: inumrho,inumth,id__r=0,inrxinv,id__z=0,inyxinv
  real(fp) :: ztol
  !---------------------------------------------------
  iersum=0
  !
  inumrho=60          ! for now...
  inumth=2*inumrho
  !
  call eq_ganum('__rgrid',id__r)
  call eq_ngrid(id__r,inrxinv)
  inrxinv=max(40,inrxinv-4)
  !
  call eq_ganum('__zgrid',id__z)
  call eq_ngrid(id__z,inyxinv)
  inyxinv=max(40,inyxinv-4)
  !
  call xstraln_init(1,inumrho,inumth,inrxinv,inyxinv,ierr)
  if(ierr.ne.0) write(ionlin,*) '??parms: xstraln_init failure.'
  if(ierr.ne.0) write(ionlin,*) '  ierr = ',ierr
  iersum=iersum+abs(ierr)
  !
  ztol=1.0e-2_fp  ! polar map faster & ok -- obtained by using largish ztol
  !
  call xstraln_setup(ztol,ierr)
  if(ierr.ne.0) write(ionlin,*) '??parms: xstraln_setup failure.'
  if(ierr.ne.0) write(ionlin,*) '  ierr = ',ierr
  iersum=iersum+abs(ierr)
  !
  call xstraln_2d_init(izp1,id_mcgrid,ierr)
  if(ierr.ne.0) write(ionlin,*) '??parms: xstraln_2d_init failure.'
  if(ierr.ne.0) write(ionlin,*) '  ierr = ',ierr
  iersum=iersum+abs(ierr)
  !
  return
end subroutine nubeam_xstraln_init

