      SUBROUTINE UPDHES(SVEC,TVEC,NVAR,IUPD)
      implicit double precision (A-H,O-Z)
      include 'SIZES'
      include 'MOP6FILE'
      dimension TVEC(*),SVEC(*)
      logical FIRST
      common/OPTEF/OLDF(MAXPAR),D(MAXPAR),VMODE(MAXPAR),
     1U(MAXPAR,MAXPAR),DD,MODE,NSTEP,NEGREQ,IPRNT
      common /NLLCOM/ HESS(MAXPAR,MAXPAR*3)
      common /GRADNT/ GRAD(MAXPAR),GNFINA
C
      data ZERO/0.0D0/
C
C  UPDATING OF THE HESSIAN
C  DEPENDS ON CURRENT GRADIENTS, OLD GRADIENTS AND THE
C  CORRECTION VECTOR USED ON THE LAST CYCLE
C  SVEC & TVEC ARE FOR TEMPORARY STORAGE
C
C  2 UPDATING PROCEDURES ARE POSSIBLE
C  (I)   THE POWELL UPDATE
C        THIS PRESERVES THE SYMMETRIC character OF THE HESSIAN
C        WHILST ALLOWING ITS EIGENVALUE STRUCTURE TO CHANGE.
C        IT IS THE DEFAULT UPDATE FOR A TRANSITION STATE SEARCH
C  (II)  THE BFGS UPDATE
C        THIS UPDATE HAS THE IMPORTANT characterISTIC OF RETAINING
C        POSITIVE DEFINITENESS (NOTE: THIS IS NOT RIGOROUSLY
C        GUARANTEED, BUT CAN BE CHECKED FOR BY THE PROGRAM).
C        IT IS THE DEFAULT UPDATE FOR A MINIMUM SEARCH
C
C     SWITCH : IUPD
C       IUPD = 0  :  SKIP UPDATE
C       IUPD = 1  :  POWELL
C       IUPD = 2  :  BFGS
C
      if (.NOT. FIRST) then
         FIRST=.TRUE.
         if (IPRNT.GE.2) then
            if (IUPD.EQ.0) write(MIOB,90)
            if (IUPD.EQ.1) write(MIOB,80)
            if (IUPD.EQ.2) write(MIOB,120)
         end if
      end if
      if (IUPD.EQ.0) return
      do 10 I=1,NVAR
         TVEC(I)=ZERO
         do 10 J=1,NVAR
            TVEC(I)=TVEC(I) + HESS(I,J)*D(J)
   10 continue
C
      if (IUPD.EQ.1) then
C
C   (I) POWELL UPDATE
C
         do 20 I=1,NVAR
            TVEC(I)=GRAD(I)-OLDF(I)-TVEC(I)
   20    continue
         DDS=DD*DD
         DDTD=DOT(TVEC,D,NVAR)
         DDTD=DDTD/DDS
C
         do 40 I=1,NVAR
            do 30 J=1,I
               TEMP=TVEC(I)*D(J) + D(I)*TVEC(J) - D(I)*DDTD*D(J)
               HESS(I,J)=HESS(I,J)+TEMP/DDS
               HESS(J,I)=HESS(I,J)
   30       continue
   40    continue
C
      end if
      if (IUPD.EQ.2) then
C
C  (II) BFGS UPDATE
C
         do 50 I=1,NVAR
            SVEC(I)=GRAD(I)-OLDF(I)
   50    continue
         DDS=DOT(SVEC,D,NVAR)
C
C  IF DDS IS NEGATIVE, RETENTION OF POSITIVE DEFINITENESS IS NOT
C  GUARANTEED. PRINT A WARNING AND SKIP UPDATE THIS CYCLE.
C
         if (DDS.LT.ZERO) then
            write(MIOB,100)
            write(MIOB,110)
            return
         end if
C
         DDTD=DOT(D,TVEC,NVAR)
C
         do 70 I=1,NVAR
            do 60 J=1,I
               TEMP= (SVEC(I)*SVEC(J))/DDS - (TVEC(I)*TVEC(J))/DDTD
               HESS(I,J)=HESS(I,J)+TEMP
               HESS(J,I)=HESS(I,J)
   60       continue
   70    continue
      end if
C
      return
C
   80 format(/,5X,'HESSIAN IS BEING UPDATED USING THE POWELL UPDATE',/)
   90 format(/,5X,'HESSIAN IS NOT BEING UPDATED',/)
  100 format(5X,'WARNING! HEREDITARY POSITIVE DEFINITENESS endANGERED')
  110 format(5X,'UPDATE SKIPPED THIS CYCLE')
  120 format(/,5X,'HESSIAN IS BEING UPDATED USING THE BFGS UPDATE',/)
      end
