0.6.2-dev0
FORCES
FORtran lib for Comp. Env. Sys.
Loading...
Searching...
No Matches
mo_netcdf.f90
Go to the documentation of this file.
1!> \file mo_netcdf.f90
2!> \brief \copybrief mo_netcdf
3!> \details \copydetails mo_netcdf
4
5
6
7!> \brief NetCDF Fortran 90 interface wrapper
8!> \details A wrapper around the NetCDF Fortran 90 interface.
9!> \changelog
10!! - David Schaefer, Jun 2015
11!! - written
12!! - Matthias Cuntz, Jan 2016
13!! - compiled with PGI Fortran rev 15.9
14!! - no automatic allocation of left-hand-side
15!! - Ricardo Torres, Feb 2017
16!! - add derived type NcGroup and NcAttributable. NcAttributable is the base derived type,
17!! NcGroup and NcVariable are extended from it. NcDataset is extended from NcGroup. No more
18!! duplicated routines to set attributes.
19!> \authors David Schaefer
20!> \date Jun 2015
21!> \copyright Copyright 2005-\today, the CHS Developers, Sabine Attinger: All rights reserved.
22!! FORCES is released under the LGPLv3+ license \license_note
24
25 use mo_kind, only: sp, dp, i1, i2, i4, i8
26 use mo_utils, only: ne
27 use ieee_arithmetic, only : ieee_is_nan
28
29 use netcdf, only : &
30 nf90_open, nf90_close, nf90_strerror, nf90_def_dim, nf90_def_var, &
31 nf90_put_var, nf90_get_var, nf90_put_att, nf90_get_att, nf90_inq_attname, &
32 nf90_inquire, nf90_inq_dimid, nf90_inquire_dimension, &
33 nf90_inq_varid, nf90_inq_varids, nf90_inquire_variable, nf90_inquire_attribute, &
34 nf90_inq_ncid, nf90_inq_grp_parent, nf90_inq_grpname, nf90_def_grp, &
35 nf90_rename_dim, nf90_rename_var, nf90_rename_att, nf90_sync, &
36 nf90_open, nf90_netcdf4, nf90_create, nf90_write, nf90_nowrite, &
37 nf90_byte, nf90_short, nf90_int, nf90_int64, nf90_float, nf90_double, nf90_char, &
38 nf90_fill_byte, nf90_fill_short, nf90_fill_int, nf90_fill_float, nf90_fill_double, &
39 nf90_noerr, nf90_unlimited, nf90_global, nf90_share, nf90_hdf5, &
40 nf90_64bit_offset, nf90_classic_model
41
42 implicit none
43
44 ! --------------------------------------------------------------------------------------
45 character(10), parameter :: cf_fill_value = '_FillValue' !< CF fill value
46 character(11), parameter :: cf_valid_range = 'valid_range' !< CF valid range
47 character(9), parameter :: cf_valid_min = 'valid_min' !< CF valid min
48 character(9), parameter :: cf_valid_max = 'valid_max' !< CF valid max
49 integer(i4), parameter :: cf_use_fill_value = 1_i4 !< CF use fill value
50 integer(i4), parameter :: cf_use_valid_min = 2_i4 !< CF use valid min
51 integer(i4), parameter :: cf_use_valid_max = 3_i4 !< CF use valid max
52 integer(i4), parameter :: cf_use_valid_range = 4_i4 !< CF use valid range
53 integer(i4), parameter :: cf_use_nan = 5_i4 !< CF use nan
54
55 !> \brief NetCDF base class
56 type, abstract :: ncbase
57
58 integer(i4) :: id !< object id
59
60 contains
61
62 procedure(getnameinterface), deferred :: getname !< object name
63 procedure(getparentinterface), deferred :: getparent !< object parent
64
65 end type ncbase
66
67 !> \brief NetCDF attributable class
68 type, abstract, extends(ncbase) :: ncattributable
69
70 contains
71
72 procedure, public :: hasattribute !< object has attribute
73 procedure, public :: renameattribute !< rename attribute
74 procedure, private :: getattributableids
75 procedure, public :: getattributenames
76
77 procedure, private :: setattribute_0d_sp
78 generic, public :: setattribute => setattribute_0d_sp !< set attribute
79 procedure, private :: getattribute_0d_sp
80 generic, public :: getattribute => getattribute_0d_sp !< get attribute
81 procedure, private :: setattribute_1d_sp
82 generic, public :: setattribute => setattribute_1d_sp !< set attribute
83 procedure, private :: getattribute_1d_sp
84 generic, public :: getattribute => getattribute_1d_sp !< get attribute
85 procedure, private :: setattribute_0d_dp
86 generic, public :: setattribute => setattribute_0d_dp !< set attribute
87 procedure, private :: getattribute_0d_dp
88 generic, public :: getattribute => getattribute_0d_dp !< get attribute
89 procedure, private :: setattribute_1d_dp
90 generic, public :: setattribute => setattribute_1d_dp !< set attribute
91 procedure, private :: getattribute_1d_dp
92 generic, public :: getattribute => getattribute_1d_dp !< get attribute
93 procedure, private :: setattribute_0d_i1
94 generic, public :: setattribute => setattribute_0d_i1 !< set attribute
95 procedure, private :: getattribute_0d_i1
96 generic, public :: getattribute => getattribute_0d_i1 !< get attribute
97 procedure, private :: setattribute_1d_i1
98 generic, public :: setattribute => setattribute_1d_i1 !< set attribute
99 procedure, private :: getattribute_1d_i1
100 generic, public :: getattribute => getattribute_1d_i1 !< get attribute
101 procedure, private :: setattribute_0d_i2
102 generic, public :: setattribute => setattribute_0d_i2 !< set attribute
103 procedure, private :: getattribute_0d_i2
104 generic, public :: getattribute => getattribute_0d_i2 !< get attribute
105 procedure, private :: setattribute_1d_i2
106 generic, public :: setattribute => setattribute_1d_i2 !< set attribute
107 procedure, private :: getattribute_1d_i2
108 generic, public :: getattribute => getattribute_1d_i2 !< get attribute
109 procedure, private :: setattribute_0d_i4
110 generic, public :: setattribute => setattribute_0d_i4 !< set attribute
111 procedure, private :: getattribute_0d_i4
112 generic, public :: getattribute => getattribute_0d_i4 !< get attribute
113 procedure, private :: setattribute_1d_i4
114 generic, public :: setattribute => setattribute_1d_i4 !< set attribute
115 procedure, private :: getattribute_1d_i4
116 generic, public :: getattribute => getattribute_1d_i4 !< get attribute
117 procedure, private :: setattribute_0d_i8
118 generic, public :: setattribute => setattribute_0d_i8 !< set attribute
119 procedure, private :: getattribute_0d_i8
120 generic, public :: getattribute => getattribute_0d_i8 !< get attribute
121 procedure, private :: setattribute_1d_i8
122 generic, public :: setattribute => setattribute_1d_i8 !< set attribute
123 procedure, private :: getattribute_1d_i8
124 generic, public :: getattribute => getattribute_1d_i8 !< get attribute
125 procedure, private :: setattribute_0d_char
126 generic, public :: setattribute => setattribute_0d_char !< set attribute
127 procedure, private :: getattribute_0d_char
128 generic, public :: getattribute => getattribute_0d_char !< get attribute
129
130 end type ncattributable
131
132 ! --------------------------------------------------------------------------------------
133
134 !> \brief NetCDF Group class
135 type, extends(ncattributable) :: ncgroup
136
137 contains
138
139 ! getter
140 procedure, private :: getVariableIds
141 procedure, public :: getvariables !< get variables
142 procedure, public :: getunlimiteddimension !< get unlimited dimension
143 procedure, public :: getnovariables !< get number of variables
144
145 procedure, private :: getdimensionbyname
146 procedure, private :: getdimensionbyid
147
148 procedure, public :: getparent => getgroupparent !< get parent
149 procedure, public :: getname => getgroupname !< get name
150 procedure, public :: getgroup => getgroupbyname !< get group by name
151 procedure, public :: getvariable => getvariablebyname !< get variable by name
152 generic, public :: getdimension => &
153 getdimensionbyid, &
154 getdimensionbyname !< get dimension
155
156 ! checker
157 procedure, public :: hasvariable !< has variable
158 procedure, public :: hasdimension !< has dimension
159 procedure, public :: hasgroup !< has group
160 procedure, public :: isunlimited => isdatasetunlimited !< is unlimited
161
162 ! setter
163 procedure, public :: setgroup !< set group
164 procedure, public :: setdimension !< set dimension
165 procedure, public :: setcoordinate !< set coordinate
166 procedure, private :: set_scrip_dimension
167 procedure, private :: set_1d_coordinate_variable
168 procedure, private :: setvariablewithtypes
169 procedure, private :: setvariablewithnames
170 procedure, private :: setvariablewithids
171
172 generic, public :: setvariable => &
173 setvariablewithnames, &
174 setvariablewithtypes, &
175 setvariablewithids !< set variable
176
177 end type ncgroup
178
179 interface ncgroup
180 procedure newncgroup
181 end interface ncgroup
182
183 ! --------------------------------------------------------------------------------------
184
185 !> \brief NetCDF Dataset class
186 type, extends(ncgroup) :: ncdataset
187
188 character(256) :: fname !< Filename of the opened dataset
189 character(1) :: mode !< File open mode
190
191 contains
192
193 procedure, public :: sync !< sync dataset
194 procedure, public :: close !< close dataset
195
196 end type ncdataset
197
198 interface ncdataset
199 procedure newncdataset
200 end interface ncdataset
201
202 ! --------------------------------------------------------------------------------------
203
204 !> \brief NetCDF Dimension class
205 type, extends(ncbase) :: ncdimension
206
207 type(ncgroup) :: parent !< The dimension's parent
208 contains
209 procedure, public :: renamedimension !< rename dimension
210 procedure, public :: getparent => getdimensionparent !< get parent
211 procedure, public :: getname => getdimensionname !< get name
212 procedure, public :: getlength => getdimensionlength !< get length
213 procedure, public :: isunlimited => isunlimiteddimension !< is unlimited
214 end type ncdimension
215
216 interface ncdimension
217 procedure newncdimension
218 end interface ncdimension
219 ! --------------------------------------------------------------------------------------
220
221 !> \brief NetCDF Variable class
222 type, extends(ncattributable) :: ncvariable
223 type(ncgroup) :: parent !< The variables's parent
224
225 contains
226
227 procedure, public :: renamevariable !< rename
228 procedure, public :: getparent => getvariableparent !< get parent
229 procedure, public :: getname => getvariablename !< get name
230 procedure, private :: getslicingshape
231
232 procedure, private :: setdata_0d_sp
233 generic, public :: setdata => setdata_0d_sp !< set data
234 procedure, private :: getdata_0d_sp
235 generic, public :: getdata => getdata_0d_sp !< get data
236 procedure, private :: setdata_1d_sp
237 generic, public :: setdata => setdata_1d_sp !< set data
238 procedure, private :: getdata_1d_sp
239 generic, public :: getdata => getdata_1d_sp !< get data
240 procedure, private :: setdata_2d_sp
241 generic, public :: setdata => setdata_2d_sp !< set data
242 procedure, private :: getdata_2d_sp
243 generic, public :: getdata => getdata_2d_sp !< get data
244 procedure, private :: setdata_3d_sp
245 generic, public :: setdata => setdata_3d_sp !< set data
246 procedure, private :: getdata_3d_sp
247 generic, public :: getdata => getdata_3d_sp !< get data
248 procedure, private :: setdata_4d_sp
249 generic, public :: setdata => setdata_4d_sp !< set data
250 procedure, private :: getdata_4d_sp
251 generic, public :: getdata => getdata_4d_sp !< get data
252 procedure, private :: setdata_5d_sp
253 generic, public :: setdata => setdata_5d_sp !< set data
254 procedure, private :: getdata_5d_sp
255 generic, public :: getdata => getdata_5d_sp !< get data
256 procedure, private :: setdata_6d_sp
257 generic, public :: setdata => setdata_6d_sp !< set data
258 procedure, private :: getdata_6d_sp
259 generic, public :: getdata => getdata_6d_sp !< get data
260 procedure, private :: getcfattributes_sp
261 generic, public :: getcfattributes => getcfattributes_sp !< get CF attributes
262 procedure, private :: setvariablefillvalue_sp
263 generic, public :: setfillvalue => setvariablefillvalue_sp !< set fill value
264 procedure, private :: getvariablefillvalue_sp
265 generic, public :: getfillvalue => getvariablefillvalue_sp !< get fill value
266 procedure, private :: setdata_0d_dp
267 generic, public :: setdata => setdata_0d_dp !< set data
268 procedure, private :: getdata_0d_dp
269 generic, public :: getdata => getdata_0d_dp !< get data
270 procedure, private :: setdata_1d_dp
271 generic, public :: setdata => setdata_1d_dp !< set data
272 procedure, private :: getdata_1d_dp
273 generic, public :: getdata => getdata_1d_dp !< get data
274 procedure, private :: setdata_2d_dp
275 generic, public :: setdata => setdata_2d_dp !< set data
276 procedure, private :: getdata_2d_dp
277 generic, public :: getdata => getdata_2d_dp !< get data
278 procedure, private :: setdata_3d_dp
279 generic, public :: setdata => setdata_3d_dp !< set data
280 procedure, private :: getdata_3d_dp
281 generic, public :: getdata => getdata_3d_dp !< get data
282 procedure, private :: setdata_4d_dp
283 generic, public :: setdata => setdata_4d_dp !< set data
284 procedure, private :: getdata_4d_dp
285 generic, public :: getdata => getdata_4d_dp !< get data
286 procedure, private :: setdata_5d_dp
287 generic, public :: setdata => setdata_5d_dp !< set data
288 procedure, private :: getdata_5d_dp
289 generic, public :: getdata => getdata_5d_dp !< get data
290 procedure, private :: setdata_6d_dp
291 generic, public :: setdata => setdata_6d_dp !< set data
292 procedure, private :: getdata_6d_dp
293 generic, public :: getdata => getdata_6d_dp !< get data
294 procedure, private :: getcfattributes_dp
295 generic, public :: getcfattributes => getcfattributes_dp !< get CF attributes
296 procedure, private :: setvariablefillvalue_dp
297 generic, public :: setfillvalue => setvariablefillvalue_dp !< set fill value
298 procedure, private :: getvariablefillvalue_dp
299 generic, public :: getfillvalue => getvariablefillvalue_dp !< get fill value
300 procedure, private :: setdata_0d_i1
301 generic, public :: setdata => setdata_0d_i1 !< set data
302 procedure, private :: getdata_0d_i1
303 generic, public :: getdata => getdata_0d_i1 !< get data
304 procedure, private :: setdata_1d_i1
305 generic, public :: setdata => setdata_1d_i1 !< set data
306 procedure, private :: getdata_1d_i1
307 generic, public :: getdata => getdata_1d_i1 !< get data
308 procedure, private :: setdata_2d_i1
309 generic, public :: setdata => setdata_2d_i1 !< set data
310 procedure, private :: getdata_2d_i1
311 generic, public :: getdata => getdata_2d_i1 !< get data
312 procedure, private :: setdata_3d_i1
313 generic, public :: setdata => setdata_3d_i1 !< set data
314 procedure, private :: getdata_3d_i1
315 generic, public :: getdata => getdata_3d_i1 !< get data
316 procedure, private :: setdata_4d_i1
317 generic, public :: setdata => setdata_4d_i1 !< set data
318 procedure, private :: getdata_4d_i1
319 generic, public :: getdata => getdata_4d_i1 !< get data
320 procedure, private :: setdata_5d_i1
321 generic, public :: setdata => setdata_5d_i1 !< set data
322 procedure, private :: getdata_5d_i1
323 generic, public :: getdata => getdata_5d_i1 !< get data
324 procedure, private :: setdata_6d_i1
325 generic, public :: setdata => setdata_6d_i1 !< set data
326 procedure, private :: getdata_6d_i1
327 generic, public :: getdata => getdata_6d_i1 !< get data
328 procedure, private :: getcfattributes_i1
329 generic, public :: getcfattributes => getcfattributes_i1 !< get CF attributes
330 procedure, private :: setvariablefillvalue_i1
331 generic, public :: setfillvalue => setvariablefillvalue_i1 !< set fill value
332 procedure, private :: getvariablefillvalue_i1
333 generic, public :: getfillvalue => getvariablefillvalue_i1 !< get fill value
334 procedure, private :: setdata_0d_i2
335 generic, public :: setdata => setdata_0d_i2 !< set data
336 procedure, private :: getdata_0d_i2
337 generic, public :: getdata => getdata_0d_i2 !< get data
338 procedure, private :: setdata_1d_i2
339 generic, public :: setdata => setdata_1d_i2 !< set data
340 procedure, private :: getdata_1d_i2
341 generic, public :: getdata => getdata_1d_i2 !< get data
342 procedure, private :: setdata_2d_i2
343 generic, public :: setdata => setdata_2d_i2 !< set data
344 procedure, private :: getdata_2d_i2
345 generic, public :: getdata => getdata_2d_i2 !< get data
346 procedure, private :: setdata_3d_i2
347 generic, public :: setdata => setdata_3d_i2 !< set data
348 procedure, private :: getdata_3d_i2
349 generic, public :: getdata => getdata_3d_i2 !< get data
350 procedure, private :: setdata_4d_i2
351 generic, public :: setdata => setdata_4d_i2 !< set data
352 procedure, private :: getdata_4d_i2
353 generic, public :: getdata => getdata_4d_i2 !< get data
354 procedure, private :: setdata_5d_i2
355 generic, public :: setdata => setdata_5d_i2 !< set data
356 procedure, private :: getdata_5d_i2
357 generic, public :: getdata => getdata_5d_i2 !< get data
358 procedure, private :: setdata_6d_i2
359 generic, public :: setdata => setdata_6d_i2 !< set data
360 procedure, private :: getdata_6d_i2
361 generic, public :: getdata => getdata_6d_i2 !< get data
362 procedure, private :: getcfattributes_i2
363 generic, public :: getcfattributes => getcfattributes_i2 !< get CF attributes
364 procedure, private :: setvariablefillvalue_i2
365 generic, public :: setfillvalue => setvariablefillvalue_i2 !< set fill value
366 procedure, private :: getvariablefillvalue_i2
367 generic, public :: getfillvalue => getvariablefillvalue_i2 !< get fill value
368 procedure, private :: setdata_0d_i4
369 generic, public :: setdata => setdata_0d_i4 !< set data
370 procedure, private :: getdata_0d_i4
371 generic, public :: getdata => getdata_0d_i4 !< get data
372 procedure, private :: setdata_1d_i4
373 generic, public :: setdata => setdata_1d_i4 !< set data
374 procedure, private :: getdata_1d_i4
375 generic, public :: getdata => getdata_1d_i4 !< get data
376 procedure, private :: setdata_2d_i4
377 generic, public :: setdata => setdata_2d_i4 !< set data
378 procedure, private :: getdata_2d_i4
379 generic, public :: getdata => getdata_2d_i4 !< get data
380 procedure, private :: setdata_3d_i4
381 generic, public :: setdata => setdata_3d_i4 !< set data
382 procedure, private :: getdata_3d_i4
383 generic, public :: getdata => getdata_3d_i4 !< get data
384 procedure, private :: setdata_4d_i4
385 generic, public :: setdata => setdata_4d_i4 !< set data
386 procedure, private :: getdata_4d_i4
387 generic, public :: getdata => getdata_4d_i4 !< get data
388 procedure, private :: setdata_5d_i4
389 generic, public :: setdata => setdata_5d_i4 !< set data
390 procedure, private :: getdata_5d_i4
391 generic, public :: getdata => getdata_5d_i4 !< get data
392 procedure, private :: setdata_6d_i4
393 generic, public :: setdata => setdata_6d_i4 !< set data
394 procedure, private :: getdata_6d_i4
395 generic, public :: getdata => getdata_6d_i4 !< get data
396 procedure, private :: getcfattributes_i4
397 generic, public :: getcfattributes => getcfattributes_i4 !< get CF attributes
398 procedure, private :: setvariablefillvalue_i4
399 generic, public :: setfillvalue => setvariablefillvalue_i4 !< set fill value
400 procedure, private :: getvariablefillvalue_i4
401 generic, public :: getfillvalue => getvariablefillvalue_i4 !< get fill value
402 procedure, private :: setdata_0d_i8
403 generic, public :: setdata => setdata_0d_i8 !< set data
404 procedure, private :: getdata_0d_i8
405 generic, public :: getdata => getdata_0d_i8 !< get data
406 procedure, private :: setdata_1d_i8
407 generic, public :: setdata => setdata_1d_i8 !< set data
408 procedure, private :: getdata_1d_i8
409 generic, public :: getdata => getdata_1d_i8 !< get data
410 procedure, private :: setdata_2d_i8
411 generic, public :: setdata => setdata_2d_i8 !< set data
412 procedure, private :: getdata_2d_i8
413 generic, public :: getdata => getdata_2d_i8 !< get data
414 procedure, private :: setdata_3d_i8
415 generic, public :: setdata => setdata_3d_i8 !< set data
416 procedure, private :: getdata_3d_i8
417 generic, public :: getdata => getdata_3d_i8 !< get data
418 procedure, private :: setdata_4d_i8
419 generic, public :: setdata => setdata_4d_i8 !< set data
420 procedure, private :: getdata_4d_i8
421 generic, public :: getdata => getdata_4d_i8 !< get data
422 procedure, private :: setdata_5d_i8
423 generic, public :: setdata => setdata_5d_i8 !< set data
424 procedure, private :: getdata_5d_i8
425 generic, public :: getdata => getdata_5d_i8 !< get data
426 procedure, private :: setdata_6d_i8
427 generic, public :: setdata => setdata_6d_i8 !< set data
428 procedure, private :: getdata_6d_i8
429 generic, public :: getdata => getdata_6d_i8 !< get data
430 procedure, private :: getcfattributes_i8
431 generic, public :: getcfattributes => getcfattributes_i8 !< get CF attributes
432 procedure, private :: setvariablefillvalue_i8
433 generic, public :: setfillvalue => setvariablefillvalue_i8 !< set fill value
434 procedure, private :: getvariablefillvalue_i8
435 generic, public :: getfillvalue => getvariablefillvalue_i8 !< get fill value
436
437 procedure, public :: getnodimensions !< get number of dimensions
438
439 procedure, public :: getdimensions => getvariabledimensions !< get dimensions
440
441 procedure, public :: getrank => getvariablerank !< get rank
442
443 procedure, public :: getshape => getvariableshape !< get shape
444
445 procedure, public :: getdtype => getvariabledtype !< get data type
446
447 procedure, public :: isunlimited => isunlimitedvariable !< is unlimited
448
449
450 end type ncvariable
451
452 interface ncvariable
453 procedure newncvariable
454 end interface ncvariable
455 ! --------------------------------------------------------------------------------------
456
457 ! abstract interfaces
458 interface
459 !> \brief get name abstract interface
460 function getnameinterface(self)
461 import ncbase
462 class(NcBase), intent(in) :: self
463 character(len = 256) :: getNameInterface
464 end function getnameinterface
465
466 !> \brief get parent abstract interface
467 function getparentinterface(self)
468 import ncbase, ncgroup
469 class(NcBase), intent(in) :: self
470 type(NcGroup) :: getParentInterface
471 end function getparentinterface
472 end interface
473
474 !> \brief NetCDF comparison operator
475 interface operator (==)
476 procedure equalNcBases
477 end interface operator (==)
478
479contains
480
481 function newncdataset(fname, fmode, cmode) result(out)
482 character(*), intent(in) :: fname
483 character(1), intent(in) :: fmode
484 character(*), intent(inout), optional :: cmode
485 integer(i4) :: status
486 type(NcDataset) :: out
487
488 select case(fmode)
489 case("w")
490 status = nf90_create(trim(fname), getcreationmode(cmode), out%id)
491 case("r")
492 status = nf90_open(trim(fname), nf90_nowrite, out%id)
493 case("a")
494 status = nf90_open(trim(fname), nf90_write, out%id)
495 case default
496 write(*, *) "Mode argument must be in 'w','r','a' ! "
497 stop 1
498 end select
499 call check(status, "Failed to open file: " // fname)
500
501 out%fname = fname
502 out%mode = fmode
503 end function newncdataset
504
505 function newncvariable(id, parent) result(out)
506 integer(i4), intent(in) :: id
507 type(NcGroup), intent(in) :: parent
508 type(NcVariable) :: out
509
510 out%id = id
511 out%parent = parent
512 end function newncvariable
513
514 function newncdimension(id, parent) result(out)
515 integer(i4), intent(in) :: id
516 type(NcGroup), intent(in) :: parent
517 type(NcDimension) :: out
518
519 out%id = id
520 out%parent = parent
521 end function newncdimension
522
523 function newncgroup(id) result(out)
524 integer(i4), intent(in) :: id
525 type(NcGroup) :: out
526
527 out%id = id
528 end function newncgroup
529
530 subroutine sync(self)
531 class(NcDataset) :: self
532
533 call check(nf90_sync(self%id), "Failed to sync file: " // self%fname)
534 end subroutine sync
535
536 subroutine close(self)
537 class(NcDataset) :: self
538
539 call check(nf90_close(self%id), "Failed to close file: " // self%fname)
540 end subroutine close
541
542 function setgroup(self, name)
543 class(NcGroup), intent(inout) :: self
544 character(*), intent(in) :: name
545 integer(i4) :: id
546 type(NcGroup) :: setGroup
547
548 call check(nf90_def_grp(self%id, name, id), "Failed to create new group: " // name)
549 setgroup = ncgroup(id)
550 end function setgroup
551
552 function getgroupparent(self)
553 class(NcGroup), intent(in) :: self
554 integer(i4) :: id
555 type(NcGroup) :: getGroupParent
556
557 call check(nf90_inq_grp_parent(self%id, id), "Failed to get parent group of: " // self%getName())
558 getgroupparent = ncgroup(id)
559 end function getgroupparent
560
561 function getgroupname(self)
562 class(NcGroup), intent(in) :: self
563 character(256) :: getGroupName
564
565 call check(nf90_inq_grpname(self%id, getgroupname), "Failed to inquire group name")
566 end function getgroupname
567
568 function getnovariables(self)
569 class(NcGroup), intent(in) :: self
570 integer(i4) :: getNoVariables
571
572 call check(nf90_inquire(self%id, nvariables = getnovariables), "Failed inquire number of variables")
573 end function getnovariables
574
575 function getdimensionparent(self)
576 class(NcDimension), intent(in) :: self
577 type(NcGroup) :: getDimensionParent
578
579 getdimensionparent = self%parent
580 end function getdimensionparent
581
582 function getvariableparent(self)
583 class(NcVariable), intent(in) :: self
584 type(NcGroup) :: getVariableParent
585
586 getvariableparent = self%parent
587 end function getvariableparent
588
589 function getvariableids(self)
590 class(NcGroup), intent(in) :: self
591 integer(i4), dimension(:), allocatable :: getVariableIds
592 integer(i4) :: tmp
593
594 allocate(getvariableids(self%getNoVariables()))
595 call check(nf90_inq_varids(self%id, tmp, getvariableids), "Failed to inquire variable ids")
596 end function getvariableids
597
598 function getvariables(self)
599 class(NcGroup), intent(in) :: self
600 type(NcVariable), dimension(:), allocatable :: getVariables
601 integer(i4), dimension(:), allocatable :: varids
602 integer(i4) :: i, nvars
603
604 nvars = self%getNoVariables()
605 allocate(getvariables(nvars), varids(nvars))
606
607 varids = self%getVariableIds()
608 do i = 1, size(varids)
609 getvariables(i) = ncvariable(varids(i), self)
610 end do
611
612 end function getvariables
613
614 function getdimensionname(self)
615 class(NcDimension), intent(in) :: self
616 character(len = 256) :: getDimensionName
617
618 call check(nf90_inquire_dimension(self%parent%id, self%id, name = getdimensionname), &
619 "Failed to inquire dimension name")
620 end function getdimensionname
621
622 function getdimensionlength(self)
623 class(NcDimension), intent(in) :: self
624 integer(i4) :: getDimensionLength
625
626 call check(nf90_inquire_dimension(self%parent%id, self%id, len = getdimensionlength), &
627 "Failed to inquire dimension: " // self%getName())
628 end function getdimensionlength
629
630 function isdatasetunlimited(self)
631 class(NcGroup), intent(in) :: self
632 logical :: isDatasetUnlimited
633 integer(i4) :: dimid
634
635 call check(nf90_inquire(self%id, unlimiteddimid = dimid), &
636 "Failed to inquire group " // self%getName())
637 isdatasetunlimited = (dimid /= -1)
638 end function isdatasetunlimited
639
640 function getunlimiteddimension(self)
641 class(NcGroup), intent(in) :: self
642 type(NcDimension) :: getUnlimitedDimension
643 integer(i4) :: dimid
644
645 call check(nf90_inquire(self%id, unlimiteddimid = dimid), &
646 "Failed to inquire group " // self%getName())
647
648 if (dimid == -1) then
649 write(*, *) "Dataset has no unlimited dimension"
650 stop 1
651 end if
652
653 getunlimiteddimension = self%getDimension(dimid)
654 end function getunlimiteddimension
655
656 function equalncbases(left, right) result(out)
657 class(NcBase), intent(in) :: left, right
658 logical :: out
659
660 out = (left%id == right%id)
661 end function equalncbases
662
663 function isunlimiteddimension(self)
664 class(NcDimension), intent(in) :: self
665 logical :: isUnlimitedDimension
666
667 isunlimiteddimension = .false.
668 if (self%parent%isUnlimited()) then
669 isunlimiteddimension = (self == self%parent%getUnlimitedDimension())
670 end if
671 end function isunlimiteddimension
672
673 function set_scrip_dimension(self, centersDim1, centersDim2, cornersDim1, cornersDim2, subDimSizes, units) &
674 result(ncdim)
675 class(NcGroup), intent(in) :: self
676 real(dp) , intent(in), dimension(:) :: centersDim1
677 real(dp) , intent(in), dimension(:) :: centersDim2
678 real(dp) , intent(in), dimension(:,:) :: cornersDim1
679 real(dp) , intent(in), dimension(:,:) :: cornersDim2
680 integer(i4) , intent(in), dimension(:) :: subDimSizes
681 character(256), intent(in) :: units
682 type(NcDimension) :: ncDim
683
684 type(NcDimension) :: cornerDim, rankDim
685 type(NcVariable) :: ncVar
686 integer(i4), allocatable, dimension(:) :: imask_data
687
688 ! set the new ncDimension (integer values and name)
689 ncdim = self%setDimension('grid_size', size(centersdim1))
690 cornerdim = self%setDimension('grid_corners', size(cornersdim1, 1))
691 rankdim = self%setDimension('grid_rank', size(subdimsizes))
692 ! here we set the reference to ncDimension for labelled ncDimension which in fact is a variable
693 ncvar = self%setVariable('grid_center_lon', "f64", [ncdim])
694 call ncvar%setData(centersdim1)
695 call ncvar%setAttribute('units', trim(units))
696 ncvar = self%setVariable('grid_center_lat', "f64", [ncdim])
697 call ncvar%setData(centersdim2)
698 call ncvar%setAttribute('units', trim(units))
699 ncvar = self%setVariable('grid_corner_lon', "f64", [cornerdim, ncdim])
700 call ncvar%setData(cornersdim1)
701 call ncvar%setAttribute('units', trim(units))
702 ncvar = self%setVariable('grid_corner_lat', "f64", [cornerdim, ncdim])
703 call ncvar%setData(cornersdim2)
704 call ncvar%setAttribute('units', trim(units))
705 ncvar = self%setVariable('grid_dims', "i32", [rankdim])
706 call ncvar%setData(subdimsizes)
707 ! set all values to 1 (True) for mask
708 ncvar = self%setVariable('grid_imask', "i32", [ncdim])
709 allocate(imask_data(size(centersdim1)))
710 imask_data = 1_i4
711 call ncvar%setData(imask_data)
712 deallocate(imask_data)
713 call ncvar%setAttribute('units', 'unitless')
714
715 end function set_scrip_dimension
716
717 subroutine set_1d_coordinate_variable(self, name, ncDim, bounds, referenceArg, ncVar)
718 class(NcGroup), intent(in) :: self
719 character(*) , intent(in) :: name
720 type(NcDimension), intent(in) :: ncDim
721 real(dp) , intent(in), dimension(:) :: bounds
722 integer(i4) , intent(in), optional :: referenceArg
723 type(NcVariable), intent(out) :: ncVar
724
725 type(NcVariable) :: ncVarBounds
726 type(NcDimension) :: bndsDim
727 integer(i8) :: dimLength, iBound
728 integer(i4) :: reference
729 character(256) :: dimBoundName
730 real(dp), allocatable, dimension(:, :) :: boundData
731
732 ! init
733 dimlength = size(bounds, kind=i8)
734 reference = 1_i4
735 if (present(referencearg)) then
736 reference = referencearg
737 end if
738 ! here we set the reference to ncDimension for labelled ncDimension which in fact is a variable
739 ncvar = self%setVariable(name, "f64", [ncdim])
740 ! write the data based on the type of reference
741 select case(reference)
742 case(0_i4)
743 ! set the start values
744 call ncvar%setData(bounds(1_i8:dimlength - 1_i8))
745 case(1_i4)
746 ! set the center values
747 call ncvar%setData((bounds(2_i8:dimlength) + bounds(1_i8:dimlength-1_i8)) / 2.0_dp)
748 case(2_4)
749 ! set the end values
750 call ncvar%setData(bounds(2_i8:dimlength))
751 case default
752 write(*,*) "reference id for set_Dimension is ", reference, ", must be 0, 1 or 2."
753 stop 1
754 end select
755
756 ! --- bounds ---
757 ! create dimension name for bounds
758 dimboundname = trim(name) // "_bnds"
759 ! set the attribute
760 call ncvar%setAttribute('bounds', trim(dimboundname))
761 ! set the dimensions used for the bounds array
762 if (self%hasDimension("bnds")) then
763 ! add it to our bounds of ncDimensions for the current array
764 bndsdim = self%getDimension("bnds")
765 else
766 bndsdim = self%setDimension("bnds", 2_i4)
767 end if
768 ncvarbounds = self%setVariable(dimboundname, "f64", [bndsdim, ncdim])
769
770 ! allocate array for data
771 allocate(bounddata(2_i8, dimlength-1_i8))
772 do ibound = 1_i8, dimlength-1_i8
773 bounddata(1_i8, ibound) = bounds(ibound)
774 bounddata(2_i8, ibound) = bounds(ibound + 1_i8)
775 end do
776 call ncvarbounds%setData(bounddata)
777 deallocate(bounddata)
778
779 end subroutine set_1d_coordinate_variable
780
781 function setdimension(self, name, length) result(ncDim)
782 class(NcGroup), intent(in) :: self
783 character(*) , intent(in) :: name
784 integer(i4), intent(in), optional :: length
785
786 type(NcDimension) :: ncDim
787 integer(i4) :: dimLength
788 integer(i4) :: id
789
790 dimlength = nf90_unlimited
791 if (present(length)) then
792 if (length > 0_i4) then
793 dimlength = length
794 end if
795 end if
796
797 call check(nf90_def_dim(self%id, name, dimlength, id), &
798 "Failed to create dimension: " // name)
799
800 ncdim = ncdimension(id, self)
801
802 end function setdimension
803
804 function setcoordinate(self, name, length, bounds, reference, attribute_names, attribute_values, &
805 centersDim1, centersDim2, cornersDim1, cornersDim2, subDimSizes, units) result(ncDim)
806 class(NcGroup), intent(in) :: self
807 character(*) , intent(in) :: name
808 integer(i4), intent(in), optional :: length
809 real(dp) , intent(in), optional, dimension(:) :: bounds
810 integer(i4) , intent(in), optional :: reference
811 character(*) , intent(in), optional, dimension(:) :: attribute_names
812 character(*) , intent(in), optional, dimension(:) :: attribute_values
813 real(dp) , intent(in), optional, dimension(:) :: centersDim1
814 real(dp) , intent(in), optional, dimension(:) :: centersDim2
815 real(dp) , intent(in), optional, dimension(:,:) :: cornersDim1
816 real(dp) , intent(in), optional, dimension(:,:) :: cornersDim2
817 integer(i4) , intent(in), optional, dimension(:) :: subDimSizes
818 character(*), intent(in), optional :: units
819
820 type(NcDimension) :: ncDim
821 type(NcVariable) :: ncVar
822 integer(i4) :: iAtt
823
824 if (present(centersdim1) .and. present(centersdim2) .and. present(cornersdim1) .and. present(cornersdim2) &
825 .and. present(subdimsizes) .and. present(units)) then
826 ncdim = self%set_scrip_dimension(centersdim1, centersdim2, cornersdim1, cornersdim2, subdimsizes, units)
827 else
828 ! set the new ncDimension (integer values and name)
829 ncdim = self%setDimension(name, length)
830
831 if (present(bounds)) then
832 call self%set_1D_coordinate_variable(name, ncdim, bounds, reference, ncvar)
833 ! set attributes
834 ! already set attributes
835 if (present(attribute_names) .and. present(attribute_values)) then
836 do iatt = 1, size(attribute_names)
837 call ncvar%setAttribute(trim(attribute_names(iatt)), &
838 trim(attribute_values(iatt)))
839 end do
840 end if
841 end if
842 end if
843
844 end function setcoordinate
845
846 function hasvariable(self, name)
847 class(NcGroup), intent(in) :: self
848 character(*), intent(in) :: name
849 logical :: hasVariable
850 integer(i4) :: tmpid
851
852 hasvariable = (nf90_inq_varid(self%id, name, tmpid) == nf90_noerr)
853 end function hasvariable
854
855 function hasdimension(self, name)
856 class(NcGroup), intent(in) :: self
857 character(*), intent(in) :: name
858 logical :: hasDimension
859 integer(i4) :: tmpid
860
861 hasdimension = (nf90_inq_dimid(self%id, name, tmpid) == nf90_noerr)
862 end function hasdimension
863
864 function hasgroup(self, name)
865 class(NcGroup), intent(in) :: self
866 character(*), intent(in) :: name
867 logical :: hasGroup
868 integer(i4) :: tmpid
869
870 hasgroup = (nf90_inq_ncid(self%id, name, tmpid) == nf90_noerr)
871 end function hasgroup
872
873 function setvariablewithids(self, name, dtype, dimensions, contiguous, &
874 chunksizes, deflate_level, shuffle, fletcher32, endianness, &
875 cache_size, cache_nelems, cache_preemption)
876 class(NcGroup), intent(in) :: self
877 character(*), intent(in) :: name
878 character(*), intent(in) :: dtype
879 integer(i4), intent(in) :: dimensions(:)
880 logical, intent(in), optional :: contiguous, shuffle, fletcher32
881 integer(i4), intent(in), optional :: endianness, deflate_level, cache_size, &
882 cache_nelems, cache_preemption, chunksizes(:)
883 type(NcVariable) :: setVariableWithIds
884 integer(i4) :: varid, status
885
886 status = nf90_def_var(self%id, name, getdtypefromstring(dtype), dimensions, varid, contiguous, &
887 chunksizes, deflate_level, shuffle, fletcher32, endianness, &
888 cache_size, cache_nelems, cache_preemption)
889 call check(status, "Failed to create variable: " // name)
890 setvariablewithids = ncvariable(varid, self)
891 end function setvariablewithids
892
893 function setvariablewithnames(self, name, dtype, dimensions, contiguous, &
894 chunksizes, deflate_level, shuffle, fletcher32, endianness, &
895 cache_size, cache_nelems, cache_preemption)
896
897 class(NcGroup), intent(in) :: self
898 character(*), intent(in) :: name
899 character(*), intent(in) :: dtype
900 character(*), intent(in) :: dimensions(:)
901 logical, intent(in), optional :: contiguous, shuffle, fletcher32
902 integer(i4), intent(in), optional :: endianness, deflate_level, cache_size, &
903 cache_nelems, cache_preemption, chunksizes(:)
904 type(NcVariable) :: setVariableWithNames
905 type(NcDimension) :: dim
906 integer(i4) :: i, dimids(size(dimensions))
907
908 do i = 1, size(dimensions)
909 dim = self%getDimension(dimensions(i))
910 dimids(i) = dim%id
911 end do
912
913 setvariablewithnames = setvariablewithids(self, name, dtype, dimids, contiguous, &
914 chunksizes, deflate_level, shuffle, fletcher32, endianness, &
915 cache_size, cache_nelems, cache_preemption)
916 end function setvariablewithnames
917
918 function setvariablewithtypes(self, name, dtype, dimensions, contiguous, &
919 chunksizes, deflate_level, shuffle, fletcher32, endianness, &
920 cache_size, cache_nelems, cache_preemption)
921 class(NcGroup), intent(in) :: self
922 character(*), intent(in) :: name
923 character(*), intent(in) :: dtype
924 type(NcDimension), intent(in) :: dimensions(:)
925 logical, intent(in), optional :: contiguous, shuffle, fletcher32
926 integer(i4), intent(in), optional :: endianness, deflate_level, cache_size, &
927 cache_nelems, cache_preemption, chunksizes(:)
928 type(NcVariable) :: setVariableWithTypes
929 type(NcDimension) :: dim
930 integer(i4) :: i, dimids(size(dimensions))
931
932 do i = 1, size(dimensions)
933 dim = dimensions(i)
934 dimids(i) = dim%id
935 end do
936
937 setvariablewithtypes = setvariablewithids(self, name, dtype, dimids, contiguous, &
938 chunksizes, deflate_level, shuffle, fletcher32, endianness, &
939 cache_size, cache_nelems, cache_preemption)
940 end function setvariablewithtypes
941
942 function getdimensionbyid(self, id)
943 class(NcGroup), intent(in) :: self
944 integer(i4) :: id
945 type(NcDimension) :: getDimensionById
946 character(32) :: msg, name
947
948 write(msg, *) id
949 call check(nf90_inquire_dimension(self%id, id, name), &
950 "Could not inquire dimension: " // msg)
951 getdimensionbyid = ncdimension(id, self)
952 end function getdimensionbyid
953
954 function getdimensionbyname(self, name)
955 class(NcGroup), intent(in) :: self
956 character(*) :: name
957 type(NcDimension) :: getDimensionByName
958 integer(i4) :: id
959
960 call check(nf90_inq_dimid(self%id, name, id), &
961 "Could not inquire dimension: " // name)
962 getdimensionbyname = self%getDimensionById(id)
963 end function getdimensionbyname
964
965 function getgroupbyname(self, name)
966 class(NcGroup), intent(in) :: self
967 character(*), intent(in) :: name
968 type(NcGroup) :: getGroupByName
969 integer(i4) :: id
970
971 call check(nf90_inq_ncid(self%id, name, id), &
972 "Could not inquire variable: " // name)
973 getgroupbyname = ncgroup(id)
974 end function getgroupbyname
975
976 function getvariablebyname(self, name)
977 class(NcGroup), intent(in) :: self
978 character(*), intent(in) :: name
979 type(NcVariable) :: getVariableByName
980 integer(i4) :: id
981
982 call check(nf90_inq_varid(self%id, name, id), &
983 "Could not inquire variable: " // name)
984 getvariablebyname = ncvariable(id, self)
985
986 end function getvariablebyname
987
988 function getvariablename(self)
989 class(NcVariable), intent(in) :: self
990 character(len = 256) :: getVariableName
991
992 call check(nf90_inquire_variable(self%parent%id, self%id, name = getvariablename), &
993 "Could not inquire variable name")
994 end function getvariablename
995
996 function getnodimensions(self)
997 class(NcVariable), intent(in) :: self
998 integer(i4) :: getNoDimensions
999
1000 call check(nf90_inquire_variable(self%parent%id, self%id, ndims = getnodimensions), &
1001 "Could not inquire variable: " // self%getName())
1002 end function getnodimensions
1003
1004 function getvariabledimensions(self)
1005 class(NcVariable), intent(in) :: self
1006 type(NcDimension), allocatable :: getVariableDimensions(:)
1007 integer(i4), allocatable :: dimids(:)
1008 integer(i4) :: ii, ndims
1009
1010 ndims = self%getNoDimensions()
1011 allocate(dimids(ndims), getvariabledimensions(ndims))
1012 call check(nf90_inquire_variable(self%parent%id, self%id, dimids = dimids), &
1013 "Could not inquire variable: " // self%getName())
1014
1015 do ii = 1, ndims
1016 getvariabledimensions(ii) = self%parent%getDimension(dimids(ii))
1017 end do
1018 end function getvariabledimensions
1019
1020 function getvariableshape(self)
1021 class(NcVariable), intent(in) :: self
1022 integer(i4), allocatable :: getVariableShape(:)
1023 type(NcDimension), allocatable :: dims(:)
1024 integer(i4) :: ii, ndims
1025
1026 ndims = self%getNoDimensions()
1027 allocate(getvariableshape(ndims), dims(ndims))
1028
1029 dims = self%getDimensions()
1030 do ii = 1, size(dims)
1031 getvariableshape(ii) = dims(ii)%getLength()
1032 end do
1033 end function getvariableshape
1034
1035 function getvariablerank(self)
1036 class(NcVariable), intent(in) :: self
1037 integer(i4) :: getVariableRank
1038
1039 getvariablerank = size(self%getDimensions())
1040 end function getvariablerank
1041
1042 function getvariabledtype(self)
1043 class(NcVariable), intent(in) :: self
1044 integer(i4) :: dtype
1045 character(4) :: getVariableDtype
1046
1047 call check(nf90_inquire_variable(self%parent%id, self%id, xtype = dtype), &
1048 "Could not inquire variable: " // self%getName())
1049 getvariabledtype = getdtypefrominteger(dtype)
1050 end function getvariabledtype
1051
1052 function isunlimitedvariable(self)
1053 class(NcVariable), intent(in) :: self
1054 logical :: isUnlimitedVariable
1055 type(NcDimension), allocatable :: dims(:)
1056 type(NcDimension) :: dim
1057 integer(i4) :: ii
1058
1059 allocate(dims(self%getNoDimensions()))
1060
1061 isunlimitedvariable = .false.
1062 dims = self%getDimensions()
1063
1064 do ii = 1, size(dims)
1065 dim = dims(ii)
1066 if (dim%isUnlimited()) then
1067 isunlimitedvariable = .true.
1068 end if
1069 end do
1070 end function isunlimitedvariable
1071
1072 logical function hasattribute(self, name, xtype, len, attnum)
1073 class(NcAttributable), intent(in) :: self
1074 character(*), intent(in) :: name
1075 integer(i4), intent(out), optional :: xtype
1076 integer(i4), intent(out), optional :: len
1077 integer(i4), intent(out), optional :: attnum
1078 integer(i4) :: status
1079
1080 select type (self)
1081 class is (ncgroup)
1082 status = nf90_inquire_attribute(self%id, nf90_global, name, xtype=xtype, len=len, attnum=attnum)
1083 class is (ncvariable)
1084 status = nf90_inquire_attribute(self%parent%id, self%id, name, xtype=xtype, len=len, attnum=attnum)
1085 end select
1086
1087 hasattribute = (status == nf90_noerr)
1088 end function hasattribute
1089
1090 function getattributenames(self) result(attributeNames)
1091 class(NcAttributable), intent(in) :: self
1092 character(256), dimension(:), allocatable :: attributeNames
1093
1094 integer(i4), parameter :: maxNames = 100_i4
1095 integer(i4) :: nAtts
1096 integer(i4) :: status
1097
1098 ! assume a maximum number of 100 attributes that are checked
1099 allocate(attributenames(maxnames))
1100 natts = 0_i4
1101 do while (natts < maxnames)
1102 select type (self)
1103 class is (ncgroup)
1104 status = nf90_inq_attname(self%id, nf90_global, natts + 1_i4, attributenames(natts + 1_i4))
1105 class is (ncvariable)
1106 status = nf90_inq_attname(self%parent%id, self%id, natts + 1_i4, attributenames(natts + 1_i4))
1107 end select
1108 ! if the status is negative, exit loop, else increase counter
1109 if (status /= nf90_noerr) then
1110 exit
1111 else
1112 natts = natts + 1_i4
1113 end if
1114 end do
1115 ! select only valid names
1116 attributenames = attributenames(1:natts)
1117
1118 end function getattributenames
1119
1120
1121
1122 subroutine setattribute_0d_sp(self, name, data)
1123 class(NcAttributable), intent(in) :: self
1124 character(len=*), intent(in) :: name
1125 real(sp), intent(in) :: data
1126 integer(i4) :: ids(2)
1127
1128 ids = self%getAttributableIds()
1129 call check(nf90_put_att(ids(1), ids(2), name, data), &
1130 "Failed to write attribute: " // name)
1131
1132 end subroutine setattribute_0d_sp
1133
1134 subroutine getattribute_0d_sp(self, name, avalue)
1135 class(NcAttributable), intent(in) :: self
1136 character(len=*), intent(in) :: name
1137 real(sp), intent(out) :: avalue
1138 integer(i4) :: length, ids(2)
1139
1140 ids = self%getAttributableIds()
1141 call check(nf90_inquire_attribute(ids(1), ids(2), name, len = length), &
1142 "Could not inquire attribute " // name)
1143 call check(nf90_get_att(ids(1), ids(2), name, avalue), &
1144 "Could not read attribute " // name)
1145
1146 end subroutine getattribute_0d_sp
1147
1148 subroutine setattribute_1d_sp(self, name, data)
1149 class(NcAttributable), intent(in) :: self
1150 character(len=*), intent(in) :: name
1151 real(sp), intent(in) :: data(:)
1152 integer(i4) :: ids(2)
1153
1154 ids = self%getAttributableIds()
1155 call check(nf90_put_att(ids(1), ids(2), name, data), &
1156 "Failed to write attribute: " // name)
1157
1158 end subroutine setattribute_1d_sp
1159
1160 subroutine getattribute_1d_sp(self, name, avalue)
1161 class(NcAttributable), intent(in) :: self
1162 character(len=*), intent(in) :: name
1163 real(sp), intent(out) :: avalue(:)
1164 integer(i4) :: length, ids(2)
1165
1166 ids = self%getAttributableIds()
1167 call check(nf90_inquire_attribute(ids(1), ids(2), name, len = length), &
1168 "Could not inquire attribute " // name)
1169 call check(nf90_get_att(ids(1), ids(2), name, avalue), &
1170 "Could not read attribute " // name)
1171
1172 end subroutine getattribute_1d_sp
1173
1174 subroutine setattribute_0d_dp(self, name, data)
1175 class(NcAttributable), intent(in) :: self
1176 character(len=*), intent(in) :: name
1177 real(dp), intent(in) :: data
1178 integer(i4) :: ids(2)
1179
1180 ids = self%getAttributableIds()
1181 call check(nf90_put_att(ids(1), ids(2), name, data), &
1182 "Failed to write attribute: " // name)
1183
1184 end subroutine setattribute_0d_dp
1185
1186 subroutine getattribute_0d_dp(self, name, avalue)
1187 class(NcAttributable), intent(in) :: self
1188 character(len=*), intent(in) :: name
1189 real(dp), intent(out) :: avalue
1190 integer(i4) :: length, ids(2)
1191
1192 ids = self%getAttributableIds()
1193 call check(nf90_inquire_attribute(ids(1), ids(2), name, len = length), &
1194 "Could not inquire attribute " // name)
1195 call check(nf90_get_att(ids(1), ids(2), name, avalue), &
1196 "Could not read attribute " // name)
1197
1198 end subroutine getattribute_0d_dp
1199
1200 subroutine setattribute_1d_dp(self, name, data)
1201 class(NcAttributable), intent(in) :: self
1202 character(len=*), intent(in) :: name
1203 real(dp), intent(in) :: data(:)
1204 integer(i4) :: ids(2)
1205
1206 ids = self%getAttributableIds()
1207 call check(nf90_put_att(ids(1), ids(2), name, data), &
1208 "Failed to write attribute: " // name)
1209
1210 end subroutine setattribute_1d_dp
1211
1212 subroutine getattribute_1d_dp(self, name, avalue)
1213 class(NcAttributable), intent(in) :: self
1214 character(len=*), intent(in) :: name
1215 real(dp), intent(out) :: avalue(:)
1216 integer(i4) :: length, ids(2)
1217
1218 ids = self%getAttributableIds()
1219 call check(nf90_inquire_attribute(ids(1), ids(2), name, len = length), &
1220 "Could not inquire attribute " // name)
1221 call check(nf90_get_att(ids(1), ids(2), name, avalue), &
1222 "Could not read attribute " // name)
1223
1224 end subroutine getattribute_1d_dp
1225
1226 subroutine setattribute_0d_i1(self, name, data)
1227 class(NcAttributable), intent(in) :: self
1228 character(len=*), intent(in) :: name
1229 integer(i1), intent(in) :: data
1230 integer(i4) :: ids(2)
1231
1232 ids = self%getAttributableIds()
1233 call check(nf90_put_att(ids(1), ids(2), name, data), &
1234 "Failed to write attribute: " // name)
1235
1236 end subroutine setattribute_0d_i1
1237
1238 subroutine getattribute_0d_i1(self, name, avalue)
1239 class(NcAttributable), intent(in) :: self
1240 character(len=*), intent(in) :: name
1241 integer(i1), intent(out) :: avalue
1242 integer(i4) :: length, ids(2)
1243
1244 ids = self%getAttributableIds()
1245 call check(nf90_inquire_attribute(ids(1), ids(2), name, len = length), &
1246 "Could not inquire attribute " // name)
1247 call check(nf90_get_att(ids(1), ids(2), name, avalue), &
1248 "Could not read attribute " // name)
1249
1250 end subroutine getattribute_0d_i1
1251
1252 subroutine setattribute_1d_i1(self, name, data)
1253 class(NcAttributable), intent(in) :: self
1254 character(len=*), intent(in) :: name
1255 integer(i1), intent(in) :: data(:)
1256 integer(i4) :: ids(2)
1257
1258 ids = self%getAttributableIds()
1259 call check(nf90_put_att(ids(1), ids(2), name, data), &
1260 "Failed to write attribute: " // name)
1261
1262 end subroutine setattribute_1d_i1
1263
1264 subroutine getattribute_1d_i1(self, name, avalue)
1265 class(NcAttributable), intent(in) :: self
1266 character(len=*), intent(in) :: name
1267 integer(i1), intent(out) :: avalue(:)
1268 integer(i4) :: length, ids(2)
1269
1270 ids = self%getAttributableIds()
1271 call check(nf90_inquire_attribute(ids(1), ids(2), name, len = length), &
1272 "Could not inquire attribute " // name)
1273 call check(nf90_get_att(ids(1), ids(2), name, avalue), &
1274 "Could not read attribute " // name)
1275
1276 end subroutine getattribute_1d_i1
1277
1278 subroutine setattribute_0d_i2(self, name, data)
1279 class(NcAttributable), intent(in) :: self
1280 character(len=*), intent(in) :: name
1281 integer(i2), intent(in) :: data
1282 integer(i4) :: ids(2)
1283
1284 ids = self%getAttributableIds()
1285 call check(nf90_put_att(ids(1), ids(2), name, data), &
1286 "Failed to write attribute: " // name)
1287
1288 end subroutine setattribute_0d_i2
1289
1290 subroutine getattribute_0d_i2(self, name, avalue)
1291 class(NcAttributable), intent(in) :: self
1292 character(len=*), intent(in) :: name
1293 integer(i2), intent(out) :: avalue
1294 integer(i4) :: length, ids(2)
1295
1296 ids = self%getAttributableIds()
1297 call check(nf90_inquire_attribute(ids(1), ids(2), name, len = length), &
1298 "Could not inquire attribute " // name)
1299 call check(nf90_get_att(ids(1), ids(2), name, avalue), &
1300 "Could not read attribute " // name)
1301
1302 end subroutine getattribute_0d_i2
1303
1304 subroutine setattribute_1d_i2(self, name, data)
1305 class(NcAttributable), intent(in) :: self
1306 character(len=*), intent(in) :: name
1307 integer(i2), intent(in) :: data(:)
1308 integer(i4) :: ids(2)
1309
1310 ids = self%getAttributableIds()
1311 call check(nf90_put_att(ids(1), ids(2), name, data), &
1312 "Failed to write attribute: " // name)
1313
1314 end subroutine setattribute_1d_i2
1315
1316 subroutine getattribute_1d_i2(self, name, avalue)
1317 class(NcAttributable), intent(in) :: self
1318 character(len=*), intent(in) :: name
1319 integer(i2), intent(out) :: avalue(:)
1320 integer(i4) :: length, ids(2)
1321
1322 ids = self%getAttributableIds()
1323 call check(nf90_inquire_attribute(ids(1), ids(2), name, len = length), &
1324 "Could not inquire attribute " // name)
1325 call check(nf90_get_att(ids(1), ids(2), name, avalue), &
1326 "Could not read attribute " // name)
1327
1328 end subroutine getattribute_1d_i2
1329
1330 subroutine setattribute_0d_i4(self, name, data)
1331 class(NcAttributable), intent(in) :: self
1332 character(len=*), intent(in) :: name
1333 integer(i4), intent(in) :: data
1334 integer(i4) :: ids(2)
1335
1336 ids = self%getAttributableIds()
1337 call check(nf90_put_att(ids(1), ids(2), name, data), &
1338 "Failed to write attribute: " // name)
1339
1340 end subroutine setattribute_0d_i4
1341
1342 subroutine getattribute_0d_i4(self, name, avalue)
1343 class(NcAttributable), intent(in) :: self
1344 character(len=*), intent(in) :: name
1345 integer(i4), intent(out) :: avalue
1346 integer(i4) :: length, ids(2)
1347
1348 ids = self%getAttributableIds()
1349 call check(nf90_inquire_attribute(ids(1), ids(2), name, len = length), &
1350 "Could not inquire attribute " // name)
1351 call check(nf90_get_att(ids(1), ids(2), name, avalue), &
1352 "Could not read attribute " // name)
1353
1354 end subroutine getattribute_0d_i4
1355
1356 subroutine setattribute_1d_i4(self, name, data)
1357 class(NcAttributable), intent(in) :: self
1358 character(len=*), intent(in) :: name
1359 integer(i4), intent(in) :: data(:)
1360 integer(i4) :: ids(2)
1361
1362 ids = self%getAttributableIds()
1363 call check(nf90_put_att(ids(1), ids(2), name, data), &
1364 "Failed to write attribute: " // name)
1365
1366 end subroutine setattribute_1d_i4
1367
1368 subroutine getattribute_1d_i4(self, name, avalue)
1369 class(NcAttributable), intent(in) :: self
1370 character(len=*), intent(in) :: name
1371 integer(i4), intent(out) :: avalue(:)
1372 integer(i4) :: length, ids(2)
1373
1374 ids = self%getAttributableIds()
1375 call check(nf90_inquire_attribute(ids(1), ids(2), name, len = length), &
1376 "Could not inquire attribute " // name)
1377 call check(nf90_get_att(ids(1), ids(2), name, avalue), &
1378 "Could not read attribute " // name)
1379
1380 end subroutine getattribute_1d_i4
1381
1382 subroutine setattribute_0d_i8(self, name, data)
1383 class(NcAttributable), intent(in) :: self
1384 character(len=*), intent(in) :: name
1385 integer(i8), intent(in) :: data
1386 integer(i4) :: ids(2)
1387
1388 ids = self%getAttributableIds()
1389 call check(nf90_put_att(ids(1), ids(2), name, data), &
1390 "Failed to write attribute: " // name)
1391
1392 end subroutine setattribute_0d_i8
1393
1394 subroutine getattribute_0d_i8(self, name, avalue)
1395 class(NcAttributable), intent(in) :: self
1396 character(len=*), intent(in) :: name
1397 integer(i8), intent(out) :: avalue
1398 integer(i4) :: length, ids(2)
1399
1400 ids = self%getAttributableIds()
1401 call check(nf90_inquire_attribute(ids(1), ids(2), name, len = length), &
1402 "Could not inquire attribute " // name)
1403 call check(nf90_get_att(ids(1), ids(2), name, avalue), &
1404 "Could not read attribute " // name)
1405
1406 end subroutine getattribute_0d_i8
1407
1408 subroutine setattribute_1d_i8(self, name, data)
1409 class(NcAttributable), intent(in) :: self
1410 character(len=*), intent(in) :: name
1411 integer(i8), intent(in) :: data(:)
1412 integer(i4) :: ids(2)
1413
1414 ids = self%getAttributableIds()
1415 call check(nf90_put_att(ids(1), ids(2), name, data), &
1416 "Failed to write attribute: " // name)
1417
1418 end subroutine setattribute_1d_i8
1419
1420 subroutine getattribute_1d_i8(self, name, avalue)
1421 class(NcAttributable), intent(in) :: self
1422 character(len=*), intent(in) :: name
1423 integer(i8), intent(out) :: avalue(:)
1424 integer(i4) :: length, ids(2)
1425
1426 ids = self%getAttributableIds()
1427 call check(nf90_inquire_attribute(ids(1), ids(2), name, len = length), &
1428 "Could not inquire attribute " // name)
1429 call check(nf90_get_att(ids(1), ids(2), name, avalue), &
1430 "Could not read attribute " // name)
1431
1432 end subroutine getattribute_1d_i8
1433
1434 subroutine setattribute_0d_char(self, name, data)
1435 class(NcAttributable), intent(in) :: self
1436 character(len=*), intent(in) :: name
1437 character(len=*), intent(in) :: data
1438 integer(i4) :: ids(2)
1439
1440 ids = self%getAttributableIds()
1441 call check(nf90_put_att(ids(1), ids(2), name, data), &
1442 "Failed to write attribute: " // name)
1443
1444 end subroutine setattribute_0d_char
1445
1446 subroutine getattribute_0d_char(self, name, avalue)
1447 class(NcAttributable), intent(in) :: self
1448 character(len=*), intent(in) :: name
1449 character(len=*), intent(out) :: avalue
1450 integer(i4) :: length, ids(2)
1451
1452 ids = self%getAttributableIds()
1453 call check(nf90_inquire_attribute(ids(1), ids(2), name, len = length), &
1454 "Could not inquire attribute " // name)
1455 call check(nf90_get_att(ids(1), ids(2), name, avalue), &
1456 "Could not read attribute " // name)
1457
1458 end subroutine getattribute_0d_char
1459
1460
1461 function getattributableids(self)
1462 class(NcAttributable), intent(in) :: self
1463 integer(i4) :: getAttributableIds(2)
1464 select type(self)
1465 class is (ncgroup)
1466 getattributableids(1) = self%id
1467 getattributableids(2) = nf90_global
1468 class is (ncvariable)
1469 getattributableids(1) = self%parent%id
1470 getattributableids(2) = self%id
1471 end select
1472 end function getattributableids
1473
1474 subroutine renameattribute(self, oldname, newname)
1475 class(NcAttributable), intent(inout) :: self
1476 character(len = *), intent(in) :: oldname, newname
1477 integer(i4) :: ids(2)
1478 ids = self%getAttributableIds()
1479 call check(nf90_rename_att(ids(1), ids(2), oldname, newname), "Failed to rename attribute: " // oldname)
1480 end subroutine renameattribute
1481
1482 subroutine renamevariable(self, name)
1483 class(NcVariable), intent(inout) :: self
1484 character(len = *), intent(in) :: name
1485 call check(nf90_rename_var(self%parent%id, self%id, name), "Failed to rename variable: " // self%getName())
1486 end subroutine renamevariable
1487
1488 subroutine renamedimension(self, name)
1489 class(NcDimension), intent(inout) :: self
1490 character(len = *), intent(in) :: name
1491 call check(nf90_rename_dim(self%parent%id, self%id, name), "Failed to rename dimension: " // self%getName())
1492 end subroutine renamedimension
1493
1494
1495
1496
1497
1498
1499 subroutine getdata_0d_sp(self, data, start, cnt, stride, map, mask)
1500 class(NcVariable), intent(in) :: self
1501 real(sp), intent(out), allocatable :: data
1502 integer(i4), intent(in), optional :: start(:), cnt(:), stride(:), map(:)
1503 logical, intent(out), allocatable, optional :: mask
1504
1505 integer(i4) :: flagMissing
1506 real(sp) :: fillValue, minValue, maxValue
1507 real(sp) :: tmp(1)
1508
1509 call check (nf90_get_var(self%parent%id, self%id, tmp, start, cnt, stride, map), &
1510 "Could not read data from variable: " // trim(self%getName()))
1511 data = tmp(1)
1512 if (present(mask)) then
1513 mask =.true.
1514 call self%getCFAttributes(minvalue, maxvalue, fillvalue, flagmissing)
1515 select case(flagmissing)
1516 case(cf_use_fill_value)
1517 mask = ne(data, fillvalue)
1518 case(cf_use_nan)
1519 mask = .not. ieee_is_nan(data)
1520 case(cf_use_valid_min)
1521 mask = data > minvalue
1522 case(cf_use_valid_max)
1523 mask = data < maxvalue
1524 case(cf_use_valid_range)
1525 mask = (data < maxvalue) .and. (data > minvalue)
1526 end select
1527 end if
1528
1529 end subroutine getdata_0d_sp
1530
1531 subroutine setdata_0d_sp(self, values, start, cnt, stride, map)
1532 class(NcVariable), intent(in) :: self
1533 real(sp), intent(in) :: values
1534 integer(i4), intent(in), optional :: start(:), cnt(:), stride(:), map(:)
1535 call check(nf90_put_var(self%parent%id, self%id, values, start), &
1536 "Failed to write data into variable: " // trim(self%getName()))
1537
1538 end subroutine setdata_0d_sp
1539
1540 subroutine getdata_1d_sp(self, data, start, cnt, stride, map, mask)
1541 class(NcVariable), intent(in) :: self
1542 real(sp), intent(out), allocatable :: data(:)
1543 integer(i4), intent(in), optional :: start(:), cnt(:), stride(:), map(:)
1544 logical, intent(out), allocatable, optional :: mask(:)
1545
1546 integer(i4) :: flagMissing
1547 real(sp) :: fillValue, minValue, maxValue
1548 integer(i4), allocatable :: slcshape(:), datashape(:)
1549
1550 slcshape = self%getSlicingShape(start, cnt, stride)
1551 datashape = getreadshape(slcshape, size(shape(data)))
1552 allocate(data(datashape(1)))
1553 call check (nf90_get_var(self%parent%id, self%id, data, start, cnt, stride, map), &
1554 "Could not read data from variable: " // trim(self%getName()))
1555 if (present(mask)) then
1556 allocate(mask(datashape(1)))
1557 mask =.true.
1558 call self%getCFAttributes(minvalue, maxvalue, fillvalue, flagmissing)
1559 select case(flagmissing)
1560 case(cf_use_fill_value)
1561 mask = ne(data, fillvalue)
1562 case(cf_use_nan)
1563 mask = .not. ieee_is_nan(data)
1564 case(cf_use_valid_min)
1565 mask = data > minvalue
1566 case(cf_use_valid_max)
1567 mask = data < maxvalue
1568 case(cf_use_valid_range)
1569 mask = (data < maxvalue) .and. (data > minvalue)
1570 end select
1571 end if
1572
1573 end subroutine getdata_1d_sp
1574
1575 subroutine setdata_1d_sp(self, values, start, cnt, stride, map)
1576 class(NcVariable), intent(in) :: self
1577 real(sp), intent(in) :: values(:)
1578 integer(i4), intent(in), optional :: start(:), cnt(:), stride(:), map(:)
1579 call check(nf90_put_var(self%parent%id, self%id, values, start, cnt, stride, map), &
1580 "Failed to write data into variable: " // trim(self%getName()))
1581
1582 end subroutine setdata_1d_sp
1583
1584 subroutine getdata_2d_sp(self, data, start, cnt, stride, map, mask)
1585 class(NcVariable), intent(in) :: self
1586 real(sp), intent(out), allocatable :: data(:,:)
1587 integer(i4), intent(in), optional :: start(:), cnt(:), stride(:), map(:)
1588 logical, intent(out), allocatable, optional :: mask(:,:)
1589
1590 integer(i4) :: flagMissing
1591 real(sp) :: fillValue, minValue, maxValue
1592 integer(i4), allocatable :: slcshape(:), datashape(:)
1593
1594 slcshape = self%getSlicingShape(start, cnt, stride)
1595 datashape = getreadshape(slcshape, size(shape(data)))
1596 allocate(data(datashape(1), datashape(2)))
1597 call check (nf90_get_var(self%parent%id, self%id, data, start, cnt, stride, map), &
1598 "Could not read data from variable: " // trim(self%getName()))
1599 if (present(mask)) then
1600 allocate(mask(datashape(1), datashape(2)))
1601 mask =.true.
1602 call self%getCFAttributes(minvalue, maxvalue, fillvalue, flagmissing)
1603 select case(flagmissing)
1604 case(cf_use_fill_value)
1605 mask = ne(data, fillvalue)
1606 case(cf_use_nan)
1607 mask = .not. ieee_is_nan(data)
1608 case(cf_use_valid_min)
1609 mask = data > minvalue
1610 case(cf_use_valid_max)
1611 mask = data < maxvalue
1612 case(cf_use_valid_range)
1613 mask = (data < maxvalue) .and. (data > minvalue)
1614 end select
1615 end if
1616
1617 end subroutine getdata_2d_sp
1618
1619 subroutine setdata_2d_sp(self, values, start, cnt, stride, map)
1620 class(NcVariable), intent(in) :: self
1621 real(sp), intent(in) :: values(:,:)
1622 integer(i4), intent(in), optional :: start(:), cnt(:), stride(:), map(:)
1623 call check(nf90_put_var(self%parent%id, self%id, values, start, cnt, stride, map), &
1624 "Failed to write data into variable: " // trim(self%getName()))
1625
1626 end subroutine setdata_2d_sp
1627
1628 subroutine getdata_3d_sp(self, data, start, cnt, stride, map, mask)
1629 class(NcVariable), intent(in) :: self
1630 real(sp), intent(out), allocatable :: data(:,:,:)
1631 integer(i4), intent(in), optional :: start(:), cnt(:), stride(:), map(:)
1632 logical, intent(out), allocatable, optional :: mask(:,:,:)
1633
1634 integer(i4) :: flagMissing
1635 real(sp) :: fillValue, minValue, maxValue
1636 integer(i4), allocatable :: slcshape(:), datashape(:)
1637
1638 slcshape = self%getSlicingShape(start, cnt, stride)
1639 datashape = getreadshape(slcshape, size(shape(data)))
1640 allocate(data(datashape(1), datashape(2), datashape(3)))
1641 call check (nf90_get_var(self%parent%id, self%id, data, start, cnt, stride, map), &
1642 "Could not read data from variable: " // trim(self%getName()))
1643 if (present(mask)) then
1644 allocate(mask(datashape(1), datashape(2), datashape(3)))
1645 mask =.true.
1646 call self%getCFAttributes(minvalue, maxvalue, fillvalue, flagmissing)
1647 select case(flagmissing)
1648 case(cf_use_fill_value)
1649 mask = ne(data, fillvalue)
1650 case(cf_use_nan)
1651 mask = .not. ieee_is_nan(data)
1652 case(cf_use_valid_min)
1653 mask = data > minvalue
1654 case(cf_use_valid_max)
1655 mask = data < maxvalue
1656 case(cf_use_valid_range)
1657 mask = (data < maxvalue) .and. (data > minvalue)
1658 end select
1659 end if
1660
1661 end subroutine getdata_3d_sp
1662
1663 subroutine setdata_3d_sp(self, values, start, cnt, stride, map)
1664 class(NcVariable), intent(in) :: self
1665 real(sp), intent(in) :: values(:,:,:)
1666 integer(i4), intent(in), optional :: start(:), cnt(:), stride(:), map(:)
1667 call check(nf90_put_var(self%parent%id, self%id, values, start, cnt, stride, map), &
1668 "Failed to write data into variable: " // trim(self%getName()))
1669
1670 end subroutine setdata_3d_sp
1671
1672 subroutine getdata_4d_sp(self, data, start, cnt, stride, map, mask)
1673 class(NcVariable), intent(in) :: self
1674 real(sp), intent(out), allocatable :: data(:,:,:,:)
1675 integer(i4), intent(in), optional :: start(:), cnt(:), stride(:), map(:)
1676 logical, intent(out), allocatable, optional :: mask(:,:,:,:)
1677
1678 integer(i4) :: flagMissing
1679 real(sp) :: fillValue, minValue, maxValue
1680 integer(i4), allocatable :: slcshape(:), datashape(:)
1681
1682 slcshape = self%getSlicingShape(start, cnt, stride)
1683 datashape = getreadshape(slcshape, size(shape(data)))
1684 allocate(data(datashape(1), datashape(2), datashape(3), datashape(4)))
1685 call check (nf90_get_var(self%parent%id, self%id, data, start, cnt, stride, map), &
1686 "Could not read data from variable: " // trim(self%getName()))
1687 if (present(mask)) then
1688 allocate(mask(datashape(1), datashape(2), datashape(3), datashape(4)))
1689 mask =.true.
1690 call self%getCFAttributes(minvalue, maxvalue, fillvalue, flagmissing)
1691 select case(flagmissing)
1692 case(cf_use_fill_value)
1693 mask = ne(data, fillvalue)
1694 case(cf_use_nan)
1695 mask = .not. ieee_is_nan(data)
1696 case(cf_use_valid_min)
1697 mask = data > minvalue
1698 case(cf_use_valid_max)
1699 mask = data < maxvalue
1700 case(cf_use_valid_range)
1701 mask = (data < maxvalue) .and. (data > minvalue)
1702 end select
1703 end if
1704
1705 end subroutine getdata_4d_sp
1706
1707 subroutine setdata_4d_sp(self, values, start, cnt, stride, map)
1708 class(NcVariable), intent(in) :: self
1709 real(sp), intent(in) :: values(:,:,:,:)
1710 integer(i4), intent(in), optional :: start(:), cnt(:), stride(:), map(:)
1711 call check(nf90_put_var(self%parent%id, self%id, values, start, cnt, stride, map), &
1712 "Failed to write data into variable: " // trim(self%getName()))
1713
1714 end subroutine setdata_4d_sp
1715
1716 subroutine getdata_5d_sp(self, data, start, cnt, stride, map, mask)
1717 class(NcVariable), intent(in) :: self
1718 real(sp), intent(out), allocatable :: data(:,:,:,:,:)
1719 integer(i4), intent(in), optional :: start(:), cnt(:), stride(:), map(:)
1720 logical, intent(out), allocatable, optional :: mask(:,:,:,:,:)
1721
1722 integer(i4) :: flagMissing
1723 real(sp) :: fillValue, minValue, maxValue
1724 integer(i4), allocatable :: slcshape(:), datashape(:)
1725
1726 slcshape = self%getSlicingShape(start, cnt, stride)
1727 datashape = getreadshape(slcshape, size(shape(data)))
1728 allocate(data(datashape(1), datashape(2), datashape(3), datashape(4), datashape(5)))
1729 call check (nf90_get_var(self%parent%id, self%id, data, start, cnt, stride, map), &
1730 "Could not read data from variable: " // trim(self%getName()))
1731 if (present(mask)) then
1732 allocate(mask(datashape(1), datashape(2), datashape(3), datashape(4), datashape(5)))
1733 mask =.true.
1734 call self%getCFAttributes(minvalue, maxvalue, fillvalue, flagmissing)
1735 select case(flagmissing)
1736 case(cf_use_fill_value)
1737 mask = ne(data, fillvalue)
1738 case(cf_use_nan)
1739 mask = .not. ieee_is_nan(data)
1740 case(cf_use_valid_min)
1741 mask = data > minvalue
1742 case(cf_use_valid_max)
1743 mask = data < maxvalue
1744 case(cf_use_valid_range)
1745 mask = (data < maxvalue) .and. (data > minvalue)
1746 end select
1747 end if
1748
1749 end subroutine getdata_5d_sp
1750
1751 subroutine setdata_5d_sp(self, values, start, cnt, stride, map)
1752 class(NcVariable), intent(in) :: self
1753 real(sp), intent(in) :: values(:,:,:,:,:)
1754 integer(i4), intent(in), optional :: start(:), cnt(:), stride(:), map(:)
1755 call check(nf90_put_var(self%parent%id, self%id, values, start, cnt, stride, map), &
1756 "Failed to write data into variable: " // trim(self%getName()))
1757
1758 end subroutine setdata_5d_sp
1759
1760 subroutine getdata_6d_sp(self, data, start, cnt, stride, map, mask)
1761 class(NcVariable), intent(in) :: self
1762 real(sp), intent(out), allocatable :: data(:,:,:,:,:,:)
1763 integer(i4), intent(in), optional :: start(:), cnt(:), stride(:), map(:)
1764 logical, intent(out), allocatable, optional :: mask(:,:,:,:,:,:)
1765
1766 integer(i4) :: flagMissing
1767 real(sp) :: fillValue, minValue, maxValue
1768 integer(i4), allocatable :: slcshape(:), datashape(:)
1769
1770 slcshape = self%getSlicingShape(start, cnt, stride)
1771 datashape = getreadshape(slcshape, size(shape(data)))
1772 allocate(data(datashape(1), datashape(2), datashape(3), datashape(4), datashape(5), datashape(6)))
1773 call check (nf90_get_var(self%parent%id, self%id, data, start, cnt, stride, map), &
1774 "Could not read data from variable: " // trim(self%getName()))
1775 if (present(mask)) then
1776 allocate(mask(datashape(1), datashape(2), datashape(3), datashape(4), datashape(5), datashape(6)))
1777 mask =.true.
1778 call self%getCFAttributes(minvalue, maxvalue, fillvalue, flagmissing)
1779 select case(flagmissing)
1780 case(cf_use_fill_value)
1781 mask = ne(data, fillvalue)
1782 case(cf_use_nan)
1783 mask = .not. ieee_is_nan(data)
1784 case(cf_use_valid_min)
1785 mask = data > minvalue
1786 case(cf_use_valid_max)
1787 mask = data < maxvalue
1788 case(cf_use_valid_range)
1789 mask = (data < maxvalue) .and. (data > minvalue)
1790 end select
1791 end if
1792
1793 end subroutine getdata_6d_sp
1794
1795 subroutine setdata_6d_sp(self, values, start, cnt, stride, map)
1796 class(NcVariable), intent(in) :: self
1797 real(sp), intent(in) :: values(:,:,:,:,:,:)
1798 integer(i4), intent(in), optional :: start(:), cnt(:), stride(:), map(:)
1799 call check(nf90_put_var(self%parent%id, self%id, values, start, cnt, stride, map), &
1800 "Failed to write data into variable: " // trim(self%getName()))
1801
1802 end subroutine setdata_6d_sp
1803
1804 subroutine getvariablefillvalue_sp(self, fvalue)
1805 class(NcVariable), intent(in) :: self
1806 real(sp), intent(out) :: fvalue
1807
1808 if (self%hasAttribute(cf_fill_value)) then
1809 call self%getAttribute(cf_fill_value, fvalue)
1810 else
1811 fvalue = nf90_fill_float
1812 end if
1813
1814 end subroutine getvariablefillvalue_sp
1815
1816 subroutine getcfattributes_sp(self, minValue, maxValue, fillValue, flagMissing)
1817 class(NcVariable), intent(in) :: self
1818 real(sp), intent(out) :: minValue, maxValue, fillValue
1819 integer(i4), intent(out) :: flagMissing
1820
1821 real(sp) :: valid_range(2)
1822
1823 flagmissing = cf_use_fill_value
1824 call self%getFillValue(fillvalue)
1825 if (ieee_is_nan(fillvalue)) then
1826 flagmissing = cf_use_nan
1827 end if
1828 if (self%hasAttribute(cf_valid_range)) then
1829 flagmissing = cf_use_valid_range
1830 call self%getAttribute(cf_valid_range, valid_range)
1831 minvalue = valid_range(1)
1832 maxvalue = valid_range(2)
1833 else if (self%hasAttribute(cf_valid_min)) then
1834 flagmissing = cf_use_valid_min
1835 call self%getAttribute(cf_valid_min, minvalue)
1836 else if (self%hasAttribute(cf_valid_max)) then
1837 flagmissing = cf_use_valid_max
1838 call self%getAttribute(cf_valid_max, maxvalue)
1839 end if
1840
1841 end subroutine getcfattributes_sp
1842
1843 subroutine setvariablefillvalue_sp(self, fvalue)
1844 class(NcVariable), intent(inout) :: self
1845 real(sp), intent(in) :: fvalue
1846
1847 if (.not. self%hasAttribute(cf_fill_value)) then
1848 call self%setAttribute(cf_fill_value, fvalue)
1849 end if
1850
1851 end subroutine setvariablefillvalue_sp
1852
1853 subroutine getdata_0d_dp(self, data, start, cnt, stride, map, mask)
1854 class(NcVariable), intent(in) :: self
1855 real(dp), intent(out), allocatable :: data
1856 integer(i4), intent(in), optional :: start(:), cnt(:), stride(:), map(:)
1857 logical, intent(out), allocatable, optional :: mask
1858
1859 integer(i4) :: flagMissing
1860 real(dp) :: fillValue, minValue, maxValue
1861 real(dp) :: tmp(1)
1862
1863 call check (nf90_get_var(self%parent%id, self%id, tmp, start, cnt, stride, map), &
1864 "Could not read data from variable: " // trim(self%getName()))
1865 data = tmp(1)
1866 if (present(mask)) then
1867 mask =.true.
1868 call self%getCFAttributes(minvalue, maxvalue, fillvalue, flagmissing)
1869 select case(flagmissing)
1870 case(cf_use_fill_value)
1871 mask = ne(data, fillvalue)
1872 case(cf_use_nan)
1873 mask = .not. ieee_is_nan(data)
1874 case(cf_use_valid_min)
1875 mask = data > minvalue
1876 case(cf_use_valid_max)
1877 mask = data < maxvalue
1878 case(cf_use_valid_range)
1879 mask = (data < maxvalue) .and. (data > minvalue)
1880 end select
1881 end if
1882
1883 end subroutine getdata_0d_dp
1884
1885 subroutine setdata_0d_dp(self, values, start, cnt, stride, map)
1886 class(NcVariable), intent(in) :: self
1887 real(dp), intent(in) :: values
1888 integer(i4), intent(in), optional :: start(:), cnt(:), stride(:), map(:)
1889 call check(nf90_put_var(self%parent%id, self%id, values, start), &
1890 "Failed to write data into variable: " // trim(self%getName()))
1891
1892 end subroutine setdata_0d_dp
1893
1894 subroutine getdata_1d_dp(self, data, start, cnt, stride, map, mask)
1895 class(NcVariable), intent(in) :: self
1896 real(dp), intent(out), allocatable :: data(:)
1897 integer(i4), intent(in), optional :: start(:), cnt(:), stride(:), map(:)
1898 logical, intent(out), allocatable, optional :: mask(:)
1899
1900 integer(i4) :: flagMissing
1901 real(dp) :: fillValue, minValue, maxValue
1902 integer(i4), allocatable :: slcshape(:), datashape(:)
1903
1904 slcshape = self%getSlicingShape(start, cnt, stride)
1905 datashape = getreadshape(slcshape, size(shape(data)))
1906 allocate(data(datashape(1)))
1907 call check (nf90_get_var(self%parent%id, self%id, data, start, cnt, stride, map), &
1908 "Could not read data from variable: " // trim(self%getName()))
1909 if (present(mask)) then
1910 allocate(mask(datashape(1)))
1911 mask =.true.
1912 call self%getCFAttributes(minvalue, maxvalue, fillvalue, flagmissing)
1913 select case(flagmissing)
1914 case(cf_use_fill_value)
1915 mask = ne(data, fillvalue)
1916 case(cf_use_nan)
1917 mask = .not. ieee_is_nan(data)
1918 case(cf_use_valid_min)
1919 mask = data > minvalue
1920 case(cf_use_valid_max)
1921 mask = data < maxvalue
1922 case(cf_use_valid_range)
1923 mask = (data < maxvalue) .and. (data > minvalue)
1924 end select
1925 end if
1926
1927 end subroutine getdata_1d_dp
1928
1929 subroutine setdata_1d_dp(self, values, start, cnt, stride, map)
1930 class(NcVariable), intent(in) :: self
1931 real(dp), intent(in) :: values(:)
1932 integer(i4), intent(in), optional :: start(:), cnt(:), stride(:), map(:)
1933 call check(nf90_put_var(self%parent%id, self%id, values, start, cnt, stride, map), &
1934 "Failed to write data into variable: " // trim(self%getName()))
1935
1936 end subroutine setdata_1d_dp
1937
1938 subroutine getdata_2d_dp(self, data, start, cnt, stride, map, mask)
1939 class(NcVariable), intent(in) :: self
1940 real(dp), intent(out), allocatable :: data(:,:)
1941 integer(i4), intent(in), optional :: start(:), cnt(:), stride(:), map(:)
1942 logical, intent(out), allocatable, optional :: mask(:,:)
1943
1944 integer(i4) :: flagMissing
1945 real(dp) :: fillValue, minValue, maxValue
1946 integer(i4), allocatable :: slcshape(:), datashape(:)
1947
1948 slcshape = self%getSlicingShape(start, cnt, stride)
1949 datashape = getreadshape(slcshape, size(shape(data)))
1950 allocate(data(datashape(1), datashape(2)))
1951 call check (nf90_get_var(self%parent%id, self%id, data, start, cnt, stride, map), &
1952 "Could not read data from variable: " // trim(self%getName()))
1953 if (present(mask)) then
1954 allocate(mask(datashape(1), datashape(2)))
1955 mask =.true.
1956 call self%getCFAttributes(minvalue, maxvalue, fillvalue, flagmissing)
1957 select case(flagmissing)
1958 case(cf_use_fill_value)
1959 mask = ne(data, fillvalue)
1960 case(cf_use_nan)
1961 mask = .not. ieee_is_nan(data)
1962 case(cf_use_valid_min)
1963 mask = data > minvalue
1964 case(cf_use_valid_max)
1965 mask = data < maxvalue
1966 case(cf_use_valid_range)
1967 mask = (data < maxvalue) .and. (data > minvalue)
1968 end select
1969 end if
1970
1971 end subroutine getdata_2d_dp
1972
1973 subroutine setdata_2d_dp(self, values, start, cnt, stride, map)
1974 class(NcVariable), intent(in) :: self
1975 real(dp), intent(in) :: values(:,:)
1976 integer(i4), intent(in), optional :: start(:), cnt(:), stride(:), map(:)
1977 call check(nf90_put_var(self%parent%id, self%id, values, start, cnt, stride, map), &
1978 "Failed to write data into variable: " // trim(self%getName()))
1979
1980 end subroutine setdata_2d_dp
1981
1982 subroutine getdata_3d_dp(self, data, start, cnt, stride, map, mask)
1983 class(NcVariable), intent(in) :: self
1984 real(dp), intent(out), allocatable :: data(:,:,:)
1985 integer(i4), intent(in), optional :: start(:), cnt(:), stride(:), map(:)
1986 logical, intent(out), allocatable, optional :: mask(:,:,:)
1987
1988 integer(i4) :: flagMissing
1989 real(dp) :: fillValue, minValue, maxValue
1990 integer(i4), allocatable :: slcshape(:), datashape(:)
1991
1992 slcshape = self%getSlicingShape(start, cnt, stride)
1993 datashape = getreadshape(slcshape, size(shape(data)))
1994 allocate(data(datashape(1), datashape(2), datashape(3)))
1995 call check (nf90_get_var(self%parent%id, self%id, data, start, cnt, stride, map), &
1996 "Could not read data from variable: " // trim(self%getName()))
1997 if (present(mask)) then
1998 allocate(mask(datashape(1), datashape(2), datashape(3)))
1999 mask =.true.
2000 call self%getCFAttributes(minvalue, maxvalue, fillvalue, flagmissing)
2001 select case(flagmissing)
2002 case(cf_use_fill_value)
2003 mask = ne(data, fillvalue)
2004 case(cf_use_nan)
2005 mask = .not. ieee_is_nan(data)
2006 case(cf_use_valid_min)
2007 mask = data > minvalue
2008 case(cf_use_valid_max)
2009 mask = data < maxvalue
2010 case(cf_use_valid_range)
2011 mask = (data < maxvalue) .and. (data > minvalue)
2012 end select
2013 end if
2014
2015 end subroutine getdata_3d_dp
2016
2017 subroutine setdata_3d_dp(self, values, start, cnt, stride, map)
2018 class(NcVariable), intent(in) :: self
2019 real(dp), intent(in) :: values(:,:,:)
2020 integer(i4), intent(in), optional :: start(:), cnt(:), stride(:), map(:)
2021 call check(nf90_put_var(self%parent%id, self%id, values, start, cnt, stride, map), &
2022 "Failed to write data into variable: " // trim(self%getName()))
2023
2024 end subroutine setdata_3d_dp
2025
2026 subroutine getdata_4d_dp(self, data, start, cnt, stride, map, mask)
2027 class(NcVariable), intent(in) :: self
2028 real(dp), intent(out), allocatable :: data(:,:,:,:)
2029 integer(i4), intent(in), optional :: start(:), cnt(:), stride(:), map(:)
2030 logical, intent(out), allocatable, optional :: mask(:,:,:,:)
2031
2032 integer(i4) :: flagMissing
2033 real(dp) :: fillValue, minValue, maxValue
2034 integer(i4), allocatable :: slcshape(:), datashape(:)
2035
2036 slcshape = self%getSlicingShape(start, cnt, stride)
2037 datashape = getreadshape(slcshape, size(shape(data)))
2038 allocate(data(datashape(1), datashape(2), datashape(3), datashape(4)))
2039 call check (nf90_get_var(self%parent%id, self%id, data, start, cnt, stride, map), &
2040 "Could not read data from variable: " // trim(self%getName()))
2041 if (present(mask)) then
2042 allocate(mask(datashape(1), datashape(2), datashape(3), datashape(4)))
2043 mask =.true.
2044 call self%getCFAttributes(minvalue, maxvalue, fillvalue, flagmissing)
2045 select case(flagmissing)
2046 case(cf_use_fill_value)
2047 mask = ne(data, fillvalue)
2048 case(cf_use_nan)
2049 mask = .not. ieee_is_nan(data)
2050 case(cf_use_valid_min)
2051 mask = data > minvalue
2052 case(cf_use_valid_max)
2053 mask = data < maxvalue
2054 case(cf_use_valid_range)
2055 mask = (data < maxvalue) .and. (data > minvalue)
2056 end select
2057 end if
2058
2059 end subroutine getdata_4d_dp
2060
2061 subroutine setdata_4d_dp(self, values, start, cnt, stride, map)
2062 class(NcVariable), intent(in) :: self
2063 real(dp), intent(in) :: values(:,:,:,:)
2064 integer(i4), intent(in), optional :: start(:), cnt(:), stride(:), map(:)
2065 call check(nf90_put_var(self%parent%id, self%id, values, start, cnt, stride, map), &
2066 "Failed to write data into variable: " // trim(self%getName()))
2067
2068 end subroutine setdata_4d_dp
2069
2070 subroutine getdata_5d_dp(self, data, start, cnt, stride, map, mask)
2071 class(NcVariable), intent(in) :: self
2072 real(dp), intent(out), allocatable :: data(:,:,:,:,:)
2073 integer(i4), intent(in), optional :: start(:), cnt(:), stride(:), map(:)
2074 logical, intent(out), allocatable, optional :: mask(:,:,:,:,:)
2075
2076 integer(i4) :: flagMissing
2077 real(dp) :: fillValue, minValue, maxValue
2078 integer(i4), allocatable :: slcshape(:), datashape(:)
2079
2080 slcshape = self%getSlicingShape(start, cnt, stride)
2081 datashape = getreadshape(slcshape, size(shape(data)))
2082 allocate(data(datashape(1), datashape(2), datashape(3), datashape(4), datashape(5)))
2083 call check (nf90_get_var(self%parent%id, self%id, data, start, cnt, stride, map), &
2084 "Could not read data from variable: " // trim(self%getName()))
2085 if (present(mask)) then
2086 allocate(mask(datashape(1), datashape(2), datashape(3), datashape(4), datashape(5)))
2087 mask =.true.
2088 call self%getCFAttributes(minvalue, maxvalue, fillvalue, flagmissing)
2089 select case(flagmissing)
2090 case(cf_use_fill_value)
2091 mask = ne(data, fillvalue)
2092 case(cf_use_nan)
2093 mask = .not. ieee_is_nan(data)
2094 case(cf_use_valid_min)
2095 mask = data > minvalue
2096 case(cf_use_valid_max)
2097 mask = data < maxvalue
2098 case(cf_use_valid_range)
2099 mask = (data < maxvalue) .and. (data > minvalue)
2100 end select
2101 end if
2102
2103 end subroutine getdata_5d_dp
2104
2105 subroutine setdata_5d_dp(self, values, start, cnt, stride, map)
2106 class(NcVariable), intent(in) :: self
2107 real(dp), intent(in) :: values(:,:,:,:,:)
2108 integer(i4), intent(in), optional :: start(:), cnt(:), stride(:), map(:)
2109 call check(nf90_put_var(self%parent%id, self%id, values, start, cnt, stride, map), &
2110 "Failed to write data into variable: " // trim(self%getName()))
2111
2112 end subroutine setdata_5d_dp
2113
2114 subroutine getdata_6d_dp(self, data, start, cnt, stride, map, mask)
2115 class(NcVariable), intent(in) :: self
2116 real(dp), intent(out), allocatable :: data(:,:,:,:,:,:)
2117 integer(i4), intent(in), optional :: start(:), cnt(:), stride(:), map(:)
2118 logical, intent(out), allocatable, optional :: mask(:,:,:,:,:,:)
2119
2120 integer(i4) :: flagMissing
2121 real(dp) :: fillValue, minValue, maxValue
2122 integer(i4), allocatable :: slcshape(:), datashape(:)
2123
2124 slcshape = self%getSlicingShape(start, cnt, stride)
2125 datashape = getreadshape(slcshape, size(shape(data)))
2126 allocate(data(datashape(1), datashape(2), datashape(3), datashape(4), datashape(5), datashape(6)))
2127 call check (nf90_get_var(self%parent%id, self%id, data, start, cnt, stride, map), &
2128 "Could not read data from variable: " // trim(self%getName()))
2129 if (present(mask)) then
2130 allocate(mask(datashape(1), datashape(2), datashape(3), datashape(4), datashape(5), datashape(6)))
2131 mask =.true.
2132 call self%getCFAttributes(minvalue, maxvalue, fillvalue, flagmissing)
2133 select case(flagmissing)
2134 case(cf_use_fill_value)
2135 mask = ne(data, fillvalue)
2136 case(cf_use_nan)
2137 mask = .not. ieee_is_nan(data)
2138 case(cf_use_valid_min)
2139 mask = data > minvalue
2140 case(cf_use_valid_max)
2141 mask = data < maxvalue
2142 case(cf_use_valid_range)
2143 mask = (data < maxvalue) .and. (data > minvalue)
2144 end select
2145 end if
2146
2147 end subroutine getdata_6d_dp
2148
2149 subroutine setdata_6d_dp(self, values, start, cnt, stride, map)
2150 class(NcVariable), intent(in) :: self
2151 real(dp), intent(in) :: values(:,:,:,:,:,:)
2152 integer(i4), intent(in), optional :: start(:), cnt(:), stride(:), map(:)
2153 call check(nf90_put_var(self%parent%id, self%id, values, start, cnt, stride, map), &
2154 "Failed to write data into variable: " // trim(self%getName()))
2155
2156 end subroutine setdata_6d_dp
2157
2158 subroutine getvariablefillvalue_dp(self, fvalue)
2159 class(NcVariable), intent(in) :: self
2160 real(dp), intent(out) :: fvalue
2161
2162 if (self%hasAttribute(cf_fill_value)) then
2163 call self%getAttribute(cf_fill_value, fvalue)
2164 else
2165 fvalue = nf90_fill_double
2166 end if
2167
2168 end subroutine getvariablefillvalue_dp
2169
2170 subroutine getcfattributes_dp(self, minValue, maxValue, fillValue, flagMissing)
2171 class(NcVariable), intent(in) :: self
2172 real(dp), intent(out) :: minValue, maxValue, fillValue
2173 integer(i4), intent(out) :: flagMissing
2174
2175 real(dp) :: valid_range(2)
2176
2177 flagmissing = cf_use_fill_value
2178 call self%getFillValue(fillvalue)
2179 if (ieee_is_nan(fillvalue)) then
2180 flagmissing = cf_use_nan
2181 end if
2182 if (self%hasAttribute(cf_valid_range)) then
2183 flagmissing = cf_use_valid_range
2184 call self%getAttribute(cf_valid_range, valid_range)
2185 minvalue = valid_range(1)
2186 maxvalue = valid_range(2)
2187 else if (self%hasAttribute(cf_valid_min)) then
2188 flagmissing = cf_use_valid_min
2189 call self%getAttribute(cf_valid_min, minvalue)
2190 else if (self%hasAttribute(cf_valid_max)) then
2191 flagmissing = cf_use_valid_max
2192 call self%getAttribute(cf_valid_max, maxvalue)
2193 end if
2194
2195 end subroutine getcfattributes_dp
2196
2197 subroutine setvariablefillvalue_dp(self, fvalue)
2198 class(NcVariable), intent(inout) :: self
2199 real(dp), intent(in) :: fvalue
2200
2201 if (.not. self%hasAttribute(cf_fill_value)) then
2202 call self%setAttribute(cf_fill_value, fvalue)
2203 end if
2204
2205 end subroutine setvariablefillvalue_dp
2206
2207 subroutine getdata_0d_i1(self, data, start, cnt, stride, map, mask)
2208 class(NcVariable), intent(in) :: self
2209 integer(i1), intent(out), allocatable :: data
2210 integer(i4), intent(in), optional :: start(:), cnt(:), stride(:), map(:)
2211 logical, intent(out), allocatable, optional :: mask
2212
2213 integer(i4) :: flagMissing
2214 integer(i1) :: fillValue, minValue, maxValue
2215 integer(i1) :: tmp(1)
2216
2217 call check (nf90_get_var(self%parent%id, self%id, tmp, start, cnt, stride, map), &
2218 "Could not read data from variable: " // trim(self%getName()))
2219 data = tmp(1)
2220 if (present(mask)) then
2221 mask =.true.
2222 call self%getCFAttributes(minvalue, maxvalue, fillvalue, flagmissing)
2223 select case(flagmissing)
2224 case(cf_use_fill_value)
2225 mask = .not. (data == fillvalue)
2226 case(cf_use_valid_min)
2227 mask = data >= minvalue
2228 case(cf_use_valid_max)
2229 mask = data <= maxvalue
2230 case(cf_use_valid_range)
2231 mask = (data <= maxvalue) .and. (data >= minvalue)
2232 end select
2233 end if
2234
2235 end subroutine getdata_0d_i1
2236
2237 subroutine setdata_0d_i1(self, values, start, cnt, stride, map)
2238 class(NcVariable), intent(in) :: self
2239 integer(i1), intent(in) :: values
2240 integer(i4), intent(in), optional :: start(:), cnt(:), stride(:), map(:)
2241 call check(nf90_put_var(self%parent%id, self%id, values, start), &
2242 "Failed to write data into variable: " // trim(self%getName()))
2243
2244 end subroutine setdata_0d_i1
2245
2246 subroutine getdata_1d_i1(self, data, start, cnt, stride, map, mask)
2247 class(NcVariable), intent(in) :: self
2248 integer(i1), intent(out), allocatable :: data(:)
2249 integer(i4), intent(in), optional :: start(:), cnt(:), stride(:), map(:)
2250 logical, intent(out), allocatable, optional :: mask(:)
2251
2252 integer(i4) :: flagMissing
2253 integer(i1) :: fillValue, minValue, maxValue
2254 integer(i4), allocatable :: slcshape(:), datashape(:)
2255
2256 slcshape = self%getSlicingShape(start, cnt, stride)
2257 datashape = getreadshape(slcshape, size(shape(data)))
2258 allocate(data(datashape(1)))
2259 call check (nf90_get_var(self%parent%id, self%id, data, start, cnt, stride, map), &
2260 "Could not read data from variable: " // trim(self%getName()))
2261 if (present(mask)) then
2262 allocate(mask(datashape(1)))
2263 mask =.true.
2264 call self%getCFAttributes(minvalue, maxvalue, fillvalue, flagmissing)
2265 select case(flagmissing)
2266 case(cf_use_fill_value)
2267 mask = .not. (data == fillvalue)
2268 case(cf_use_valid_min)
2269 mask = data >= minvalue
2270 case(cf_use_valid_max)
2271 mask = data <= maxvalue
2272 case(cf_use_valid_range)
2273 mask = (data <= maxvalue) .and. (data >= minvalue)
2274 end select
2275 end if
2276
2277 end subroutine getdata_1d_i1
2278
2279 subroutine setdata_1d_i1(self, values, start, cnt, stride, map)
2280 class(NcVariable), intent(in) :: self
2281 integer(i1), intent(in) :: values(:)
2282 integer(i4), intent(in), optional :: start(:), cnt(:), stride(:), map(:)
2283 call check(nf90_put_var(self%parent%id, self%id, values, start, cnt, stride, map), &
2284 "Failed to write data into variable: " // trim(self%getName()))
2285
2286 end subroutine setdata_1d_i1
2287
2288 subroutine getdata_2d_i1(self, data, start, cnt, stride, map, mask)
2289 class(NcVariable), intent(in) :: self
2290 integer(i1), intent(out), allocatable :: data(:,:)
2291 integer(i4), intent(in), optional :: start(:), cnt(:), stride(:), map(:)
2292 logical, intent(out), allocatable, optional :: mask(:,:)
2293
2294 integer(i4) :: flagMissing
2295 integer(i1) :: fillValue, minValue, maxValue
2296 integer(i4), allocatable :: slcshape(:), datashape(:)
2297
2298 slcshape = self%getSlicingShape(start, cnt, stride)
2299 datashape = getreadshape(slcshape, size(shape(data)))
2300 allocate(data(datashape(1), datashape(2)))
2301 call check (nf90_get_var(self%parent%id, self%id, data, start, cnt, stride, map), &
2302 "Could not read data from variable: " // trim(self%getName()))
2303 if (present(mask)) then
2304 allocate(mask(datashape(1), datashape(2)))
2305 mask =.true.
2306 call self%getCFAttributes(minvalue, maxvalue, fillvalue, flagmissing)
2307 select case(flagmissing)
2308 case(cf_use_fill_value)
2309 mask = .not. (data == fillvalue)
2310 case(cf_use_valid_min)
2311 mask = data >= minvalue
2312 case(cf_use_valid_max)
2313 mask = data <= maxvalue
2314 case(cf_use_valid_range)
2315 mask = (data <= maxvalue) .and. (data >= minvalue)
2316 end select
2317 end if
2318
2319 end subroutine getdata_2d_i1
2320
2321 subroutine setdata_2d_i1(self, values, start, cnt, stride, map)
2322 class(NcVariable), intent(in) :: self
2323 integer(i1), intent(in) :: values(:,:)
2324 integer(i4), intent(in), optional :: start(:), cnt(:), stride(:), map(:)
2325 call check(nf90_put_var(self%parent%id, self%id, values, start, cnt, stride, map), &
2326 "Failed to write data into variable: " // trim(self%getName()))
2327
2328 end subroutine setdata_2d_i1
2329
2330 subroutine getdata_3d_i1(self, data, start, cnt, stride, map, mask)
2331 class(NcVariable), intent(in) :: self
2332 integer(i1), intent(out), allocatable :: data(:,:,:)
2333 integer(i4), intent(in), optional :: start(:), cnt(:), stride(:), map(:)
2334 logical, intent(out), allocatable, optional :: mask(:,:,:)
2335
2336 integer(i4) :: flagMissing
2337 integer(i1) :: fillValue, minValue, maxValue
2338 integer(i4), allocatable :: slcshape(:), datashape(:)
2339
2340 slcshape = self%getSlicingShape(start, cnt, stride)
2341 datashape = getreadshape(slcshape, size(shape(data)))
2342 allocate(data(datashape(1), datashape(2), datashape(3)))
2343 call check (nf90_get_var(self%parent%id, self%id, data, start, cnt, stride, map), &
2344 "Could not read data from variable: " // trim(self%getName()))
2345 if (present(mask)) then
2346 allocate(mask(datashape(1), datashape(2), datashape(3)))
2347 mask =.true.
2348 call self%getCFAttributes(minvalue, maxvalue, fillvalue, flagmissing)
2349 select case(flagmissing)
2350 case(cf_use_fill_value)
2351 mask = .not. (data == fillvalue)
2352 case(cf_use_valid_min)
2353 mask = data >= minvalue
2354 case(cf_use_valid_max)
2355 mask = data <= maxvalue
2356 case(cf_use_valid_range)
2357 mask = (data <= maxvalue) .and. (data >= minvalue)
2358 end select
2359 end if
2360
2361 end subroutine getdata_3d_i1
2362
2363 subroutine setdata_3d_i1(self, values, start, cnt, stride, map)
2364 class(NcVariable), intent(in) :: self
2365 integer(i1), intent(in) :: values(:,:,:)
2366 integer(i4), intent(in), optional :: start(:), cnt(:), stride(:), map(:)
2367 call check(nf90_put_var(self%parent%id, self%id, values, start, cnt, stride, map), &
2368 "Failed to write data into variable: " // trim(self%getName()))
2369
2370 end subroutine setdata_3d_i1
2371
2372 subroutine getdata_4d_i1(self, data, start, cnt, stride, map, mask)
2373 class(NcVariable), intent(in) :: self
2374 integer(i1), intent(out), allocatable :: data(:,:,:,:)
2375 integer(i4), intent(in), optional :: start(:), cnt(:), stride(:), map(:)
2376 logical, intent(out), allocatable, optional :: mask(:,:,:,:)
2377
2378 integer(i4) :: flagMissing
2379 integer(i1) :: fillValue, minValue, maxValue
2380 integer(i4), allocatable :: slcshape(:), datashape(:)
2381
2382 slcshape = self%getSlicingShape(start, cnt, stride)
2383 datashape = getreadshape(slcshape, size(shape(data)))
2384 allocate(data(datashape(1), datashape(2), datashape(3), datashape(4)))
2385 call check (nf90_get_var(self%parent%id, self%id, data, start, cnt, stride, map), &
2386 "Could not read data from variable: " // trim(self%getName()))
2387 if (present(mask)) then
2388 allocate(mask(datashape(1), datashape(2), datashape(3), datashape(4)))
2389 mask =.true.
2390 call self%getCFAttributes(minvalue, maxvalue, fillvalue, flagmissing)
2391 select case(flagmissing)
2392 case(cf_use_fill_value)
2393 mask = .not. (data == fillvalue)
2394 case(cf_use_valid_min)
2395 mask = data >= minvalue
2396 case(cf_use_valid_max)
2397 mask = data <= maxvalue
2398 case(cf_use_valid_range)
2399 mask = (data <= maxvalue) .and. (data >= minvalue)
2400 end select
2401 end if
2402
2403 end subroutine getdata_4d_i1
2404
2405 subroutine setdata_4d_i1(self, values, start, cnt, stride, map)
2406 class(NcVariable), intent(in) :: self
2407 integer(i1), intent(in) :: values(:,:,:,:)
2408 integer(i4), intent(in), optional :: start(:), cnt(:), stride(:), map(:)
2409 call check(nf90_put_var(self%parent%id, self%id, values, start, cnt, stride, map), &
2410 "Failed to write data into variable: " // trim(self%getName()))
2411
2412 end subroutine setdata_4d_i1
2413
2414 subroutine getdata_5d_i1(self, data, start, cnt, stride, map, mask)
2415 class(NcVariable), intent(in) :: self
2416 integer(i1), intent(out), allocatable :: data(:,:,:,:,:)
2417 integer(i4), intent(in), optional :: start(:), cnt(:), stride(:), map(:)
2418 logical, intent(out), allocatable, optional :: mask(:,:,:,:,:)
2419
2420 integer(i4) :: flagMissing
2421 integer(i1) :: fillValue, minValue, maxValue
2422 integer(i4), allocatable :: slcshape(:), datashape(:)
2423
2424 slcshape = self%getSlicingShape(start, cnt, stride)
2425 datashape = getreadshape(slcshape, size(shape(data)))
2426 allocate(data(datashape(1), datashape(2), datashape(3), datashape(4), datashape(5)))
2427 call check (nf90_get_var(self%parent%id, self%id, data, start, cnt, stride, map), &
2428 "Could not read data from variable: " // trim(self%getName()))
2429 if (present(mask)) then
2430 allocate(mask(datashape(1), datashape(2), datashape(3), datashape(4), datashape(5)))
2431 mask =.true.
2432 call self%getCFAttributes(minvalue, maxvalue, fillvalue, flagmissing)
2433 select case(flagmissing)
2434 case(cf_use_fill_value)
2435 mask = .not. (data == fillvalue)
2436 case(cf_use_valid_min)
2437 mask = data >= minvalue
2438 case(cf_use_valid_max)
2439 mask = data <= maxvalue
2440 case(cf_use_valid_range)
2441 mask = (data <= maxvalue) .and. (data >= minvalue)
2442 end select
2443 end if
2444
2445 end subroutine getdata_5d_i1
2446
2447 subroutine setdata_5d_i1(self, values, start, cnt, stride, map)
2448 class(NcVariable), intent(in) :: self
2449 integer(i1), intent(in) :: values(:,:,:,:,:)
2450 integer(i4), intent(in), optional :: start(:), cnt(:), stride(:), map(:)
2451 call check(nf90_put_var(self%parent%id, self%id, values, start, cnt, stride, map), &
2452 "Failed to write data into variable: " // trim(self%getName()))
2453
2454 end subroutine setdata_5d_i1
2455
2456 subroutine getdata_6d_i1(self, data, start, cnt, stride, map, mask)
2457 class(NcVariable), intent(in) :: self
2458 integer(i1), intent(out), allocatable :: data(:,:,:,:,:,:)
2459 integer(i4), intent(in), optional :: start(:), cnt(:), stride(:), map(:)
2460 logical, intent(out), allocatable, optional :: mask(:,:,:,:,:,:)
2461
2462 integer(i4) :: flagMissing
2463 integer(i1) :: fillValue, minValue, maxValue
2464 integer(i4), allocatable :: slcshape(:), datashape(:)
2465
2466 slcshape = self%getSlicingShape(start, cnt, stride)
2467 datashape = getreadshape(slcshape, size(shape(data)))
2468 allocate(data(datashape(1), datashape(2), datashape(3), datashape(4), datashape(5), datashape(6)))
2469 call check (nf90_get_var(self%parent%id, self%id, data, start, cnt, stride, map), &
2470 "Could not read data from variable: " // trim(self%getName()))
2471 if (present(mask)) then
2472 allocate(mask(datashape(1), datashape(2), datashape(3), datashape(4), datashape(5), datashape(6)))
2473 mask =.true.
2474 call self%getCFAttributes(minvalue, maxvalue, fillvalue, flagmissing)
2475 select case(flagmissing)
2476 case(cf_use_fill_value)
2477 mask = .not. (data == fillvalue)
2478 case(cf_use_valid_min)
2479 mask = data >= minvalue
2480 case(cf_use_valid_max)
2481 mask = data <= maxvalue
2482 case(cf_use_valid_range)
2483 mask = (data <= maxvalue) .and. (data >= minvalue)
2484 end select
2485 end if
2486
2487 end subroutine getdata_6d_i1
2488
2489 subroutine setdata_6d_i1(self, values, start, cnt, stride, map)
2490 class(NcVariable), intent(in) :: self
2491 integer(i1), intent(in) :: values(:,:,:,:,:,:)
2492 integer(i4), intent(in), optional :: start(:), cnt(:), stride(:), map(:)
2493 call check(nf90_put_var(self%parent%id, self%id, values, start, cnt, stride, map), &
2494 "Failed to write data into variable: " // trim(self%getName()))
2495
2496 end subroutine setdata_6d_i1
2497
2498 subroutine getvariablefillvalue_i1(self, fvalue)
2499 class(NcVariable), intent(in) :: self
2500 integer(i1), intent(out) :: fvalue
2501
2502 if (self%hasAttribute(cf_fill_value)) then
2503 call self%getAttribute(cf_fill_value, fvalue)
2504 else
2505 fvalue = nf90_fill_byte
2506 end if
2507
2508 end subroutine getvariablefillvalue_i1
2509
2510 subroutine getcfattributes_i1(self, minValue, maxValue, fillValue, flagMissing)
2511 class(NcVariable), intent(in) :: self
2512 integer(i1), intent(out) :: minValue, maxValue, fillValue
2513 integer(i4), intent(out) :: flagMissing
2514
2515 integer(i1) :: valid_range(2)
2516
2517 flagmissing = cf_use_fill_value
2518 call self%getFillValue(fillvalue)
2519 if (self%hasAttribute(cf_valid_range)) then
2520 flagmissing = cf_use_valid_range
2521 call self%getAttribute(cf_valid_range, valid_range)
2522 minvalue = valid_range(1)
2523 maxvalue = valid_range(2)
2524 else if (self%hasAttribute(cf_valid_min)) then
2525 flagmissing = cf_use_valid_min
2526 call self%getAttribute(cf_valid_min, minvalue)
2527 else if (self%hasAttribute(cf_valid_max)) then
2528 flagmissing = cf_use_valid_max
2529 call self%getAttribute(cf_valid_max, maxvalue)
2530 end if
2531
2532 end subroutine getcfattributes_i1
2533
2534 subroutine setvariablefillvalue_i1(self, fvalue)
2535 class(NcVariable), intent(inout) :: self
2536 integer(i1), intent(in) :: fvalue
2537
2538 if (.not. self%hasAttribute(cf_fill_value)) then
2539 call self%setAttribute(cf_fill_value, fvalue)
2540 end if
2541
2542 end subroutine setvariablefillvalue_i1
2543
2544 subroutine getdata_0d_i2(self, data, start, cnt, stride, map, mask)
2545 class(NcVariable), intent(in) :: self
2546 integer(i2), intent(out), allocatable :: data
2547 integer(i4), intent(in), optional :: start(:), cnt(:), stride(:), map(:)
2548 logical, intent(out), allocatable, optional :: mask
2549
2550 integer(i4) :: flagMissing
2551 integer(i2) :: fillValue, minValue, maxValue
2552 integer(i2) :: tmp(1)
2553
2554 call check (nf90_get_var(self%parent%id, self%id, tmp, start, cnt, stride, map), &
2555 "Could not read data from variable: " // trim(self%getName()))
2556 data = tmp(1)
2557 if (present(mask)) then
2558 mask =.true.
2559 call self%getCFAttributes(minvalue, maxvalue, fillvalue, flagmissing)
2560 select case(flagmissing)
2561 case(cf_use_fill_value)
2562 mask = .not. (data == fillvalue)
2563 case(cf_use_valid_min)
2564 mask = data >= minvalue
2565 case(cf_use_valid_max)
2566 mask = data <= maxvalue
2567 case(cf_use_valid_range)
2568 mask = (data <= maxvalue) .and. (data >= minvalue)
2569 end select
2570 end if
2571
2572 end subroutine getdata_0d_i2
2573
2574 subroutine setdata_0d_i2(self, values, start, cnt, stride, map)
2575 class(NcVariable), intent(in) :: self
2576 integer(i2), intent(in) :: values
2577 integer(i4), intent(in), optional :: start(:), cnt(:), stride(:), map(:)
2578 call check(nf90_put_var(self%parent%id, self%id, values, start), &
2579 "Failed to write data into variable: " // trim(self%getName()))
2580
2581 end subroutine setdata_0d_i2
2582
2583 subroutine getdata_1d_i2(self, data, start, cnt, stride, map, mask)
2584 class(NcVariable), intent(in) :: self
2585 integer(i2), intent(out), allocatable :: data(:)
2586 integer(i4), intent(in), optional :: start(:), cnt(:), stride(:), map(:)
2587 logical, intent(out), allocatable, optional :: mask(:)
2588
2589 integer(i4) :: flagMissing
2590 integer(i2) :: fillValue, minValue, maxValue
2591 integer(i4), allocatable :: slcshape(:), datashape(:)
2592
2593 slcshape = self%getSlicingShape(start, cnt, stride)
2594 datashape = getreadshape(slcshape, size(shape(data)))
2595 allocate(data(datashape(1)))
2596 call check (nf90_get_var(self%parent%id, self%id, data, start, cnt, stride, map), &
2597 "Could not read data from variable: " // trim(self%getName()))
2598 if (present(mask)) then
2599 allocate(mask(datashape(1)))
2600 mask =.true.
2601 call self%getCFAttributes(minvalue, maxvalue, fillvalue, flagmissing)
2602 select case(flagmissing)
2603 case(cf_use_fill_value)
2604 mask = .not. (data == fillvalue)
2605 case(cf_use_valid_min)
2606 mask = data >= minvalue
2607 case(cf_use_valid_max)
2608 mask = data <= maxvalue
2609 case(cf_use_valid_range)
2610 mask = (data <= maxvalue) .and. (data >= minvalue)
2611 end select
2612 end if
2613
2614 end subroutine getdata_1d_i2
2615
2616 subroutine setdata_1d_i2(self, values, start, cnt, stride, map)
2617 class(NcVariable), intent(in) :: self
2618 integer(i2), intent(in) :: values(:)
2619 integer(i4), intent(in), optional :: start(:), cnt(:), stride(:), map(:)
2620 call check(nf90_put_var(self%parent%id, self%id, values, start, cnt, stride, map), &
2621 "Failed to write data into variable: " // trim(self%getName()))
2622
2623 end subroutine setdata_1d_i2
2624
2625 subroutine getdata_2d_i2(self, data, start, cnt, stride, map, mask)
2626 class(NcVariable), intent(in) :: self
2627 integer(i2), intent(out), allocatable :: data(:,:)
2628 integer(i4), intent(in), optional :: start(:), cnt(:), stride(:), map(:)
2629 logical, intent(out), allocatable, optional :: mask(:,:)
2630
2631 integer(i4) :: flagMissing
2632 integer(i2) :: fillValue, minValue, maxValue
2633 integer(i4), allocatable :: slcshape(:), datashape(:)
2634
2635 slcshape = self%getSlicingShape(start, cnt, stride)
2636 datashape = getreadshape(slcshape, size(shape(data)))
2637 allocate(data(datashape(1), datashape(2)))
2638 call check (nf90_get_var(self%parent%id, self%id, data, start, cnt, stride, map), &
2639 "Could not read data from variable: " // trim(self%getName()))
2640 if (present(mask)) then
2641 allocate(mask(datashape(1), datashape(2)))
2642 mask =.true.
2643 call self%getCFAttributes(minvalue, maxvalue, fillvalue, flagmissing)
2644 select case(flagmissing)
2645 case(cf_use_fill_value)
2646 mask = .not. (data == fillvalue)
2647 case(cf_use_valid_min)
2648 mask = data >= minvalue
2649 case(cf_use_valid_max)
2650 mask = data <= maxvalue
2651 case(cf_use_valid_range)
2652 mask = (data <= maxvalue) .and. (data >= minvalue)
2653 end select
2654 end if
2655
2656 end subroutine getdata_2d_i2
2657
2658 subroutine setdata_2d_i2(self, values, start, cnt, stride, map)
2659 class(NcVariable), intent(in) :: self
2660 integer(i2), intent(in) :: values(:,:)
2661 integer(i4), intent(in), optional :: start(:), cnt(:), stride(:), map(:)
2662 call check(nf90_put_var(self%parent%id, self%id, values, start, cnt, stride, map), &
2663 "Failed to write data into variable: " // trim(self%getName()))
2664
2665 end subroutine setdata_2d_i2
2666
2667 subroutine getdata_3d_i2(self, data, start, cnt, stride, map, mask)
2668 class(NcVariable), intent(in) :: self
2669 integer(i2), intent(out), allocatable :: data(:,:,:)
2670 integer(i4), intent(in), optional :: start(:), cnt(:), stride(:), map(:)
2671 logical, intent(out), allocatable, optional :: mask(:,:,:)
2672
2673 integer(i4) :: flagMissing
2674 integer(i2) :: fillValue, minValue, maxValue
2675 integer(i4), allocatable :: slcshape(:), datashape(:)
2676
2677 slcshape = self%getSlicingShape(start, cnt, stride)
2678 datashape = getreadshape(slcshape, size(shape(data)))
2679 allocate(data(datashape(1), datashape(2), datashape(3)))
2680 call check (nf90_get_var(self%parent%id, self%id, data, start, cnt, stride, map), &
2681 "Could not read data from variable: " // trim(self%getName()))
2682 if (present(mask)) then
2683 allocate(mask(datashape(1), datashape(2), datashape(3)))
2684 mask =.true.
2685 call self%getCFAttributes(minvalue, maxvalue, fillvalue, flagmissing)
2686 select case(flagmissing)
2687 case(cf_use_fill_value)
2688 mask = .not. (data == fillvalue)
2689 case(cf_use_valid_min)
2690 mask = data >= minvalue
2691 case(cf_use_valid_max)
2692 mask = data <= maxvalue
2693 case(cf_use_valid_range)
2694 mask = (data <= maxvalue) .and. (data >= minvalue)
2695 end select
2696 end if
2697
2698 end subroutine getdata_3d_i2
2699
2700 subroutine setdata_3d_i2(self, values, start, cnt, stride, map)
2701 class(NcVariable), intent(in) :: self
2702 integer(i2), intent(in) :: values(:,:,:)
2703 integer(i4), intent(in), optional :: start(:), cnt(:), stride(:), map(:)
2704 call check(nf90_put_var(self%parent%id, self%id, values, start, cnt, stride, map), &
2705 "Failed to write data into variable: " // trim(self%getName()))
2706
2707 end subroutine setdata_3d_i2
2708
2709 subroutine getdata_4d_i2(self, data, start, cnt, stride, map, mask)
2710 class(NcVariable), intent(in) :: self
2711 integer(i2), intent(out), allocatable :: data(:,:,:,:)
2712 integer(i4), intent(in), optional :: start(:), cnt(:), stride(:), map(:)
2713 logical, intent(out), allocatable, optional :: mask(:,:,:,:)
2714
2715 integer(i4) :: flagMissing
2716 integer(i2) :: fillValue, minValue, maxValue
2717 integer(i4), allocatable :: slcshape(:), datashape(:)
2718
2719 slcshape = self%getSlicingShape(start, cnt, stride)
2720 datashape = getreadshape(slcshape, size(shape(data)))
2721 allocate(data(datashape(1), datashape(2), datashape(3), datashape(4)))
2722 call check (nf90_get_var(self%parent%id, self%id, data, start, cnt, stride, map), &
2723 "Could not read data from variable: " // trim(self%getName()))
2724 if (present(mask)) then
2725 allocate(mask(datashape(1), datashape(2), datashape(3), datashape(4)))
2726 mask =.true.
2727 call self%getCFAttributes(minvalue, maxvalue, fillvalue, flagmissing)
2728 select case(flagmissing)
2729 case(cf_use_fill_value)
2730 mask = .not. (data == fillvalue)
2731 case(cf_use_valid_min)
2732 mask = data >= minvalue
2733 case(cf_use_valid_max)
2734 mask = data <= maxvalue
2735 case(cf_use_valid_range)
2736 mask = (data <= maxvalue) .and. (data >= minvalue)
2737 end select
2738 end if
2739
2740 end subroutine getdata_4d_i2
2741
2742 subroutine setdata_4d_i2(self, values, start, cnt, stride, map)
2743 class(NcVariable), intent(in) :: self
2744 integer(i2), intent(in) :: values(:,:,:,:)
2745 integer(i4), intent(in), optional :: start(:), cnt(:), stride(:), map(:)
2746 call check(nf90_put_var(self%parent%id, self%id, values, start, cnt, stride, map), &
2747 "Failed to write data into variable: " // trim(self%getName()))
2748
2749 end subroutine setdata_4d_i2
2750
2751 subroutine getdata_5d_i2(self, data, start, cnt, stride, map, mask)
2752 class(NcVariable), intent(in) :: self
2753 integer(i2), intent(out), allocatable :: data(:,:,:,:,:)
2754 integer(i4), intent(in), optional :: start(:), cnt(:), stride(:), map(:)
2755 logical, intent(out), allocatable, optional :: mask(:,:,:,:,:)
2756
2757 integer(i4) :: flagMissing
2758 integer(i2) :: fillValue, minValue, maxValue
2759 integer(i4), allocatable :: slcshape(:), datashape(:)
2760
2761 slcshape = self%getSlicingShape(start, cnt, stride)
2762 datashape = getreadshape(slcshape, size(shape(data)))
2763 allocate(data(datashape(1), datashape(2), datashape(3), datashape(4), datashape(5)))
2764 call check (nf90_get_var(self%parent%id, self%id, data, start, cnt, stride, map), &
2765 "Could not read data from variable: " // trim(self%getName()))
2766 if (present(mask)) then
2767 allocate(mask(datashape(1), datashape(2), datashape(3), datashape(4), datashape(5)))
2768 mask =.true.
2769 call self%getCFAttributes(minvalue, maxvalue, fillvalue, flagmissing)
2770 select case(flagmissing)
2771 case(cf_use_fill_value)
2772 mask = .not. (data == fillvalue)
2773 case(cf_use_valid_min)
2774 mask = data >= minvalue
2775 case(cf_use_valid_max)
2776 mask = data <= maxvalue
2777 case(cf_use_valid_range)
2778 mask = (data <= maxvalue) .and. (data >= minvalue)
2779 end select
2780 end if
2781
2782 end subroutine getdata_5d_i2
2783
2784 subroutine setdata_5d_i2(self, values, start, cnt, stride, map)
2785 class(NcVariable), intent(in) :: self
2786 integer(i2), intent(in) :: values(:,:,:,:,:)
2787 integer(i4), intent(in), optional :: start(:), cnt(:), stride(:), map(:)
2788 call check(nf90_put_var(self%parent%id, self%id, values, start, cnt, stride, map), &
2789 "Failed to write data into variable: " // trim(self%getName()))
2790
2791 end subroutine setdata_5d_i2
2792
2793 subroutine getdata_6d_i2(self, data, start, cnt, stride, map, mask)
2794 class(NcVariable), intent(in) :: self
2795 integer(i2), intent(out), allocatable :: data(:,:,:,:,:,:)
2796 integer(i4), intent(in), optional :: start(:), cnt(:), stride(:), map(:)
2797 logical, intent(out), allocatable, optional :: mask(:,:,:,:,:,:)
2798
2799 integer(i4) :: flagMissing
2800 integer(i2) :: fillValue, minValue, maxValue
2801 integer(i4), allocatable :: slcshape(:), datashape(:)
2802
2803 slcshape = self%getSlicingShape(start, cnt, stride)
2804 datashape = getreadshape(slcshape, size(shape(data)))
2805 allocate(data(datashape(1), datashape(2), datashape(3), datashape(4), datashape(5), datashape(6)))
2806 call check (nf90_get_var(self%parent%id, self%id, data, start, cnt, stride, map), &
2807 "Could not read data from variable: " // trim(self%getName()))
2808 if (present(mask)) then
2809 allocate(mask(datashape(1), datashape(2), datashape(3), datashape(4), datashape(5), datashape(6)))
2810 mask =.true.
2811 call self%getCFAttributes(minvalue, maxvalue, fillvalue, flagmissing)
2812 select case(flagmissing)
2813 case(cf_use_fill_value)
2814 mask = .not. (data == fillvalue)
2815 case(cf_use_valid_min)
2816 mask = data >= minvalue
2817 case(cf_use_valid_max)
2818 mask = data <= maxvalue
2819 case(cf_use_valid_range)
2820 mask = (data <= maxvalue) .and. (data >= minvalue)
2821 end select
2822 end if
2823
2824 end subroutine getdata_6d_i2
2825
2826 subroutine setdata_6d_i2(self, values, start, cnt, stride, map)
2827 class(NcVariable), intent(in) :: self
2828 integer(i2), intent(in) :: values(:,:,:,:,:,:)
2829 integer(i4), intent(in), optional :: start(:), cnt(:), stride(:), map(:)
2830 call check(nf90_put_var(self%parent%id, self%id, values, start, cnt, stride, map), &
2831 "Failed to write data into variable: " // trim(self%getName()))
2832
2833 end subroutine setdata_6d_i2
2834
2835 subroutine getvariablefillvalue_i2(self, fvalue)
2836 class(NcVariable), intent(in) :: self
2837 integer(i2), intent(out) :: fvalue
2838
2839 if (self%hasAttribute(cf_fill_value)) then
2840 call self%getAttribute(cf_fill_value, fvalue)
2841 else
2842 fvalue = nf90_fill_short
2843 end if
2844
2845 end subroutine getvariablefillvalue_i2
2846
2847 subroutine getcfattributes_i2(self, minValue, maxValue, fillValue, flagMissing)
2848 class(NcVariable), intent(in) :: self
2849 integer(i2), intent(out) :: minValue, maxValue, fillValue
2850 integer(i4), intent(out) :: flagMissing
2851
2852 integer(i2) :: valid_range(2)
2853
2854 flagmissing = cf_use_fill_value
2855 call self%getFillValue(fillvalue)
2856 if (self%hasAttribute(cf_valid_range)) then
2857 flagmissing = cf_use_valid_range
2858 call self%getAttribute(cf_valid_range, valid_range)
2859 minvalue = valid_range(1)
2860 maxvalue = valid_range(2)
2861 else if (self%hasAttribute(cf_valid_min)) then
2862 flagmissing = cf_use_valid_min
2863 call self%getAttribute(cf_valid_min, minvalue)
2864 else if (self%hasAttribute(cf_valid_max)) then
2865 flagmissing = cf_use_valid_max
2866 call self%getAttribute(cf_valid_max, maxvalue)
2867 end if
2868
2869 end subroutine getcfattributes_i2
2870
2871 subroutine setvariablefillvalue_i2(self, fvalue)
2872 class(NcVariable), intent(inout) :: self
2873 integer(i2), intent(in) :: fvalue
2874
2875 if (.not. self%hasAttribute(cf_fill_value)) then
2876 call self%setAttribute(cf_fill_value, fvalue)
2877 end if
2878
2879 end subroutine setvariablefillvalue_i2
2880
2881 subroutine getdata_0d_i4(self, data, start, cnt, stride, map, mask)
2882 class(NcVariable), intent(in) :: self
2883 integer(i4), intent(out), allocatable :: data
2884 integer(i4), intent(in), optional :: start(:), cnt(:), stride(:), map(:)
2885 logical, intent(out), allocatable, optional :: mask
2886
2887 integer(i4) :: flagMissing
2888 integer(i4) :: fillValue, minValue, maxValue
2889 integer(i4) :: tmp(1)
2890
2891 call check (nf90_get_var(self%parent%id, self%id, tmp, start, cnt, stride, map), &
2892 "Could not read data from variable: " // trim(self%getName()))
2893 data = tmp(1)
2894 if (present(mask)) then
2895 mask =.true.
2896 call self%getCFAttributes(minvalue, maxvalue, fillvalue, flagmissing)
2897 select case(flagmissing)
2898 case(cf_use_fill_value)
2899 mask = .not. (data == fillvalue)
2900 case(cf_use_valid_min)
2901 mask = data >= minvalue
2902 case(cf_use_valid_max)
2903 mask = data <= maxvalue
2904 case(cf_use_valid_range)
2905 mask = (data <= maxvalue) .and. (data >= minvalue)
2906 end select
2907 end if
2908
2909 end subroutine getdata_0d_i4
2910
2911 subroutine setdata_0d_i4(self, values, start, cnt, stride, map)
2912 class(NcVariable), intent(in) :: self
2913 integer(i4), intent(in) :: values
2914 integer(i4), intent(in), optional :: start(:), cnt(:), stride(:), map(:)
2915 call check(nf90_put_var(self%parent%id, self%id, values, start), &
2916 "Failed to write data into variable: " // trim(self%getName()))
2917
2918 end subroutine setdata_0d_i4
2919
2920 subroutine getdata_1d_i4(self, data, start, cnt, stride, map, mask)
2921 class(NcVariable), intent(in) :: self
2922 integer(i4), intent(out), allocatable :: data(:)
2923 integer(i4), intent(in), optional :: start(:), cnt(:), stride(:), map(:)
2924 logical, intent(out), allocatable, optional :: mask(:)
2925
2926 integer(i4) :: flagMissing
2927 integer(i4) :: fillValue, minValue, maxValue
2928 integer(i4), allocatable :: slcshape(:), datashape(:)
2929
2930 slcshape = self%getSlicingShape(start, cnt, stride)
2931 datashape = getreadshape(slcshape, size(shape(data)))
2932 allocate(data(datashape(1)))
2933 call check (nf90_get_var(self%parent%id, self%id, data, start, cnt, stride, map), &
2934 "Could not read data from variable: " // trim(self%getName()))
2935 if (present(mask)) then
2936 allocate(mask(datashape(1)))
2937 mask =.true.
2938 call self%getCFAttributes(minvalue, maxvalue, fillvalue, flagmissing)
2939 select case(flagmissing)
2940 case(cf_use_fill_value)
2941 mask = .not. (data == fillvalue)
2942 case(cf_use_valid_min)
2943 mask = data >= minvalue
2944 case(cf_use_valid_max)
2945 mask = data <= maxvalue
2946 case(cf_use_valid_range)
2947 mask = (data <= maxvalue) .and. (data >= minvalue)
2948 end select
2949 end if
2950
2951 end subroutine getdata_1d_i4
2952
2953 subroutine setdata_1d_i4(self, values, start, cnt, stride, map)
2954 class(NcVariable), intent(in) :: self
2955 integer(i4), intent(in) :: values(:)
2956 integer(i4), intent(in), optional :: start(:), cnt(:), stride(:), map(:)
2957 call check(nf90_put_var(self%parent%id, self%id, values, start, cnt, stride, map), &
2958 "Failed to write data into variable: " // trim(self%getName()))
2959
2960 end subroutine setdata_1d_i4
2961
2962 subroutine getdata_2d_i4(self, data, start, cnt, stride, map, mask)
2963 class(NcVariable), intent(in) :: self
2964 integer(i4), intent(out), allocatable :: data(:,:)
2965 integer(i4), intent(in), optional :: start(:), cnt(:), stride(:), map(:)
2966 logical, intent(out), allocatable, optional :: mask(:,:)
2967
2968 integer(i4) :: flagMissing
2969 integer(i4) :: fillValue, minValue, maxValue
2970 integer(i4), allocatable :: slcshape(:), datashape(:)
2971
2972 slcshape = self%getSlicingShape(start, cnt, stride)
2973 datashape = getreadshape(slcshape, size(shape(data)))
2974 allocate(data(datashape(1), datashape(2)))
2975 call check (nf90_get_var(self%parent%id, self%id, data, start, cnt, stride, map), &
2976 "Could not read data from variable: " // trim(self%getName()))
2977 if (present(mask)) then
2978 allocate(mask(datashape(1), datashape(2)))
2979 mask =.true.
2980 call self%getCFAttributes(minvalue, maxvalue, fillvalue, flagmissing)
2981 select case(flagmissing)
2982 case(cf_use_fill_value)
2983 mask = .not. (data == fillvalue)
2984 case(cf_use_valid_min)
2985 mask = data >= minvalue
2986 case(cf_use_valid_max)
2987 mask = data <= maxvalue
2988 case(cf_use_valid_range)
2989 mask = (data <= maxvalue) .and. (data >= minvalue)
2990 end select
2991 end if
2992
2993 end subroutine getdata_2d_i4
2994
2995 subroutine setdata_2d_i4(self, values, start, cnt, stride, map)
2996 class(NcVariable), intent(in) :: self
2997 integer(i4), intent(in) :: values(:,:)
2998 integer(i4), intent(in), optional :: start(:), cnt(:), stride(:), map(:)
2999 call check(nf90_put_var(self%parent%id, self%id, values, start, cnt, stride, map), &
3000 "Failed to write data into variable: " // trim(self%getName()))
3001
3002 end subroutine setdata_2d_i4
3003
3004 subroutine getdata_3d_i4(self, data, start, cnt, stride, map, mask)
3005 class(NcVariable), intent(in) :: self
3006 integer(i4), intent(out), allocatable :: data(:,:,:)
3007 integer(i4), intent(in), optional :: start(:), cnt(:), stride(:), map(:)
3008 logical, intent(out), allocatable, optional :: mask(:,:,:)
3009
3010 integer(i4) :: flagMissing
3011 integer(i4) :: fillValue, minValue, maxValue
3012 integer(i4), allocatable :: slcshape(:), datashape(:)
3013
3014 slcshape = self%getSlicingShape(start, cnt, stride)
3015 datashape = getreadshape(slcshape, size(shape(data)))
3016 allocate(data(datashape(1), datashape(2), datashape(3)))
3017 call check (nf90_get_var(self%parent%id, self%id, data, start, cnt, stride, map), &
3018 "Could not read data from variable: " // trim(self%getName()))
3019 if (present(mask)) then
3020 allocate(mask(datashape(1), datashape(2), datashape(3)))
3021 mask =.true.
3022 call self%getCFAttributes(minvalue, maxvalue, fillvalue, flagmissing)
3023 select case(flagmissing)
3024 case(cf_use_fill_value)
3025 mask = .not. (data == fillvalue)
3026 case(cf_use_valid_min)
3027 mask = data >= minvalue
3028 case(cf_use_valid_max)
3029 mask = data <= maxvalue
3030 case(cf_use_valid_range)
3031 mask = (data <= maxvalue) .and. (data >= minvalue)
3032 end select
3033 end if
3034
3035 end subroutine getdata_3d_i4
3036
3037 subroutine setdata_3d_i4(self, values, start, cnt, stride, map)
3038 class(NcVariable), intent(in) :: self
3039 integer(i4), intent(in) :: values(:,:,:)
3040 integer(i4), intent(in), optional :: start(:), cnt(:), stride(:), map(:)
3041 call check(nf90_put_var(self%parent%id, self%id, values, start, cnt, stride, map), &
3042 "Failed to write data into variable: " // trim(self%getName()))
3043
3044 end subroutine setdata_3d_i4
3045
3046 subroutine getdata_4d_i4(self, data, start, cnt, stride, map, mask)
3047 class(NcVariable), intent(in) :: self
3048 integer(i4), intent(out), allocatable :: data(:,:,:,:)
3049 integer(i4), intent(in), optional :: start(:), cnt(:), stride(:), map(:)
3050 logical, intent(out), allocatable, optional :: mask(:,:,:,:)
3051
3052 integer(i4) :: flagMissing
3053 integer(i4) :: fillValue, minValue, maxValue
3054 integer(i4), allocatable :: slcshape(:), datashape(:)
3055
3056 slcshape = self%getSlicingShape(start, cnt, stride)
3057 datashape = getreadshape(slcshape, size(shape(data)))
3058 allocate(data(datashape(1), datashape(2), datashape(3), datashape(4)))
3059 call check (nf90_get_var(self%parent%id, self%id, data, start, cnt, stride, map), &
3060 "Could not read data from variable: " // trim(self%getName()))
3061 if (present(mask)) then
3062 allocate(mask(datashape(1), datashape(2), datashape(3), datashape(4)))
3063 mask =.true.
3064 call self%getCFAttributes(minvalue, maxvalue, fillvalue, flagmissing)
3065 select case(flagmissing)
3066 case(cf_use_fill_value)
3067 mask = .not. (data == fillvalue)
3068 case(cf_use_valid_min)
3069 mask = data >= minvalue
3070 case(cf_use_valid_max)
3071 mask = data <= maxvalue
3072 case(cf_use_valid_range)
3073 mask = (data <= maxvalue) .and. (data >= minvalue)
3074 end select
3075 end if
3076
3077 end subroutine getdata_4d_i4
3078
3079 subroutine setdata_4d_i4(self, values, start, cnt, stride, map)
3080 class(NcVariable), intent(in) :: self
3081 integer(i4), intent(in) :: values(:,:,:,:)
3082 integer(i4), intent(in), optional :: start(:), cnt(:), stride(:), map(:)
3083 call check(nf90_put_var(self%parent%id, self%id, values, start, cnt, stride, map), &
3084 "Failed to write data into variable: " // trim(self%getName()))
3085
3086 end subroutine setdata_4d_i4
3087
3088 subroutine getdata_5d_i4(self, data, start, cnt, stride, map, mask)
3089 class(NcVariable), intent(in) :: self
3090 integer(i4), intent(out), allocatable :: data(:,:,:,:,:)
3091 integer(i4), intent(in), optional :: start(:), cnt(:), stride(:), map(:)
3092 logical, intent(out), allocatable, optional :: mask(:,:,:,:,:)
3093
3094 integer(i4) :: flagMissing
3095 integer(i4) :: fillValue, minValue, maxValue
3096 integer(i4), allocatable :: slcshape(:), datashape(:)
3097
3098 slcshape = self%getSlicingShape(start, cnt, stride)
3099 datashape = getreadshape(slcshape, size(shape(data)))
3100 allocate(data(datashape(1), datashape(2), datashape(3), datashape(4), datashape(5)))
3101 call check (nf90_get_var(self%parent%id, self%id, data, start, cnt, stride, map), &
3102 "Could not read data from variable: " // trim(self%getName()))
3103 if (present(mask)) then
3104 allocate(mask(datashape(1), datashape(2), datashape(3), datashape(4), datashape(5)))
3105 mask =.true.
3106 call self%getCFAttributes(minvalue, maxvalue, fillvalue, flagmissing)
3107 select case(flagmissing)
3108 case(cf_use_fill_value)
3109 mask = .not. (data == fillvalue)
3110 case(cf_use_valid_min)
3111 mask = data >= minvalue
3112 case(cf_use_valid_max)
3113 mask = data <= maxvalue
3114 case(cf_use_valid_range)
3115 mask = (data <= maxvalue) .and. (data >= minvalue)
3116 end select
3117 end if
3118
3119 end subroutine getdata_5d_i4
3120
3121 subroutine setdata_5d_i4(self, values, start, cnt, stride, map)
3122 class(NcVariable), intent(in) :: self
3123 integer(i4), intent(in) :: values(:,:,:,:,:)
3124 integer(i4), intent(in), optional :: start(:), cnt(:), stride(:), map(:)
3125 call check(nf90_put_var(self%parent%id, self%id, values, start, cnt, stride, map), &
3126 "Failed to write data into variable: " // trim(self%getName()))
3127
3128 end subroutine setdata_5d_i4
3129
3130 subroutine getdata_6d_i4(self, data, start, cnt, stride, map, mask)
3131 class(NcVariable), intent(in) :: self
3132 integer(i4), intent(out), allocatable :: data(:,:,:,:,:,:)
3133 integer(i4), intent(in), optional :: start(:), cnt(:), stride(:), map(:)
3134 logical, intent(out), allocatable, optional :: mask(:,:,:,:,:,:)
3135
3136 integer(i4) :: flagMissing
3137 integer(i4) :: fillValue, minValue, maxValue
3138 integer(i4), allocatable :: slcshape(:), datashape(:)
3139
3140 slcshape = self%getSlicingShape(start, cnt, stride)
3141 datashape = getreadshape(slcshape, size(shape(data)))
3142 allocate(data(datashape(1), datashape(2), datashape(3), datashape(4), datashape(5), datashape(6)))
3143 call check (nf90_get_var(self%parent%id, self%id, data, start, cnt, stride, map), &
3144 "Could not read data from variable: " // trim(self%getName()))
3145 if (present(mask)) then
3146 allocate(mask(datashape(1), datashape(2), datashape(3), datashape(4), datashape(5), datashape(6)))
3147 mask =.true.
3148 call self%getCFAttributes(minvalue, maxvalue, fillvalue, flagmissing)
3149 select case(flagmissing)
3150 case(cf_use_fill_value)
3151 mask = .not. (data == fillvalue)
3152 case(cf_use_valid_min)
3153 mask = data >= minvalue
3154 case(cf_use_valid_max)
3155 mask = data <= maxvalue
3156 case(cf_use_valid_range)
3157 mask = (data <= maxvalue) .and. (data >= minvalue)
3158 end select
3159 end if
3160
3161 end subroutine getdata_6d_i4
3162
3163 subroutine setdata_6d_i4(self, values, start, cnt, stride, map)
3164 class(NcVariable), intent(in) :: self
3165 integer(i4), intent(in) :: values(:,:,:,:,:,:)
3166 integer(i4), intent(in), optional :: start(:), cnt(:), stride(:), map(:)
3167 call check(nf90_put_var(self%parent%id, self%id, values, start, cnt, stride, map), &
3168 "Failed to write data into variable: " // trim(self%getName()))
3169
3170 end subroutine setdata_6d_i4
3171
3172 subroutine getvariablefillvalue_i4(self, fvalue)
3173 class(NcVariable), intent(in) :: self
3174 integer(i4), intent(out) :: fvalue
3175
3176 if (self%hasAttribute(cf_fill_value)) then
3177 call self%getAttribute(cf_fill_value, fvalue)
3178 else
3179 fvalue = nf90_fill_int
3180 end if
3181
3182 end subroutine getvariablefillvalue_i4
3183
3184 subroutine getcfattributes_i4(self, minValue, maxValue, fillValue, flagMissing)
3185 class(NcVariable), intent(in) :: self
3186 integer(i4), intent(out) :: minValue, maxValue, fillValue
3187 integer(i4), intent(out) :: flagMissing
3188
3189 integer(i4) :: valid_range(2)
3190
3191 flagmissing = cf_use_fill_value
3192 call self%getFillValue(fillvalue)
3193 if (self%hasAttribute(cf_valid_range)) then
3194 flagmissing = cf_use_valid_range
3195 call self%getAttribute(cf_valid_range, valid_range)
3196 minvalue = valid_range(1)
3197 maxvalue = valid_range(2)
3198 else if (self%hasAttribute(cf_valid_min)) then
3199 flagmissing = cf_use_valid_min
3200 call self%getAttribute(cf_valid_min, minvalue)
3201 else if (self%hasAttribute(cf_valid_max)) then
3202 flagmissing = cf_use_valid_max
3203 call self%getAttribute(cf_valid_max, maxvalue)
3204 end if
3205
3206 end subroutine getcfattributes_i4
3207
3208 subroutine setvariablefillvalue_i4(self, fvalue)
3209 class(NcVariable), intent(inout) :: self
3210 integer(i4), intent(in) :: fvalue
3211
3212 if (.not. self%hasAttribute(cf_fill_value)) then
3213 call self%setAttribute(cf_fill_value, fvalue)
3214 end if
3215
3216 end subroutine setvariablefillvalue_i4
3217
3218 subroutine getdata_0d_i8(self, data, start, cnt, stride, map, mask)
3219 class(NcVariable), intent(in) :: self
3220 integer(i8), intent(out), allocatable :: data
3221 integer(i4), intent(in), optional :: start(:), cnt(:), stride(:), map(:)
3222 logical, intent(out), allocatable, optional :: mask
3223
3224 integer(i4) :: flagMissing
3225 integer(i8) :: fillValue, minValue, maxValue
3226 integer(i8) :: tmp(1)
3227
3228 call check (nf90_get_var(self%parent%id, self%id, tmp, start, cnt, stride, map), &
3229 "Could not read data from variable: " // trim(self%getName()))
3230 data = tmp(1)
3231 if (present(mask)) then
3232 mask =.true.
3233 call self%getCFAttributes(minvalue, maxvalue, fillvalue, flagmissing)
3234 select case(flagmissing)
3235 case(cf_use_fill_value)
3236 mask = .not. (data == fillvalue)
3237 case(cf_use_valid_min)
3238 mask = data >= minvalue
3239 case(cf_use_valid_max)
3240 mask = data <= maxvalue
3241 case(cf_use_valid_range)
3242 mask = (data <= maxvalue) .and. (data >= minvalue)
3243 end select
3244 end if
3245
3246 end subroutine getdata_0d_i8
3247
3248 subroutine setdata_0d_i8(self, values, start, cnt, stride, map)
3249 class(NcVariable), intent(in) :: self
3250 integer(i8), intent(in) :: values
3251 integer(i4), intent(in), optional :: start(:), cnt(:), stride(:), map(:)
3252 call check(nf90_put_var(self%parent%id, self%id, values, start), &
3253 "Failed to write data into variable: " // trim(self%getName()))
3254
3255 end subroutine setdata_0d_i8
3256
3257 subroutine getdata_1d_i8(self, data, start, cnt, stride, map, mask)
3258 class(NcVariable), intent(in) :: self
3259 integer(i8), intent(out), allocatable :: data(:)
3260 integer(i4), intent(in), optional :: start(:), cnt(:), stride(:), map(:)
3261 logical, intent(out), allocatable, optional :: mask(:)
3262
3263 integer(i4) :: flagMissing
3264 integer(i8) :: fillValue, minValue, maxValue
3265 integer(i4), allocatable :: slcshape(:), datashape(:)
3266
3267 slcshape = self%getSlicingShape(start, cnt, stride)
3268 datashape = getreadshape(slcshape, size(shape(data)))
3269 allocate(data(datashape(1)))
3270 call check (nf90_get_var(self%parent%id, self%id, data, start, cnt, stride, map), &
3271 "Could not read data from variable: " // trim(self%getName()))
3272 if (present(mask)) then
3273 allocate(mask(datashape(1)))
3274 mask =.true.
3275 call self%getCFAttributes(minvalue, maxvalue, fillvalue, flagmissing)
3276 select case(flagmissing)
3277 case(cf_use_fill_value)
3278 mask = .not. (data == fillvalue)
3279 case(cf_use_valid_min)
3280 mask = data >= minvalue
3281 case(cf_use_valid_max)
3282 mask = data <= maxvalue
3283 case(cf_use_valid_range)
3284 mask = (data <= maxvalue) .and. (data >= minvalue)
3285 end select
3286 end if
3287
3288 end subroutine getdata_1d_i8
3289
3290 subroutine setdata_1d_i8(self, values, start, cnt, stride, map)
3291 class(NcVariable), intent(in) :: self
3292 integer(i8), intent(in) :: values(:)
3293 integer(i4), intent(in), optional :: start(:), cnt(:), stride(:), map(:)
3294 call check(nf90_put_var(self%parent%id, self%id, values, start, cnt, stride, map), &
3295 "Failed to write data into variable: " // trim(self%getName()))
3296
3297 end subroutine setdata_1d_i8
3298
3299 subroutine getdata_2d_i8(self, data, start, cnt, stride, map, mask)
3300 class(NcVariable), intent(in) :: self
3301 integer(i8), intent(out), allocatable :: data(:,:)
3302 integer(i4), intent(in), optional :: start(:), cnt(:), stride(:), map(:)
3303 logical, intent(out), allocatable, optional :: mask(:,:)
3304
3305 integer(i4) :: flagMissing
3306 integer(i8) :: fillValue, minValue, maxValue
3307 integer(i4), allocatable :: slcshape(:), datashape(:)
3308
3309 slcshape = self%getSlicingShape(start, cnt, stride)
3310 datashape = getreadshape(slcshape, size(shape(data)))
3311 allocate(data(datashape(1), datashape(2)))
3312 call check (nf90_get_var(self%parent%id, self%id, data, start, cnt, stride, map), &
3313 "Could not read data from variable: " // trim(self%getName()))
3314 if (present(mask)) then
3315 allocate(mask(datashape(1), datashape(2)))
3316 mask =.true.
3317 call self%getCFAttributes(minvalue, maxvalue, fillvalue, flagmissing)
3318 select case(flagmissing)
3319 case(cf_use_fill_value)
3320 mask = .not. (data == fillvalue)
3321 case(cf_use_valid_min)
3322 mask = data >= minvalue
3323 case(cf_use_valid_max)
3324 mask = data <= maxvalue
3325 case(cf_use_valid_range)
3326 mask = (data <= maxvalue) .and. (data >= minvalue)
3327 end select
3328 end if
3329
3330 end subroutine getdata_2d_i8
3331
3332 subroutine setdata_2d_i8(self, values, start, cnt, stride, map)
3333 class(NcVariable), intent(in) :: self
3334 integer(i8), intent(in) :: values(:,:)
3335 integer(i4), intent(in), optional :: start(:), cnt(:), stride(:), map(:)
3336 call check(nf90_put_var(self%parent%id, self%id, values, start, cnt, stride, map), &
3337 "Failed to write data into variable: " // trim(self%getName()))
3338
3339 end subroutine setdata_2d_i8
3340
3341 subroutine getdata_3d_i8(self, data, start, cnt, stride, map, mask)
3342 class(NcVariable), intent(in) :: self
3343 integer(i8), intent(out), allocatable :: data(:,:,:)
3344 integer(i4), intent(in), optional :: start(:), cnt(:), stride(:), map(:)
3345 logical, intent(out), allocatable, optional :: mask(:,:,:)
3346
3347 integer(i4) :: flagMissing
3348 integer(i8) :: fillValue, minValue, maxValue
3349 integer(i4), allocatable :: slcshape(:), datashape(:)
3350
3351 slcshape = self%getSlicingShape(start, cnt, stride)
3352 datashape = getreadshape(slcshape, size(shape(data)))
3353 allocate(data(datashape(1), datashape(2), datashape(3)))
3354 call check (nf90_get_var(self%parent%id, self%id, data, start, cnt, stride, map), &
3355 "Could not read data from variable: " // trim(self%getName()))
3356 if (present(mask)) then
3357 allocate(mask(datashape(1), datashape(2), datashape(3)))
3358 mask =.true.
3359 call self%getCFAttributes(minvalue, maxvalue, fillvalue, flagmissing)
3360 select case(flagmissing)
3361 case(cf_use_fill_value)
3362 mask = .not. (data == fillvalue)
3363 case(cf_use_valid_min)
3364 mask = data >= minvalue
3365 case(cf_use_valid_max)
3366 mask = data <= maxvalue
3367 case(cf_use_valid_range)
3368 mask = (data <= maxvalue) .and. (data >= minvalue)
3369 end select
3370 end if
3371
3372 end subroutine getdata_3d_i8
3373
3374 subroutine setdata_3d_i8(self, values, start, cnt, stride, map)
3375 class(NcVariable), intent(in) :: self
3376 integer(i8), intent(in) :: values(:,:,:)
3377 integer(i4), intent(in), optional :: start(:), cnt(:), stride(:), map(:)
3378 call check(nf90_put_var(self%parent%id, self%id, values, start, cnt, stride, map), &
3379 "Failed to write data into variable: " // trim(self%getName()))
3380
3381 end subroutine setdata_3d_i8
3382
3383 subroutine getdata_4d_i8(self, data, start, cnt, stride, map, mask)
3384 class(NcVariable), intent(in) :: self
3385 integer(i8), intent(out), allocatable :: data(:,:,:,:)
3386 integer(i4), intent(in), optional :: start(:), cnt(:), stride(:), map(:)
3387 logical, intent(out), allocatable, optional :: mask(:,:,:,:)
3388
3389 integer(i4) :: flagMissing
3390 integer(i8) :: fillValue, minValue, maxValue
3391 integer(i4), allocatable :: slcshape(:), datashape(:)
3392
3393 slcshape = self%getSlicingShape(start, cnt, stride)
3394 datashape = getreadshape(slcshape, size(shape(data)))
3395 allocate(data(datashape(1), datashape(2), datashape(3), datashape(4)))
3396 call check (nf90_get_var(self%parent%id, self%id, data, start, cnt, stride, map), &
3397 "Could not read data from variable: " // trim(self%getName()))
3398 if (present(mask)) then
3399 allocate(mask(datashape(1), datashape(2), datashape(3), datashape(4)))
3400 mask =.true.
3401 call self%getCFAttributes(minvalue, maxvalue, fillvalue, flagmissing)
3402 select case(flagmissing)
3403 case(cf_use_fill_value)
3404 mask = .not. (data == fillvalue)
3405 case(cf_use_valid_min)
3406 mask = data >= minvalue
3407 case(cf_use_valid_max)
3408 mask = data <= maxvalue
3409 case(cf_use_valid_range)
3410 mask = (data <= maxvalue) .and. (data >= minvalue)
3411 end select
3412 end if
3413
3414 end subroutine getdata_4d_i8
3415
3416 subroutine setdata_4d_i8(self, values, start, cnt, stride, map)
3417 class(NcVariable), intent(in) :: self
3418 integer(i8), intent(in) :: values(:,:,:,:)
3419 integer(i4), intent(in), optional :: start(:), cnt(:), stride(:), map(:)
3420 call check(nf90_put_var(self%parent%id, self%id, values, start, cnt, stride, map), &
3421 "Failed to write data into variable: " // trim(self%getName()))
3422
3423 end subroutine setdata_4d_i8
3424
3425 subroutine getdata_5d_i8(self, data, start, cnt, stride, map, mask)
3426 class(NcVariable), intent(in) :: self
3427 integer(i8), intent(out), allocatable :: data(:,:,:,:,:)
3428 integer(i4), intent(in), optional :: start(:), cnt(:), stride(:), map(:)
3429 logical, intent(out), allocatable, optional :: mask(:,:,:,:,:)
3430
3431 integer(i4) :: flagMissing
3432 integer(i8) :: fillValue, minValue, maxValue
3433 integer(i4), allocatable :: slcshape(:), datashape(:)
3434
3435 slcshape = self%getSlicingShape(start, cnt, stride)
3436 datashape = getreadshape(slcshape, size(shape(data)))
3437 allocate(data(datashape(1), datashape(2), datashape(3), datashape(4), datashape(5)))
3438 call check (nf90_get_var(self%parent%id, self%id, data, start, cnt, stride, map), &
3439 "Could not read data from variable: " // trim(self%getName()))
3440 if (present(mask)) then
3441 allocate(mask(datashape(1), datashape(2), datashape(3), datashape(4), datashape(5)))
3442 mask =.true.
3443 call self%getCFAttributes(minvalue, maxvalue, fillvalue, flagmissing)
3444 select case(flagmissing)
3445 case(cf_use_fill_value)
3446 mask = .not. (data == fillvalue)
3447 case(cf_use_valid_min)
3448 mask = data >= minvalue
3449 case(cf_use_valid_max)
3450 mask = data <= maxvalue
3451 case(cf_use_valid_range)
3452 mask = (data <= maxvalue) .and. (data >= minvalue)
3453 end select
3454 end if
3455
3456 end subroutine getdata_5d_i8
3457
3458 subroutine setdata_5d_i8(self, values, start, cnt, stride, map)
3459 class(NcVariable), intent(in) :: self
3460 integer(i8), intent(in) :: values(:,:,:,:,:)
3461 integer(i4), intent(in), optional :: start(:), cnt(:), stride(:), map(:)
3462 call check(nf90_put_var(self%parent%id, self%id, values, start, cnt, stride, map), &
3463 "Failed to write data into variable: " // trim(self%getName()))
3464
3465 end subroutine setdata_5d_i8
3466
3467 subroutine getdata_6d_i8(self, data, start, cnt, stride, map, mask)
3468 class(NcVariable), intent(in) :: self
3469 integer(i8), intent(out), allocatable :: data(:,:,:,:,:,:)
3470 integer(i4), intent(in), optional :: start(:), cnt(:), stride(:), map(:)
3471 logical, intent(out), allocatable, optional :: mask(:,:,:,:,:,:)
3472
3473 integer(i4) :: flagMissing
3474 integer(i8) :: fillValue, minValue, maxValue
3475 integer(i4), allocatable :: slcshape(:), datashape(:)
3476
3477 slcshape = self%getSlicingShape(start, cnt, stride)
3478 datashape = getreadshape(slcshape, size(shape(data)))
3479 allocate(data(datashape(1), datashape(2), datashape(3), datashape(4), datashape(5), datashape(6)))
3480 call check (nf90_get_var(self%parent%id, self%id, data, start, cnt, stride, map), &
3481 "Could not read data from variable: " // trim(self%getName()))
3482 if (present(mask)) then
3483 allocate(mask(datashape(1), datashape(2), datashape(3), datashape(4), datashape(5), datashape(6)))
3484 mask =.true.
3485 call self%getCFAttributes(minvalue, maxvalue, fillvalue, flagmissing)
3486 select case(flagmissing)
3487 case(cf_use_fill_value)
3488 mask = .not. (data == fillvalue)
3489 case(cf_use_valid_min)
3490 mask = data >= minvalue
3491 case(cf_use_valid_max)
3492 mask = data <= maxvalue
3493 case(cf_use_valid_range)
3494 mask = (data <= maxvalue) .and. (data >= minvalue)
3495 end select
3496 end if
3497
3498 end subroutine getdata_6d_i8
3499
3500 subroutine setdata_6d_i8(self, values, start, cnt, stride, map)
3501 class(NcVariable), intent(in) :: self
3502 integer(i8), intent(in) :: values(:,:,:,:,:,:)
3503 integer(i4), intent(in), optional :: start(:), cnt(:), stride(:), map(:)
3504 call check(nf90_put_var(self%parent%id, self%id, values, start, cnt, stride, map), &
3505 "Failed to write data into variable: " // trim(self%getName()))
3506
3507 end subroutine setdata_6d_i8
3508
3509 subroutine getvariablefillvalue_i8(self, fvalue)
3510 class(NcVariable), intent(in) :: self
3511 integer(i8), intent(out) :: fvalue
3512
3513 if (self%hasAttribute(cf_fill_value)) then
3514 call self%getAttribute(cf_fill_value, fvalue)
3515 else
3516 fvalue = nf90_fill_int
3517 end if
3518
3519 end subroutine getvariablefillvalue_i8
3520
3521 subroutine getcfattributes_i8(self, minValue, maxValue, fillValue, flagMissing)
3522 class(NcVariable), intent(in) :: self
3523 integer(i8), intent(out) :: minValue, maxValue, fillValue
3524 integer(i4), intent(out) :: flagMissing
3525
3526 integer(i8) :: valid_range(2)
3527
3528 flagmissing = cf_use_fill_value
3529 call self%getFillValue(fillvalue)
3530 if (self%hasAttribute(cf_valid_range)) then
3531 flagmissing = cf_use_valid_range
3532 call self%getAttribute(cf_valid_range, valid_range)
3533 minvalue = valid_range(1)
3534 maxvalue = valid_range(2)
3535 else if (self%hasAttribute(cf_valid_min)) then
3536 flagmissing = cf_use_valid_min
3537 call self%getAttribute(cf_valid_min, minvalue)
3538 else if (self%hasAttribute(cf_valid_max)) then
3539 flagmissing = cf_use_valid_max
3540 call self%getAttribute(cf_valid_max, maxvalue)
3541 end if
3542
3543 end subroutine getcfattributes_i8
3544
3545 subroutine setvariablefillvalue_i8(self, fvalue)
3546 class(NcVariable), intent(inout) :: self
3547 integer(i8), intent(in) :: fvalue
3548
3549 if (.not. self%hasAttribute(cf_fill_value)) then
3550 call self%setAttribute(cf_fill_value, fvalue)
3551 end if
3552
3553 end subroutine setvariablefillvalue_i8
3554
3555
3556 function getslicingshape(self, instart, incnt, instride) result(out)
3557 class(NcVariable), intent(in) :: self
3558 integer(i4), intent(in), optional :: instart(:), incnt(:), instride(:)
3559 integer(i4), allocatable :: out(:)
3560
3561 out = self%getShape()
3562
3563 if (present(incnt)) then
3564 out(:size(incnt)) = incnt
3565 ! out = incnt
3566 else
3567 if (present(instart)) then
3568 out(:size(instart)) = out(:size(instart)) - (instart - 1)
3569 end if
3570 if (present(instride)) then
3571 out(:size(instride)) = out(:size(instride)) / instride
3572 end if
3573 end if
3574
3575 end function getslicingshape
3576
3577 function getreadshape(slcshape, outrank) result(out)
3578 integer(i4), intent(in) :: slcshape(:)
3579 integer(i4), intent(in) :: outrank
3580 integer(i4) :: naxis
3581 integer(i4), allocatable :: out(:)
3582
3583 naxis = count(slcshape > 1)
3584
3585 if (all(slcshape == 1)) then
3586 ! return 1-element array
3587 allocate(out(size(slcshape)))
3588 out(:) = 1
3589 else if (size(slcshape) == outrank) then
3590 ! sizes fit
3591 out = slcshape
3592 else if (naxis == outrank) then
3593 out = pack(slcshape, slcshape > 1)
3594 ! else if (naxis .lt. outrank) then
3595 ! would be nice...
3596 else
3597 write(*, *) "Given indices do not match output variable rank!"
3598 stop 1
3599 end if
3600 end function getreadshape
3601
3602 function getdtypefromstring(dtype)
3603 integer(i4) :: getDtypeFromString
3604 character(*) :: dtype
3605
3606 select case(dtype)
3607 case("f32")
3608 getdtypefromstring = nf90_float
3609 case("f64")
3610 getdtypefromstring = nf90_double
3611 case("i8")
3612 getdtypefromstring = nf90_byte
3613 case("i16")
3614 getdtypefromstring = nf90_short
3615 case("i32")
3616 getdtypefromstring = nf90_int
3617 case("i64")
3618 getdtypefromstring = nf90_int64
3619 case("char")
3620 getdtypefromstring = nf90_char
3621 case default
3622 write(*,*) "Datatype not understood: ", dtype
3623 stop 1
3624 end select
3625 end function getdtypefromstring
3626
3627 function getdtypefrominteger(dtype)
3628 character(4) :: getDtypeFromInteger
3629 integer(i4) :: dtype
3630
3631 select case(dtype)
3632 case(nf90_float)
3633 getdtypefrominteger = "f32"
3634 case(nf90_double)
3635 getdtypefrominteger = "f64"
3636 case(nf90_byte)
3637 getdtypefrominteger = "i8"
3638 case(nf90_short)
3639 getdtypefrominteger = "i16"
3640 case(nf90_int)
3641 getdtypefrominteger = "i32"
3642 case(nf90_int64)
3643 getdtypefrominteger = "i64"
3644 case(nf90_char)
3645 getdtypefrominteger = "char"
3646 case default
3647 write(*,*) "Datatype not understood: ", dtype
3648 stop 1
3649 end select
3650 end function getdtypefrominteger
3651
3652 function getcreationmode(cmode)
3653 character(*), intent(in), optional :: cmode
3654 integer(i4) :: getCreationMode
3655 character(256) :: mode
3656
3657 if (.not. (present(cmode))) then
3658 mode = "NETCDF4"
3659 else
3660 mode = cmode
3661 end if
3662
3663 select case(trim(mode))
3664 case ("NETCDF4")
3665 getcreationmode = nf90_netcdf4
3666 case ("SHARE")
3667 getcreationmode = nf90_share
3668 case ("CLASSIC")
3669 getcreationmode = nf90_classic_model
3670 case ("HDF5")
3671 getcreationmode = nf90_hdf5
3672 case ("64BIT_OFFSET")
3673 getcreationmode = nf90_64bit_offset
3674 case default
3675 print*, "Creation mode not understood: " // trim(mode)
3676 stop 1
3677 end select
3678
3679 end function getcreationmode
3680
3681 subroutine check(status, msg)
3682 integer(i4), intent(in) :: status
3683 character(*), intent(in) :: msg
3684
3685 if (status /= nf90_noerr) then
3686 write(*, *) msg
3687 write(*, *) nf90_strerror(status)
3688 stop 1
3689 end if
3690 end subroutine check
3691
3692end module mo_netcdf
get name abstract interface
get parent abstract interface
Comparison of real values for inequality.
Definition mo_utils.F90:289
Define number representations.
Definition mo_kind.F90:17
integer, parameter sp
Single Precision Real Kind.
Definition mo_kind.F90:44
integer, parameter i4
4 Byte Integer Kind
Definition mo_kind.F90:40
integer, parameter i8
8 Byte Integer Kind
Definition mo_kind.F90:42
integer, parameter i2
2 Byte Integer Kind
Definition mo_kind.F90:38
integer, parameter i1
1 Byte Integer Kind
Definition mo_kind.F90:36
integer, parameter dp
Double Precision Real Kind.
Definition mo_kind.F90:46
NetCDF Fortran 90 interface wrapper.
Definition mo_netcdf.f90:23
integer(i4), parameter cf_use_valid_max
CF use valid max.
Definition mo_netcdf.f90:51
character(9), parameter cf_valid_min
CF valid min.
Definition mo_netcdf.f90:47
integer(i4), parameter cf_use_valid_range
CF use valid range.
Definition mo_netcdf.f90:52
integer(i4), parameter cf_use_nan
CF use nan.
Definition mo_netcdf.f90:53
character(10), parameter cf_fill_value
CF fill value.
Definition mo_netcdf.f90:45
character(11), parameter cf_valid_range
CF valid range.
Definition mo_netcdf.f90:46
character(9), parameter cf_valid_max
CF valid max.
Definition mo_netcdf.f90:48
integer(i4), parameter cf_use_fill_value
CF use fill value.
Definition mo_netcdf.f90:49
integer(i4), parameter cf_use_valid_min
CF use valid min.
Definition mo_netcdf.f90:50
General utilities for the CHS library.
Definition mo_utils.F90:20
NetCDF attributable class.
Definition mo_netcdf.f90:68
NetCDF base class.
Definition mo_netcdf.f90:56
NetCDF Dataset class.
NetCDF Dimension class.
NetCDF Group class.
NetCDF Variable class.