post_parse_validate Subroutine

private subroutine post_parse_validate(this, label, err_buf, n_err, status, errors)

Required-key + cross-check pass shared by the file and buffer parsers, then the error-return / error-stop finalization.

Arguments

Type IntentOptional Attributes Name
type(nml_schema_t), intent(inout) :: this
character(len=*), intent(in) :: label
character(len=:), intent(inout), allocatable :: err_buf(:)
integer, intent(inout) :: n_err
integer, intent(out), optional :: status
character(len=:), intent(out), optional, allocatable :: errors(:)

Calls

proc~~post_parse_validate~~CallsGraph proc~post_parse_validate post_parse_validate error error proc~post_parse_validate->error proc~add_err add_err proc~post_parse_validate->proc~add_err proc~error_ring_push error_ring_push proc~post_parse_validate->proc~error_ring_push

Called by

proc~~post_parse_validate~~CalledByGraph proc~post_parse_validate post_parse_validate proc~schema_parse nml_schema_t%schema_parse proc~schema_parse->proc~post_parse_validate proc~schema_parse_lines nml_schema_t%schema_parse_lines proc~schema_parse_lines->proc~post_parse_validate proc~read_config_from_string_impl read_config_from_string_impl proc~read_config_from_string_impl->proc~schema_parse_lines proc~read_config_impl read_config_impl proc~read_config_impl->proc~schema_parse proc~read_config read_config proc~read_config->proc~read_config_impl proc~read_config_from_string read_config_from_string proc~read_config_from_string->proc~read_config_from_string_impl proc~build_pending_handle build_pending_handle proc~build_pending_handle->proc~read_config_from_string proc~rdb_ocean_create_from_string rdb_ocean_create_from_string proc~rdb_ocean_create_from_string->proc~build_pending_handle proc~rdb_ocean_create_pending rdb_ocean_create_pending proc~rdb_ocean_create_pending->proc~build_pending_handle

Variables

Type Visibility Attributes Name Initial
integer, private :: i
integer, private :: ig
logical, private :: testable

Source Code

   subroutine post_parse_validate(this, label, err_buf, n_err, status, errors)
      !! Required-key + cross-check pass shared by the file and buffer
      !! parsers, then the error-return / error-stop finalization.
      type(nml_schema_t), intent(inout) :: this
      character(len=*), intent(in) :: label
      character(len=:), allocatable, intent(inout) :: err_buf(:)
      integer, intent(inout) :: n_err
      integer, intent(out), optional :: status
      character(len=:), allocatable, intent(out), optional :: errors(:)

      integer :: i, ig
      logical :: testable

      testable = present(status) .and. present(errors)

      ! Required-key check (only for groups present in the source).
      do ig = 1, size(this%groups)
         if (.not. this%groups(ig)%found) cycle
         if (.not. allocated(this%groups(ig)%keys)) cycle
         do i = 1, size(this%groups(ig)%keys)
            associate (k => this%groups(ig)%keys(i)%key)
               if (k%required .and. .not. k%found) then
                  call add_err(err_buf, n_err, label//": required key '"//k%name// &
                               "' missing in group '"//this%groups(ig)%name//"'")
               end if
            end associate
         end do
      end do

      ! Cross-checks: run for every registered group regardless of presence.
      do ig = 1, size(this%groups)
         if (associated(this%groups(ig)%cross_check)) then
            block
               character(len=:), allocatable :: cmsg
               cmsg = this%groups(ig)%cross_check()
               if (len_trim(cmsg) > 0) then
                  call add_err(err_buf, n_err, label//": group '"// &
                               this%groups(ig)%name//"': "//trim(cmsg))
               end if
            end block
         end if
      end do

      if (testable) then
         status = n_err
         if (n_err > 0) then
            allocate (character(len=len(err_buf)) :: errors(n_err))
            do i = 1, n_err
               errors(i) = err_buf(i)
            end do
         end if
         return
      end if

      if (n_err > 0) then
         do i = 1, n_err
            call error_ring_push(trim(err_buf(i)))
            call global_logger%error(trim(err_buf(i)))
         end do
         error stop "rdb_nml_schema: namelist validation failed"
      end if
   end subroutine post_parse_validate