40 integer(I4B) :: blocknum
41 logical(LGP) :: deferred_shape = .false.
42 integer(I4B) :: deferred_size_init = 5
43 character(len=LENMEMPATH) :: mempath
44 character(len=LENMEMPATH) :: component_mempath
46 integer(I4B),
dimension(:),
allocatable :: startidx
47 integer(I4B),
dimension(:),
allocatable :: numcols
73 component_mempath)
result(struct_array)
75 integer(I4B),
intent(in) :: ncol
76 integer(I4B),
intent(in) :: nrow
77 integer(I4B),
intent(in) :: blocknum
78 character(len=*),
intent(in) :: mempath
79 character(len=*),
intent(in) :: component_mempath
83 allocate (struct_array)
86 struct_array%mf6_input = mf6_input
89 struct_array%ncol = ncol
92 struct_array%nrow = nrow
93 if (struct_array%nrow == -1)
then
95 struct_array%deferred_shape = .true.
99 if (blocknum > 0)
then
100 struct_array%blocknum = blocknum
102 struct_array%blocknum = 0
106 struct_array%mempath = mempath
107 struct_array%component_mempath = component_mempath
110 allocate (struct_array%struct_vectors(ncol))
111 allocate (struct_array%startidx(ncol))
112 allocate (struct_array%numcols(ncol))
120 deallocate (struct_array%struct_vectors)
121 deallocate (struct_array%startidx)
122 deallocate (struct_array%numcols)
123 deallocate (struct_array)
124 nullify (struct_array)
131 integer(I4B),
intent(in) :: icol
134 integer(I4B) :: numcol
142 if (this%deferred_shape)
then
143 sv%size = this%deferred_size_init
149 select case (idt%datatype)
153 call this%allocate_int_type(sv)
157 call this%allocate_dbl_type(sv)
159 case (
'STRING',
'KEYWORD')
161 call this%allocate_charstr_type(sv)
165 call this%allocate_int1d_type(sv)
166 if (sv%memtype == 5)
then
172 call this%allocate_dbl1d_type(sv)
176 errmsg =
'IDM unimplemented. StructArray::mem_create_vector &
177 &type='//trim(idt%datatype)
182 this%struct_vectors(icol) = sv
184 this%numcols(icol) = numcol
186 this%startidx(icol) = 1
188 this%startidx(icol) = this%startidx(icol - 1) + this%numcols(icol - 1)
194 integer(I4B) ::
count
195 count =
size(this%struct_vectors)
204 function get(this, idx)
result(sv)
206 integer(I4B),
intent(in) :: idx
216 integer(I4B),
dimension(:),
pointer,
contiguous :: int1d
217 integer(I4B) :: j, nrow
219 if (this%deferred_shape)
then
221 nrow = this%deferred_size_init
222 allocate (int1d(this%deferred_size_init))
226 call mem_allocate(int1d, this%nrow, sv%idt%mf6varname, this%mempath)
243 real(DP),
dimension(:),
pointer,
contiguous :: dbl1d
244 integer(I4B) :: j, nrow
246 if (this%deferred_shape)
then
248 nrow = this%deferred_size_init
249 allocate (dbl1d(this%deferred_size_init))
253 call mem_allocate(dbl1d, this%nrow, sv%idt%mf6varname, this%mempath)
273 if (this%deferred_shape)
then
274 allocate (charstr1d(this%deferred_size_init))
277 sv%idt%mf6varname, this%mempath)
285 sv%charstr1d => charstr1d
296 integer(I4B),
dimension(:, :),
pointer,
contiguous :: int2d
298 integer(I4B),
pointer :: ncelldim, exgid
299 character(len=LENMEMPATH) :: input_mempath
300 character(len=LENMODELNAME) :: mname
303 integer(I4B) :: nrow, n, m
305 if (sv%idt%shape ==
'NCELLDIM')
then
308 if (this%mf6_input%component_type ==
'EXG')
then
311 call mem_setptr(exgid,
'EXGID', this%mf6_input%mempath)
316 if (sv%idt%tagname ==
'CELLIDM1')
then
317 call mem_setptr(charstr1d,
'EXGMNAMEA', input_mempath)
318 else if (sv%idt%tagname ==
'CELLIDM2')
then
319 call mem_setptr(charstr1d,
'EXGMNAMEB', input_mempath)
323 mname = charstr1d(exgid)
327 call mem_setptr(ncelldim, sv%idt%shape, input_mempath)
330 call mem_setptr(ncelldim, sv%idt%shape, this%component_mempath)
333 if (this%deferred_shape)
then
335 nrow = this%deferred_size_init
336 allocate (int2d(ncelldim, this%deferred_size_init))
342 sv%idt%mf6varname, this%mempath)
354 sv%intshape => ncelldim
362 call intvector%init()
365 sv%intvector => intvector
369 call mem_setptr(sv%intvector_shape, sv%idt%shape, this%mempath)
379 real(DP),
dimension(:, :),
pointer,
contiguous :: dbl2d
380 integer(I4B),
pointer :: naux, nseg, nseg_1
381 integer(I4B) :: nseg1_isize, n, m
383 if (sv%idt%shape ==
'NAUX')
then
384 call mem_setptr(naux, sv%idt%shape, this%mempath)
386 call mem_allocate(dbl2d, naux, this%nrow, sv%idt%mf6varname, this%mempath)
399 else if (sv%idt%shape ==
'NSEG-1')
then
402 call get_isize(
'NSEG_1', this%mempath, nseg1_isize)
404 if (nseg1_isize < 0)
then
408 call mem_setptr(nseg_1,
'NSEG_1', this%mempath)
411 call mem_allocate(dbl2d, nseg_1, this%nrow, sv%idt%mf6varname, this%mempath)
422 sv%intshape => nseg_1
425 errmsg =
'IDM unimplemented. StructArray::allocate_dbl1d_type &
426 & unsupported shape "'//trim(sv%idt%shape)//
'".'
434 integer(I4B),
intent(in) :: icol
435 integer(I4B) :: i, j, isize
436 integer(I4B),
dimension(:),
pointer,
contiguous :: p_int1d
437 integer(I4B),
dimension(:, :),
pointer,
contiguous :: p_int2d
438 real(DP),
dimension(:),
pointer,
contiguous :: p_dbl1d
440 character(len=LENVARNAME) :: varname
443 varname = this%struct_vectors(icol)%idt%mf6varname
446 call get_isize(varname, this%mempath, isize)
449 select case (this%struct_vectors(icol)%memtype)
455 call mem_setptr(p_int1d, varname, this%mempath)
459 call mem_reallocate(p_int1d, this%nrow + isize, varname, this%mempath)
462 p_int1d(isize + i) = this%struct_vectors(icol)%int1d(i)
467 call mem_allocate(p_int1d, this%nrow, varname, this%mempath)
471 p_int1d(i) = this%struct_vectors(icol)%int1d(i)
476 deallocate (this%struct_vectors(icol)%int1d)
479 this%struct_vectors(icol)%int1d => p_int1d
480 this%struct_vectors(icol)%size = this%nrow
485 call mem_setptr(p_dbl1d, varname, this%mempath)
490 p_dbl1d(isize + i) = this%struct_vectors(icol)%dbl1d(i)
493 call mem_allocate(p_dbl1d, this%nrow, varname, this%mempath)
496 p_dbl1d(i) = this%struct_vectors(icol)%dbl1d(i)
500 deallocate (this%struct_vectors(icol)%dbl1d)
502 this%struct_vectors(icol)%dbl1d => p_dbl1d
503 this%struct_vectors(icol)%size = this%nrow
508 call mem_setptr(p_charstr1d, varname, this%mempath)
513 p_charstr1d(isize + i) = this%struct_vectors(icol)%charstr1d(i)
521 p_charstr1d(i) = this%struct_vectors(icol)%charstr1d(i)
525 deallocate (this%struct_vectors(icol)%charstr1d)
527 this%struct_vectors(icol)%charstr1d => p_charstr1d
528 this%struct_vectors(icol)%size = this%nrow
534 call mem_setptr(p_int2d, varname, this%mempath)
535 call mem_reallocate(p_int2d, this%struct_vectors(icol)%intshape, &
536 this%nrow, varname, this%mempath)
539 do j = 1, this%struct_vectors(icol)%intshape
540 p_int2d(j, isize + i) = this%struct_vectors(icol)%int2d(j, i)
544 call mem_allocate(p_int2d, this%struct_vectors(icol)%intshape, &
545 this%nrow, varname, this%mempath)
548 do j = 1, this%struct_vectors(icol)%intshape
549 p_int2d(j, i) = this%struct_vectors(icol)%int2d(j, i)
554 deallocate (this%struct_vectors(icol)%int2d)
556 this%struct_vectors(icol)%int2d => p_int2d
557 this%struct_vectors(icol)%size = this%nrow
561 errmsg =
'IDM unimplemented. StructArray::load_deferred_vector &
562 &unsupported memtype.'
571 integer(I4B) :: icol, j
572 integer(I4B),
dimension(:),
pointer,
contiguous :: p_intvector
573 character(len=LENVARNAME) :: varname
575 do icol = 1, this%ncol
578 varname = this%struct_vectors(icol)%idt%mf6varname
580 if (this%struct_vectors(icol)%memtype == 4)
then
584 call this%struct_vectors(icol)%intvector%shrink_to_fit()
588 this%struct_vectors(icol)%intvector%size, &
589 varname, this%mempath)
592 do j = 1, this%struct_vectors(icol)%intvector%size
593 p_intvector(j) = this%struct_vectors(icol)%intvector%at(j)
597 call this%struct_vectors(icol)%intvector%destroy()
598 deallocate (this%struct_vectors(icol)%intvector)
599 nullify (this%struct_vectors(icol)%intvector_shape)
601 else if (this%deferred_shape)
then
604 call this%load_deferred_vector(icol)
613 integer(I4B),
intent(in) :: iout
615 integer(I4B),
dimension(:),
pointer,
contiguous :: int1d
621 select case (this%struct_vectors(j)%memtype)
626 this%struct_vectors(j)%idt%tagname, &
631 if (this%struct_vectors(j)%ts_strlocs%count() > 0)
then
632 call idm_log_var(this%struct_vectors(j)%idt%tagname, &
633 this%mempath, iout, .false.)
636 this%struct_vectors(j)%idt%tagname, &
642 call mem_setptr(int1d, this%struct_vectors(j)%idt%mf6varname, &
645 call idm_log_var(int1d, this%struct_vectors(j)%idt%tagname, &
651 this%struct_vectors(j)%idt%tagname, &
656 if (this%struct_vectors(j)%ts_strlocs%count() > 0)
then
657 call idm_log_var(this%struct_vectors(j)%idt%tagname, &
658 this%mempath, iout, .false.)
661 this%struct_vectors(j)%idt%tagname, &
674 integer(I4B) :: i, j, k, newsize
675 integer(I4B),
dimension(:),
pointer,
contiguous :: p_int1d
676 integer(I4B),
dimension(:, :),
pointer,
contiguous :: p_int2d
677 real(DP),
dimension(:),
pointer,
contiguous :: p_dbl1d
679 integer(I4B) :: reallocate_mult
687 select case (this%struct_vectors(j)%memtype)
692 if (this%nrow > this%struct_vectors(j)%size)
then
695 newsize = this%struct_vectors(j)%size * reallocate_mult
698 allocate (p_int1d(newsize))
701 do i = 1, this%struct_vectors(j)%size
702 p_int1d(i) = this%struct_vectors(j)%int1d(i)
706 deallocate (this%struct_vectors(j)%int1d)
709 this%struct_vectors(j)%int1d => p_int1d
710 this%struct_vectors(j)%size = newsize
714 if (this%nrow > this%struct_vectors(j)%size)
then
716 newsize = this%struct_vectors(j)%size * reallocate_mult
718 allocate (p_dbl1d(newsize))
720 do i = 1, this%struct_vectors(j)%size
721 p_dbl1d(i) = this%struct_vectors(j)%dbl1d(i)
724 deallocate (this%struct_vectors(j)%dbl1d)
726 this%struct_vectors(j)%dbl1d => p_dbl1d
727 this%struct_vectors(j)%size = newsize
731 if (this%nrow > this%struct_vectors(j)%size)
then
733 newsize = this%struct_vectors(j)%size * reallocate_mult
735 allocate (p_charstr1d(newsize))
737 do i = 1, this%struct_vectors(j)%size
738 p_charstr1d(i) = this%struct_vectors(j)%charstr1d(i)
741 deallocate (this%struct_vectors(j)%charstr1d)
743 this%struct_vectors(j)%charstr1d => p_charstr1d
744 this%struct_vectors(j)%size = newsize
747 if (this%nrow > this%struct_vectors(j)%size)
then
749 newsize = this%struct_vectors(j)%size * reallocate_mult
751 allocate (p_int2d(this%struct_vectors(j)%intshape, newsize))
753 do i = 1, this%struct_vectors(j)%size
754 do k = 1, this%struct_vectors(j)%intshape
755 p_int2d(k, i) = this%struct_vectors(j)%int2d(k, i)
759 deallocate (this%struct_vectors(j)%int2d)
761 this%struct_vectors(j)%int2d => p_int2d
762 this%struct_vectors(j)%size = newsize
766 errmsg =
'IDM unimplemented. StructArray::check_reallocate &
767 &unsupported memtype.'
777 integer(I4B),
intent(in) :: sv_col
778 integer(I4B),
intent(in) :: irow
779 logical(LGP),
intent(in) :: timeseries
780 integer(I4B),
intent(in) :: iout
781 integer(I4B),
optional,
intent(in) :: auxcol
782 integer(I4B) :: n, intval, numval, icol
783 character(len=LINELENGTH) :: str
784 character(len=:),
allocatable :: line
785 logical(LGP) :: preserve_case
787 select case (this%struct_vectors(sv_col)%memtype)
792 if (sv_col == 1 .and. this%blocknum > 0)
then
794 this%struct_vectors(sv_col)%int1d(irow) = this%blocknum
797 this%struct_vectors(sv_col)%int1d(irow) = parser%GetInteger()
802 if (this%struct_vectors(sv_col)%idt%timeseries .and. timeseries)
then
803 call parser%GetString(str)
804 if (
present(auxcol))
then
809 this%struct_vectors(sv_col)%dbl1d(irow) = &
810 this%struct_vectors(sv_col)%read_token(str, this%startidx(sv_col), &
813 this%struct_vectors(sv_col)%dbl1d(irow) = parser%GetDouble()
818 if (this%struct_vectors(sv_col)%idt%shape /=
'')
then
820 if (sv_col == this%ncol)
then
821 call parser%GetRemainingLine(line)
822 this%struct_vectors(sv_col)%charstr1d(irow) = line
828 preserve_case = (.not. this%struct_vectors(sv_col)%idt%preserve_case)
829 call parser%GetString(str, preserve_case)
830 this%struct_vectors(sv_col)%charstr1d(irow) = str
836 numval = this%struct_vectors(sv_col)%intvector_shape(irow)
840 intval = parser%GetInteger()
841 call this%struct_vectors(sv_col)%intvector%push_back(intval)
847 do n = 1, this%struct_vectors(sv_col)%intshape
848 this%struct_vectors(sv_col)%int2d(n, irow) = parser%GetInteger()
854 do n = 1, this%struct_vectors(sv_col)%intshape
855 if (this%struct_vectors(sv_col)%idt%timeseries .and. timeseries)
then
856 call parser%GetString(str)
857 icol = this%startidx(sv_col) + n - 1
858 this%struct_vectors(sv_col)%dbl2d(n, irow) = &
859 this%struct_vectors(sv_col)%read_token(str, icol, n, irow)
861 this%struct_vectors(sv_col)%dbl2d(n, irow) = parser%GetDouble()
873 logical(LGP),
intent(in) :: timeseries
874 integer(I4B),
intent(in) :: iout
875 integer(I4B) :: irow, j
876 logical(LGP) :: endofblock
885 call parser%GetNextLine(endofblock)
891 else if (this%deferred_shape)
then
894 this%nrow = this%nrow + 1
897 call this%check_reallocate()
906 call this%write_struct_vector(parser, j, irow, timeseries, iout)
912 call this%memload_vectors()
916 call this%log_structarray_vars(iout)
924 integer(I4B),
intent(in) :: inunit
925 integer(I4B),
intent(in) :: iout
926 integer(I4B) :: irow, ierr
928 integer(I4B) :: intval, numval
929 character(len=LINELENGTH) :: fname
930 character(len=*),
parameter :: fmtlsterronly = &
931 "('Error reading LIST from file: ',&
932 &1x,a,1x,' on UNIT: ',I0)"
935 if (this%deferred_shape)
then
937 errmsg =
'IDM unimplemented. StructArray::read_from_binary deferred shape &
938 ¬ supported for binary inputs.'
955 select case (this%struct_vectors(j)%memtype)
958 read (inunit, iostat=ierr) this%struct_vectors(j)%int1d(irow)
960 read (inunit, iostat=ierr) this%struct_vectors(j)%dbl1d(irow)
963 errmsg =
'List style binary inputs not supported &
964 &for text columns, tag='// &
965 trim(this%struct_vectors(j)%idt%tagname)//
'.'
971 numval = this%struct_vectors(j)%intvector_shape(irow)
976 read (inunit, iostat=ierr) intval
977 call this%struct_vectors(j)%intvector%push_back(intval)
984 do k = 1, this%struct_vectors(j)%intshape
986 read (inunit, iostat=ierr) this%struct_vectors(j)%int2d(k, irow)
991 do k = 1, this%struct_vectors(j)%intshape
993 read (inunit, iostat=ierr) this%struct_vectors(j)%dbl2d(k, irow)
1011 inquire (unit=inunit, name=fname)
1012 write (
errmsg, fmtlsterronly) trim(adjustl(fname)), inunit
1020 if (irow == this%nrow)
exit readloop
1030 call this%memload_vectors()
1034 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