update new files
[unres.git] / source / maxlik / src_MD_T_maxlik-NEWCORR-PMF-5 / 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(maxsym,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 print '(i3,2x,100i3)',kkk+1,(a(i),i=1,n)
24       kkk=kkk+1
25       do i=1,n
26       tabperm(i,kkk)=a(i)
27       enddo
28       if(nextp(n,a)) go to 10
29       return
30       end
31  
32       function nextp(n,a)
33       integer n,a,i,j,k,t
34       logical nextp
35       dimension a(n)
36       i=n-1
37    10 if(a(i).lt.a(i+1)) go to 20
38       i=i-1
39       if(i.eq.0) go to 20
40       go to 10
41    20 j=i+1
42       k=n
43    30 t=a(j)
44       a(j)=a(k)
45       a(k)=t
46       j=j+1
47       k=k-1
48       if(j.lt.k) go to 30
49       j=i
50       if(j.ne.0) go to 40
51       nextp=.false.
52       return
53    40 j=j+1
54       if(a(j).lt.a(i)) go to 40
55       t=a(i)
56       a(i)=a(j)
57       a(j)=t
58       nextp=.true.
59       return
60       end