!
! Prepare the Calculation of Gradient g and Hesse H in any chain point 
! by GamessUS 
      Program A22Vri4
      INTEGER nn,le,I5
      PARAMETER (nn=58,le=12,I5=3)
c beachte: I5 in Teil 3 reduziert auf I5=3      
      DOUBLE PRECISION g(nn),H(nn,nn),point(nn),
     1  kette(le+1,nn),torad,btoa
      INTEGER istatus,j,J1
c      ,icalc,sgn
      Character*5  Zcoor(nn+2)   ! dih4 and dih22 are fixed 
      Data Zcoor/'ch2  ','cc3  ','cch3 ','oc4  ','occ4 ','dih4 ',
     1   'hc5  ','hcc5 ','dih5 ','hc6  ','hcc6 ','dih6 ','nc7  ',
     2   'ncc7 ','dih7 ','cn8  ','cnc8 ','dih8 ','cc9  ','ccn9 ',
     3   'dih9 ','oc10 ','occ10','dih10','hc11 ','hcn11','dih11',
     7   'hn12 ','hnc12','dih12','cc13 ','ccn13','dih13','hc14 ',
     8   'hcc14','dih14','hc15 ','hcc15','dih15','hc16 ','hcc16',
     7   'dih16','nc17 ','ncc17','dih17','cn18 ','cnc18','dih18',
     8   'hc19 ','hcn19','dih19','hn20 ','hnc20','dih20','hc21 ',
     7   'hcn21','dih21','hc22 ','hcn22','dih22'/
c                                              
      OPEN(8,FILE='a22Vkette.dat')
      OPEN(9,FILE='a22VketNrj.dat')
      OPEN(10,FILE='a22Vket3.dat')
      OPEN(18,FILE='a22Vistat.dat')
      OPEN(83,FILE='a22Vpoig.dat')
c protocol file: all interesting output of the vri-search
      OPEN(44,FILE='a22Vprotocol.txt',status='unknown',access='append')
ccccccccccccccccccccccccccccccccccccccccc
2     FORMAT(3F20.14)
       rewind 9
       Read(9,*) j
       rewind 18 
       read(18,*) istatus
ccccccccccccccccccccccccccccccccccccccccc      
       if(istatus.eq.2) then
          J1=1
          rewind 8
          DO 11 k=1,le+1
11        READ(8,*) (kette(k,i),i=1,nn)
c Calculate one chain node only !
          DO 12 i=1,nn
12        kette(J1,i)=kette(j,i)        
       else
          if(istatus.eq.10) goto 55 
          J1=j
          write(44,*) 'j   in    vri4   ', j 
          rewind 10
          DO 13 k=1,I5+1
13        READ(10,*) (kette(k,i),i=1,nn)
       endif
       rewind 83
       Do 7, i=1,5
7        WRITE(83,*) Zcoor(i), kette(J1,i)
         Do 71, i=6,nn
71       WRITE(83,*) Zcoor(i+1), kette(J1,i)
         WRITE(83,*) '  '
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
        If(istatus.eq.2) goto 55
c use j for vri3 to calculate a full chain of points: istatus > 2  
        IF(j.LT.I5+1) THEN
            istatus=4 
            rewind 18
            write(18,*) istatus
            j=j+1
            rewind 9
            write(9,*) j
          ELSE
            istatus=3
            rewind 18
            write(18,*) istatus
          ENDIF                                                                                      
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
55     CONTINUE
       rewind 18
       write(18,*) istatus
       call exit(istatus)
      END
