      SUBROUTINE SPACE(MRESET, MSET, XPARAM, GRAD, HEAT, NVAR,
     1                 XSET, GSET, ESET, FRST)
      implicit double precision (A-H,O-Z)
      include 'SIZES'
      include 'MOP6FILE'
      dimension XPARAM(NVAR), GRAD(NVAR)
      dimension XSET(MRESET*NVAR),GSET(MRESET*NVAR), ESET(MRESET)
      logical FRST
C
C     UPDATE PARAMETER AND GRADIENT SUBSPACE
C
      if (FRST) then
         NRESET=MIN(NVAR/2,MRESET)
         FRST=.FALSE.
         MSET=0
      end if
C
      if (MSET .EQ. NRESET) then
         do 10 I=1,MSET-1
            MI = NVAR*(I-1)
            NI = NVAR*I
            ESET(I)=ESET(I+1)
            do 10 K=1,NVAR
               XSET(MI+K) = XSET(NI+K)
   10    GSET(MI+K) = GSET(NI+K)
         MSET=NRESET-1
      end if
C
C     STORE THE CURRENT POINT
C
      do 20 K=1,NVAR
         NMK = NVAR*MSET+K
         XSET(NMK) = XPARAM(K)
   20 GSET(NMK) = GRAD(K)
      MSET=MSET+1
      ESET(MSET)=HEAT
C
      return
      end
