CFIO_GetRealAtt Subroutine

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

CFIO_GetRealAtt – Read a user-defined real attribute

This routine allows the user to read a real 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.
  • 1999.08.23 Lucchesi Changed .OR. to .AND.

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 number of attributes

real :: buf(count)

Buffer with real 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_getrealatt~~CallsGraph proc~cfio_getrealatt CFIO_GetRealAtt nf90_get_att nf90_get_att proc~cfio_getrealatt->nf90_get_att nf90_inquire_attribute nf90_inquire_attribute proc~cfio_getrealatt->nf90_inquire_attribute proc~err err proc~cfio_getrealatt->proc~err

Called by

proc~~cfio_getrealatt~~CalledByGraph proc~cfio_getrealatt CFIO_GetRealAtt proc~esmf_cfiosdffileopen ESMF_CFIOSdfFileOpen proc~esmf_cfiosdffileopen->proc~cfio_getrealatt proc~esmf_cfiofileopen ESMF_CFIOFileOpen proc~esmf_cfiofileopen->proc~esmf_cfiosdffileopen none~find~33 CFIOCollection%find none~find~33->proc~esmf_cfiofileopen proc~mapl_cfioopenwrite MAPL_CFIOOpenWrite proc~mapl_cfioopenwrite->proc~esmf_cfiofileopen program~test test program~test->proc~esmf_cfiofileopen program~test~10 test program~test~10->proc~esmf_cfiofileopen program~test~2 test program~test~2->proc~esmf_cfiofileopen program~test~4 test program~test~4->proc~esmf_cfiofileopen proc~mapl_cfiocreatefromfile MAPL_CFIOCreateFromFile proc~mapl_cfiocreatefromfile->none~find~33 proc~mapl_cfioreadbundleread MAPL_CFIOReadBundleRead proc~mapl_cfioreadbundleread->none~find~33

Source Code

      subroutine CFIO_GetRealAtt ( 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 number of attributes
!
! !OUTPUT PARAMETERS:
!
      real     buf(count)  !! Buffer with real 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
      real r
      integer i
      real(kind=REAL32) dummy32
      real(kind=REAL64) dummy64
      real(kind=REAL32), allocatable :: buf32(:)
      real(kind=REAL64), allocatable :: buf64(:)


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

      if ( count .NE. length ) then
        rc = -1
        count = length
        return
      endif
      if ( type .NE. NF90_FLOAT .AND. type .NE. NF90_DOUBLE) then
        rc = -2
        return
      endif

      if ( HUGE(dummy32) .EQ. HUGE(r)) then
        if ( type .EQ. NF90_FLOAT ) then         ! -r4 32bit
          rc  = NF90_GET_ATT(fid,NF90_GLOBAL,name,buf)
        else            ! type .EQ. NF90_DOUBLE
          allocate (buf64(count))             ! -r4 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(r)) then
        if ( type .EQ. NF90_FLOAT ) then
          allocate (buf32(count))             ! -r8 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("GetRealAtt: error reading attribute value",rc,-51) &
           .NE. 0) return

      rc = 0
      return
      end subroutine CFIO_GetRealAtt