Oasis3 4.0.2
qlins.f
Go to the documentation of this file.
00001       SUBROUTINE qlins (prho, kto, kwg, prnew, kjwg)
00002 C****
00003 C               *****************************
00004 C               * OASIS ROUTINE  -  LEVEL 3 *
00005 C               * -------------     ------- *
00006 C               *****************************
00007 C
00008 C**** *qlins* - Insert a new element in a sorted list
00009 C
00010 C     Purpose:
00011 C     -------
00012 C     Given a sorted array prho and associated array kto of indices
00013 C     of length klwg, insert a new element prnew in prho, if needed,
00014 C     and  kjwg in kto accordingly, and trash the lowest element.
00015 C
00016 C     N.B: The method is a trivial one. The first element is assumed 
00017 C     to be the smallest and then tested against the following 
00018 C     one. If an element is smallest a permutation is made, 
00019 C     and the testing goes on with the next elements. There
00020 C     is no need to test again the  elements previously tested
00021 C     as they are known to be greater. At the end of the loop
00022 C     the smallest is in first position, and we repeat the 
00023 C     the procedure with the array starting in position two
00024 C     and so on.
00025 C
00026 C**   Interface:
00027 C     ---------
00028 C       *CALL*  *qlins (prho, kto, kwg, prnew, kjwg)*
00029 C
00030 C     Input:
00031 C     -----
00032 C                prho  : array to be sorted
00033 C                kto   : array to be re-arranged as prho
00034 C                kwg   : size of prho and kto
00035 C                prnew : the new vallue to insert in prho, if needed
00036 C                kjwg  : to be inserted in kto accordingly
00037 C 
00038 C     Output:
00039 C     ------
00040 C                prho  : the sorted array
00041 C                kto   : the re-arranged array
00042 C
00043 C     Workspace:
00044 C     ---------
00045 C     None
00046 C
00047 C     External:
00048 C     --------
00049 C     None
00050 C
00051 C     References:
00052 C     ----------
00053 C     O. Thual, Simple ocean-atmosphere interpolation. 
00054 C               Part A: The method, EPICOA 0629 (1992)
00055 C               Part B: Software implementation, EPICOA 0630 (1992)
00056 C     See also OASIS manual (1995)
00057 C
00058 C     History:
00059 C     -------
00060 C       Version   Programmer     Date      Description
00061 C       -------   ----------     ----      ----------- 
00062 C       1.1       O. Thual       93/04/15  created 
00063 C       2.0       L. Terray      95/10/01  modified: new structure
00064 C
00065 C %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00066 C
00067 C* ---------------------------- Include files ---------------------------
00068 C
00069       USE mod_kinds_oasis
00070       USE mod_unit
00071 C
00072 C* ---------------------------- Argument declarations -------------------
00073 C
00074       REAL (kind=ip_realwp_p) prho(kwg)
00075       INTEGER (kind=ip_intwp_p) kto(kwg)
00076 C
00077 C* ---------------------------- Poema verses ----------------------------
00078 C
00079 C %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00080 C 
00081 C*    1. Insertion
00082 C        ---------
00083 C     
00084 C* If kwg is equal to one: nothing special 
00085 C
00086 C* Loop on all the positions
00087 C
00088       DO 110 jwg = 1, kwg
00089         zsmal = prho(jwg)
00090 C          
00091 C* Testing if insertion is needed 
00092 C
00093         IF (zsmal .GT. prnew) THEN
00094 C             
00095 C* Shift to insert new value excepted the last element
00096 C
00097             IF (jwg .NE. kwg) THEN
00098                 ijwgp = jwg + 1
00099                 DO 120 ji = kwg, ijwgp, -1
00100                   prho(ji) = prho(ji-1)
00101                   kto(ji) = kto(ji-1)
00102  120            CONTINUE
00103             ENDIF
00104             prho(jwg) = prnew
00105             kto(jwg) = kjwg
00106             RETURN
00107         ENDIF
00108  110  CONTINUE
00109 C
00110 C* End of routine
00111 C
00112       RETURN 
00113       END
 All Data Structures Namespaces Files Functions Variables Defines