      IF(WQ.EQ.'POWL'.OR.WQ.EQ.'P'.OR.WQ.EQ.'POWELL') THEN
        WRITE(OUTLYNE,*)
     1  'PERFORMING POWELL OPTIMIZATION'
      CALL SHOWIT(1)
        WRITE(OUTLYNE,*)
     1  'PLEASE WAIT...'
      CALL SHOWIT(1)
                   SOLEXT=.FALSE.
      IIID=OPCNT
      JJJD=VBCNT
      IF(IIID.GE.JJJD)MAXCNT=IIID+1
      IF(IIID.LT.JJJD)MAXCNT=JJJD+1
      VIP=MAXCNT+1
                        CALL ITERIP(VIP,0,ITERROR)
                   SOLEXT=.TRUE.
                       PLL=.TRUE.
                        RETURN
                        END IF
      SUBROUTINE POWELL(V,VN,PCNT,P)
      IMPLICIT NONE
      INTEGER ITER,NUB,VN,PCNT
      COMMON/ITTERY/ITER
      REAL*8 FRET,FUNCIP,P
      COMMON/FRETTY/FRET
      EXTERNAL FUNCIP
C     USES LINMIN,FUNCIP
      INTEGER I,J,IBIG,ALLOERR
      REAL*8 DEL,FP,FPTT,T,V
      DIMENSION V(VN,VN)
C
      REAL*8 PT,XIT
     1,XDUM(1:100000)
C
      DIMENSION P(PCNT),PT(:),XIT(:)
C
      ALLOCATABLE :: PT,XIT
C
      COMMON/FNPEE/XDUM
C
        REAL*8
     2  X(1:100000)
C
      COMMON/SVD2/X
C
      INCLUDE 'DATSUB.INC'
      INCLUDE 'DATLEN.INC'
      INCLUDE 'DATMAI.INC'
      NUB=VBCNT+1
      DEALLOCATE(PT,XIT,STAT=ALLOERR)
      ALLOCATE(PT(NUB),XIT(NUB),STAT=ALLOERR)
      XDUM(1:VBCNT)=P(1:VBCNT)
      FRET=FUNCIP()
      PT(1:VBCNT)=P(1:VBCNT)
      ITER=0
1     ITER=ITER+1
      FP=FRET
      IBIG=0
      DEL=0.0D0
      DO I=1,VBCNT
          XIT(1:VBCNT)=V(1:VBCNT,I)
        FPTT=FRET
C     LINMIN IS CALLED ONCE FOR EACH VARIABLE (THE ITH VARIABLE)
        CALL LINMIN(V,VN,I,PCNT,P,XIT)
        IF(DABS(FPTT-FRET).GT.DEL) THEN
          DEL=DABS(FPTT-FRET)
          IBIG=I
        END IF
      END DO
      DEALLOCATE(PT,XIT,STAT=ALLOERR)
      RETURN
      END
C
      SUBROUTINE LINMIN(V,VN,K,PCNT,P,XXI)
      IMPLICIT NONE
      INTEGER NUB,K,PCNT,ALLOERR
      REAL*8 FRET,P,XXI,TOL
      DIMENSION P(PCNT),XXI(PCNT)
      COMMON/FRETTY/FRET
CU    USES JACME
      INTEGER J,NCOM,VN
      REAL*8 AX,BX,FA,FB,FX,XMIN,XX,PCOM,JKX
      REAL*8 JKAX,JKXX,JKBX,JKXMIN,V
     1,XICOM,JACME
      DIMENSION PCOM(:),XICOM(:)
      ALLOCATABLE :: PCOM,XICOM
      COMMON/MNBRAC/AX,XX,BX,FA,FX,FB
      COMMON /F1COM/NCOM
      COMMON/F2COM/JKX
      COMMON/JACMEON/JKAX,JKXX,JKBX,JKXMIN
      EXTERNAL JACME
      DIMENSION V(VN,VN)
C
      INCLUDE 'DATSUB.INC'
      INCLUDE 'DATLEN.INC'
      INCLUDE 'DATMAI.INC'
      NUB=VBCNT+1
      DEALLOCATE(PCOM,XICOM,STAT=ALLOERR)
      ALLOCATE(PCOM(NUB),XICOM(NUB),STAT=ALLOERR)
      NCOM=NUB
      J=NUB
        PCOM(1:J)=P(1:J)
        XICOM(1:J)=XXI(1:J)
      AX=-1.0D0
      XX=0.0D0
      BX=1.0D0
      JKAX=AX
      JKXX=XX
      JKBX=BX
      JKXMIN=XMIN
      FRET=JACME(NUB,PCOM,XICOM)
      AX=JKAX
      XX=JKXX
      BX=JKBX
      XMIN=JKXMIN
      J=NUB
        XXI(1:J)=XMIN*XXI(1:J)
        P(1:J)=P(1:J)+XXI(1:J)
      DEALLOCATE(PCOM,STAT=ALLOERR)
      RETURN
      END
C
      FUNCTION JACME(NUB,PCOM,XICOM)
      IMPLICIT NONE
      INTEGER NUB
      REAL*8 JACME,AX,BX,CX,F1DIM,JKX,FAX,FBX,FCX
     1,FX,X,XMIN,FDEL1,FDEL2,FDEL3,DX1,DX2,DX3,DX12,DX22,DX32
     2,AXX,BXX,CXX,AAEE,BBEE,CCEE,PCOM,XICOM
      DIMENSION PCOM(NUB),XICOM(NUB)
      EXTERNAL F1DIM
      COMMON/F2COM/JKX
      COMMON/JACMEON/AX,BX,CX,XMIN
      INCLUDE 'DATLEN.INC'
      INCLUDE 'DATMAI.INC'
      INCLUDE 'DATSUB.INC'
C
C     AX,BX,CX ALL EQUAL
      IF(AX.EQ.BX.AND.AX.EQ.CX) THEN
      JKX=AX
      FAX=F1DIM(NUB,PCOM,XICOM)
      XMIN=AX
      JACME=FAX
                   RETURN
                   END IF
C
C     TWO VALUES EQUAL
      IF(AX.EQ.BX.AND.AX.NE.CX.OR.
     1BX.EQ.CX.AND.AX.NE.CX.OR.
     1AX.NE.BX.AND.AX.EQ.CX.OR.
     1BX.NE.CX.AND.AX.EQ.CX) THEN
C
      IF(AX.EQ.BX.AND.AX.NE.CX.OR.
     1BX.EQ.CX.AND.AX.NE.CX) AXX=(AX+CX)/2.0D0
      IF(AX.NE.BX.AND.AX.EQ.CX.OR.
     1BX.NE.CX.AND.AX.EQ.CX) AXX=(BX+CX)/2.0D0
      JKX=AXX
      FAX=F1DIM(NUB,PCOM,XICOM)
      XMIN=AXX
      JACME=FAX
                   RETURN
                   END IF
