NetCDF-Fortran  4.4.2
netcdf4_variables.f90
1  ! -----
2  ! Variable definitions and inquiry
3  ! -----
4  function nf90_def_var_scalar(ncid, name, xtype, varid)
5  integer, intent( in) :: ncid
6  character (len = *), intent( in) :: name
7  integer, intent(in) :: xtype
8  integer, intent(out) :: varid
9  integer :: nf90_def_var_scalar
10 
11  ! Dummy - shouldn't get used
12  integer, dimension(1) :: dimids
13 
14  ! These may not be used with scalars, but it causes an interface
15  ! violation if they are not optional arguments.
16 
17  nf90_def_var_scalar = nf_def_var(ncid, name, xtype, 0, dimids, varid)
18  end function nf90_def_var_scalar
19  ! -----
20  function nf90_def_var_onedim(ncid, name, xtype, dimids, varid, contiguous, &
21  chunksizes, deflate_level, shuffle, fletcher32, endianness, &
22  cache_size, cache_nelems, cache_preemption)
23  integer, intent( in) :: ncid
24  character (len = *), intent( in) :: name
25  integer, intent(in) :: xtype
26  integer, intent(in) :: dimids
27  integer, intent(out) :: varid
28  logical, optional, intent(in) :: contiguous
29  integer, optional, intent(in) :: chunksizes
30  integer, optional, intent(in) :: deflate_level
31  logical, optional, intent(in) :: shuffle, fletcher32
32  integer, optional, intent(in) :: endianness
33  integer, optional, intent(in) :: cache_size, cache_nelems, cache_preemption
34  integer :: nf90_def_var_onedim
35 
36  integer, dimension(1) :: dimidsa, chunksizes1
37  integer :: size1 = -1, nelems1 = -1, preemption1 = -1
38  integer :: contiguous1
39 
40  ! Put this int into an array, where all decent folk keep ids.
41  dimidsa(1) = dimids
42 
43  ! This is forbidden! Don't even think about it.
44  if (present(contiguous)) then
45  if (contiguous .and. present(chunksizes)) then
46  nf90_def_var_onedim = nf90_einval
47  return
48  end if
49  end if
50  if (present(contiguous)) then
51  if (.not. contiguous .and. .not. present(chunksizes)) then
52  nf90_def_var_onedim = nf90_einval
53  return
54  end if
55  end if
56 
57 
58  ! Define the variable.
59  nf90_def_var_onedim = nf_def_var(ncid, name, xtype, 1, dimidsa, varid)
60  if (nf90_def_var_onedim .ne. nf90_noerr) return
61 
62  ! Handle chunksizes and contiguous.
63  if (present(chunksizes) .or. present(contiguous)) then
64  if (present(contiguous)) then
65  if (contiguous) then
66  contiguous1 = nf90_contiguous
67  else
68  contiguous1 = nf90_notcontiguous
69  endif
70  endif
71  if (present(chunksizes)) then
72  contiguous1 = 0
73  chunksizes1(1) = chunksizes
74  endif
75  nf90_def_var_onedim = nf_def_var_chunking(ncid, varid, contiguous1, chunksizes1)
76  endif
77  if (present(contiguous)) then
78  if (contiguous) then
79  chunksizes1(1) = 0
80  nf90_def_var_onedim = nf_def_var_chunking(ncid, varid, 1, chunksizes1(1:1))
81  endif
82  endif
83  if (nf90_def_var_onedim .ne. nf90_noerr) return
84 
85  ! Handle deflate and shuffle.
86  if (present(deflate_level)) then
87  if (deflate_level .gt. 0) then
88  if (present(shuffle)) then
89  if (shuffle) then
90  nf90_def_var_onedim = nf_def_var_deflate(ncid, varid, 1, 1, deflate_level)
91  else
92  nf90_def_var_onedim = nf_def_var_deflate(ncid, varid, 0, 1, deflate_level)
93  end if
94  if (nf90_def_var_onedim .ne. nf90_noerr) return
95  end if
96  end if
97  endif
98 
99  ! Handle fletcher32.
100  if (present(fletcher32)) then
101  if (fletcher32) then
102  nf90_def_var_onedim = nf_def_var_fletcher32(ncid, varid, 1)
103  if (nf90_def_var_onedim .ne. nf90_noerr) return
104  endif
105  endif
106 
107  ! Handle endianness.
108  if (present(endianness)) then
109  nf90_def_var_onedim = nf_def_var_endian(ncid, varid, endianness)
110  if (nf90_def_var_onedim .ne. nf90_noerr) return
111  endif
112 
113  ! Set the cache if the user wants to.
114  if (present(cache_size) .or. present(cache_nelems) .or. &
115  present(cache_preemption)) then
116  ! Negative values mean leave it alone.
117  if (present(cache_size)) size1 = cache_size
118  if (present(cache_nelems)) nelems1 = cache_nelems
119  if (present(cache_preemption)) preemption1 = cache_preemption
120 
121  nf90_def_var_onedim = nf_set_var_chunk_cache(ncid, varid, &
122  size1, nelems1, preemption1)
123  if (nf90_def_var_onedim .ne. nf90_noerr) return
124  endif
125 
126  end function nf90_def_var_onedim
127  ! -----
128  function nf90_def_var_manydims(ncid, name, xtype, dimids, varid, contiguous, &
129  chunksizes, deflate_level, shuffle, fletcher32, endianness, cache_size, &
130  cache_nelems, cache_preemption)
131  integer, intent(in) :: ncid
132  character (len = *), intent(in) :: name
133  integer, intent( in) :: xtype
134  integer, dimension(:), intent(in) :: dimids
135  integer, intent(out) :: varid
136  logical, optional, intent(in) :: contiguous
137  integer, optional, dimension(:), intent(in) :: chunksizes
138  integer, optional, intent(in) :: deflate_level
139  logical, optional, intent(in) :: shuffle, fletcher32
140  integer, optional, intent(in) :: endianness
141  integer, optional, intent(in) :: cache_size, cache_nelems, cache_preemption
142  integer :: nf90_def_var_manydims
143 
144  ! Local variables.
145  integer :: contiguous1, d
146  integer :: size1 = -1, nelems1 = -1, preemption1 = -1
147  integer, dimension(nf90_max_dims) :: chunksizes1
148 
149  ! This is forbidden!
150  if (present(contiguous)) then
151  if (contiguous .and. present(chunksizes)) then
152  nf90_def_var_manydims = nf90_einval
153  return
154  end if
155  end if
156  if (present(contiguous)) then
157  if (.not. contiguous .and. .not. present(chunksizes)) then
158  nf90_def_var_manydims = nf90_einval
159  return
160  endif
161  end if
162 
163  ! Be nice and check array size.
164  if (present(chunksizes)) then
165  if (size(chunksizes) .ne. size(dimids)) then
166  nf90_def_var_manydims = nf90_einval
167  return
168  end if
169  end if
170 
171  ! Define the variable.
172  nf90_def_var_manydims = nf_def_var(ncid, name, xtype, size(dimids), dimids, varid)
173  if (nf90_def_var_manydims .ne. nf90_noerr) return
174 
175  ! Handle chunksizes and contiguous.
176  if (present(chunksizes) .or. present(contiguous)) then
177  if (present(contiguous)) then
178  if (contiguous) then
179  contiguous1 = nf90_contiguous
180  else
181  contiguous1 = nf90_notcontiguous
182  endif
183  endif
184  if (present(chunksizes)) then
185  contiguous1 = 0
186  do d = 1, size(dimids)
187  chunksizes1(d) = chunksizes(d)
188  end do
189  endif
190  nf90_def_var_manydims = nf_def_var_chunking(ncid, varid, contiguous1, chunksizes1)
191  endif
192  if (present(contiguous)) then
193  if (contiguous) then
194  chunksizes1(1) = 0
195  nf90_def_var_manydims = nf_def_var_chunking(ncid, varid, 1, chunksizes1(1:1))
196  endif
197  endif
198  if (nf90_def_var_manydims .ne. nf90_noerr) return
199 
200  ! Handle deflate and shuffle.
201  if (present(deflate_level)) then
202  if (deflate_level .gt. 0) then
203  if (present(shuffle)) then
204  if (shuffle) then
205  nf90_def_var_manydims = nf_def_var_deflate(ncid, varid, 1, 1, deflate_level)
206  else
207  nf90_def_var_manydims = nf_def_var_deflate(ncid, varid, 0, 1, deflate_level)
208  end if
209  else
210  nf90_def_var_manydims = nf_def_var_deflate(ncid, varid, 0, 1, deflate_level)
211  end if
212  end if
213  endif
214  if (nf90_def_var_manydims .ne. nf90_noerr) return
215 
216  ! Handle fletcher32.
217  if (present(fletcher32)) then
218  if (fletcher32) then
219  nf90_def_var_manydims = nf_def_var_fletcher32(ncid, varid, 1)
220  endif
221  endif
222  if (nf90_def_var_manydims .ne. nf90_noerr) return
223 
224  ! Handle endianness.
225  if (present(endianness)) then
226  nf90_def_var_manydims = nf_def_var_endian(ncid, varid, endianness)
227  endif
228 
229  ! Set the cache if the user wants to.
230  if (present(cache_size) .or. present(cache_nelems) .or. &
231  present(cache_preemption)) then
232  ! Negative values mean leave it alone.
233  if (present(cache_size)) size1 = cache_size
234  if (present(cache_nelems)) nelems1 = cache_nelems
235  if (present(cache_preemption)) preemption1 = cache_preemption
236 
237  nf90_def_var_manydims = nf_set_var_chunk_cache(ncid, varid, &
238  size1, nelems1, preemption1)
239  if (nf90_def_var_manydims .ne. nf90_noerr) return
240  endif
241 
242  end function nf90_def_var_manydims
243  ! -----
244  function nf90_inq_varid(ncid, name, varid)
245  integer, intent(in) :: ncid
246  character (len = *), intent( in) :: name
247  integer, intent(out) :: varid
248  integer :: nf90_inq_varid
249 
250  nf90_inq_varid = nf_inq_varid(ncid, name, varid)
251  if (nf90_inq_varid .ne. nf90_noerr) return
252 
253  end function nf90_inq_varid
254  ! -----
255  function nf90_set_var_chunk_cache(ncid, varid, size, nelems, preemption)
256  integer, intent(in) :: ncid, varid, size, nelems, preemption
257  integer :: nf90_set_var_chunk_cache
258 
259  nf90_set_var_chunk_cache = nf_set_var_chunk_cache(ncid, varid, &
260  size, nelems, preemption)
261  if (nf90_set_var_chunk_cache .ne. nf90_noerr) return
262 
263  end function nf90_set_var_chunk_cache
264  ! -----
265  function nf90_inquire_variable(ncid, varid, name, xtype, ndims, dimids, nAtts, &
266  contiguous, chunksizes, deflate_level, shuffle, fletcher32, endianness, &
267  cache_size, cache_nelems, cache_preemption)
268  integer, intent(in) :: ncid, varid
269  character (len = *), optional, intent(out) :: name
270  integer, optional, intent(out) :: xtype, ndims
271  integer, dimension(:), optional, intent(out) :: dimids
272  integer, optional, intent(out) :: natts
273  logical, optional, intent(out) :: contiguous
274  integer, optional, dimension(:), intent(out) :: chunksizes
275  integer, optional, intent(out) :: deflate_level
276  logical, optional, intent(out) :: shuffle, fletcher32
277  integer, optional, intent(out) :: endianness
278  integer, optional, intent(out) :: cache_size, cache_nelems, cache_preemption
279  integer :: nf90_inquire_variable
280 
281  ! Local variables
282  character (len = nf90_max_name) :: varname = ''
283  integer :: externaltype, numdimensions
284  integer, dimension(nf90_max_var_dims) :: dimensionids
285  integer :: numattributes
286  integer :: deflate1, deflate_level1, contiguous1, shuffle1, fletcher321
287  integer, dimension(nf90_max_dims) :: chunksizes1
288  integer :: size1, nelems1, preemption1
289  integer :: d
290 
291  ! Learn the basic facts.
292  nf90_inquire_variable = nf_inq_var(ncid, varid, varname, externaltype, &
293  numdimensions, dimensionids, numattributes)
294  if (nf90_inquire_variable .ne. nf90_noerr) return
295 
296  ! Tell the user what he wants to know.
297  if (present(name)) name = trim(varname)
298  if (present(xtype)) xtype = externaltype
299  if (present(ndims)) ndims = numdimensions
300  if (present(dimids)) then
301  if (size(dimids) .ge. numdimensions) then
302  dimids(:numdimensions) = dimensionids(:numdimensions)
303  else
304  nf90_inquire_variable = nf90_einval
305  endif
306  endif
307  if (present(natts)) natts = numattributes
308 
309  ! Get the chunksizes and contiguous settings, if desired.
310  if (present(chunksizes) .or. present(contiguous)) then
311  nf90_inquire_variable = nf_inq_var_chunking(ncid, varid, contiguous1, chunksizes1)
312  if (nf90_inquire_variable .ne. nf90_noerr) return
313  if (present(contiguous)) contiguous = contiguous1 .ne. nf90_notcontiguous
314  if (present(chunksizes)) then
315  do d = 1, numdimensions
316  chunksizes(d) = chunksizes1(d)
317  end do
318  endif
319  endif
320 
321  ! Get the fletcher32 settings, if desired.
322  if (present(fletcher32)) then
323  nf90_inquire_variable = nf_inq_var_fletcher32(ncid, varid, fletcher321)
324  if (nf90_inquire_variable .ne. nf90_noerr) return
325  fletcher32 = fletcher321 .gt. 0
326  endif
327 
328  ! Get the deflate and shuffle settings, if desired.
329  if (present(deflate_level) .or. present(shuffle)) then
330  nf90_inquire_variable = nf_inq_var_deflate(ncid, varid, shuffle1, deflate1, deflate_level1)
331  if (nf90_inquire_variable .ne. nf90_noerr) return
332  if (present(deflate_level)) deflate_level = deflate_level1
333  if (present(shuffle)) shuffle = shuffle1 .ne. 0
334  endif
335 
336  ! And the endianness...
337  if (present(endianness)) then
338  nf90_inquire_variable = nf_inq_var_endian(ncid, varid, endianness)
339  if (nf90_inquire_variable .ne. nf90_noerr) return
340  endif
341 
342  ! Does the user want cache settings?
343  if (present(cache_size) .or. present(cache_nelems) .or. present(cache_preemption)) then
344  nf90_inquire_variable = nf_get_var_chunk_cache(ncid, varid, &
345  size1, nelems1, preemption1)
346  if (nf90_inquire_variable .ne. nf90_noerr) return
347  if (present(cache_size)) cache_size = size1
348  if (present(cache_nelems)) cache_nelems = nelems1
349  if (present(cache_preemption)) cache_preemption = preemption1
350  endif
351  end function nf90_inquire_variable
352  ! -----
353  function nf90_rename_var(ncid, varid, newname)
354  integer, intent( in) :: ncid, varid
355  character (len = *), intent( in) :: newname
356  integer :: nf90_rename_var
357 
358  nf90_rename_var = nf_rename_var(ncid, varid, newname)
359  end function nf90_rename_var
360  ! -----

Return to the Main Unidata NetCDF page.
Generated on Fri Sep 25 2015 01:52:27 for NetCDF-Fortran. NetCDF is a Unidata library.