subroutine nbi_fld_state_update(filenamefld)
! will update n_outtim, nbs_step for standalone nubeam in transp
  use nbi_com,only : n_outtim,nbs_step,nonlin
  use nbi_mpi_com
  use ezcdf

  implicit none

  character*(*), intent(in) :: filenamefld ! state filenames
  integer :: icdf                     ! netcdf channel id
  integer :: iwarn
  character*4 zvartype
  integer :: idm(3)

  call nbi_mpi_com_init       ! set myidd=0 numprocd=1 for serial run
  
  if(myidd.gt.0) return
  call ezcdf_open(icdf,trim(filenamefld),'m',iwarn)
  if(iwarn.ne.0) then
     write(nonlin,*) ' ?nbi_fld_state_update: unable to open file'//trim(filenamefld)
     return
  else
     idm = (/ -1, -1, -1 /)
     call cdfinqvar(icdf,'n_outtim', idm , zvartype)
     if(idm(1).ne.-1) then
        call cdfputvar(icdf, 'n_outtim', n_outtim)
     else
        write(nonlin,*) ' %variable not in state file, cannot update n_outtim '
     endif

     idm = (/ -1, -1, -1 /)
     call cdfinqvar(icdf,'nbs_step', idm , zvartype)
     if(idm(1).ne.-1) then
        call cdfputvar(icdf, 'nbs_step', nbs_step)
     else
        write(nonlin,*) ' %variable not in state file, cannot update nbs_step '
     endif

     call ezcdf_close(icdf)
  endif

  return
end subroutine nbi_fld_state_update