C     AX,BX,CX ALL DIFFERENT
C     LARGEST VALUE
      CXX=DMAX1(AX,BX,CX)
C     SMALLEST VALUE
      AXX=DMIN1(AX,BX,CX)
C     MIDDLE VALUE
      IF(AX.LT.CXX.AND.AX.GT.AXX) BXX=AX
      IF(BX.LT.CXX.AND.BX.GT.AXX) BXX=BX
      IF(CX.LT.CXX.AND.CX.GT.AXX) BXX=CX
      JKX=AXX
      FAX=F1DIM(NUB,PCOM,XICOM)
      JKX=BXX
      FBX=F1DIM(NUB,PCOM,XICOM)
      JKX=CXX
      FCX=F1DIM(NUB,PCOM,XICOM)
C     FIT TO A PARABOLA AND SOLVE FOR THE MINIMUM
C     THE X FOR THE MINIMUM WILL BE XMIN
C     WITH FUNCTIONAL VALUE JACME
C     THIS IS TO DO AFTER MY RUN
      FDEL1=FAX-FBX
      FDEL2=FAX-FCX
      FDEL3=FBX-FCX
      DX1=AXX-BXX
      DX2=AXX-CXX
      DX3=BXX-CXX
      DX12=(AXX**2)-(BXX**2)
      DX22=(AXX**2)-(CXX**2)
      DX32=(BXX**2)-(CXX**2)
C
      IF(FDEL1.EQ.0.0D0.OR.FDEL2.EQ.0.0D0.OR.FDEL3.EQ.0.0D0) THEN
C     USE MIDDLE VALUE
      JKX=BXX
      FBX=F1DIM(NUB,PCOM,XICOM)
      XMIN=BXX
      JACME=FBX
                       RETURN
                       ELSE
C     SOLVE FOR X AND FX ON A PARABOLA
C
      IF(((DX1*DX22)-(DX2*DX12)).EQ.0.0D0.OR.DX12.EQ.0.0D0) THEN
                   X=BXX
                   FX=FBX
                   ELSE
      BBEE=((FDEL1*DX22)-(FDEL2*DX12))/((DX1*DX22)-(DX2*DX12))
      AAEE=(FDEL1-(BBEE*DX1))/DX12
      CCEE=FAX-(AAEE*DX12)-(BBEE*DX1)
      IF(BBEE.EQ.0.0D0) THEN
               X=0.0D0
               ELSE
      IF(AAEE.EQ.0.0D0) THEN
               X=BXX
               ELSE
      X=-BBEE/(2.0D0*AAEE)
               END IF
               END IF
      FX=(AAEE*(X**2))+(BBEE*X)+CCEE
               END IF
      XMIN=X
      JACME=FX
      RETURN
                       END IF
      END
      FUNCTION F1DIM(NUB,PCOM,XICOM)
      IMPLICIT NONE
      INTEGER ALLOERR
      REAL*8 F1DIM,FUNCIP,JKX,XDUM(1:100000)
      COMMON/FNPEE/XDUM
CU    USES FUNCIP
      EXTERNAL FUNCIP
      INTEGER J,NCOM,NUB
      REAL*8 XT,PCOM,XICOM
      DIMENSION PCOM(NUB),XICOM(NUB),XT(:)
      ALLOCATABLE :: XT
      COMMON /F1COM/NCOM
      COMMON/F2COM/JKX
      INCLUDE 'DATSUB.INC'
      INCLUDE 'DATMAI.INC'
      DEALLOCATE (XT,STAT=ALLOERR)
      ALLOCATE(XT(NCOM),STAT=ALLOERR)
      J=NCOM
        XT(1:J)=PCOM(1:J)+JKX*XICOM(1:J)
        XDUM(1:J)=XT(1:J)
      F1DIM=FUNCIP()
      DEALLOCATE (XT,STAT=ALLOERR)
      RETURN
      END
C
C FUN FUNCIP.FOR
      FUNCTION FUNCIP()
C
      IMPLICIT NONE
C
      INTEGER I,J,VCFG,VTYPE,ALTYPE,VADD,II,JJ,NUB
C
      CHARACTER AN1*23,AV1*23,OLDAV1*23
C
      INTEGER ISURF
C
      REAL*8 NEWDEFVAL
C
      COMMON/DEFVALCOM/NEWDEFVAL
C
      REAL*8 IPFUN,V1,OLDV1,JK_DEL
     1,N1,FUNCIP,XDUM(1:100000)
      LOGICAL COMPOPS,ERR1,ERR2
      COMMON/OPSCOMP/COMPOPS
C
      COMMON/FNPEE/XDUM
C
      EXTERNAL IPFUN
C
      COMMON/CAUX1/N1,AN1
C
C     THIS ROUTINE APPLIES THE VARIABLES CONTAINED IN THE XDIM
C     ARRAY TO THE CURRENT LENS AND THEN COMPUTES THE NEW RESULTANT FMT
C
C     IPFMT IS THE RESULTING FIGURE OF MERIT
C
        INCLUDE 'DATSUB.INC'
        INCLUDE 'DATMAI.INC'
        INCLUDE 'DATLEN.INC'
        INCLUDE 'DATCFG.INC'
        INCLUDE 'DATMAC.INC'
C
C       THIS IS SUBROUTINE FUNCIP. THIS IS THE SUBROUTINE WHICH
C       CALCULATES THE FMT FOR POWELL OPTIMIZATION
C       FOR THE VARIABLE VALUES IN ARRAY XDUM
C
      NUB=VBCNT+1
C
C     SAVE THE ORIGINAL OPERANDS BEFORE WE START
                   OLDOP(1:OPCNT,1:20)=OPERND(1:OPCNT,1:20)
                   DO I=1,VBCNT
C     NOW FOR VARIABLE I MAKE THE APPROPRIATE
C     CHANGE TO THE LENS
C     FIRST, IF THE VARIABLE IS A CONFIG 1 VARIABLE
C     NEXT IF THE VARIABLE IS IN A CONFIG OTHER THAN 1
      IF(COMPOPS) VARABL(I,2)=1.0D0
      IF(VARABL(I,2).EQ.1.0D0) THEN
C     NON-CONFIGS VARIABLE MEANING CONFIG 1
C     THIS IS A LENS LEVEL VARIABLE CHANGE AND DERIVATIVE STUFF
C     GET THE DATA TYPE NUMBER OF THE VARIABLE
      VTYPE=INT(VARABL(I,1))
