[4918] | 1 | # Variables |
---|
| 2 | |
---|
| 3 | This page describles procedures handling NetCDF variables. |
---|
| 4 | |
---|
| 5 | See the [improvements page](improvements.md) for an explanation of |
---|
| 6 | the mnemonics "basic change", "interface change", "functionality |
---|
| 7 | change", "additional procedure". |
---|
| 8 | |
---|
| 9 | ## Reminder on allocatable arguments |
---|
| 10 | |
---|
| 11 | Some NetCDF95 procedures below have a dummy argument with attributes |
---|
| 12 | allocatable and `intent(out)`. Recall that in this case the associated |
---|
| 13 | actual argument must also have the allocatable attribute. If it is |
---|
| 14 | allocated before the call, it will automatically be deallocated and |
---|
| 15 | reallocated in the NetCDF95 procedure. |
---|
| 16 | |
---|
| 17 | ## `nf95_def_var` and `nf95_def_var_scalar` |
---|
| 18 | |
---|
| 19 | (interface change) |
---|
| 20 | |
---|
| 21 | ``` |
---|
| 22 | subroutine nf95_def_var_scalar(ncid, name, xtype, varid, ncerr) |
---|
| 23 | integer, intent( in) :: ncid |
---|
| 24 | character (len = *), intent( in) :: name |
---|
| 25 | integer, intent( in) :: xtype |
---|
| 26 | integer, intent(out) :: varid |
---|
| 27 | integer, intent(out), optional:: ncerr |
---|
| 28 | ``` |
---|
| 29 | |
---|
| 30 | ``` |
---|
| 31 | subroutine nf95_def_var(ncid, name, xtype, dimids, varid, ncerr) |
---|
| 32 | integer, intent( in) :: ncid |
---|
| 33 | character (len = *), intent( in) :: name |
---|
| 34 | integer, intent( in) :: xtype |
---|
| 35 | integer[, dimension(:)], intent( in) :: dimids |
---|
| 36 | integer, intent(out) :: varid |
---|
| 37 | integer, intent(out), optional:: ncerr |
---|
| 38 | ``` |
---|
| 39 | |
---|
| 40 | (`dimids` may be either a scalar or a rank 1 array.) |
---|
| 41 | |
---|
| 42 | Because of the additional optional argument `ncerr`, the generic |
---|
| 43 | procedure name `nf95_def_var` cannot include the case of a scalar |
---|
| 44 | variable. So there is a specific public procedure `nf95_def_var_scalar` |
---|
| 45 | for this case. |
---|
| 46 | |
---|
| 47 | Reference: |
---|
| 48 | [`nf90_def_var`](https://docs.unidata.ucar.edu/netcdf-fortran/current/f90-variables.html#f90-create-a-variable-nf90_def_var) |
---|
| 49 | |
---|
| 50 | ## `nf95_get_var` |
---|
| 51 | |
---|
| 52 | (functionality change) |
---|
| 53 | |
---|
| 54 | ``` |
---|
| 55 | subroutine nf95_get_var(ncid, varid, values, start, & |
---|
| 56 | new_missing, ncerr) |
---|
| 57 | |
---|
| 58 | integer, intent(in) :: ncid, varid |
---|
| 59 | any type, intent(out):: values |
---|
| 60 | integer, dimension(:), optional, intent(in):: start |
---|
| 61 | same type as values, optional, intent(in):: new_missing |
---|
| 62 | integer, intent(out), optional:: ncerr |
---|
| 63 | ``` |
---|
| 64 | |
---|
| 65 | (if argument `values` is a scalar then arguments `count_nc`, stride and map |
---|
| 66 | must not be present) |
---|
| 67 | |
---|
| 68 | or |
---|
| 69 | |
---|
| 70 | ``` |
---|
| 71 | subroutine nf95_get_var(ncid, varid, values, start, & |
---|
| 72 | count_nc, stride, map, new_missing, ncerr) |
---|
| 73 | |
---|
| 74 | integer, intent(in) :: ncid, varid |
---|
| 75 | any type and any rank >= 1, intent(out):: values |
---|
| 76 | integer, dimension(:), optional, intent(in):: start, count_nc, stride, map |
---|
| 77 | same type as values, optional, intent(in):: new_missing |
---|
| 78 | integer, intent(out), optional:: ncerr |
---|
| 79 | ``` |
---|
| 80 | |
---|
| 81 | (if argument `values` is an array then arguments `count_nc`, stride and |
---|
| 82 | map may be present) |
---|
| 83 | |
---|
| 84 | The argument for the number of indices selected along each dimension is |
---|
| 85 | called `count_nc` in `nf95_get_var`, instead of `count` in |
---|
| 86 | `nf90_get_var`. `count` is not a good choice for a variable name because |
---|
| 87 | it is the name of a Fortran intrinsic procedure. |
---|
| 88 | |
---|
| 89 | `nf95_get_var` checks that : |
---|
| 90 | |
---|
| 91 | - the size of arguments `start` and `count_nc` equals the rank of the |
---|
| 92 | NetCDF variable ; |
---|
| 93 | - if `count_nc` is absent, the rank of argument `values` is lower than |
---|
| 94 | or equal to the rank of the NetCDF variable. |
---|
| 95 | |
---|
| 96 | There is an optional argument, `new_missing`, which is not in the |
---|
| 97 | [Fortran 90 NetCDF |
---|
| 98 | interface](https://www.unidata.ucar.edu/software/netcdf/docs-fortran/f90_The-NetCDF-Fortran-90-Interface-Guide.html). If |
---|
| 99 | the argument `new_missing` is present then, in the returned `values`, |
---|
| 100 | the missing value from the NetCDF variable is replaced by |
---|
| 101 | `new_missing`. This may be useful for example if, in your program, |
---|
| 102 | you need the missing value to be `ieee_value(0., IEEE_QUIET_NAN)` |
---|
| 103 | rather than `NF90_FILL_REAL`. |
---|
| 104 | |
---|
| 105 | Reference: |
---|
| 106 | [`nf90_get_var`](https://docs.unidata.ucar.edu/netcdf-fortran/current/f90-variables.html#f90-reading-data-values-nf90_get_var) |
---|
| 107 | |
---|
| 108 | ## `nf95_gw_var` |
---|
| 109 | |
---|
| 110 | (additional procedure) |
---|
| 111 | |
---|
| 112 | subroutine nf95_gw_var(ncid, varid, values) |
---|
| 113 | integer, intent(in):: ncid |
---|
| 114 | integer, intent(in):: varid |
---|
| 115 | any type and kind, any rank, allocatable, intent(out):: values |
---|
| 116 | |
---|
| 117 | `nf95_gw_var` stands for "NetCDF95 get whole variable". This |
---|
| 118 | procedure reads a whole NetCDF variable into an array. When you want all |
---|
| 119 | the values of the NetCDF variable, this procedure is a shortcut to: |
---|
| 120 | inquiring about the dimension IDs of the variable, inquiring about the |
---|
| 121 | length of each dimension found, allocating the Fortran variable, reading |
---|
| 122 | the values from the NetCDF variable. |
---|
| 123 | |
---|
| 124 | The procedure checks that the rank of the argument `values` equals the |
---|
| 125 | rank of the NetCDF variable. The procedure does not require nor check |
---|
| 126 | that the type of `values` corresponds to the type of the NetCDF |
---|
| 127 | variable: conversion will occur if necessary. |
---|
| 128 | |
---|
| 129 | See [reminder on allocatable arguments](#reminder-on-allocatable-arguments). |
---|
| 130 | |
---|
| 131 | ## `nf95_inq_varid` |
---|
| 132 | |
---|
| 133 | (basic change) |
---|
| 134 | |
---|
| 135 | subroutine nf95_inq_varid(ncid, name, varid, ncerr) |
---|
| 136 | integer, intent(in) :: ncid |
---|
| 137 | character (len = *), intent(in) :: name |
---|
| 138 | integer, intent(out) :: varid |
---|
| 139 | integer, intent(out), optional:: ncerr |
---|
| 140 | |
---|
| 141 | Reference: |
---|
| 142 | [`nf90_inq_varid`](https://docs.unidata.ucar.edu/netcdf-fortran/current/f90-variables.html#f90-get-the-id-of-a-variable-from-the-name-nf90_inq_varid) |
---|
| 143 | |
---|
| 144 | ## `nf95_inquire_variable` |
---|
| 145 | |
---|
| 146 | (functionality change) |
---|
| 147 | |
---|
| 148 | subroutine nf95_inquire_variable(ncid, varid, name, xtype, ndims, dimids, & |
---|
| 149 | nAtts, ncerr) |
---|
| 150 | integer, intent(in):: ncid, varid |
---|
| 151 | character(len = *), optional, intent(out):: name |
---|
| 152 | integer, optional, intent(out) :: xtype, ndims |
---|
| 153 | integer, dimension(:), optional, allocatable, intent(out) :: dimids |
---|
| 154 | integer, optional, intent(out) :: nAtts |
---|
| 155 | integer, intent(out), optional :: ncerr |
---|
| 156 | |
---|
| 157 | In the "new" `nf95_inquire_variable`, the argument `dimids` has the |
---|
| 158 | allocatable attribute. The procedure `nf95_inquire_variable` allocates |
---|
| 159 | and defines `dimids` if the argument is present. `dimids` is defined as |
---|
| 160 | a zero-sized array if the NetCDF variable is a scalar with no dimension. |
---|
| 161 | |
---|
| 162 | In the "old" `nf90_inquire_variable`, `dimids` was an assumed-size |
---|
| 163 | array. This was Fortran 77 style, not optimal. You had to allocate |
---|
| 164 | `dimids` in the calling procedure with a maximum possible number of |
---|
| 165 | dimensions. You also needed to call `nf90_inquire_variable` with the |
---|
| 166 | argument `ndims` present, to tell you which part of `dimids` was |
---|
| 167 | defined. |
---|
| 168 | |
---|
| 169 | See [reminder on allocatable arguments](#reminder-on-allocatable-arguments). |
---|
| 170 | |
---|
| 171 | Reference: |
---|
| 172 | [`nf90_inquire_variable`](https://docs.unidata.ucar.edu/netcdf-fortran/current/f90-variables.html#f90-get-information-about-a-variable-from-its-id-nf90_inquire_variable) |
---|
| 173 | |
---|
| 174 | ## `nf95_put_var` |
---|
| 175 | |
---|
| 176 | (functionality change) |
---|
| 177 | |
---|
| 178 | ``` |
---|
| 179 | subroutine nf95_put_var(ncid, varid, values, start, & |
---|
| 180 | ncerr) |
---|
| 181 | integer, intent(in) :: ncid, varid |
---|
| 182 | any type and any kind, intent(in) :: values |
---|
| 183 | integer, dimension(:), optional, intent(in) :: start, count_nc, stride, map |
---|
| 184 | integer, intent(out), optional:: ncerr |
---|
| 185 | ``` |
---|
| 186 | |
---|
| 187 | (argument `values` is a scalar then arguments `count_nc`, stride and map |
---|
| 188 | must not be present) |
---|
| 189 | |
---|
| 190 | or |
---|
| 191 | |
---|
| 192 | ``` |
---|
| 193 | subroutine nf95_put_var(ncid, varid, values, start, & |
---|
| 194 | count_nc, stride, map, ncerr) |
---|
| 195 | integer, intent(in) :: ncid, varid |
---|
| 196 | any type and any kind, any rank >= 1, intent(in) :: values |
---|
| 197 | integer, dimension(:), optional, intent(in) :: start, count_nc, stride, map |
---|
| 198 | integer, intent(out), optional:: ncerr |
---|
| 199 | ``` |
---|
| 200 | |
---|
| 201 | (argument `values` is an array then arguments `count_nc`, stride and |
---|
| 202 | map may be present) |
---|
| 203 | |
---|
| 204 | The argument for the number of indices selected along each dimension is |
---|
| 205 | called `count_nc` in `nf95_put_var`, instead of `count` in |
---|
| 206 | `nf90_put_var`. `count` is not a good choice for a variable name because |
---|
| 207 | it is the name of a Fortran intrinsic procedure. |
---|
| 208 | |
---|
| 209 | `nf95_put_var` checks that : |
---|
| 210 | |
---|
| 211 | - the size of arguments `start` and `count_nc` equals the rank of the |
---|
| 212 | NetCDF variable ; |
---|
| 213 | - if `count_nc` is absent, the rank of argument `values` is lower than |
---|
| 214 | or equal to the rank of the NetCDF variable. |
---|
| 215 | |
---|
| 216 | Reference: |
---|
| 217 | [`nf90_put_var`](https://docs.unidata.ucar.edu/netcdf-fortran/current/f90-variables.html#f90-writing-data-values-nf90_put_var) |
---|