CFIO_GetIntAtt Subroutine

public subroutine CFIO_GetIntAtt(fid, name, count, buf, rc)

CFIO_GetIntAtt – Read a user-defined integer attribute

This routine allows the user to read an integer attribute from an open CFIO file.

History

  • 1998.07.30 Lucchesi Initial interface design.
  • 1998.07.30 Lucchesi Initial coding.
  • 1998.09.29 Lucchesi Changed error handling. Added 64-bit support.

Arguments

Type IntentOptional Attributes Name
integer :: fid

File handle

character(len=*) :: name

Name of attribute

integer :: count

On input: Number of items in attribute On output: If rc = -1, count will contain the correct count of this attribute

integer :: buf(count)

Buffer with integer values

integer :: rc

Error return code: rc = 0 all is well rc = -1 invalid count rc = -2 type mismatch rc = -12 error determining default precision

NetCDF Errors


rc = -36 error from NF90_PUT_ATT (global attribute) rc = -51 error from NF90_GET_ATT (global attribute)


Calls

proc~~cfio_getintatt~~CallsGraph proc~cfio_getintatt CFIO_GetIntAtt nf90_get_att nf90_get_att proc~cfio_getintatt->nf90_get_att nf90_inquire_attribute nf90_inquire_attribute proc~cfio_getintatt->nf90_inquire_attribute proc~err err proc~cfio_getintatt->proc~err

Called by

proc~~cfio_getintatt~~CalledByGraph proc~cfio_getintatt CFIO_GetIntAtt proc~esmf_cfiosdffileopen ESMF_CFIOSdfFileOpen proc~esmf_cfiosdffileopen->proc~cfio_getintatt proc~esmf_cfiofileopen ESMF_CFIOFileOpen proc~esmf_cfiofileopen->proc~esmf_cfiosdffileopen none~find~4 CFIOCollection%find none~find~4->proc~esmf_cfiofileopen proc~mapl_cfioopenwrite MAPL_CFIOOpenWrite proc~mapl_cfioopenwrite->proc~esmf_cfiofileopen program~test~11 test program~test~11->proc~esmf_cfiofileopen program~test~2 test program~test~2->proc~esmf_cfiofileopen program~test~4 test program~test~4->proc~esmf_cfiofileopen program~test~6 test program~test~6->proc~esmf_cfiofileopen proc~mapl_cfiocreatefromfile MAPL_CFIOCreateFromFile proc~mapl_cfiocreatefromfile->none~find~4 proc~mapl_cfioreadbundleread MAPL_CFIOReadBundleRead proc~mapl_cfioreadbundleread->none~find~4

Source Code

      subroutine CFIO_GetIntAtt ( fid, name, count, buf, rc )
!
! !USES:
!
      Implicit NONE
!
! !INPUT PARAMETERS:
!
      integer        fid        !! File handle
      character(len=*)  name       !! Name of attribute
!
! !INPUT/OUTPUT PARAMETERS:
!
      integer        count      !! On input: Number of items in attribute
                                !! On output: If rc = -1, count will contain
                                !!        the correct count of this attribute
!
! !OUTPUT PARAMETERS:
!
      integer   buf(count) !! Buffer with integer values
      integer   rc         !! Error return code:
                           !!   rc = 0    all is well
                           !!   rc = -1   invalid count
                           !!   rc = -2   type mismatch
                           !!   rc = -12  error determining default precision
                           !!
                           !!  NetCDF Errors
                           !!  -------------
                           !!   rc = -36  error from NF90_PUT_ATT (global attribute)
                           !!   rc = -51  error from NF90_GET_ATT (global attribute)

!
!-------------------------------------------------------------------------

      integer length, type
      integer i
      integer(kind=INT32) dummy32
      integer(kind=INT64) dummy64
      integer(kind=INT32), allocatable :: buf32(:)
      integer(kind=INT64), allocatable :: buf64(:)


      rc = NF90_INQUIRE_ATTRIBUTE (fid, NF90_GLOBAL, name, type, length)
      if (err("GetIntAtt: error reading attribute info",rc,-58) &
           .NE. 0) return

      if ( count .NE. length ) then
        rc = -1
        count = length
        return
      endif

      if ( type .NE. NF90_INT .AND. type .NE. NF90_DOUBLE) then
        rc = -2
        return
      endif
      if ( HUGE(dummy32) .EQ. HUGE(i)) then
        if ( type .EQ. NF90_INT ) then          ! -i4 32bit
          rc  = NF90_GET_ATT(fid,NF90_GLOBAL,name,buf)
        else            ! type .EQ. NF90_DOUBLE
          allocate (buf64(count))             ! -i4 64bit
          rc  = NF90_GET_ATT(fid,NF90_GLOBAL,name,buf64)
          do i=1,count
            buf(i) = buf64(i)
          enddo
          deallocate (buf64)
        endif
      else if (HUGE(dummy64) .EQ. HUGE(i)) then
        if ( type .EQ. NF90_INT ) then
          allocate (buf32(count))             ! -i8 32bit
          rc  = NF90_GET_ATT(fid,NF90_GLOBAL,name,buf32)
          do i=1,count
            buf(i) = buf32(i)
          enddo
          deallocate (buf32)
        else            ! type .EQ. NF90_DOUBLE
          rc  = NF90_GET_ATT(fid,NF90_GLOBAL,name,buf)
        endif
      else
        rc = -12
        return
      endif
      if (err("GetIntAtt: error reading attribute value",rc,-51) &
           .NE. 0) return

      rc = 0
      return
      end subroutine CFIO_GetIntAtt