C                          CURVATURE
      IF(VTYPE.EQ.2.OR.VTYPE.EQ.1) THEN
C     SURFACE CURVATURE
C     NEW VALUE IS:
      V1=XDUM(I)
                      ALENS(1,INT(VARABL(I,3)))=V1
C                     CURVATURE DONE
                        END IF
      IF(VTYPE.EQ.10.OR.VTYPE.EQ.9) THEN
C     SURFACE TORIC CURVATURE
C     NEW VALUE IS:
      V1=XDUM(I)
      ALENS(24,INT(VARABL(I,3)))=V1
                   END IF
      IF(VTYPE.GE.3.AND.VTYPE.LE.8) THEN
      IF(VTYPE.EQ.3) ALTYPE=3
      IF(VTYPE.EQ.4) ALTYPE=2
      IF(VTYPE.EQ.5) ALTYPE=4
      IF(VTYPE.EQ.6) ALTYPE=5
      IF(VTYPE.EQ.7) ALTYPE=6
      IF(VTYPE.EQ.8) ALTYPE=7
C     NEW VALUE IS:
      V1=XDUM(I)
      ALENS(ALTYPE,INT(VARABL(I,3)))=V1
                       END IF
      IF(VTYPE.GE.11.AND.VTYPE.LE.25.OR.VTYPE.EQ.75.OR.VTYPE.GE.
     1124.AND.VTYPE.LE.149) THEN
      IF(VTYPE.EQ.11) ALTYPE=41
      IF(VTYPE.EQ.12) ALTYPE=37
      IF(VTYPE.EQ.13) ALTYPE=38
      IF(VTYPE.EQ.14) ALTYPE=39
      IF(VTYPE.EQ.15) ALTYPE=40
      IF(VTYPE.EQ.16) ALTYPE=118
      IF(VTYPE.EQ.17) ALTYPE=119
      IF(VTYPE.EQ.18) ALTYPE=120
      IF(VTYPE.EQ.19) ALTYPE=114
      IF(VTYPE.EQ.20) ALTYPE=115
      IF(VTYPE.EQ.21) ALTYPE=46
      IF(VTYPE.EQ.22) ALTYPE=47
      IF(VTYPE.EQ.23) ALTYPE=48
      IF(VTYPE.EQ.24) ALTYPE=49
      IF(VTYPE.EQ.25) ALTYPE=50
      IF(VTYPE.EQ.75) ALTYPE=43
      IF(VTYPE.EQ.124) ALTYPE=71
      IF(VTYPE.EQ.125) ALTYPE=72
      IF(VTYPE.EQ.126) ALTYPE=73
      IF(VTYPE.EQ.127) ALTYPE=74
      IF(VTYPE.EQ.128) ALTYPE=75
      IF(VTYPE.EQ.129) ALTYPE=81
      IF(VTYPE.EQ.130) ALTYPE=82
      IF(VTYPE.EQ.131) ALTYPE=83
      IF(VTYPE.EQ.132) ALTYPE=84
      IF(VTYPE.EQ.133) ALTYPE=85
      IF(VTYPE.EQ.134) ALTYPE=116
      IF(VTYPE.EQ.135) ALTYPE=86
      IF(VTYPE.EQ.136) ALTYPE=87
      IF(VTYPE.EQ.137) ALTYPE=78
      IF(VTYPE.EQ.138) ALTYPE=79
      IF(VTYPE.EQ.139) ALTYPE=80
      IF(VTYPE.EQ.140) ALTYPE=89
      IF(VTYPE.EQ.141) ALTYPE=11
      IF(VTYPE.EQ.142) ALTYPE=10
      IF(VTYPE.EQ.143) ALTYPE=90
      IF(VTYPE.EQ.144) ALTYPE=91
      IF(VTYPE.EQ.145) ALTYPE=92
      IF(VTYPE.EQ.146) ALTYPE=93
      IF(VTYPE.EQ.147) ALTYPE=94
      IF(VTYPE.EQ.148) ALTYPE=95
      IF(VTYPE.EQ.149) ALTYPE=98
C     NEW VALUE IS:
      V1=XDUM(I)
      ALENS(ALTYPE,INT(VARABL(I,3)))=V1
                   END IF
      IF(VTYPE.EQ.150) THEN
      V1=XDUM(I)
      GPREG(INT(VARABL(I,3)))=V1
                   END IF
      IF(VTYPE.GE.250.AND.VTYPE.LE.4218) THEN
      ALTYPE=VTYPE-249
C     NEW VALUE IS:
      V1=VARABL(I,4)
C     RESET THE APPRORIATE ARRAY VALUE IN THE DEFORMABLE SURFACE
      ISURF=INT(VARABL(I,3))
      DEFGR1=ALENS(103,ISURF)
      DEFGR2=ALENS(104,ISURF)
      DEFGR3=ALENS(105,ISURF)
      DEFGR4=ALENS(106,ISURF)
      DEFGR5=ALENS(107,ISURF)
      DEFGR6=0.0D0
      DEFGR7=ALENS(109,ISURF)
      DEFGR8=0.0D0
      ACTNUM=ALTYPE
      NEWDEFVAL=V1
      ERR1=.FALSE.
      ERR2=.FALSE.
      CALL DEFGRIDS(6,ISURF,ERR1,ERR2)
                        END IF
      IF(VTYPE.GE.27.AND.VTYPE.LE.74) THEN
C     SPECIAL SURFACE COEFFICIENTS
C     NEW VALUE IS:
      V1=XDUM(I)
      FTFL01((VTYPE-26),INT(VARABL(I,3)))=V1
C                       SPECIAL SURFACE COEFICIENTS DONE
                        END IF
      IF(VTYPE.GE.76.AND.VTYPE.LE.123) THEN
C     SPECIAL SURFACE COEFFICIENTS
C     NEW VALUE IS:
      V1=XDUM(I)
      FTFL01((VTYPE-27),INT(VARABL(I,3)))=V1
                               END IF
                                ELSE
C     CONFIGS VARIABLE
C     VCFG IS THE CONFIG NUMBER
      VCFG=INT(VARABL(I,2))
C     VTYPE IS THE VARIABLE TYPE NUMBER AS USED IN THE VARIABLES ARRAYS
      VTYPE=INT(VARABL(I,1))
C
C     FOR VARIABLE I, APPLY THE SPECIFIED CHANGE TO THE SPECIFIED
C     CONFIG, DO AN EOS AND EVALUATE ALL OPERANDS
C
C     THE OLD VARIABLE VALUE IS:
                OLDV1=VARABL(I,4)
