source: LMDZ6/trunk/tools/netcdf95/Variables/nf95_inquire_variable.f90 @ 5227

Last change on this file since 5227 was 5084, checked in by Laurent Fairhead, 4 months ago

Reverting to r4065. Updating fortran standard broke too much stuff. Will do it by smaller chunks
AB, LF

File size: 1.8 KB
Line 
1module nf95_inquire_variable_m
2
3  implicit none
4
5contains
6
7  subroutine nf95_inquire_variable(ncid, varid, name, xtype, ndims, dimids, &
8       nAtts, ncerr)
9
10    ! In "nf90_inquire_variable", "dimids" is an assumed-size array.
11    ! This is not optimal.
12    ! We are in the classical case of an array the size of which is
13    ! unknown in the calling procedure, before the call.
14    ! Here we use a better solution: an allocatable argument array.
15    ! This procedure allocates and defines "dimids" if it is present.
16
17    use nf95_abort_m, only: nf95_abort
18    use netcdf, only: nf90_inquire_variable, nf90_max_var_dims
19    use nf95_constants, only: nf95_noerr
20
21    integer, intent(in):: ncid, varid
22    character(len = *), optional, intent(out):: name
23    integer, optional, intent(out) :: xtype, ndims
24    integer, optional, allocatable, intent(out) :: dimids(:)
25    integer, optional, intent(out) :: nAtts
26    integer, intent(out), optional :: ncerr
27
28    ! Variable local to the procedure:
29    integer ncerr_not_opt
30    integer dimids_local(nf90_max_var_dims)
31    integer ndims_not_opt
32
33    !-------------------
34
35    if (present(dimids)) then
36       ncerr_not_opt = nf90_inquire_variable(ncid, varid, name, xtype, &
37            ndims_not_opt, dimids_local, nAtts)
38       dimids = dimids_local(:ndims_not_opt) ! also works if ndims_not_opt == 0
39       if (present(ndims)) ndims = ndims_not_opt
40    else
41       ncerr_not_opt = nf90_inquire_variable(ncid, varid, name, xtype, ndims, &
42            nAtts=nAtts)
43    end if
44
45    if (present(ncerr)) then
46       ncerr = ncerr_not_opt
47    else
48       if (ncerr_not_opt /= nf95_noerr) call &
49            nf95_abort("nf95_inquire_variable", ncerr_not_opt, ncid, varid)
50    end if
51
52  end subroutine nf95_inquire_variable
53
54end module nf95_inquire_variable_m
Note: See TracBrowser for help on using the repository browser.