OpenRadioss 2025.1.11
OpenRadioss project
Loading...
Searching...
No Matches
dichotomic_search_i_asc.F
Go to the documentation of this file.
1Copyright> OpenRadioss
2Copyright> Copyright (C) 1986-2025 Altair Engineering Inc.
3Copyright>
4Copyright> This program is free software: you can redistribute it and/or modify
5Copyright> it under the terms of the GNU Affero General Public License as published by
6Copyright> the Free Software Foundation, either version 3 of the License, or
7Copyright> (at your option) any later version.
8Copyright>
9Copyright> This program is distributed in the hope that it will be useful,
10Copyright> but WITHOUT ANY WARRANTY; without even the implied warranty of
11Copyright> MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12Copyright> GNU Affero General Public License for more details.
13Copyright>
14Copyright> You should have received a copy of the GNU Affero General Public License
15Copyright> along with this program. If not, see <https://www.gnu.org/licenses/>.
16Copyright>
17Copyright>
18Copyright> Commercial Alternative: Altair Radioss Software
19Copyright>
20Copyright> As an alternative to this open-source version, Altair also offers Altair Radioss
21Copyright> software under a commercial license. Contact Altair to discuss further if the
22Copyright> commercial version may interest you: https://www.altair.com/radioss/.
23!||====================================================================
24!|| dichotomic_search_i_asc ../common_source/tools/search/dichotomic_search_i_asc.F
25!||====================================================================
26 FUNCTION dichotomic_search_i_asc(VAL, ARRAY, LEN)
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 (ascending 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)
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
86 END FUNCTION dichotomic_search_i_asc
87C-----------------------------------------------
integer function dichotomic_search_i_asc(val, array, len)