C     CONVERT THIS VALUE TO A CHARACTER*23 CHARACTER VARIABLE
C     OLDVA1 IS THE VALUE WE WILL USE IN THE RESTORATION PROCESS
C     AFTER THE DERIVATIVE IS CALCULATED
                VADD=INT(VARABL(I,14))
      IF(CFADD(VADD,1).EQ.1.AND.OLDV1.NE.0.0D0) OLDV1=1.0D0/OLDV1
      IF(CFADD(VADD,1).EQ.9.AND.OLDV1.NE.0.0D0) OLDV1=1.0D0/OLDV1
                   N1=OLDV1
                CALL AUXNTA
                   OLDAV1=AN1
C     THE NEW VARAIBLE VALUE IS JUST
                V1=XDUM(I)
C     CONVERT THIS VALUE TO A CHARACTER*23 CHARACTER VARIABLE
      IF(CFADD(VADD,1).EQ.1.AND.V1.NE.0.0D0) V1=1.0D0/V1
      IF(CFADD(VADD,1).EQ.9.AND.V1.NE.0.0D0) V1=1.0D0/V1
                   N1=V1
                CALL AUXNTA
                   AV1=AN1
C
C     THE POSITION IN THE CFADD,CFVAL AND CFCHAR ARRAYS WHERE THIS
C     VARIABLE IS FOUND IS:
C
      IF(CFADD(VADD,1).GE.27.AND.CFADD(VADD,1).LE.74.OR.
     1CFADD(VADD,1).GE.76.AND.CFADD(VADD,1).LE.123
     1.OR.CFADD(VADD,1).EQ.141) THEN
      CFVAL(VADD,2)=V1
      CFCHAR(VADD,2)=AV1
                      ELSE
      CFVAL(VADD,1)=V1
      CFCHAR(VADD,1)=AV1
                      END IF
C     NOW UPDATE THE CONFIG ARRAY
C     NOW LOOK UP WHERE THIS CHARACTER REPRESENTATION OF THE NEW VALUE
C     SHOULD BE STUFFED INTO THE CONFIG ARRAYS CONFG AND
C     STUFF IT THERE.
C     NOW UPDATE THE CONFIG ARRAY
                VADD=INT(VARABL(I,14))
      IF(CFADD(VADD,1).GE.27.AND.CFADD(VADD,1).LE.74.OR.
     1CFADD(VADD,1).GE.76.AND.CFADD(VADD,1).LE.123
     1.OR.CFADD(VADD,1).EQ.141) THEN
      CONFG(CFADD(VADD,3),CFADD(VADD,9))(CFADD(VADD,6):CFADD(VADD,7))
     1=AV1(1:23)
                       ELSE
      CONFG(CFADD(VADD,3),CFADD(VADD,9))(CFADD(VADD,4):CFADD(VADD,5))
     1=AV1(1:23)
                       END IF
C
C     VARIABLE DONE
C     FINISHED WITH A CONFIG VARIABLE
                        END IF
                        END DO
C     EVALUATE THE MERIT FUNCTION
C     UPDATE THE LENS
                        F6=1
                        F1=0
                        F22=0
                       IF(.NOT.COMPOPS)LNSTYP=2
                       IF(COMPOPS)LNSTYP=3
                       CALL LNSEOS
C     CALCULATE OPERANDS AND LOAD THEM
      IF(.NOT.COMPOPS)OPCALC_TYPE=3
      IF(COMPOPS) OPCALC_TYPE=1
                        CALL OPCALC
      IF(.NOT.COMPOPS.AND.F28.EQ.0) RETURN
      IF(COMPOPS.AND.F31.EQ.0) RETURN
                        CALL OPLOAD
      IF(KILOPT) THEN
C     NO SOLUTION IS ATTEMPTED
      OUTLYNE='SOME OPERANDS ARE NOT CALCULABLE.'
      CALL SHOWIT(1)
      OUTLYNE='"ITER POWELL" CAN NOT PROCEED.'
      CALL SHOWIT(1)
                       IF(.NOT.COMPOPS) F28=0
                       IF(COMPOPS) F31=0
                       CALL MACFAL
                       RETURN
                       END IF
      IF(.NOT.COMPOPS.AND.F28.EQ.0) RETURN
      IF(COMPOPS.AND.F31.EQ.0) RETURN
C     CALCULATE IPFMT
               IPFMT=IPFUN()
               FUNCIP=IPFMT
C
C     NOW RESTORE THE LENS
                        DO I=1,VBCNT
      IF(VARABL(I,2).EQ.1.0D0) THEN
C     NON-CONFIGS VARIABLE MEANING CONFIG 1
C     THIS IS A LENS LEVEL VARIABLE CHANGE AND DERIVATIVE STUFF
C     GET THE DATA TYPE NUMBER OF THE VARIABLE
      VTYPE=INT(VARABL(I,1))
C                          CURVATURE
      IF(VTYPE.EQ.2.OR.VTYPE.EQ.1) THEN
C     SURFACE CURVATURE
C     RESTORE THE LENS
      ALENS(1,INT(VARABL(I,3)))=VARABL(I,4)
C                       CURVATURE DONE
                        END IF
      IF(VTYPE.EQ.10.OR.VTYPE.EQ.9) THEN
C     SURFACE TORIC CURVATURE
C     RESTORE THE LENS
      ALENS(24,INT(VARABL(I,3)))=VARABL(I,4)
C                       TORIC CURVATURE DONE
                        END IF
      IF(VTYPE.GE.3.AND.VTYPE.LE.8) THEN
      IF(VTYPE.EQ.3) ALTYPE=3
      IF(VTYPE.EQ.4) ALTYPE=2
      IF(VTYPE.EQ.5) ALTYPE=4
      IF(VTYPE.EQ.6) ALTYPE=5
      IF(VTYPE.EQ.7) ALTYPE=6
      IF(VTYPE.EQ.8) ALTYPE=7
C     RESTORE THE LENS
      ALENS(ALTYPE,INT(VARABL(I,3)))=VARABL(I,4)
