39 integer(I4B) :: blocknum
40 logical(LGP) :: deferred_shape = .false.
41 integer(I4B) :: deferred_size_init = 5
42 character(len=LENMEMPATH) :: mempath
43 character(len=LENMEMPATH) :: component_mempath
45 integer(I4B),
dimension(:),
allocatable :: startidx
46 integer(I4B),
dimension(:),
allocatable :: numcols
72 component_mempath)
result(struct_array)
74 integer(I4B),
intent(in) :: ncol
75 integer(I4B),
intent(in) :: nrow
76 integer(I4B),
intent(in) :: blocknum
77 character(len=*),
intent(in) :: mempath
78 character(len=*),
intent(in) :: component_mempath
82 allocate (struct_array)
85 struct_array%mf6_input = mf6_input
88 struct_array%ncol = ncol
91 struct_array%nrow = nrow
92 if (struct_array%nrow == -1)
then
94 struct_array%deferred_shape = .true.
98 if (blocknum > 0)
then
99 struct_array%blocknum = blocknum
101 struct_array%blocknum = 0
105 struct_array%mempath = mempath
106 struct_array%component_mempath = component_mempath
109 allocate (struct_array%struct_vectors(ncol))
110 allocate (struct_array%startidx(ncol))
111 allocate (struct_array%numcols(ncol))
118 deallocate (struct_array%struct_vectors)
119 deallocate (struct_array%startidx)
120 deallocate (struct_array%numcols)
121 deallocate (struct_array)
122 nullify (struct_array)
129 integer(I4B),
intent(in) :: icol
132 integer(I4B) :: numcol
140 if (this%deferred_shape)
then
141 sv%size = this%deferred_size_init
147 select case (idt%datatype)
149 call this%allocate_int_type(sv)
151 call this%allocate_dbl_type(sv)
152 case (
'STRING',
'KEYWORD')
153 call this%allocate_charstr_type(sv)
155 call this%allocate_int1d_type(sv)
156 if (sv%memtype == 5)
then
160 call this%allocate_dbl1d_type(sv)
163 errmsg =
'IDM unimplemented. StructArray::mem_create_vector &
164 &type='//trim(idt%datatype)
169 this%struct_vectors(icol) = sv
170 this%numcols(icol) = numcol
172 this%startidx(icol) = 1
174 this%startidx(icol) = this%startidx(icol - 1) + this%numcols(icol - 1)
180 integer(I4B) ::
count
181 count =
size(this%struct_vectors)
190 function get(this, idx)
result(sv)
192 integer(I4B),
intent(in) :: idx
202 integer(I4B),
dimension(:),
pointer,
contiguous :: int1d
203 integer(I4B) :: j, nrow
205 if (this%deferred_shape)
then
207 nrow = this%deferred_size_init
208 allocate (int1d(this%deferred_size_init))
212 call mem_allocate(int1d, this%nrow, sv%idt%mf6varname, this%mempath)
229 real(DP),
dimension(:),
pointer,
contiguous :: dbl1d
230 integer(I4B) :: j, nrow
232 if (this%deferred_shape)
then
234 nrow = this%deferred_size_init
235 allocate (dbl1d(this%deferred_size_init))
239 call mem_allocate(dbl1d, this%nrow, sv%idt%mf6varname, this%mempath)
259 if (this%deferred_shape)
then
260 allocate (charstr1d(this%deferred_size_init))
263 sv%idt%mf6varname, this%mempath)
271 sv%charstr1d => charstr1d
282 integer(I4B),
dimension(:, :),
pointer,
contiguous :: int2d
284 integer(I4B),
pointer :: ncelldim, exgid
285 character(len=LENMEMPATH) :: input_mempath
286 character(len=LENMODELNAME) :: mname
289 integer(I4B) :: nrow, n, m
291 if (sv%idt%shape ==
'NCELLDIM')
then
293 if (this%mf6_input%component_type ==
'EXG')
then
295 call mem_setptr(exgid,
'EXGID', this%mf6_input%mempath)
298 if (sv%idt%tagname ==
'CELLIDM1')
then
299 call mem_setptr(charstr1d,
'EXGMNAMEA', input_mempath)
300 else if (sv%idt%tagname ==
'CELLIDM2')
then
301 call mem_setptr(charstr1d,
'EXGMNAMEB', input_mempath)
305 mname = charstr1d(exgid)
309 call mem_setptr(ncelldim, sv%idt%shape, input_mempath)
311 call mem_setptr(ncelldim, sv%idt%shape, this%component_mempath)
314 if (this%deferred_shape)
then
316 nrow = this%deferred_size_init
317 allocate (int2d(ncelldim, this%deferred_size_init))
322 sv%idt%mf6varname, this%mempath)
334 sv%intshape => ncelldim
339 call intvector%init()
341 sv%intvector => intvector
344 call mem_setptr(sv%intvector_shape, sv%idt%shape, this%mempath)
354 real(DP),
dimension(:, :),
pointer,
contiguous :: dbl2d
355 integer(I4B),
pointer :: naux, nseg, nseg_1
356 integer(I4B) :: nseg1_isize, n, m
358 if (sv%idt%shape ==
'NAUX')
then
359 call mem_setptr(naux, sv%idt%shape, this%mempath)
360 call mem_allocate(dbl2d, naux, this%nrow, sv%idt%mf6varname, this%mempath)
372 else if (sv%idt%shape ==
'NSEG-1')
then
374 call get_isize(
'NSEG_1', this%mempath, nseg1_isize)
376 if (nseg1_isize < 0)
then
380 call mem_setptr(nseg_1,
'NSEG_1', this%mempath)
384 call mem_allocate(dbl2d, nseg_1, this%nrow, sv%idt%mf6varname, this%mempath)
395 sv%intshape => nseg_1
397 errmsg =
'IDM unimplemented. StructArray::allocate_dbl1d_type &
398 & unsupported shape "'//trim(sv%idt%shape)//
'".'
406 integer(I4B),
intent(in) :: icol
407 integer(I4B) :: i, j, isize
408 integer(I4B),
dimension(:),
pointer,
contiguous :: p_int1d
409 integer(I4B),
dimension(:, :),
pointer,
contiguous :: p_int2d
410 real(DP),
dimension(:),
pointer,
contiguous :: p_dbl1d
412 character(len=LENVARNAME) :: varname
415 varname = this%struct_vectors(icol)%idt%mf6varname
417 call get_isize(varname, this%mempath, isize)
420 select case (this%struct_vectors(icol)%memtype)
424 call mem_setptr(p_int1d, varname, this%mempath)
428 call mem_reallocate(p_int1d, this%nrow + isize, varname, this%mempath)
431 p_int1d(isize + i) = this%struct_vectors(icol)%int1d(i)
435 call mem_allocate(p_int1d, this%nrow, varname, this%mempath)
439 p_int1d(i) = this%struct_vectors(icol)%int1d(i)
444 deallocate (this%struct_vectors(icol)%int1d)
447 this%struct_vectors(icol)%int1d => p_int1d
448 this%struct_vectors(icol)%size = this%nrow
451 call mem_setptr(p_dbl1d, varname, this%mempath)
455 p_dbl1d(isize + i) = this%struct_vectors(icol)%dbl1d(i)
458 call mem_allocate(p_dbl1d, this%nrow, varname, this%mempath)
461 p_dbl1d(i) = this%struct_vectors(icol)%dbl1d(i)
465 deallocate (this%struct_vectors(icol)%dbl1d)
467 this%struct_vectors(icol)%dbl1d => p_dbl1d
468 this%struct_vectors(icol)%size = this%nrow
472 call mem_setptr(p_charstr1d, varname, this%mempath)
476 p_charstr1d(isize + i) = this%struct_vectors(icol)%charstr1d(i)
482 p_charstr1d(i) = this%struct_vectors(icol)%charstr1d(i)
483 call this%struct_vectors(icol)%charstr1d(i)%destroy()
487 deallocate (this%struct_vectors(icol)%charstr1d)
489 this%struct_vectors(icol)%charstr1d => p_charstr1d
490 this%struct_vectors(icol)%size = this%nrow
495 call mem_setptr(p_int2d, varname, this%mempath)
496 call mem_reallocate(p_int2d, this%struct_vectors(icol)%intshape, &
497 this%nrow, varname, this%mempath)
500 do j = 1, this%struct_vectors(icol)%intshape
501 p_int2d(j, isize + i) = this%struct_vectors(icol)%int2d(j, i)
505 call mem_allocate(p_int2d, this%struct_vectors(icol)%intshape, &
506 this%nrow, varname, this%mempath)
508 do j = 1, this%struct_vectors(icol)%intshape
509 p_int2d(j, i) = this%struct_vectors(icol)%int2d(j, i)
514 deallocate (this%struct_vectors(icol)%int2d)
516 this%struct_vectors(icol)%int2d => p_int2d
517 this%struct_vectors(icol)%size = this%nrow
521 errmsg =
'IDM unimplemented. StructArray::load_deferred_vector &
522 &unsupported memtype.'
531 integer(I4B) :: icol, j
532 integer(I4B),
dimension(:),
pointer,
contiguous :: p_intvector
533 character(len=LENVARNAME) :: varname
535 do icol = 1, this%ncol
537 varname = this%struct_vectors(icol)%idt%mf6varname
539 if (this%struct_vectors(icol)%memtype == 4)
then
542 call this%struct_vectors(icol)%intvector%shrink_to_fit()
546 this%struct_vectors(icol)%intvector%size, &
547 varname, this%mempath)
550 do j = 1, this%struct_vectors(icol)%intvector%size
551 p_intvector(j) = this%struct_vectors(icol)%intvector%at(j)
555 call this%struct_vectors(icol)%intvector%destroy()
556 deallocate (this%struct_vectors(icol)%intvector)
557 nullify (this%struct_vectors(icol)%intvector_shape)
558 else if (this%deferred_shape)
then
560 call this%load_deferred_vector(icol)
569 integer(I4B),
intent(in) :: iout
571 integer(I4B),
dimension(:),
pointer,
contiguous :: int1d
576 select case (this%struct_vectors(j)%memtype)
579 this%struct_vectors(j)%idt%tagname, &
582 if (this%struct_vectors(j)%ts_strlocs%count() > 0)
then
583 call idm_log_var(this%struct_vectors(j)%idt%tagname, &
584 this%mempath, iout, .false.)
587 this%struct_vectors(j)%idt%tagname, &
591 call mem_setptr(int1d, this%struct_vectors(j)%idt%mf6varname, &
593 call idm_log_var(int1d, this%struct_vectors(j)%idt%tagname, &
597 this%struct_vectors(j)%idt%tagname, &
600 if (this%struct_vectors(j)%ts_strlocs%count() > 0)
then
601 call idm_log_var(this%struct_vectors(j)%idt%tagname, &
602 this%mempath, iout, .false.)
605 this%struct_vectors(j)%idt%tagname, &
616 integer(I4B) :: i, j, k, newsize
617 integer(I4B),
dimension(:),
pointer,
contiguous :: p_int1d
618 integer(I4B),
dimension(:, :),
pointer,
contiguous :: p_int2d
619 real(DP),
dimension(:),
pointer,
contiguous :: p_dbl1d
621 integer(I4B) :: reallocate_mult
628 select case (this%struct_vectors(j)%memtype)
631 if (this%nrow > this%struct_vectors(j)%size)
then
633 newsize = this%struct_vectors(j)%size * reallocate_mult
635 allocate (p_int1d(newsize))
638 do i = 1, this%struct_vectors(j)%size
639 p_int1d(i) = this%struct_vectors(j)%int1d(i)
643 deallocate (this%struct_vectors(j)%int1d)
646 this%struct_vectors(j)%int1d => p_int1d
647 this%struct_vectors(j)%size = newsize
650 if (this%nrow > this%struct_vectors(j)%size)
then
651 newsize = this%struct_vectors(j)%size * reallocate_mult
652 allocate (p_dbl1d(newsize))
654 do i = 1, this%struct_vectors(j)%size
655 p_dbl1d(i) = this%struct_vectors(j)%dbl1d(i)
658 deallocate (this%struct_vectors(j)%dbl1d)
660 this%struct_vectors(j)%dbl1d => p_dbl1d
661 this%struct_vectors(j)%size = newsize
665 if (this%nrow > this%struct_vectors(j)%size)
then
666 newsize = this%struct_vectors(j)%size * reallocate_mult
667 allocate (p_charstr1d(newsize))
669 do i = 1, this%struct_vectors(j)%size
670 p_charstr1d(i) = this%struct_vectors(j)%charstr1d(i)
671 call this%struct_vectors(j)%charstr1d(i)%destroy()
674 deallocate (this%struct_vectors(j)%charstr1d)
676 this%struct_vectors(j)%charstr1d => p_charstr1d
677 this%struct_vectors(j)%size = newsize
680 if (this%nrow > this%struct_vectors(j)%size)
then
681 newsize = this%struct_vectors(j)%size * reallocate_mult
682 allocate (p_int2d(this%struct_vectors(j)%intshape, newsize))
684 do i = 1, this%struct_vectors(j)%size
685 do k = 1, this%struct_vectors(j)%intshape
686 p_int2d(k, i) = this%struct_vectors(j)%int2d(k, i)
690 deallocate (this%struct_vectors(j)%int2d)
692 this%struct_vectors(j)%int2d => p_int2d
693 this%struct_vectors(j)%size = newsize
697 errmsg =
'IDM unimplemented. StructArray::check_reallocate &
698 &unsupported memtype.'
708 integer(I4B),
intent(in) :: sv_col
709 integer(I4B),
intent(in) :: irow
710 logical(LGP),
intent(in) :: timeseries
711 integer(I4B),
intent(in) :: iout
712 integer(I4B),
optional,
intent(in) :: auxcol
713 integer(I4B) :: n, intval, numval, icol
714 character(len=LINELENGTH) :: str
715 character(len=:),
allocatable :: line
716 logical(LGP) :: preserve_case
718 select case (this%struct_vectors(sv_col)%memtype)
721 if (sv_col == 1 .and. this%blocknum > 0)
then
723 this%struct_vectors(sv_col)%int1d(irow) = this%blocknum
726 this%struct_vectors(sv_col)%int1d(irow) = parser%GetInteger()
729 if (this%struct_vectors(sv_col)%idt%timeseries .and. timeseries)
then
730 call parser%GetString(str)
731 if (
present(auxcol))
then
736 this%struct_vectors(sv_col)%dbl1d(irow) = &
737 this%struct_vectors(sv_col)%read_token(str, this%startidx(sv_col), &
740 this%struct_vectors(sv_col)%dbl1d(irow) = parser%GetDouble()
743 if (this%struct_vectors(sv_col)%idt%shape /=
'')
then
745 if (sv_col == this%ncol)
then
746 call parser%GetRemainingLine(line)
747 this%struct_vectors(sv_col)%charstr1d(irow) = line
752 preserve_case = (.not. this%struct_vectors(sv_col)%idt%preserve_case)
753 call parser%GetString(str, preserve_case)
754 this%struct_vectors(sv_col)%charstr1d(irow) = str
758 numval = this%struct_vectors(sv_col)%intvector_shape(irow)
761 intval = parser%GetInteger()
762 call this%struct_vectors(sv_col)%intvector%push_back(intval)
766 do n = 1, this%struct_vectors(sv_col)%intshape
767 this%struct_vectors(sv_col)%int2d(n, irow) = parser%GetInteger()
771 do n = 1, this%struct_vectors(sv_col)%intshape
772 if (this%struct_vectors(sv_col)%idt%timeseries .and. timeseries)
then
773 call parser%GetString(str)
774 icol = this%startidx(sv_col) + n - 1
775 this%struct_vectors(sv_col)%dbl2d(n, irow) = &
776 this%struct_vectors(sv_col)%read_token(str, icol, n, irow)
778 this%struct_vectors(sv_col)%dbl2d(n, irow) = parser%GetDouble()
789 logical(LGP),
intent(in) :: timeseries
790 integer(I4B),
intent(in) :: iout
791 integer(I4B) :: irow, j
792 logical(LGP) :: endofblock
800 call parser%GetNextLine(endofblock)
804 else if (this%deferred_shape)
then
806 this%nrow = this%nrow + 1
808 call this%check_reallocate()
814 call this%write_struct_vector(parser, j, irow, timeseries, iout)
818 call this%memload_vectors()
821 call this%log_structarray_vars(iout)
829 integer(I4B),
intent(in) :: inunit
830 integer(I4B),
intent(in) :: iout
831 integer(I4B) :: irow, ierr
833 integer(I4B) :: intval, numval
834 character(len=LINELENGTH) :: fname
835 character(len=*),
parameter :: fmtlsterronly = &
836 "('Error reading LIST from file: ',&
837 &1x,a,1x,' on UNIT: ',I0)"
840 if (this%deferred_shape)
then
841 errmsg =
'IDM unimplemented. StructArray::read_from_binary deferred shape &
842 ¬ supported for binary inputs.'
853 select case (this%struct_vectors(j)%memtype)
855 read (inunit, iostat=ierr) this%struct_vectors(j)%int1d(irow)
857 read (inunit, iostat=ierr) this%struct_vectors(j)%dbl1d(irow)
859 errmsg =
'List style binary inputs not supported &
860 &for text columns, tag='// &
861 trim(this%struct_vectors(j)%idt%tagname)//
'.'
865 numval = this%struct_vectors(j)%intvector_shape(irow)
869 read (inunit, iostat=ierr) intval
870 call this%struct_vectors(j)%intvector%push_back(intval)
875 do k = 1, this%struct_vectors(j)%intshape
877 read (inunit, iostat=ierr) this%struct_vectors(j)%int2d(k, irow)
881 do k = 1, this%struct_vectors(j)%intshape
883 read (inunit, iostat=ierr) this%struct_vectors(j)%dbl2d(k, irow)
898 inquire (unit=inunit, name=fname)
899 write (
errmsg, fmtlsterronly) trim(adjustl(fname)), inunit
904 if (irow == this%nrow)
exit readloop
913 call this%memload_vectors()
917 call this%log_structarray_vars(iout)
This module contains block parser methods.
This module contains simulation constants.
integer(i4b), parameter linelength
maximum length of a standard line
integer(i4b), parameter lenmodelname
maximum length of the model name
real(dp), parameter dnodata
real no data constant
integer(i4b), parameter lenvarname
maximum length of a variable name
integer(i4b), parameter izero
integer constant zero
real(dp), parameter dzero
real constant zero
integer(i4b), parameter lenmempath
maximum length of the memory path
This module contains the Input Data Model Logger Module.
This module defines variable data types.
character(len=lenmempath) function create_mem_path(component, subcomponent, context)
returns the path to the memory object
subroutine, public get_isize(name, mem_path, isize)
@ brief Get the number of elements for this variable
This module contains simulation methods.
subroutine, public store_error(msg, terminate)
Store an error message.
This module contains simulation variables.
character(len=maxcharlen) errmsg
error message string
character(len=linelength) idm_context
This module contains the StructArrayModule.
integer(i4b) function count(this)
subroutine mem_create_vector(this, icol, idt)
create new vector in StructArrayType
type(structarraytype) function, pointer, public constructstructarray(mf6_input, ncol, nrow, blocknum, mempath, component_mempath)
constructor for a struct_array
integer(i4b) function read_from_parser(this, parser, timeseries, iout)
read from the block parser to fill the StructArrayType
integer(i4b) function read_from_binary(this, inunit, iout)
read from binary input to fill the StructArrayType
subroutine memload_vectors(this)
load deferred vectors into managed memory
subroutine set_pointer(sv, sv_target)
subroutine allocate_dbl1d_type(this, sv)
allocate dbl1d input type
subroutine check_reallocate(this)
reallocate local memory for deferred vectors if necessary
subroutine load_deferred_vector(this, icol)
subroutine write_struct_vector(this, parser, sv_col, irow, timeseries, iout, auxcol)
subroutine allocate_dbl_type(this, sv)
allocate double input type
subroutine allocate_charstr_type(this, sv)
allocate charstr input type
subroutine allocate_int_type(this, sv)
allocate integer input type
subroutine log_structarray_vars(this, iout)
log information about the StructArrayType
subroutine, public destructstructarray(struct_array)
destructor for a struct_array
subroutine allocate_int1d_type(this, sv)
allocate int1d input type
type(structvectortype) function, pointer get(this, idx)
This module contains the StructVectorModule.
This class is used to store a single deferred-length character string. It was designed to work in an ...
type for structured array
derived type for generic vector