OpenRadioss 2025.1.11
OpenRadioss project
Loading...
Searching...
No Matches
dichotomic_search_i_desc.F File Reference
#include "implicit_f.inc"

Go to the source code of this file.

Functions/Subroutines

integer function dichotomic_search_i_desc (val, array, len)

Function/Subroutine Documentation

◆ dichotomic_search_i_desc()

integer function dichotomic_search_i_desc ( integer, intent(in) val,
integer, dimension(len), intent(in) array,
integer, intent(in) len )

Definition at line 26 of file dichotomic_search_i_desc.F.

27C-----------------------------------------------
28C D e s c r i p t i o n
29C-----------------------------------------------
30C This subroutines is searching and returning the index in integer array ARRAY(1:LEN)
31C such as ARRAY(index)<= VAL <ARRAY(index)
32C Dichotomic search is used
33C-----------------------------------------------
34C P r e c o n d i t i on
35C-----------------------------------------------
36C ARRAY(1:LEN) must be sorted integers (descending order)
37C LEN >= 1
38C VAL is an integer
39C-----------------------------------------------
40C I m p l i c i t T y p e s
41C-----------------------------------------------
42#include "implicit_f.inc"
43C-----------------------------------------------
44C D u m m y A r g u m e n t s
45C-----------------------------------------------
46 INTEGER, INTENT(IN) :: VAL
47 INTEGER, INTENT(IN) :: LEN
48 INTEGER, INTENT(IN) :: ARRAY(LEN)
49 INTEGER :: DICHOTOMIC_SEARCH_I_DESC
50C-----------------------------------------------
51C L o c a l V a r i a b l e s
52C-----------------------------------------------
53 INTEGER :: IMID,ISTART,IEND
54C-----------------------------------------------
55C S o u r c e L i n e s
56C-----------------------------------------------
57 istart = 1
58 iend = len
59 !VAL ABOVE UPPER BOUND
60 IF(array(1)<val)THEN
62 RETURN
63 ENDIF
64 !VAL LOWER THAN LOWER BOUND
65 IF(array(len)>val)THEN
67 RETURN
68 ENDIF
69 !VAL IS BETWEEN THE BOUNDS
70 DO WHILE (istart+1<iend)
71 imid=(iend+istart)/2
72 IF(array(imid) < val)THEN
73 !FOCUS ON LEFT PART
74 iend = imid
75 ELSEIF(array(imid) > val)THEN
76 !FOCUS ON RIGHT PART
77 istart = imid
78 ELSE
79 !FOUND BY CHANCE NO NEED TO ITERATE MORE
81 RETURN
82 ENDIF
83 ENDDO
85 RETURN
integer function dichotomic_search_i_desc(val, array, len)