C                       THESE VARIABLES DONE
                        END IF
      IF(VTYPE.GE.11.AND.VTYPE.LE.25.OR.VTYPE.EQ.75.OR.VTYPE.GE.
     1124.AND.VTYPE.LE.149) THEN
      IF(VTYPE.EQ.11) ALTYPE=41
      IF(VTYPE.EQ.12) ALTYPE=37
      IF(VTYPE.EQ.13) ALTYPE=38
      IF(VTYPE.EQ.14) ALTYPE=39
      IF(VTYPE.EQ.15) ALTYPE=40
      IF(VTYPE.EQ.16) ALTYPE=118
      IF(VTYPE.EQ.17) ALTYPE=119
      IF(VTYPE.EQ.18) ALTYPE=120
      IF(VTYPE.EQ.19) ALTYPE=114
      IF(VTYPE.EQ.20) ALTYPE=115
      IF(VTYPE.EQ.21) ALTYPE=46
      IF(VTYPE.EQ.22) ALTYPE=47
      IF(VTYPE.EQ.23) ALTYPE=48
      IF(VTYPE.EQ.24) ALTYPE=49
      IF(VTYPE.EQ.25) ALTYPE=50
      IF(VTYPE.EQ.75) ALTYPE=43
      IF(VTYPE.EQ.124) ALTYPE=71
      IF(VTYPE.EQ.125) ALTYPE=72
      IF(VTYPE.EQ.126) ALTYPE=73
      IF(VTYPE.EQ.127) ALTYPE=74
      IF(VTYPE.EQ.128) ALTYPE=75
      IF(VTYPE.EQ.129) ALTYPE=81
      IF(VTYPE.EQ.130) ALTYPE=82
      IF(VTYPE.EQ.131) ALTYPE=83
      IF(VTYPE.EQ.132) ALTYPE=84
      IF(VTYPE.EQ.133) ALTYPE=85
      IF(VTYPE.EQ.134) ALTYPE=116
      IF(VTYPE.EQ.135) ALTYPE=86
      IF(VTYPE.EQ.136) ALTYPE=87
      IF(VTYPE.EQ.137) ALTYPE=78
      IF(VTYPE.EQ.138) ALTYPE=79
      IF(VTYPE.EQ.139) ALTYPE=80
      IF(VTYPE.EQ.140) ALTYPE=89
      IF(VTYPE.EQ.141) ALTYPE=11
      IF(VTYPE.EQ.142) ALTYPE=10
      IF(VTYPE.EQ.143) ALTYPE=90
      IF(VTYPE.EQ.144) ALTYPE=91
      IF(VTYPE.EQ.145) ALTYPE=92
      IF(VTYPE.EQ.146) ALTYPE=93
      IF(VTYPE.EQ.147) ALTYPE=94
      IF(VTYPE.EQ.148) ALTYPE=95
      IF(VTYPE.EQ.149) ALTYPE=98
C     RESTORE THE LENS
      ALENS(ALTYPE,INT(VARABL(I,3)))=VARABL(I,4)
                        END IF
      IF(VTYPE.EQ.150) THEN
      V1=VARABL(I,4)
      GPREG(INT(VARABL(I,3)))=V1
                   END IF
      IF(VTYPE.GE.250.AND.VTYPE.LE.4218) THEN
      ALTYPE=VTYPE-249
C     NEW VALUE IS:
      V1=VARABL(I,4)
C     RESET THE APPRORIATE ARRAY VALUE IN THE DEFORMABLE SURFACE
      ISURF=INT(VARABL(I,3))
      DEFGR1=ALENS(103,ISURF)
      DEFGR2=ALENS(104,ISURF)
      DEFGR3=ALENS(105,ISURF)
      DEFGR4=ALENS(106,ISURF)
      DEFGR5=ALENS(107,ISURF)
      DEFGR6=0.0D0
      DEFGR7=ALENS(109,ISURF)
      DEFGR8=0.0D0
      ACTNUM=ALTYPE
      NEWDEFVAL=V1
      ERR1=.FALSE.
      ERR2=.FALSE.
      CALL DEFGRIDS(6,ISURF,ERR1,ERR2)
                        END IF
      IF(VTYPE.GE.27.AND.VTYPE.LE.74) THEN
C     SPECIAL SURFACE COEFFICIENTS
C     RESTORE THE LENS
      FTFL01((VTYPE-26),INT(VARABL(I,3)))=VARABL(I,4)
C                       SPECIAL SURFACE COEFICIENTS DONE
                        END IF
      IF(VTYPE.GE.76.AND.VTYPE.LE.123) THEN
C     SPECIAL SURFACE COEFFICIENTS
C     RESTORE THE LENS
      FTFL01((VTYPE-27),INT(VARABL(I,3)))=VARABL(I,4)
C                       SPECIAL SURFACE COEFICIENTS DONE
                        END IF
                                ELSE
C     CONFIGS VARIABLE
C     VCFG IS THE CONFIG NUMBER
      VCFG=INT(VARABL(I,2))
C     VTYPE IS THE VARIABLE TYPE NUMBER AS USED IN THE VARIABLES ARRAYS
      VTYPE=INT(VARABL(I,1))
C
C     FOR VARIABLE I, APPLY THE SPECIFIED CHANGE TO THE SPECIFIED
C     CONFIG, DO AN EOS AND EVALUATE ALL OPERANDS
C
C     THE OLD VARIABLE VALUE IS:
                OLDV1=VARABL(I,4)
C     CONVERT THIS VALUE TO A CHARACTER*23 CHARACTER VARIABLE
C     OLDVA1 IS THE VALUE WE WILL USE IN THE RESTORATION PROCESS
C     AFTER THE DERIVATIVE IS CALCULATED
                VADD=INT(VARABL(I,14))
      IF(CFADD(VADD,1).EQ.1.AND.OLDV1.NE.0.0D0) OLDV1=1.0D0/OLDV1
      IF(CFADD(VADD,1).EQ.9.AND.OLDV1.NE.0.0D0) OLDV1=1.0D0/OLDV1
                   N1=OLDV1
                CALL AUXNTA
                   OLDAV1=AN1
C
C     THE POSITION IN THE CFADD,CFVAL AND CFCHAR ARRAYS WHERE THIS
C     VARIABLE IS FOUND IS:
C
C
C     STUFF OLDAV1
      IF(CFADD(VADD,1).GE.27.AND.CFADD(VADD,1).LE.74.OR.
     1CFADD(VADD,1).GE.76.AND.CFADD(VADD,1).LE.123
     1.OR.CFADD(VADD,1).EQ.141) THEN
      CFVAL(VADD,2)=OLDV1
      CFCHAR(VADD,2)=OLDAV1
C     NOW UPDATE THE CONFIG ARRAY
      CONFG(CFADD(VADD,3),CFADD(VADD,9))(CFADD(VADD,6):CFADD(VADD,6))
     1=OLDAV1(1:23)
                                        ELSE
      CFVAL(VADD,1)=OLDV1
      CFCHAR(VADD,1)=OLDAV1
C     NOW UPDATE THE CONFIG ARRAY
      CONFG(CFADD(VADD,3),CFADD(VADD,9))(CFADD(VADD,4):CFADD(VADD,5))
     1=OLDAV1(1:23)
                                         END IF

C     VARIABLE DONE
C     FINISHED WITH A CONFIG VARIABLE
                        END IF
                        END DO
