2023-12-17 18:09:12 -03:00
|
|
|
!===============================================================================
|
|
|
|
!
|
|
|
|
! This file is part of the source code of AMUN, a magnetohydrodynamic
|
|
|
|
! (classical and relativistic) plasma modeling software for the study of
|
|
|
|
! astrophysical phenomena.
|
|
|
|
!
|
2024-03-07 09:34:43 -03:00
|
|
|
! Copyright (C) 2008-2024 Grzegorz Kowal <grzegorz@amuncode.org>
|
2023-12-17 18:09:12 -03:00
|
|
|
! <respective copyright line for all contributing authors>
|
|
|
|
!
|
|
|
|
! This program is free software: you can redistribute it and/or modify
|
|
|
|
! it under the terms of the GNU General Public License as published by
|
|
|
|
! the Free Software Foundation, either version 3 of the License, or
|
|
|
|
! (at your option) any later version.
|
|
|
|
!
|
|
|
|
! This program is distributed in the hope that it will be useful,
|
|
|
|
! but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
! GNU General Public License for more details.
|
|
|
|
!
|
|
|
|
! You should have received a copy of the GNU General Public License
|
|
|
|
! along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
!
|
|
|
|
!===============================================================================
|
|
|
|
!
|
|
|
|
! Name: PARAMETERS
|
|
|
|
!
|
|
|
|
! Description:
|
|
|
|
!
|
|
|
|
! This module handles runtime parameters by reading them from a parameter
|
|
|
|
! file and distributing among all processes.
|
|
|
|
!
|
|
|
|
!-------------------------------------------------------------------------------
|
2012-07-22 19:22:07 -03:00
|
|
|
!
|
|
|
|
module parameters
|
|
|
|
|
|
|
|
implicit none
|
|
|
|
|
2023-12-17 18:09:12 -03:00
|
|
|
private
|
|
|
|
|
|
|
|
! MODULE INTERFACES
|
|
|
|
! -----------------
|
2019-01-28 21:05:12 -02:00
|
|
|
!
|
|
|
|
interface get_parameter
|
|
|
|
module procedure get_parameter_integer
|
|
|
|
module procedure get_parameter_real
|
|
|
|
module procedure get_parameter_string
|
|
|
|
end interface
|
|
|
|
|
2023-12-17 18:09:12 -03:00
|
|
|
! MODULE STRUCTURES
|
|
|
|
! -----------------
|
2012-07-22 19:22:07 -03:00
|
|
|
!
|
2023-12-17 18:09:12 -03:00
|
|
|
type item
|
|
|
|
character(len=:), allocatable :: key, val
|
2012-07-22 19:22:07 -03:00
|
|
|
|
2023-12-17 18:09:12 -03:00
|
|
|
type(item), pointer :: next
|
|
|
|
end type
|
2018-08-27 18:56:58 -03:00
|
|
|
|
2023-12-17 18:09:12 -03:00
|
|
|
! MODULE VARIABLES
|
|
|
|
! ----------------
|
2018-08-27 18:56:58 -03:00
|
|
|
!
|
2023-12-17 18:09:12 -03:00
|
|
|
character(len=:), allocatable :: parameter_file
|
|
|
|
type(item) , pointer :: parameter_list => null()
|
2012-07-22 19:22:07 -03:00
|
|
|
|
|
|
|
|
2023-12-17 18:09:12 -03:00
|
|
|
! PUBLIC MEMBERS
|
|
|
|
! --------------
|
2012-07-22 19:22:07 -03:00
|
|
|
!
|
|
|
|
public :: read_parameters, finalize_parameters
|
2023-12-18 09:30:07 -03:00
|
|
|
public :: parameter_file, update_parameter, get_parameter
|
|
|
|
#ifdef MPI
|
|
|
|
public :: distribute_parameters
|
|
|
|
#endif /* MPI */
|
2012-07-22 19:22:07 -03:00
|
|
|
|
|
|
|
contains
|
2023-12-17 18:09:12 -03:00
|
|
|
|
2012-07-22 19:22:07 -03:00
|
|
|
!===============================================================================
|
|
|
|
!
|
|
|
|
! subroutine READ_PARAMETERS:
|
|
|
|
! --------------------------
|
|
|
|
!
|
2023-12-17 18:09:12 -03:00
|
|
|
! Description:
|
|
|
|
!
|
2012-07-22 19:22:07 -03:00
|
|
|
! Subroutine checks if the parameter file exists, checks its length,
|
|
|
|
! allocates structures to store all parameters provided in the parameters
|
|
|
|
! file and read parameters into these structures.
|
|
|
|
!
|
2023-12-17 18:09:12 -03:00
|
|
|
! There is a possibility to specify customized input file by adding a
|
|
|
|
! command line option -i or --input followed by the name of the input file.
|
2012-07-22 19:22:07 -03:00
|
|
|
!
|
2023-12-17 18:09:12 -03:00
|
|
|
! Arguments:
|
2012-07-22 19:22:07 -03:00
|
|
|
!
|
2023-12-17 18:09:12 -03:00
|
|
|
! verbose - the flag determining if the subroutine should be verbose;
|
|
|
|
! status - the return flag of the procedure execution status;
|
2012-07-22 19:22:07 -03:00
|
|
|
!
|
|
|
|
!===============================================================================
|
|
|
|
!
|
2020-07-30 10:13:48 -03:00
|
|
|
subroutine read_parameters(verbose, status)
|
2012-07-22 19:22:07 -03:00
|
|
|
|
2019-01-28 15:45:35 -02:00
|
|
|
use iso_fortran_env, only : error_unit
|
|
|
|
|
2012-07-22 19:22:07 -03:00
|
|
|
implicit none
|
|
|
|
|
2020-07-30 10:13:48 -03:00
|
|
|
logical, intent(in) :: verbose
|
|
|
|
integer, intent(out) :: status
|
2012-07-22 19:22:07 -03:00
|
|
|
|
2023-12-17 18:09:12 -03:00
|
|
|
character(len=4096) :: arg
|
2020-07-30 10:13:48 -03:00
|
|
|
integer :: l
|
|
|
|
logical :: info
|
2021-11-16 11:36:26 -03:00
|
|
|
|
2012-07-22 19:22:07 -03:00
|
|
|
!-------------------------------------------------------------------------------
|
|
|
|
!
|
2021-02-25 20:05:27 -03:00
|
|
|
status = 0
|
|
|
|
|
2023-12-17 18:09:12 -03:00
|
|
|
parameter_file = 'params.in'
|
|
|
|
|
|
|
|
! parse the command line to check for the parameter file
|
2012-07-22 19:22:07 -03:00
|
|
|
!
|
2020-07-30 10:23:31 -03:00
|
|
|
do l = 1, command_argument_count()
|
|
|
|
call get_command_argument(l, arg)
|
|
|
|
if (trim(arg) == '-i' .or. trim(arg) == '--input') then
|
2023-12-17 18:09:12 -03:00
|
|
|
call get_command_argument(l+1, arg)
|
2020-07-30 10:23:31 -03:00
|
|
|
if (trim(arg) /= '') then
|
2023-12-17 18:09:12 -03:00
|
|
|
parameter_file = trim(arg)
|
2020-07-30 10:23:31 -03:00
|
|
|
else
|
2023-12-17 18:09:12 -03:00
|
|
|
if (verbose) &
|
2023-12-19 15:33:29 -03:00
|
|
|
write (error_unit,*) &
|
2023-12-17 18:09:12 -03:00
|
|
|
"The option '--input' or '-i' requires an argument. Exiting..."
|
2020-07-30 10:23:31 -03:00
|
|
|
status = 112
|
|
|
|
return
|
2012-07-22 19:22:07 -03:00
|
|
|
end if
|
2023-12-17 18:09:12 -03:00
|
|
|
exit
|
2012-07-22 19:22:07 -03:00
|
|
|
end if
|
|
|
|
end do
|
|
|
|
|
2023-12-19 15:33:29 -03:00
|
|
|
inquire (file=parameter_file, exist=info)
|
2012-07-22 19:22:07 -03:00
|
|
|
|
|
|
|
if (info) then
|
2023-12-17 18:09:12 -03:00
|
|
|
call parse_parameters(status)
|
2012-07-22 19:22:07 -03:00
|
|
|
else
|
2023-12-19 15:33:29 -03:00
|
|
|
write (error_unit,*) "The parameter file '" // parameter_file // &
|
2023-12-17 18:09:12 -03:00
|
|
|
"' does not exist. Exiting..."
|
2020-07-30 10:13:48 -03:00
|
|
|
status = 111
|
2012-07-22 19:22:07 -03:00
|
|
|
end if
|
|
|
|
|
2023-12-17 21:47:38 -03:00
|
|
|
#ifdef MPI
|
|
|
|
call distribute_parameters()
|
|
|
|
#endif /* MPI */
|
|
|
|
|
2012-07-22 19:22:07 -03:00
|
|
|
!-------------------------------------------------------------------------------
|
|
|
|
!
|
|
|
|
end subroutine read_parameters
|
2023-12-17 18:09:12 -03:00
|
|
|
|
2012-07-22 19:22:07 -03:00
|
|
|
!===============================================================================
|
|
|
|
!
|
|
|
|
! subroutine FINALIZE_PARAMETERS:
|
|
|
|
! ------------------------------
|
|
|
|
!
|
2023-12-17 18:09:12 -03:00
|
|
|
! Description:
|
|
|
|
!
|
2012-07-22 19:22:07 -03:00
|
|
|
! Subroutine releases memory used by arrays in this module.
|
|
|
|
!
|
|
|
|
!===============================================================================
|
|
|
|
!
|
|
|
|
subroutine finalize_parameters()
|
|
|
|
|
|
|
|
implicit none
|
2021-11-16 11:36:26 -03:00
|
|
|
|
2023-12-17 18:09:12 -03:00
|
|
|
type(item), pointer :: item_ptr
|
2012-07-22 19:22:07 -03:00
|
|
|
|
|
|
|
!-------------------------------------------------------------------------------
|
|
|
|
!
|
2023-12-17 18:09:12 -03:00
|
|
|
item_ptr => parameter_list
|
|
|
|
do while(associated(item_ptr))
|
|
|
|
parameter_list => parameter_list%next
|
2020-04-29 17:36:54 -03:00
|
|
|
|
2023-12-17 18:09:12 -03:00
|
|
|
nullify(item_ptr%next)
|
|
|
|
deallocate(item_ptr%key, item_ptr%val)
|
|
|
|
deallocate(item_ptr)
|
2020-04-29 17:36:54 -03:00
|
|
|
|
2023-12-17 18:09:12 -03:00
|
|
|
item_ptr => parameter_list
|
|
|
|
end do
|
2021-11-16 11:36:26 -03:00
|
|
|
|
2020-04-29 17:36:54 -03:00
|
|
|
!-------------------------------------------------------------------------------
|
|
|
|
!
|
2023-12-17 18:09:12 -03:00
|
|
|
end subroutine finalize_parameters
|
2020-04-29 17:36:54 -03:00
|
|
|
|
|
|
|
!===============================================================================
|
|
|
|
!
|
2023-12-17 18:09:12 -03:00
|
|
|
! subroutine PARSE_PARAMETERS:
|
|
|
|
! ---------------------------
|
2012-07-22 19:22:07 -03:00
|
|
|
!
|
2023-12-17 18:09:12 -03:00
|
|
|
! Description:
|
2012-07-22 19:22:07 -03:00
|
|
|
!
|
2023-12-17 18:09:12 -03:00
|
|
|
! Subroutine scans the input file, reads parameter names and values, and
|
|
|
|
! stores them in module arrays.
|
|
|
|
!
|
|
|
|
! Arguments:
|
2012-07-22 19:22:07 -03:00
|
|
|
!
|
2023-12-17 18:09:12 -03:00
|
|
|
! status - the status value, 0 for success;
|
2012-07-22 19:22:07 -03:00
|
|
|
!
|
|
|
|
!===============================================================================
|
|
|
|
!
|
2023-12-17 18:09:12 -03:00
|
|
|
subroutine parse_parameters(status)
|
2012-07-22 19:22:07 -03:00
|
|
|
|
2018-08-27 18:56:58 -03:00
|
|
|
use iso_fortran_env, only : error_unit
|
2023-12-17 21:47:38 -03:00
|
|
|
use mpitools , only : master
|
2018-08-27 18:56:58 -03:00
|
|
|
|
2012-07-22 19:22:07 -03:00
|
|
|
implicit none
|
|
|
|
|
2020-07-30 10:13:48 -03:00
|
|
|
integer, intent(out) :: status
|
2012-07-22 19:22:07 -03:00
|
|
|
|
2023-12-17 18:09:12 -03:00
|
|
|
type(item), pointer :: item_ptr
|
2012-07-22 19:22:07 -03:00
|
|
|
|
2023-12-17 18:09:12 -03:00
|
|
|
logical :: exists
|
2012-07-22 19:22:07 -03:00
|
|
|
|
2023-12-17 18:09:12 -03:00
|
|
|
integer :: io = 10, n, i, j
|
2012-07-22 19:22:07 -03:00
|
|
|
|
2023-12-17 18:09:12 -03:00
|
|
|
character(len=:), allocatable :: line, key, val
|
2012-07-22 19:22:07 -03:00
|
|
|
|
2023-12-17 18:09:12 -03:00
|
|
|
character(len=*), parameter :: loc = 'PARAMETERS::parse_parameters()'
|
2012-07-22 19:22:07 -03:00
|
|
|
|
|
|
|
!-------------------------------------------------------------------------------
|
|
|
|
!
|
2023-12-17 18:09:12 -03:00
|
|
|
status = 0
|
2012-07-22 19:22:07 -03:00
|
|
|
|
2023-12-17 21:47:38 -03:00
|
|
|
if (.not. master) return
|
2012-07-22 19:22:07 -03:00
|
|
|
|
2023-12-17 18:09:12 -03:00
|
|
|
n = 0
|
|
|
|
j = 1024
|
2018-08-27 18:56:58 -03:00
|
|
|
|
2023-12-19 15:33:29 -03:00
|
|
|
inquire (file=parameter_file, size=j)
|
2021-11-16 11:36:26 -03:00
|
|
|
|
2023-12-17 18:09:12 -03:00
|
|
|
allocate(character(len=j) :: line)
|
2012-07-22 19:22:07 -03:00
|
|
|
|
2023-12-19 15:24:45 -03:00
|
|
|
open (newunit=io, file=parameter_file, action='read', err=30)
|
2012-07-22 19:22:07 -03:00
|
|
|
|
2023-12-19 15:33:29 -03:00
|
|
|
10 read (io, fmt="(a)", end=20) line
|
2012-07-22 19:22:07 -03:00
|
|
|
|
2023-12-17 18:09:12 -03:00
|
|
|
n = n + 1
|
2013-12-10 15:17:30 -02:00
|
|
|
|
2023-12-17 18:09:12 -03:00
|
|
|
! remove comments
|
2012-07-22 19:22:07 -03:00
|
|
|
!
|
2023-12-17 18:09:12 -03:00
|
|
|
i = index(line, '#')
|
2023-12-19 15:33:29 -03:00
|
|
|
if (i > 0) write (line,"(a)") trim(adjustl(line(:i-1)))
|
2012-07-22 19:22:07 -03:00
|
|
|
|
2023-12-17 18:09:12 -03:00
|
|
|
! skip empty lines
|
2012-07-22 19:22:07 -03:00
|
|
|
!
|
2023-12-17 18:09:12 -03:00
|
|
|
if (len_trim(line) == 0) go to 10
|
2013-12-10 15:17:30 -02:00
|
|
|
|
2023-12-17 18:09:12 -03:00
|
|
|
! process only lines containing '='
|
2013-12-10 15:17:30 -02:00
|
|
|
!
|
2023-12-17 18:09:12 -03:00
|
|
|
i = index(line, '=')
|
|
|
|
if (i > 1) then
|
|
|
|
key = trim(adjustl(line(:i-1)))
|
|
|
|
|
|
|
|
if (len_trim(key) > 0) then
|
|
|
|
val = trim(adjustl(line(i+1:)))
|
|
|
|
if (index(val, '"') > 0 .and. index(val, "'") > 0) then
|
|
|
|
status = 1
|
|
|
|
else
|
|
|
|
i = index(val, '"')
|
|
|
|
if (i > 0) then
|
|
|
|
j = index(val, '"', back=.true.)
|
|
|
|
val = val(i+1:j-1)
|
|
|
|
end if
|
|
|
|
i = index(val, "'")
|
|
|
|
if (i > 0) then
|
|
|
|
j = index(val, "'", back=.true.)
|
|
|
|
val = val(i+1:j-1)
|
|
|
|
end if
|
|
|
|
end if
|
|
|
|
if (len_trim(val) == 0) status = 1
|
|
|
|
else
|
|
|
|
status = 1
|
|
|
|
end if
|
|
|
|
else
|
|
|
|
status = 1
|
2013-12-10 15:17:30 -02:00
|
|
|
end if
|
2012-07-22 19:22:07 -03:00
|
|
|
|
2023-12-17 18:09:12 -03:00
|
|
|
if (status > 0) then
|
2023-12-19 15:33:29 -03:00
|
|
|
write (error_unit,"('[',a,']: ',a)") loc, &
|
2023-12-17 18:09:12 -03:00
|
|
|
"Wrong parameter format in '" // parameter_file // "'."
|
|
|
|
write (error_unit,"('[',a,']: ',a,i0,':')") loc, "Verify line ", n
|
|
|
|
write (error_unit,"('[',a,']: ',a)") loc, trim(adjustl(line))
|
2012-07-22 19:22:07 -03:00
|
|
|
|
2023-12-17 18:09:12 -03:00
|
|
|
go to 10
|
|
|
|
end if
|
2012-07-22 19:22:07 -03:00
|
|
|
|
2023-12-17 18:09:12 -03:00
|
|
|
! allocate a new item and add it to the parameter list
|
2012-07-22 19:22:07 -03:00
|
|
|
!
|
2023-12-17 18:09:12 -03:00
|
|
|
exists = .false.
|
|
|
|
item_ptr => parameter_list
|
|
|
|
do while(associated(item_ptr))
|
|
|
|
if (key == item_ptr%key) then
|
|
|
|
exists = .true.
|
|
|
|
exit
|
|
|
|
end if
|
|
|
|
item_ptr => item_ptr%next
|
|
|
|
end do
|
|
|
|
if (exists) then
|
2023-12-19 15:33:29 -03:00
|
|
|
write (error_unit,"('[',a,']: ',a)") loc, "Parameter '" // key // &
|
2023-12-17 18:09:12 -03:00
|
|
|
"' appears multiple times. " // &
|
|
|
|
"Only the value of the first occurrence is considered."
|
|
|
|
else
|
|
|
|
allocate(item_ptr)
|
|
|
|
item_ptr%key = key
|
|
|
|
item_ptr%val = val
|
|
|
|
item_ptr%next => parameter_list
|
|
|
|
parameter_list => item_ptr
|
|
|
|
end if
|
|
|
|
|
2012-07-22 19:22:07 -03:00
|
|
|
go to 10
|
|
|
|
|
2023-12-19 15:39:44 -03:00
|
|
|
20 close (io)
|
2023-12-17 18:09:12 -03:00
|
|
|
|
|
|
|
deallocate(line)
|
2012-07-22 19:22:07 -03:00
|
|
|
|
|
|
|
return
|
|
|
|
|
2023-12-19 15:33:29 -03:00
|
|
|
30 write (error_unit,"('[',a,']: ',a)") loc, &
|
2023-12-17 18:09:12 -03:00
|
|
|
"Unable to open the parameter file '" // &
|
|
|
|
parameter_file // "'!"
|
2012-07-22 19:22:07 -03:00
|
|
|
|
2020-07-30 10:13:48 -03:00
|
|
|
status = 140
|
2012-07-22 19:22:07 -03:00
|
|
|
|
|
|
|
!-------------------------------------------------------------------------------
|
|
|
|
!
|
2023-12-17 18:09:12 -03:00
|
|
|
end subroutine parse_parameters
|
2012-07-22 19:22:07 -03:00
|
|
|
|
2023-12-18 09:30:07 -03:00
|
|
|
!===============================================================================
|
|
|
|
!
|
|
|
|
! subroutine UPDATE_PARAMETER:
|
|
|
|
! ---------------------------
|
|
|
|
!
|
|
|
|
! Description:
|
|
|
|
!
|
|
|
|
! Subroutine updates the value of the item by the given key.
|
|
|
|
!
|
|
|
|
! Arguments:
|
|
|
|
!
|
|
|
|
! key - the parameter name;
|
|
|
|
! val - the value of parameter;
|
|
|
|
!
|
|
|
|
!===============================================================================
|
|
|
|
!
|
|
|
|
subroutine update_parameter(key, val)
|
|
|
|
|
|
|
|
use iso_fortran_env, only : error_unit
|
|
|
|
|
|
|
|
implicit none
|
|
|
|
|
|
|
|
character(len=*), intent(in) :: key, val
|
|
|
|
|
|
|
|
type(item), pointer :: item_ptr
|
|
|
|
|
|
|
|
logical :: exists
|
|
|
|
|
|
|
|
character(len=*), parameter :: loc = 'PARAMETERS::update_parameter()'
|
|
|
|
|
|
|
|
!-------------------------------------------------------------------------------
|
|
|
|
!
|
|
|
|
exists = .false.
|
|
|
|
item_ptr => parameter_list
|
|
|
|
do while(associated(item_ptr))
|
|
|
|
if (key == item_ptr%key) then
|
|
|
|
if (val /= item_ptr%val) item_ptr%val = val
|
|
|
|
exists = .true.
|
|
|
|
exit
|
|
|
|
end if
|
|
|
|
item_ptr => item_ptr%next
|
|
|
|
end do
|
|
|
|
|
|
|
|
if (.not. exists) then
|
|
|
|
allocate(item_ptr)
|
|
|
|
item_ptr%key = key
|
|
|
|
item_ptr%val = val
|
|
|
|
item_ptr%next => parameter_list
|
|
|
|
parameter_list => item_ptr
|
|
|
|
end if
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
!-------------------------------------------------------------------------------
|
|
|
|
!
|
|
|
|
end subroutine update_parameter
|
|
|
|
|
2012-07-22 19:22:07 -03:00
|
|
|
!===============================================================================
|
|
|
|
!
|
|
|
|
! subroutine GET_PARAMETER_INTEGER:
|
|
|
|
! --------------------------------
|
|
|
|
!
|
2023-12-17 18:09:12 -03:00
|
|
|
! Description:
|
|
|
|
!
|
2012-07-22 19:22:07 -03:00
|
|
|
! Subroutine reads a given parameter name and returns its integer value.
|
|
|
|
!
|
2023-12-17 18:09:12 -03:00
|
|
|
! Arguments:
|
2012-07-22 19:22:07 -03:00
|
|
|
!
|
2023-12-17 18:09:12 -03:00
|
|
|
! key - the input parameter name;
|
|
|
|
! val - the output integer value of parameter;
|
2012-07-22 19:22:07 -03:00
|
|
|
!
|
|
|
|
!===============================================================================
|
|
|
|
!
|
2023-12-17 18:09:12 -03:00
|
|
|
subroutine get_parameter_integer(key, val)
|
2012-07-22 19:22:07 -03:00
|
|
|
|
2018-08-27 18:56:58 -03:00
|
|
|
use iso_fortran_env, only : error_unit
|
|
|
|
|
2012-07-22 19:22:07 -03:00
|
|
|
implicit none
|
|
|
|
|
2023-12-17 18:09:12 -03:00
|
|
|
character(len=*), intent(in) :: key
|
|
|
|
integer , intent(inout) :: val
|
2012-07-22 19:22:07 -03:00
|
|
|
|
2023-12-17 18:09:12 -03:00
|
|
|
type(item), pointer :: item_ptr
|
2018-08-27 18:56:58 -03:00
|
|
|
|
|
|
|
character(len=*), parameter :: loc = 'PARAMETERS::get_parameter_integer()'
|
2021-11-16 11:36:26 -03:00
|
|
|
|
2012-07-22 19:22:07 -03:00
|
|
|
!-------------------------------------------------------------------------------
|
|
|
|
!
|
2023-12-17 18:09:12 -03:00
|
|
|
item_ptr => parameter_list
|
|
|
|
do while(associated(item_ptr))
|
|
|
|
if (item_ptr%key == key) then
|
2023-12-19 15:33:29 -03:00
|
|
|
read (item_ptr%val, err=10, fmt=*) val
|
2023-12-17 18:09:12 -03:00
|
|
|
exit
|
2012-07-22 19:22:07 -03:00
|
|
|
end if
|
2023-12-17 18:09:12 -03:00
|
|
|
item_ptr => item_ptr%next
|
2012-07-22 19:22:07 -03:00
|
|
|
end do
|
|
|
|
|
|
|
|
return
|
|
|
|
|
2023-12-19 15:33:29 -03:00
|
|
|
10 write (error_unit,"('[',a,']: ',a)") loc, &
|
2023-12-17 18:09:12 -03:00
|
|
|
"Incorrect format for the integer parameter '" // key // &
|
|
|
|
"', or its value is either too small or too large!"
|
2012-07-22 19:22:07 -03:00
|
|
|
|
|
|
|
!-------------------------------------------------------------------------------
|
|
|
|
!
|
|
|
|
end subroutine get_parameter_integer
|
2023-12-17 18:09:12 -03:00
|
|
|
|
2012-07-22 19:22:07 -03:00
|
|
|
!===============================================================================
|
|
|
|
!
|
|
|
|
! subroutine GET_PARAMETER_REAL:
|
|
|
|
! -----------------------------
|
|
|
|
!
|
2023-12-17 18:09:12 -03:00
|
|
|
! Description:
|
|
|
|
!
|
2012-07-22 19:22:07 -03:00
|
|
|
! Subroutine reads a given parameter name and returns its real value.
|
|
|
|
!
|
2023-12-17 18:09:12 -03:00
|
|
|
! Arguments:
|
2012-07-22 19:22:07 -03:00
|
|
|
!
|
2023-12-17 18:09:12 -03:00
|
|
|
! key - the input parameter name;
|
|
|
|
! val - the output real value of parameter;
|
2012-07-22 19:22:07 -03:00
|
|
|
!
|
|
|
|
!===============================================================================
|
|
|
|
!
|
2023-12-17 18:09:12 -03:00
|
|
|
subroutine get_parameter_real(key, val)
|
2012-07-22 19:22:07 -03:00
|
|
|
|
2018-08-27 18:56:58 -03:00
|
|
|
use iso_fortran_env, only : error_unit
|
|
|
|
|
2012-07-22 19:22:07 -03:00
|
|
|
implicit none
|
|
|
|
|
2023-12-17 18:09:12 -03:00
|
|
|
character(len=*), intent(in) :: key
|
|
|
|
real(kind=8) , intent(inout) :: val
|
2012-07-22 19:22:07 -03:00
|
|
|
|
2023-12-17 18:09:12 -03:00
|
|
|
type(item), pointer :: item_ptr
|
2018-08-27 18:56:58 -03:00
|
|
|
|
|
|
|
character(len=*), parameter :: loc = 'PARAMETERS::get_parameter_real()'
|
2021-11-16 11:36:26 -03:00
|
|
|
|
2012-07-22 19:22:07 -03:00
|
|
|
!-------------------------------------------------------------------------------
|
|
|
|
!
|
2023-12-17 18:09:12 -03:00
|
|
|
item_ptr => parameter_list
|
|
|
|
do while(associated(item_ptr))
|
|
|
|
if (item_ptr%key == key) then
|
2023-12-19 15:33:29 -03:00
|
|
|
read (item_ptr%val, err=10, fmt=*) val
|
2023-12-17 18:09:12 -03:00
|
|
|
exit
|
2012-07-22 19:22:07 -03:00
|
|
|
end if
|
2023-12-17 18:09:12 -03:00
|
|
|
item_ptr => item_ptr%next
|
2012-07-22 19:22:07 -03:00
|
|
|
end do
|
|
|
|
|
|
|
|
return
|
|
|
|
|
2023-12-19 15:33:29 -03:00
|
|
|
10 write (error_unit,"('[',a,']: ',a)") loc, &
|
2023-12-17 18:09:12 -03:00
|
|
|
"Incorrect format for the float parameter '" // key // &
|
|
|
|
"', or its value is either too small or too large!"
|
2012-07-22 19:22:07 -03:00
|
|
|
|
|
|
|
!-------------------------------------------------------------------------------
|
|
|
|
!
|
|
|
|
end subroutine get_parameter_real
|
2023-12-17 18:09:12 -03:00
|
|
|
|
2012-07-22 19:22:07 -03:00
|
|
|
!===============================================================================
|
|
|
|
!
|
|
|
|
! subroutine GET_PARAMETER_STRING:
|
|
|
|
! -------------------------------
|
|
|
|
!
|
2023-12-17 18:09:12 -03:00
|
|
|
! Description:
|
|
|
|
!
|
2012-07-22 19:22:07 -03:00
|
|
|
! Subroutine reads a given parameter name and returns its string value.
|
|
|
|
!
|
2023-12-17 18:09:12 -03:00
|
|
|
! Arguments:
|
2012-07-22 19:22:07 -03:00
|
|
|
!
|
2023-12-17 18:09:12 -03:00
|
|
|
! key - the input parameter name;
|
|
|
|
! val - the output string value of parameter;
|
2012-07-22 19:22:07 -03:00
|
|
|
!
|
|
|
|
!===============================================================================
|
|
|
|
!
|
2023-12-17 18:09:12 -03:00
|
|
|
subroutine get_parameter_string(key, val)
|
2012-07-22 19:22:07 -03:00
|
|
|
|
|
|
|
implicit none
|
|
|
|
|
2023-12-17 18:09:12 -03:00
|
|
|
character(len=*), intent(in) :: key
|
|
|
|
character(len=*), intent(inout) :: val
|
2012-07-22 19:22:07 -03:00
|
|
|
|
2023-12-17 18:09:12 -03:00
|
|
|
type(item), pointer :: item_ptr
|
2021-11-16 11:36:26 -03:00
|
|
|
|
2012-07-22 19:22:07 -03:00
|
|
|
!-------------------------------------------------------------------------------
|
|
|
|
!
|
2023-12-17 18:09:12 -03:00
|
|
|
item_ptr => parameter_list
|
|
|
|
do while(associated(item_ptr))
|
|
|
|
if (item_ptr%key == key) then
|
|
|
|
val = item_ptr%val
|
|
|
|
exit
|
2012-07-22 19:22:07 -03:00
|
|
|
end if
|
2023-12-17 18:09:12 -03:00
|
|
|
item_ptr => item_ptr%next
|
2012-07-22 19:22:07 -03:00
|
|
|
end do
|
|
|
|
|
|
|
|
!-------------------------------------------------------------------------------
|
|
|
|
!
|
|
|
|
end subroutine get_parameter_string
|
2023-12-17 21:47:38 -03:00
|
|
|
#ifdef MPI
|
|
|
|
!===============================================================================
|
|
|
|
!
|
|
|
|
! subroutine DISTRIBUTE_PARAMETERS:
|
|
|
|
! --------------------------------
|
|
|
|
!
|
|
|
|
! Description:
|
|
|
|
!
|
|
|
|
! Subroutine distributes parameters among the MPI processes.
|
|
|
|
!
|
|
|
|
!===============================================================================
|
|
|
|
!
|
|
|
|
subroutine distribute_parameters()
|
|
|
|
|
|
|
|
use mpitools, only : master, broadcast
|
|
|
|
|
|
|
|
implicit none
|
|
|
|
|
|
|
|
type(item), pointer :: item_ptr
|
|
|
|
|
|
|
|
character(len=:), allocatable :: str
|
|
|
|
|
|
|
|
integer, dimension(2) :: counters ! 1: nitems, 2: maxlen
|
|
|
|
integer :: n, i
|
|
|
|
|
|
|
|
!-------------------------------------------------------------------------------
|
|
|
|
!
|
|
|
|
counters = 0
|
|
|
|
|
|
|
|
if (master) then
|
|
|
|
item_ptr => parameter_list
|
|
|
|
do while(associated(item_ptr))
|
|
|
|
counters(1) = counters(1) + 1
|
|
|
|
counters(2) = max(counters(2), len(item_ptr%key // '|' // item_ptr%val))
|
|
|
|
item_ptr => item_ptr%next
|
|
|
|
end do
|
2023-12-18 09:30:07 -03:00
|
|
|
else
|
|
|
|
item_ptr => parameter_list
|
|
|
|
do while(associated(item_ptr))
|
|
|
|
parameter_list => parameter_list%next
|
|
|
|
|
|
|
|
nullify(item_ptr%next)
|
|
|
|
deallocate(item_ptr%key, item_ptr%val)
|
|
|
|
deallocate(item_ptr)
|
|
|
|
|
|
|
|
item_ptr => parameter_list
|
|
|
|
end do
|
2023-12-17 21:47:38 -03:00
|
|
|
end if
|
|
|
|
|
|
|
|
! broadcast the number of items and the maximum item length
|
|
|
|
!
|
|
|
|
call broadcast(counters)
|
|
|
|
|
|
|
|
! allocate string buffer
|
|
|
|
!
|
|
|
|
allocate(character(len=counters(2)) :: str)
|
|
|
|
|
|
|
|
! iterate over all items in the list and broadcast them
|
|
|
|
!
|
|
|
|
if (master) then
|
|
|
|
item_ptr => parameter_list
|
|
|
|
do while(associated(item_ptr))
|
2023-12-19 15:33:29 -03:00
|
|
|
write (str,"(a)") item_ptr%key // '|' // item_ptr%val
|
2023-12-17 21:47:38 -03:00
|
|
|
|
|
|
|
call broadcast(str)
|
|
|
|
|
|
|
|
item_ptr => item_ptr%next
|
|
|
|
end do
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
do n = 1, counters(1)
|
|
|
|
|
|
|
|
call broadcast(str)
|
|
|
|
|
|
|
|
i = index(str, '|')
|
|
|
|
|
|
|
|
allocate(item_ptr)
|
|
|
|
item_ptr%key = trim(adjustl(str(:i-1)))
|
|
|
|
item_ptr%val = trim(adjustl(str(i+1:)))
|
|
|
|
item_ptr%next => parameter_list
|
|
|
|
parameter_list => item_ptr
|
|
|
|
end do
|
|
|
|
|
|
|
|
end if
|
|
|
|
|
|
|
|
deallocate(str)
|
|
|
|
|
|
|
|
!-------------------------------------------------------------------------------
|
|
|
|
!
|
|
|
|
end subroutine distribute_parameters
|
|
|
|
#endif /* MPI */
|
2012-07-22 19:22:07 -03:00
|
|
|
|
|
|
|
!===============================================================================
|
|
|
|
!
|
|
|
|
end module parameters
|