Create a list of leaves and a list of parents for a level
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(mg_box_t), | intent(in) | :: | boxes(:) |
List of boxes |
||
| type(mg_lvl_t), | intent(inout) | :: | level |
Level type which contains the indices of boxes |
subroutine mg_set_leaves_parents(boxes, level) type(mg_box_t), intent(in) :: boxes(:) !< List of boxes type(mg_lvl_t), intent(inout) :: level !< Level type which contains the indices of boxes integer :: i, id, i_leaf, i_parent integer :: n_parents, n_leaves n_parents = count(mg_has_children(boxes(level%ids))) n_leaves = size(level%ids) - n_parents if (.not. allocated(level%parents)) then allocate(level%parents(n_parents)) else if (n_parents /= size(level%parents)) then deallocate(level%parents) allocate(level%parents(n_parents)) end if if (.not. allocated(level%leaves)) then allocate(level%leaves(n_leaves)) else if (n_leaves /= size(level%leaves)) then deallocate(level%leaves) allocate(level%leaves(n_leaves)) end if i_leaf = 0 i_parent = 0 do i = 1, size(level%ids) id = level%ids(i) if (mg_has_children(boxes(id))) then i_parent = i_parent + 1 level%parents(i_parent) = id else i_leaf = i_leaf + 1 level%leaves(i_leaf) = id end if end do end subroutine mg_set_leaves_parents