C
C     WE JUST DID THE LAST CALCULATION AND WE WANT TO
C     RESTORE THE ORIGINAL OPERANDS
                     OPERND(1:OPCNT,1:20)=OLDOP(1:OPCNT,1:20)
C     UPDATE THE LENS OR THE PERMANENT LENS WILL BE ******!
                        F6=1
                        F1=0
                        F22=0
                       IF(.NOT.COMPOPS)LNSTYP=2
                       IF(COMPOPS)LNSTYP=3
                       CALL LNSEOS
                        RETURN
                        END
      FUNCTION IPFUN()
      IMPLICIT NONE
      REAL*8 IPFUN
      INTEGER I
        INCLUDE 'DATSUB.INC'
        INCLUDE 'DATMAI.INC'
C
                        IPFUN=0.0D0
                        DO I=1,OPCNT
      IPFUN=IPFUN+(OPERND(I,14)**2)
                        END DO
                        RETURN
                        END
      SUBROUTINE ITERIP(VN,IITTPP,ITERROR)
      IMPLICIT NONE
C     SUBROUTINE WHICH RUNS ONE CYCLE OF POWELL'S OPTIMIZATION
C     SPECIAL VARIABLES ARE IN DATLEN.FOR
C     AND DATSUB.FOR
C
      REAL*8 P
C
      DIMENSION P(:)
C
      ALLOCATABLE :: P
C
      REAL*8 OCRIT(10),NCRIT(10)
C
      COMMON/ONCRIT/OCRIT,NCRIT
C
      INTEGER NUB,ALLOERR,PCNT
C
      INTEGER ISURF
C
      REAL*8 NEWDEFVAL
C
      COMMON/DEFVALCOM/NEWDEFVAL
C
      INTEGER CMPSURF(10)
C
      COMMON/SURFCMP/CMPSURF
C
      REAL*8 MOT(1:10)
C
      COMMON/LOCOMOTION/MOT
C
        INTEGER VN,N,L,M,VTYPE,ALTYPE,VADD,VCFG,IITTPP
C
        REAL*8
     2  X(1:100000),V1,MAX,VTEMP,OLDCUR,NEWCUR
     3  ,N1
C
      LOGICAL LVAL
C
      CHARACTER AN1*23,AV1*23
C
      COMMON/SVD2/X
C
      INTEGER I,II,JJ,ITER
      COMMON/ITTERY/ITER
C
      REAL*8 FRET,V
      DIMENSION V(:,:)
      ALLOCATABLE :: V
      COMMON/FRETTY/FRET
C
      LOGICAL PLL,ERR1,ERR2
      LOGICAL COMPOPS
      COMMON/OPSCOMP/COMPOPS
      COMMON/PLLPLL/PLL
C
      COMMON/CAUX1/N1,AN1
C
        INCLUDE 'DATSUB.INC'
        INCLUDE 'DATMAI.INC'
        INCLUDE 'DATLEN.INC'
        INCLUDE 'DATCFG.INC'
        INCLUDE 'DATMAC.INC'
C
      INTEGER J
      REAL*8 FUNCIP
      EXTERNAL FUNCIP
C
C
      COMPOPS=.FALSE.
      IF(IITTPP.NE.0) THEN
      COMPOPS=.TRUE.
      F31=1
      END IF
      PCNT=VBCNT+1
C
      DEALLOCATE(V,STAT=ALLOERR)
      DEALLOCATE(P,STAT=ALLOERR)
      ALLOCATE(V(VN,VN),STAT=ALLOERR)
      ALLOCATE(P(PCNT),STAT=ALLOERR)
C
      IF(OPCNT.EQ.0.OR.VBCNT.EQ.0) THEN
        WRITE(OUTLYNE,*)
     1'"ITER POWL" OR "IT P" OR "ITER POWELL"'
      CALL SHOWIT(1)
        WRITE(OUTLYNE,*)
     1'REQUIRES VARIABLES AND OPERANDS TO EXIST'
      CALL SHOWIT(1)
        WRITE(OUTLYNE,*)
     1  'BEFORE IT CAN FUNCTION'
      CALL SHOWIT(1)
        WRITE(OUTLYNE,*)'NO ACTION TAKEN'
      CALL SHOWIT(1)
                        CALL MACFAL
      DEALLOCATE(V,P,STAT=ALLOERR)
                        RETURN
                        END IF
        IF(.NOT.FMTEXT) THEN
                        SAVE_KDP(4)=SAVEINPT(4)
        IF(.NOT.COMPOPS) F28=1
        IF(COMPOPS) F31=1
        MSG=.FALSE.
        OPTMES=.FALSE.
                        WC='FMT'
      IF(F31.EQ.1) THEN
                        WQ='NP'
                        SQ=1
                   ELSE
                        WQ='        '
                        SQ=0
                   END IF
                        SN=0
                        SST=0
                        WS=' '
                        DF1=1
                        DF2=1
                        DF3=1
                        DF4=1
                        DF5=1
                        S1=0
                        S2=0
                        S3=0
                        S4=0
                        S5=0
                        STI=0
                        CALL FMT4
                        REST_KDP(4)=RESTINPT(4)
                        END IF
          OLDOP(1:OPCNT,1:20)=OPERND(1:OPCNT,1:20)
                       OPCALC_TYPE=1
                        CALL OPCALC
      IF(.NOT.COMPOPS.AND.F28.EQ.0) RETURN
      IF(COMPOPS.AND.F31.EQ.0) RETURN
                        CALL OPLOAD
      IF(.NOT.COMPOPS.AND.F28.EQ.0) RETURN
      IF(COMPOPS.AND.F31.EQ.0) RETURN
          OPERND(1:OPCNT,1:20)=OLDOP(1:OPCNT,1:20)
C
C     SET THE ORIGINAL P AND XI ARRAY VALUES
                   DO I=1,VBCNT
                   P(I)=VARABL(I,4)
                   DO J=1,VBCNT
C     BTB IS ARRAY XI IN NUM REC
      IF(I.EQ.J) V(I,J)=DINMUL*VARABL(I,8)
      IF(I.NE.J) V(I,J)=0.0D0
                   END DO
                   END DO
      CALL POWELL(V,VN,PCNT,P)
      NUB=VBCNT+1
                   X(1:VBCNT)=P(1:VBCNT)
C     NOW APPLY THE SOLUTION VECTOR X(I) TO THE VARABL ARRAY AND TO THE LENS
C     THE ITH SOLUTION VECTOR COMPONENT APPLIES TO THE ITH VARIABLE
                        LCVLCV=0.0D0
                        DO I=1,VBCNT
C
C     THE CURRENT VARIABLE VALUE BECOMES THE PREVIOUS VARIABLE VALUE
      VARABL(I,5)=VARABL(I,4)
