! written by nbigen.py
! *** do not edit *** (use nbigen.py instead)
 
subroutine nbi_zcheck_orb
  use nbi_com
  use nbi_pllbuf
  implicit NONE
 
  integer ir,ib,inum
 
  inum = 0
  nbuf_data = 0
  nbuf_orb = 0
 
  call r8nz(dxsm_kdsaw(lcentr:lep1,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in dxsm_kdsaw(lcentr:lep1,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(dxwt_kdsaw(lcentr:lep1,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in dxwt_kdsaw(lcentr:lep1,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(wsum_kdspre(lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in wsum_kdspre(lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(wsum_kdspost(lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in wsum_kdspost(lsbeam) at lsbeam=",lsbeam
  endif
 
  do ib=1,nbeam
     if(lsbeama(ib).eq.lsbeam) then
        call r8nz(wts_ien(1:3,ib),inum)
        if (inum.ne.0) then
           write(nonlin,*) &
               "non-zero value in wts_ien(1:3,ib) at ib=",ib
        endif
     endif
  enddo
 
  call r8nz(ebb_rel_co(1:mimxbzf,1:3,1:nbeam,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in ebb_rel_co(1:mimxbzf,1:3,1:nbeam,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(ebb_rel2_co(1:mimxbzf,1:3,1:nbeam,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in ebb_rel2_co(1:mimxbzf,1:3,1:nbeam,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(ebb_rel_cnt(1:mimxbzf,1:3,1:nbeam,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in ebb_rel_cnt(1:mimxbzf,1:3,1:nbeam,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(ebb_rel2_cnt(1:mimxbzf,1:3,1:nbeam,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in ebb_rel2_cnt(1:mimxbzf,1:3,1:nbeam,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(bnb_ien2(1:mimxbzf,1:2,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in bnb_ien2(1:mimxbzf,1:2,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(ebb_rel_fn(1:mimxbzf,1:3,1:nbeam,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in ebb_rel_fn(1:mimxbzf,1:3,1:nbeam,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(ebb_rel2_fn(1:mimxbzf,1:3,1:nbeam,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in ebb_rel2_fn(1:mimxbzf,1:3,1:nbeam,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(bnb_fn(1:mimxbzf,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in bnb_fn(1:mimxbzf,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(orb_code_error(lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in orb_code_error(lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(xnorbs(lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in xnorbs(lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(dt_adj0_sums(lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in dt_adj0_sums(lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(xnum_dt_adj0(lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in xnum_dt_adj0(lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(xmcloss_o(lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in xmcloss_o(lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(wtqbxfs(lcentr:lep1,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in wtqbxfs(lcentr:lep1,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(bntots(lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in bntots(lsbeam) at lsbeam=",lsbeam
  endif
 
  do ir=1,mireact
     if(lsbeamr(ir).eq.lsbeam) then
        call r8nz(btntn2(1:mimxbz,ir),inum)
        if (inum.ne.0) then
           write(nonlin,*) &
               "non-zero value in btntn2(1:mimxbz,ir) at ir=",ir
        endif
     endif
  enddo
 
  call r8nz(wgvdx(lcentr:lep1,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in wgvdx(lcentr:lep1,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(hexbbxrc(1:mimxbz,lsbeam,1:nsfast),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in hexbbxrc(1:mimxbz,lsbeam,1:nsfast) at lsbeam=",lsbeam
  endif
 
 
  call r8nz(sn00i2(1:nbeam,1:3,1:mimxbzf,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in sn00i2(1:nbeam,1:3,1:mimxbzf,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(sn00x2(1:nbeam,1:3,1:mimxbzf,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in sn00x2(1:nbeam,1:3,1:mimxbzf,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(snb0i2(1:mimxbz,1:ng,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in snb0i2(1:mimxbz,1:ng,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(snbn02(1:mimxbz,1:ng,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in snbn02(1:mimxbz,1:ng,lsbeam) at lsbeam=",lsbeam
  endif
 
  if(levmod_halo.eq.2) then
     call r8nz(svn3vii_h(1:mimxbe0,1:mimxba0,1:mgyro,1:mimxbzf,lsbeam),inum)
     if (inum.ne.0) then
        write(nonlin,*) "non-zero value in svn3vii_h(1:mimxbe0,1:mimxba0,1:mgyro,1:mimxbzf,lsbeam) at lsbeam=",lsbeam
     endif
  endif
 
  if(levmod_halo.eq.2) then
     call r8nz(svn3vii_he(1:mimxbe0,1:mimxba0,1:mgyro,1:mimxbzf,lsbeam),inum)
     if (inum.ne.0) then
        write(nonlin,*) "non-zero value in svn3vii_he(1:mimxbe0,1:mimxba0,1:mgyro,1:mimxbzf,lsbeam) at lsbeam=",lsbeam
     endif
  endif
 
  if(levmod_halo.eq.2) then
     call r8nz(svn3vcx_h(1:mimxbe0,1:mimxba0,1:mgyro,1:mimxbzf,lsbeam),inum)
     if (inum.ne.0) then
        write(nonlin,*) "non-zero value in svn3vcx_h(1:mimxbe0,1:mimxba0,1:mgyro,1:mimxbzf,lsbeam) at lsbeam=",lsbeam
     endif
  endif
 
  if(levmod_halo.eq.2) then
     call r8nz(svn3vcx_he(1:mimxbe0,1:mimxba0,1:mgyro,1:mimxbzf,lsbeam),inum)
     if (inum.ne.0) then
        write(nonlin,*) "non-zero value in svn3vcx_he(1:mimxbe0,1:mimxba0,1:mgyro,1:mimxbzf,lsbeam) at lsbeam=",lsbeam
     endif
  endif
 
  call r8nz(wtrap(lcentr:lep1,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in wtrap(lcentr:lep1,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(wtrape(lcentr:lep1,1:miefi,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in wtrape(lcentr:lep1,1:miefi,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(xcrb2c(1:mimxbz,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in xcrb2c(1:mimxbz,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(xcurb2(1:mimxbz,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in xcurb2(1:mimxbz,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(enolds(lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in enolds(lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(fpixbts(lcentr:lep1,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in fpixbts(lcentr:lep1,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(tirtots(lcentr:lep1,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in tirtots(lcentr:lep1,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(wnlight(lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in wnlight(lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(wnlkill(lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in wnlkill(lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(wndoubl(lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in wndoubl(lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(pljbbms(lcentr:lep1,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in pljbbms(lcentr:lep1,lsbeam) at lsbeam=",lsbeam
  endif
 
  do ib=1,nbeam
     if(lsbeama(ib).eq.lsbeam) then
        call r8nz(pljbbm_nb(lcentr:lep1,ib),inum)
        if (inum.ne.0) then
           write(nonlin,*) &
               "non-zero value in pljbbm_nb(lcentr:lep1,ib) at ib=",ib
        endif
     endif
  enddo
 
  call r8nz(pljbcct(lcentr:lep1,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in pljbcct(lcentr:lep1,lsbeam) at lsbeam=",lsbeam
  endif
 
  do ir=1,mireact
     if(lsbeamr(ir).eq.lsbeam) then
        call r8nz(btntns(lcentr:lep1,ir),inum)
        if (inum.ne.0) then
           write(nonlin,*) &
               "non-zero value in btntns(lcentr:lep1,ir) at ir=",ir
        endif
     endif
  enddo
 
  do ir=1,mireact
     if(lsbeamr(ir).eq.lsbeam) then
        call r8nz(btntrs(lcentr:lep1,ir),inum)
        if (inum.ne.0) then
           write(nonlin,*) &
               "non-zero value in btntrs(lcentr:lep1,ir) at ir=",ir
        endif
     endif
  enddo
 
  do ir=1,mireact
     if(lsbeamr(ir).eq.lsbeam) then
        call r8nz(btntws(lcentr:lep1,ir),inum)
        if (inum.ne.0) then
           write(nonlin,*) &
               "non-zero value in btntws(lcentr:lep1,ir) at ir=",ir
        endif
     endif
  enddo
 
  call r8nz(bdenss(lcentr:lep1,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in bdenss(lcentr:lep1,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(mc_dens(lcentr:lep1,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in mc_dens(lcentr:lep1,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(bdenssw(lcentr:lep1,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in bdenssw(lcentr:lep1,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(udensplw(lcentr:lep1,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in udensplw(lcentr:lep1,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(udensppw(lcentr:lep1,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in udensppw(lcentr:lep1,lsbeam) at lsbeam=",lsbeam
  endif
 
  do ib=1,nbeam
     if(lsbeama(ib).eq.lsbeam) then
        call r8nz(bnb_ien(lcentr:lep1,1:3,ib),inum)
        if (inum.ne.0) then
           write(nonlin,*) &
               "non-zero value in bnb_ien(lcentr:lep1,1:3,ib) at ib=",ib
        endif
     endif
  enddo
 
  do ib=1,nbeam
     if(lsbeama(ib).eq.lsbeam) then
        call r8nz(pbe_ien(lcentr:lep1,1:3,ib),inum)
        if (inum.ne.0) then
           write(nonlin,*) &
               "non-zero value in pbe_ien(lcentr:lep1,1:3,ib) at ib=",ib
        endif
     endif
  enddo
 
  do ib=1,nbeam
     if(lsbeama(ib).eq.lsbeam) then
        call r8nz(pbi_ien(lcentr:lep1,1:3,ib),inum)
        if (inum.ne.0) then
           write(nonlin,*) &
               "non-zero value in pbi_ien(lcentr:lep1,1:3,ib) at ib=",ib
        endif
     endif
  enddo
 
  do ib=1,nbeam
     if(lsbeama(ib).eq.lsbeam) then
        call r8nz(upb_ien(lcentr:lep1,1:3,ib),inum)
        if (inum.ne.0) then
           write(nonlin,*) &
               "non-zero value in upb_ien(lcentr:lep1,1:3,ib) at ib=",ib
        endif
     endif
  enddo
 
  do ib=1,nbeam
     if(lsbeama(ib).eq.lsbeam) then
        call r8nz(ein_ien(1:3,ib),inum)
        if (inum.ne.0) then
           write(nonlin,*) &
               "non-zero value in ein_ien(1:3,ib) at ib=",ib
        endif
     endif
  enddo
 
  do ib=1,nbeam
     if(lsbeama(ib).eq.lsbeam) then
        call r8nz(dei_ien(1:3,ib),inum)
        if (inum.ne.0) then
           write(nonlin,*) &
               "non-zero value in dei_ien(1:3,ib) at ib=",ib
        endif
     endif
  enddo
 
  call r8nz(bnbs_ien(lcentr:lep1,1:3,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in bnbs_ien(lcentr:lep1,1:3,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(pbes_ien(lcentr:lep1,1:3,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in pbes_ien(lcentr:lep1,1:3,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(pbis_ien(lcentr:lep1,1:3,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in pbis_ien(lcentr:lep1,1:3,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(upbs_ien(lcentr:lep1,1:3,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in upbs_ien(lcentr:lep1,1:3,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(btrap(lcentr:lep1,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in btrap(lcentr:lep1,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(btrape(lcentr:lep1,1:miefi,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in btrape(lcentr:lep1,1:miefi,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(densfi(lcentr:lep1,1:miefi,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in densfi(lcentr:lep1,1:miefi,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(ebapl2s(lcentr:lep1,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in ebapl2s(lcentr:lep1,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(ebapp2s(lcentr:lep1,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in ebapp2s(lcentr:lep1,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(omegabs(lcentr:lep1,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in omegabs(lcentr:lep1,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(omegabsw(lcentr:lep1,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in omegabsw(lcentr:lep1,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(pbcprss(lcentr:lep1,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in pbcprss(lcentr:lep1,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(pbdfbes(lcentr:lep1,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in pbdfbes(lcentr:lep1,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(pbdfbis(lcentr:lep1,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in pbdfbis(lcentr:lep1,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(pbes(lcentr:lep1,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in pbes(lcentr:lep1,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(pbis(lcentr:lep1,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in pbis(lcentr:lep1,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(pbohs(lcentr:lep1,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in pbohs(lcentr:lep1,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(pbephis(lcentr:lep1,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in pbephis(lcentr:lep1,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(pbths(lcentr:lep1,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in pbths(lcentr:lep1,lsbeam) at lsbeam=",lsbeam
  endif
 
  do ib=1,nbeam
     if(lsbeama(ib).eq.lsbeam) then
        call r8nz(pbth_nb(lcentr:lep1,ib),inum)
        if (inum.ne.0) then
           write(nonlin,*) &
               "non-zero value in pbth_nb(lcentr:lep1,ib) at ib=",ib
        endif
     endif
  enddo
 
  call r8nz(pbthr2s(lcentr:lep1,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in pbthr2s(lcentr:lep1,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(orbrzv_prf(lcentr:lep1,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in orbrzv_prf(lcentr:lep1,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(sinb0is(lcentr:lep1,1:ng,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in sinb0is(lcentr:lep1,1:ng,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(sinbn0s(lcentr:lep1,1:ng,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in sinbn0s(lcentr:lep1,1:ng,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(sorbes(lcentr:lep1,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in sorbes(lcentr:lep1,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(sorbhs(lcentr:lep1,1:ng,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in sorbhs(lcentr:lep1,1:ng,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(sorbths(lcentr:lep1,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in sorbths(lcentr:lep1,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(tirabds(lcentr:lep1,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in tirabds(lcentr:lep1,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(tirfshs(lcentr:lep1,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in tirfshs(lcentr:lep1,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(tirorbs(lcentr:lep1,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in tirorbs(lcentr:lep1,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(tirrips(lcentr:lep1,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in tirrips(lcentr:lep1,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(difbx(lcentr:lep1,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in difbx(lcentr:lep1,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(velbx(lcentr:lep1,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in velbx(lcentr:lep1,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(tqbes(lcentr:lep1,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in tqbes(lcentr:lep1,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(tqbis(lcentr:lep1,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in tqbis(lcentr:lep1,lsbeam) at lsbeam=",lsbeam
  endif
 
  do ib=1,nbeam
     if(lsbeama(ib).eq.lsbeam) then
        call r8nz(tqbco_nb(lcentr:lep1,ib),inum)
        if (inum.ne.0) then
           write(nonlin,*) &
               "non-zero value in tqbco_nb(lcentr:lep1,ib) at ib=",ib
        endif
     endif
  enddo
 
  do ib=1,nbeam
     if(lsbeama(ib).eq.lsbeam) then
        call r8nz(tqbth_nb(lcentr:lep1,ib),inum)
        if (inum.ne.0) then
           write(nonlin,*) &
               "non-zero value in tqbth_nb(lcentr:lep1,ib) at ib=",ib
        endif
     endif
  enddo
 
  call r8nz(tqbths(lcentr:lep1,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in tqbths(lcentr:lep1,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(tqbxfs(lcentr:lep1,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in tqbxfs(lcentr:lep1,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(tqdifbs(lcentr:lep1,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in tqdifbs(lcentr:lep1,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(tqjxbs(lcentr:lep1,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in tqjxbs(lcentr:lep1,lsbeam) at lsbeam=",lsbeam
  endif
 
  do ib=1,nbeam
     if(lsbeama(ib).eq.lsbeam) then
        call r8nz(tqjxb_nb(lcentr:lep1,ib),inum)
        if (inum.ne.0) then
           write(nonlin,*) &
               "non-zero value in tqjxb_nb(lcentr:lep1,ib) at ib=",ib
        endif
     endif
  enddo
 
  call r8nz(tqohbs(lcentr:lep1,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in tqohbs(lcentr:lep1,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(tqrpls(lcentr:lep1,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in tqrpls(lcentr:lep1,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(xzbmav(lcentr:lep1,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in xzbmav(lcentr:lep1,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(bperrs(lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in bperrs(lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(pbaepms(lcentr:lep1,1:mnkaep,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in pbaepms(lcentr:lep1,1:mnkaep,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(bpfshs(lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in bpfshs(lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(bpls(lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in bpls(lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(bprpls(lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in bprpls(lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(pbdepmc(lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in pbdepmc(lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(orbrzv_prftot(lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in orbrzv_prftot(lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(bphdfbs(lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in bphdfbs(lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(bpherrs(lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in bpherrs(lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(bphfshs(lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in bphfshs(lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(bphjxbs(lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in bphjxbs(lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(bpholds(lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in bpholds(lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(bphorbs(lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in bphorbs(lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(bphrpls(lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in bphrpls(lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(bptdfbs(lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in bptdfbs(lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(bpthsfs(lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in bpthsfs(lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(bpjxbs(lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in bpjxbs(lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(bxflws(lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in bxflws(lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(bxflws_prompt(lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in bxflws_prompt(lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(bxfshs(lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in bxfshs(lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(bxrpls(lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in bxrpls(lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(snbcxos(lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in snbcxos(lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(snbxbb0(lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in snbxbb0(lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(snbxbb1(lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in snbxbb1(lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(snbxtot(lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in snbxtot(lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(snbx1d(lcentr:lep1,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in snbx1d(lcentr:lep1,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(snbxv0(lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in snbxv0(lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(snbxw0(lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in snbxw0(lsbeam) at lsbeam=",lsbeam
  endif
 
  nbuf_orb = nbuf_data
end subroutine nbi_zcheck_orb
 
subroutine nbi_zzero_orb
  use nbi_com
  use nbi_pllbuf
  implicit NONE
 
  integer ir,ib,inum
 
  inum = 0
 
  call r8zero(dxsm_kdsaw(lcentr:lep1,lsbeam),inum)
 
  call r8zero(dxwt_kdsaw(lcentr:lep1,lsbeam),inum)
 
  call r8zero(wsum_kdspre(lsbeam),inum)
 
  call r8zero(wsum_kdspost(lsbeam),inum)
 
  do ib=1,nbeam
     if(lsbeama(ib).eq.lsbeam) then
        call r8zero(wts_ien(1:3,ib),inum)
     endif
  enddo
 
  call r8zero(ebb_rel_co(1:mimxbzf,1:3,1:nbeam,lsbeam),inum)
 
  call r8zero(ebb_rel2_co(1:mimxbzf,1:3,1:nbeam,lsbeam),inum)
 
  call r8zero(ebb_rel_cnt(1:mimxbzf,1:3,1:nbeam,lsbeam),inum)
 
  call r8zero(ebb_rel2_cnt(1:mimxbzf,1:3,1:nbeam,lsbeam),inum)
 
  call r8zero(bnb_ien2(1:mimxbzf,1:2,lsbeam),inum)
 
  call r8zero(ebb_rel_fn(1:mimxbzf,1:3,1:nbeam,lsbeam),inum)
 
  call r8zero(ebb_rel2_fn(1:mimxbzf,1:3,1:nbeam,lsbeam),inum)
 
  call r8zero(bnb_fn(1:mimxbzf,lsbeam),inum)
 
  call r8zero(orb_code_error(lsbeam),inum)
 
  call r8zero(xnorbs(lsbeam),inum)
 
  call r8zero(dt_adj0_sums(lsbeam),inum)
 
  call r8zero(xnum_dt_adj0(lsbeam),inum)
 
  call r8zero(xmcloss_o(lsbeam),inum)
 
  call r8zero(wtqbxfs(lcentr:lep1,lsbeam),inum)
 
  call r8zero(bntots(lsbeam),inum)
 
  do ir=1,mireact
     if(lsbeamr(ir).eq.lsbeam) then
        call r8zero(btntn2(1:mimxbz,ir),inum)
     endif
  enddo
 
  call r8zero(wgvdx(lcentr:lep1,lsbeam),inum)
 
  call r8zero(hexbbxrc(1:mimxbz,lsbeam,1:nsfast),inum)
 
 
  call r8zero(sn00i2(1:nbeam,1:3,1:mimxbzf,lsbeam),inum)
 
  call r8zero(sn00x2(1:nbeam,1:3,1:mimxbzf,lsbeam),inum)
 
  call r8zero(snb0i2(1:mimxbz,1:ng,lsbeam),inum)
 
  call r8zero(snbn02(1:mimxbz,1:ng,lsbeam),inum)
 
  if(levmod_halo.eq.2) then
     call r8zero(svn3vii_h(1:mimxbe0,1:mimxba0,1:mgyro,1:mimxbzf,lsbeam),inum)
  endif
 
  if(levmod_halo.eq.2) then
     call r8zero(svn3vii_he(1:mimxbe0,1:mimxba0,1:mgyro,1:mimxbzf,lsbeam),inum)
  endif
 
  if(levmod_halo.eq.2) then
     call r8zero(svn3vcx_h(1:mimxbe0,1:mimxba0,1:mgyro,1:mimxbzf,lsbeam),inum)
  endif
 
  if(levmod_halo.eq.2) then
     call r8zero(svn3vcx_he(1:mimxbe0,1:mimxba0,1:mgyro,1:mimxbzf,lsbeam),inum)
  endif
 
  call r8zero(wtrap(lcentr:lep1,lsbeam),inum)
 
  call r8zero(wtrape(lcentr:lep1,1:miefi,lsbeam),inum)
 
  call r8zero(xcrb2c(1:mimxbz,lsbeam),inum)
 
  call r8zero(xcurb2(1:mimxbz,lsbeam),inum)
 
  call r8zero(enolds(lsbeam),inum)
 
  call r8zero(fpixbts(lcentr:lep1,lsbeam),inum)
 
  call r8zero(tirtots(lcentr:lep1,lsbeam),inum)
 
  call r8zero(wnlight(lsbeam),inum)
 
  call r8zero(wnlkill(lsbeam),inum)
 
  call r8zero(wndoubl(lsbeam),inum)
 
  call r8zero(pljbbms(lcentr:lep1,lsbeam),inum)
 
  do ib=1,nbeam
     if(lsbeama(ib).eq.lsbeam) then
        call r8zero(pljbbm_nb(lcentr:lep1,ib),inum)
     endif
  enddo
 
  call r8zero(pljbcct(lcentr:lep1,lsbeam),inum)
 
  do ir=1,mireact
     if(lsbeamr(ir).eq.lsbeam) then
        call r8zero(btntns(lcentr:lep1,ir),inum)
     endif
  enddo
 
  do ir=1,mireact
     if(lsbeamr(ir).eq.lsbeam) then
        call r8zero(btntrs(lcentr:lep1,ir),inum)
     endif
  enddo
 
  do ir=1,mireact
     if(lsbeamr(ir).eq.lsbeam) then
        call r8zero(btntws(lcentr:lep1,ir),inum)
     endif
  enddo
 
  call r8zero(bdenss(lcentr:lep1,lsbeam),inum)
 
  call r8zero(mc_dens(lcentr:lep1,lsbeam),inum)
 
  call r8zero(bdenssw(lcentr:lep1,lsbeam),inum)
 
  call r8zero(udensplw(lcentr:lep1,lsbeam),inum)
 
  call r8zero(udensppw(lcentr:lep1,lsbeam),inum)
 
  do ib=1,nbeam
     if(lsbeama(ib).eq.lsbeam) then
        call r8zero(bnb_ien(lcentr:lep1,1:3,ib),inum)
     endif
  enddo
 
  do ib=1,nbeam
     if(lsbeama(ib).eq.lsbeam) then
        call r8zero(pbe_ien(lcentr:lep1,1:3,ib),inum)
     endif
  enddo
 
  do ib=1,nbeam
     if(lsbeama(ib).eq.lsbeam) then
        call r8zero(pbi_ien(lcentr:lep1,1:3,ib),inum)
     endif
  enddo
 
  do ib=1,nbeam
     if(lsbeama(ib).eq.lsbeam) then
        call r8zero(upb_ien(lcentr:lep1,1:3,ib),inum)
     endif
  enddo
 
  do ib=1,nbeam
     if(lsbeama(ib).eq.lsbeam) then
        call r8zero(ein_ien(1:3,ib),inum)
     endif
  enddo
 
  do ib=1,nbeam
     if(lsbeama(ib).eq.lsbeam) then
        call r8zero(dei_ien(1:3,ib),inum)
     endif
  enddo
 
  call r8zero(bnbs_ien(lcentr:lep1,1:3,lsbeam),inum)
 
  call r8zero(pbes_ien(lcentr:lep1,1:3,lsbeam),inum)
 
  call r8zero(pbis_ien(lcentr:lep1,1:3,lsbeam),inum)
 
  call r8zero(upbs_ien(lcentr:lep1,1:3,lsbeam),inum)
 
  call r8zero(btrap(lcentr:lep1,lsbeam),inum)
 
  call r8zero(btrape(lcentr:lep1,1:miefi,lsbeam),inum)
 
  call r8zero(densfi(lcentr:lep1,1:miefi,lsbeam),inum)
 
  call r8zero(ebapl2s(lcentr:lep1,lsbeam),inum)
 
  call r8zero(ebapp2s(lcentr:lep1,lsbeam),inum)
 
  call r8zero(omegabs(lcentr:lep1,lsbeam),inum)
 
  call r8zero(omegabsw(lcentr:lep1,lsbeam),inum)
 
  call r8zero(pbcprss(lcentr:lep1,lsbeam),inum)
 
  call r8zero(pbdfbes(lcentr:lep1,lsbeam),inum)
 
  call r8zero(pbdfbis(lcentr:lep1,lsbeam),inum)
 
  call r8zero(pbes(lcentr:lep1,lsbeam),inum)
 
  call r8zero(pbis(lcentr:lep1,lsbeam),inum)
 
  call r8zero(pbohs(lcentr:lep1,lsbeam),inum)
 
  call r8zero(pbephis(lcentr:lep1,lsbeam),inum)
 
  call r8zero(pbths(lcentr:lep1,lsbeam),inum)
 
  do ib=1,nbeam
     if(lsbeama(ib).eq.lsbeam) then
        call r8zero(pbth_nb(lcentr:lep1,ib),inum)
     endif
  enddo
 
  call r8zero(pbthr2s(lcentr:lep1,lsbeam),inum)
 
  call r8zero(orbrzv_prf(lcentr:lep1,lsbeam),inum)
 
  call r8zero(sinb0is(lcentr:lep1,1:ng,lsbeam),inum)
 
  call r8zero(sinbn0s(lcentr:lep1,1:ng,lsbeam),inum)
 
  call r8zero(sorbes(lcentr:lep1,lsbeam),inum)
 
  call r8zero(sorbhs(lcentr:lep1,1:ng,lsbeam),inum)
 
  call r8zero(sorbths(lcentr:lep1,lsbeam),inum)
 
  call r8zero(tirabds(lcentr:lep1,lsbeam),inum)
 
  call r8zero(tirfshs(lcentr:lep1,lsbeam),inum)
 
  call r8zero(tirorbs(lcentr:lep1,lsbeam),inum)
 
  call r8zero(tirrips(lcentr:lep1,lsbeam),inum)
 
  call r8zero(difbx(lcentr:lep1,lsbeam),inum)
 
  call r8zero(velbx(lcentr:lep1,lsbeam),inum)
 
  call r8zero(tqbes(lcentr:lep1,lsbeam),inum)
 
  call r8zero(tqbis(lcentr:lep1,lsbeam),inum)
 
  do ib=1,nbeam
     if(lsbeama(ib).eq.lsbeam) then
        call r8zero(tqbco_nb(lcentr:lep1,ib),inum)
     endif
  enddo
 
  do ib=1,nbeam
     if(lsbeama(ib).eq.lsbeam) then
        call r8zero(tqbth_nb(lcentr:lep1,ib),inum)
     endif
  enddo
 
  call r8zero(tqbths(lcentr:lep1,lsbeam),inum)
 
  call r8zero(tqbxfs(lcentr:lep1,lsbeam),inum)
 
  call r8zero(tqdifbs(lcentr:lep1,lsbeam),inum)
 
  call r8zero(tqjxbs(lcentr:lep1,lsbeam),inum)
 
  do ib=1,nbeam
     if(lsbeama(ib).eq.lsbeam) then
        call r8zero(tqjxb_nb(lcentr:lep1,ib),inum)
     endif
  enddo
 
  call r8zero(tqohbs(lcentr:lep1,lsbeam),inum)
 
  call r8zero(tqrpls(lcentr:lep1,lsbeam),inum)
 
  call r8zero(xzbmav(lcentr:lep1,lsbeam),inum)
 
  call r8zero(bperrs(lsbeam),inum)
 
  call r8zero(pbaepms(lcentr:lep1,1:mnkaep,lsbeam),inum)
 
  call r8zero(bpfshs(lsbeam),inum)
 
  call r8zero(bpls(lsbeam),inum)
 
  call r8zero(bprpls(lsbeam),inum)
 
  call r8zero(pbdepmc(lsbeam),inum)
 
  call r8zero(orbrzv_prftot(lsbeam),inum)
 
  call r8zero(bphdfbs(lsbeam),inum)
 
  call r8zero(bpherrs(lsbeam),inum)
 
  call r8zero(bphfshs(lsbeam),inum)
 
  call r8zero(bphjxbs(lsbeam),inum)
 
  call r8zero(bpholds(lsbeam),inum)
 
  call r8zero(bphorbs(lsbeam),inum)
 
  call r8zero(bphrpls(lsbeam),inum)
 
  call r8zero(bptdfbs(lsbeam),inum)
 
  call r8zero(bpthsfs(lsbeam),inum)
 
  call r8zero(bpjxbs(lsbeam),inum)
 
  call r8zero(bxflws(lsbeam),inum)
 
  call r8zero(bxflws_prompt(lsbeam),inum)
 
  call r8zero(bxfshs(lsbeam),inum)
 
  call r8zero(bxrpls(lsbeam),inum)
 
  call r8zero(snbcxos(lsbeam),inum)
 
  call r8zero(snbxbb0(lsbeam),inum)
 
  call r8zero(snbxbb1(lsbeam),inum)
 
  call r8zero(snbxtot(lsbeam),inum)
 
  call r8zero(snbx1d(lcentr:lep1,lsbeam),inum)
 
  call r8zero(snbxv0(lsbeam),inum)
 
  call r8zero(snbxw0(lsbeam),inum)
 
end subroutine nbi_zzero_orb
 
subroutine nbi_pput_orb
  use nbi_com
  use nbi_pllbuf
  implicit NONE
 
  integer ir,ib,inum
 
  inum = 0
  nbuf_data =  nbuf_orb + 1   ! count puseyp(lsbeam)
 
  call r8put(dxsm_kdsaw(lcentr:lep1,lsbeam),inum)
 
  call r8put(dxwt_kdsaw(lcentr:lep1,lsbeam),inum)
 
  call r8put(wsum_kdspre(lsbeam),inum)
 
  call r8put(wsum_kdspost(lsbeam),inum)
 
  do ib=1,nbeam
     if(lsbeama(ib).eq.lsbeam) then
        call r8put(wts_ien(1:3,ib),inum)
     endif
  enddo
 
  call r8put(ebb_rel_co(1:mimxbzf,1:3,1:nbeam,lsbeam),inum)
 
  call r8put(ebb_rel2_co(1:mimxbzf,1:3,1:nbeam,lsbeam),inum)
 
  call r8put(ebb_rel_cnt(1:mimxbzf,1:3,1:nbeam,lsbeam),inum)
 
  call r8put(ebb_rel2_cnt(1:mimxbzf,1:3,1:nbeam,lsbeam),inum)
 
  call r8put(bnb_ien2(1:mimxbzf,1:2,lsbeam),inum)
 
  call r8put(ebb_rel_fn(1:mimxbzf,1:3,1:nbeam,lsbeam),inum)
 
  call r8put(ebb_rel2_fn(1:mimxbzf,1:3,1:nbeam,lsbeam),inum)
 
  call r8put(bnb_fn(1:mimxbzf,lsbeam),inum)
 
  call r8put(orb_code_error(lsbeam),inum)
 
  call r8put(xnorbs(lsbeam),inum)
 
  call r8put(dt_adj0_sums(lsbeam),inum)
 
  call r8put(xnum_dt_adj0(lsbeam),inum)
 
  call r8put(xmcloss_o(lsbeam),inum)
 
  call r8put(wtqbxfs(lcentr:lep1,lsbeam),inum)
 
  call r8put(bntots(lsbeam),inum)
 
  do ir=1,mireact
     if(lsbeamr(ir).eq.lsbeam) then
        call r8put(btntn2(1:mimxbz,ir),inum)
     endif
  enddo
 
  call r8put(wgvdx(lcentr:lep1,lsbeam),inum)
 
  call r8put(hexbbxrc(1:mimxbz,lsbeam,1:nsfast),inum)
 
  call r8put(puseyp(lsbeam),inum)
 
  call r8put(sn00i2(1:nbeam,1:3,1:mimxbzf,lsbeam),inum)
 
  call r8put(sn00x2(1:nbeam,1:3,1:mimxbzf,lsbeam),inum)
 
  call r8put(snb0i2(1:mimxbz,1:ng,lsbeam),inum)
 
  call r8put(snbn02(1:mimxbz,1:ng,lsbeam),inum)
 
  if(levmod_halo.eq.2) then
     call r8put(svn3vii_h(1:mimxbe0,1:mimxba0,1:mgyro,1:mimxbzf,lsbeam),inum)
  endif
 
  if(levmod_halo.eq.2) then
     call r8put(svn3vii_he(1:mimxbe0,1:mimxba0,1:mgyro,1:mimxbzf,lsbeam),inum)
  endif
 
  if(levmod_halo.eq.2) then
     call r8put(svn3vcx_h(1:mimxbe0,1:mimxba0,1:mgyro,1:mimxbzf,lsbeam),inum)
  endif
 
  if(levmod_halo.eq.2) then
     call r8put(svn3vcx_he(1:mimxbe0,1:mimxba0,1:mgyro,1:mimxbzf,lsbeam),inum)
  endif
 
  call r8put(wtrap(lcentr:lep1,lsbeam),inum)
 
  call r8put(wtrape(lcentr:lep1,1:miefi,lsbeam),inum)
 
  call r8put(xcrb2c(1:mimxbz,lsbeam),inum)
 
  call r8put(xcurb2(1:mimxbz,lsbeam),inum)
 
  call r8put(enolds(lsbeam),inum)
 
  call r8put(fpixbts(lcentr:lep1,lsbeam),inum)
 
  call r8put(tirtots(lcentr:lep1,lsbeam),inum)
 
  call r8put(wnlight(lsbeam),inum)
 
  call r8put(wnlkill(lsbeam),inum)
 
  call r8put(wndoubl(lsbeam),inum)
 
  call r8put(pljbbms(lcentr:lep1,lsbeam),inum)
 
  do ib=1,nbeam
     if(lsbeama(ib).eq.lsbeam) then
        call r8put(pljbbm_nb(lcentr:lep1,ib),inum)
     endif
  enddo
 
  call r8put(pljbcct(lcentr:lep1,lsbeam),inum)
 
  do ir=1,mireact
     if(lsbeamr(ir).eq.lsbeam) then
        call r8put(btntns(lcentr:lep1,ir),inum)
     endif
  enddo
 
  do ir=1,mireact
     if(lsbeamr(ir).eq.lsbeam) then
        call r8put(btntrs(lcentr:lep1,ir),inum)
     endif
  enddo
 
  do ir=1,mireact
     if(lsbeamr(ir).eq.lsbeam) then
        call r8put(btntws(lcentr:lep1,ir),inum)
     endif
  enddo
 
  call r8put(bdenss(lcentr:lep1,lsbeam),inum)
 
  call r8put(mc_dens(lcentr:lep1,lsbeam),inum)
 
  call r8put(bdenssw(lcentr:lep1,lsbeam),inum)
 
  call r8put(udensplw(lcentr:lep1,lsbeam),inum)
 
  call r8put(udensppw(lcentr:lep1,lsbeam),inum)
 
  do ib=1,nbeam
     if(lsbeama(ib).eq.lsbeam) then
        call r8put(bnb_ien(lcentr:lep1,1:3,ib),inum)
     endif
  enddo
 
  do ib=1,nbeam
     if(lsbeama(ib).eq.lsbeam) then
        call r8put(pbe_ien(lcentr:lep1,1:3,ib),inum)
     endif
  enddo
 
  do ib=1,nbeam
     if(lsbeama(ib).eq.lsbeam) then
        call r8put(pbi_ien(lcentr:lep1,1:3,ib),inum)
     endif
  enddo
 
  do ib=1,nbeam
     if(lsbeama(ib).eq.lsbeam) then
        call r8put(upb_ien(lcentr:lep1,1:3,ib),inum)
     endif
  enddo
 
  do ib=1,nbeam
     if(lsbeama(ib).eq.lsbeam) then
        call r8put(ein_ien(1:3,ib),inum)
     endif
  enddo
 
  do ib=1,nbeam
     if(lsbeama(ib).eq.lsbeam) then
        call r8put(dei_ien(1:3,ib),inum)
     endif
  enddo
 
  call r8put(bnbs_ien(lcentr:lep1,1:3,lsbeam),inum)
 
  call r8put(pbes_ien(lcentr:lep1,1:3,lsbeam),inum)
 
  call r8put(pbis_ien(lcentr:lep1,1:3,lsbeam),inum)
 
  call r8put(upbs_ien(lcentr:lep1,1:3,lsbeam),inum)
 
  call r8put(btrap(lcentr:lep1,lsbeam),inum)
 
  call r8put(btrape(lcentr:lep1,1:miefi,lsbeam),inum)
 
  call r8put(densfi(lcentr:lep1,1:miefi,lsbeam),inum)
 
  call r8put(ebapl2s(lcentr:lep1,lsbeam),inum)
 
  call r8put(ebapp2s(lcentr:lep1,lsbeam),inum)
 
  call r8put(omegabs(lcentr:lep1,lsbeam),inum)
 
  call r8put(omegabsw(lcentr:lep1,lsbeam),inum)
 
  call r8put(pbcprss(lcentr:lep1,lsbeam),inum)
 
  call r8put(pbdfbes(lcentr:lep1,lsbeam),inum)
 
  call r8put(pbdfbis(lcentr:lep1,lsbeam),inum)
 
  call r8put(pbes(lcentr:lep1,lsbeam),inum)
 
  call r8put(pbis(lcentr:lep1,lsbeam),inum)
 
  call r8put(pbohs(lcentr:lep1,lsbeam),inum)
 
  call r8put(pbephis(lcentr:lep1,lsbeam),inum)
 
  call r8put(pbths(lcentr:lep1,lsbeam),inum)
 
  do ib=1,nbeam
     if(lsbeama(ib).eq.lsbeam) then
        call r8put(pbth_nb(lcentr:lep1,ib),inum)
     endif
  enddo
 
  call r8put(pbthr2s(lcentr:lep1,lsbeam),inum)
 
  call r8put(orbrzv_prf(lcentr:lep1,lsbeam),inum)
 
  call r8put(sinb0is(lcentr:lep1,1:ng,lsbeam),inum)
 
  call r8put(sinbn0s(lcentr:lep1,1:ng,lsbeam),inum)
 
  call r8put(sorbes(lcentr:lep1,lsbeam),inum)
 
  call r8put(sorbhs(lcentr:lep1,1:ng,lsbeam),inum)
 
  call r8put(sorbths(lcentr:lep1,lsbeam),inum)
 
  call r8put(tirabds(lcentr:lep1,lsbeam),inum)
 
  call r8put(tirfshs(lcentr:lep1,lsbeam),inum)
 
  call r8put(tirorbs(lcentr:lep1,lsbeam),inum)
 
  call r8put(tirrips(lcentr:lep1,lsbeam),inum)
 
  call r8put(difbx(lcentr:lep1,lsbeam),inum)
 
  call r8put(velbx(lcentr:lep1,lsbeam),inum)
 
  call r8put(tqbes(lcentr:lep1,lsbeam),inum)
 
  call r8put(tqbis(lcentr:lep1,lsbeam),inum)
 
  do ib=1,nbeam
     if(lsbeama(ib).eq.lsbeam) then
        call r8put(tqbco_nb(lcentr:lep1,ib),inum)
     endif
  enddo
 
  do ib=1,nbeam
     if(lsbeama(ib).eq.lsbeam) then
        call r8put(tqbth_nb(lcentr:lep1,ib),inum)
     endif
  enddo
 
  call r8put(tqbths(lcentr:lep1,lsbeam),inum)
 
  call r8put(tqbxfs(lcentr:lep1,lsbeam),inum)
 
  call r8put(tqdifbs(lcentr:lep1,lsbeam),inum)
 
  call r8put(tqjxbs(lcentr:lep1,lsbeam),inum)
 
  do ib=1,nbeam
     if(lsbeama(ib).eq.lsbeam) then
        call r8put(tqjxb_nb(lcentr:lep1,ib),inum)
     endif
  enddo
 
  call r8put(tqohbs(lcentr:lep1,lsbeam),inum)
 
  call r8put(tqrpls(lcentr:lep1,lsbeam),inum)
 
  call r8put(xzbmav(lcentr:lep1,lsbeam),inum)
 
  call r8put(bperrs(lsbeam),inum)
 
  call r8put(pbaepms(lcentr:lep1,1:mnkaep,lsbeam),inum)
 
  call r8put(bpfshs(lsbeam),inum)
 
  call r8put(bpls(lsbeam),inum)
 
  call r8put(bprpls(lsbeam),inum)
 
  call r8put(pbdepmc(lsbeam),inum)
 
  call r8put(orbrzv_prftot(lsbeam),inum)
 
  call r8put(bphdfbs(lsbeam),inum)
 
  call r8put(bpherrs(lsbeam),inum)
 
  call r8put(bphfshs(lsbeam),inum)
 
  call r8put(bphjxbs(lsbeam),inum)
 
  call r8put(bpholds(lsbeam),inum)
 
  call r8put(bphorbs(lsbeam),inum)
 
  call r8put(bphrpls(lsbeam),inum)
 
  call r8put(bptdfbs(lsbeam),inum)
 
  call r8put(bpthsfs(lsbeam),inum)
 
  call r8put(bpjxbs(lsbeam),inum)
 
  call r8put(bxflws(lsbeam),inum)
 
  call r8put(bxflws_prompt(lsbeam),inum)
 
  call r8put(bxfshs(lsbeam),inum)
 
  call r8put(bxrpls(lsbeam),inum)
 
  call r8put(snbcxos(lsbeam),inum)
 
  call r8put(snbxbb0(lsbeam),inum)
 
  call r8put(snbxbb1(lsbeam),inum)
 
  call r8put(snbxtot(lsbeam),inum)
 
  call r8put(snbx1d(lcentr:lep1,lsbeam),inum)
 
  call r8put(snbxv0(lsbeam),inum)
 
  call r8put(snbxw0(lsbeam),inum)
 
end subroutine nbi_pput_orb
 
subroutine nbi_pget_orb
  use nbi_com
  use nbi_pllbuf
  implicit NONE
 
  integer ir,ib,inum
 
  inum = 0
 
  call r8get(dxsm_kdsaw(lcentr:lep1,lsbeam),inum)
 
  call r8get(dxwt_kdsaw(lcentr:lep1,lsbeam),inum)
 
  call r8get(wsum_kdspre(lsbeam),inum)
 
  call r8get(wsum_kdspost(lsbeam),inum)
 
  do ib=1,nbeam
     if(lsbeama(ib).eq.lsbeam) then
        call r8get(wts_ien(1:3,ib),inum)
     endif
  enddo
 
  call r8get(ebb_rel_co(1:mimxbzf,1:3,1:nbeam,lsbeam),inum)
 
  call r8get(ebb_rel2_co(1:mimxbzf,1:3,1:nbeam,lsbeam),inum)
 
  call r8get(ebb_rel_cnt(1:mimxbzf,1:3,1:nbeam,lsbeam),inum)
 
  call r8get(ebb_rel2_cnt(1:mimxbzf,1:3,1:nbeam,lsbeam),inum)
 
  call r8get(bnb_ien2(1:mimxbzf,1:2,lsbeam),inum)
 
  call r8get(ebb_rel_fn(1:mimxbzf,1:3,1:nbeam,lsbeam),inum)
 
  call r8get(ebb_rel2_fn(1:mimxbzf,1:3,1:nbeam,lsbeam),inum)
 
  call r8get(bnb_fn(1:mimxbzf,lsbeam),inum)
 
  call r8get(orb_code_error(lsbeam),inum)
 
  call r8get(xnorbs(lsbeam),inum)
 
  call r8get(dt_adj0_sums(lsbeam),inum)
 
  call r8get(xnum_dt_adj0(lsbeam),inum)
 
  call r8get(xmcloss_o(lsbeam),inum)
 
  call r8get(wtqbxfs(lcentr:lep1,lsbeam),inum)
 
  call r8get(bntots(lsbeam),inum)
 
  do ir=1,mireact
     if(lsbeamr(ir).eq.lsbeam) then
        call r8get(btntn2(1:mimxbz,ir),inum)
     endif
  enddo
 
  call r8get(wgvdx(lcentr:lep1,lsbeam),inum)
 
  call r8get(hexbbxrc(1:mimxbz,lsbeam,1:nsfast),inum)
 
  call r8get(puseyp(lsbeam),inum)
 
  call r8get(sn00i2(1:nbeam,1:3,1:mimxbzf,lsbeam),inum)
 
  call r8get(sn00x2(1:nbeam,1:3,1:mimxbzf,lsbeam),inum)
 
  call r8get(snb0i2(1:mimxbz,1:ng,lsbeam),inum)
 
  call r8get(snbn02(1:mimxbz,1:ng,lsbeam),inum)
 
  if(levmod_halo.eq.2) then
     call r8get(svn3vii_h(1:mimxbe0,1:mimxba0,1:mgyro,1:mimxbzf,lsbeam),inum)
  endif
 
  if(levmod_halo.eq.2) then
     call r8get(svn3vii_he(1:mimxbe0,1:mimxba0,1:mgyro,1:mimxbzf,lsbeam),inum)
  endif
 
  if(levmod_halo.eq.2) then
     call r8get(svn3vcx_h(1:mimxbe0,1:mimxba0,1:mgyro,1:mimxbzf,lsbeam),inum)
  endif
 
  if(levmod_halo.eq.2) then
     call r8get(svn3vcx_he(1:mimxbe0,1:mimxba0,1:mgyro,1:mimxbzf,lsbeam),inum)
  endif
 
  call r8get(wtrap(lcentr:lep1,lsbeam),inum)
 
  call r8get(wtrape(lcentr:lep1,1:miefi,lsbeam),inum)
 
  call r8get(xcrb2c(1:mimxbz,lsbeam),inum)
 
  call r8get(xcurb2(1:mimxbz,lsbeam),inum)
 
  call r8get(enolds(lsbeam),inum)
 
  call r8get(fpixbts(lcentr:lep1,lsbeam),inum)
 
  call r8get(tirtots(lcentr:lep1,lsbeam),inum)
 
  call r8get(wnlight(lsbeam),inum)
 
  call r8get(wnlkill(lsbeam),inum)
 
  call r8get(wndoubl(lsbeam),inum)
 
  call r8get(pljbbms(lcentr:lep1,lsbeam),inum)
 
  do ib=1,nbeam
     if(lsbeama(ib).eq.lsbeam) then
        call r8get(pljbbm_nb(lcentr:lep1,ib),inum)
     endif
  enddo
 
  call r8get(pljbcct(lcentr:lep1,lsbeam),inum)
 
  do ir=1,mireact
     if(lsbeamr(ir).eq.lsbeam) then
        call r8get(btntns(lcentr:lep1,ir),inum)
     endif
  enddo
 
  do ir=1,mireact
     if(lsbeamr(ir).eq.lsbeam) then
        call r8get(btntrs(lcentr:lep1,ir),inum)
     endif
  enddo
 
  do ir=1,mireact
     if(lsbeamr(ir).eq.lsbeam) then
        call r8get(btntws(lcentr:lep1,ir),inum)
     endif
  enddo
 
  call r8get(bdenss(lcentr:lep1,lsbeam),inum)
 
  call r8get(mc_dens(lcentr:lep1,lsbeam),inum)
 
  call r8get(bdenssw(lcentr:lep1,lsbeam),inum)
 
  call r8get(udensplw(lcentr:lep1,lsbeam),inum)
 
  call r8get(udensppw(lcentr:lep1,lsbeam),inum)
 
  do ib=1,nbeam
     if(lsbeama(ib).eq.lsbeam) then
        call r8get(bnb_ien(lcentr:lep1,1:3,ib),inum)
     endif
  enddo
 
  do ib=1,nbeam
     if(lsbeama(ib).eq.lsbeam) then
        call r8get(pbe_ien(lcentr:lep1,1:3,ib),inum)
     endif
  enddo
 
  do ib=1,nbeam
     if(lsbeama(ib).eq.lsbeam) then
        call r8get(pbi_ien(lcentr:lep1,1:3,ib),inum)
     endif
  enddo
 
  do ib=1,nbeam
     if(lsbeama(ib).eq.lsbeam) then
        call r8get(upb_ien(lcentr:lep1,1:3,ib),inum)
     endif
  enddo
 
  do ib=1,nbeam
     if(lsbeama(ib).eq.lsbeam) then
        call r8get(ein_ien(1:3,ib),inum)
     endif
  enddo
 
  do ib=1,nbeam
     if(lsbeama(ib).eq.lsbeam) then
        call r8get(dei_ien(1:3,ib),inum)
     endif
  enddo
 
  call r8get(bnbs_ien(lcentr:lep1,1:3,lsbeam),inum)
 
  call r8get(pbes_ien(lcentr:lep1,1:3,lsbeam),inum)
 
  call r8get(pbis_ien(lcentr:lep1,1:3,lsbeam),inum)
 
  call r8get(upbs_ien(lcentr:lep1,1:3,lsbeam),inum)
 
  call r8get(btrap(lcentr:lep1,lsbeam),inum)
 
  call r8get(btrape(lcentr:lep1,1:miefi,lsbeam),inum)
 
  call r8get(densfi(lcentr:lep1,1:miefi,lsbeam),inum)
 
  call r8get(ebapl2s(lcentr:lep1,lsbeam),inum)
 
  call r8get(ebapp2s(lcentr:lep1,lsbeam),inum)
 
  call r8get(omegabs(lcentr:lep1,lsbeam),inum)
 
  call r8get(omegabsw(lcentr:lep1,lsbeam),inum)
 
  call r8get(pbcprss(lcentr:lep1,lsbeam),inum)
 
  call r8get(pbdfbes(lcentr:lep1,lsbeam),inum)
 
  call r8get(pbdfbis(lcentr:lep1,lsbeam),inum)
 
  call r8get(pbes(lcentr:lep1,lsbeam),inum)
 
  call r8get(pbis(lcentr:lep1,lsbeam),inum)
 
  call r8get(pbohs(lcentr:lep1,lsbeam),inum)
 
  call r8get(pbephis(lcentr:lep1,lsbeam),inum)
 
  call r8get(pbths(lcentr:lep1,lsbeam),inum)
 
  do ib=1,nbeam
     if(lsbeama(ib).eq.lsbeam) then
        call r8get(pbth_nb(lcentr:lep1,ib),inum)
     endif
  enddo
 
  call r8get(pbthr2s(lcentr:lep1,lsbeam),inum)
 
  call r8get(orbrzv_prf(lcentr:lep1,lsbeam),inum)
 
  call r8get(sinb0is(lcentr:lep1,1:ng,lsbeam),inum)
 
  call r8get(sinbn0s(lcentr:lep1,1:ng,lsbeam),inum)
 
  call r8get(sorbes(lcentr:lep1,lsbeam),inum)
 
  call r8get(sorbhs(lcentr:lep1,1:ng,lsbeam),inum)
 
  call r8get(sorbths(lcentr:lep1,lsbeam),inum)
 
  call r8get(tirabds(lcentr:lep1,lsbeam),inum)
 
  call r8get(tirfshs(lcentr:lep1,lsbeam),inum)
 
  call r8get(tirorbs(lcentr:lep1,lsbeam),inum)
 
  call r8get(tirrips(lcentr:lep1,lsbeam),inum)
 
  call r8get(difbx(lcentr:lep1,lsbeam),inum)
 
  call r8get(velbx(lcentr:lep1,lsbeam),inum)
 
  call r8get(tqbes(lcentr:lep1,lsbeam),inum)
 
  call r8get(tqbis(lcentr:lep1,lsbeam),inum)
 
  do ib=1,nbeam
     if(lsbeama(ib).eq.lsbeam) then
        call r8get(tqbco_nb(lcentr:lep1,ib),inum)
     endif
  enddo
 
  do ib=1,nbeam
     if(lsbeama(ib).eq.lsbeam) then
        call r8get(tqbth_nb(lcentr:lep1,ib),inum)
     endif
  enddo
 
  call r8get(tqbths(lcentr:lep1,lsbeam),inum)
 
  call r8get(tqbxfs(lcentr:lep1,lsbeam),inum)
 
  call r8get(tqdifbs(lcentr:lep1,lsbeam),inum)
 
  call r8get(tqjxbs(lcentr:lep1,lsbeam),inum)
 
  do ib=1,nbeam
     if(lsbeama(ib).eq.lsbeam) then
        call r8get(tqjxb_nb(lcentr:lep1,ib),inum)
     endif
  enddo
 
  call r8get(tqohbs(lcentr:lep1,lsbeam),inum)
 
  call r8get(tqrpls(lcentr:lep1,lsbeam),inum)
 
  call r8get(xzbmav(lcentr:lep1,lsbeam),inum)
 
  call r8get(bperrs(lsbeam),inum)
 
  call r8get(pbaepms(lcentr:lep1,1:mnkaep,lsbeam),inum)
 
  call r8get(bpfshs(lsbeam),inum)
 
  call r8get(bpls(lsbeam),inum)
 
  call r8get(bprpls(lsbeam),inum)
 
  call r8get(pbdepmc(lsbeam),inum)
 
  call r8get(orbrzv_prftot(lsbeam),inum)
 
  call r8get(bphdfbs(lsbeam),inum)
 
  call r8get(bpherrs(lsbeam),inum)
 
  call r8get(bphfshs(lsbeam),inum)
 
  call r8get(bphjxbs(lsbeam),inum)
 
  call r8get(bpholds(lsbeam),inum)
 
  call r8get(bphorbs(lsbeam),inum)
 
  call r8get(bphrpls(lsbeam),inum)
 
  call r8get(bptdfbs(lsbeam),inum)
 
  call r8get(bpthsfs(lsbeam),inum)
 
  call r8get(bpjxbs(lsbeam),inum)
 
  call r8get(bxflws(lsbeam),inum)
 
  call r8get(bxflws_prompt(lsbeam),inum)
 
  call r8get(bxfshs(lsbeam),inum)
 
  call r8get(bxrpls(lsbeam),inum)
 
  call r8get(snbcxos(lsbeam),inum)
 
  call r8get(snbxbb0(lsbeam),inum)
 
  call r8get(snbxbb1(lsbeam),inum)
 
  call r8get(snbxtot(lsbeam),inum)
 
  call r8get(snbx1d(lcentr:lep1,lsbeam),inum)
 
  call r8get(snbxv0(lsbeam),inum)
 
  call r8get(snbxw0(lsbeam),inum)
 
end subroutine nbi_pget_orb
 
subroutine nbi_zcheck_dep
  use nbi_com
  use nbi_pllbuf
  implicit NONE
 
  integer ir,ib,inum
 
  inum = 0
  nbuf_data = 0
  nbuf_dep = 0
 
  call r8nz(dep_code_error(lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in dep_code_error(lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(xmcloss_d(lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in xmcloss_d(lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(weinjav(lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in weinjav(lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(ewghtdep(lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in ewghtdep(lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(ewghtdep0(lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in ewghtdep0(lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(wghtdep(lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in wghtdep(lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(zidep0(lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in zidep0(lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(zitrk0(lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in zitrk0(lsbeam) at lsbeam=",lsbeam
  endif
 
  do ib=1,nbeam
     if(lsbeama(ib).eq.lsbeam) then
        call r8nz(sfrac_survive(1:3,ib),inum)
        if (inum.ne.0) then
           write(nonlin,*) &
               "non-zero value in sfrac_survive(1:3,ib) at ib=",ib
        endif
     endif
  enddo
 
  do ib=1,nbeam
     if(lsbeama(ib).eq.lsbeam) then
        call r8nz(wfrac_survive(1:3,ib),inum)
        if (inum.ne.0) then
           write(nonlin,*) &
               "non-zero value in wfrac_survive(1:3,ib) at ib=",ib
        endif
     endif
  enddo
 
  do ib=1,nbeam
     if(lsbeama(ib).eq.lsbeam) then
        call r8nz(bn002(ib,1:3,1:2,1:mimxbzf),inum)
        if (inum.ne.0) then
           write(nonlin,*) &
               "non-zero value in bn002(ib,1:3,1:2,1:mimxbzf) at ib=",ib
        endif
     endif
  enddo
 
  do ib=1,nbeam
     if(lsbeama(ib).eq.lsbeam) then
        call r8nz(hexbbcx0(ib,1:3,1:2,1:mimxbzf,1:nsfast),inum)
        if (inum.ne.0) then
           write(nonlin,*) &
               "non-zero value in hexbbcx0(ib,1:3,1:2,1:mimxbzf,1:nsfast) at ib=",ib
        endif
     endif
  enddo
 
 
  call r8nz(srbn02_dep(1:mimxbz,1:ng,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in srbn02_dep(1:mimxbz,1:ng,lsbeam) at lsbeam=",lsbeam
  endif
 
  do ib=1,nbeam
     if(lsbeama(ib).eq.lsbeam) then
        call r8nz(vcxbn0(ib,1:3,1:2,1:mimxbzf),inum)
        if (inum.ne.0) then
           write(nonlin,*) &
               "non-zero value in vcxbn0(ib,1:3,1:2,1:mimxbzf) at ib=",ib
        endif
     endif
  enddo
 
  do ib=1,nbeam
     if(lsbeama(ib).eq.lsbeam) then
        call r8nz(vpvn00(ib,1:3,lcentr:lep1),inum)
        if (inum.ne.0) then
           write(nonlin,*) &
               "non-zero value in vpvn00(ib,1:3,lcentr:lep1) at ib=",ib
        endif
     endif
  enddo
 
  call r8nz(wtrap0(lcentr:lep1,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in wtrap0(lcentr:lep1,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(xn_dep(lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in xn_dep(lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(xn_orb(lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in xn_orb(lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(xp_dep(lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in xp_dep(lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(xp_orb(lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in xp_orb(lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(xph_dep(lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in xph_dep(lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(xph_orb(lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in xph_orb(lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(fpixbts_dep(lcentr:lep1,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in fpixbts_dep(lcentr:lep1,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(tirtots_dep(lcentr:lep1,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in tirtots_dep(lcentr:lep1,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(fbdepco(lcentr:lep1,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in fbdepco(lcentr:lep1,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(fbdepct(lcentr:lep1,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in fbdepct(lcentr:lep1,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(wkill(lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in wkill(lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(wnkill(lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in wnkill(lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(taubpa(lcentr:lep1,1:20,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in taubpa(lcentr:lep1,1:20,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(taubsl(lcentr:lep1,1:20,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in taubsl(lcentr:lep1,1:20,lsbeam) at lsbeam=",lsbeam
  endif
 
  do ib=1,nbeam
     if(lsbeama(ib).eq.lsbeam) then
        call r8nz(bdepb(lcentr:lep1,1:3,ib),inum)
        if (inum.ne.0) then
           write(nonlin,*) &
               "non-zero value in bdepb(lcentr:lep1,1:3,ib) at ib=",ib
        endif
     endif
  enddo
 
  call r8nz(sdep_oa(lcentr:lep1,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in sdep_oa(lcentr:lep1,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(mc_newdens(lcentr:lep1,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in mc_newdens(lcentr:lep1,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(einjav(lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in einjav(lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(sbbidpe(lcentr:lep1,1:3,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in sbbidpe(lcentr:lep1,1:3,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(sbbidps(lcentr:lep1,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in sbbidps(lcentr:lep1,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(sbbxdpe(lcentr:lep1,1:3,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in sbbxdpe(lcentr:lep1,1:3,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(sbbxdps(lcentr:lep1,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in sbbxdps(lcentr:lep1,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(sbcxdpe(lcentr:lep1,1:ng,1:3,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in sbcxdpe(lcentr:lep1,1:ng,1:3,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(sbedepe(lcentr:lep1,1:3,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in sbedepe(lcentr:lep1,1:3,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(sbedeps(lcentr:lep1,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in sbedeps(lcentr:lep1,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(sbiedepe(lcentr:lep1,1:3,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in sbiedepe(lcentr:lep1,1:3,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(sbiedeps(lcentr:lep1,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in sbiedeps(lcentr:lep1,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(sbildepe(lcentr:lep1,1:3,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in sbildepe(lcentr:lep1,1:3,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(sbildeps(lcentr:lep1,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in sbildeps(lcentr:lep1,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(sbizdepe(lcentr:lep1,1:3,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in sbizdepe(lcentr:lep1,1:3,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(sbizdeps(lcentr:lep1,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in sbizdeps(lcentr:lep1,lsbeam) at lsbeam=",lsbeam
  endif
 
  do ib=1,nbeam
     if(lsbeama(ib).eq.lsbeam) then
        call r8nz(bpshna(ib,1:3),inum)
        if (inum.ne.0) then
           write(nonlin,*) &
               "non-zero value in bpshna(ib,1:3) at ib=",ib
        endif
     endif
  enddo
 
  do ib=1,nbeam
     if(lsbeama(ib).eq.lsbeam) then
        call r8nz(bn00(ib,1:3,lcentr:lep1),inum)
        if (inum.ne.0) then
           write(nonlin,*) &
               "non-zero value in bn00(ib,1:3,lcentr:lep1) at ib=",ib
        endif
     endif
  enddo
 
  call r8nz(btrap0(lcentr:lep1,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in btrap0(lcentr:lep1,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(excit0(lcentr:lep1,1:3,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in excit0(lcentr:lep1,1:3,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(pbephis_dep(lcentr:lep1,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in pbephis_dep(lcentr:lep1,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(sorbn0s_dep(lcentr:lep1,1:ng,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in sorbn0s_dep(lcentr:lep1,1:ng,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(sorbes_dep(lcentr:lep1,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in sorbes_dep(lcentr:lep1,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(sorbhs_dep(lcentr:lep1,1:ng,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in sorbhs_dep(lcentr:lep1,1:ng,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(tqbcxs_dep(lcentr:lep1,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in tqbcxs_dep(lcentr:lep1,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(tqjxbs_dep(lcentr:lep1,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in tqjxbs_dep(lcentr:lep1,lsbeam) at lsbeam=",lsbeam
  endif
 
  do ib=1,nbeam
     if(lsbeama(ib).eq.lsbeam) then
        call r8nz(tqjxb_nb_dep(lcentr:lep1,ib),inum)
        if (inum.ne.0) then
           write(nonlin,*) &
               "non-zero value in tqjxb_nb_dep(lcentr:lep1,ib) at ib=",ib
        endif
     endif
  enddo
 
  call r8nz(bpls_dep(lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in bpls_dep(lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(bpshins(lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in bpshins(lsbeam) at lsbeam=",lsbeam
  endif
 
  do ib=1,nbeam
     if(lsbeama(ib).eq.lsbeam) then
        call r8nz(bpprma(ib),inum)
        if (inum.ne.0) then
           write(nonlin,*) &
               "non-zero value in bpprma(ib) at ib=",ib
        endif
     endif
  enddo
 
  call r8nz(bphinjs(lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in bphinjs(lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(bphdepsgc(lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in bphdepsgc(lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(bphdeps(lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in bphdeps(lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(bphshins(lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in bphshins(lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(bphjxbs_dep(lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in bphjxbs_dep(lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(bphorbs_dep(lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in bphorbs_dep(lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(bpjxbs_dep(lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in bpjxbs_dep(lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(bxflws_dep(lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in bxflws_dep(lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(sfdbbcx(lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in sfdbbcx(lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(sfdbbiz(lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in sfdbbiz(lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(sfdepcx(lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in sfdepcx(lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(sfdepiz(lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in sfdepiz(lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(sfdeprr(lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in sfdeprr(lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(sfdepsc(lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in sfdepsc(lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(sforbrr(lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in sforbrr(lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(sfshine(lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in sfshine(lsbeam) at lsbeam=",lsbeam
  endif
 
  nbuf_dep = nbuf_data
end subroutine nbi_zcheck_dep
 
subroutine nbi_zzero_dep
  use nbi_com
  use nbi_pllbuf
  implicit NONE
 
  integer ir,ib,inum
 
  inum = 0
 
  call r8zero(dep_code_error(lsbeam),inum)
 
  call r8zero(xmcloss_d(lsbeam),inum)
 
  call r8zero(weinjav(lsbeam),inum)
 
  call r8zero(ewghtdep(lsbeam),inum)
 
  call r8zero(ewghtdep0(lsbeam),inum)
 
  call r8zero(wghtdep(lsbeam),inum)
 
  call r8zero(zidep0(lsbeam),inum)
 
  call r8zero(zitrk0(lsbeam),inum)
 
  do ib=1,nbeam
     if(lsbeama(ib).eq.lsbeam) then
        call r8zero(sfrac_survive(1:3,ib),inum)
     endif
  enddo
 
  do ib=1,nbeam
     if(lsbeama(ib).eq.lsbeam) then
        call r8zero(wfrac_survive(1:3,ib),inum)
     endif
  enddo
 
  do ib=1,nbeam
     if(lsbeama(ib).eq.lsbeam) then
        call r8zero(bn002(ib,1:3,1:2,1:mimxbzf),inum)
     endif
  enddo
 
  do ib=1,nbeam
     if(lsbeama(ib).eq.lsbeam) then
        call r8zero(hexbbcx0(ib,1:3,1:2,1:mimxbzf,1:nsfast),inum)
     endif
  enddo
 
 
  call r8zero(srbn02_dep(1:mimxbz,1:ng,lsbeam),inum)
 
  do ib=1,nbeam
     if(lsbeama(ib).eq.lsbeam) then
        call r8zero(vcxbn0(ib,1:3,1:2,1:mimxbzf),inum)
     endif
  enddo
 
  do ib=1,nbeam
     if(lsbeama(ib).eq.lsbeam) then
        call r8zero(vpvn00(ib,1:3,lcentr:lep1),inum)
     endif
  enddo
 
  call r8zero(wtrap0(lcentr:lep1,lsbeam),inum)
 
  call r8zero(xn_dep(lsbeam),inum)
 
  call r8zero(xn_orb(lsbeam),inum)
 
  call r8zero(xp_dep(lsbeam),inum)
 
  call r8zero(xp_orb(lsbeam),inum)
 
  call r8zero(xph_dep(lsbeam),inum)
 
  call r8zero(xph_orb(lsbeam),inum)
 
  call r8zero(fpixbts_dep(lcentr:lep1,lsbeam),inum)
 
  call r8zero(tirtots_dep(lcentr:lep1,lsbeam),inum)
 
  call r8zero(fbdepco(lcentr:lep1,lsbeam),inum)
 
  call r8zero(fbdepct(lcentr:lep1,lsbeam),inum)
 
  call r8zero(wkill(lsbeam),inum)
 
  call r8zero(wnkill(lsbeam),inum)
 
  call r8zero(taubpa(lcentr:lep1,1:20,lsbeam),inum)
 
  call r8zero(taubsl(lcentr:lep1,1:20,lsbeam),inum)
 
  do ib=1,nbeam
     if(lsbeama(ib).eq.lsbeam) then
        call r8zero(bdepb(lcentr:lep1,1:3,ib),inum)
     endif
  enddo
 
  call r8zero(sdep_oa(lcentr:lep1,lsbeam),inum)
 
  call r8zero(mc_newdens(lcentr:lep1,lsbeam),inum)
 
  call r8zero(einjav(lsbeam),inum)
 
  call r8zero(sbbidpe(lcentr:lep1,1:3,lsbeam),inum)
 
  call r8zero(sbbidps(lcentr:lep1,lsbeam),inum)
 
  call r8zero(sbbxdpe(lcentr:lep1,1:3,lsbeam),inum)
 
  call r8zero(sbbxdps(lcentr:lep1,lsbeam),inum)
 
  call r8zero(sbcxdpe(lcentr:lep1,1:ng,1:3,lsbeam),inum)
 
  call r8zero(sbedepe(lcentr:lep1,1:3,lsbeam),inum)
 
  call r8zero(sbedeps(lcentr:lep1,lsbeam),inum)
 
  call r8zero(sbiedepe(lcentr:lep1,1:3,lsbeam),inum)
 
  call r8zero(sbiedeps(lcentr:lep1,lsbeam),inum)
 
  call r8zero(sbildepe(lcentr:lep1,1:3,lsbeam),inum)
 
  call r8zero(sbildeps(lcentr:lep1,lsbeam),inum)
 
  call r8zero(sbizdepe(lcentr:lep1,1:3,lsbeam),inum)
 
  call r8zero(sbizdeps(lcentr:lep1,lsbeam),inum)
 
  do ib=1,nbeam
     if(lsbeama(ib).eq.lsbeam) then
        call r8zero(bpshna(ib,1:3),inum)
     endif
  enddo
 
  do ib=1,nbeam
     if(lsbeama(ib).eq.lsbeam) then
        call r8zero(bn00(ib,1:3,lcentr:lep1),inum)
     endif
  enddo
 
  call r8zero(btrap0(lcentr:lep1,lsbeam),inum)
 
  call r8zero(excit0(lcentr:lep1,1:3,lsbeam),inum)
 
  call r8zero(pbephis_dep(lcentr:lep1,lsbeam),inum)
 
  call r8zero(sorbn0s_dep(lcentr:lep1,1:ng,lsbeam),inum)
 
  call r8zero(sorbes_dep(lcentr:lep1,lsbeam),inum)
 
  call r8zero(sorbhs_dep(lcentr:lep1,1:ng,lsbeam),inum)
 
  call r8zero(tqbcxs_dep(lcentr:lep1,lsbeam),inum)
 
  call r8zero(tqjxbs_dep(lcentr:lep1,lsbeam),inum)
 
  do ib=1,nbeam
     if(lsbeama(ib).eq.lsbeam) then
        call r8zero(tqjxb_nb_dep(lcentr:lep1,ib),inum)
     endif
  enddo
 
  call r8zero(bpls_dep(lsbeam),inum)
 
  call r8zero(bpshins(lsbeam),inum)
 
  do ib=1,nbeam
     if(lsbeama(ib).eq.lsbeam) then
        call r8zero(bpprma(ib),inum)
     endif
  enddo
 
  call r8zero(bphinjs(lsbeam),inum)
 
  call r8zero(bphdepsgc(lsbeam),inum)
 
  call r8zero(bphdeps(lsbeam),inum)
 
  call r8zero(bphshins(lsbeam),inum)
 
  call r8zero(bphjxbs_dep(lsbeam),inum)
 
  call r8zero(bphorbs_dep(lsbeam),inum)
 
  call r8zero(bpjxbs_dep(lsbeam),inum)
 
  call r8zero(bxflws_dep(lsbeam),inum)
 
  call r8zero(sfdbbcx(lsbeam),inum)
 
  call r8zero(sfdbbiz(lsbeam),inum)
 
  call r8zero(sfdepcx(lsbeam),inum)
 
  call r8zero(sfdepiz(lsbeam),inum)
 
  call r8zero(sfdeprr(lsbeam),inum)
 
  call r8zero(sfdepsc(lsbeam),inum)
 
  call r8zero(sforbrr(lsbeam),inum)
 
  call r8zero(sfshine(lsbeam),inum)
 
end subroutine nbi_zzero_dep
 
subroutine nbi_pput_dep
  use nbi_com
  use nbi_pllbuf
  implicit NONE
 
  integer ir,ib,inum
 
  inum = 0
  nbuf_data =  nbuf_dep + 1   ! count puseyp(lsbeam)
 
  call r8put(dep_code_error(lsbeam),inum)
 
  call r8put(xmcloss_d(lsbeam),inum)
 
  call r8put(weinjav(lsbeam),inum)
 
  call r8put(ewghtdep(lsbeam),inum)
 
  call r8put(ewghtdep0(lsbeam),inum)
 
  call r8put(wghtdep(lsbeam),inum)
 
  call r8put(zidep0(lsbeam),inum)
 
  call r8put(zitrk0(lsbeam),inum)
 
  do ib=1,nbeam
     if(lsbeama(ib).eq.lsbeam) then
        call r8put(sfrac_survive(1:3,ib),inum)
     endif
  enddo
 
  do ib=1,nbeam
     if(lsbeama(ib).eq.lsbeam) then
        call r8put(wfrac_survive(1:3,ib),inum)
     endif
  enddo
 
  do ib=1,nbeam
     if(lsbeama(ib).eq.lsbeam) then
        call r8put(bn002(ib,1:3,1:2,1:mimxbzf),inum)
     endif
  enddo
 
  do ib=1,nbeam
     if(lsbeama(ib).eq.lsbeam) then
        call r8put(hexbbcx0(ib,1:3,1:2,1:mimxbzf,1:nsfast),inum)
     endif
  enddo
 
  call r8put(puseyp(lsbeam),inum)
 
  call r8put(srbn02_dep(1:mimxbz,1:ng,lsbeam),inum)
 
  do ib=1,nbeam
     if(lsbeama(ib).eq.lsbeam) then
        call r8put(vcxbn0(ib,1:3,1:2,1:mimxbzf),inum)
     endif
  enddo
 
  do ib=1,nbeam
     if(lsbeama(ib).eq.lsbeam) then
        call r8put(vpvn00(ib,1:3,lcentr:lep1),inum)
     endif
  enddo
 
  call r8put(wtrap0(lcentr:lep1,lsbeam),inum)
 
  call r8put(xn_dep(lsbeam),inum)
 
  call r8put(xn_orb(lsbeam),inum)
 
  call r8put(xp_dep(lsbeam),inum)
 
  call r8put(xp_orb(lsbeam),inum)
 
  call r8put(xph_dep(lsbeam),inum)
 
  call r8put(xph_orb(lsbeam),inum)
 
  call r8put(fpixbts_dep(lcentr:lep1,lsbeam),inum)
 
  call r8put(tirtots_dep(lcentr:lep1,lsbeam),inum)
 
  call r8put(fbdepco(lcentr:lep1,lsbeam),inum)
 
  call r8put(fbdepct(lcentr:lep1,lsbeam),inum)
 
  call r8put(wkill(lsbeam),inum)
 
  call r8put(wnkill(lsbeam),inum)
 
  call r8put(taubpa(lcentr:lep1,1:20,lsbeam),inum)
 
  call r8put(taubsl(lcentr:lep1,1:20,lsbeam),inum)
 
  do ib=1,nbeam
     if(lsbeama(ib).eq.lsbeam) then
        call r8put(bdepb(lcentr:lep1,1:3,ib),inum)
     endif
  enddo
 
  call r8put(sdep_oa(lcentr:lep1,lsbeam),inum)
 
  call r8put(mc_newdens(lcentr:lep1,lsbeam),inum)
 
  call r8put(einjav(lsbeam),inum)
 
  call r8put(sbbidpe(lcentr:lep1,1:3,lsbeam),inum)
 
  call r8put(sbbidps(lcentr:lep1,lsbeam),inum)
 
  call r8put(sbbxdpe(lcentr:lep1,1:3,lsbeam),inum)
 
  call r8put(sbbxdps(lcentr:lep1,lsbeam),inum)
 
  call r8put(sbcxdpe(lcentr:lep1,1:ng,1:3,lsbeam),inum)
 
  call r8put(sbedepe(lcentr:lep1,1:3,lsbeam),inum)
 
  call r8put(sbedeps(lcentr:lep1,lsbeam),inum)
 
  call r8put(sbiedepe(lcentr:lep1,1:3,lsbeam),inum)
 
  call r8put(sbiedeps(lcentr:lep1,lsbeam),inum)
 
  call r8put(sbildepe(lcentr:lep1,1:3,lsbeam),inum)
 
  call r8put(sbildeps(lcentr:lep1,lsbeam),inum)
 
  call r8put(sbizdepe(lcentr:lep1,1:3,lsbeam),inum)
 
  call r8put(sbizdeps(lcentr:lep1,lsbeam),inum)
 
  do ib=1,nbeam
     if(lsbeama(ib).eq.lsbeam) then
        call r8put(bpshna(ib,1:3),inum)
     endif
  enddo
 
  do ib=1,nbeam
     if(lsbeama(ib).eq.lsbeam) then
        call r8put(bn00(ib,1:3,lcentr:lep1),inum)
     endif
  enddo
 
  call r8put(btrap0(lcentr:lep1,lsbeam),inum)
 
  call r8put(excit0(lcentr:lep1,1:3,lsbeam),inum)
 
  call r8put(pbephis_dep(lcentr:lep1,lsbeam),inum)
 
  call r8put(sorbn0s_dep(lcentr:lep1,1:ng,lsbeam),inum)
 
  call r8put(sorbes_dep(lcentr:lep1,lsbeam),inum)
 
  call r8put(sorbhs_dep(lcentr:lep1,1:ng,lsbeam),inum)
 
  call r8put(tqbcxs_dep(lcentr:lep1,lsbeam),inum)
 
  call r8put(tqjxbs_dep(lcentr:lep1,lsbeam),inum)
 
  do ib=1,nbeam
     if(lsbeama(ib).eq.lsbeam) then
        call r8put(tqjxb_nb_dep(lcentr:lep1,ib),inum)
     endif
  enddo
 
  call r8put(bpls_dep(lsbeam),inum)
 
  call r8put(bpshins(lsbeam),inum)
 
  do ib=1,nbeam
     if(lsbeama(ib).eq.lsbeam) then
        call r8put(bpprma(ib),inum)
     endif
  enddo
 
  call r8put(bphinjs(lsbeam),inum)
 
  call r8put(bphdepsgc(lsbeam),inum)
 
  call r8put(bphdeps(lsbeam),inum)
 
  call r8put(bphshins(lsbeam),inum)
 
  call r8put(bphjxbs_dep(lsbeam),inum)
 
  call r8put(bphorbs_dep(lsbeam),inum)
 
  call r8put(bpjxbs_dep(lsbeam),inum)
 
  call r8put(bxflws_dep(lsbeam),inum)
 
  call r8put(sfdbbcx(lsbeam),inum)
 
  call r8put(sfdbbiz(lsbeam),inum)
 
  call r8put(sfdepcx(lsbeam),inum)
 
  call r8put(sfdepiz(lsbeam),inum)
 
  call r8put(sfdeprr(lsbeam),inum)
 
  call r8put(sfdepsc(lsbeam),inum)
 
  call r8put(sforbrr(lsbeam),inum)
 
  call r8put(sfshine(lsbeam),inum)
 
end subroutine nbi_pput_dep
 
subroutine nbi_pget_dep
  use nbi_com
  use nbi_pllbuf
  implicit NONE
 
  integer ir,ib,inum
 
  inum = 0
 
  call r8get(dep_code_error(lsbeam),inum)
 
  call r8get(xmcloss_d(lsbeam),inum)
 
  call r8get(weinjav(lsbeam),inum)
 
  call r8get(ewghtdep(lsbeam),inum)
 
  call r8get(ewghtdep0(lsbeam),inum)
 
  call r8get(wghtdep(lsbeam),inum)
 
  call r8get(zidep0(lsbeam),inum)
 
  call r8get(zitrk0(lsbeam),inum)
 
  do ib=1,nbeam
     if(lsbeama(ib).eq.lsbeam) then
        call r8get(sfrac_survive(1:3,ib),inum)
     endif
  enddo
 
  do ib=1,nbeam
     if(lsbeama(ib).eq.lsbeam) then
        call r8get(wfrac_survive(1:3,ib),inum)
     endif
  enddo
 
  do ib=1,nbeam
     if(lsbeama(ib).eq.lsbeam) then
        call r8get(bn002(ib,1:3,1:2,1:mimxbzf),inum)
     endif
  enddo
 
  do ib=1,nbeam
     if(lsbeama(ib).eq.lsbeam) then
        call r8get(hexbbcx0(ib,1:3,1:2,1:mimxbzf,1:nsfast),inum)
     endif
  enddo
 
  call r8get(puseyp(lsbeam),inum)
 
  call r8get(srbn02_dep(1:mimxbz,1:ng,lsbeam),inum)
 
  do ib=1,nbeam
     if(lsbeama(ib).eq.lsbeam) then
        call r8get(vcxbn0(ib,1:3,1:2,1:mimxbzf),inum)
     endif
  enddo
 
  do ib=1,nbeam
     if(lsbeama(ib).eq.lsbeam) then
        call r8get(vpvn00(ib,1:3,lcentr:lep1),inum)
     endif
  enddo
 
  call r8get(wtrap0(lcentr:lep1,lsbeam),inum)
 
  call r8get(xn_dep(lsbeam),inum)
 
  call r8get(xn_orb(lsbeam),inum)
 
  call r8get(xp_dep(lsbeam),inum)
 
  call r8get(xp_orb(lsbeam),inum)
 
  call r8get(xph_dep(lsbeam),inum)
 
  call r8get(xph_orb(lsbeam),inum)
 
  call r8get(fpixbts_dep(lcentr:lep1,lsbeam),inum)
 
  call r8get(tirtots_dep(lcentr:lep1,lsbeam),inum)
 
  call r8get(fbdepco(lcentr:lep1,lsbeam),inum)
 
  call r8get(fbdepct(lcentr:lep1,lsbeam),inum)
 
  call r8get(wkill(lsbeam),inum)
 
  call r8get(wnkill(lsbeam),inum)
 
  call r8get(taubpa(lcentr:lep1,1:20,lsbeam),inum)
 
  call r8get(taubsl(lcentr:lep1,1:20,lsbeam),inum)
 
  do ib=1,nbeam
     if(lsbeama(ib).eq.lsbeam) then
        call r8get(bdepb(lcentr:lep1,1:3,ib),inum)
     endif
  enddo
 
  call r8get(sdep_oa(lcentr:lep1,lsbeam),inum)
 
  call r8get(mc_newdens(lcentr:lep1,lsbeam),inum)
 
  call r8get(einjav(lsbeam),inum)
 
  call r8get(sbbidpe(lcentr:lep1,1:3,lsbeam),inum)
 
  call r8get(sbbidps(lcentr:lep1,lsbeam),inum)
 
  call r8get(sbbxdpe(lcentr:lep1,1:3,lsbeam),inum)
 
  call r8get(sbbxdps(lcentr:lep1,lsbeam),inum)
 
  call r8get(sbcxdpe(lcentr:lep1,1:ng,1:3,lsbeam),inum)
 
  call r8get(sbedepe(lcentr:lep1,1:3,lsbeam),inum)
 
  call r8get(sbedeps(lcentr:lep1,lsbeam),inum)
 
  call r8get(sbiedepe(lcentr:lep1,1:3,lsbeam),inum)
 
  call r8get(sbiedeps(lcentr:lep1,lsbeam),inum)
 
  call r8get(sbildepe(lcentr:lep1,1:3,lsbeam),inum)
 
  call r8get(sbildeps(lcentr:lep1,lsbeam),inum)
 
  call r8get(sbizdepe(lcentr:lep1,1:3,lsbeam),inum)
 
  call r8get(sbizdeps(lcentr:lep1,lsbeam),inum)
 
  do ib=1,nbeam
     if(lsbeama(ib).eq.lsbeam) then
        call r8get(bpshna(ib,1:3),inum)
     endif
  enddo
 
  do ib=1,nbeam
     if(lsbeama(ib).eq.lsbeam) then
        call r8get(bn00(ib,1:3,lcentr:lep1),inum)
     endif
  enddo
 
  call r8get(btrap0(lcentr:lep1,lsbeam),inum)
 
  call r8get(excit0(lcentr:lep1,1:3,lsbeam),inum)
 
  call r8get(pbephis_dep(lcentr:lep1,lsbeam),inum)
 
  call r8get(sorbn0s_dep(lcentr:lep1,1:ng,lsbeam),inum)
 
  call r8get(sorbes_dep(lcentr:lep1,lsbeam),inum)
 
  call r8get(sorbhs_dep(lcentr:lep1,1:ng,lsbeam),inum)
 
  call r8get(tqbcxs_dep(lcentr:lep1,lsbeam),inum)
 
  call r8get(tqjxbs_dep(lcentr:lep1,lsbeam),inum)
 
  do ib=1,nbeam
     if(lsbeama(ib).eq.lsbeam) then
        call r8get(tqjxb_nb_dep(lcentr:lep1,ib),inum)
     endif
  enddo
 
  call r8get(bpls_dep(lsbeam),inum)
 
  call r8get(bpshins(lsbeam),inum)
 
  do ib=1,nbeam
     if(lsbeama(ib).eq.lsbeam) then
        call r8get(bpprma(ib),inum)
     endif
  enddo
 
  call r8get(bphinjs(lsbeam),inum)
 
  call r8get(bphdepsgc(lsbeam),inum)
 
  call r8get(bphdeps(lsbeam),inum)
 
  call r8get(bphshins(lsbeam),inum)
 
  call r8get(bphjxbs_dep(lsbeam),inum)
 
  call r8get(bphorbs_dep(lsbeam),inum)
 
  call r8get(bpjxbs_dep(lsbeam),inum)
 
  call r8get(bxflws_dep(lsbeam),inum)
 
  call r8get(sfdbbcx(lsbeam),inum)
 
  call r8get(sfdbbiz(lsbeam),inum)
 
  call r8get(sfdepcx(lsbeam),inum)
 
  call r8get(sfdepiz(lsbeam),inum)
 
  call r8get(sfdeprr(lsbeam),inum)
 
  call r8get(sfdepsc(lsbeam),inum)
 
  call r8get(sforbrr(lsbeam),inum)
 
  call r8get(sfshine(lsbeam),inum)
 
end subroutine nbi_pget_dep
 
subroutine nbi_zcheck_ntr
  use nbi_com
  use nbi_pllbuf
  implicit NONE
 
  integer ir,ib,inum
 
  inum = 0
  nbuf_data = 0
  nbuf_ntr = 0
 
  call r8nz(be0cx(lcentr:lep1,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in be0cx(lcentr:lep1,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(be0cx2(1:mimxbz,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in be0cx2(1:mimxbz,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(be20cx2(1:mimxbz,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in be20cx2(1:mimxbz,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(bn0cx2(1:mimxbz,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in bn0cx2(1:mimxbz,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(bv0cx2(1:mimxbz,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in bv0cx2(1:mimxbz,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(bvrhocx2(1:mimxbz,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in bvrhocx2(1:mimxbz,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(bvthcx2(1:mimxbz,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in bvthcx2(1:mimxbz,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(bvpllcx2(1:mimxbz,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in bvpllcx2(1:mimxbz,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(balpha_gyro(1:mimxbz,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in balpha_gyro(1:mimxbz,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(hexbbxrc(1:mimxbz,lsbeam,1:nsfast),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in hexbbxrc(1:mimxbz,lsbeam,1:nsfast) at lsbeam=",lsbeam
  endif
 
  call r8nz(srbn02(1:mimxbz,1:ng,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in srbn02(1:mimxbz,1:ng,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(bv0cx(lcentr:lep1,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in bv0cx(lcentr:lep1,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(fpixbts_ntr(lcentr:lep1,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in fpixbts_ntr(lcentr:lep1,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(tirtots_ntr(lcentr:lep1,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in tirtots_ntr(lcentr:lep1,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(bn0cx(lcentr:lep1,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in bn0cx(lcentr:lep1,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(excitr(lcentr:lep1,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in excitr(lcentr:lep1,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(pbephis_ntr(lcentr:lep1,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in pbephis_ntr(lcentr:lep1,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(sbcx0s(lcentr:lep1,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in sbcx0s(lcentr:lep1,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(sorbn0s(lcentr:lep1,1:ng,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in sorbn0s(lcentr:lep1,1:ng,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(sbcxrbs(lcentr:lep1,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in sbcxrbs(lcentr:lep1,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(sbcxres(lcentr:lep1,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in sbcxres(lcentr:lep1,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(sbcxris(lcentr:lep1,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in sbcxris(lcentr:lep1,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(sbcxrls(lcentr:lep1,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in sbcxrls(lcentr:lep1,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(sbcxrxs(1:ng,lcentr:lep1,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in sbcxrxs(1:ng,lcentr:lep1,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(sbcxrzs(lcentr:lep1,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in sbcxrzs(lcentr:lep1,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(sorbes_ntr(lcentr:lep1,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in sorbes_ntr(lcentr:lep1,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(sorbhs_ntr(lcentr:lep1,1:ng,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in sorbhs_ntr(lcentr:lep1,1:ng,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(tqbcxs(lcentr:lep1,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in tqbcxs(lcentr:lep1,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(tqjxbs_ntr(lcentr:lep1,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in tqjxbs_ntr(lcentr:lep1,lsbeam) at lsbeam=",lsbeam
  endif
 
  do ib=1,nbeam
     if(lsbeama(ib).eq.lsbeam) then
        call r8nz(tqjxbnb_ntr(lcentr:lep1,ib),inum)
        if (inum.ne.0) then
           write(nonlin,*) &
               "non-zero value in tqjxbnb_ntr(lcentr:lep1,ib) at ib=",ib
        endif
     endif
  enddo
 
  call r8nz(bpcxers(lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in bpcxers(lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(bpcxi0s(lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in bpcxi0s(lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(bpcxins(lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in bpcxins(lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(bpcxots(lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in bpcxots(lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(bpcxris(lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in bpcxris(lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(bpcxrxs(lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in bpcxrxs(lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(bpcxx0s(lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in bpcxx0s(lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(bph0was(lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in bph0was(lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(bphcxls(lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in bphcxls(lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(bphjxbs_ntr(lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in bphjxbs_ntr(lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(bphrcas(lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in bphrcas(lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(bpjxbs_ntr(lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in bpjxbs_ntr(lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(sbcxxs(lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in sbcxxs(lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(sfcx0mc(lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in sfcx0mc(lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(sfcxmc1d(lcentr:lep1,lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in sfcxmc1d(lcentr:lep1,lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(sfcxesc(lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in sfcxesc(lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(sfcxrmc(lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in sfcxrmc(lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(sfcxrr(lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in sfcxrr(lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(sfrbbcx(lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in sfrbbcx(lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(sfrbbiz(lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in sfrbbiz(lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(sfxrccx(lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in sfxrccx(lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(sfxrciz(lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in sfxrciz(lsbeam) at lsbeam=",lsbeam
  endif
 
  call r8nz(sfxrcsc(lsbeam),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in sfxrcsc(lsbeam) at lsbeam=",lsbeam
  endif
 
  nbuf_ntr = nbuf_data
end subroutine nbi_zcheck_ntr
 
subroutine nbi_zzero_ntr
  use nbi_com
  use nbi_pllbuf
  implicit NONE
 
  integer ir,ib,inum
 
  inum = 0
 
  call r8zero(be0cx(lcentr:lep1,lsbeam),inum)
 
  call r8zero(be0cx2(1:mimxbz,lsbeam),inum)
 
  call r8zero(be20cx2(1:mimxbz,lsbeam),inum)
 
  call r8zero(bn0cx2(1:mimxbz,lsbeam),inum)
 
  call r8zero(bv0cx2(1:mimxbz,lsbeam),inum)
 
  call r8zero(bvrhocx2(1:mimxbz,lsbeam),inum)
 
  call r8zero(bvthcx2(1:mimxbz,lsbeam),inum)
 
  call r8zero(bvpllcx2(1:mimxbz,lsbeam),inum)
 
  call r8zero(balpha_gyro(1:mimxbz,lsbeam),inum)
 
  call r8zero(hexbbxrc(1:mimxbz,lsbeam,1:nsfast),inum)
 
  call r8zero(srbn02(1:mimxbz,1:ng,lsbeam),inum)
 
  call r8zero(bv0cx(lcentr:lep1,lsbeam),inum)
 
  call r8zero(fpixbts_ntr(lcentr:lep1,lsbeam),inum)
 
  call r8zero(tirtots_ntr(lcentr:lep1,lsbeam),inum)
 
  call r8zero(bn0cx(lcentr:lep1,lsbeam),inum)
 
  call r8zero(excitr(lcentr:lep1,lsbeam),inum)
 
  call r8zero(pbephis_ntr(lcentr:lep1,lsbeam),inum)
 
  call r8zero(sbcx0s(lcentr:lep1,lsbeam),inum)
 
  call r8zero(sorbn0s(lcentr:lep1,1:ng,lsbeam),inum)
 
  call r8zero(sbcxrbs(lcentr:lep1,lsbeam),inum)
 
  call r8zero(sbcxres(lcentr:lep1,lsbeam),inum)
 
  call r8zero(sbcxris(lcentr:lep1,lsbeam),inum)
 
  call r8zero(sbcxrls(lcentr:lep1,lsbeam),inum)
 
  call r8zero(sbcxrxs(1:ng,lcentr:lep1,lsbeam),inum)
 
  call r8zero(sbcxrzs(lcentr:lep1,lsbeam),inum)
 
  call r8zero(sorbes_ntr(lcentr:lep1,lsbeam),inum)
 
  call r8zero(sorbhs_ntr(lcentr:lep1,1:ng,lsbeam),inum)
 
  call r8zero(tqbcxs(lcentr:lep1,lsbeam),inum)
 
  call r8zero(tqjxbs_ntr(lcentr:lep1,lsbeam),inum)
 
  do ib=1,nbeam
     if(lsbeama(ib).eq.lsbeam) then
        call r8zero(tqjxbnb_ntr(lcentr:lep1,ib),inum)
     endif
  enddo
 
  call r8zero(bpcxers(lsbeam),inum)
 
  call r8zero(bpcxi0s(lsbeam),inum)
 
  call r8zero(bpcxins(lsbeam),inum)
 
  call r8zero(bpcxots(lsbeam),inum)
 
  call r8zero(bpcxris(lsbeam),inum)
 
  call r8zero(bpcxrxs(lsbeam),inum)
 
  call r8zero(bpcxx0s(lsbeam),inum)
 
  call r8zero(bph0was(lsbeam),inum)
 
  call r8zero(bphcxls(lsbeam),inum)
 
  call r8zero(bphjxbs_ntr(lsbeam),inum)
 
  call r8zero(bphrcas(lsbeam),inum)
 
  call r8zero(bpjxbs_ntr(lsbeam),inum)
 
  call r8zero(sbcxxs(lsbeam),inum)
 
  call r8zero(sfcx0mc(lsbeam),inum)
 
  call r8zero(sfcxmc1d(lcentr:lep1,lsbeam),inum)
 
  call r8zero(sfcxesc(lsbeam),inum)
 
  call r8zero(sfcxrmc(lsbeam),inum)
 
  call r8zero(sfcxrr(lsbeam),inum)
 
  call r8zero(sfrbbcx(lsbeam),inum)
 
  call r8zero(sfrbbiz(lsbeam),inum)
 
  call r8zero(sfxrccx(lsbeam),inum)
 
  call r8zero(sfxrciz(lsbeam),inum)
 
  call r8zero(sfxrcsc(lsbeam),inum)
 
end subroutine nbi_zzero_ntr
 
subroutine nbi_pput_ntr
  use nbi_com
  use nbi_pllbuf
  implicit NONE
 
  integer ir,ib,inum
 
  inum = 0
  nbuf_data =  nbuf_ntr
 
  call r8put(be0cx(lcentr:lep1,lsbeam),inum)
 
  call r8put(be0cx2(1:mimxbz,lsbeam),inum)
 
  call r8put(be20cx2(1:mimxbz,lsbeam),inum)
 
  call r8put(bn0cx2(1:mimxbz,lsbeam),inum)
 
  call r8put(bv0cx2(1:mimxbz,lsbeam),inum)
 
  call r8put(bvrhocx2(1:mimxbz,lsbeam),inum)
 
  call r8put(bvthcx2(1:mimxbz,lsbeam),inum)
 
  call r8put(bvpllcx2(1:mimxbz,lsbeam),inum)
 
  call r8put(balpha_gyro(1:mimxbz,lsbeam),inum)
 
  call r8put(hexbbxrc(1:mimxbz,lsbeam,1:nsfast),inum)
 
  call r8put(srbn02(1:mimxbz,1:ng,lsbeam),inum)
 
  call r8put(bv0cx(lcentr:lep1,lsbeam),inum)
 
  call r8put(fpixbts_ntr(lcentr:lep1,lsbeam),inum)
 
  call r8put(tirtots_ntr(lcentr:lep1,lsbeam),inum)
 
  call r8put(bn0cx(lcentr:lep1,lsbeam),inum)
 
  call r8put(excitr(lcentr:lep1,lsbeam),inum)
 
  call r8put(pbephis_ntr(lcentr:lep1,lsbeam),inum)
 
  call r8put(sbcx0s(lcentr:lep1,lsbeam),inum)
 
  call r8put(sorbn0s(lcentr:lep1,1:ng,lsbeam),inum)
 
  call r8put(sbcxrbs(lcentr:lep1,lsbeam),inum)
 
  call r8put(sbcxres(lcentr:lep1,lsbeam),inum)
 
  call r8put(sbcxris(lcentr:lep1,lsbeam),inum)
 
  call r8put(sbcxrls(lcentr:lep1,lsbeam),inum)
 
  call r8put(sbcxrxs(1:ng,lcentr:lep1,lsbeam),inum)
 
  call r8put(sbcxrzs(lcentr:lep1,lsbeam),inum)
 
  call r8put(sorbes_ntr(lcentr:lep1,lsbeam),inum)
 
  call r8put(sorbhs_ntr(lcentr:lep1,1:ng,lsbeam),inum)
 
  call r8put(tqbcxs(lcentr:lep1,lsbeam),inum)
 
  call r8put(tqjxbs_ntr(lcentr:lep1,lsbeam),inum)
 
  do ib=1,nbeam
     if(lsbeama(ib).eq.lsbeam) then
        call r8put(tqjxbnb_ntr(lcentr:lep1,ib),inum)
     endif
  enddo
 
  call r8put(bpcxers(lsbeam),inum)
 
  call r8put(bpcxi0s(lsbeam),inum)
 
  call r8put(bpcxins(lsbeam),inum)
 
  call r8put(bpcxots(lsbeam),inum)
 
  call r8put(bpcxris(lsbeam),inum)
 
  call r8put(bpcxrxs(lsbeam),inum)
 
  call r8put(bpcxx0s(lsbeam),inum)
 
  call r8put(bph0was(lsbeam),inum)
 
  call r8put(bphcxls(lsbeam),inum)
 
  call r8put(bphjxbs_ntr(lsbeam),inum)
 
  call r8put(bphrcas(lsbeam),inum)
 
  call r8put(bpjxbs_ntr(lsbeam),inum)
 
  call r8put(sbcxxs(lsbeam),inum)
 
  call r8put(sfcx0mc(lsbeam),inum)
 
  call r8put(sfcxmc1d(lcentr:lep1,lsbeam),inum)
 
  call r8put(sfcxesc(lsbeam),inum)
 
  call r8put(sfcxrmc(lsbeam),inum)
 
  call r8put(sfcxrr(lsbeam),inum)
 
  call r8put(sfrbbcx(lsbeam),inum)
 
  call r8put(sfrbbiz(lsbeam),inum)
 
  call r8put(sfxrccx(lsbeam),inum)
 
  call r8put(sfxrciz(lsbeam),inum)
 
  call r8put(sfxrcsc(lsbeam),inum)
 
end subroutine nbi_pput_ntr
 
subroutine nbi_pget_ntr
  use nbi_com
  use nbi_pllbuf
  implicit NONE
 
  integer ir,ib,inum
 
  inum = 0
 
  call r8get(be0cx(lcentr:lep1,lsbeam),inum)
 
  call r8get(be0cx2(1:mimxbz,lsbeam),inum)
 
  call r8get(be20cx2(1:mimxbz,lsbeam),inum)
 
  call r8get(bn0cx2(1:mimxbz,lsbeam),inum)
 
  call r8get(bv0cx2(1:mimxbz,lsbeam),inum)
 
  call r8get(bvrhocx2(1:mimxbz,lsbeam),inum)
 
  call r8get(bvthcx2(1:mimxbz,lsbeam),inum)
 
  call r8get(bvpllcx2(1:mimxbz,lsbeam),inum)
 
  call r8get(balpha_gyro(1:mimxbz,lsbeam),inum)
 
  call r8get(hexbbxrc(1:mimxbz,lsbeam,1:nsfast),inum)
 
  call r8get(srbn02(1:mimxbz,1:ng,lsbeam),inum)
 
  call r8get(bv0cx(lcentr:lep1,lsbeam),inum)
 
  call r8get(fpixbts_ntr(lcentr:lep1,lsbeam),inum)
 
  call r8get(tirtots_ntr(lcentr:lep1,lsbeam),inum)
 
  call r8get(bn0cx(lcentr:lep1,lsbeam),inum)
 
  call r8get(excitr(lcentr:lep1,lsbeam),inum)
 
  call r8get(pbephis_ntr(lcentr:lep1,lsbeam),inum)
 
  call r8get(sbcx0s(lcentr:lep1,lsbeam),inum)
 
  call r8get(sorbn0s(lcentr:lep1,1:ng,lsbeam),inum)
 
  call r8get(sbcxrbs(lcentr:lep1,lsbeam),inum)
 
  call r8get(sbcxres(lcentr:lep1,lsbeam),inum)
 
  call r8get(sbcxris(lcentr:lep1,lsbeam),inum)
 
  call r8get(sbcxrls(lcentr:lep1,lsbeam),inum)
 
  call r8get(sbcxrxs(1:ng,lcentr:lep1,lsbeam),inum)
 
  call r8get(sbcxrzs(lcentr:lep1,lsbeam),inum)
 
  call r8get(sorbes_ntr(lcentr:lep1,lsbeam),inum)
 
  call r8get(sorbhs_ntr(lcentr:lep1,1:ng,lsbeam),inum)
 
  call r8get(tqbcxs(lcentr:lep1,lsbeam),inum)
 
  call r8get(tqjxbs_ntr(lcentr:lep1,lsbeam),inum)
 
  do ib=1,nbeam
     if(lsbeama(ib).eq.lsbeam) then
        call r8get(tqjxbnb_ntr(lcentr:lep1,ib),inum)
     endif
  enddo
 
  call r8get(bpcxers(lsbeam),inum)
 
  call r8get(bpcxi0s(lsbeam),inum)
 
  call r8get(bpcxins(lsbeam),inum)
 
  call r8get(bpcxots(lsbeam),inum)
 
  call r8get(bpcxris(lsbeam),inum)
 
  call r8get(bpcxrxs(lsbeam),inum)
 
  call r8get(bpcxx0s(lsbeam),inum)
 
  call r8get(bph0was(lsbeam),inum)
 
  call r8get(bphcxls(lsbeam),inum)
 
  call r8get(bphjxbs_ntr(lsbeam),inum)
 
  call r8get(bphrcas(lsbeam),inum)
 
  call r8get(bpjxbs_ntr(lsbeam),inum)
 
  call r8get(sbcxxs(lsbeam),inum)
 
  call r8get(sfcx0mc(lsbeam),inum)
 
  call r8get(sfcxmc1d(lcentr:lep1,lsbeam),inum)
 
  call r8get(sfcxesc(lsbeam),inum)
 
  call r8get(sfcxrmc(lsbeam),inum)
 
  call r8get(sfcxrr(lsbeam),inum)
 
  call r8get(sfrbbcx(lsbeam),inum)
 
  call r8get(sfrbbiz(lsbeam),inum)
 
  call r8get(sfxrccx(lsbeam),inum)
 
  call r8get(sfxrciz(lsbeam),inum)
 
  call r8get(sfxrcsc(lsbeam),inum)
 
end subroutine nbi_pget_ntr
 
subroutine nbi_pput_dpt
  use nbi_com
  use nbi_pllbuf
  implicit NONE
 
  integer ir,ib,inum
 
  inum = 0
  nbuf_data =  mdep0*mibs_use*12 + mtrk0*8 
 
  call r8put(track_nbsce(1:mdep0,1:mibs_use),inum)
  deallocate(track_nbsce)
 
  call r8put(track_nbien(1:mdep0,1:mibs_use),inum)
  deallocate(track_nbien)
 
  call r8put(xntrack(1:mdep0,1:mibs_use),inum)
  deallocate(xntrack)
 
  call r8put(track_rin(1:mdep0,1:mibs_use),inum)
  deallocate(track_rin)
 
  call r8put(track_zin(1:mdep0,1:mibs_use),inum)
  deallocate(track_zin)
 
  call r8put(track_phiin(1:mdep0,1:mibs_use),inum)
  deallocate(track_phiin)
 
  call r8put(track_rout(1:mdep0,1:mibs_use),inum)
  deallocate(track_rout)
 
  call r8put(track_zout(1:mdep0,1:mibs_use),inum)
  deallocate(track_zout)
 
  call r8put(track_phiout(1:mdep0,1:mibs_use),inum)
  deallocate(track_phiout)
 
  call r8put(track_time(1:mdep0,1:mibs_use),inum)
  deallocate(track_time)
 
  call r8put(track_einj(1:mdep0,1:mibs_use),inum)
  deallocate(track_einj)
 
  call r8put(track_sinj(1:mdep0,1:mibs_use),inum)
  deallocate(track_sinj)
 
  call r8put(track_xl(1:mtrk0),inum)
  deallocate(track_xl)
 
  call r8put(track_pdep(1:mtrk0),inum)
  deallocate(track_pdep)
 
  call r8put(track_dr_flr(1:mtrk0),inum)
  deallocate(track_dr_flr)
 
  call r8put(track_dz_flr(1:mtrk0),inum)
  deallocate(track_dz_flr)
 
  call r8put(track_de_flr(1:mtrk0),inum)
  deallocate(track_de_flr)
 
  call r8put(track_vpv_dep(1:mtrk0),inum)
  deallocate(track_vpv_dep)
 
  call r8put(track_dvpv_flr(1:mtrk0),inum)
  deallocate(track_dvpv_flr)
 
  call r8put(track_xjadep(1:mtrk0),inum)
  deallocate(track_xjadep)
 
end subroutine nbi_pput_dpt
 
subroutine nbi_pget_dpt(mtrks)
! MPI run only. Read track data from black box and write to NetCdf file 
  use nbi_com
  use nbi_pllbuf
  use nbi_mpi_com
  use netcdf
  implicit NONE
 
  integer :: ir,isb,inum,ip,ic
  integer :: mdep,mtrk_0 !local
  real(fp), dimension(:,:),allocatable :: tmp !local
  integer :: id_ndep0_use, id_mdep, id_mibs_use, id_mtrk0
  character*150 fname !NetCdf file name for track data
  integer :: ierr
  character*30 :: cvar
  integer, parameter :: iversion_deptrk = 3 ! 3d arrays of the track data have been written as 1d arrays, 01/15/10
                                            ! iversion_deptrk = 2
  integer, dimension(:),allocatable :: mtrk_n, iadr_empty !local
  integer, dimension(*) :: mtrks !# of track for each species
  integer :: icdf
  integer :: id_iversion_deptrk
  integer, dimension(2) :: idims,istart,icount
  integer :: ijmem,fsystem_mem
! Serial run only. Write track data to NetCdf file 
  integer :: id_track_nbsce
  integer :: id_track_nbien
  integer :: id_xntrack
  integer :: id_track_rin
  integer :: id_track_zin
  integer :: id_track_phiin
  integer :: id_track_rout
  integer :: id_track_zout
  integer :: id_track_phiout
  integer :: id_track_time
  integer :: id_track_einj
  integer :: id_track_sinj
  integer :: id_track_xl
  integer :: id_track_pdep
  integer :: id_track_dr_flr
  integer :: id_track_dz_flr
  integer :: id_track_de_flr
  integer :: id_track_vpv_dep
  integer :: id_track_dvpv_flr
  integer :: id_track_xjadep
 
 
 if(mibs_use.le.0) then 
    write(nonlin,*) ' !nbi_pget_dpt: no beams species -- mibs_use.le.0'
    return 
 endif 
 ijmem = fsystem_mem() ! print out memory usage
 mdep = mdep0
 mdep0 = ndep0_use
 write(nonlin,*) ' %nbi_pget_dpt: ndep0_use=',ndep0_use,', mibs_use=',mibs_use,', mtrk0=',mtrk0
 
 inum = 0
 mtrk_0 = 0
 if(allocated(mtrk_n)) deallocate(mtrk_n)
 allocate(mtrk_n(mibs_use))
 if(allocated(iadr_empty)) deallocate(iadr_empty)
 allocate(iadr_empty(mibs_use))
 
 mtrk_n = 0
 iadr_empty = 0
 
 ierr=0
 fname = trim(workpath)//trim(runid)//'_dpt.cdf'
!overwrite file
 ierr = nf90_create(path=trim(fname),cmode= or(NF90_CLOBBER,NF90_64BIT_OFFSET),ncid=icdf)
 if(ierr.ne.0) then
   write(nonlin,*) ' ?nbi_pget_dpt error: cannot create file: '//trim(fname)
   return
 endif
 call check(nf90_def_var(icdf,'iversion_deptrk',NF90_INT,id_iversion_deptrk),'iversion_deptrk')
 call check(nf90_def_var(icdf,'mdep',NF90_INT,id_mdep),'mdep')
 call check(nf90_def_dim(icdf,'ndep0_use',ndep0_use,id_ndep0_use),'ndep0_use')
 call check(nf90_def_dim(icdf,'mtrk0',mtrk0,id_mtrk0),'mtrk0')
 call check(nf90_def_dim(icdf,'mibs_use',mibs_use,id_mibs_use),'mibs_use')
 
 idims = (/id_ndep0_use,id_mibs_use/)
 icount = (/mdep,mibs_use/)
 
  cvar = 'track_nbsce'
  call check( nf90_def_var(icdf,cvar,NF90_DOUBLE,idims,id_track_nbsce),cvar)
 
  cvar = 'track_nbien'
  call check( nf90_def_var(icdf,cvar,NF90_DOUBLE,idims,id_track_nbien),cvar)
 
  cvar = 'xntrack'
  call check( nf90_def_var(icdf,cvar,NF90_DOUBLE,idims,id_xntrack),cvar)
 
  cvar = 'track_rin'
  call check( nf90_def_var(icdf,cvar,NF90_DOUBLE,idims,id_track_rin),cvar)
 
  cvar = 'track_zin'
  call check( nf90_def_var(icdf,cvar,NF90_DOUBLE,idims,id_track_zin),cvar)
 
  cvar = 'track_phiin'
  call check( nf90_def_var(icdf,cvar,NF90_DOUBLE,idims,id_track_phiin),cvar)
 
  cvar = 'track_rout'
  call check( nf90_def_var(icdf,cvar,NF90_DOUBLE,idims,id_track_rout),cvar)
 
  cvar = 'track_zout'
  call check( nf90_def_var(icdf,cvar,NF90_DOUBLE,idims,id_track_zout),cvar)
 
  cvar = 'track_phiout'
  call check( nf90_def_var(icdf,cvar,NF90_DOUBLE,idims,id_track_phiout),cvar)
 
  cvar = 'track_time'
  call check( nf90_def_var(icdf,cvar,NF90_DOUBLE,idims,id_track_time),cvar)
 
  cvar = 'track_einj'
  call check( nf90_def_var(icdf,cvar,NF90_DOUBLE,idims,id_track_einj),cvar)
 
  cvar = 'track_sinj'
  call check( nf90_def_var(icdf,cvar,NF90_DOUBLE,idims,id_track_sinj),cvar)
 
  cvar = 'track_xl'
  call check( nf90_def_var(icdf,cvar,NF90_DOUBLE,id_mtrk0,id_track_xl),cvar)
 
  cvar = 'track_pdep'
  call check( nf90_def_var(icdf,cvar,NF90_DOUBLE,id_mtrk0,id_track_pdep),cvar)
 
  cvar = 'track_dr_flr'
  call check( nf90_def_var(icdf,cvar,NF90_DOUBLE,id_mtrk0,id_track_dr_flr),cvar)
 
  cvar = 'track_dz_flr'
  call check( nf90_def_var(icdf,cvar,NF90_DOUBLE,id_mtrk0,id_track_dz_flr),cvar)
 
  cvar = 'track_de_flr'
  call check( nf90_def_var(icdf,cvar,NF90_DOUBLE,id_mtrk0,id_track_de_flr),cvar)
 
  cvar = 'track_vpv_dep'
  call check( nf90_def_var(icdf,cvar,NF90_DOUBLE,id_mtrk0,id_track_vpv_dep),cvar)
 
  cvar = 'track_dvpv_flr'
  call check( nf90_def_var(icdf,cvar,NF90_DOUBLE,id_mtrk0,id_track_dvpv_flr),cvar)
 
  cvar = 'track_xjadep'
  call check( nf90_def_var(icdf,cvar,NF90_DOUBLE,id_mtrk0,id_track_xjadep),cvar)
 ierr = nf90_enddef(icdf) ! out of def mode and go to data mode
 
 call check( nf90_put_var(icdf,id_mdep,mdep),'mdep')
 call check( nf90_put_var(icdf,id_iversion_deptrk,iversion_deptrk),'iversion_deptrk')
 
 iadr_empty(1)=1
 if(mibs_use.gt.1)then
    do isb=2,mibs_use
       iadr_empty(isb)=iadr_empty(isb-1)+mtrks(isb-1)
    enddo 
  endif
 
 do ir = 1, numprocd
 
  if(allocated(tmp)) deallocate(tmp)
  allocate(tmp(mdep,mibs_use))
 
  istart = (/1+(ir-1)*mdep,1/)
 
  tmp = zero
 
  call r8get(tmp(1:mdep,1:mibs_use),inum)
 
  cvar = 'track_nbsce'
  call check( nf90_put_var(icdf,id_track_nbsce,tmp,start=istart,count=icount),cvar)
 
 
  tmp = zero
  call r8get(tmp(1:mdep,1:mibs_use),inum)
 
  cvar = 'track_nbien'
  call check( nf90_put_var(icdf,id_track_nbien,tmp,start=istart,count=icount),cvar)
 
 
  tmp = zero
  call r8get(tmp(1:mdep,1:mibs_use),inum)
 
  cvar = 'xntrack'
  call check( nf90_put_var(icdf,id_xntrack,tmp,start=istart,count=icount),cvar)
  mtrk_n(1:mibs_use) = sum(tmp(1:mdep,1:mibs_use),dim=1) + 0.5_fp
  mtrk_0 = sum(tmp(1:mdep,1:mibs_use)) + 0.5_fp
 
 
  tmp = zero
  call r8get(tmp(1:mdep,1:mibs_use),inum)
 
  cvar = 'track_rin'
  call check( nf90_put_var(icdf,id_track_rin,tmp,start=istart,count=icount),cvar)
 
 
  tmp = zero
  call r8get(tmp(1:mdep,1:mibs_use),inum)
 
  cvar = 'track_zin'
  call check( nf90_put_var(icdf,id_track_zin,tmp,start=istart,count=icount),cvar)
 
 
  tmp = zero
  call r8get(tmp(1:mdep,1:mibs_use),inum)
 
  cvar = 'track_phiin'
  call check( nf90_put_var(icdf,id_track_phiin,tmp,start=istart,count=icount),cvar)
 
 
  tmp = zero
  call r8get(tmp(1:mdep,1:mibs_use),inum)
 
  cvar = 'track_rout'
  call check( nf90_put_var(icdf,id_track_rout,tmp,start=istart,count=icount),cvar)
 
 
  tmp = zero
  call r8get(tmp(1:mdep,1:mibs_use),inum)
 
  cvar = 'track_zout'
  call check( nf90_put_var(icdf,id_track_zout,tmp,start=istart,count=icount),cvar)
 
 
  tmp = zero
  call r8get(tmp(1:mdep,1:mibs_use),inum)
 
  cvar = 'track_phiout'
  call check( nf90_put_var(icdf,id_track_phiout,tmp,start=istart,count=icount),cvar)
 
 
  tmp = zero
  call r8get(tmp(1:mdep,1:mibs_use),inum)
 
  cvar = 'track_time'
  call check( nf90_put_var(icdf,id_track_time,tmp,start=istart,count=icount),cvar)
 
 
  tmp = zero
  call r8get(tmp(1:mdep,1:mibs_use),inum)
 
  cvar = 'track_einj'
  call check( nf90_put_var(icdf,id_track_einj,tmp,start=istart,count=icount),cvar)
 
 
  tmp = zero
  call r8get(tmp(1:mdep,1:mibs_use),inum)
 
  cvar = 'track_sinj'
  call check( nf90_put_var(icdf,id_track_sinj,tmp,start=istart,count=icount),cvar)
 
 
 
  if(allocated(tmp)) deallocate(tmp)
  allocate(tmp(mtrk_0,1))
  tmp = zero
  
  call r8get(tmp(1:mtrk_0,1),inum)
 
  cvar = 'track_xl'
  ip = 1
  ic = 0
  do isb=1,mibs_use
   ic = ic + mtrk_n(isb)
   call check( nf90_put_var(icdf,id_track_xl,tmp(ip:ic,1),start=(/iadr_empty(isb)/),count=(/mtrk_n(isb)/)),cvar)
   ip = ic + 1
  enddo
 
 
  tmp = zero
  call r8get(tmp(1:mtrk_0,1),inum)
 
  cvar = 'track_pdep'
  ip = 1
  ic = 0
  do isb=1,mibs_use
   ic = ic + mtrk_n(isb)
   call check( nf90_put_var(icdf,id_track_pdep,tmp(ip:ic,1),start=(/iadr_empty(isb)/),count=(/mtrk_n(isb)/)),cvar)
   ip = ic + 1
  enddo
 
 
  tmp = zero
  call r8get(tmp(1:mtrk_0,1),inum)
 
  cvar = 'track_dr_flr'
  ip = 1
  ic = 0
  do isb=1,mibs_use
   ic = ic + mtrk_n(isb)
   call check( nf90_put_var(icdf,id_track_dr_flr,tmp(ip:ic,1),start=(/iadr_empty(isb)/),count=(/mtrk_n(isb)/)),cvar)
   ip = ic + 1
  enddo
 
 
  tmp = zero
  call r8get(tmp(1:mtrk_0,1),inum)
 
  cvar = 'track_dz_flr'
  ip = 1
  ic = 0
  do isb=1,mibs_use
   ic = ic + mtrk_n(isb)
   call check( nf90_put_var(icdf,id_track_dz_flr,tmp(ip:ic,1),start=(/iadr_empty(isb)/),count=(/mtrk_n(isb)/)),cvar)
   ip = ic + 1
  enddo
 
 
  tmp = zero
  call r8get(tmp(1:mtrk_0,1),inum)
 
  cvar = 'track_de_flr'
  ip = 1
  ic = 0
  do isb=1,mibs_use
   ic = ic + mtrk_n(isb)
   call check( nf90_put_var(icdf,id_track_de_flr,tmp(ip:ic,1),start=(/iadr_empty(isb)/),count=(/mtrk_n(isb)/)),cvar)
   ip = ic + 1
  enddo
 
 
  tmp = zero
  call r8get(tmp(1:mtrk_0,1),inum)
 
  cvar = 'track_vpv_dep'
  ip = 1
  ic = 0
  do isb=1,mibs_use
   ic = ic + mtrk_n(isb)
   call check( nf90_put_var(icdf,id_track_vpv_dep,tmp(ip:ic,1),start=(/iadr_empty(isb)/),count=(/mtrk_n(isb)/)),cvar)
   ip = ic + 1
  enddo
 
 
  tmp = zero
  call r8get(tmp(1:mtrk_0,1),inum)
 
  cvar = 'track_dvpv_flr'
  ip = 1
  ic = 0
  do isb=1,mibs_use
   ic = ic + mtrk_n(isb)
   call check( nf90_put_var(icdf,id_track_dvpv_flr,tmp(ip:ic,1),start=(/iadr_empty(isb)/),count=(/mtrk_n(isb)/)),cvar)
   ip = ic + 1
  enddo
 
 
  tmp = zero
  call r8get(tmp(1:mtrk_0,1),inum)
 
  cvar = 'track_xjadep'
  ip = 1
  ic = 0
  do isb=1,mibs_use
   ic = ic + mtrk_n(isb)
   call check( nf90_put_var(icdf,id_track_xjadep,tmp(ip:ic,1),start=(/iadr_empty(isb)/),count=(/mtrk_n(isb)/)),cvar)
   ip = ic + 1
  enddo
 
  do isb=1,mibs_use
   iadr_empty(isb)=iadr_empty(isb)+mtrk_n(isb)
  enddo 
 enddo
 if(allocated(mtrk_n)) deallocate(mtrk_n)
 if(allocated(iadr_empty)) deallocate(iadr_empty)
 ierr = nf90_close( icdf)
 if(ierr.ne.0) then
   write(nonlin,*) ' ?nbi_pget_dpt: NETCDF close failure: ',trim(fname)
   return
 endif
 
contains 
  subroutine check(status,varnam)
    integer, intent ( in) :: status 
    character*(*),intent(in) :: varnam ! dimension name input 
 
    if(status /= nf90_noerr) then 
       write(nonlin,*) ' ?nbi_pget_dpt error:'& 
      &// trim(nf90_strerror(status))//' for var.= '//trim(varnam) 
       call exit(status) 
    end if 
  end subroutine check 
 
end subroutine nbi_pget_dpt
 
subroutine nbi_zcheck_lst
  use nbi_com
  use nbi_pllbuf
  implicit NONE
 
  integer ir,ib,inum
 
  inum = 0
  nbuf_data = 0
  nbuf_lst = 0
 
  call r8nz(gtime_lost(1:mlost_data),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in gtime_lost(1:mlost_data) at lsbeam=",lsbeam
  endif
 
  call r8nz(ynbsce_lost(1:mlost_data),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in ynbsce_lost(1:mlost_data) at lsbeam=",lsbeam
  endif
 
  call r8nz(ynbien_lost(1:mlost_data),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in ynbien_lost(1:mlost_data) at lsbeam=",lsbeam
  endif
 
  call r8nz(wght_lost(1:mlost_data),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in wght_lost(1:mlost_data) at lsbeam=",lsbeam
  endif
 
  call r8nz(rmjion_lost(1:mlost_data),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in rmjion_lost(1:mlost_data) at lsbeam=",lsbeam
  endif
 
  call r8nz(yyion_lost(1:mlost_data),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in yyion_lost(1:mlost_data) at lsbeam=",lsbeam
  endif
 
  call r8nz(yze_lost(1:mlost_data),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in yze_lost(1:mlost_data) at lsbeam=",lsbeam
  endif
 
  call r8nz(xksid_lost(1:mlost_data),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in xksid_lost(1:mlost_data) at lsbeam=",lsbeam
  endif
 
  call r8nz(goose_lost(1:mlost_data),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in goose_lost(1:mlost_data) at lsbeam=",lsbeam
  endif
 
  call r8nz(species_lost(1:mlost_data),inum)
  if (inum.ne.0) then
     write(nonlin,*) "non-zero value in species_lost(1:mlost_data) at lsbeam=",lsbeam
  endif
 
  nbuf_lst = nbuf_data
end subroutine nbi_zcheck_lst
 
subroutine nbi_zzero_lst
  use nbi_com
  use nbi_pllbuf
  implicit NONE
 
  integer ir,ib,inum
 
  inum = 0
 
  call r8zero(gtime_lost(1:mlost_data),inum)
 
  call r8zero(ynbsce_lost(1:mlost_data),inum)
 
  call r8zero(ynbien_lost(1:mlost_data),inum)
 
  call r8zero(wght_lost(1:mlost_data),inum)
 
  call r8zero(rmjion_lost(1:mlost_data),inum)
 
  call r8zero(yyion_lost(1:mlost_data),inum)
 
  call r8zero(yze_lost(1:mlost_data),inum)
 
  call r8zero(xksid_lost(1:mlost_data),inum)
 
  call r8zero(goose_lost(1:mlost_data),inum)
 
  call r8zero(species_lost(1:mlost_data),inum)
 
end subroutine nbi_zzero_lst
 
subroutine nbi_pput_lst
  use nbi_com
  use nbi_pllbuf
  implicit NONE
 
  integer ir,ib,inum
 
  inum = 0
  nbuf_data =  nbuf_lst
 
  call r8put(gtime_lost(1:mlost_data),inum)
 
  call r8put(ynbsce_lost(1:mlost_data),inum)
 
  call r8put(ynbien_lost(1:mlost_data),inum)
 
  call r8put(wght_lost(1:mlost_data),inum)
 
  call r8put(rmjion_lost(1:mlost_data),inum)
 
  call r8put(yyion_lost(1:mlost_data),inum)
 
  call r8put(yze_lost(1:mlost_data),inum)
 
  call r8put(xksid_lost(1:mlost_data),inum)
 
  call r8put(goose_lost(1:mlost_data),inum)
 
  call r8put(species_lost(1:mlost_data),inum)
 
end subroutine nbi_pput_lst
 
subroutine nbi_pget_lst
  use nbi_com
  use nbi_pllbuf
  use nbi_mpi_com
  use nbi_lost_ptcl, only: mlost_all
  implicit NONE
 
  integer ir,inum, mlst0, mlst
  real(fp), dimension(:),allocatable :: tmp !local
 
 mlost_data = sum(mlost_all)
 if(mlost_data.eq.0) return
 call nbi_alloc_lost  ! allocate lost arrays only on CPU0
 
 inum = 0
 mlst0 = 1
 do ir = 1, numprocd
  mlst = mlost_all(ir)
  if(mlst.eq.0) cycle
 
  if(allocated(tmp)) deallocate(tmp)
  allocate(tmp(mlst))
  
  call r8get(tmp(1:mlst),inum)
  gtime_lost(mlst0:mlst0+mlst-1) = tmp(1:mlst)
  tmp = zero
 
 
  call r8get(tmp(1:mlst),inum)
  ynbsce_lost(mlst0:mlst0+mlst-1) = tmp(1:mlst)
  tmp = zero
 
 
  call r8get(tmp(1:mlst),inum)
  ynbien_lost(mlst0:mlst0+mlst-1) = tmp(1:mlst)
  tmp = zero
 
 
  call r8get(tmp(1:mlst),inum)
  wght_lost(mlst0:mlst0+mlst-1) = tmp(1:mlst)
  tmp = zero
 
 
  call r8get(tmp(1:mlst),inum)
  rmjion_lost(mlst0:mlst0+mlst-1) = tmp(1:mlst)
  tmp = zero
 
 
  call r8get(tmp(1:mlst),inum)
  yyion_lost(mlst0:mlst0+mlst-1) = tmp(1:mlst)
  tmp = zero
 
 
  call r8get(tmp(1:mlst),inum)
  yze_lost(mlst0:mlst0+mlst-1) = tmp(1:mlst)
  tmp = zero
 
 
  call r8get(tmp(1:mlst),inum)
  xksid_lost(mlst0:mlst0+mlst-1) = tmp(1:mlst)
  tmp = zero
 
 
  call r8get(tmp(1:mlst),inum)
  goose_lost(mlst0:mlst0+mlst-1) = tmp(1:mlst)
  tmp = zero
 
 
  call r8get(tmp(1:mlst),inum)
  species_lost(mlst0:mlst0+mlst-1) = tmp(1:mlst)
  tmp = zero
 
  mlst0 = mlst0+mlst
 enddo
 
end subroutine nbi_pget_lst
 
