schema_render_json Subroutine

private subroutine schema_render_json(this, path)

Emit the schema as JSON: one object per group, nesting one object per key. This is the ONLY thing tools/gen_python_config.py reads – it parses no Fortran source, mirroring the precedent schema_render_markdown already set for docs/generated_nml_knobs.md. &ocean_bc_nml is NOT here – it is registered via add_external_group (see rdb_config.F90), so it carries no keys on this schema; python/rdb/_config_bc.py is a hand-written stub with its own drift test (see docs D5.7).

Type Bound

nml_schema_t

Arguments

Type IntentOptional Attributes Name
class(nml_schema_t), intent(in) :: this
character(len=*), intent(in) :: path

Calls

proc~~schema_render_json~~CallsGraph proc~schema_render_json nml_schema_t%schema_render_json proc~json_escape json_escape proc~schema_render_json->proc~json_escape proc~write_key_json write_key_json proc~schema_render_json->proc~write_key_json proc~write_key_json->proc~json_escape proc~fmt_int fmt_int proc~write_key_json->proc~fmt_int proc~fmt_json_bool fmt_json_bool proc~write_key_json->proc~fmt_json_bool proc~json_fmt_real json_fmt_real proc~write_key_json->proc~json_fmt_real proc~json_real_array json_real_array proc~write_key_json->proc~json_real_array proc~json_string_array json_string_array proc~write_key_json->proc~json_string_array proc~json_real_array->proc~json_fmt_real proc~json_string_array->proc~json_escape

Variables

Type Visibility Attributes Name Initial
integer, private :: ig
integer, private :: ik
integer, private :: nk
integer, private :: u

Source Code

   subroutine schema_render_json(this, path)
      !! Emit the schema as JSON: one object per group, nesting one object
      !! per key.  This is the ONLY thing `tools/gen_python_config.py`
      !! reads -- it parses no Fortran source, mirroring the precedent
      !! `schema_render_markdown` already set for `docs/generated_nml_knobs.md`.
      !! `&ocean_bc_nml` is NOT here -- it is registered via
      !! `add_external_group` (see `rdb_config.F90`), so it carries no keys
      !! on this schema; python/rdb/_config_bc.py is a hand-written
      !! stub with its own drift test (see docs D5.7).
      class(nml_schema_t), intent(in) :: this
      character(len=*), intent(in) :: path
      integer :: u, ig, ik, nk

      open (newunit=u, file=path, status="replace", action="write")
      write (u, "(A)") "{"
      write (u, "(A)") '  "groups": ['
      do ig = 1, size(this%groups)
         write (u, "(A)") "    {"
         write (u, "(A)") '      "name": "'//json_escape(this%groups(ig)%name)//'",'
         write (u, "(A)") '      "doc": "'//json_escape(trim(this%groups(ig)%doc))//'",'
         write (u, "(A)") '      "keys": ['
         nk = 0
         if (allocated(this%groups(ig)%keys)) nk = size(this%groups(ig)%keys)
         do ik = 1, nk
            call write_key_json(u, this%groups(ig)%keys(ik), ik == nk)
         end do
         write (u, "(A)") "      ]"
         if (ig < size(this%groups)) then
            write (u, "(A)") "    },"
         else
            write (u, "(A)") "    }"
         end if
      end do
      write (u, "(A)") "  ]"
      write (u, "(A)") "}"
      close (u)
   end subroutine schema_render_json