subroutine r8_boxn0_return(zboxn0,iwant,ierr)
 
  use nbi_com
  implicit none
 
  !  return results of "beam in box" calculation
  !  i.e. neutral densities in front of one or more beamlines in a 3d
  !  cartesian grid
 
  integer, intent(in) :: iwant   ! caller's expected size of results
  real(fp), intent(out) :: zboxn0(iwant)  ! returned copy of calculation results
  integer, intent(out) :: ierr   ! completion code, 0=ok
 
  !  ierr is set if the caller's expected size of results differs from
  !       the internal calculation; if ierr is set, zboxn0 is untouched.
 
  !$r8real_output: zboxn0
  !---------------------------------------------
  !  local:
 
  integer isize
 
  !---------------------------------------------
 
  isize=nbbox*nxbox*nybox*nlbox
  if(levmod_halo.eq.2.and.nsplt.gt.0) then
     isize=isize*3
  endif
 
  ierr=0
  if(isize.ne.iwant) then
     ierr=1
     write(nonlin,*) ' ?boxn0_return: results size inconsistency.'
     write(nonlin,*) '  caller wants ',iwant,' numbers, but...'
     write(nonlin,*) '  we calculated ',isize,' numbers.'
     return
  endif
 
  if(isize.eq.0) return
  if(allocated(boxn0)) then
     
     zboxn0(1:isize)=boxn0(1:isize)
  else
     ierr=1
  endif
  return
end subroutine r8_boxn0_return
