read_parameters Subroutine

private subroutine read_parameters(driver_config_in, stir_config_in)

FIXME : Add documentation

Arguments

Type IntentOptional Attributes Name
type(driver_config_type), intent(in), optional :: driver_config_in
type(stir_config_type), intent(in), optional, dimension(:), allocatable :: stir_config_in

Contents

Source Code


Source Code

  subroutine read_parameters(driver_config_in, stir_config_in)
    use file_utils, only: input_unit_exist, get_indexed_namelist_unit
    use file_utils, only: open_output_file, input_unit
    use mp, only: proc0
    use antenna_data, only: init_antenna_data
    use gs2_save, only: init_ant_amp
    implicit none
    type(driver_config_type), intent(in), optional :: driver_config_in
    type(stir_config_type), intent(in), dimension(:), allocatable, optional :: stir_config_in
    complex :: a, b
    integer :: kx, ky, kz, i, ierr
    logical :: exist, travel, ant_off

    if (present(driver_config_in)) driver_config = driver_config_in

    call driver_config%init(name = 'driver', requires_index = .false.)

    ! Copy out internal values into module level parameters
    amplitude = driver_config%amplitude
    ant_off = driver_config%ant_off
    nk_stir = driver_config%nk_stir
    restarting = driver_config%restarting
    t0 = driver_config%t0
    w_antenna = driver_config%w_antenna
    w_dot = driver_config%w_dot
    write_antenna = driver_config%write_antenna

    exist = driver_config%exist

    ! If the namelist wasn't present, or if [[driver_config:ant_off]]
    ! was explicitly set to true, then we won't be using the antenna,
    ! so for consistency, we turn it off in this case
    no_driver = driver_config%ant_off .or. .not. driver_config%exist
    driver_config%ant_off = no_driver

    if (no_driver) return

    call init_antenna_data (nk_stir)
    allocate (kx_stir(nk_stir))
    allocate (ky_stir(nk_stir))
    allocate (kz_stir(nk_stir))
    allocate (trav(nk_stir))

    ! BD
    ! get initial antenna amplitudes from restart file
    ! if none are found, a_ant = b_ant = 0 will be returned
    ! and ierr will be non-zero.
    !
    ! TO DO: need to know if there IS a restart file to check...
    !

    ierr = 1
    if (restarting) call init_ant_amp (a_ant, b_ant, nk_stir, ierr)

    if (present(stir_config_in)) stir_config = stir_config_in

    if (.not.allocated(stir_config)) allocate(stir_config(nk_stir))
    if (size(stir_config) .ne. nk_stir) then
      if (proc0) print*,"Warning: inconsistent config size in antenna"
    endif

    do i=1,nk_stir
      call stir_config(i)%init(name = 'stir', requires_index = .true., index = i)

      ! Copy out internal values into module level parameters
      a = stir_config(i)%a
      b = stir_config(i)%b
      kx = stir_config(i)%kx
      ky = stir_config(i)%ky
      kz = stir_config(i)%kz
      travel = stir_config(i)%travel

      kx_stir(i) = kx
      ky_stir(i) = ky
      kz_stir(i) = kz
      trav(i) = travel
      ! If a, b are not specified in the input file:
      if (a == -1.0 .and. b == -1.0) then
        ! And if a, b are not specified in the restart file
        ! (else use values from restart file by default)
        if (ierr /= 0) then
          a_ant(i) = amplitude*cmplx(1.,1.)/2.
          b_ant(i) = amplitude*cmplx(1.,1.)/2.
        end if
        ! Else if a, b ARE specified in the input file (ignore restart file):
      else
        a_ant(i) = a
        b_ant(i) = b
      end if
    end do

    if (proc0) then
       call open_output_file (out_unit, ".antenna")
    end if
  end subroutine read_parameters