source: LMDZ6/trunk/tools/netcdf95/Groups/nf95_inq_file_ncid.f90 @ 5411

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

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

File size: 1.3 KB
Line 
1module nf95_inq_file_ncid_m
2
3  implicit none
4
5contains
6
7  subroutine nf95_inq_file_ncid(ncid_file, grpid, ncerr)
8
9    ! Find the ncid of the file (that is, the root group), knowing the
10    ! ncid of a group in the file. Note that this procedure is called
11    ! by nf95_abort, so it cannot call it.
12
13    use netcdf, only: nf90_strerror
14
15    use nf95_constants, only: Nf95_ENOGRP, nf95_noerr
16    use nf95_inq_grp_parent_m, only: nf95_inq_grp_parent
17
18    integer, intent(out):: ncid_file
19    integer, intent(in):: grpid
20    integer, intent(out), optional:: ncerr
21
22    ! Local:
23    integer parent_ncid, ncerr_local
24
25    !--------------------------------------------------------------------
26
27    ncid_file = grpid
28
29    do
30       call nf95_inq_grp_parent(ncid_file, parent_ncid, ncerr_local)
31       if (ncerr_local /= nf95_noerr) exit
32       ncid_file = parent_ncid
33    end do
34
35    if (ncerr_local == NF95_ENOGRP) then
36       ! ncid_file is the root group
37       if (present(ncerr)) ncerr = nf95_noerr
38    else
39       if (present(ncerr)) then
40          ncerr = ncerr_local
41       else
42          print *, "nf95_inq_file_ncid: nf95_inq_grp_parent failed"
43          print *, trim(nf90_strerror(ncerr_local))
44          stop 1
45       end if
46    end if
47
48  end subroutine nf95_inq_file_ncid
49
50end module nf95_inq_file_ncid_m
Note: See TracBrowser for help on using the repository browser.