!--------------------------------------------------------------------------- !--------------------------------------------------------------------------- !--------------------------------------------------------------------------- !+ ! Subroutine TO_TOP10 (TOP10, VALUE, NAME, IX, ORDER) ! ! Subroutine to record largest contributors to the merit function in the ! top 10 list. !- subroutine to_top10 (top10, value, top_name, indx, order) use cesrv_struct use cesrv_interface implicit none type (top10s) top10(:) integer N_top10, i_put, i, j, indx real(rp) value character(*) top_name, order logical better_value ! initialize if TOP_NAME = 'INIT_TOP10' N_top10 = size(top10) if (top_name == 'INIT_TOP10') then do i = 1, N_top10 top10(i)%value = value top10(i)%name = '------' top10(i)%index = 0 top10(i)%valid = .false. enddo return endif ! go from bottom to top and see if VALUE is greater than any in the ! current TOP10 do i = N_top10, 1, -1 if (top10(i)%valid) then better_value = .false. ! assume initially .false. if (order == 'abs') then if (abs(value) > abs(top10(i)%value)) better_value = .true. elseif (order == 'max') then if (value > top10(i)%value) better_value = .true. elseif (order == 'min') then if (value < top10(i)%value) better_value = .true. else print *, 'ERROR IN TO_TOP10: BAD ORDER SWITCH ', order endif else better_value = .true. endif if (.not. better_value) then ! stop when VALUE is not as good if (i == N_top10) return ! return if VALUE is not in top10 i_put = i + 1 ! index to put VALUE elseif (i == 1) then ! if VALUE is larger than evarone... i_put = 1 ! then put it at the top else i_put = 0 ! no put (yet) endif if (i_put /= 0) then do j = N_top10-1, i_put, -1 ! move the rest down top10(j+1) = top10(j) enddo top10(i_put)%name = top_name top10(i_put)%value = value ! and put in value and info top10(i_put)%index = indx top10(i_put)%valid = .true. return ! and we are done endif enddo end subroutine