MODFLOW 6 version 6.9.0.dev0
USGS Modular Hydrologic Model
Loading...
Searching...
No Matches
NCArrayReader.f90
Go to the documentation of this file.
1!> @brief This module contains the NCArrayReaderModule
2!!
3!! This module defines the netcdf_array_load interface
4!! which can read layered (UGRID) and non-layered (STRUCTURED)
5!! netcdf arrays stored in modflow6 designated input variables.
6!!
7!<
9
10 use kindmodule, only: dp, i4b, lgp
12 use simvariablesmodule, only: errmsg
19 use netcdf
20
21 implicit none
22 private
23 public :: netcdf_array_load
24
26 module procedure nc_array_load_int1d, nc_array_load_int2d, &
29 end interface netcdf_array_load
30
31contains
32
33 !> @brief does the grid support per layer variables
34 !<
35 function is_layered(grid) result(layered)
36 character(len=*), intent(in) :: grid
37 logical(LGP) :: layered
38 select case (grid)
39 case ('LAYERED MESH')
40 layered = .true.
41 case ('STRUCTURED')
42 layered = .false.
43 case default
44 layered = .false.
45 end select
46 end function is_layered
47
48 !> @brief Load NetCDF integer 1D array
49 !<
50 subroutine nc_array_load_int1d(int1d, mshape, idt, mf6_input, nc_vars, &
51 input_fname, iout, kper)
52 integer(I4B), dimension(:), pointer, contiguous, intent(in) :: int1d
53 integer(I4B), dimension(:), contiguous, pointer, intent(in) :: mshape !< model shape
54 type(inputparamdefinitiontype), intent(in) :: idt !< input data type object describing this record
55 type(modflowinputtype), intent(in) :: mf6_input
56 type(ncpackagevarstype), pointer, intent(in) :: nc_vars
57 character(len=*), intent(in) :: input_fname
58 integer(I4B), intent(in) :: iout
59 integer(I4B), optional, intent(in) :: kper !< flag if set > 0 indicates ts
60 integer(I4B) :: varid, iper
61 logical(LGP) :: layered
62
63 iper = 0
64 layered = (idt%layered .and. is_layered(nc_vars%grid))
65
66 if (present(kper)) then
67 iper = kper
68 end if
69
70 if (layered) then
71 if (iper > 0) then
72 call load_integer1d_layered_spd(int1d, mf6_input, mshape, idt, nc_vars, &
73 iper, input_fname)
74 else
75 call load_integer1d_layered(int1d, mf6_input, mshape, idt, nc_vars, &
76 input_fname)
77 end if
78 else
79 if (iper > 0) then
80 call load_integer1d_spd(int1d, mf6_input, mshape, idt, nc_vars, &
81 iper, input_fname)
82 else
83 varid = nc_vars%varid(idt%tagname)
84 call load_integer1d_type(int1d, mf6_input, mshape, idt, nc_vars, &
85 varid, input_fname)
86 end if
87 end if
88 end subroutine nc_array_load_int1d
89
90 !> @brief Load NetCDF integer 2D array
91 !<
92 subroutine nc_array_load_int2d(int2d, mshape, idt, mf6_input, nc_vars, &
93 input_fname, iout)
94 integer(I4B), dimension(:, :), pointer, contiguous, intent(in) :: int2d
95 integer(I4B), dimension(:), contiguous, pointer, intent(in) :: mshape !< model shape
96 type(inputparamdefinitiontype), intent(in) :: idt !< input data type object describing this record
97 type(modflowinputtype), intent(in) :: mf6_input
98 type(ncpackagevarstype), pointer, intent(in) :: nc_vars
99 character(len=*), intent(in) :: input_fname
100 integer(I4B), intent(in) :: iout
101 integer(I4B) :: varid
102 logical(LGP) :: layered
103
104 layered = (idt%layered .and. is_layered(nc_vars%grid))
105
106 if (layered) then
107 call load_integer2d_layered(int2d, mf6_input, mshape, idt, nc_vars, &
108 input_fname)
109 else
110 varid = nc_vars%varid(idt%tagname)
111 call load_integer2d_type(int2d, mf6_input, mshape, idt, nc_vars, &
112 varid, input_fname)
113 end if
114 end subroutine nc_array_load_int2d
115
116 !> @brief Load NetCDF integer 3D array
117 !<
118 subroutine nc_array_load_int3d(int3d, mshape, idt, mf6_input, nc_vars, &
119 input_fname, iout)
120 integer(I4B), dimension(:, :, :), pointer, contiguous, intent(in) :: int3d
121 integer(I4B), dimension(:), contiguous, pointer, intent(in) :: mshape !< model shape
122 type(inputparamdefinitiontype), intent(in) :: idt !< input data type object describing this record
123 type(modflowinputtype), intent(in) :: mf6_input
124 type(ncpackagevarstype), pointer, intent(in) :: nc_vars
125 character(len=*), intent(in) :: input_fname
126 integer(I4B), intent(in) :: iout
127 integer(I4B) :: varid
128 logical(LGP) :: layered
129
130 layered = (idt%layered .and. is_layered(nc_vars%grid))
131
132 if (layered) then
133 call load_integer3d_layered(int3d, mf6_input, mshape, idt, nc_vars, &
134 input_fname)
135 else
136 varid = nc_vars%varid(idt%tagname)
137 call load_integer3d_type(int3d, mf6_input, mshape, idt, nc_vars, &
138 varid, input_fname)
139 end if
140 end subroutine nc_array_load_int3d
141
142 !> @brief Load NetCDF double 1D array
143 !<
144 subroutine nc_array_load_dbl1d(dbl1d, mshape, idt, mf6_input, nc_vars, &
145 input_fname, iout, kper, iaux)
146 real(DP), dimension(:), pointer, contiguous, intent(in) :: dbl1d
147 integer(I4B), dimension(:), contiguous, pointer, intent(in) :: mshape !< model shape
148 type(inputparamdefinitiontype), intent(in) :: idt !< input data type object describing this record
149 type(modflowinputtype), intent(in) :: mf6_input
150 type(ncpackagevarstype), pointer, intent(in) :: nc_vars
151 character(len=*), intent(in) :: input_fname
152 integer(I4B), intent(in) :: iout
153 integer(I4B), optional, intent(in) :: kper !< flag if set > 0 indicates ts
154 integer(I4B), optional, intent(in) :: iaux
155 integer(I4B) :: varid, iper
156 logical(LGP) :: layered
157
158 iper = 0
159 layered = (idt%layered .and. is_layered(nc_vars%grid))
160
161 if (present(kper)) then
162 iper = kper
163 end if
164
165 if (layered) then
166 if (iper > 0) then
167 call load_double1d_layered_spd(dbl1d, mf6_input, mshape, idt, nc_vars, &
168 iper, input_fname, iaux)
169 else
170 call load_double1d_layered(dbl1d, mf6_input, mshape, idt, nc_vars, &
171 input_fname)
172 end if
173 else
174 if (iper > 0) then
175 call load_double1d_spd(dbl1d, mf6_input, mshape, idt, nc_vars, &
176 iper, input_fname, iaux)
177 else
178 varid = nc_vars%varid(idt%tagname)
179 call load_double1d_type(dbl1d, mf6_input, mshape, idt, nc_vars, &
180 varid, input_fname)
181 end if
182 end if
183 end subroutine nc_array_load_dbl1d
184
185 !> @brief Load NetCDF double 2D array
186 !<
187 subroutine nc_array_load_dbl2d(dbl2d, mshape, idt, mf6_input, nc_vars, &
188 input_fname, iout)
189 real(DP), dimension(:, :), pointer, contiguous, intent(in) :: dbl2d
190 integer(I4B), dimension(:), contiguous, pointer, intent(in) :: mshape !< model shape
191 type(inputparamdefinitiontype), intent(in) :: idt !< input data type object describing this record
192 type(modflowinputtype), intent(in) :: mf6_input
193 type(ncpackagevarstype), pointer, intent(in) :: nc_vars
194 character(len=*), intent(in) :: input_fname
195 integer(I4B), intent(in) :: iout
196 integer(I4B) :: varid
197 logical(LGP) :: layered
198
199 layered = (idt%layered .and. is_layered(nc_vars%grid))
200
201 if (layered) then
202 call load_double2d_layered(dbl2d, mf6_input, mshape, idt, nc_vars, &
203 input_fname)
204 else
205 varid = nc_vars%varid(idt%tagname)
206 call load_double2d_type(dbl2d, mf6_input, mshape, idt, nc_vars, &
207 varid, input_fname)
208 end if
209 end subroutine nc_array_load_dbl2d
210
211 !> @brief Load NetCDF double 3D array
212 !<
213 subroutine nc_array_load_dbl3d(dbl3d, mshape, idt, mf6_input, nc_vars, &
214 input_fname, iout)
215 real(DP), dimension(:, :, :), pointer, contiguous, intent(in) :: dbl3d
216 integer(I4B), dimension(:), contiguous, pointer, intent(in) :: mshape !< model shape
217 type(inputparamdefinitiontype), intent(in) :: idt !< input data type object describing this record
218 type(modflowinputtype), intent(in) :: mf6_input
219 type(ncpackagevarstype), pointer, intent(in) :: nc_vars
220 character(len=*), intent(in) :: input_fname
221 integer(I4B), intent(in) :: iout
222 integer(I4B) :: varid
223 logical(LGP) :: layered
224
225 layered = (idt%layered .and. is_layered(nc_vars%grid))
226
227 if (layered) then
228 call load_double3d_layered(dbl3d, mf6_input, mshape, idt, nc_vars, &
229 input_fname)
230 else
231 varid = nc_vars%varid(idt%tagname)
232 call load_double3d_type(dbl3d, mf6_input, mshape, idt, nc_vars, &
233 varid, input_fname)
234 end if
235 end subroutine nc_array_load_dbl3d
236
237 !> @brief load type 1d integer
238 !<
239 subroutine load_integer1d_type(int1d, mf6_input, mshape, idt, nc_vars, &
240 varid, input_fname)
241 integer(I4B), dimension(:), contiguous, pointer, intent(in) :: int1d
242 type(modflowinputtype), intent(in) :: mf6_input
243 integer(I4B), dimension(:), contiguous, pointer, intent(in) :: mshape
244 type(inputparamdefinitiontype), intent(in) :: idt
245 type(ncpackagevarstype), pointer, intent(in) :: nc_vars
246 integer(I4B), intent(in) :: varid
247 character(len=*), intent(in) :: input_fname
248 integer(I4B), dimension(:), allocatable :: array_shape
249 integer(I4B), dimension(:, :, :), contiguous, pointer :: int3d_ptr
250 integer(I4B), dimension(:, :), contiguous, pointer :: int2d_ptr
251 integer(I4B) :: nvals
252
253 ! initialize
254 nvals = 0
255
256 if (idt%shape == 'NODES') then
257 ! set number of values
258 nvals = product(mshape)
259 if (size(mshape) == 3) then
260 int3d_ptr(1:mshape(3), 1:mshape(2), 1:mshape(1)) => int1d(1:nvals)
261 call nf_verify(nf90_get_var(nc_vars%ncid, varid, int3d_ptr), &
262 nc_vars%nc_fname)
263 else if (size(mshape) == 2) then
264 int2d_ptr(1:mshape(2), 1:mshape(1)) => int1d(1:nvals)
265 call nf_verify(nf90_get_var(nc_vars%ncid, varid, int2d_ptr), &
266 nc_vars%nc_fname)
267 else if (size(mshape) == 1) then
268 call nf_verify(nf90_get_var(nc_vars%ncid, varid, int1d), nc_vars%nc_fname)
269 end if
270 else
271 ! interpret shape
272 call get_shape_from_string(idt%shape, array_shape, mf6_input%mempath)
273 ! set nvals
274 nvals = array_shape(1)
275 ! read and set data
276 call nf_verify(nf90_get_var(nc_vars%ncid, varid, int1d), nc_vars%nc_fname)
277 end if
278 end subroutine load_integer1d_type
279
280 !> @brief load type 1d double
281 !<
282 subroutine load_integer1d_spd(int1d, mf6_input, mshape, idt, nc_vars, &
283 iper, input_fname)
284 use tdismodule, only: kper
285 use constantsmodule, only: dnodata
286 integer(I4B), dimension(:), contiguous, pointer, intent(in) :: int1d
287 type(modflowinputtype), intent(in) :: mf6_input
288 integer(I4B), dimension(:), contiguous, pointer, intent(in) :: mshape
289 type(inputparamdefinitiontype), intent(in) :: idt
290 type(ncpackagevarstype), pointer, intent(in) :: nc_vars
291 integer(I4B), intent(in) :: iper
292 character(len=*), intent(in) :: input_fname
293 integer(I4B), dimension(:), allocatable :: layer_shape
294 integer(I4B) :: varid, nlay, ncpl
295
296 ! set varid
297 varid = nc_vars%varid(idt%tagname)
298
299 call get_layered_shape(mshape, nlay, layer_shape)
300 ncpl = product(layer_shape)
301
302 select case (idt%shape)
303 case ('NCPL', 'NAUX NCPL')
304 if (nc_vars%grid == 'STRUCTURED') then
305 call nf_verify(nf90_get_var(nc_vars%ncid, varid, int1d, &
306 start=(/1, 1, kper/), &
307 count=(/mshape(3), mshape(2), 1/)), &
308 nc_vars%nc_fname)
309 else if (nc_vars%grid == 'LAYERED MESH') then
310 call nf_verify(nf90_get_var(nc_vars%ncid, varid, int1d, &
311 start=(/1, kper/), count=(/ncpl, 1/)), &
312 nc_vars%nc_fname)
313 end if
314 case ('NODES', 'NAUX NODES')
315 write (errmsg, '(a,a,a)') &
316 'Timeseries netcdf input read not supported for full grid int1d &
317 &type ('//trim(idt%tagname)//').'
318 call store_error(errmsg)
319 call store_error_filename(input_fname)
320 case default
321 end select
322 end subroutine load_integer1d_spd
323
324 !> @brief load type 1d integer layered
325 !<
326 subroutine load_integer1d_layered(int1d, mf6_input, mshape, idt, nc_vars, &
327 input_fname)
328 integer(I4B), dimension(:), contiguous, pointer, intent(in) :: int1d
329 type(modflowinputtype), intent(in) :: mf6_input
330 integer(I4B), dimension(:), contiguous, pointer, intent(in) :: mshape
331 type(inputparamdefinitiontype), intent(in) :: idt
332 type(ncpackagevarstype), pointer, intent(in) :: nc_vars
333 character(len=*), intent(in) :: input_fname
334 integer(I4B), dimension(:), allocatable :: layer_shape
335 integer(I4B) :: nlay, varid
336 integer(I4B) :: k, ncpl
337 integer(I4B) :: index_start, index_stop
338 integer(I4B), dimension(:), contiguous, pointer :: int1d_ptr
339
340 nullify (int1d_ptr)
341
342 call get_layered_shape(mshape, nlay, layer_shape)
343
344 ncpl = product(layer_shape)
345 index_start = 1
346 do k = 1, nlay
347 varid = nc_vars%varid(idt%tagname, layer=k)
348 index_stop = index_start + ncpl - 1
349 int1d_ptr(1:ncpl) => int1d(index_start:index_stop)
350 call nf_verify(nf90_get_var(nc_vars%ncid, varid, int1d_ptr), &
351 nc_vars%nc_fname)
352 index_start = index_stop + 1
353 end do
354 end subroutine load_integer1d_layered
355
356 !> @brief load type 1d integer layered
357 !<
358 subroutine load_integer1d_layered_spd(int1d, mf6_input, mshape, idt, nc_vars, &
359 iper, input_fname)
360 use tdismodule, only: kper
361 use constantsmodule, only: dnodata
362 integer(I4B), dimension(:), contiguous, pointer, intent(in) :: int1d
363 type(modflowinputtype), intent(in) :: mf6_input
364 integer(I4B), dimension(:), contiguous, pointer, intent(in) :: mshape
365 type(inputparamdefinitiontype), intent(in) :: idt
366 type(ncpackagevarstype), pointer, intent(in) :: nc_vars
367 integer(I4B), intent(in) :: iper
368 character(len=*), intent(in) :: input_fname
369 integer(I4B), dimension(:), allocatable :: layer_shape
370 integer(I4B) :: nlay, varid
371 integer(I4B) :: ncpl, nvals
372
373 call get_layered_shape(mshape, nlay, layer_shape)
374 nvals = product(mshape)
375 ncpl = product(layer_shape)
376
377 varid = nc_vars%varid(idt%tagname)
378 select case (idt%shape)
379 case ('NCPL', 'NAUX NCPL')
380 call nf_verify(nf90_get_var(nc_vars%ncid, varid, int1d, &
381 start=(/1, kper/), count=(/ncpl, 1/)), &
382 nc_vars%nc_fname)
383 case ('NODES', 'NAUX NODES')
384 call nf_verify(nf90_get_var(nc_vars%ncid, varid, int1d, &
385 start=(/1, kper/), count=(/nvals, 1/)), &
386 nc_vars%nc_fname)
387 case default
388 end select
389 end subroutine load_integer1d_layered_spd
390
391 !> @brief load type 2d integer
392 !<
393 subroutine load_integer2d_type(int2d, mf6_input, mshape, idt, nc_vars, varid, &
394 input_fname)
395 integer(I4B), dimension(:, :), contiguous, pointer, intent(in) :: int2d
396 type(modflowinputtype), intent(in) :: mf6_input
397 integer(I4B), dimension(:), contiguous, pointer, intent(in) :: mshape
398 type(inputparamdefinitiontype), intent(in) :: idt
399 type(ncpackagevarstype), pointer, intent(in) :: nc_vars
400 integer(I4B), intent(in) :: varid
401 character(len=*), intent(in) :: input_fname
402 integer(I4B), dimension(:), contiguous, pointer :: int1d_ptr
403 integer(I4B), dimension(:), allocatable :: array_shape
404 integer(I4B) :: ncpl, nlay
405
406 nullify (int1d_ptr)
407
408 if (nc_vars%grid == 'STRUCTURED') then
409 call nf_verify(nf90_get_var(nc_vars%ncid, varid, int2d), nc_vars%nc_fname)
410 else if (nc_vars%grid == 'LAYERED MESH') then
411 call get_layered_shape(mshape, nlay, array_shape)
412 ncpl = product(array_shape)
413 int1d_ptr(1:ncpl) => int2d(:, :)
414 call nf_verify(nf90_get_var(nc_vars%ncid, varid, int1d_ptr), &
415 nc_vars%nc_fname)
416 end if
417 end subroutine load_integer2d_type
418
419 !> @brief load type 2d integer layered
420 !<
421 subroutine load_integer2d_layered(int2d, mf6_input, mshape, idt, nc_vars, &
422 input_fname)
423 integer(I4B), dimension(:, :), contiguous, pointer, intent(in) :: int2d
424 type(modflowinputtype), intent(in) :: mf6_input
425 integer(I4B), dimension(:), contiguous, pointer, intent(in) :: mshape
426 type(inputparamdefinitiontype), intent(in) :: idt
427 type(ncpackagevarstype), pointer, intent(in) :: nc_vars
428 character(len=*), intent(in) :: input_fname
429 integer(I4B), dimension(:), allocatable :: layer_shape
430 integer(I4B) :: k
431 integer(I4B) :: ncpl, nlay, varid
432 integer(I4B), dimension(:), contiguous, pointer :: int1d_ptr
433
434 nullify (int1d_ptr)
435
436 if (size(mshape) == 3) then
437 write (errmsg, '(a,a,a)') &
438 'Layered netcdf read not supported for DIS int2d type ('// &
439 trim(idt%tagname)//').'
440 call store_error(errmsg)
441 call store_error_filename(input_fname)
442 else if (size(mshape) == 2) then
443 call get_layered_shape(mshape, nlay, layer_shape)
444 ncpl = layer_shape(1)
445 do k = 1, nlay
446 varid = nc_vars%varid(idt%tagname, layer=k)
447 int1d_ptr(1:ncpl) => int2d(1:ncpl, k)
448 call nf_verify(nf90_get_var(nc_vars%ncid, varid, int1d_ptr), &
449 nc_vars%nc_fname)
450 end do
451 end if
452 end subroutine load_integer2d_layered
453
454 !> @brief load type 3d integer
455 !<
456 subroutine load_integer3d_type(int3d, mf6_input, mshape, idt, nc_vars, varid, &
457 input_fname)
458 integer(I4B), dimension(:, :, :), contiguous, pointer, intent(in) :: int3d
459 type(modflowinputtype), intent(in) :: mf6_input
460 integer(I4B), dimension(:), contiguous, pointer, intent(in) :: mshape
461 type(inputparamdefinitiontype), intent(in) :: idt
462 type(ncpackagevarstype), pointer, intent(in) :: nc_vars
463 integer(I4B), intent(in) :: varid
464 character(len=*), intent(in) :: input_fname
465 call nf_verify(nf90_get_var(nc_vars%ncid, varid, int3d), nc_vars%nc_fname)
466 end subroutine load_integer3d_type
467
468 !> @brief load type 3d integer layered
469 !<
470 subroutine load_integer3d_layered(int3d, mf6_input, mshape, idt, nc_vars, &
471 input_fname)
472 integer(I4B), dimension(:, :, :), contiguous, pointer, intent(in) :: int3d
473 type(modflowinputtype), intent(in) :: mf6_input
474 integer(I4B), dimension(:), contiguous, pointer, intent(in) :: mshape
475 type(inputparamdefinitiontype), intent(in) :: idt
476 type(ncpackagevarstype), pointer, intent(in) :: nc_vars
477 character(len=*), intent(in) :: input_fname
478 integer(I4B), dimension(:), allocatable :: layer_shape
479 integer(I4B) :: k !, i, j
480 integer(I4B) :: ncpl, nlay, varid
481 integer(I4B) :: index_start, index_stop
482 integer(I4B), dimension(:), contiguous, pointer :: int1d_ptr
483
484 nullify (int1d_ptr)
485 index_start = 1
486 call get_layered_shape(mshape, nlay, layer_shape)
487 ncpl = product(layer_shape)
488
489 do k = 1, nlay
490 varid = nc_vars%varid(idt%tagname, layer=k)
491 index_stop = index_start + ncpl - 1
492 int1d_ptr(1:ncpl) => int3d(:, :, k:k)
493 call nf_verify(nf90_get_var(nc_vars%ncid, varid, int1d_ptr), &
494 nc_vars%nc_fname)
495 index_start = index_stop + 1
496 end do
497 end subroutine load_integer3d_layered
498
499 !> @brief load type 1d double
500 !<
501 subroutine load_double1d_type(dbl1d, mf6_input, mshape, idt, nc_vars, &
502 varid, input_fname)
503 real(DP), dimension(:), contiguous, pointer, intent(in) :: dbl1d
504 type(modflowinputtype), intent(in) :: mf6_input
505 integer(I4B), dimension(:), contiguous, pointer, intent(in) :: mshape
506 type(inputparamdefinitiontype), intent(in) :: idt
507 type(ncpackagevarstype), pointer, intent(in) :: nc_vars
508 integer(I4B), intent(in) :: varid
509 character(len=*), intent(in) :: input_fname
510 integer(I4B), dimension(:), allocatable :: array_shape
511 real(DP), dimension(:, :, :), contiguous, pointer :: dbl3d_ptr
512 real(DP), dimension(:, :), contiguous, pointer :: dbl2d_ptr
513 integer(I4B) :: nvals
514
515 ! initialize
516 nvals = 0
517
518 if (idt%shape == 'NODES') then
519 ! set number of values
520 nvals = product(mshape)
521 if (size(mshape) == 3) then
522 dbl3d_ptr(1:mshape(3), 1:mshape(2), 1:mshape(1)) => dbl1d(1:nvals)
523 call nf_verify(nf90_get_var(nc_vars%ncid, varid, dbl3d_ptr), &
524 nc_vars%nc_fname)
525 else if (size(mshape) == 2) then
526 dbl2d_ptr(1:mshape(2), 1:mshape(1)) => dbl1d(1:nvals)
527 call nf_verify(nf90_get_var(nc_vars%ncid, varid, dbl2d_ptr), &
528 nc_vars%nc_fname)
529 else if (size(mshape) == 1) then
530 call nf_verify(nf90_get_var(nc_vars%ncid, varid, dbl1d), nc_vars%nc_fname)
531 end if
532 else
533 ! interpret shape
534 call get_shape_from_string(idt%shape, array_shape, mf6_input%mempath)
535 ! set nvals
536 nvals = array_shape(1)
537 ! read and set data
538 call nf_verify(nf90_get_var(nc_vars%ncid, varid, dbl1d), nc_vars%nc_fname)
539 end if
540 end subroutine load_double1d_type
541
542 !> @brief load type 1d double
543 !<
544 subroutine load_double1d_spd(dbl1d, mf6_input, mshape, idt, nc_vars, &
545 iper, input_fname, iaux)
546 use tdismodule, only: kper
547 use constantsmodule, only: dnodata
548 real(DP), dimension(:), contiguous, pointer, intent(in) :: dbl1d
549 type(modflowinputtype), intent(in) :: mf6_input
550 integer(I4B), dimension(:), contiguous, pointer, intent(in) :: mshape
551 type(inputparamdefinitiontype), intent(in) :: idt
552 type(ncpackagevarstype), pointer, intent(in) :: nc_vars
553 integer(I4B), intent(in) :: iper
554 character(len=*), intent(in) :: input_fname
555 integer(I4B), optional, intent(in) :: iaux
556 integer(I4B), dimension(:), allocatable :: layer_shape
557 real(DP), dimension(:, :, :), contiguous, pointer :: dbl3d
558 integer(I4B) :: varid, nlay, ncpl, nvals
559 integer(I4B) :: n
560
561 ! initialize
562 n = 0
563
564 ! set varid
565 if (present(iaux)) then
566 varid = nc_vars%varid(idt%tagname, iaux=iaux)
567 else
568 varid = nc_vars%varid(idt%tagname)
569 end if
570
571 call get_layered_shape(mshape, nlay, layer_shape)
572 ncpl = product(layer_shape)
573 nvals = product(mshape)
574
575 select case (idt%shape)
576 case ('NCPL', 'NAUX NCPL')
577 if (nc_vars%grid == 'STRUCTURED') then
578 call nf_verify(nf90_get_var(nc_vars%ncid, varid, dbl1d, &
579 start=(/1, 1, kper/), &
580 count=(/mshape(3), mshape(2), 1/)), &
581 nc_vars%nc_fname)
582 else if (nc_vars%grid == 'LAYERED MESH') then
583 call nf_verify(nf90_get_var(nc_vars%ncid, varid, dbl1d, &
584 start=(/1, kper/), count=(/ncpl, 1/)), &
585 nc_vars%nc_fname)
586 end if
587 case ('NODES', 'NAUX NODES')
588 if (nc_vars%grid == 'STRUCTURED') then
589 dbl3d(1:mshape(3), 1:mshape(2), 1:mshape(1)) => dbl1d(1:nvals)
590 call nf_verify(nf90_get_var(nc_vars%ncid, varid, dbl3d, &
591 start=(/1, 1, 1, kper/), &
592 count=(/mshape(3), mshape(2), mshape(1), &
593 1/)), nc_vars%nc_fname)
594 else if (nc_vars%grid == 'LAYERED MESH') then
595 call nf_verify(nf90_get_var(nc_vars%ncid, varid, dbl1d, &
596 start=(/1, kper/), count=(/nvals, 1/)), &
597 nc_vars%nc_fname)
598 end if
599 case default
600 end select
601 end subroutine load_double1d_spd
602
603 !> @brief load type 1d double layered
604 !<
605 subroutine load_double1d_layered(dbl1d, mf6_input, mshape, idt, nc_vars, &
606 input_fname)
607 real(DP), dimension(:), contiguous, pointer, intent(in) :: dbl1d
608 type(modflowinputtype), intent(in) :: mf6_input
609 integer(I4B), dimension(:), contiguous, pointer, intent(in) :: mshape
610 type(inputparamdefinitiontype), intent(in) :: idt
611 type(ncpackagevarstype), pointer, intent(in) :: nc_vars
612 character(len=*), intent(in) :: input_fname
613 integer(I4B), dimension(:), allocatable :: layer_shape
614 integer(I4B) :: nlay, varid
615 integer(I4B) :: k, ncpl
616 integer(I4B) :: index_start, index_stop
617 real(DP), dimension(:), contiguous, pointer :: dbl1d_ptr
618
619 nullify (dbl1d_ptr)
620 index_start = 1
621 call get_layered_shape(mshape, nlay, layer_shape)
622 ncpl = product(layer_shape)
623
624 do k = 1, nlay
625 varid = nc_vars%varid(idt%tagname, layer=k)
626 index_stop = index_start + ncpl - 1
627 dbl1d_ptr(1:ncpl) => dbl1d(index_start:index_stop)
628 call nf_verify(nf90_get_var(nc_vars%ncid, varid, dbl1d_ptr), &
629 nc_vars%nc_fname)
630 index_start = index_stop + 1
631 end do
632 end subroutine load_double1d_layered
633
634 !> @brief load type 1d double layered
635 !<
636 subroutine load_double1d_layered_spd(dbl1d, mf6_input, mshape, idt, nc_vars, &
637 iper, input_fname, iaux)
638 use tdismodule, only: kper
639 use constantsmodule, only: dnodata
640 real(DP), dimension(:), contiguous, pointer, intent(in) :: dbl1d
641 type(modflowinputtype), intent(in) :: mf6_input
642 integer(I4B), dimension(:), contiguous, pointer, intent(in) :: mshape
643 type(inputparamdefinitiontype), intent(in) :: idt
644 type(ncpackagevarstype), pointer, intent(in) :: nc_vars
645 integer(I4B), intent(in) :: iper
646 character(len=*), intent(in) :: input_fname
647 integer(I4B), optional, intent(in) :: iaux
648 integer(I4B), dimension(:), allocatable :: layer_shape
649 integer(I4B) :: nlay, varid
650 integer(I4B) :: k, n, ncpl, idx
651 real(DP), dimension(:), contiguous, pointer :: dbl1d_ptr
652
653 call get_layered_shape(mshape, nlay, layer_shape)
654 ncpl = product(layer_shape)
655 allocate (dbl1d_ptr(ncpl))
656
657 do k = 1, nlay
658 if (present(iaux)) then
659 varid = nc_vars%varid(idt%tagname, layer=k, iaux=iaux)
660 else
661 varid = nc_vars%varid(idt%tagname, layer=k)
662 end if
663 call nf_verify(nf90_get_var(nc_vars%ncid, varid, dbl1d_ptr, &
664 start=(/1, kper/), count=(/ncpl, 1/)), &
665 nc_vars%nc_fname)
666 if (idt%shape == 'NODES' .or. idt%shape == 'NAUX NODES') then
667 do n = 1, ncpl
668 idx = (k - 1) * ncpl + n
669 dbl1d(idx) = dbl1d_ptr(n)
670 end do
671 else if (idt%shape == 'NCPL' .or. idt%shape == 'NAUX NCPL') then
672 do n = 1, ncpl
673 dbl1d(n) = dbl1d_ptr(n)
674 end do
675 end if
676 end do
677
678 ! cleanup
679 deallocate (dbl1d_ptr)
680 end subroutine load_double1d_layered_spd
681
682 !> @brief load type 2d double
683 !<
684 subroutine load_double2d_type(dbl2d, mf6_input, mshape, idt, nc_vars, varid, &
685 input_fname)
686 real(DP), dimension(:, :), contiguous, pointer, intent(in) :: dbl2d
687 type(modflowinputtype), intent(in) :: mf6_input
688 integer(I4B), dimension(:), contiguous, pointer, intent(in) :: mshape
689 type(inputparamdefinitiontype), intent(in) :: idt
690 type(ncpackagevarstype), pointer, intent(in) :: nc_vars
691 integer(I4B), intent(in) :: varid
692 character(len=*), intent(in) :: input_fname
693 real(DP), dimension(:), contiguous, pointer :: dbl1d_ptr
694 integer(I4B), dimension(:), allocatable :: array_shape
695 integer(I4B) :: ncpl, nlay
696
697 nullify (dbl1d_ptr)
698
699 if (nc_vars%grid == 'STRUCTURED') then
700 call nf_verify(nf90_get_var(nc_vars%ncid, varid, dbl2d), nc_vars%nc_fname)
701 else if (nc_vars%grid == 'LAYERED MESH') then
702 call get_layered_shape(mshape, nlay, array_shape)
703 ncpl = product(array_shape)
704 dbl1d_ptr(1:ncpl) => dbl2d(:, :)
705 call nf_verify(nf90_get_var(nc_vars%ncid, varid, dbl1d_ptr), &
706 nc_vars%nc_fname)
707 end if
708 end subroutine load_double2d_type
709
710 !> @brief load type 2d double layered
711 !<
712 subroutine load_double2d_layered(dbl2d, mf6_input, mshape, idt, nc_vars, &
713 input_fname)
714 real(DP), dimension(:, :), contiguous, pointer, intent(in) :: dbl2d
715 type(modflowinputtype), intent(in) :: mf6_input
716 integer(I4B), dimension(:), contiguous, pointer, intent(in) :: mshape
717 type(inputparamdefinitiontype), intent(in) :: idt
718 type(ncpackagevarstype), pointer, intent(in) :: nc_vars
719 character(len=*), intent(in) :: input_fname
720 integer(I4B), dimension(:), allocatable :: layer_shape
721 integer(I4B) :: k
722 integer(I4B) :: ncpl, nlay, varid
723 real(DP), dimension(:), contiguous, pointer :: dbl1d_ptr
724
725 nullify (dbl1d_ptr)
726
727 if (size(mshape) == 3) then
728 write (errmsg, '(a,a,a)') &
729 'Layered netcdf read not supported for DIS dbl2d type ('// &
730 trim(idt%tagname)//').'
731 call store_error(errmsg)
732 call store_error_filename(input_fname)
733 else if (size(mshape) == 2) then
734 call get_layered_shape(mshape, nlay, layer_shape)
735 ncpl = layer_shape(1)
736 do k = 1, nlay
737 varid = nc_vars%varid(idt%tagname, layer=k)
738 dbl1d_ptr(1:ncpl) => dbl2d(1:ncpl, k)
739 call nf_verify(nf90_get_var(nc_vars%ncid, varid, dbl1d_ptr), &
740 nc_vars%nc_fname)
741 end do
742 end if
743 end subroutine load_double2d_layered
744
745 !> @brief load type 3d double
746 !<
747 subroutine load_double3d_type(dbl3d, mf6_input, mshape, idt, nc_vars, varid, &
748 input_fname)
749 real(DP), dimension(:, :, :), contiguous, pointer, intent(in) :: dbl3d
750 type(modflowinputtype), intent(in) :: mf6_input
751 integer(I4B), dimension(:), contiguous, pointer, intent(in) :: mshape
752 type(inputparamdefinitiontype), intent(in) :: idt
753 type(ncpackagevarstype), pointer, intent(in) :: nc_vars
754 integer(I4B), intent(in) :: varid
755 character(len=*), intent(in) :: input_fname
756 !
757 call nf_verify(nf90_get_var(nc_vars%ncid, varid, dbl3d), nc_vars%nc_fname)
758 end subroutine load_double3d_type
759
760 !> @brief load type 3d double layered
761 !<
762 subroutine load_double3d_layered(dbl3d, mf6_input, mshape, idt, nc_vars, &
763 input_fname)
764 real(DP), dimension(:, :, :), contiguous, pointer, intent(in) :: dbl3d
765 type(modflowinputtype), intent(in) :: mf6_input
766 integer(I4B), dimension(:), contiguous, pointer, intent(in) :: mshape
767 type(inputparamdefinitiontype), intent(in) :: idt
768 type(ncpackagevarstype), pointer, intent(in) :: nc_vars
769 character(len=*), intent(in) :: input_fname
770 integer(I4B), dimension(:), allocatable :: layer_shape
771 integer(I4B) :: k !, i, j
772 integer(I4B) :: ncpl, nlay, varid
773 integer(I4B) :: index_start, index_stop
774 real(DP), dimension(:), contiguous, pointer :: dbl1d_ptr
775
776 nullify (dbl1d_ptr)
777
778 call get_layered_shape(mshape, nlay, layer_shape)
779
780 ncpl = product(layer_shape)
781 index_start = 1
782 do k = 1, nlay
783 varid = nc_vars%varid(idt%tagname, layer=k)
784 index_stop = index_start + ncpl - 1
785 dbl1d_ptr(1:ncpl) => dbl3d(:, :, k:k)
786 call nf_verify(nf90_get_var(nc_vars%ncid, varid, dbl1d_ptr), &
787 nc_vars%nc_fname)
788 index_start = index_stop + 1
789 end do
790 end subroutine load_double3d_layered
791
792end module ncarrayreadermodule
This module contains simulation constants.
Definition Constants.f90:9
integer(i4b), parameter linelength
maximum length of a standard line
Definition Constants.f90:45
real(dp), parameter dnodata
real no data constant
Definition Constants.f90:95
Input definition module.
This module defines variable data types.
Definition kind.f90:8
This module contains the ModflowInputModule.
This module contains the NCArrayReaderModule.
subroutine load_double1d_layered(dbl1d, mf6_input, mshape, idt, nc_vars, input_fname)
load type 1d double layered
subroutine nc_array_load_int2d(int2d, mshape, idt, mf6_input, nc_vars, input_fname, iout)
Load NetCDF integer 2D array.
subroutine load_integer1d_layered_spd(int1d, mf6_input, mshape, idt, nc_vars, iper, input_fname)
load type 1d integer layered
subroutine load_double3d_layered(dbl3d, mf6_input, mshape, idt, nc_vars, input_fname)
load type 3d double layered
subroutine nc_array_load_dbl2d(dbl2d, mshape, idt, mf6_input, nc_vars, input_fname, iout)
Load NetCDF double 2D array.
subroutine load_integer3d_layered(int3d, mf6_input, mshape, idt, nc_vars, input_fname)
load type 3d integer layered
subroutine load_integer1d_type(int1d, mf6_input, mshape, idt, nc_vars, varid, input_fname)
load type 1d integer
subroutine load_double3d_type(dbl3d, mf6_input, mshape, idt, nc_vars, varid, input_fname)
load type 3d double
logical(lgp) function is_layered(grid)
does the grid support per layer variables
subroutine nc_array_load_int3d(int3d, mshape, idt, mf6_input, nc_vars, input_fname, iout)
Load NetCDF integer 3D array.
subroutine load_double2d_type(dbl2d, mf6_input, mshape, idt, nc_vars, varid, input_fname)
load type 2d double
subroutine load_integer1d_spd(int1d, mf6_input, mshape, idt, nc_vars, iper, input_fname)
load type 1d double
subroutine load_integer3d_type(int3d, mf6_input, mshape, idt, nc_vars, varid, input_fname)
load type 3d integer
subroutine load_integer2d_layered(int2d, mf6_input, mshape, idt, nc_vars, input_fname)
load type 2d integer layered
subroutine load_integer2d_type(int2d, mf6_input, mshape, idt, nc_vars, varid, input_fname)
load type 2d integer
subroutine nc_array_load_int1d(int1d, mshape, idt, mf6_input, nc_vars, input_fname, iout, kper)
Load NetCDF integer 1D array.
subroutine load_double1d_layered_spd(dbl1d, mf6_input, mshape, idt, nc_vars, iper, input_fname, iaux)
load type 1d double layered
subroutine load_integer1d_layered(int1d, mf6_input, mshape, idt, nc_vars, input_fname)
load type 1d integer layered
subroutine load_double1d_type(dbl1d, mf6_input, mshape, idt, nc_vars, varid, input_fname)
load type 1d double
subroutine load_double2d_layered(dbl2d, mf6_input, mshape, idt, nc_vars, input_fname)
load type 2d double layered
subroutine nc_array_load_dbl3d(dbl3d, mshape, idt, mf6_input, nc_vars, input_fname, iout)
Load NetCDF double 3D array.
subroutine nc_array_load_dbl1d(dbl1d, mshape, idt, mf6_input, nc_vars, input_fname, iout, kper, iaux)
Load NetCDF double 1D array.
subroutine load_double1d_spd(dbl1d, mf6_input, mshape, idt, nc_vars, iper, input_fname, iaux)
load type 1d double
This module contains the NCFileVarsModule.
Definition NCFileVars.f90:7
This module contains the NetCDFCommonModule.
subroutine, public nf_verify(res, nc_fname)
error check a netcdf-fortran interface call
This module contains simulation methods.
Definition Sim.f90:10
subroutine, public store_error(msg, terminate)
Store an error message.
Definition Sim.f90:94
subroutine, public store_error_filename(filename, terminate)
Store the erroring file name.
Definition Sim.f90:208
This module contains simulation variables.
character(len=maxcharlen) errmsg
error message string
This module contains the SourceCommonModule.
subroutine, public get_layered_shape(mshape, nlay, layer_shape)
subroutine, public get_shape_from_string(shape_string, array_shape, memorypath)
integer(i4b), pointer, public kper
current stress period number
Definition tdis.f90:26
Input parameter definition. Describes an input parameter.
derived type for storing input definition for a file
Type describing input variables for a package in NetCDF file.