#! /usr/local/tk3.2/bin/wish -f
# Currently, this does not work correctly with 3.0; the behavior of the
# message window has changed.
#!/usr/local/tk3.0/bin/wish -f
#
# This script uses tcl/tk to provide an x-windows interface for setting up
# parameters.  We should take the options
#   svtb [ program [ directory ] ]
#
set auto_path "/home/gropp/tools.n/solvers/svtb"
source svmeth
source svaccel
source svcomple
source svdialog
source svfields
source svfile
source svfilter
source svgraph
source svhelp
source svmsg
source svquery
proc nop {} { }
#source svrun
wm title . "Solver Setup"
frame .menu -relief raised -borderwidth 1

frame .graph -geometry 500x500 -relief raised -bg white -borderwidth 2

frame .msgtty -geometry 600x200 -relief raised -borderwidth 2
message .msgtty.msg -font *-fixed-Medium-R-Normal-*-120-* -text {} -aspect 300
pack append .msgtty .msgtty.msg {top fill}

pack append . .msgtty { bottom fillx pady 4} 
#pack append . .graph { top left frame n padx 2} \
#	      .menu { top right frame n padx 2} 

#
# default values
set itm "gmres"
set svm "ilu"

set itoptnames {}
set itoptvalues {}
set itoptvars  {}
set maxit 101
set tol   1.0e-5
set gmresrestart 20

set svoptnames  {}
set svoptvalues {}
set svoptvars   {}
set nd    "4"
set fill  "0"
set rfill "0"
set omega "1.0"
set order "nd"
set use2d "No"
set svinner "ilu"
set itinner "preonly"

set resmethod ""

set probsize 3

proc runexample {} {
    global svm itm maxit nd tol svinner itinner order fill resmethod probsize \
	   use2d
    if {[string compare $svm "lu" ] == 0} {
	msgtty .output [ exec example3 -n $probsize -svmethod $svm -ordering $order ]
	} else {
    # this could be smarter about not issuing ignored values
    set specialargs {}
    if {[string compare $svm "osm" ] == 0 || \
	[string compare $svm "bdd" ] == 0} {
	set specialargs "-svinner $svinner -itinner $itinner -nd $nd"
	if {[string compare $use2d "Yes"] == 0} { 
	    set specialargs "$specialargs -2d"
	    }
	}
    set grfid [ winfo id .graph ]

    msgtty .output [ exec example3 -n $probsize -sv $svm -itmethod $itm -maxit $maxit -tol $tol $specialargs -ilufill $fill $resmethod -winid $grfid ]
    }
}


#
# Put up a message in the message window
proc msgtty {w text} {
    .msgtty.msg configure -text "$text"
    }

#Iterative options menu
proc itopts2 {} {
    global svm itoptnames itoptvalues itoptvars tol maxit
    if {[ string compare $svm "lu" ] == 0} {
	msgtext .menu.itoptions.message \
	        "No iterative options for LU factorization"
        } \
    else {
	set names "Tolerance: {Max Iterations:} $itoptnames"
	set values "{$tol} {$maxit} $itoptvalues"
	set vars   "tol maxit $itoptvars" 
	dialog .itoptions $names $values $vars
	}
}

proc svopts2 {} {
    global svm svoptnames svoptvalues svoptvars
    set names "$svoptnames"
    set values "$svoptvalues"
    set vars   "$svoptvars" 
    dialog .itoptions "Method Options" $names $values $vars
}

proc setsize {} {
     global probsize
     dialog .szoptions "Problem size" {Mesh size:} $probsize probsize
     }

# Generate the solvers menu
solvers_menu .menu.solvers

# Generate the iterative methods menu
accel_menu .menu.itmethod

button .menu.itoptions -relief flat -text "Iterative options" -command itopts2
button .menu.svoptions -relief flat -text "Solver options" -command svopts2

menubutton .menu.residual -text "Residual Display" -menu .menu.residual.m
menu .menu.residual.m
.menu.residual.m add radio -label "None"        -command {set resmethod ""} \
	-variable rmeth -value none
.menu.residual.m add radio -label "Print Norm"  \
	-command "set resmethod -dpres" -variable rmeth -value prnt
.menu.residual.m add radio -label "Graph Norm" -command "set resmethod -dres" \
	-variable rmeth -value grph
.menu.residual.m add radio -label "Graph Residual" \
	-command "set resmethod -dresv" -variable rmeth -value gres
.menu.residual.m invoke 0
# gmres

# Create the command bar
frame .commandbar -relief raised -borderwidth 1
AddFile    .commandbar.file
AddQuery   .commandbar.query
AddFilters .commandbar.filters
AddGraph   .commandbar.graph
AddHelp    .commandbar.help

pack append .commandbar .commandbar.file { left } .commandbar.query { left } \
            .commandbar.filters { left } .commandbar.graph { left } \
            .commandbar.help {left fillx}

pack append . .commandbar {top fillx}
pack append . .graph { top left frame n padx 2} \

# A toolbar with common operations could also be defined (like compare two
# methods)
