src/gray_params.f90: handle missing mandatory parameters

This commit is contained in:
Michele Guerini Rocco 2024-02-07 23:02:32 +01:00
parent b582eb19b8
commit 6a91eaa3a8
Signed by: rnhmjoj
GPG Key ID: BFBAF4C975F76450
2 changed files with 42 additions and 3 deletions

View File

@ -203,6 +203,25 @@ module gray_params
type(misc_parameters) :: misc
end type
! List of mandatory GRAY parameters
integer, parameter :: max_name_size = 40
character(len=*), parameter :: mandatory(*) = [ &
character(len=max_name_size) :: &
"antenna.alpha", &
"antenna.beta", &
"antenna.iox", &
"antenna.ibeam", &
"antenna.filenm", &
"equilibrium.filenm", &
"profiles.irho", &
"profiles.iprof", &
"profiles.filenm", &
"raytracing.dst", &
"raytracing.nrayr", &
"raytracing.nrayth", &
"misc.rwall" &
]
! All GRAY input data
type gray_data
type(equilibrium_data) :: equilibrium
@ -355,15 +374,31 @@ contains
subroutine read_gray_config(filename, params, err)
! Reads the GRAY parameters from the gray.ini configuration file
use ini_parser, only : parse_ini, property_handler, ini_error
use ini_parser, only : parse_ini, property_handler, ini_error, ERR_SUCCESS
use logger, only : log_error
! subroutine arguments
character(len=*), intent(in) :: filename
type(gray_parameters), intent(out) :: params
integer(kind(ini_error)), intent(out) :: err
integer, parameter :: max_lines = 100
integer :: count, i
character(len=max_name_size) :: provided(max_lines), name
! parse the configuration
count = 1
call parse_ini(filename, ini_handler, err)
if (err /= ERR_SUCCESS) return
! check if all mandatory parameters were given
do i = 1, size(mandatory)
name = mandatory(i)
if (findloc(provided, trim(name), count) /= 0) cycle
call log_error('mandatory parameter `'//trim(name)//'` is missing!', &
mod='gray_params', proc='read_gray_config')
err = 1
end do
contains
@ -376,6 +411,10 @@ contains
integer(kind(ini_error)) :: err
err = update_parameter(params, section // "." // name, value)
! store the parameter name
provided(count) = section // "." // name
count = count + 1
end function ini_handler
end subroutine read_gray_config

View File

@ -137,7 +137,7 @@ contains
cycle
case (ERR_VALUE)
write (msg, '("invalid value for property ",a,": ", a)') name, value
write (msg, '("invalid value for property `",a,"`: ", a)') name, value
call log_error(msg, proc='parse_ini', mod='ini_parser')
deallocate(line)
error = ERR_VALUE