! written by nbigen.py
! *** do not edit *** (use nbigen.py instead)
 
subroutine nbi_spltexpnd(ierror)
 
  use nbi_com
  implicit NONE
  integer :: ierror
  integer :: minbs_save
  integer,save :: i_spltexpnd = 2
  integer,allocatable :: itmp(:)
  real(fp),allocatable :: tmp(:)
 
  ierror = 0
  minbs_save = minbs_expnd   ! old value
  minbs_expnd = minbs * i_spltexpnd
  minbs_expnd = min(minbs_expnd, ntotptp(lsbeam)-nuse(lsbeam))
  if(minbs_expnd.le.0) then 
     ierror = 1
     return
  endif
  if(allocated(tmp)) deallocate(tmp)
  allocate(tmp(1:minbs_save)); tmp = zero
  if(allocated(itmp)) deallocate(itmp)
  allocate(itmp(1:minbs_save)); itmp = zero
 
  !==============================================
  ! expand arrays
 
  itmp(1:minbs_save) = nbsbsa(1:minbs_save)
  if(allocated(nbsbsa)) deallocate(nbsbsa)
  allocate(nbsbsa(1:minbs_expnd))
  nbsbsa = 0
  nbsbsa(1:minbs_save) = itmp(1:minbs_save) 
  itmp(1:minbs_save) = nbebsa(1:minbs_save)
  if(allocated(nbebsa)) deallocate(nbebsa)
  allocate(nbebsa(1:minbs_expnd))
  nbebsa = 0
  nbebsa(1:minbs_save) = itmp(1:minbs_save) 
  tmp(1:minbs_save) = einjbsa(1:minbs_save)
  if(allocated(einjbsa)) deallocate(einjbsa)
  allocate(einjbsa(1:minbs_expnd))
  einjbsa = zero
  einjbsa(1:minbs_save) = tmp(1:minbs_save) 
  tmp(1:minbs_save) = pinjbsa(1:minbs_save)
  if(allocated(pinjbsa)) deallocate(pinjbsa)
  allocate(pinjbsa(1:minbs_expnd))
  pinjbsa = zero
  pinjbsa(1:minbs_save) = tmp(1:minbs_save) 
  tmp(1:minbs_save) = rbsa(1:minbs_save)
  if(allocated(rbsa)) deallocate(rbsa)
  allocate(rbsa(1:minbs_expnd))
  rbsa = zero
  rbsa(1:minbs_save) = tmp(1:minbs_save) 
  tmp(1:minbs_save) = tbsa(1:minbs_save)
  if(allocated(tbsa)) deallocate(tbsa)
  allocate(tbsa(1:minbs_expnd))
  tbsa = zero
  tbsa(1:minbs_save) = tmp(1:minbs_save) 
  tmp(1:minbs_save) = thbsa(1:minbs_save)
  if(allocated(thbsa)) deallocate(thbsa)
  allocate(thbsa(1:minbs_expnd))
  thbsa = zero
  thbsa(1:minbs_save) = tmp(1:minbs_save) 
  tmp(1:minbs_save) = vbsa(1:minbs_save)
  if(allocated(vbsa)) deallocate(vbsa)
  allocate(vbsa(1:minbs_expnd))
  vbsa = zero
  vbsa(1:minbs_save) = tmp(1:minbs_save) 
  tmp(1:minbs_save) = wtbsa(1:minbs_save)
  if(allocated(wtbsa)) deallocate(wtbsa)
  allocate(wtbsa(1:minbs_expnd))
  wtbsa = zero
  wtbsa(1:minbs_save) = tmp(1:minbs_save) 
  tmp(1:minbs_save) = xisbsa(1:minbs_save)
  if(allocated(xisbsa)) deallocate(xisbsa)
  allocate(xisbsa(1:minbs_expnd))
  xisbsa = zero
  xisbsa(1:minbs_save) = tmp(1:minbs_save) 
  tmp(1:minbs_save) = xksbsa(1:minbs_save)
  if(allocated(xksbsa)) deallocate(xksbsa)
  allocate(xksbsa(1:minbs_expnd))
  xksbsa = zero
  xksbsa(1:minbs_save) = tmp(1:minbs_save) 
  i_spltexpnd = i_spltexpnd + 1
  if(allocated(tmp)) deallocate(tmp)
  if(allocated(itmp)) deallocate(itmp)
 
end subroutine nbi_spltexpnd
