!
! Prepare the Calculation of Gradient g and Hesse H in any chain point 
      Program hcnvri4
      INTEGER nn,le,N3,I5
      PARAMETER (nn=3,le=50,I5=5)
c note: le is reduced in part (3) to I5=5 , see ''do 13'' below 
      DOUBLE PRECISION g(nn),H(nn,nn),point(nn),
     1  kette(le+1,nn),torad,btoa
      INTEGER istatus,j,J1,icalc
      Character*2  Zcoor(nn)
       Data Zcoor/'hc','nc','w '/
      OPEN(8,FILE='hcnVkette.dat')
      OPEN(9,FILE='hcnVketNrj.dat')
      OPEN(10,FILE='hcnVket3.dat')
      OPEN(18,FILE='hcnVistat.dat')
      OPEN(19,FILE='hcnVicalc.dat') 
      OPEN(83,FILE='hcnVpoig.dat')
c protocol file: all interesting output of the vri-search
      OPEN(44,FILE='hcnVprotocol.txt',status='unknown',access='append')
ccccccccccccccccccccccccccccccccccccccccc
2     FORMAT(3F20.14)
       rewind 9
       Read(9,*) j
       rewind 18 
       read(18,*) istatus
       rewind 19
       read(19,*) icalc,sgn
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 ! ccccccc
          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,nn
         write(44,*) Zcoor(i), kette(J1,i)
7        WRITE(83,*) Zcoor(i), 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
       if( (icalc.ne.0) .and. (icalc.ne.2)) icalc=1
       rewind 19
       write(19,*) icalc,sgn
       rewind 18
       write(18,*) istatus
       call exit(istatus)
      END
