read_stir_config Subroutine

private subroutine read_stir_config(self)

Uses

Reads in the stir namelist and populates the member variables

Type Bound

stir_config_type

Arguments

Type IntentOptional Attributes Name
class(stir_config_type), intent(inout) :: self

Contents

Source Code


Source Code

  subroutine read_stir_config(self)
    use file_utils, only: input_unit_exist, get_indexed_namelist_unit
    use mp, only: proc0
    implicit none
    class(stir_config_type), intent(in out) :: self
    logical :: exist
    integer :: in_file

    ! Note: When this routine is in the module where these variables live
    ! we shadow the module level variables here. This is intentional to provide
    ! isolation and ensure we can move this routine to another module easily.
    integer :: kx, ky, kz
    logical :: travel
    real :: a, b

    namelist /stir/ a, b, kx, ky, kz, travel

    ! Only proc0 reads from file
    if (.not. proc0) return

    ! First set local variables from current values
    a = self%a
    b = self%b
    kx = self%kx
    ky = self%ky
    kz = self%kz
    travel = self%travel

    ! Now read in the main namelist
    call get_indexed_namelist_unit(in_file, trim(self%get_name()), self%index, exist)
    if (exist) read(in_file, nml = stir)
    close(unit = in_file)

    ! Now copy from local variables into type members
    self%a = a
    self%b = b
    self%kx = kx
    self%ky = ky
    self%kz = kz
    self%travel = travel

    self%exist = exist
  end subroutine read_stir_config