get_attribute_from_group Subroutine

public subroutine get_attribute_from_group(filename, group_name, var_name, attr_name, attr, rc)

Uses

  • proc~~get_attribute_from_group~~UsesGraph proc~get_attribute_from_group get_attribute_from_group module~pfio_netcdf_supplement pfio_NetCDF_Supplement proc~get_attribute_from_group->module~pfio_netcdf_supplement netcdf netcdf proc~get_attribute_from_group->netcdf iso_c_binding iso_c_binding module~pfio_netcdf_supplement->iso_c_binding

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: filename
character(len=*), intent(in) :: group_name
character(len=*), intent(in) :: var_name
character(len=*), intent(in) :: attr_name
character(len=*), intent(inout) :: attr
integer, intent(out), optional :: rc

Calls

proc~~get_attribute_from_group~~CallsGraph proc~get_attribute_from_group get_attribute_from_group interface~mapl_assert MAPL_Assert proc~get_attribute_from_group->interface~mapl_assert nf90_close nf90_close proc~get_attribute_from_group->nf90_close nf90_get_att nf90_get_att proc~get_attribute_from_group->nf90_get_att nf90_inq_ncid nf90_inq_ncid proc~get_attribute_from_group->nf90_inq_ncid nf90_inq_varid nf90_inq_varid proc~get_attribute_from_group->nf90_inq_varid nf90_inquire_attribute nf90_inquire_attribute proc~get_attribute_from_group->nf90_inquire_attribute nf90_open nf90_open proc~get_attribute_from_group->nf90_open proc~check_nc_status check_nc_status proc~get_attribute_from_group->proc~check_nc_status proc~is_success is_success proc~get_attribute_from_group->proc~is_success proc~mapl_return MAPL_Return proc~get_attribute_from_group->proc~mapl_return proc~mapl_verify MAPL_Verify proc~get_attribute_from_group->proc~mapl_verify proc~pfio_get_att_string pfio_get_att_string proc~get_attribute_from_group->proc~pfio_get_att_string proc~check_nc_status->interface~mapl_assert proc~check_nc_status->proc~mapl_return nf90_strerror nf90_strerror proc~check_nc_status->nf90_strerror at at proc~mapl_return->at insert insert proc~mapl_return->insert proc~mapl_throw_exception MAPL_throw_exception proc~mapl_return->proc~mapl_throw_exception proc~mapl_verify->proc~mapl_throw_exception

Source Code

  subroutine get_attribute_from_group(filename, group_name, var_name, attr_name, attr, rc)
    use netcdf
    use pfio_NetCDF_Supplement
    implicit none
    character(len=*), intent(in) :: filename, group_name, var_name, attr_name
    character(len=*), intent(INOUT) :: attr
    integer, optional, intent(out) :: rc
    integer :: ncid, varid, ncid2
    integer :: status
    integer :: len, i, j, k
    integer :: xtype
    character(len=:), allocatable :: str
    integer(kind=C_INT) :: c_ncid, c_varid
    character(len=100) :: str2

    call check_nc_status(nf90_open(fileName, NF90_NOWRITE, ncid2), _RC)
    if (group_name/='') then
       call check_nc_status(nf90_inq_ncid(ncid2, group_name, ncid), _RC)
    else
       ncid = ncid2
    end if
    call check_nc_status(nf90_inq_varid(ncid, var_name, varid), _RC)
    call check_nc_status(nf90_inquire_attribute(ncid, varid, attr_name, xtype, len=len), _RC)
    c_ncid= ncid
    c_varid= varid
    select case (xtype)
    case(NF90_STRING)
       _ASSERT(is_success(pfio_get_att_string(c_ncid, c_varid, attr_name, str)), 'Error return from pfio_get_att_string')
    case(NF90_CHAR)
       allocate(character(len=len) :: str)
       call check_nc_status(nf90_get_att(ncid, varid, trim(attr_name), str), _RC)
    case default
       _FAIL('code works only with string attribute')
    end select
    i=index(str, 'since')
    ! get rid of T in 1970-01-01T00:00:0
    str2=str(i+6:i+24)
    j=index(str2, 'T')
    if(j>1) then
       k=len_trim(str2)
       str2=str2(1:j-1)//' '//str2(j+1:k)
    endif
    attr = str(1:i+5)//trim(str2)
    deallocate(str)
    call check_nc_status(nf90_close(ncid2), _RC)

    _RETURN(_SUCCESS)

  end subroutine get_attribute_from_group