CFIO_GetIntAtt
– Read a user-defined integer attribute
This routine allows the user to read an integer 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 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) |
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