subroutine nbi_fld_state(filenamefld,action,ierr)
  use nbi_com
  use nbi_mpi_com
  use ezcdf
 
  !-----------------------------

  implicit none

  character*(*), intent(in) :: filenamefld ! state filenames
  character*1, intent(in) :: action   ! "s" or "s": save, "r" or "r": restore
  ! "d" or "d" to delete state files
  ! "b" or "b" to backup state files: <file> -> <file>_save
  ! "c" or "c" to retrieve prior backup files: <file>_save -> <file>

  integer, intent(out) :: ierr        ! completion code: 0 = ok
  integer :: icdf                     ! netcdf channel id
  integer :: iwarn
  character*1 actup
 
  !-----------------------------
  actup = action
  call uupper(actup)

  if(actup.eq.'R') then
     ! restore state: issue warning & skip if state already exists
     
     call nbi_states(filenamefld,' ',action,-1,ierr)
     need_read_ptcl=.true.  ! not read yet

  else
     call errmsg_exit('nbi_fld_state: only "R" action supported here.')
  endif

  return
end subroutine nbi_fld_state
