1      logical function argos_prepare_dihsel(catm,nparms,nparmsp,matm,
2     + natm,
3     + ldih,mdih,ndih)
4c
5c $Id$
6c
7      implicit none
8c
9#include "argos_prepare_common.fh"
10c
11      integer argos_prepare_atnum
12      external argos_prepare_atnum
13c
14      integer matm,natm,mdih,ndih,nparms,nparmsp
15      integer ldih(4,mdih)
16      character*6 catm(nparmsp,matm)
17c
18      integer i,j,nd
19c
20      if(ffield(1:6).eq.'gromos') then
21c
22      nd=ndih
23      ndih=0
24      do 1 i=1,nd
25      do 2 j=1,ndih
26      if(ldih(2,i).eq.ldih(2,j).and.ldih(3,i).eq.ldih(3,j)) then
27      if(argos_prepare_atnum(catm(1,ldih(1,
28     + i)))+argos_prepare_atnum(catm(1,ldih(4,i))).lt.
29     + argos_prepare_atnum(catm(1,ldih(1,
30     + j)))+argos_prepare_atnum(catm(1,ldih(4,j)))) then
31      ldih(2,i)=ldih(2,j)
32      ldih(4,i)=ldih(4,j)
33      endif
34      goto 1
35      endif
36    2 continue
37      ndih=ndih+1
38      ldih(1,ndih)=ldih(1,i)
39      ldih(2,ndih)=ldih(2,i)
40      ldih(3,ndih)=ldih(3,i)
41      ldih(4,ndih)=ldih(4,i)
42    1 continue
43      endif
44c
45      argos_prepare_dihsel=.true.
46c
47      return
48      end
49