Parse a single name[:attr]... token into a diag_spec_t.
Fails loud on an unrecognised attribute.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | tok | |||
| type(diag_spec_t), | intent(out) | :: | s |
| 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 |
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