[6328] | 1 | !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
| 2 | ! NASA/GSFC, Data Assimilation Office, Code 910.3, GEOS/DAS ! |
---|
| 3 | !----------------------------------------------------------------------- |
---|
| 4 | ! CVS $Id$ |
---|
| 5 | ! CVS $Name$ |
---|
| 6 | !BOP ------------------------------------------------------------------- |
---|
| 7 | ! |
---|
| 8 | ! !MODULE: m_SortingTools - A collection of different sorting tools |
---|
| 9 | ! |
---|
| 10 | ! !DESCRIPTION: |
---|
| 11 | ! |
---|
| 12 | ! This module contains a collection of sorting utilities. The |
---|
| 13 | ! utilities are accessed through three generic interfaces, IndexSet(), |
---|
| 14 | ! IndexSort(), and IndexBin(). |
---|
| 15 | ! |
---|
| 16 | ! Note that, a version of IndexBin() for real arguments is not |
---|
| 17 | ! implemented due to the difficulty of comparing two real values as |
---|
| 18 | ! being equal. For example, a bin for real values may be specified |
---|
| 19 | ! as a single number, a range of two numbers, a number with an |
---|
| 20 | ! absolute error-bar, or a number with a relative error-bar. |
---|
| 21 | ! |
---|
| 22 | ! In general, one may have to map both keys(:) and bins(:) to |
---|
| 23 | ! integer indices by the a given rule, then use the integer version |
---|
| 24 | ! of IndexBin() with the two integer index arrays to do the sorting. |
---|
| 25 | ! This mapping rule, however, is application dependent. |
---|
| 26 | ! |
---|
| 27 | ! Also note that, in principle, it is possible to use both |
---|
| 28 | ! IndexSort() and IndexBin() in the same sorting task. |
---|
| 29 | ! |
---|
| 30 | ! !INTERFACE: |
---|
| 31 | |
---|
| 32 | module m_SortingTools |
---|
| 33 | |
---|
| 34 | use m_MergeSorts !only : IndexSet,IndexSort |
---|
| 35 | use m_IndexBin_integer !only : IndexBin |
---|
| 36 | use m_IndexBin_char !only : IndexBin |
---|
| 37 | use m_IndexBin_logical !only : IndexBin |
---|
| 38 | use m_rankMerge !only : RankSet,RankMerge,IndexedRankMerge |
---|
| 39 | use m_Permuter !only : Permute, Unpermute |
---|
| 40 | |
---|
| 41 | implicit none |
---|
| 42 | |
---|
| 43 | private ! except |
---|
| 44 | |
---|
| 45 | public :: IndexSet ! define an initial list of indices |
---|
| 46 | public :: IndexSort ! index for a new rank out of the old |
---|
| 47 | public :: IndexBin ! index for sorting bins |
---|
| 48 | public :: RankSet ! define an initial list of ranks |
---|
| 49 | public :: RankMerge ! merge two arrays by re-ranking |
---|
| 50 | public :: IndexedRankMerge ! index-merge two array segments |
---|
| 51 | public :: Permute ! permute array entries |
---|
| 52 | public :: Unpermute ! invert permutation |
---|
| 53 | |
---|
| 54 | ! !EXAMPLES: |
---|
| 55 | ! |
---|
| 56 | ! - An example of using IndexSet()/IndexSort() in combination with |
---|
| 57 | ! the convenience of the Fortran 90 array syntex can be found in the |
---|
| 58 | ! prolog of m_MergeSorts. |
---|
| 59 | ! |
---|
| 60 | ! - An example of using IndexSet()/IndexBin(): Copying all "good" |
---|
| 61 | ! data to another array. |
---|
| 62 | ! |
---|
| 63 | ! integer :: indx(n) |
---|
| 64 | ! call IndexSet(n,indx) |
---|
| 65 | ! call IndexBin(n,indx,allObs(:)%qcflag,GOOD,ln0=ln_GOOD) |
---|
| 66 | ! |
---|
| 67 | ! ! Copy all "good" data to another array |
---|
| 68 | ! goodObs(1:ln_GOOD)=allObs( indx(1:ln_GOOD) ) |
---|
| 69 | ! |
---|
| 70 | ! ! Refill all "good" data back to their original places |
---|
| 71 | ! allObs( indx(1:ln_GOOD) ) = goodObs(1:ln_GOOD) |
---|
| 72 | ! |
---|
| 73 | ! - Similarily, multiple keys may be used in an IndexBin() call |
---|
| 74 | ! to selectively sort the data. The following code will move data |
---|
| 75 | ! with kt = kt_Us,kt_U,kt_Vs,kt_V up to the front: |
---|
| 76 | ! |
---|
| 77 | ! call IndexBin(n,indx,allObs(:)%kt,(/kt_Us,kt_U,kt_Vs,kt_V/)) |
---|
| 78 | ! allObs(1:n) = allObs( indx(1:n) ) |
---|
| 79 | ! |
---|
| 80 | ! - Additional applications can also be implemented with other |
---|
| 81 | ! argument combinations. |
---|
| 82 | ! |
---|
| 83 | ! !REVISION HISTORY: |
---|
| 84 | ! 15Mar00 - Jing Guo |
---|
| 85 | ! . Added m_rankMerge module interface |
---|
| 86 | ! 20Apr99 - Jing Guo |
---|
| 87 | ! - Commented "only" in use m_IndexBin_xxx to avoid an |
---|
| 88 | ! apperent compiler bug on DEC/OSF1 |
---|
| 89 | ! 17Feb99 - Jing Guo <guo@thunder> - initial prototype/prolog/code |
---|
| 90 | ! 19Oct00 - J.W. Larson <larson@mcs.anl.gov> - added Permuter and |
---|
| 91 | ! Unpermuter to list of public functions. |
---|
| 92 | !EOP ___________________________________________________________________ |
---|
| 93 | |
---|
| 94 | character(len=*),parameter :: myname='MCT(MPEU)::m_SortingTools' |
---|
| 95 | |
---|
| 96 | end module m_SortingTools |
---|