CFIO_PutRealAtt Subroutine

public subroutine CFIO_PutRealAtt(fid, name, count, buf, prec, rc)

CFIO_PutRealAtt – Write a user-defined real attribute

This routine allows the user to define a real attribute in an open CFIO file.

History

  • 1998.07.30 Lucchesi Initial interface design.
  • 1998.07.30 Lucchesi Initial coding.
  • 1998.09.24 Lucchesi Changed error handling.
  • 1998.09.28 Lucchesi Added support for multiple precisions

Arguments

Type IntentOptional Attributes Name
integer :: fid

File handle

character(len=*) :: name

Name of attribute

integer :: count

Number of integers to write

real :: buf(count)

Buffer with real values

integer :: prec

Desired precision of attribute value: 0 = 32 bit 1 = 64 bit

integer :: rc

Error return code: rc = 0 all is well rc = -12 error determining default precision

NetCDF Errors


rc = -36 error from NF90_PUT_ATT (global attribute) rc = -55 error from NF90_REDEF (enter define mode) rc = -56 error from NF90_ENDDEF (exit define mode)


Calls

proc~~cfio_putrealatt~~CallsGraph proc~cfio_putrealatt CFIO_PutRealAtt nf90_enddef nf90_enddef proc~cfio_putrealatt->nf90_enddef nf90_put_att nf90_put_att proc~cfio_putrealatt->nf90_put_att nf90_redef nf90_redef proc~cfio_putrealatt->nf90_redef proc~err err proc~cfio_putrealatt->proc~err

Called by

proc~~cfio_putrealatt~~CalledByGraph proc~cfio_putrealatt CFIO_PutRealAtt proc~esmf_cfiosdffilecreate ESMF_CFIOSdfFileCreate proc~esmf_cfiosdffilecreate->proc~cfio_putrealatt proc~esmf_cfiofilecreate ESMF_CFIOFileCreate proc~esmf_cfiofilecreate->proc~esmf_cfiosdffilecreate proc~mapl_cfiocreatewrite MAPL_CFIOCreatewrite proc~mapl_cfiocreatewrite->proc~esmf_cfiofilecreate program~test~10 test program~test~10->proc~esmf_cfiofilecreate program~test~11 test program~test~11->proc~esmf_cfiofilecreate program~test~13 test program~test~13->proc~esmf_cfiofilecreate program~test~14 test program~test~14->proc~esmf_cfiofilecreate program~test~2 test program~test~2->proc~esmf_cfiofilecreate program~test~3 test program~test~3->proc~esmf_cfiofilecreate program~test~4 test program~test~4->proc~esmf_cfiofilecreate program~test~6 test program~test~6->proc~esmf_cfiofilecreate program~test~7 test program~test~7->proc~esmf_cfiofilecreate program~test~9 test program~test~9->proc~esmf_cfiofilecreate

Source Code

      subroutine CFIO_PutRealAtt ( fid, name, count, buf, prec, rc )
!
! !USES:
!
      Implicit NONE
!
! !INPUT PARAMETERS:
!
      integer        fid        !! File handle
      character(len=*)  name       !! Name of attribute
      integer        count      !! Number of integers to write
      real           buf(count) !! Buffer with real values
      integer        prec       !! Desired precision of attribute value:
                                !!   0 = 32 bit
                                !!   1 = 64 bit
!
! !OUTPUT PARAMETERS:
!
      integer     rc     !! Error return code:
                         !!   rc = 0    all is well
                         !!   rc = -12  error determining default precision
                         !!
                         !!  NetCDF Errors
                         !!  -------------
                         !!   rc = -36  error from NF90_PUT_ATT (global attribute)
                         !!   rc = -55  error from NF90_REDEF (enter define mode)
                         !!   rc = -56  error from NF90_ENDDEF (exit define mode)

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

      real(kind=REAL32) dummy32
      real(kind=REAL64) dummy64
      real r
      integer i
      real(kind=REAL32), allocatable :: buf32(:)
      real(kind=REAL64), allocatable :: buf64(:)

      rc = NF90_REDEF ( fid )
      if (err("PutRealAtt: could not enter define mode",rc,-55) .NE. 0) &
         return

      if (HUGE(dummy32) .EQ. HUGE(r) .AND. prec .EQ. 0) then        ! -r4
        rc = NF90_PUT_ATT ( fid, NF90_GLOBAL, name, buf ) ! 32-bit out

      else if (HUGE(dummy32) .EQ. HUGE(r) .AND. prec .EQ. 1) then  ! -r4
        allocate (buf64(count))                                    ! 64-bit out
        do i=1,count
          buf64(i) = buf(i)
        enddo
        rc = NF90_PUT_ATT ( fid, NF90_GLOBAL, name, buf64 )
        deallocate (buf64)

      else if (HUGE(dummy64) .EQ. huge(r) .AND. prec .EQ. 0) then  ! -r8
        allocate (buf32(count))                                    ! 32-bit out
        do i=1,count
          buf32(i) = buf(i)
        enddo
        rc = NF90_PUT_ATT ( fid, NF90_GLOBAL, name, buf32 )
        deallocate (buf32)

      else if (HUGE(dummy64) .EQ. huge(r) .AND. prec .EQ. 1) then    ! -r8
        rc = NF90_PUT_ATT ( fid, NF90_GLOBAL, name, buf ) ! 64-bit out

      else
        rc = -12
        return
      endif
      if (err("PutRealAtt: error writing attribute",rc,-36) .NE. 0) &
         return

      rc = NF90_ENDDEF(fid)
      if (err("PutRealAtt: could not exit define mode",rc,-56) .NE. 0) &
         return

      rc = 0
      return
      end subroutine CFIO_PutRealAtt