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