subroutine nbi_get_dpsidrho(inum,zxi,zdpsidrho)

  !  get dpsi/drho based on qgeo & tflux

  use nbi_com
  implicit none

  integer, intent(in) :: inum     ! number of values
  real(fp), intent(in) :: zxi(inum) ! sqrt(phi/philim) values
  real(fp), intent(out) :: zdpsidrho(inum) ! dpsi/dx = x*tflux/(qgeo*pi)

  ! this is used by nbspline; the grid will match the nbi_com grid, 
  ! we think.  check...

  integer :: i,j
  real(fp) :: zdiff
  real(fp), parameter :: maxtol = 1.0d-7

  !--------------------------
  if(inum.ne.nzp1) then
     write(nonlin,*) ' ?? nbi_get_dpsidrho: inum.ne.nzp1: ',inum,nzp1
     zdpsidrho = 0
     return
  endif

  zdiff = 0.0_fp
  do j=lcentr,lep1
     i = j - lcentr + 1
     zdiff = max(zdiff,abs(xizb(j)-zxi(i)))
  enddo

  if(zdiff.gt.maxtol) then
     write(nonlin,*) ' ?? nbi_get_dpsidrho:  xi mismatch: '
     write(nonlin,*) '  #  xi(nubeam)    xi(arg)     abs(diff)'
     do j=lcentr,ledge
        i = j - lcentr + 1
        write(nonlin,*) i,xizb(j),zxi(i),abs(xizb(j)-zxi(i))
     enddo
     zdpsidrho = 0.0_fp
     return
  endif

  !  ok

  do j=lcentr,lep1
     i = j - lcentr + 1
     zdpsidrho(i) = xizb(j)*tflux/(qgeo(j)*xpi)
  enddo

end subroutine nbi_get_dpsidrho
