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