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

Go to the source code of this file.

Functions/Subroutines

integer function dichotomic_search_r_asc (val, array, len)

Function/Subroutine Documentation

◆ dichotomic_search_r_asc()

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

Definition at line 28 of file dichotomic_search_r_asc.F.

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