source: LMDZ4/trunk/libf/bibio/nf95_get_att_m.F90 @ 5456

Last change on this file since 5456 was 1279, checked in by Laurent Fairhead, 15 years ago

Merged LMDZ4-dev branch changes r1241:1278 into the trunk
Running trunk and LMDZ4-dev in LMDZOR configuration on local
machine (sequential) and SX8 (4-proc) yields identical results
(restart and restartphy are identical binarily)
Log history from r1241 to r1278 is available by switching to
source:LMDZ4/branches/LMDZ4-dev-20091210

File size: 1.8 KB
RevLine 
[1263]1! $Id$
2module 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
13contains
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
60end module nf95_get_att_m
Note: See TracBrowser for help on using the repository browser.