C
C     THE NEW SOLUTION VECTOR ADDED TO THE PREVIOS VARIABLE VALUE
C     BECOMES THE NEW SOLUTION VECTOR
C     VALUE
      LCVLCV=LCVLCV+DABS(((X(I)))/(DINMUL*VARABL(I,8)))
      VARABL(I,4)=VARABL(I,4)+(X(I))
C
      IF(VARABL(I,1).EQ.1.0D0) THEN
      IF(VARABL(I,9).LT.THMINLIM) VARABL(I,9)=THMINLIM
      IF(VARABL(I,10).GT.THMAXLIM) VARABL(I,10)=THMAXLIM
                END IF
      IF(VARABL(I,1).EQ.2.0D0.OR.VARABL(I,1).EQ.10.0D0) THEN
      IF(RDNEGLIM.EQ.0.0D0) RDNEGLIM=-1.0D-20
      IF(RDPOSLIM.EQ.0.0D0) RDPOSLIM=1.0D-20
      IF(VARABL(I,9).LT.(1.0D0/RDNEGLIM)) VARABL(I,9)=1.0D0/RDNEGLIM
      IF(VARABL(I,10).GT.(1.0D0/RDPOSLIM)) VARABL(I,10)=1.0D0/RDPOSLIM
                END IF
C     BOUNDS CHECKER
      IF(VARABL(I,4).LT.VARABL(I,9)) THEN
      VARABL(I,4)=VARABL(I,9)
      WRITE(OUTLYNE,*)
     1'WARNING: '
      CALL SHOWIT(1)
      WRITE(OUTLYNE,*)
     1'VARIABLE # ',I,' HAS REACHED ITS LOWER BOUNDARY VALUE'
      CALL SHOWIT(1)
                        END IF
      IF(VARABL(I,4).GT.VARABL(I,10)) THEN
      VARABL(I,4)=VARABL(I,10)
      WRITE(OUTLYNE,*)
     1'WARNING: '
      CALL SHOWIT(1)
      WRITE(OUTLYNE,*)
     1'VARIABLE # ',I,' HAS REACHED ITS UPPER BOUNDARY VALUE'
      CALL SHOWIT(1)
                        END IF
C
C
C     THE VARIABLE CHANGE IS (THE NEW CURRENT VALUE-OLD LAST CURRENT VALUE)
      VARABL(I,6)=VARABL(I,4)-VARABL(I,5)
C
C     DINCRS ARE ONLY CHANGED BY HAND AND BY THE ITER ADJUST COMMAND
C
                        END DO
            LCVLCV=(LCVLCV)/DBLE(VBCNT)
C
C     NOW APPLY THE CHANGE VECTOR TO THE LENS
C**********************************************************************
                        DO I=1,VBCNT
      IF(I.LE.10) CMPSURF(I)=INT(VARABL(I,3))
C     FIRST, IF THE VARIABLE IS A CONFIG 1 VARIABLE
C     NEXT IF THE VARIABLE IS IN A CONFIG OTHER THAN 1
      IF(VARABL(I,2).EQ.1.0D0) THEN
C     NON-CONFIGS VARIABLE MEANING CONFIG 1
C     THIS IS A LENS LEVEL VARIABLE CHANGE
C     GET THE DATA TYPE NUMBER OF THE VARIABLE
      VTYPE=INT(VARABL(I,1))
C                          CURVATURE
      IF(VTYPE.EQ.2.OR.VTYPE.EQ.1) THEN
C     SURFACE CURVATURE
C     NEW VALUE IS:
      V1=VARABL(I,4)
                      ALENS(1,INT(VARABL(I,3)))=V1
C                       CURVATURE DONE
                        END IF
      IF(VTYPE.EQ.10.OR.VTYPE.EQ.9) THEN
C     SURFACE TORIC CURVATURE
C     NEW VALUE IS:
      V1=VARABL(I,4)
                      ALENS(24,INT(VARABL(I,3)))=V1
C                       TORIC CURVATURE DONE
                        END IF
      IF(VTYPE.GE.3.AND.VTYPE.LE.8) THEN
      IF(VTYPE.EQ.3) ALTYPE=3
      IF(VTYPE.EQ.4) ALTYPE=2
      IF(VTYPE.EQ.5) ALTYPE=4
      IF(VTYPE.EQ.6) ALTYPE=5
      IF(VTYPE.EQ.7) ALTYPE=6
      IF(VTYPE.EQ.8) ALTYPE=7
C     NEW VALUE IS:
      V1=VARABL(I,4)
      ALENS(ALTYPE,INT(VARABL(I,3)))=V1
C                       THESE VARIABLES DONE
                        END IF
      IF(VTYPE.GE.11.AND.VTYPE.LE.25.OR.VTYPE.EQ.75.OR.VTYPE.GE.
     1124.AND.VTYPE.LE.149) THEN
      IF(VTYPE.EQ.11) ALTYPE=41
      IF(VTYPE.EQ.12) ALTYPE=37
      IF(VTYPE.EQ.13) ALTYPE=38
      IF(VTYPE.EQ.14) ALTYPE=39
      IF(VTYPE.EQ.15) ALTYPE=40
      IF(VTYPE.EQ.16) ALTYPE=118
      IF(VTYPE.EQ.17) ALTYPE=119
      IF(VTYPE.EQ.18) ALTYPE=120
      IF(VTYPE.EQ.19) ALTYPE=114
      IF(VTYPE.EQ.20) ALTYPE=115
      IF(VTYPE.EQ.21) ALTYPE=46
      IF(VTYPE.EQ.22) ALTYPE=47
      IF(VTYPE.EQ.23) ALTYPE=48
      IF(VTYPE.EQ.24) ALTYPE=49
      IF(VTYPE.EQ.25) ALTYPE=50
      IF(VTYPE.EQ.75) ALTYPE=43
      IF(VTYPE.EQ.124) ALTYPE=71
      IF(VTYPE.EQ.125) ALTYPE=72
      IF(VTYPE.EQ.126) ALTYPE=73
      IF(VTYPE.EQ.127) ALTYPE=74
      IF(VTYPE.EQ.128) ALTYPE=75
      IF(VTYPE.EQ.129) ALTYPE=81
      IF(VTYPE.EQ.130) ALTYPE=82
      IF(VTYPE.EQ.131) ALTYPE=83
      IF(VTYPE.EQ.132) ALTYPE=84
      IF(VTYPE.EQ.133) ALTYPE=85
      IF(VTYPE.EQ.134) ALTYPE=116
      IF(VTYPE.EQ.135) ALTYPE=86
      IF(VTYPE.EQ.136) ALTYPE=87
      IF(VTYPE.EQ.137) ALTYPE=78
      IF(VTYPE.EQ.138) ALTYPE=79
      IF(VTYPE.EQ.139) ALTYPE=80
      IF(VTYPE.EQ.140) ALTYPE=89
      IF(VTYPE.EQ.141) ALTYPE=11
      IF(VTYPE.EQ.142) ALTYPE=10
      IF(VTYPE.EQ.143) ALTYPE=90
      IF(VTYPE.EQ.144) ALTYPE=91
      IF(VTYPE.EQ.145) ALTYPE=92
      IF(VTYPE.EQ.146) ALTYPE=93
      IF(VTYPE.EQ.147) ALTYPE=94
      IF(VTYPE.EQ.148) ALTYPE=95
      IF(VTYPE.EQ.149) ALTYPE=98
