        PROGRAM Ala22cgGS1
C CCC for ALA potential CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
C*********************************************************
C   for Alanine-dipeptide 
C    --  energy + gradient from Gaussian03 
c  cccccccccccccccccccccccccccccccccccccccccccccc
C   output in file ala22gs.weg, usable for Mathematica input
C   to visualize the calculated path 
C*cccccccccccccccccccccccccccccccccccccccccccccccccccccc 
C W.Quapp  30.09.2004  for RGF=Newton Trajectory       c
C GS nach: Baron Peters et al. JCP 120 (2004)7877-7886 c 
c script version - modular structure of program        c
cccccccccccccccccccccccccccccccccccccccccccccccccccccccc
C    eps:  tolerance
C    L :   chain length, maximum 52 
C          are to defined by the user
C          nodes: L-2
C    N :   dimension of the problem
C          here N=66 given by the problem  
C    Y(LA,N) are the chain nodes, LA=1,..,L+1  
cccccccccccccccccccccccccccccccccccccccccccccccccccccccc
c  NDIM, L, und NDIM1 in cgGS3 are to put in every program: 1,2r,3,5 
      Integer NDIM,L
      PARAMETER(NDIM=66,L=12)
      REAL*8  Y(L+1,NDIM),Yb(NDIM),Ye(NDIM)
      Integer N,N3,J,I,LA,ITall,Natoms(22) 
c 7: all points of chain for Mma output
cc         OPEN(7,FILE='ala22gs.weg')
       OPEN(17,FILE='ala22start.weg')        
c 77: all energys for Mma input in part 5 
c      OPEN(77,FILE='ala22keten.weg')    
cccccccccccccccccccccccccccccccccccccccc
c 8,81: minima input  min1, min2 
c       startALA321G.dat is C5 
c       endeALA321G.dat  is C7ax
cccc  
c       OPEN(8,FILE='startALA321G.dat') 
        OPEN(8,FILE='InterMinALA321G.dat')
        OPEN(81,FILE='endeALA321G.dat')
c
cccccccccccccccccccccccccccccccccccccccc                                        
c 9: all points of chain
        OPEN(9,FILE='ala22chain.dat') 
       OPEN(11,FILE='ala22param.dat') 
c      OPEN(12,FILE='ala22proj.dat') 
c 13 actual point X of GS iteration
       OPEN(13,FILE='ala22point.dat') 
c      OPEN(14,FILE='ala22ener.dat') 
c      OPEN(15,FILE='ala22grad.dat')
c for gaussian data: 
       OPEN(32,FILE='alaatoms.dat',status='old')
       OPEN(33,FILE='alapoig.dat')
c for molden file:
       OPEN(38,FILE='ala22chain.mol',status='unknown',access='append')
       OPEN(44,FILE='protocol.txt',status='unknown',access='append')
C Constants           
        N=NDIM
        N3=N/3
        eps=3.33333d-3
        ITall=0
c
c        WRITE(6,*) 'give eps !! now ' 
c        Read(5,*) eps 
c
      PRINT*,' Chain from interMin2 to C7ax for 22 atoms ' 
      write(44,*)' Chain from  interMin2 to C7ax for 22 atoms: ALA '
      write(44,*)' Nodes L+1 = ' ,L+1,'  threshold eps = ',eps 
c  Start - Kette  zwischen den Minima
      READ(8,*)  (Yb(I),I=1,N)
         write(38,*) '    22   '  
         write(38,*)
         write(38,505)  (Yb(I),I=1,N)
505      FORMAT(1X,4H ar ,3F20.10)
      READ(81,*) (Ye(I),I=1,N)
      Do 1 J=1,L
      Do 1 I=1,N
c   first straigt chain between 2 Minima
      Y(J,I)= ((L-J)*Yb(I)+(J-1)*Ye(I))/(L-1)
 1    continue
      rewind 9
      Do 2, J=1,L
 2     WRITE(9,50) (Y(J,I),I=1,N)
       WRITE(9,50) ( Ye(I),I=1,N) 
c actual node is LA, node number is LA-1
c so, min1=Y_1, min_fin=Y_L+1 
      WRITE(17,*) ' { '  
      Do 6, J=1,L
      WRITE(17,22)(Y(J,I),I=1,N3)
 6    continue        
      WRITE(17,21)(Ye(I),I=1,N3)
cc
      LA=1
      rewind 13 
      WRITE(13,50)(Y(LA,I),I=1,N)

      READ(32,*) (Natoms(I),I=1,N3) 
      WRITE(44,*) ' first point'
      rewind 33 
      Do 7 J=1,N3 
      WRITE(44,*) Natoms(J), (Y(LA,3*(J-1)+I ),I=1,3)
 7    WRITE(33,*) Natoms(J), (Y(LA,3*(J-1)+I ),I=1,3)
      WRITE(33,*) '  ' 
      WRITE(6,*)  L, LA,  EPS, ITall, N 
      WRITE(44,*) L, LA,  EPS, ITall, N
      rewind 11
      I=1
      J=0
      WRITE(11,*) L, LA,  EPS, I, J  
      close(44)
 22   FORMAT(3H { , 21(F13.9, 3H , ), F13.9, 3H }, )    
 21   FORMAT(3H { , 21(F13.9, 3H , ), F13.9, 3H }} )
 50   FORMAT(1X,3F20.10)
      Stop
      End 
