source: flexpart.git/src/sort2.f90 @ 92fab65

10.4.1_peseiGFS_025bugfixes+enhancementsdevrelease-10release-10.4.1scaling-bug
Last change on this file since 92fab65 was 92fab65, checked in by Ignacio Pisso <ip@…>, 4 years ago

add SPDX-License-Identifier to all .f90 files

  • Property mode set to 100644
File size: 2.0 KB
Line 
1! SPDX-FileCopyrightText: FLEXPART 1998-2019, see flexpart_license.txt
2! SPDX-License-Identifier: GPL-3.0-or-later
3
4! From numerical recipes
5! Change by A. Stohl: Use of integer instead of real values
6
7subroutine sort2(n,arr,brr)
8
9  implicit none
10
11  integer :: n
12  integer :: arr(n),brr(n)
13  integer,parameter :: m=7,nstack=50
14  integer :: i,ir,j,jstack,k,l,istack(nstack)
15  integer :: a,b,temp
16  jstack=0
17  l=1
18  ir=n
191   if(ir-l.lt.m)then
20    do j=l+1,ir
21      a=arr(j)
22      b=brr(j)
23      do i=j-1,1,-1
24        if(arr(i).le.a)goto 2
25        arr(i+1)=arr(i)
26        brr(i+1)=brr(i)
27      end do
28      i=0
292     arr(i+1)=a
30      brr(i+1)=b
31    end do
32    if(jstack.eq.0)return
33    ir=istack(jstack)
34    l=istack(jstack-1)
35    jstack=jstack-2
36  else
37    k=(l+ir)/2
38    temp=arr(k)
39    arr(k)=arr(l+1)
40    arr(l+1)=temp
41    temp=brr(k)
42    brr(k)=brr(l+1)
43    brr(l+1)=temp
44    if(arr(l+1).gt.arr(ir))then
45      temp=arr(l+1)
46      arr(l+1)=arr(ir)
47      arr(ir)=temp
48      temp=brr(l+1)
49      brr(l+1)=brr(ir)
50      brr(ir)=temp
51    endif
52    if(arr(l).gt.arr(ir))then
53      temp=arr(l)
54      arr(l)=arr(ir)
55      arr(ir)=temp
56      temp=brr(l)
57      brr(l)=brr(ir)
58      brr(ir)=temp
59    endif
60    if(arr(l+1).gt.arr(l))then
61      temp=arr(l+1)
62      arr(l+1)=arr(l)
63      arr(l)=temp
64      temp=brr(l+1)
65      brr(l+1)=brr(l)
66      brr(l)=temp
67    endif
68    i=l+1
69    j=ir
70    a=arr(l)
71    b=brr(l)
723   continue
73      i=i+1
74    if(arr(i).lt.a)goto 3
754   continue
76      j=j-1
77    if(arr(j).gt.a)goto 4
78    if(j.lt.i)goto 5
79    temp=arr(i)
80    arr(i)=arr(j)
81    arr(j)=temp
82    temp=brr(i)
83    brr(i)=brr(j)
84    brr(j)=temp
85    goto 3
865   arr(l)=arr(j)
87    arr(j)=a
88    brr(l)=brr(j)
89    brr(j)=b
90    jstack=jstack+2
91    if(jstack.gt.nstack) then
92       print*, 'nstack too small in sort2'
93       stop
94    end if
95    if(ir-i+1.ge.j-l)then
96      istack(jstack)=ir
97      istack(jstack-1)=i
98      ir=j-1
99    else
100      istack(jstack)=j-1
101      istack(jstack-1)=l
102      l=i
103    endif
104  endif
105  goto 1
106end subroutine sort2
107!  (C) Copr. 1986-92 Numerical Recipes Software us.
Note: See TracBrowser for help on using the repository browser.
hosted by ZAMG