C     NEW VALUE IS:
      V1=VARABL(I,4)
                      ALENS(ALTYPE,INT(VARABL(I,3)))=V1
                        END IF
      IF(VTYPE.EQ.150) THEN
      V1=VARABL(I,4)
      GPREG(INT(VARABL(I,3)))=V1
                   END IF
      IF(VTYPE.GE.250.AND.VTYPE.LE.4218) THEN
      ALTYPE=VTYPE-249
C     NEW VALUE IS:
      V1=VARABL(I,4)
C     RESET THE APPRORIATE ARRAY VALUE IN THE DEFORMABLE SURFACE
      ISURF=INT(VARABL(I,3))
      DEFGR1=ALENS(103,ISURF)
      DEFGR2=ALENS(104,ISURF)
      DEFGR3=ALENS(105,ISURF)
      DEFGR4=ALENS(106,ISURF)
      DEFGR5=ALENS(107,ISURF)
      DEFGR6=0.0D0
      DEFGR7=ALENS(109,ISURF)
      DEFGR8=0.0D0
      ACTNUM=ALTYPE
      NEWDEFVAL=V1
      ERR1=.FALSE.
      ERR2=.FALSE.
      CALL DEFGRIDS(6,ISURF,ERR1,ERR2)
                        END IF
      IF(VTYPE.GE.27.AND.VTYPE.LE.74) THEN
C     SPECIAL SURFACE COEFFICIENTS
C     NEW VALUE IS:
      V1=VARABL(I,4)
      FTFL01((VTYPE-26),INT(VARABL(I,3)))=V1
C                       SPECIAL SURFACE COEFICIENTS DONE
                        END IF
      IF(VTYPE.GE.76.AND.VTYPE.LE.123) THEN
C     SPECIAL SURFACE COEFFICIENTS
C     NEW VALUE IS:
      V1=VARABL(I,4)
      FTFL01((VTYPE-27),INT(VARABL(I,3)))=V1
C                       SPECIAL SURFACE COEFICIENTS DONE
                        END IF
C
                                ELSE
C     CONFIGS VARIABLE
C     VCFG IS THE CONFIG NUMBER
      VCFG=INT(VARABL(I,2))
C     VTYPE IS THE VARIABLE TYPE NUMBER AS USED IN THE VARIABLES ARRAYS
      VTYPE=INT(VARABL(I,1))
C
C     FOR VARIABLE I, APPLY THE SPECIFIED CHANGE TO THE SPECIFIED
C     CONFIG
C
C     THE NEW VARAIBLE VALUE IS JUST
      V1=VARABL(I,4)
C     CONVERT THIS VALUE TO A CHARACTER*23 CHARACTER VARIABLE
                VADD=INT(VARABL(I,14))
      IF(CFADD(VADD,1).EQ.1.AND.V1.NE.0.0D0) V1=1.0D0/V1
      IF(CFADD(VADD,1).EQ.9.AND.V1.NE.0.0D0) V1=1.0D0/V1
                   N1=V1
                CALL AUXNTA
                   AV1=AN1
C
C     THE POSITION IN THE CFADD,CFVAL AND CFCHAR ARRAYS WHERE THIS
C     VARIABLE IS FOUND IS:
C
      IF(CFADD(VADD,1).GE.27.AND.CFADD(VADD,1).LE.74.OR.
     1CFADD(VADD,1).GE.76.AND.CFADD(VADD,1).LE.123
     1.OR.CFADD(VADD,1).EQ.141) THEN
      CFVAL(VADD,2)=V1
      CFCHAR(VADD,2)=AV1
C     NOW UPDATE THE CONFIG ARRAY
      CONFG(CFADD(VADD,3),CFADD(VADD,9))(CFADD(VADD,6):CFADD(VADD,7))
     1=AV1(1:23)
                      ELSE
      CFVAL(VADD,1)=V1
      CFCHAR(VADD,1)=AV1
C     NOW UPDATE THE CONFIG ARRAY
      CONFG(CFADD(VADD,3),CFADD(VADD,9))(CFADD(VADD,4):CFADD(VADD,5))
     1=AV1(1:23)
                      END IF
C     NOW LOOK UP WHERE THIS CHARACTER REPRESENTATION OF THE NEW VALUE
C     SHOULD BE STUFFED INTO THE CONFIG ARRAYS CONFG AND
C     STUFF IT THERE.
C
C     NOW LOOP BACK AND REPEAT FOR THE NEXT VARIABLE.
C     FINISHED WITH A CONFIG VARIABLE
                        END IF
C     LOOP TO NEXT VARIABL
                        END DO
C     UPDATE THE LENS OR THE PERMANENT LENS WILL BE ******!
                        CALL FIXDEFORMFILE
                        F6=1
                        F1=0
                        F22=0
                       IF(.NOT.COMPOPS)LNSTYP=2
                       IF(COMPOPS)LNSTYP=3
                       CALL LNSEOS
C**********************************************************************
C     AND RE-EVALUATE THE OPERANDS AND DISPLAY
C     THE NEW FIGURE OF MERIT, THE OLD FIGURE OF MERIT  AND ITS CHANGE
                        SAVE_KDP(4)=SAVEINPT(4)
        IF(.NOT.COMPOPS) F28=1
        IF(COMPOPS) F31=1
        MSG=.FALSE.
        OPTMES=.FALSE.
                        WC='FMT'
      IF(F31.EQ.1) THEN
                        WQ='NP'
                        SQ=1
                   ELSE
                        WQ='        '
                        SQ=0
                   END IF
                        SN=0
                        SST=0
                        WS=' '
                        DF1=1
                        DF2=1
                        DF3=1
                        DF4=1
                        DF5=1
                        S1=0
                        S2=0
                        S3=0
                        S4=0
                        S5=0
                        STI=0
                        CALL FMT2
                        REST_KDP(4)=RESTINPT(4)
      DEALLOCATE(V,P,STAT=ALLOERR)
                        RETURN
      END
