Add an option (with scalar value).
If the option already exists, its value is updated.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(section), | intent(inout) | :: | self | Section data. |
||
character, | intent(in) | :: | option_name | Option name. |
||
class(*), | intent(in) | :: | val | Option value. |
||
integer(kind=I4P), | intent(out), | optional | :: | error | Error code. |
pure subroutine add_option(self, option_name, val, error)
!< Add an option (with scalar value).
!<
!< If the option already exists, its value is updated.
class(section), intent(inout) :: self !< Section data.
character(*), intent(in) :: option_name !< Option name.
class(*), intent(in) :: val !< Option value.
integer(I4P), intent(out), optional :: error !< Error code.
type(option), allocatable :: options(:) !< Temporary options array.
integer(I4P) :: errd !< Error code.
errd = ERR_SECTION_OPTIONS
if (allocated(self%options)) then
call self%set(error=errd, option_name=option_name, val=val)
if (errd /= 0) then ! the option does not exist
allocate(options(1:size(self%options, dim=1)+1))
options(1:size(self%options, dim=1) ) = self%options
options( size(self%options, dim=1)+1) = option(option_name=option_name)
call move_alloc(options, self%options)
call self%set(error=errd, option_name=option_name, val=val)
endif
else
allocate(self%options(1:1))
self%options(1) = option(option_name=option_name)
call self%set(error=errd, option_name=option_name, val=val)
endif
if (present(error)) error = errd
endsubroutine add_option