OpenRadioss 2025.1.11
OpenRadioss project
Loading...
Searching...
No Matches
dichotomic_search_r_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_r_asc ../common_source/tools/search/dichotomic_search_r_asc.F
25!||--- called by ------------------------------------------------------
26!|| pblast_parameters__air_burst ../common_source/modules/loads/pblast_mod.F90
27!||====================================================================
28 FUNCTION dichotomic_search_r_asc(VAL, ARRAY, LEN)
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)
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
88 END FUNCTION dichotomic_search_r_asc
89C-----------------------------------------------
#define my_real
Definition cppsort.cpp:32
integer function dichotomic_search_r_asc(val, array, len)