Required-key + cross-check pass shared by the file and buffer parsers, then the error-return / error-stop finalization.
| Type | Intent | Optional | 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(:) |
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| integer, | private | :: | i | ||||
| integer, | private | :: | ig | ||||
| logical, | private | :: | testable |
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