1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995 integer, intent(in) :: ng, model, varid
1996
1997 integer, intent(in), optional :: ncid
1998
1999 character (len=*), intent(in) :: ncname
2000 character (len=*), intent(in) :: AttName(:)
2001
2002 logical, intent(out) :: foundit(:)
2003
2004 real(dp), intent(out) :: AttValue(:)
2005
2006
2007
2008 integer :: i, j, my_natts, my_ncid, natts, status
2009
2010# if !defined PARALLEL_IO && defined DISTRIBUTE
2011
2012 real(dp), allocatable :: rbuffer(:)
2013# endif
2014
2015 character (len=40) :: my_Aname
2016 character (len=40) :: my_Vname
2017
2018 character (len=*), parameter :: MyFile = &
2019 & __FILE__//", netcdf_get_fatt"
2020
2021
2022
2023
2024
2025
2026
2027 natts=ubound(attname, dim=1)
2028 DO i=1,natts
2029 foundit(i)=.false.
2030 attvalue(i)=0.0_dp
2031 END DO
2032# if !defined PARALLEL_IO && defined DISTRIBUTE
2033 IF (.not.allocated(rbuffer)) THEN
2034 allocate ( rbuffer(2*natts+1) )
2035 END IF
2036# endif
2037
2038
2039
2040 IF (.not.PRESENT(ncid)) THEN
2041 CALL netcdf_open (ng, model, trim(ncname), 0, my_ncid)
2042 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
2043 ELSE
2044 my_ncid=ncid
2045 END IF
2046
2047
2048
2049 IF (inpthread) THEN
2050 IF (varid.eq.nf90_global) THEN
2051 status=nf90_inquire(my_ncid, &
2052 & nattributes = my_natts)
2053 ELSE
2054 status=nf90_inquire_variable(my_ncid, varid, &
2055 & name = my_vname, &
2056 & natts = my_natts)
2057 END IF
2058 IF (status.eq.nf90_noerr) THEN
2059 DO j=1,my_natts
2060 status=nf90_inq_attname(my_ncid, varid, j, my_aname)
2061 IF (status.eq.nf90_noerr) THEN
2062 DO i=1,natts
2063 IF (trim(my_aname).eq.trim(attname(i))) THEN
2064 status=nf90_get_att(my_ncid, varid, trim(attname(i)), &
2065 & attvalue(i))
2066 IF (founderror(status, nf90_noerr, &
2067 & __line__, myfile)) THEN
2068 IF (master) WRITE (stdout,10) trim(attname(i)), &
2069 & trim(my_vname), &
2070 & trim(ncname), &
2071 & trim(sourcefile), &
2072 & nf90_strerror(status)
2073 exit_flag=2
2074 ioerror=status
2075 END IF
2076 foundit(i)=.true.
2077 EXIT
2078 END IF
2079 END DO
2080 ELSE
2081 IF (master) WRITE (stdout,20) j, &
2082 & trim(my_vname), &
2083 & trim(ncname), &
2084 & trim(sourcefile), &
2085 & nf90_strerror(status)
2086 exit_flag=2
2087 ioerror=status
2088 EXIT
2089 END IF
2090 END DO
2091# if !defined PARALLEL_IO && defined DISTRIBUTE
2092
2093 rbuffer=0.0_dp
2094 DO i=1,natts
2095 rbuffer(i)=attvalue(i)
2096 IF (foundit(i)) THEN
2097 rbuffer(i+natts)=1.0_dp
2098 END IF
2099 END DO
2100 rbuffer(2*natts+1)=real(ioerror, dp)
2101# endif
2102 ELSE
2103 IF (master) WRITE (stdout,30) trim(my_vname), &
2104 & trim(ncname), &
2105 & trim(sourcefile), &
2106 & nf90_strerror(status)
2107 exit_flag=2
2108 ioerror=status
2109 END IF
2110 END IF
2111
2112# if !defined PARALLEL_IO && defined DISTRIBUTE
2113
2114
2115
2116
2117 CALL mp_bcasti (ng, model, exit_flag)
2118 IF (exit_flag.eq.noerror) THEN
2119 CALL mp_bcastf (ng, model, rbuffer)
2120 DO i=1,natts
2121 attvalue(i)=rbuffer(i)
2122 IF (rbuffer(i+natts).gt.0.0_dp) THEN
2123 foundit(i)=.true.
2124 END IF
2125 END DO
2126 ioerror=int(rbuffer(2*natts+1))
2127 IF (allocated(rbuffer)) THEN
2128 deallocate (rbuffer)
2129 END IF
2130 END IF
2131# endif
2132
2133
2134
2135 IF (.not.PRESENT(ncid)) THEN
2136 CALL netcdf_close (ng, model, my_ncid, ncname, .false.)
2137 END IF
2138
2139 10 FORMAT (/,' NETCDF_GET_FATT_DP - error while reading attribute:', &
2140 & 1x,a,'for variable',1x,a,/,22x,'in input file:',2x,a,/, &
2141 & 22x,'call from:',2x,a,/,22x,a)
2142 20 FORMAT (/,' NETCDF_GET_FATT_DP - error while inquiring ', &
2143 & 'attribute: ',i2.2,'for variable',1x,a,/,22x, &
2144 & 'in input file:',2x,a,/,19x,'call from:',2x,a,/,19x,a)
2145 30 FORMAT (/,' NETCDF_GET_FATT_DP - error while inquiring number of',&
2146 & ' attributes for variable:',1x,a,/,22x,'in input file:', &
2147 & 2x,a,/,22x,'call from:',2x,a,/,22x,a)
2148
2149 RETURN