        PROGRAM A22cgGS1
C CCC for LJ potential  CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
C   for 22*3-dimensional version Lennard-Johns-Potential
C    --  the LJ routine is from D. Wales  
C   output in file at22gs.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
      Integer NDIM,L
      PARAMETER(NDIM=66,L=25)
      REAL*8  Y(L+1,NDIM),Yb(NDIM),Ye(NDIM)
      Integer N,J,I,LA,ITall,Natoms(22) 
c
c 7: all points of chain for Mma output
        OPEN(17,FILE='at22start.weg')        
cccccccccccccccccccccccccccccccccccccccc
c 8,81: minima input  min1, min2 of LJ_22
c   use factor 3.4 for scaling of the Wales-structur
        OPEN(8,FILE='LJ22NebenMin.dat')
        OPEN(81,FILE='LJ22Minimum.dat')                                           
cccccccccccccccccccccccccccccccccccccccc                                        
c 9: all points of chain
        OPEN(9,FILE='at22chain.dat') 
        OPEN(11,FILE='at22param.dat') 
c 13 actual point X of GS iteration
        OPEN(13,FILE='at22point.dat') 
c for gaussian data: 
c       OPEN(32,FILE='alaatoms.dat',status='old')
        OPEN(33,FILE='alapoig.dat')
c for molden file:
       OPEN(38,FILE='at22chain.mol',status='unknown',access='append')
       OPEN(44,FILE='protocol.txt',status='unknown',access='append')
C Constants           
        N=NDIM
        N3=N/3
        eps=0.50000001d0
        ITall=0
        WRITE(6,*) 'give eps !! now ' 
        Read(5,*) eps 
c
c
      PRINT*,' Chain from SP1 to SP2 for 22 atoms ' 
      write(44,*)' Chain from MIn1 to Min2 for 22 atoms, TEST '
      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)

      LA=1
cc      rewind 13 
      WRITE(13,50)(Y(LA,I),I=1,N)
c
c      READ(32,*) (Natoms(I),I=1,N3) 
       Do 18,I=1,N3
18     Natoms(I)=18 
      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 
