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

Go to the source code of this file.

Functions/Subroutines

subroutine itrimhpsort (tab, len)

Function/Subroutine Documentation

◆ itrimhpsort()

subroutine itrimhpsort ( integer, dimension(len) tab,
integer len )

Definition at line 28 of file itrimhpsort.F.

29C-----------------------------------------------
30c in place heap sort algorithm of integer table with elimination
31c of double entries. Returns the sorted table and final length.
32C-----------------------------------------------
33C I m p l i c i t T y p e s
34C-----------------------------------------------
35#include "implicit_f.inc"
36C-----------------------------------------------
37C D u m m y A r g u m e n t s
38C-----------------------------------------------
39 INTEGER :: LEN, TAB(LEN)
40C-----------------------------------------------
41C L o c a l V a r i a b l e s
42C-----------------------------------------------
43 INTEGER I,J,K,L,VAL
44c=======================================================================
45 IF (len < 2) RETURN
46 l = len/2 + 1
47 k = len
48c
49 !The index L will be decremented from its initial value during the
50 !"hKing" (heap creation) phase. Once it reaches 1, the index K
51 !will be decremented from its initial value down to 1 during the
52 !"retKement-and-promotion" (heap selection) phase.
53
54 DO ! main heap sort loop
55 IF (l > 1)THEN
56 l=l-1
57 val=tab(l)
58 ELSE
59 val=tab(k)
60 tab(k)=tab(1)
61 k=k-1
62 IF (k == 1) THEN
63 tab(1)=val
64 EXIT
65 END IF
66 END IF
67 i=l
68 j=l+l
69 DO WHILE (j <= k)
70 IF(j < k) THEN
71 IF (tab(j) < tab(j+1)) j=j+1
72 END IF
73 IF (val < tab(j)) THEN
74 tab(i)=tab(j)
75 i=j
76 j=j+j
77 ELSE
78 j=k+1
79 END IF
80 END DO
81 tab(i)=val
82 ENDDO ! main heap sort loop
83c
84c-----------
85c eliminate double entries
86c-----------
87 j = 1
88 val = tab(1)
89 DO i=2,len
90 IF (tab(i) == val) cycle
91 val = tab(i)
92 j = j+1
93 tab(j) = val
94 END DO
95 len = j
96c-----------
97 RETURN