A structarray is similar to a numpy recarray. It it used to load a list of data in which each column in the list may be a different type. Each column in the list is stored as a 1d vector.
568 class(LoadMf6FileType) :: this
569 integer(I4B), intent(in) :: iblk
570 type(LoadContextType) :: ctx
571 character(len=LINELENGTH), dimension(:), allocatable :: param_names
572 type(InputParamDefinitionType), pointer :: idt
573 type(InputParamDefinitionType), pointer :: shape_idt
574 type(InputParamDefinitionType), target :: blockvar_idt
575 integer(I4B) :: blocknum
576 integer(I4B), pointer :: nrow
577 integer(I4B), dimension(:), pointer, contiguous :: int1d
578 integer(I4B) :: nrows, nrowsread
579 integer(I4B) :: mem_rank, isize
580 integer(I4B) :: ibinary, oc_inunit
581 integer(I4B) :: icol, iparam
582 integer(I4B) :: ncol, nparam
583 logical(LGP) :: shape_found
584 logical(LGP) :: is_sum_shape
585 character(len=LINELENGTH) :: shape_name
586 integer(I4B), pointer :: pkgdata_maxbound
587
588 nrows = -1
589
590
591 call ctx%init(this%mf6_input, blockname= &
592 this%mf6_input%block_dfns(iblk)%blockname)
593
594 param_names = ctx%params
595 nparam = size(ctx%params)
596 call ctx%check_developmode(this%filename)
597
598 idt => &
599 get_aggregate_definition_type(this%mf6_input%aggregate_dfns, &
600 this%mf6_input%component_type, &
601 this%mf6_input%subcomponent_type, &
602 this%mf6_input%block_dfns(iblk)%blockname)
603
604 if (this%mf6_input%block_dfns(iblk)%block_variable) then
605 blocknum = this%parser%GetInteger()
606 else
607 blocknum = 0
608 end if
609
610
611 ncol = nparam
612
613 if (blocknum > 0) ncol = ncol + 1
614
615 if (idt%shape /= '') then
616
617
618
619 is_sum_shape = .false.
620 shape_name = idt%shape
621 if (idt%shape(1:4) == 'SUM(') then
622 is_sum_shape = .true.
623 shape_name = idt%shape(5:len_trim(idt%shape) - 1)
624 end if
625 shape_idt => &
626 get_param_definition_type(this%mf6_input%param_dfns, &
627 this%mf6_input%component_type, &
628 this%mf6_input%subcomponent_type, &
629 'DIMENSIONS', shape_name, this%filename, &
630 found=shape_found)
631 if (.not. shape_found) then
632
633 shape_idt => &
634 get_param_definition_type(this%mf6_input%param_dfns, &
635 this%mf6_input%component_type, &
636 this%mf6_input%subcomponent_type, &
637 'PACKAGEDATA', shape_name, this%filename, &
638 found=shape_found)
639 end if
640 if (shape_found) then
641 call get_isize(shape_idt%mf6varname, this%mf6_input%mempath, isize)
642 if (isize < 0) then
643 if (shape_idt%required) then
644 write (errmsg, '(3a)') 'Required dimension "', &
645 trim(shape_name), '" not found.'
646 call store_error(errmsg)
647 call this%parser%StoreErrorUnit()
648 end if
649 else
650
651
652
653 call get_mem_rank(shape_idt%mf6varname, this%mf6_input%mempath, &
654 mem_rank)
655 if (is_sum_shape .and. mem_rank == 1) then
656 call mem_setptr(int1d, shape_idt%mf6varname, this%mf6_input%mempath)
657 nrows = sum(int1d)
658 nullify (int1d)
659 else if (.not. is_sum_shape .and. mem_rank == 0) then
660
661 call mem_setptr(nrow, shape_idt%mf6varname, this%mf6_input%mempath)
662 nrows = nrow
663 else
664 write (errmsg, '(5a)') 'Shape variable "', trim(shape_name), &
665 '" rank does not match its declared shape "', &
666 trim(idt%shape), '".'
667 call store_error(errmsg)
668 call this%parser%StoreErrorUnit()
669 end if
670 end if
671 end if
672
673
674 end if
675
676
677
678 if (nrows < 0) then
680 blocknum, this%mf6_input%mempath, &
681 this%mf6_input%component_mempath, &
682 size_init=64)
683 else
685 blocknum, this%mf6_input%mempath, &
686 this%mf6_input%component_mempath)
687 end if
688
689 do icol = 1, ncol
690
691 if (blocknum > 0) then
692 if (icol == 1) then
693 blockvar_idt = this%block_index_dfn(iblk)
694 idt => blockvar_idt
695 call this%structarray%mem_create_vector(icol, idt)
696
697 cycle
698 end if
699
700 iparam = icol - 1
701 else
702
703 iparam = icol
704 end if
705
706 idt => &
707 get_param_definition_type(this%mf6_input%param_dfns, &
708 this%mf6_input%component_type, &
709 this%mf6_input%subcomponent_type, &
710 this%mf6_input%block_dfns(iblk)%blockname, &
711 param_names(iparam), this%filename)
712
713 call this%structarray%mem_create_vector(icol, idt)
714 end do
715
716
717 call ctx%allocate_arrays()
718
719
720 ibinary = read_control_record(this%parser, oc_inunit, this%iout)
721
722 if (ibinary == 1) then
723
724 nrowsread = this%structarray%read_from_binary(oc_inunit, this%iout)
725 call this%parser%terminateblock()
726 close (oc_inunit)
727 else
728
729 nrowsread = this%structarray%read_from_parser(this%parser, this%ts_active, &
730 this%iout, this%filename)
731 end if
732
733
734 call this%alloc_tslink(iblk)
735
736
737 if (ibinary == 0 .and. this%ts_active) call this%save_ts_sa()
738
739
740
741 if (this%mf6_input%block_dfns(iblk)%blockname == 'PACKAGEDATA' .and. &
743 call get_isize('MAXBOUND', this%mf6_input%mempath, isize)
744 if (isize < 0) then
745 call mem_allocate(pkgdata_maxbound, 'MAXBOUND', this%mf6_input%mempath)
746 pkgdata_maxbound = nrowsread
747 end if
748 end if
749
750
751 call ctx%destroy()
logical(lgp) function, public is_feature_keystring(mf6_input)
.true. if mf6_input's PERIOD block is feature-addressed (see is_feature_tag). Block-independent,...
type(structarraytype) function, pointer, public constructstructarray(mf6_input, ncol, nrow, blocknum, mempath, component_mempath, size_init)
constructor for a struct_array
Input load context for generic dynamic loaders and StructArray based static loads....
type for structured array