nc_get_att_text Subroutine

public 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.

Arguments

Type IntentOptional 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 intent(out), which risks silent truncation — fortitude C072): filled from a fixed local buffer sized for a CF units string.

logical, intent(out) :: ok

Calls

proc~~nc_get_att_text~~CallsGraph proc~nc_get_att_text nc_get_att_text nf90_get_att nf90_get_att proc~nc_get_att_text->nf90_get_att

Called by

proc~~nc_get_att_text~~CalledByGraph proc~nc_get_att_text nc_get_att_text proc~register_common register_common proc~register_common->proc~nc_get_att_text proc~ocean_data_input_register_2d ocean_data_input_register_2d proc~ocean_data_input_register_2d->proc~register_common proc~ocean_data_input_register_3d ocean_data_input_register_3d proc~ocean_data_input_register_3d->proc~register_common proc~ocean_data_input_register_segment_2d ocean_data_input_register_segment_2d proc~ocean_data_input_register_segment_2d->proc~register_common proc~ocean_data_input_register_segment_3d ocean_data_input_register_segment_3d proc~ocean_data_input_register_segment_3d->proc~register_common proc~ocean_data_input_load_static_2d ocean_data_input_load_static_2d proc~ocean_data_input_load_static_2d->proc~ocean_data_input_register_2d proc~register_tag register_tag proc~register_tag->proc~ocean_data_input_register_2d proc~ocean_data_forcing_configure ocean_data_forcing_configure proc~ocean_data_forcing_configure->proc~register_tag proc~seed_cavity_draft seed_cavity_draft proc~seed_cavity_draft->proc~ocean_data_input_load_static_2d proc~engine_setup engine_setup proc~engine_setup->proc~ocean_data_forcing_configure proc~ocean_state_seed_from_cfg ocean_state_seed_from_cfg proc~ocean_state_seed_from_cfg->proc~seed_cavity_draft

Variables

Type Visibility Attributes Name Initial
character(len=1024), private :: buf
integer, private :: status

Source Code

   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