1 | SUBROUTINE qlsort (prho, kto, kwg) |
---|
2 | C**** |
---|
3 | C ***************************** |
---|
4 | C * OASIS ROUTINE - LEVEL 3 * |
---|
5 | C * ------------- ------- * |
---|
6 | C ***************************** |
---|
7 | C |
---|
8 | C**** *qlsort* - Sort kwg numbers with adresses |
---|
9 | C |
---|
10 | C Purpose: |
---|
11 | C ------- |
---|
12 | C Given kwg real in prho, this routine sort them and |
---|
13 | C rearrange the array kto in the same way. |
---|
14 | C |
---|
15 | C N.B: The method is a trivial one. the first element is assumed |
---|
16 | C to be the smallest and then tested against the following |
---|
17 | C one. If an element is smallest a permutation is made, |
---|
18 | C and the testing goes on with the next elements. There |
---|
19 | C is no need to test again the elements previously tested |
---|
20 | C as they are known to be greater. At the end of the loop |
---|
21 | C the smallest is in first position, and we repeat the |
---|
22 | C the procedure with the array starting in position two |
---|
23 | C and so on. |
---|
24 | C |
---|
25 | C** Interface: |
---|
26 | C --------- |
---|
27 | C *CALL* *qlsort (prho, kto, kwg)* |
---|
28 | C |
---|
29 | C Input: |
---|
30 | C ----- |
---|
31 | C prho : array to be sorted |
---|
32 | C kto : array to be re-arranged as prho |
---|
33 | C kwg : size of prho and kto |
---|
34 | C |
---|
35 | C Output: |
---|
36 | C ------ |
---|
37 | C prho : the sorted array |
---|
38 | C kto : the re-arranged array |
---|
39 | C |
---|
40 | C Workspace: |
---|
41 | C --------- |
---|
42 | C None |
---|
43 | C |
---|
44 | C External: |
---|
45 | C -------- |
---|
46 | C None |
---|
47 | C |
---|
48 | C References: |
---|
49 | C ---------- |
---|
50 | C O. Thual, Simple ocean-atmosphere interpolation. |
---|
51 | C Part A: The method, EPICOA 0629 (1992) |
---|
52 | C Part B: Software implementation, EPICOA 0630 (1992) |
---|
53 | C See also OASIS manual (1995) |
---|
54 | C |
---|
55 | C History: |
---|
56 | C ------- |
---|
57 | C Version Programmer Date Description |
---|
58 | C ------- ---------- ---- ----------- |
---|
59 | C 1.1 O. Thual 93/04/15 created |
---|
60 | C 2.0 L. Terray 95/10/01 modified: new structure |
---|
61 | C |
---|
62 | C %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
63 | C |
---|
64 | C* ---------------------------- Include files --------------------------- |
---|
65 | C |
---|
66 | USE mod_kinds_oasis |
---|
67 | USE mod_unit |
---|
68 | C |
---|
69 | C* ---------------------------- Argument declarations ------------------- |
---|
70 | C |
---|
71 | REAL (kind=ip_realwp_p) prho(kwg) |
---|
72 | INTEGER (kind=ip_intwp_p) kto(kwg) |
---|
73 | C |
---|
74 | C* ---------------------------- Poema verses ---------------------------- |
---|
75 | C |
---|
76 | C %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
77 | C |
---|
78 | C* 1. Sorting algorithm |
---|
79 | C ----------------- |
---|
80 | C |
---|
81 | C* If kwg is equal to one no sorting is needed |
---|
82 | C |
---|
83 | IF (kwg .EQ. 1) RETURN |
---|
84 | C |
---|
85 | C* Loop on all the positions |
---|
86 | C |
---|
87 | ikwgm = kwg - 1 |
---|
88 | DO 110 jwg = 1, ikwgm |
---|
89 | ijwgp = jwg + 1 |
---|
90 | C |
---|
91 | C* Loop on the element following the position |
---|
92 | C |
---|
93 | DO 120 jnext = ijwgp, kwg |
---|
94 | zsmal = prho(jwg) |
---|
95 | zbig = prho(jnext) |
---|
96 | C |
---|
97 | C* Testing the smallness assumption |
---|
98 | C |
---|
99 | IF (zsmal .GT. zbig) THEN |
---|
100 | C |
---|
101 | C* Permutation of prho |
---|
102 | C |
---|
103 | prho(jnext) = zsmal |
---|
104 | prho(jwg) = zbig |
---|
105 | C |
---|
106 | C* Permutation of kto |
---|
107 | C |
---|
108 | ikbig = kto(jnext) |
---|
109 | kto(jnext) = kto(jwg) |
---|
110 | kto(jwg) = ikbig |
---|
111 | ENDIF |
---|
112 | 120 CONTINUE |
---|
113 | 110 CONTINUE |
---|
114 | C |
---|
115 | C* End of routine |
---|
116 | C |
---|
117 | RETURN |
---|
118 | END |
---|