        SUBROUTINE OPTIMIZE(MESSAGE)
!        USE WINTERACTER
        IMPLICIT NONE
        REAL*8 DW1,DW2
        INTEGER ISET,JSET
        CHARACTER OUTPUT*10,MESSAGE*20
        INCLUDE 'DATLEN.INC'
        INCLUDE 'DATMAC.INC'
        INCLUDE 'DATMAI.INC'
        INCLUDE 'DATSUB.INC'
        INCLUDE 'RESOURCE.INC'
 !       TYPE(WIN_MESSAGE)   :: MESSAGE
C*****************************************************************************************
C*****************************************************************************************
C
C       THIS CODE TAKES CARE OF THE OPERATION OF THE OPTIMIZE GUI
C
C       OPTIMIZE
C
C
 !       CALL WDIALOGSELECT(IDD_OPTIM)
 !       CALL WDIALOGFIELDSTATE(PFAC,1)
 !       CALL WDIALOGFIELDSTATE(CY,1)
 !       CALL WDIALOGFIELDSTATE(CF,1)
C
        SELECT CASE(OUTPUT)
C
        CASE('MEIRON')
 !       CALL WDIALOGFIELDSTATE(CY,1)
 !       CALL WDIALOGFIELDSTATE(CF,1)
 !       CALL WDIALOGFIELDSTATE(PFAC,1)
 !       CALL WDIALOGGETDOUBLE(PFAC,DW1)
        WRITE(OUTLYNE,*) 'PFAC RESET TO: ',DW1
        CALL SHOWIT(1)
        PFAC=DW1
 !       CALL WDIALOGPUTDOUBLE(PFAC,DW1)
 !       CALL WDialogShow(-1,-1,0,Modeless)
C
        CASE('PFIND')
C       BOOK KEEPING
 !       CALL WDIALOGGETCHECKBOX(VERB,JSET)
        IF(JSET.EQ.0) THEN
 !       CALL WDIALOGPUTCHECKBOX(VERB,0)
                INPUT='OVERBOSE NO'
                CALL PROCES
                ELSE
 !       CALL WDIALOGPUTCHECKBOX(VERB,1)
                INPUT='OVERBOSE YES'
                CALL PROCES
                END IF
C
 !       CALL WDIALOGGETINTEGER(CY,ISET)
 !       CALL WDIALOGGETDOUBLE(CF,DW1)
        WRITE(INPUT,*) 'PFIND,',ISET,',',DW1
        CALL PROCES
 !       CALL WDIALOGPUTDOUBLE(PFAC,PFAC)
C
        CASE('REST1')
C       BOOK KEEPING
 !       CALL WDIALOGGETCHECKBOX(VERB,JSET)
        IF(JSET.EQ.0) THEN
 !       CALL WDIALOGPUTCHECKBOX(VERB,0)
                INPUT='OVERBOSE NO'
                CALL PROCES
                ELSE
 !       CALL WDIALOGPUTCHECKBOX(VERB,1)
                INPUT='OVERBOSE YES'
                CALL PROCES
                END IF
        INPUT='RESTORE'
        CALL PROCES
C
        CASE('REST2')
C       BOOK KEEPING
 !       CALL WDIALOGGETCHECKBOX(VERB,JSET)
        IF(JSET.EQ.0) THEN
 !       CALL WDIALOGPUTCHECKBOX(VERB,0)
                INPUT='OVERBOSE NO'
                CALL PROCES
                ELSE
 !       CALL WDIALOGPUTCHECKBOX(VERB,1)
                INPUT='OVERBOSE YES'
                CALL PROCES
                END IF
        INPUT='RESTORE MIN'
        CALL PROCES
C
        CASE('REST3')
C       BOOK KEEPING
 !       CALL WDIALOGGETCHECKBOX(VERB,JSET)
        IF(JSET.EQ.0) THEN
 !       CALL WDIALOGPUTCHECKBOX(VERB,0)
                INPUT='OVERBOSE NO'
                CALL PROCES
                ELSE
 !       CALL WDIALOGPUTCHECKBOX(VERB,1)
                INPUT='OVERBOSE YES'
                CALL PROCES
                END IF
        INPUT='RESTORE ORIG'
        CALL PROCES
C
        CASE('ITER')
C       BOOK KEEPING
 !       CALL WDIALOGGETCHECKBOX(VERB,JSET)
        IF(JSET.EQ.0) THEN
 !       CALL WDIALOGPUTCHECKBOX(VERB,0)
                INPUT='OVERBOSE NO'
                CALL PROCES
                ELSE
 !       CALL WDIALOGPUTCHECKBOX(VERB,1)
                INPUT='OVERBOSE YES'
                CALL PROCES
                END IF
 !       CALL WDIALOGGETINTEGER(NITER,ISET)
        WRITE(INPUT,*) 'ITER,',ISET
        CALL PROCES
C
        CASE('ITERFULL')
C       BOOK KEEPING
 !       CALL WDIALOGGETCHECKBOX(VERB,JSET)
        IF(JSET.EQ.0) THEN
 !       CALL WDIALOGPUTCHECKBOX(VERB,0)
                INPUT='OVERBOSE NO'
                CALL PROCES
                ELSE
 !       CALL WDIALOGPUTCHECKBOX(VERB,1)
                INPUT='OVERBOSE YES'
                CALL PROCES
                END IF
 !       CALL WDIALOGGETINTEGER(NITERFULL,ISET)
        WRITE(INPUT,*) 'ITER FULL,',ISET
        CALL PROCES
C
        CASE('ITERP')
C       BOOK KEEPING
 !       CALL WDIALOGGETCHECKBOX(VERB,JSET)
        IF(JSET.EQ.0) THEN
 !       CALL WDIALOGPUTCHECKBOX(VERB,0)
                INPUT='OVERBOSE NO'
                CALL PROCES
                ELSE
 !       CALL WDIALOGPUTCHECKBOX(VERB,1)
                INPUT='OVERBOSE YES'
                CALL PROCES
                END IF
 !       CALL WDIALOGGETINTEGER(NITERP,ISET)
        WRITE(INPUT,*) 'IT P,',ISET
        CALL PROCES
C
        CASE('ROBB')
C       BOOK KEEPING
 !       CALL WDIALOGGETCHECKBOX(VERB,JSET)
        IF(JSET.EQ.0) THEN
 !       CALL WDIALOGPUTCHECKBOX(VERB,0)
                INPUT='OVERBOSE NO'
                CALL PROCES
                ELSE
 !       CALL WDIALOGPUTCHECKBOX(VERB,1)
                INPUT='OVERBOSE YES'
                CALL PROCES
                END IF
 !       CALL WDIALOGGETDOUBLE(BETA,DW1)
 !       CALL WDIALOGGETDOUBLE(DELTA,DW2)
 !       CALL WDIALOGGETINTEGER(NROBB,ISET)
        WRITE(INPUT,*) 'ROBB,',DW1,',',DW2,',',ISET
        CALL PROCES
C
        CASE('IDCANCEL')
 !       CALL WDialogHide()
 !       CALL WDialogUnload()
        END SELECT
                        RETURN
                        END
