1      subroutine fporde(x,y,m,kx,ky,tx,nx,ty,ny,nummer,index,nreg)
2c  subroutine fporde sorts the data points (x(i),y(i)),i=1,2,...,m
3c  according to the panel tx(l)<=x<tx(l+1),ty(k)<=y<ty(k+1), they belong
4c  to. for each panel a stack is constructed  containing the numbers
5c  of data points lying inside; index(j),j=1,2,...,nreg points to the
6c  first data point in the jth panel while nummer(i),i=1,2,...,m gives
7c  the number of the next data point in the panel.
8c  ..
9c  ..scalar arguments..
10      integer m,kx,ky,nx,ny,nreg
11c  ..array arguments..
12      real*8 x(m),y(m),tx(nx),ty(ny)
13      integer nummer(m),index(nreg)
14c  ..local scalars..
15      real*8 xi,yi
16      integer i,im,k,kx1,ky1,k1,l,l1,nk1x,nk1y,num,nyy
17c  ..
18      kx1 = kx+1
19      ky1 = ky+1
20      nk1x = nx-kx1
21      nk1y = ny-ky1
22      nyy = nk1y-ky
23      do 10 i=1,nreg
24        index(i) = 0
25  10  continue
26      do 60 im=1,m
27        xi = x(im)
28        yi = y(im)
29        l = kx1
30        l1 = l+1
31  20    if(xi.lt.tx(l1) .or. l.eq.nk1x) go to 30
32        l = l1
33        l1 = l+1
34        go to 20
35  30    k = ky1
36        k1 = k+1
37  40    if(yi.lt.ty(k1) .or. k.eq.nk1y) go to 50
38        k = k1
39        k1 = k+1
40        go to 40
41  50    num = (l-kx1)*nyy+k-ky
42        nummer(im) = index(num)
43        index(num) = im
44  60  continue
45      return
46      end
47
48