subroutine nbo_smoo1(ztype,zdata)

  use nbi_com
  implicit none

  character*(*) ztype  ! type of data
  real(fp) zdata(mj)       ! data to be smoothed


  !  generic smoothing for 1d output profiles from nubeam
  !  smoothing parameter was set by prior r8bsmoo_init call

  !  ztype = "density" -- smooth to conserve total number
  !  ztype = "parameter" -- generic smooth
  !    anything else:  no smooth

  real(fp), dimension(:), allocatable :: z1,zinteg
  logical :: initz1 = .false.
  integer :: icount = 0

  save initz1,z1,zinteg,icount

  integer :: idtmp,ierr,j,jj
  real(fp) :: zdelx_sm
  integer, parameter :: inorm_vol = 1
  integer, parameter :: inorm_area= 2
  !===========================================

  if(.not.initz1) then
     allocate(z1(mj),zinteg(mj))
     z1=1
     zinteg=zero
     initz1=.true.
     icount = 0
  endif

  icount = icount + 1

  if(ztype.eq.'density') then
     !!! call r8bsmoo(zdata,dvolzc_r8)

     call r8bsmoo_get(zdelx_sm)
     if(zdelx_sm.le.zero) return

     jj=1
     zinteg(jj)=zero

     do j=lcentr,ledge
        jj=jj+1
        zinteg(jj)=zinteg(jj-1)+zdata(j)
     enddo

     call nbo_load1_xizb
     call eqm_irhofun_sm(id_rhozb,'_tmp_nbo_smoo1',nzp1,zinteg, &
          inorm_vol,zdelx_sm, idtmp, ierr)
     if(ierr.ne.0) then
        write(nonlin,*) ' ?nbo_smoo1("density") eqm_irhofun_sm error, call #',&
             icount
        write(nonlin,*) '  continuing but with no data smoothing.'
        return
     else
        call eq_rgetf(nzp1,xizb(lcentr:lep1),idtmp,0,zinteg(1:nzp1),ierr)
        if(ierr.ne.0) then
           write(nonlin,*) ' ?? nbo_smoo1: call #',icount, &
                ' eqm_irhofun_sm success must imply eq_rgetf success.'
           call errmsg_exit( &
                ' ?? nbo_smoo1(vol): irrecoverable error in eq_rgetf')
        endif
     endif

     jj=1
     do j=lcentr,ledge
        jj=jj+1
        zdata(j)=zinteg(jj)-zinteg(jj-1)
     enddo

  else if(ztype.eq.'curdens') then
     !!! call r8bsmoo(zdata,dareazc_r8)

     call r8bsmoo_get(zdelx_sm)
     if(zdelx_sm.le.zero) return

     jj=1
     zinteg(jj)=zero

     do j=lcentr,ledge
        jj=jj+1
        zinteg(jj)=zinteg(jj-1)+zdata(j)
     enddo

     call nbo_load1_xizb
     call eqm_irhofun_sm(id_rhozb,'_tmp_nbo_smoo1',nzp1,zinteg, &
          inorm_area,zdelx_sm, idtmp, ierr)
     if(ierr.ne.0) then
        write(nonlin,*) ' ?nbo_smoo1("curdens") eqm_irhofun_sm error, call #',&
             icount
        write(nonlin,*) '  continuing but with no data smoothing.'
     else
        call eq_rgetf(nzp1,xizb(lcentr:lep1),idtmp,0,zinteg(1:nzp1),ierr)
        if(ierr.ne.0) then
           write(nonlin,*) ' ?? nbo_smoo1: call #',icount, &
                ' eqm_irhofun_sm success must imply eq_rgetf success.'
           call errmsg_exit( &
                ' ?? nbo_smoo1(area): irrecoverable error in eq_rgetf')
        endif
     endif

     jj=1
     do j=lcentr,ledge
        jj=jj+1
        zdata(j)=zinteg(jj)-zinteg(jj-1)
     enddo

  else if(ztype.eq.'parameter') then

     call r8bsmoo(zdata,z1)

  endif

end subroutine nbo_smoo1
