[4918] | 1 | # Groups |
---|
| 2 | |
---|
| 3 | This page describles procedures handling NetCDF groups. |
---|
| 4 | |
---|
| 5 | See the [improvements page](improvements.md) for an |
---|
| 6 | explanation of the mnemonics \"basic change\", \"interface change\", |
---|
| 7 | \"functionality change\", \"additional procedure\". |
---|
| 8 | |
---|
| 9 | ## `nf95_inq_file_ncid` |
---|
| 10 | |
---|
| 11 | (additional procedure) |
---|
| 12 | |
---|
| 13 | ``` |
---|
| 14 | subroutine nf95_inq_file_ncid(ncid_file, grpid, ncerr) |
---|
| 15 | |
---|
| 16 | ! Find the ncid of the file (that is, the root group), knowing the |
---|
| 17 | ! ncid of a group in the file. |
---|
| 18 | |
---|
| 19 | integer, intent(out):: ncid_file |
---|
| 20 | integer, intent(in):: grpid |
---|
| 21 | integer, intent(out), optional:: ncerr |
---|
| 22 | ``` |
---|
| 23 | |
---|
| 24 | ## `nf95_inq_grp_full_ncid` |
---|
| 25 | |
---|
| 26 | (basic change) |
---|
| 27 | |
---|
| 28 | ``` |
---|
| 29 | subroutine nf95_inq_grp_full_ncid(ncid, full_name, grp_ncid, ncerr) |
---|
| 30 | |
---|
| 31 | integer, intent(in):: ncid ! can be the file id or a group id |
---|
| 32 | |
---|
| 33 | character(len = *), intent(in):: full_name |
---|
| 34 | ! Should be a path relative to ncid (which can correspond to the |
---|
| 35 | ! root group or a subgroup). Can be an immediate subgroup or a |
---|
| 36 | ! deeper subgroup. |
---|
| 37 | |
---|
| 38 | integer, intent(out):: grp_ncid |
---|
| 39 | integer, intent(out), optional:: ncerr |
---|
| 40 | ``` |
---|
| 41 | |
---|
| 42 | You know the relative path of a group and you want its ncid. |
---|
| 43 | |
---|
| 44 | Reference: |
---|
| 45 | [`nc_inq_grp_full_ncid`](https://docs.unidata.ucar.edu/netcdf-c/current/group__groups.html#ga41d2e214f1a880493ed8ea3fbddab806) |
---|
| 46 | |
---|
| 47 | ## `nf95_inq_grpname` |
---|
| 48 | |
---|
| 49 | (functionality change) |
---|
| 50 | |
---|
| 51 | ``` |
---|
| 52 | subroutine nf95_inq_grpname(ncid, name, ncerr) |
---|
| 53 | |
---|
| 54 | integer, intent(in):: ncid ! can be the file id or a group id |
---|
| 55 | character(len = :), allocatable, intent(out):: name ! without path |
---|
| 56 | integer, intent(out), optional:: ncerr |
---|
| 57 | ``` |
---|
| 58 | |
---|
| 59 | You know the ncid of a group (which can be the root group) and you |
---|
| 60 | want the basename of this group. The basename of the group is the last |
---|
| 61 | part in the absolute path, as in the Unix basename program. The |
---|
| 62 | basename of the root group is "/". |
---|
| 63 | |
---|
| 64 | The functionality change is that the argument `name` has dynamic, |
---|
| 65 | deferred length. |
---|
| 66 | |
---|
| 67 | The problem with the Fortran 90 interface: `name` has assumed length |
---|
| 68 | in the Fortran 90 interface. Also, there is no way in the Fortran 90 |
---|
| 69 | interface to only inquire about the length of the name. The function |
---|
| 70 | `nf90_inq_grpname_len` gives the length of the absolute path of the |
---|
| 71 | group, not the length of the basename of the group. |
---|
| 72 | |
---|
| 73 | Reference: |
---|
| 74 | [`nf90_inq_grpname`](https://docs.unidata.ucar.edu/netcdf-fortran/current/f90_groups.html#f90-find-a-groups-name-nf90_inq_grpname) |
---|
| 75 | |
---|
| 76 | ## `nf95_inq_grpname_full` |
---|
| 77 | |
---|
| 78 | (functionality change) |
---|
| 79 | |
---|
| 80 | ``` |
---|
| 81 | subroutine nf95_inq_grpname_full(ncid, full_name, ncerr) |
---|
| 82 | |
---|
| 83 | integer, intent(in):: ncid |
---|
| 84 | character(len = :), allocatable, intent(out):: full_name ! absolute path |
---|
| 85 | integer, intent(out), optional:: ncerr |
---|
| 86 | ``` |
---|
| 87 | |
---|
| 88 | You know the ncid of a group (which can be the root group) and you |
---|
| 89 | want the absolute path of the group. |
---|
| 90 | |
---|
| 91 | The functionality change is that the argument `full_name` has dynamic, |
---|
| 92 | deferred length, and there is no length argument. Since `full_name` is |
---|
| 93 | allocated to the exact length of the path, the length argument is |
---|
| 94 | useless, you can just query the length of the actual argument after |
---|
| 95 | the call. |
---|
| 96 | |
---|
| 97 | The problem with the Fortran 90 interface: the name argument has assumed length |
---|
| 98 | in the Fortran 90 interface. You have to call `nf90_inq_grpname_len` |
---|
| 99 | first to know the length of the actual argument that you will |
---|
| 100 | associate to name. |
---|
| 101 | |
---|
| 102 | Reference: |
---|
| 103 | [`nf90_inq_grpname_full`](https://docs.unidata.ucar.edu/netcdf-fortran/current/f90_groups.html#f90-find-a-groups-full-name-nf90_inq_grpname_full) |
---|
| 104 | |
---|
| 105 | ## `nf95_inq_grp_parent` |
---|
| 106 | |
---|
| 107 | (basic change) |
---|
| 108 | |
---|
| 109 | ``` |
---|
| 110 | subroutine nf95_inq_grp_parent(ncid, parent_ncid, ncerr) |
---|
| 111 | |
---|
| 112 | integer, intent(in):: ncid |
---|
| 113 | integer, intent(out):: parent_ncid |
---|
| 114 | integer, intent(out), optional:: ncerr |
---|
| 115 | ``` |
---|
| 116 | |
---|
| 117 | You know the ncid of a group and you want the ncid of the parent |
---|
| 118 | group. |
---|
| 119 | |
---|
| 120 | ## `nf95_inq_grps` |
---|
| 121 | |
---|
| 122 | (functionality change) |
---|
| 123 | |
---|
| 124 | ``` |
---|
| 125 | subroutine nf95_inq_grps(ncid, ncids, ncerr) |
---|
| 126 | |
---|
| 127 | integer, intent(in):: ncid ! can be the file id or a group id |
---|
| 128 | integer, allocatable, intent(out):: ncids(:) |
---|
| 129 | integer, intent(out), optional:: ncerr |
---|
| 130 | ``` |
---|
| 131 | |
---|
| 132 | You know the ncid of a group (which can be the root group) and you |
---|
| 133 | want the ncids of its immediate subgroups. |
---|
| 134 | |
---|
| 135 | The functionality change is that the argument ncids is allocatable and |
---|
| 136 | there is no argument numgrps. Since ncids is allocated to the number |
---|
| 137 | of groups, the argument numgrps is useless, you can just query the |
---|
| 138 | size of the actual argument associated to ncids after the call. |
---|
| 139 | |
---|
| 140 | The problem with the Fortran 90 interface: ncids has assumed shape in |
---|
| 141 | the Fortran 90 interface. Also, there is no way in the Fortran 90 |
---|
| 142 | interface to only inquire about the number of subgroups. The Fortran |
---|
| 143 | 90 interface is dangerous here because it does not check that the size |
---|
| 144 | of ncids is large enough: a segmentation violation will occur if it is |
---|
| 145 | not. NetCDF95 solves this by going directly to the C interface. |
---|
| 146 | |
---|
| 147 | Reference: |
---|
| 148 | [`nf90_inq_grps`](https://docs.unidata.ucar.edu/netcdf-fortran/current/f90_groups.html#f90-get-a-list-of-groups-in-a-group-nf90_inq_grps) |
---|
| 149 | and |
---|
| 150 | [`nc_inq_grps`](https://docs.unidata.ucar.edu/netcdf-c/current/group__groups.html#ga33eb934cc6810770be78eaa822656a00) |
---|
| 151 | |
---|