1      subroutine pre_wrtnoe(lfntop,filtop,mdrs,ndrs,idrs,rdrs)
2c
3      implicit none
4c
5      integer lfntop
6      character*(*) filtop
7      integer mdrs,ndrs
8      integer idrs(2,mdrs)
9      real*8 rdrs(5,mdrs)
10c
11      integer i,j
12      character*3 string
13c
14c     write solute NOE restraints
15c
16      if(ndrs.gt.0) then
17      open(unit=lfntop,file=filtop(1:index(filtop,' ')-1),
18     + form='formatted',status='unknown',err=9999)
19    9 continue
20      read(lfntop,100,end=10,err=9999) string
21  100 format(a3)
22      if(string.ne.'noe') goto 9
23      goto 11
24   10 continue
25      write(lfntop,101)
26  101 format('noe')
27   11 continue
28      write(lfntop,1000) ndrs
29 1000 format(i5)
30      do 1 j=1,ndrs
31      write(lfntop,1001)
32     + (idrs(i,j),i=1,2),(rdrs(i,j),i=1,5)
33 1001 format(2i10,3f12.6,/,20x,2e12.5)
34    1 continue
35      close(unit=lfntop)
36      endif
37c
38      return
39c
40 9999 continue
41      call md_abort('Could not open filtop to write noe',0)
42      return
43      end
44c $Id$
45