source: LMDZ6/branches/cirrus/tools/netcdf95/docs/Detailed_content/variables.md @ 5223

Last change on this file since 5223 was 4918, checked in by Laurent Fairhead, 7 months ago

Reintegrated NetCDF95 in LMDZ so that it is compiled and made available by the makelmdz_fcm script.
The makelmdz_fcm creates the libnetcdf95 library and copies it in the tools/netcdf/lib directory, copying
the mod files in the tools/netcdf/include library.

File size: 7.9 KB
Line 
1# Variables
2
3This page describles procedures handling NetCDF variables.
4
5See the [improvements page](improvements.md) for an explanation of
6the mnemonics "basic change", "interface change", "functionality
7change", "additional procedure".
8
9## Reminder on allocatable arguments
10
11Some NetCDF95 procedures below have a dummy argument with attributes
12allocatable and `intent(out)`. Recall that in this case the associated
13actual argument must also have the allocatable attribute. If it is
14allocated before the call, it will automatically be deallocated and
15reallocated in the NetCDF95 procedure.
16
17## `nf95_def_var` and `nf95_def_var_scalar`
18
19(interface change)
20
21```
22subroutine 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```
31subroutine 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
42Because of the additional optional argument `ncerr`, the generic
43procedure name `nf95_def_var` cannot include the case of a scalar
44variable. So there is a specific public procedure `nf95_def_var_scalar`
45for this case.
46
47Reference:
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```
55subroutine 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
66must not be present)
67
68or
69
70```
71subroutine 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
82map may be present)
83
84The argument for the number of indices selected along each dimension is
85called `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
87it 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
96There is an optional argument, `new_missing`, which is not in the
97[Fortran 90 NetCDF
98interface](https://www.unidata.ucar.edu/software/netcdf/docs-fortran/f90_The-NetCDF-Fortran-90-Interface-Guide.html). If
99the argument `new_missing` is present then, in the returned `values`,
100the missing value from the NetCDF variable is replaced by
101`new_missing`.  This may be useful for example if, in your program,
102you need the missing value to be `ieee_value(0., IEEE_QUIET_NAN)`
103rather than `NF90_FILL_REAL`.
104
105Reference:
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
118procedure reads a whole NetCDF variable into an array. When you want all
119the values of the NetCDF variable, this procedure is a shortcut to:
120inquiring about the dimension IDs of the variable, inquiring about the
121length of each dimension found, allocating the Fortran variable, reading
122the values from the NetCDF variable.
123
124The procedure checks that the rank of the argument `values` equals the
125rank of the NetCDF variable. The procedure does not require nor check
126that the type of `values` corresponds to the type of the NetCDF
127variable: conversion will occur if necessary.
128
129See [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
141Reference:
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
157In the "new" `nf95_inquire_variable`, the argument `dimids` has the
158allocatable attribute. The procedure `nf95_inquire_variable` allocates
159and defines `dimids` if the argument is present. `dimids` is defined as
160a zero-sized array if the NetCDF variable is a scalar with no dimension.
161
162In the "old" `nf90_inquire_variable`, `dimids` was an assumed-size
163array. This was Fortran 77 style, not optimal. You had to allocate
164`dimids` in the calling procedure with a maximum possible number of
165dimensions. You also needed to call `nf90_inquire_variable` with the
166argument `ndims` present, to tell you which part of `dimids` was
167defined.
168
169See [reminder on allocatable arguments](#reminder-on-allocatable-arguments).
170
171Reference:
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```
179subroutine 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
188must not be present)
189
190or
191
192```
193subroutine 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
202map may be present)
203
204The argument for the number of indices selected along each dimension is
205called `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
207it 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
216Reference:
217[`nf90_put_var`](https://docs.unidata.ucar.edu/netcdf-fortran/current/f90-variables.html#f90-writing-data-values-nf90_put_var)
Note: See TracBrowser for help on using the repository browser.