c
c
c     ###################################################
c     ##  COPYRIGHT (C)  1990  by  Jay William Ponder  ##
c     ##              All Rights Reserved              ##
c     ###################################################
c
c     #############################################################
c     ##                                                         ##
c     ##  subroutine prtint  --  output of internal coordinates  ##
c     ##                                                         ##
c     #############################################################
c
c
c     "prtint" writes out a set of Z-matrix internal
c     coordinates to an external disk file
c
c
      subroutine prtint (izmt)
      implicit none
      include 'sizes.i'
      include 'atmtyp.i'
      include 'atoms.i'
      include 'files.i'
      include 'titles.i'
      include 'zclose.i'
      include 'zcoord.i'
      integer i,k,izmt
      character*60 coordfile
      logical opened
c
c
c     open output unit if not already done
c
      inquire (unit=izmt,opened=opened)
      if (.not. opened) then
         coordfile = filename(1:leng)//'.int'
         call version (coordfile,'new')
         open (unit=izmt,file=coordfile,status='new')
      end if
c
c     write out the number of atoms and the title
c
      if (ltitle .eq. 0) then
         write (izmt,10)  n
   10    format (i6)
      else
         write (izmt,20)  n,title(1:ltitle)
   20    format (i6,2x,a)
      end if
c
c     first three atoms are special cases
c
      if (n .ge. 1) then
         write (izmt,30)  1,name(1),type(1)
   30    format (i6,2x,a3,i5)
      end if
      if (n .ge. 2) then
         write (izmt,40)  2,name(2),type(2),iz(1,2),blen(2)
   40    format (i6,2x,a3,i5,i6,f10.5)
      end if
      if (n .ge. 3) then
         write (izmt,50)  3,name(3),type(3),iz(1,3),blen(3),
     &                    iz(2,3),alph(3)
   50    format (i6,2x,a3,i5,i6,f10.5,i6,f10.4)
      end if
c
c     now, the fourth through final atoms
c
      do i = 4, n
         if (iz(4,i) .eq. 0) then
            dowhile (bet(i) .lt. -180.0d0)
               bet(i) = bet(i) + 360.0d0
            end do
            dowhile (bet(i) .gt. 180.0d0)
               bet(i) = bet(i) - 360.0d0
            end do
         end if
         write (izmt,60)  i,name(i),type(i),iz(1,i),blen(i),
     &                    iz(2,i),alph(i),iz(3,i),bet(i),iz(4,i)
   60    format (i6,2x,a3,i5,i6,f10.5,i6,f10.4,i6,f10.4,i6)
      end do
c
c     finally, add or delete bonds as required
c
      if (nadd.ne.0 .or. ndel.ne.0)  write (izmt,70)
   70 format ()
      do i = 1, nadd
         write (izmt,80)  (iadd(k,i),k=1,2)
   80    format (2i6)
      end do
      if (ndel .ne. 0)  write (izmt,90)
   90 format ()
      do i = 1, ndel
         write (izmt,100)  (idel(k,i),k=1,2)
  100    format (2i6)
      end do
      if (.not. opened)  close (unit=izmt)
      return
      end
