subroutine nubeam_ctrl_substep(ierr)

  ! this routine can be called by rank > 0 processes in an mpi jobs
  ! to advance a sublist one step
  ! called from trmpi_listener

  use nbi_pstypes
  use nbi_mpi_com
  use nbi_com
  use mpi_proc_data
  use logmod

  implicit none
  integer, intent(out) :: ierr

  ! local
  logical  ::  have_group
  integer  ::  grp_comm
  integer  ::  grp_rank

  !---------------------------------

  ! check if in nubeam group (test programs dont use groups)
  ! use mpi_proc_info instead of trmpi_group to avoid linking in trmpi
  call mpi_proc_info('NUBEAM',have_group,grp_comm,irank=grp_rank)
  if (have_group) then
     if (grp_rank.gt.0) then
        nbi_comm=grp_comm
     ! should not have been called if not a member of group 
     else if (grp_rank.eq.0) then
        call errorlog('nubeam_ctrl_substep called by nubeam rank=',grp_rank)
        ierr = 1
        return
     else
        call errorlog('nubeam_ctrl_substep called but not in group nubeam')
        ierr = 1
        return
     endif
  endif

  call nbi_mpi_com_init

  if(myidd.eq.0) then
     write(nout,*) ' ?nubeam_ctrl_substep: called by rank 0 cpu.'
     ierr = 1

  else

     call nubeam_ctrl_step_child(ierr)

  endif
  return

end subroutine nubeam_ctrl_substep
