source: CPL/oasis3/trunk/src/lib/anaisg/src/qlins.f @ 1677

Last change on this file since 1677 was 1677, checked in by aclsce, 12 years ago

Imported oasis3 (tag ipslcm5a) from cvs server to svn server (igcmg project).

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