subroutine rfxqlo_rfgrid_dflts(zgrid)
  !  get default settings for instance of rfxqlo_rfgrid compound data type
  use rfxqlo_types
  implicit NONE
  type (rfxqlo_rfgrid), intent(out) :: zgrid

  zgrid%npsi_in = 0
  zgrid%nchi_in = 0
  zgrid%nmod = 15

  zgrid%ncpu = 1
  zgrid%ncptype = 1

  zgrid%id_xqlo = 0
  zgrid%xnam_xqlo = " "
  zgrid%id_xpsi = 0
  zgrid%xnam_xpsi = " "

  zgrid%nxmulti = 1  ! subgrid expansion, radial (x~r/a, 1d space) direction
  zgrid%nvmulti = 1  ! subgrid expansion, velocity space (2d); 1= no expansion
  zgrid%symflag = .FALSE.

end subroutine rfxqlo_rfgrid_dflts

subroutine rfxqlo_rfgrid_set(zgrid,ierr)
  !  define rfgrid settings for rfxqlo module
  use rfxqlo_private
  implicit NONE
  type (rfxqlo_rfgrid), intent(in) :: zgrid
  integer, intent(out) :: ierr     ! 0: OK; 1: error

  if(ready) then
     ierr=1
     write(lunmsg,*) &
          ' ?rfxqlo_rfgrid_set: grid has already been set and allocated.'
  else
     ierr=0
     have_rfgrid = .TRUE.
     rfx_grid = zgrid
  endif

end subroutine rfxqlo_rfgrid_set

subroutine rfxqlo_rfgrid_get(zgrid,ierr)
  !  fetch rfgrid settings from rfxqlo module
  use rfxqlo_private
  implicit NONE
  type (rfxqlo_rfgrid), intent(out) :: zgrid
  integer, intent(out) :: ierr     ! 0: OK; 1: error

  ierr=0
  if(.not.have_rfgrid) then
     ierr=1
     write(lunmsg,*) &
          ' ?rfxqlo_rfgrid: rfgrid settings have not been provided', &
          ' to rfxqlo module.'
  else
     zgrid = rfx_grid
  endif

end subroutine rfxqlo_rfgrid_get
