copy src_MD-M-SAXS-homology src-HCD-5D
[unres.git] / source / unres / src-HCD-5D / permut.F
1       subroutine permut(isym,nperm,tabperm)
2 c      integer maxperm,maxsym
3 c      parameter (maxperm=3628800)
4 c      parameter (maxsym=10)
5       include "DIMENSIONS"
6       integer n,a,tabperm
7       logical nextp
8       external nextp
9       dimension a(isym),tabperm(maxchain,maxperm)
10       n=isym
11       nperm=1
12       if (n.eq.1) then
13         tabperm(1,1)=1
14         return
15       endif
16       do i=2,n
17         nperm=nperm*i
18       enddo
19       kkk=0
20       do i=1,n
21       a(i)=i
22       enddo
23    10 continue
24 c     print '(i3,2x,100i3)',kkk+1,(a(i),i=1,n)
25       kkk=kkk+1
26       do i=1,n
27       tabperm(i,kkk)=a(i)
28       enddo
29       if(nextp(n,a)) go to 10
30       return
31       end
32  
33       function nextp(n,a)
34       integer n,a,i,j,k,t
35       logical nextp
36       dimension a(n)
37       i=n-1
38    10 if(a(i).lt.a(i+1)) go to 20
39       i=i-1
40       if(i.eq.0) go to 20
41       go to 10
42    20 j=i+1
43       k=n
44    30 t=a(j)
45       a(j)=a(k)
46       a(k)=t
47       j=j+1
48       k=k-1
49       if(j.lt.k) go to 30
50       j=i
51       if(j.ne.0) go to 40
52       nextp=.false.
53       return
54    40 j=j+1
55       if(a(j).lt.a(i)) go to 40
56       t=a(i)
57       a(i)=a(j)
58       a(j)=t
59       nextp=.true.
60       return
61       end