process Function

function process(p) result(accepted)

process this part through all the workflows.

Arguments

Type IntentOptional Attributes Name
type(part), intent(in) :: p

Return Value logical


Calls

proc~~process~~CallsGraph proc~process problem_19::process proc~workflow_name_to_index problem_19::workflow_name_to_index proc~process->proc~workflow_name_to_index

Called by

proc~~process~~CalledByGraph proc~process problem_19::process program~problem_19 problem_19 program~problem_19->proc~process

Source Code

        function process(p) result(accepted)
            !! process this part through all the workflows.
            type(part),intent(in) :: p
            logical :: accepted

            integer :: i, irule

            i = workflow_name_to_index('in')     ! start at the first workflow
            irule = 1 ! first rule
            do
                associate( r => workflows(i)%rules(irule) )
                    ! check if we are done
                    if (r%accept) then; accepted = .true.; return; end if
                    if (r%reject) then; accepted = .false.;return; end if
                    if (r%operator>0) then
                        ! process the operator
                        select case (r%operator)
                        case(1) ! <
                            if (p%xmas(r%operator_arg) < r%operator_val) then
                                ! check if done
                                if (r%goto=='A') then; accepted = .true.; return; end if
                                if (r%goto=='R') then; accepted = .false.; return; end if
                                ! go to next workflow:
                                i = workflow_name_to_index(r%goto)
                                !write(*,*) 'goto '//r%goto
                                irule = 1 ! start at first rule of new workflow
                             else
                                irule = irule + 1 ! next rule
                             end if
                        case(2) ! >
                            if (p%xmas(r%operator_arg) > r%operator_val) then
                                ! check if done
                                if (r%goto=='A') then; accepted = .true.; return; end if
                                if (r%goto=='R') then; accepted = .false.; return; end if
                                ! go to next workflow:
                                i = workflow_name_to_index(r%goto)
                                irule = 1 ! start at first rule of new workflow
                            else
                                irule = irule + 1 ! next rule
                            end if
                        end select
                    else
                        ! goto another workflow
                        i = workflow_name_to_index(r%goto)
                        irule = 1 ! start at first rule of new workflow
                    end if
                end associate
            end do

        end function process