Read a character (text) attribute from a variable — used for the
CF units attribute on a time axis. Non-fail-loud: ok is
.false. (and value blank) when the attribute is absent or the
wrong type, so callers can fall back to a default rather than
aborting on a missing/optional attribute.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer, | intent(in) | :: | ncid | |||
| integer, | intent(in) | :: | varid | |||
| character(len=*), | intent(in) | :: | name | |||
| character(len=:), | intent(out), | allocatable | :: | value |
Deferred-length (not assumed-length |
|
| logical, | intent(out) | :: | ok |
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| character(len=1024), | private | :: | buf | ||||
| integer, | private | :: | status |
subroutine nc_get_att_text(ncid, varid, name, value, ok) !! Read a character (text) attribute from a variable — used for the !! CF `units` attribute on a time axis. Non-fail-loud: `ok` is !! `.false.` (and `value` blank) when the attribute is absent or the !! wrong type, so callers can fall back to a default rather than !! aborting on a missing/optional attribute. integer, intent(in) :: ncid, varid character(len=*), intent(in) :: name character(len=:), allocatable, intent(out) :: value !! Deferred-length (not assumed-length `intent(out)`, which risks !! silent truncation — fortitude C072): filled from a fixed local !! buffer sized for a CF `units` string. logical, intent(out) :: ok integer :: status character(len=1024) :: buf buf = "" status = nf90_get_att(ncid, varid, name, buf) ok = (status == nf90_noerr) if (ok) then value = trim(buf) else value = "" end if end subroutine nc_get_att_text