parse_one_spec_token Subroutine

private subroutine parse_one_spec_token(tok, s)

Parse a single name[:attr]... token into a diag_spec_t. Fails loud on an unrecognised attribute.

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: tok
type(diag_spec_t), intent(out) :: s

Calls

proc~~parse_one_spec_token~~CallsGraph proc~parse_one_spec_token parse_one_spec_token error error proc~parse_one_spec_token->error proc~lower_ascii lower_ascii proc~parse_one_spec_token->proc~lower_ascii proc~parse_cadence_attr parse_cadence_attr proc~parse_one_spec_token->proc~parse_cadence_attr

Called by

proc~~parse_one_spec_token~~CalledByGraph proc~parse_one_spec_token parse_one_spec_token proc~parse_diag_spec parse_diag_spec proc~parse_diag_spec->proc~parse_one_spec_token proc~apply_diag_selection apply_diag_selection proc~apply_diag_selection->proc~parse_diag_spec proc~engine_configure_diag engine_configure_diag proc~engine_configure_diag->proc~apply_diag_selection proc~engine_setup engine_setup proc~engine_setup->proc~engine_configure_diag proc~complete_ocean_create complete_ocean_create proc~complete_ocean_create->proc~engine_setup proc~driver_run_ocean driver_run_ocean proc~driver_run_ocean->proc~engine_setup proc~driver_validate driver_validate proc~driver_validate->proc~engine_setup

Variables

Type Visibility Attributes Name Initial
character(len=:), private, allocatable :: attr
integer, private :: m
logical, private :: ok
integer, private :: p
integer, private :: q
real(kind=wp), private :: secs

Source Code

   subroutine parse_one_spec_token(tok, s)
      !! Parse a single `name[:attr]...` token into a `diag_spec_t`.
      !! Fails loud on an unrecognised attribute.
      character(len=*), intent(in) :: tok
      type(diag_spec_t), intent(out) :: s
      integer :: p, q, m
      real(wp) :: secs
      logical :: ok
      character(len=:), allocatable :: attr

      m = len_trim(tok)
      ! First colon field is the name.
      p = index(tok(1:m), ":")
      if (p == 0) then
         s%name = tok(1:m)
         return
      end if
      s%name = tok(1:p - 1)

      ! Remaining colon-separated fields are attributes.
      p = p + 1
      do while (p <= m)
         q = index(tok(p:m), ":")
         if (q == 0) then
            attr = lower_ascii(tok(p:m))
            p = m + 1
         else
            attr = lower_ascii(tok(p:p + q - 2))
            p = p + q
         end if
         if (len_trim(attr) == 0) cycle

         select case (attr)
         case ("off")
            s%off = .true.
         case ("instant")
            s%time_op = DIAG_OP_INSTANT
         case ("mean")
            s%time_op = DIAG_OP_MEAN
         case ("max")
            s%time_op = DIAG_OP_MAX
         case ("min")
            s%time_op = DIAG_OP_MIN
         case ("integral")
            s%time_op = DIAG_OP_INTEGRAL
         case ("layer")
            s%coord = DIAG_VGRID_LAYER
         case ("z")
            s%coord = DIAG_VGRID_Z_FIXED
         case ("zstar", "z*")
            s%coord = DIAG_VGRID_ZSTAR
         case ("sigma")
            s%coord = DIAG_VGRID_SIGMA
         case ("density", "rho")
            s%coord = DIAG_VGRID_DENSITY
         case default
            call parse_cadence_attr(attr, secs, ok)
            if (ok) then
               s%dt_out = secs
            else
               call logger%error("unknown diag attribute '"//attr// &
                                 "' in spec token '"//trim(tok)// &
                                 "'; valid: off | instant|mean|max|min|integral | "// &
                                 "layer|z|zstar|sigma|density | <int>s/m/h/d")
               error stop "parse_diag_spec: unknown attribute"
            end if
         end select
      end do
   end subroutine parse_one_spec_token