[4918] | 1 | module nf95_inq_file_ncid_m |
---|
| 2 | |
---|
| 3 | implicit none |
---|
| 4 | |
---|
| 5 | contains |
---|
| 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 | |
---|
[5088] | 13 | use netcdf, only: nf90_strerror |
---|
[4918] | 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 |
---|
[5086] | 33 | END DO |
---|
[4918] | 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 | |
---|
| 50 | end module nf95_inq_file_ncid_m |
---|