@@ -77,13 +77,14 @@ module StructArrayModule
7777 ! > @brief constructor for a struct_array
7878 ! <
7979 function constructStructArray (mf6_input , ncol , nrow , blocknum , mempath , &
80- component_mempath ) result(struct_array)
80+ component_mempath , size_init ) result(struct_array)
8181 type (ModflowInputType), intent (in ) :: mf6_input
8282 integer (I4B), intent (in ) :: ncol ! < number of columns in the StructArrayType
8383 integer (I4B), intent (in ) :: nrow ! < number of rows in the StructArrayType
8484 integer (I4B), intent (in ) :: blocknum ! < valid block number or 0
8585 character (len=* ), intent (in ) :: mempath ! < memory path for storing the vector
8686 character (len=* ), intent (in ) :: component_mempath
87+ integer (I4B), optional , intent (in ) :: size_init ! < initial deferred allocation size (default 5)
8788 type (StructArrayType), pointer :: struct_array ! < new StructArrayType
8889
8990 ! allocate StructArrayType
@@ -100,6 +101,7 @@ function constructStructArray(mf6_input, ncol, nrow, blocknum, mempath, &
100101 if (struct_array% nrow == - 1 ) then
101102 struct_array% nrow = 0
102103 struct_array% deferred_shape = .true.
104+ if (present (size_init)) struct_array% deferred_size_init = size_init
103105 end if
104106
105107 ! set blocknum
@@ -397,10 +399,16 @@ subroutine allocate_dbl1d_type(this, sv)
397399
398400 if (sv% idt% shape == ' NAUX' ) then
399401 call mem_setptr(naux, sv% idt% shape, this% mempath)
400- call mem_allocate(dbl2d, naux, this% nrow, sv% idt% mf6varname, this% mempath)
402+
403+ if (this% deferred_shape) then
404+ ! deferred: plain allocate so check_reallocate can grow it safely
405+ allocate (dbl2d(naux, sv% size))
406+ else
407+ call mem_allocate(dbl2d, naux, this% nrow, sv% idt% mf6varname, this% mempath)
408+ end if
401409
402410 ! initialize
403- do m = 1 , this % nrow
411+ do m = 1 , sv % size
404412 do n = 1 , naux
405413 dbl2d(n, m) = DZERO
406414 end do
@@ -420,11 +428,11 @@ subroutine allocate_dbl1d_type(this, sv)
420428 call mem_setptr(nseg_1, ' NSEG_1' , this% mempath)
421429 end if
422430
423- ! allocate
424- call mem_allocate(dbl2d, nseg_1, this % nrow , sv% idt% mf6varname, this% mempath)
431+ ! allocate; use sv%size for deferred-compatible initial row count
432+ call mem_allocate(dbl2d, nseg_1, sv % size , sv% idt% mf6varname, this% mempath)
425433
426434 ! initialize
427- do m = 1 , this % nrow
435+ do m = 1 , sv % size
428436 do n = 1 , nseg_1
429437 dbl2d(n, m) = DZERO
430438 end do
@@ -448,6 +456,7 @@ subroutine load_deferred_vector(this, icol)
448456 integer (I4B), dimension (:), pointer , contiguous :: p_int1d
449457 integer (I4B), dimension (:, :), pointer , contiguous :: p_int2d
450458 real (DP), dimension (:), pointer , contiguous :: p_dbl1d
459+ real (DP), dimension (:, :), pointer , contiguous :: p_dbl2d
451460 type (CharacterStringType), dimension (:), pointer , contiguous :: p_charstr1d
452461 character (len= LENVARNAME) :: varname
453462 logical (LGP) :: overwrite
@@ -612,9 +621,24 @@ subroutine load_deferred_vector(this, icol)
612621 this% struct_vectors(icol)% int2d = > p_int2d
613622 this% struct_vectors(icol)% size = this% nrow
614623 case (MTYPE_DBL2D)
615- errmsg = ' StructArray::load_deferred_vector &
616- &dbl2d reallocate unimplemented.'
617- call store_error(errmsg, terminate= .TRUE. )
624+ if (isize > - 1 ) then
625+ errmsg = ' StructArray::load_deferred_vector &
626+ &dbl2d reallocate unimplemented.'
627+ call store_error(errmsg, terminate= .TRUE. )
628+ else
629+ call mem_allocate(p_dbl2d, this% struct_vectors(icol)% intshape, &
630+ this% nrow, varname, this% mempath)
631+ do i = 1 , this% nrow
632+ do j = 1 , this% struct_vectors(icol)% intshape
633+ p_dbl2d(j, i) = this% struct_vectors(icol)% dbl2d(j, i)
634+ end do
635+ end do
636+ end if
637+
638+ deallocate (this% struct_vectors(icol)% dbl2d)
639+
640+ this% struct_vectors(icol)% dbl2d = > p_dbl2d
641+ this% struct_vectors(icol)% size = this% nrow
618642 case default
619643 end select
620644 end subroutine load_deferred_vector
@@ -717,6 +741,7 @@ subroutine check_reallocate(this)
717741 integer (I4B), dimension (:), pointer , contiguous :: p_int1d
718742 integer (I4B), dimension (:, :), pointer , contiguous :: p_int2d
719743 real (DP), dimension (:), pointer , contiguous :: p_dbl1d
744+ real (DP), dimension (:, :), pointer , contiguous :: p_dbl2d
720745 type (CharacterStringType), dimension (:), pointer , contiguous :: p_charstr1d
721746 integer (I4B) :: reallocate_mult
722747
@@ -792,7 +817,24 @@ subroutine check_reallocate(this)
792817 this% struct_vectors(j)% int2d = > p_int2d
793818 this% struct_vectors(j)% size = newsize
794819 end if
795- ! TODO: case (6)
820+ case (MTYPE_DBL2D)
821+ if (this% nrow > this% struct_vectors(j)% size) then
822+ newsize = this% struct_vectors(j)% size * reallocate_mult
823+ allocate (p_dbl2d(this% struct_vectors(j)% intshape, newsize))
824+
825+ do i = 1 , this% struct_vectors(j)% size
826+ do k = 1 , this% struct_vectors(j)% intshape
827+ p_dbl2d(k, i) = this% struct_vectors(j)% dbl2d(k, i)
828+ end do
829+ end do
830+
831+ deallocate (this% struct_vectors(j)% dbl2d)
832+
833+ this% struct_vectors(j)% dbl2d = > p_dbl2d
834+ this% struct_vectors(j)% size = newsize
835+ end if
836+ case (MTYPE_UNDEF, MTYPE_INTVEC)
837+ ! metadata-only or unsupported: skip reallocation check
796838 case default
797839 errmsg = ' IDM unimplemented. StructArray::check_reallocate &
798840 &unsupported memtype.'
@@ -1222,8 +1264,9 @@ subroutine ts_update(this, tsmanager, subcomp_name, iprpak, input_name, &
12221264 logical (LGP) :: do_clear, do_static
12231265
12241266 do_clear = .true.
1225- if (present (clear_strlocs)) do_clear = clear_strlocs
12261267 do_static = .false.
1268+
1269+ if (present (clear_strlocs)) do_clear = clear_strlocs
12271270 if (present (is_static)) do_static = is_static
12281271
12291272 ! find BOUNDNAME column (0 = none)
0 commit comments