@@ -31,17 +31,19 @@ program testgrad
3131 integer i,j,ixyz
3232 integer next,frame
3333 integer freeunit
34- real * 8 etot,f,f0,eps,eps0,old,energy
35- real * 8 eb0,ea0,eba0,eub0,eaa0,eopb0
36- real * 8 eopd0,eid0,eit0,et0,ept0,ebt0
37- real * 8 eat0,ett0,ev0,er0,edsp0,ec0
38- real * 8 ecd0,ed0,em0,ep0,ect0,erxf0
34+ real * 8 eval,energy
35+ real * 8 f,f0,eps,eps0,old
36+ real * 8 eb0,ea0,eba0,eub0
37+ real * 8 eaa0,eopb0,eopd0,eid0
38+ real * 8 eit0,et0,ept0,ebt0
39+ real * 8 eat0,ett0,ev0,er0
40+ real * 8 edsp0,ec0,ecd0,ed0
41+ real * 8 em0,ep0,ect0,erxf0
3942 real * 8 es0,elf0,eg0,ex0
4043 real * 8 totnorm,ntotnorm,rms,nrms
4144 real * 8 , allocatable :: denorm(:)
4245 real * 8 , allocatable :: ndenorm(:)
43- real * 8 , allocatable :: detot(:,:)
44- real * 8 , allocatable :: ndetot(:,:)
46+ real * 8 , allocatable :: ndesum(:,:)
4547 real * 8 , allocatable :: ndeb(:,:)
4648 real * 8 , allocatable :: ndea(:,:)
4749 real * 8 , allocatable :: ndeba(:,:)
@@ -70,6 +72,7 @@ program testgrad
7072 real * 8 , allocatable :: ndelf(:,:)
7173 real * 8 , allocatable :: ndeg(:,:)
7274 real * 8 , allocatable :: ndex(:,:)
75+ real * 8 , allocatable :: derivs(:,:)
7376 logical exist,query
7477 logical doanalyt,donumer,dofull
7578 character * 1 answer
@@ -170,11 +173,13 @@ program testgrad
170173c
171174c perform dynamic allocation of some local arrays
172175c
173- allocate (denorm(n))
174- allocate (detot(3 ,n))
176+ if (doanalyt) then
177+ allocate (denorm(n))
178+ allocate (derivs(3 ,n))
179+ end if
175180 if (donumer) then
176181 allocate (ndenorm(n))
177- allocate (ndetot (3 ,n))
182+ allocate (ndesum (3 ,n))
178183 allocate (ndeb(3 ,n))
179184 allocate (ndea(3 ,n))
180185 allocate (ndeba(3 ,n))
@@ -214,25 +219,25 @@ program testgrad
214219 100 format (/ ,' Analysis for Archive Structure :' ,8x ,i8)
215220 end if
216221c
217- c compute the analytical gradient components
222+ c compute the energy and analytical gradient components
218223c
219224 if (doanalyt) then
220- call gradient (etot,detot )
225+ call gradient (eval,derivs )
221226 end if
222227c
223228c print the total potential energy of the system
224229c
225230 if (doanalyt) then
226231 if (digits .ge. 8 ) then
227- write (iout,110 ) etot
232+ write (iout,110 ) esum
228233 110 format (/ ,' Total Potential Energy :' ,8x ,f20.8 ,
229234 & ' Kcal/mole' )
230235 else if (digits .ge. 6 ) then
231- write (iout,120 ) etot
236+ write (iout,120 ) esum
232237 120 format (/ ,' Total Potential Energy :' ,8x ,f18.6 ,
233238 & ' Kcal/mole' )
234239 else
235- write (iout,130 ) etot
240+ write (iout,130 ) esum
236241 130 format (/ ,' Total Potential Energy :' ,8x ,f16.4 ,
237242 & ' Kcal/mole' )
238243 end if
@@ -399,7 +404,7 @@ program testgrad
399404 else if (j .eq. 3 ) then
400405 z(i) = old
401406 end if
402- ndetot (j,i) = (f - f0) / eps
407+ ndesum (j,i) = (f - f0) / eps
403408 ndeb(j,i) = (eb - eb0) / eps
404409 ndea(j,i) = (ea - ea0) / eps
405410 ndeba(j,i) = (eba - eba0) / eps
@@ -574,34 +579,34 @@ program testgrad
574579 ntotnorm = 0.0d0
575580 do i = 1 , n
576581 if (doanalyt .and. use(i)) then
577- denorm(i) = detot (1 ,i)** 2 + detot (2 ,i)** 2
578- & + detot (3 ,i)** 2
582+ denorm(i) = desum (1 ,i)** 2 + desum (2 ,i)** 2
583+ & + desum (3 ,i)** 2
579584 totnorm = totnorm + denorm(i)
580585 denorm(i) = sqrt (denorm(i))
581586 if (digits .ge. 8 ) then
582- write (iout,350 ) i,(detot (j,i),j= 1 ,3 ),denorm(i)
587+ write (iout,350 ) i,(desum (j,i),j= 1 ,3 ),denorm(i)
583588 350 format (' Anlyt' ,i8,1x ,3f16 .8 ,f16.8 )
584589 else if (digits .ge. 6 ) then
585- write (iout,360 ) i,(detot (j,i),j= 1 ,3 ),denorm(i)
590+ write (iout,360 ) i,(desum (j,i),j= 1 ,3 ),denorm(i)
586591 360 format (' Anlyt' ,2x ,i8,3x ,3f14 .6 ,2x ,f14.6 )
587592 else
588- write (iout,370 ) i,(detot (j,i),j= 1 ,3 ),denorm(i)
593+ write (iout,370 ) i,(desum (j,i),j= 1 ,3 ),denorm(i)
589594 370 format (' Anlyt' ,2x ,i8,7x ,3f12 .4 ,2x ,f12.4 )
590595 end if
591596 end if
592597 if (donumer .and. use(i)) then
593- ndenorm(i) = ndetot (1 ,i)** 2 + ndetot (2 ,i)** 2
594- & + ndetot (3 ,i)** 2
598+ ndenorm(i) = ndesum (1 ,i)** 2 + ndesum (2 ,i)** 2
599+ & + ndesum (3 ,i)** 2
595600 ntotnorm = ntotnorm + ndenorm(i)
596601 ndenorm(i) = sqrt (ndenorm(i))
597602 if (digits .ge. 8 ) then
598- write (iout,380 ) i,(ndetot (j,i),j= 1 ,3 ),ndenorm(i)
603+ write (iout,380 ) i,(ndesum (j,i),j= 1 ,3 ),ndenorm(i)
599604 380 format (' Numer' ,i8,1x ,3f16 .8 ,f16.8 )
600605 else if (digits .ge. 6 ) then
601- write (iout,390 ) i,(ndetot (j,i),j= 1 ,3 ),ndenorm(i)
606+ write (iout,390 ) i,(ndesum (j,i),j= 1 ,3 ),ndenorm(i)
602607 390 format (' Numer' ,2x ,i8,3x ,3f14 .6 ,2x ,f14.6 )
603608 else
604- write (iout,400 ) i,(ndetot (j,i),j= 1 ,3 ),ndenorm(i)
609+ write (iout,400 ) i,(ndesum (j,i),j= 1 ,3 ),ndenorm(i)
605610 400 format (' Numer' ,2x ,i8,7x ,3f12 .4 ,2x ,f12.4 )
606611 end if
607612 end if
@@ -699,11 +704,13 @@ program testgrad
699704c
700705c perform deallocation of some local arrays
701706c
702- deallocate (denorm)
703- deallocate (detot)
707+ if (doanalyt) then
708+ deallocate (denorm)
709+ deallocate (derivs)
710+ end if
704711 if (donumer) then
705712 deallocate (ndenorm)
706- deallocate (ndetot )
713+ deallocate (ndesum )
707714 deallocate (ndeb)
708715 deallocate (ndea)
709716 deallocate (ndeba)
0 commit comments