[1263] | 1 | ! $Id$ |
---|
| 2 | module nf95_get_att_m |
---|
| 3 | |
---|
| 4 | implicit none |
---|
| 5 | |
---|
| 6 | interface nf95_get_att |
---|
| 7 | module procedure nf95_get_att_text |
---|
| 8 | end interface |
---|
| 9 | |
---|
| 10 | private |
---|
| 11 | public nf95_get_att |
---|
| 12 | |
---|
| 13 | contains |
---|
| 14 | |
---|
| 15 | subroutine nf95_get_att_text(ncid, varid, name, values, ncerr) |
---|
| 16 | |
---|
| 17 | use netcdf, only: nf90_get_att, nf90_inquire_attribute, nf90_noerr |
---|
| 18 | use handle_err_m, only: handle_err |
---|
| 19 | |
---|
| 20 | integer, intent( in) :: ncid, varid |
---|
| 21 | character(len = *), intent( in) :: name |
---|
| 22 | character(len = *), intent(out) :: values |
---|
| 23 | integer, intent(out), optional:: ncerr |
---|
| 24 | |
---|
| 25 | ! Variable local to the procedure: |
---|
| 26 | integer ncerr_not_opt |
---|
| 27 | integer att_len |
---|
| 28 | |
---|
| 29 | !------------------- |
---|
| 30 | |
---|
| 31 | ! Check that the length of "values" is large enough: |
---|
| 32 | ncerr_not_opt = nf90_inquire_attribute(ncid, varid, name, len=att_len) |
---|
| 33 | call handle_err("nf95_get_att_text nf90_inquire_attribute " & |
---|
| 34 | // trim(name), ncerr_not_opt, ncid, varid) |
---|
| 35 | if (len(values) < att_len) then |
---|
| 36 | print *, "nf95_get_att_text" |
---|
| 37 | print *, "varid = ", varid |
---|
| 38 | print *, "attribute name: ", name |
---|
| 39 | print *, 'length of "values" is not large enough' |
---|
| 40 | print *, "len(values) = ", len(values) |
---|
| 41 | print *, "number of characters in attribute: ", att_len |
---|
| 42 | stop 1 |
---|
| 43 | end if |
---|
| 44 | |
---|
| 45 | values = "" ! useless in NetCDF version 3.6.2 or better |
---|
| 46 | ncerr_not_opt = nf90_get_att(ncid, varid, name, values) |
---|
| 47 | if (present(ncerr)) then |
---|
| 48 | ncerr = ncerr_not_opt |
---|
| 49 | else |
---|
| 50 | call handle_err("nf95_get_att_text", ncerr_not_opt, ncid, varid) |
---|
| 51 | end if |
---|
| 52 | |
---|
| 53 | if (att_len >= 1 .and. ncerr_not_opt == nf90_noerr) then |
---|
| 54 | ! Remove null terminator, if any: |
---|
| 55 | if (iachar(values(att_len:att_len)) == 0) values(att_len:att_len) = " " |
---|
| 56 | end if |
---|
| 57 | |
---|
| 58 | end subroutine nf95_get_att_text |
---|
| 59 | |
---|
| 60 | end module nf95_get_att_m |
---|