CFIO_GetRealAtt
– Read a user-defined real attribute
This routine allows the user to read a real attribute from an open CFIO file.
Type | Intent | Optional | 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) |
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