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