#!/usr/bin/env wish
#!/bin/env wish
# $Id: petscopts,v 1.18 1998/04/24 20:16:56 balay Exp $ 
#
#  You may have to set the correct location of wish on your machine
# in the first line of this file.
#
# Tcl/Tk continualy changes. We try to keep PETScOpts up to date, but that
# would be a full time job. We hope that PETScOpts will work with an
# wish version larger then 3.6. If you have trouble with it, please send
# email to petsc-maint@mcs.anl.gov with the Tcl/Tk version numbers and the
# exact code that is causing the problem.
#
set petsc_dir $env(PETSC_DIR)
wm title . "PETSc Options"

set np 1
set execfile ""

#
# tk version 4 has incompatible commands for 
# checkbutton (-selectcolor instead of -selector)
# scrollbar   (-command needs to be different)
# canvas config (-xscrollcommand instead of -xscroll, and command is 
#                different)
# scale         (-activebackground instead of -activeforeground!)
# tk_listboxSingleSelect var(list) replaced with
#   var(list) config -selectmode single.  
# See /home/MPI/mpich/profiling/upshot/bin/upshot.in for an example of
# code that can run with either version of tk

# program options
set message(run) "Runs the currently specified executable file"
set message(np) "Sets the number of processors"
set message(execfile) "The current executable file"
set message(select_program) "Select an executable file"

# general options
set message(help) "Displays all options available"
set message(version) "Cause PETSc to display version number."
set message(on_error_attach_debugger) "Attach debugger when error is encountered"
set message(start_in_debugger) "Start in debugger during execution"
set message(on_error_abort) "Useful when the program is started in a debugger"
set message(debugger_type) "Selects a specific debugger"
set message(display) "Sets the display"
set message(no_signal_handler) "No signal handler"
set message(fp_trap) "Stop on floating point exceptions"
set message(trdump) "Enagle memory tracing; dump list of unfreed memory at conclusion of the run"
set message(trmalloc) "Enable memory tracing"
set message(trinfo) "Prints the total memory used by the program"
set message(trdebug) "Does extended checking for memory corruption"
set message(optionstable) "List options passed to program"
set message(optionsleft) "List options unused by program"
set message(log) "Log creation & destruction with performance info only"
set message(log_all) "Log all events"
set message(log_summary) "Log performance info only"
set message(logfile) "Specify the log file"
set message(info) "Prints useful information from key functions as they are executed"
set message(log_history) "Prints the history of the execution (residuals etc)"
set message(log_mpe)  "Enable mpe loging, which can be viewable by upshot/nupshot"
set message(mpelogfile) "Log file name for mpe profiling"

# preconditioner options
set message(pc_type) "Selects a specific preconditioner"
set message(pc_sor_omega) "Set the relaxation factor"
set message(pc_sor_its) "Set the number of iterations"
set message(pc_sor) "Set the direction"
set message(pc_lu_in_place) "Do the factorization in place"
set message(pc_lu_ordering) "Specify the matrix ordering"
set message(pc_ilu_ordering) "Specify the matrix ordering"
set message(pc_ilu_levels) "Specify the levels of fill"
set message(pc_ilu_in_place) "Replaces the original matrix with Factored matrix"
set message(pc_ilu_factorpointwise) "Do not use Block Factorization (for MPIROWBS only)"
set message(pc_bjacobi_blocks) "Set the number of blocks"
set message(pc_bjacobi_truelocal) "Use the local matrix for both solve and PC"
set message(pc_bs_max_it) "Set the number of iterations"
set message(pc_bs_blocksize) "Set the blocksize"
set message(pc_bs_rtol) "Specify the relative tolerance"
set message(pc_bs) "Select the type of preconditioning"

# ksp options
set message(ksp_type) "Select the Krylov Subspace type"
set message(ksp_max_it) "Specify the maximum number of iterations"
set message(ksp_rtol) "Set the relative tolerance"
set message(ksp_atol) "Set the absolute tolerance"
set message(ksp_divtol) "Specify the divergence tolerance"
set message(ksp_preres) "Use preconditioned residual for convergence test"
set message(ksp_right_pc) "Use right preconditioning"
set message(ksp_eigen) "Calculate the eigenvalues at each iteration"
set message(ksp_monitor) "Monitor convergence (text)"
set message(ksp_xmonitor_switch) "Monitor convergence (X-window)"
set message(ksp_xmonitor_x) "Sets the x-coordinate of the X-window"
set message(ksp_xmonitor_y) "Sets the y-coordinate of the X-windows"
set message(ksp_xmonitor_w) "Sets the width of the X-window"
set message(ksp_xmonitor_h) "Sets the height of the X-window"
set message(ksp_gmres_restart) "Set the restart value"
set message(ksp_gmres_unmodifiedgrammschmidt) "Use unmodified Gramm-Schmidt algorithim during orthogonalization"

# sub preconditioner options
set message(sub_pc_type) "Selects the type of preconditioning to be done on the blocks"
set message(sub_pc_sor_omega) "Specify the relaxation factor"
set message(sub_pc_sor_its) "Set the number of iterations"
set message(sub_pc_sor) "Specify the direction"
set message(sub_pc_lu_in_place) "Do the factorization in place"
set message(sub_pc_lu_ordering) "Specify the matrix ordering"
set message(sub_pc_ilu_ordering) "Specify the matrix ordering"
set message(sub_pc_ilu_levels) "Set the levels of fill"
set message(sub_pc_ilu_in_place) "Replaces the original matrix with Factored matrix"
set message(sub_pc_ilu_factorpointwise) "Do not use Block Factorization (for MPIROWBS only)"
set message(sub_pc_bs_max_it) "Specify the maximum iterations"
set message(sub_pc_bs_blocksize) "Set the blocksize"
set message(sub_pc_bs_rtol) "Specify the relative tolerance"
set message(sub_pc_bs) "Select the type of preconditioning"

# sub ksp options
set message(sub_ksp_type) "Specify the Krylov subspace type to be used on each block"
set message(sub_ksp_max_it) "Sets the maximum number of iterations"
set message(sub_ksp_rtol) "Sets the relative tolerance"
set message(sub_ksp_atol) "Sets the absolute tolerance"
set message(sub_ksp_divtol) "Specify the divergence tolerance"
set message(sub_ksp_preres) "Use preconditioned residual for convergence test"
set message(sub_ksp_right_pc) "Use right preconditioning"
set message(sub_ksp_eigen) "Calculate eigenvalues at each iteration"
set message(sub_ksp_monitor) "Monitor convergence (text)"
set message(sub_ksp_xmonitor_switch) "Monitor convergenc (X-window)"
set message(sub_ksp_xmonitor_x) "Sets the x-coordinate of the X-window"
set message(sub_ksp_xmonitor_y) "Sets the y-coordinate of the X-window"
set message(sub_ksp_xmonitor_w) "Sets the width of the X-window"
set message(sub_ksp_xmonitor_h) "Sets the height of the X-window"
set message(sub_ksp_gmres_restart) "Sets the GMRES restart value"
set message(sub_ksp_gmres_unmodifiedgrammschmidt) "Use unmodified Gramm-Schmidt algorithm during orthogonlization"

# sles options
set message(sles_view) "View the SLES package data structure"

# snes options 
set message(snes_view) "View the SNES package data structures"
set message(snes_type) "Select the nonlinear solution type"
set message(snes_max_it) "Specify the maximum number of iterations"
set message(snes_max_funcs) "Specify the maximum number of function evaluations"
set message(snes_stol) "Set the step tolerance"
set message(snes_atol) "Set the absolute tolerance"
set message(snes_rtol) "Set the relative tolerance"
set message(snes_ttol) "Set the truncation tolerance"
set message(snes_monitor) "Monitor convergence (text)"
set message(snes_xmonitor_switch) "Monitor convergence (X-window)"
set message(snes_xmonitor_x) "Set the x-coordinate of the X-window"
set message(snes_xmonitor_y) "Set the y-coordinate of the X-window"
set message(snes_xmonitor_w) "Set the width of the X-window"
set message(snes_xmonitor_h) "Set the height of the X-window"
set message(snes_fd) "Use finite differences"
set message(snes_mf) "Use matrix free variants"
set message(snes_line_search) "Select the line search type"
set message(snes_line_search_alpha) "Specify alpha?"
set message(snes_line_search_maxstep) "Specify the maximum stepsize"
set message(snes_line_search_steptol) "Set the step tolerance"

# graphics options
set message(pause) "Sets delay in between events"
set message(nox) "Forces no X-windows to be opened"

frame .mbar -relief raised -bd 2
frame .progopts -relief raised -bd 2
frame .genopts -bd 2 -relief groove 
frame .graphopts -bd 2 -relief groove 
frame .pcopts -bd 2 -relief groove 
frame .kspopts -bd 2 -relief groove 
frame .snesopts -bd 2 -relief groove 
frame .slesopts -bd 2 -relief groove 
frame .help -bd 2 -relief raised 

pack .mbar .progopts .genopts .graphopts .pcopts .kspopts .slesopts \
	.snesopts .help -fill both

menubutton .mbar.file -text File -menu .mbar.file.menu -relief raised
button .mbar.about -text "About PETScOpts" -command PV_Introduction
pack .mbar.file .mbar.about -side left

menu .mbar.file.menu
.mbar.file.menu add command -label "Jobs..." -command {Jobs}
.mbar.file.menu add separator
.mbar.file.menu add command -label "Open" -command {Select_Open_File}
.mbar.file.menu add separator
.mbar.file.menu add command -label "Save" -command \
	{Write_PETSc_Options $filename}
.mbar.file.menu add command -label "Save as..." -command {Select_Save_File}
.mbar.file.menu add separator
.mbar.file.menu add command -label "Revert to Defaults" -command \
	{PETSc_Defaults}
.mbar.file.menu add separator
.mbar.file.menu add command -label "Exit" -command {Exit}

set helpm ""
message .help.help -width 600 -textvariable helpm
pack .help.help -side left -anchor w


#
#  Buttons for program
#
proc Jobs {} {
	global job total_jobs current_job

	set total_jobs 0
	set tmp_job(execfile) ""  
	set tmp_job(options) ""
	set tmp_job(np) 1
	set tmp_job(xterm) 0
	set tmp_job(file) 0
	set tmp_job(filename) ""
	set current_job 0

	toplevel .jobs
	wm title .jobs "Jobs"
	
	frame .jobs.top
	frame .jobs.mid
	frame .jobs.bot
	pack .jobs.top .jobs.mid .jobs.bot -side top -fill both

	frame .jobs.top.id
	frame .jobs.top.exec
	frame .jobs.top.opts
	frame .jobs.top.left
	frame .jobs.top.output
	pack .jobs.top.id .jobs.top.exec .jobs.top.opts -side top -fill x \
		-expand 1 -padx 1m
	pack .jobs.top.left .jobs.top.output -side left -fill both -expand 1 \
		-padx 1m -pady 1m

	label .jobs.top.exec.lbl -text "Executable:"
	entry .jobs.top.exec.entry -relief sunken -width 50 -textvariable \
		tmp_job(execfile)
	pack .jobs.top.exec.lbl -side left
	pack .jobs.top.exec.entry -side right

	label .jobs.top.opts.lbl -text "Options     :"
	entry .jobs.top.opts.entry -relief sunken -width 50 -textvariable \
		tmp_job(options)
	pack .jobs.top.opts.lbl -side left
	pack .jobs.top.opts.entry -side right

	frame .jobs.top.left.proc
	label .jobs.top.left.proc.lbl -text "Processors:"
	entry .jobs.top.left.proc.entry -relief sunken -width 5 -textvariable \
		tmp_job(np)
	pack .jobs.top.left.proc.lbl -side left
	pack .jobs.top.left.proc.entry -side right
	button .jobs.top.left.submit -text "Submit Job" -command {Edit_Job $current_job ; Exec_Job $current_job}
	pack .jobs.top.left.proc -side top -fill x
	pack .jobs.top.left.submit -side top -anchor w

	label .jobs.top.output.lbl -text "Stdout/Stderr Options:"
	checkbutton .jobs.top.output.xterm -text "Output to Display" -variable \
		tmp_job(xterm) -relief flat
	checkbutton .jobs.top.output.file -text "Output to File" -variable \
		tmp_job(file) -relief flat
	frame .jobs.top.output.filename 
	label .jobs.top.output.filename.lbl -text "Filename:"
	entry .jobs.top.output.filename.entry -relief sunken -width 20 \
		-textvariable tmp_job(filename)
	pack .jobs.top.output.filename.lbl -side left
	pack .jobs.top.output.filename.entry -side right
	pack .jobs.top.output.lbl .jobs.top.output.xterm .jobs.top.output.file \
		-side top -anchor w
	pack .jobs.top.output.filename -side bottom -fill x

	scrollbar .jobs.mid.scrollv -command ".jobs.mid.jobs yview"
	scrollbar .jobs.mid.scrollh -command ".jobs.mid.jobs xview" -orient \
		horizontal
	listbox .jobs.mid.jobs -geometry 66x10  -relief sunken \
		-yscrollcommand ".jobs.mid.scrollv set" \
		-xscrollcommand ".jobs.mid.scrollh set"
	pack .jobs.mid.scrollh -side bottom -fill x
	pack .jobs.mid.scrollv .jobs.mid.jobs -side left -fill y

	bind .jobs.mid.jobs <Button-1> {
		%W select from [%W nearest %y]
		set current_job [lindex [%W get [%W nearest %y]] 0]
		Display_Info $current_job
	}
	bind .jobs.mid.jobs <Double-ButtonPress-1> {
		%W select from [%W nearest %y]
		set current_job [lindex [%W get [%W nearest %y]] 0]
		Display_Info $current_job
		Exec_Job $current_job
	}

	button .jobs.bot.add -text "Add" -command {Insert_Job [expr $total_jobs+1]}
	button .jobs.bot.ins -text "Insert" -command {Insert_Job $current_job}
	button .jobs.bot.rem -text "Remove" -command {Remove_Job $current_job}
	button .jobs.bot.edt -text "Edit" -command {Edit_Job $current_job}
	button .jobs.bot.clr -text "Clear" -command {Clear}
	button .jobs.bot.jobs -text "Submit All" -command {Run_All}
	button .jobs.bot.exit -text "Exit" -command {Exit_Jobs}

	pack .jobs.bot.add .jobs.bot.ins .jobs.bot.rem .jobs.bot.edt .jobs.bot.clr\
		.jobs.bot.jobs .jobs.bot.exit -side left -padx 2m -pady 2m -ipadx 2m \
		-ipady 2m -fill x -expand 1
}
proc Exit_Jobs {} {
	global total_jobs current_job

	set total_jobs 0
	set current_job 0
	destroy .jobs
}
proc Display_Info {id} {
	global job tmp_job
	
	set tmp_job(execfile) $job($id,execfile) 
	set tmp_job(options) $job($id,options)
	set tmp_job(np) $job($id,np)
	set tmp_job(xterm) $job($id,xterm)
	set tmp_job(file) $job($id,file)
	set tmp_job(filename) $job($id,filename)
}
proc Clear {} {
	global tmp_job
	
	set tmp_job(np) ""
	set tmp_job(execfile) ""
	set tmp_job(options) ""
	set tmp_job(xterm) 0
	set tmp_job(file) 0
	set tmp_job(filename) ""
}
proc Compose_Job {id} {
	global job

	if {$job($id,np) < 1} {set job($id,np) 1}

	if {$job($id,xterm) == 1} {
		if {($job($id,file) == 1) && ([string compare "" $job($id,filename)])} {
			set cmd "xterm -T $job($id,execfile) -e csh -c \"mpirun -np $job($id,np) $job($id,execfile) $job($id,options) >& $job($id,filename) \; sleep 3600\""
		} else {
			set cmd "xterm -T $job($id,execfile) -e csh -c \"mpirun -np $job($id,np) $job($id,execfile) $job($id,options) \; sleep 3600\""
		}
	} else {
		if {($job($id,file) == 1) && ([string compare "" $job($id,filename)])} {
			set cmd "mpirun -np $job($id,np) $job($id,execfile) $job($id,options) >& $job($id,filename)"
		} else {
			set cmd "mpirun -np $job($id,np) $job($id,execfile) $job($id,options) >& /dev/null"
		}
	}
	return $cmd
}
proc Insert_Job {id} {
	global total_jobs job tmp_job current_job

	if {$id == 0} {set id 1}
	if {![string compare "" $tmp_job(execfile)]} {return}

	for {set i $total_jobs} {$i >= $id} {incr i -1} {
		set job([expr $i+1],execfile) $job($i,execfile)
		set job([expr $i+1],options) $job($i,options)
		set job([expr $i+1],np) $job($i,np)
		set job([expr $i+1],xterm) $job($i,xterm)
		set job([expr $i+1],file) $job($i,file)
		set job([expr $i+1],filename) $job($i,filename)
	}	
	set job($id,execfile) $tmp_job(execfile)
	set job($id,options) $tmp_job(options)
	set job($id,np) $tmp_job(np)
	set job($id,xterm) $tmp_job(xterm)
	set job($id,file) $tmp_job(file)
	set job($id,filename) $tmp_job(filename)
	incr total_jobs
	for {set i $id} {$i <= $total_jobs} {incr i} {
		.jobs.mid.jobs delete [expr $i-1]
		.jobs.mid.jobs insert [expr $i-1] "$i . [Compose_Job $i]"
	}
	set current_job 0
}
proc Remove_Job {id} {
	global job total_jobs current_job

	if {$current_job <= 0} {return}

	for {set i $id} {$i < $total_jobs} {incr i} {
		set job($i,execfile) $job([expr $i+1],execfile)
		set job($i,options) $job([expr $i+1],options)
		set job($i,np) $job([expr $i+1],np)
		set job($i,xterm) $job([expr $i+1],xterm)
		set job($i,file) $job([expr $i+1],file)
		set job($i,filename) $job([expr $i+1],filename)
	}
	for {set i $id} {$i < $total_jobs} {incr i} {
		.jobs.mid.jobs delete $i
		.jobs.mid.jobs insert $i "$i . [Compose_Job $i]"
	}
	.jobs.mid.jobs delete [expr $id-1]
	incr total_jobs -1
	Clear
	set current_job 0
}
proc Edit_Job {id} {
	global job tmp_job
	
	if {![string compare $tmp_job(execfile) ""]} {return}

	set job($id,execfile) $tmp_job(execfile)
	set job($id,options) $tmp_job(options)
	set job($id,np) $tmp_job(np)
	set job($id,xterm) $tmp_job(xterm)
	set job($id,file) $tmp_job(file)
	set job($id,filename) $tmp_job(filename)

	.jobs.mid.jobs delete [expr $id-1]
	.jobs.mid.jobs insert [expr $id-1] "$id . [Compose_Job $id]"
}

proc Exec_Job {id} {
	global filename

	if {$id == 0} {return}
	set command [lrange [.jobs.mid.jobs get [expr $id-1]] 2 end]
	Write_PETSc_Options $filename
	eval "exec $command &"
}
proc Run_All {} {
	global total_jobs
	
	if {$total_jobs <= 0} {return}

	for {set i 1} {$i <= $total_jobs} {incr i} {
		Exec_Job $i
	}
}

#
#  Buttons for general Petsc options
#
proc Display_General_Options {} {
	frame .genopts.1 -bd 4
	frame .genopts.2 -bd 4
	frame .genopts.3 -bd 4

	checkbutton .genopts.1.help -text "Get help" -variable help -relief flat
	bind .genopts.1.help <Any-Enter> {set helpm $message(help)}
	bind .genopts.1.help <Any-Leave> {set helpm ""}
#	bind .genopts.1.help <Button-1> {.genopts.1.help invoke}
	
	checkbutton .genopts.1.vers -text "Show version" -variable version \
		-relief flat
	bind .genopts.1.vers <Any-Enter> {set helpm $message(version)}
	bind .genopts.1.vers <Any-Leave> {set helpm ""}
#	bind .genopts.1.vers <Button-1> {.genopts.1.vers invoke}

	checkbutton .genopts.1.nsh -text "Don't trap error signals" -variable \
		no_signal_handler -relief flat
	bind .genopts.1.nsh <Any-Enter> {set helpm $message(no_signal_handler)}
	bind .genopts.1.nsh <Any-Leave> {set helpm ""}
#	bind .genopts.1.nsh <Button-1> {.genopts.1.nsh invoke}

	checkbutton .genopts.1.fpt -text "Enable floating pt. trap" -variable \
		fp_trap -relief flat
	bind .genopts.1.fpt <Any-Enter> {set helpm $message(fp_trap)}
	bind .genopts.1.fpt <Any-Leave> {set helpm ""}
#	bind .genopts.1.fpt <Button-1> {.genopts.1.fpt invoke}

	checkbutton .genopts.1.trd -text "Dump unfreed memory" -variable \
		trdump -relief flat
	bind .genopts.1.trd <Any-Enter> {set helpm $message(trdump)}
	bind .genopts.1.trd <Any-Leave> {set helpm ""}
#	bind .genopts.1.trd <Button-1> {.genopts.1.trd invoke}

	checkbutton .genopts.1.trm -text "Enable memory tracing" -variable \
		trmalloc -relief flat
	bind .genopts.1.trm <Any-Enter> {set helpm $message(trmalloc)}
	bind .genopts.1.trm <Any-Leave> {set helpm ""}
#	bind .genopts.1.trm <Button-1> {.genopts.1.trm invoke}

	checkbutton .genopts.1.trinf -text "Display memory used" -variable \
		trinfo -relief flat
	bind .genopts.1.trinf <Any-Enter> {set helpm $message(trinfo)}
	bind .genopts.1.trinf <Any-Leave> {set helpm ""}
#	bind .genopts.1.trinf <Button-1> {.genopts.1.trinf invoke}

	checkbutton .genopts.1.trdb -text "Enable memory debugging" -variable \
		trdebug -relief flat
	bind .genopts.1.trdb <Any-Enter> {set helpm $message(trdebug)}
	bind .genopts.1.trdb <Any-Leave> {set helpm ""}
#	bind .genopts.1.trdb <Button-1> {.genopts.1.trdb invoke}

	pack .genopts.1.help .genopts.1.vers .genopts.1.nsh .genopts.1.fpt \
		.genopts.1.trd .genopts.1.trm .genopts.1.trinf \
                .genopts.1.trdb -side top -anchor w


	checkbutton .genopts.2.opttbl -text "Dump inputted options" -variable \
		optionstable -relief flat
	bind .genopts.2.opttbl <Any-Enter> {set helpm $message(optionstable)}
	bind .genopts.2.opttbl <Any-Leave> {set helpm ""}
#	bind .genopts.2.opttbl <Button-1> {.genopts.2.opttbl invoke}

	checkbutton .genopts.2.optlft -text "Dump unused options" -variable \
		optionsleft -relief flat
	bind .genopts.2.optlft <Any-Enter> {set helpm $message(optionsleft)}
	bind .genopts.2.optlft <Any-Leave> {set helpm ""}
#	bind .genopts.2.optlft <Button-1> {.genopts.2.optlft invoke}

	label .genopts.2.lbl -text "Debugger Options:"

	checkbutton .genopts.2.debuggerattach -text "Attach debugger on error" \
		-variable on_error_attach_debugger -relief flat -command \
		{set start_in_debugger 0}
	bind .genopts.2.debuggerattach <Any-Enter> {set helpm \
		$message(on_error_attach_debugger)}
	bind .genopts.2.debuggerattach <Any-Leave> {set helpm ""}
#	bind .genopts.2.debuggerattach <Button-1> {.genopts.2.debuggerattach invoke}

	checkbutton .genopts.2.debuggerstart -text "Start in debugger" -variable \
		start_in_debugger -relief flat -command {set on_error_attach_debugger 0}
	bind .genopts.2.debuggerstart <Any-Enter> {set helpm \
		$message(start_in_debugger)}
	bind .genopts.2.debuggerstart <Any-Leave> {set helpm ""}
#	bind .genopts.2.debuggerstart <Button-1> {.genopts.2.debuggerstart invoke}
	
	checkbutton .genopts.2.errorabort -text "Abort on Error" -variable \
                on_error_abort -relief flat 
	bind .genopts.2.errorabort <Any-Enter> {set helpm \
		$message(on_error_abort)}
	bind .genopts.2.errorabort <Any-Leave> {set helpm ""}
#	bind .genopts.2.errorabort <Button-1> {.genopts.2.errorabort invoke}

	frame .genopts.2.debugger -bd 2
	bind .genopts.2.debugger <Any-Enter> {set helpm $message(debugger_type)}
	bind .genopts.2.debugger <Any-Leave> {set helpm ""}
	label .genopts.2.debugger.lbl -text "Debugger:" 
	menubutton .genopts.2.debugger.type -textvariable debugger_type \
		-menu .genopts.2.debugger.type.menu -fg red -relief raised
	menu .genopts.2.debugger.type.menu
	.genopts.2.debugger.type.menu add radiobutton -label "xxgdb" \
		-variable debugger_type -value xxgdb
	.genopts.2.debugger.type.menu add radiobutton -label "gdb" \
		-variable debugger_type -value gdb
	.genopts.2.debugger.type.menu add radiobutton -label "dbx" \
		-variable debugger_type -value dbx
	.genopts.2.debugger.type.menu add radiobutton -label "gdb,noxterm" \
		-variable debugger_type -value "gdb,noxterm"
	.genopts.2.debugger.type.menu add radiobutton -label "dbx,noxterm" \
		-variable debugger_type -value "dbx,noxterm"
	.genopts.2.debugger.type.menu add radiobutton -label "ups (sun4)" \
		-variable debugger_type -value "ups"
	.genopts.2.debugger.type.menu add radiobutton -label "xldb (rs6k)" \
		-variable debugger_type -value "xldb"

	pack .genopts.2.debugger.lbl -side left
	pack .genopts.2.debugger.type -side right
	
	
	frame .genopts.2.display
	label .genopts.2.display.lbl -text "Display:"
	entry .genopts.2.display.dsply -textvariable display -relief sunken \
		-width 20
	bind .genopts.2.display.dsply <Any-Enter> {set helpm $message(display)}
	bind .genopts.2.display.dsply <Any-Leave> {set helpm ""}
	pack .genopts.2.display.lbl -side left
	pack .genopts.2.display.dsply -side right

	pack .genopts.2.opttbl .genopts.2.optlft .genopts.2.lbl \
		.genopts.2.debuggerattach .genopts.2.debuggerstart\
                .genopts.2.errorabort -side top -anchor w
	pack .genopts.2.debugger -side top -fill x
	pack .genopts.2.display -side top -fill x


	label .genopts.3.lbl -text "Profiling Options:"

	checkbutton .genopts.3.inf -text "Performance info of key functions" \
                -variable info -relief flat
	bind .genopts.3.inf <Any-Enter> {set helpm $message(info)}
	bind .genopts.3.inf <Any-Leave> {set helpm ""}
#	bind .genopts.3.inf <Button-1> {.genopts.3.inf invoke}

	checkbutton .genopts.3.loghis -text "Log history to file" -variable \
		log_history -relief flat
	bind .genopts.3.loghis <Any-Enter> {set helpm $message(log_history)}
	bind .genopts.3.loghis <Any-Leave> {set helpm ""}
#	bind .genopts.3.loghis <Button-1> {.genopts.3.loghis invoke}

	checkbutton .genopts.3.logsum -text "Output summary to screen" -variable \
		log_summary -relief flat
	bind .genopts.3.logsum <Any-Enter> {set helpm $message(log_summary)}
	bind .genopts.3.logsum <Any-Leave> {set helpm ""}
#	bind .genopts.3.logsum <Button-1> {.genopts.3.logsum invoke}

	checkbutton .genopts.3.log -text "Log creation/dest. only" -variable log \
		-relief flat -command {set log_all 0}
	bind .genopts.3.log <Any-Enter> {set helpm $message(log)}
	bind .genopts.3.log <Any-Leave> {set helpm ""}
#	bind .genopts.3.log <Button-1> {.genopts.3.log invoke}

	checkbutton .genopts.3.logall -text "Log all events" -variable log_all \
		-relief flat -command {set log 0}
	bind .genopts.3.logall <Any-Enter> {set helpm $message(log_all)}
	bind .genopts.3.logall <Any-Leave> {set helpm ""}
#	bind .genopts.3.logall <Button-1> {.genopts.3.logall invoke}

	frame .genopts.3.logfile
	label .genopts.3.logfile.lbl -text "Log file:"
	entry .genopts.3.logfile.entry -textvariable logfile -relief sunken \
		-width 20
	bind .genopts.3.logfile.entry <Any-Enter> {set helpm $message(logfile)}
	bind .genopts.3.logfile.entry <Any-Leave> {set helpm ""}
	pack .genopts.3.logfile.lbl -side left
	pack .genopts.3.logfile.entry -side right

	frame .genopts.3.mpe
	checkbutton .genopts.3.mpe.mplog -text "MPE loging" -variable \
		log_mpe -relief flat
	bind .genopts.3.mpe.mplog <Any-Enter> {set helpm $message(log_mpe)}
	bind .genopts.3.mpe.mplog <Any-Leave> {set helpm ""}
#	bind .genopts.3.mpe.mplog <Button-1> {.genopts.3.mpe.mplog invoke}
	entry .genopts.3.mpe.entry -textvariable mpelogfile -relief sunken \
		-width 20
	bind .genopts.3.mpe.entry <Any-Enter> {set helpm $message(mpelogfile)}
	bind .genopts.3.mpe.entry <Any-Leave> {set helpm ""}
	pack .genopts.3.mpe.mplog -side left 
        pack .genopts.3.mpe.entry -side right

        pack .genopts.3.lbl .genopts.3.inf .genopts.3.loghis .genopts.3.logsum\
                .genopts.3.log .genopts.3.logall -side top -anchor w
        pack .genopts.3.logfile  -side top -fill x
	pack .genopts.3.mpe -side top -fill x
	
	pack .genopts.1 .genopts.2 .genopts.3 -side left -fill both -expand 1
}

#
# PC Options  
#
proc Display_PC_BJacobi_Options {w} {

	frame $w.pcopts.1 -bd 4
	frame $w.pcopts.2 -bd 4

	frame $w.pcopts.1.pc
	bind $w.pcopts.1.pc <Any-Enter> {set sub_helpm $message(sub_pc_type)}
	bind $w.pcopts.1.pc <Any-Leave> {set sub_helpm ""}
	label $w.pcopts.1.pc.lbl -text "Preconditioner:"
	menubutton $w.pcopts.1.pc.pc -textvariable sub_pc_type -menu \
		$w.pcopts.1.pc.pc.menu -fg red -relief raised
	menu $w.pcopts.1.pc.pc.menu
	$w.pcopts.1.pc.pc.menu add radiobutton -label "Default" -variable\
		 sub_pc_type -value "Default" -command \
		"Display_PC_BJacobi_Specific_Options $w.pcopts.2.specopts"
	$w.pcopts.1.pc.pc.menu add radiobutton -label "Jacobi" -variable \
		sub_pc_type -value Jacobi -command \
		"Display_PC_BJacobi_Specific_Options $w.pcopts.2.specopts"
	$w.pcopts.1.pc.pc.menu add radiobutton -label "SOR" -variable \
		sub_pc_type -value SOR -command \
		"Display_PC_BJacobi_Specific_Options $w.pcopts.2.specopts"
	$w.pcopts.1.pc.pc.menu add radiobutton -label "LU" -variable sub_pc_type \
		-value LU \
		-command "Display_PC_BJacobi_Specific_Options $w.pcopts.2.specopts"
	$w.pcopts.1.pc.pc.menu add radiobutton -label "ILU" -variable \
		sub_pc_type -value "ILU" -command \
		"Display_PC_BJacobi_Specific_Options $w.pcopts.2.specopts"
	$w.pcopts.1.pc.pc.menu add radiobutton -label "ICC" -variable \
		sub_pc_type -value ICC -command \
		"Display_PC_BJacobi_Specific_Options $w.pcopts.2.specopts"
	$w.pcopts.1.pc.pc.menu add radiobutton -label "Shell" -variable \
		sub_pc_type -value Shell -command \
		"Display_PC_BJacobi_Specific_Options $w.pcopts.2.specopts"
	$w.pcopts.1.pc.pc.menu add radiobutton -label "None" -variable \
		sub_pc_type -value "None" -command \
		"Display_PC_BJacobi_Specific_Options $w.pcopts.2.specopts"

	pack $w.pcopts.1.pc.lbl -side left
	pack $w.pcopts.1.pc.pc -side right
	label $w.pcopts.1.1 -text " "
	label $w.pcopts.1.2 -text " "
	label $w.pcopts.1.3 -text " "
	label $w.pcopts.1.4 -text " "

	pack $w.pcopts.1.pc $w.pcopts.1.1 $w.pcopts.1.2 $w.pcopts.1.3 \
		$w.pcopts.1.4 -side top -fill x

	label $w.pcopts.2.lbl -text \
		"         Specific Preconditioner Options:         "
	pack $w.pcopts.2.lbl -side top -fill x

	frame $w.pcopts.2.specopts

	pack $w.pcopts.1 -side left -fill both
	pack $w.pcopts.2 -side right -fill both
	Display_PC_BJacobi_Specific_Options $w.pcopts.2.specopts
}
proc Display_PC_Options {} {

	frame .pcopts.1 -bd 4
	frame .pcopts.2 -bd 4

	frame .pcopts.1.pc
	bind .pcopts.1.pc <Any-Enter> {set helpm $message(pc_type)}
	bind .pcopts.1.pc <Any-Leave> {set helpm ""}

	label .pcopts.1.pc.lbl -text "Preconditioner:"
	menubutton .pcopts.1.pc.pc -textvariable pc_type -menu \
		.pcopts.1.pc.pc.menu -fg red -relief raised
	menu .pcopts.1.pc.pc.menu
	.pcopts.1.pc.pc.menu add radiobutton -label "Default" -variable pc_type\
		-value "Default" -command \
		"Display_PC_Specific_Options .pcopts.2.specopts"
	.pcopts.1.pc.pc.menu add radiobutton -label "Jacobi" -variable pc_type \
		-value Jacobi -command \
	"Display_PC_Specific_Options .pcopts.2.specopts"
	.pcopts.1.pc.pc.menu add radiobutton -label "SOR" -variable pc_type \
		-value SOR -command \
		"Display_PC_Specific_Options .pcopts.2.specopts"
	.pcopts.1.pc.pc.menu add radiobutton -label "Block Jacobi" -variable \
		pc_type -value "Block Jacobi" \
		-command "Display_PC_Specific_Options .pcopts.2.specopts"
	.pcopts.1.pc.pc.menu add radiobutton -label "LU" -variable pc_type \
		-value LU \
		-command "Display_PC_Specific_Options .pcopts.2.specopts"
	.pcopts.1.pc.pc.menu add radiobutton -label "ILU" -variable pc_type \
		-value "ILU" -command \
		"Display_PC_Specific_Options .pcopts.2.specopts"
	.pcopts.1.pc.pc.menu add radiobutton -label "ICC" -variable pc_type \
		-value ICC -command \
		"Display_PC_Specific_Options .pcopts.2.specopts"
	.pcopts.1.pc.pc.menu add radiobutton -label "BGS" -variable pc_type \
		-value "BGS" -command \
                "Display_PC_Specific_Options .pcopts.2.specopts"
	.pcopts.1.pc.pc.menu add radiobutton -label "ASM" -variable pc_type \
		-value ASM -command \
                "Display_PC_Specific_Options .pcopts.2.specopts"
	.pcopts.1.pc.pc.menu add radiobutton -label "Shell" -variable pc_type \
		-value Shell -command \
		"Display_PC_Specific_Options .pcopts.2.specopts"
	.pcopts.1.pc.pc.menu add radiobutton -label "None" -variable pc_type \
		-value "None" -command \
		"Display_PC_Specific_Options .pcopts.2.specopts"

	pack .pcopts.1.pc.lbl -side left
	pack .pcopts.1.pc.pc -side right
	label .pcopts.1.1 -text " "
	label .pcopts.1.2 -text " "
	label .pcopts.1.3 -text " "
	label .pcopts.1.4 -text " "

	pack .pcopts.1.pc .pcopts.1.1 .pcopts.1.2 .pcopts.1.3 \
		.pcopts.1.4 -side top -fill x

	label .pcopts.2.lbl -text \
		"         Specific Preconditioner Options:         "
	pack .pcopts.2.lbl -side top -fill x

	frame .pcopts.2.specopts

	pack .pcopts.1 -side left -fill both
	pack .pcopts.2 -side right -fill both
}

proc Display_PC_BJacobi_Specific_Options {w} {
	 global sub_pc_type

	 destroy $w
	 frame $w
	 pack $w -fill both -expand 1
	 
	 if {[string compare "SOR" $sub_pc_type] == 0} {
		  frame $w.omega
		  label $w.omega.lbl -text "Relaxation factor:"
		  entry $w.omega.entry -textvariable sub_pc_sor_omega \
					 -width 10 -relief sunken
		  bind $w.omega.entry <Any-Enter> {set sub_helpm \
		     $message(sub_pc_sor_omega)}
		  bind $w.omega.entry <Any-Leave> {set sub_helpm ""}
		  pack $w.omega.lbl -side left
		  pack $w.omega.entry -side right
		  
		  frame $w.maxits
		  label $w.maxits.lbl -text "Max. iterations:"
		  entry $w.maxits.entry -textvariable sub_pc_sor_its \
					 -width 10 -relief sunken
		  bind $w.maxits.entry <Any-Enter> {set sub_helpm \
		     $message(sub_pc_sor_its)}
		  bind $w.maxits.entry <Any-Leave> {set sub_helpm ""}
		  pack $w.maxits.lbl -side left
		  pack $w.maxits.entry -side right
		  
		  frame $w.dir
		  bind $w.dir <Any-Enter> {set sub_helpm $message(sub_pc_sor)}
		  bind $w.dir <Any-Leave> {set sub_helpm ""}
		  label $w.dir.lbl -text "Direction:"
		  menubutton $w.dir.entry -textvariable sub_pc_sor -menu  \
                          $w.dir.entry.menu -fg red -relief raised 
		  menu $w.dir.entry.menu

		  $w.dir.entry.menu add radiobutton -label "Default" -variable \
					 sub_pc_sor -value Default
		  $w.dir.entry.menu add radiobutton -label "Backward" -variable \
					 sub_pc_sor -value Backward
		  $w.dir.entry.menu add radiobutton -label "Symmetric" -variable \
					 sub_pc_sor -value Symmetric
		  $w.dir.entry.menu add radiobutton -label "Local Forward" -variable \
					 sub_pc_sor -value "Local forward"
		  $w.dir.entry.menu add radiobutton -label "Local backward" -variable \
					 sub_pc_sor -value "Local Backward"
		  $w.dir.entry.menu add radiobutton -label "Local Symmetric" -variable \
					 sub_pc_sor -value "Local Symmetric"
		  pack $w.dir.lbl -side left
		  pack $w.dir.entry -side right
		  
		  pack $w.omega $w.maxits $w.dir -side top -fill x
	 } elseif {[string compare "LU" $sub_pc_type] == 0} {
		  checkbutton $w.ip -text "Do in-place Factorization" -variable \
					 sub_pc_lu_in_place -relief flat
		  bind $w.ip <Any-Enter> {set sub_helpm $message(sub_pc_lu_in_place)}
		  bind $w.ip <Any-Leave> {set sub_helpm ""}
#		  bind $w.ip <Button-1> "$w.ip invoke"
		  
		  frame $w.ord
		  bind $w.ord <Any-Enter> {set sub_helpm $message(sub_pc_lu_ordering)}
		  bind $w.ord <Any-Leave> {set sub_helpm ""}
		  label $w.ord.lbl -text "Matrix Orderings:"
		  menubutton $w.ord.ord -textvariable sub_pc_lu_ordering -menu \
					 $w.ord.ord.menu -fg red -relief raised
		  menu $w.ord.ord.menu
		  $w.ord.ord.menu add radiobutton -label "Default" -variable \
					 sub_pc_lu_ordering -value Default
		  $w.ord.ord.menu add radiobutton -label "Natural" -variable \
					 sub_pc_lu_ordering -value Natural
		  $w.ord.ord.menu add radiobutton -label "Nested Dissection" -variable \
					 sub_pc_lu_ordering -value "Nested Dissection"
		  $w.ord.ord.menu add radiobutton -label "One-way Dissection" -variable \
					 sub_pc_lu_ordering -value "One-way Dissection"
		  $w.ord.ord.menu add radiobutton -label "Reverse Cuthill-McGee" \
					 -variable sub_pc_lu_ordering -value "Reverse Cuthill-McGee"
		  $w.ord.ord.menu add radiobutton -label "Quotient Minimum Degree" \
					 -variable sub_pc_lu_ordering -value "Quotient Minimum Degree"
		  pack $w.ord.lbl -side left
		  pack $w.ord.ord -side right 

		  pack $w.ip -side top -anchor w
		  pack $w.ord -side top -fill x 
	} elseif {[string compare "ILU" $sub_pc_type] == 0} {
		  frame $w.levels
		  label $w.levels.lbl -text "Levels of fill:"
		  entry $w.levels.entry -textvariable sub_pc_ilu_levels \
					 -width 10 -relief sunken
		  bind $w.levels.entry <Any-Enter> {set sub_helpm \
		     $message(sub_pc_ilu_levels)}
		  bind $w.levels.entry <Any-Leave> {set sub_helpm ""}

                  checkbutton  $w.inplace -text "Factor in Place" -variable \
                          sub_pc_ilu_in_place  -relief flat
                  bind $w.inplace <Any-Enter> {set helpm $message(sub_pc_ilu_in_place)}
                  bind $w.inplace <Any-Leave> {set helpm ""}
#                  bind $w.inplace <Button-1> "$w.inplace invoke"
	
                  checkbutton $w.fpw -text "Factor Pointwise" -variable \
                          sub_pc_ilu_factorpointwise  -relief flat
                  bind $w.fpw <Any-Enter> {set helpm \
                          $message(sub_pc_ilu_factorpointwise)}
                  bind $w.fpw <Any-Leave> {set helpm ""}
#                  bind $w.fpw <Button-1> "$w.fpw invoke"
	
		  pack $w.inplace  $w.fpw
		  pack $w.levels.lbl -side left
		  pack $w.levels.entry -side right


		  frame $w.ord
		  bind $w.ord <Any-Enter> {set sub_helpm $message(sub_pc_ilu_ordering)}
		  bind $w.ord <Any-Leave> {set sub_helpm ""}
		  label $w.ord.lbl -text "Matrix Orderings:"
		  menubutton $w.ord.ord -textvariable sub_pc_ilu_ordering -menu \
					 $w.ord.ord.menu -fg red -relief raised
		  menu $w.ord.ord.menu
		  $w.ord.ord.menu add radiobutton -label "Default" -variable \
					 sub_pc_ilu_ordering -value Default
		  $w.ord.ord.menu add radiobutton -label "Natural" -variable \
					 sub_pc_ilu_ordering -value Natural
		  $w.ord.ord.menu add radiobutton -label "Nested Dissection" -variable \
					 sub_pc_ilu_ordering -value "Nested Dissection"
		  $w.ord.ord.menu add radiobutton -label "One-way Dissection" -variable \
					 sub_pc_ilu_ordering -value "One-way Dissection"
		  $w.ord.ord.menu add radiobutton -label "Reverse Cuthill-McGee" \
					 -variable sub_pc_ilu_ordering -value "Reverse Cuthill-McGee"
		  $w.ord.ord.menu add radiobutton -label "Quotient Minimum Degree" \
					 -variable sub_pc_ilu_ordering -value "Quotient Minimum Degree"
		  pack $w.ord.lbl -side left
		  pack $w.ord.ord -side right 

		  pack $w.levels -side top -fill x
		  pack $w.ord -side top -fill x 
	} elseif {[string compare "ICC" $sub_pc_type] == 0} {
		  frame $w.maxits
		  label $w.maxits.lbl -text "Maximum iterations:"
		  entry $w.maxits.entry -textvariable sub_pc_bs_max_it \
					 -width 10 -relief sunken
		  bind $w.maxits.entry <Any-Enter> {set sub_helpm \
		     $message(sub_pc_bs_max_it)}
		  bind $w.maxits.entry <Any-Leave> {set sub_helpm ""}
		  pack $w.maxits.lbl -side left
		  pack $w.maxits.entry -side right

		  frame $w.bs
		  label $w.bs.lbl -text "Blocksize:"
		  entry $w.bs.entry -textvariable sub_pc_bs_blocksize \
					 -width 10 -relief sunken
		  bind $w.bs.entry <Any-Enter> {set sub_helpm \
		     $message(sub_pc_bs_blocksize)}
		  bind $w.bs.entry <Any-Leave> {set sub_helpm ""}
		  pack $w.bs.lbl -side left
		  pack $w.bs.entry -side right

		  frame $w.rtol
		  label $w.rtol.lbl -text "Relative tolerance:"
		  entry $w.rtol.entry -textvariable sub_pc_bs_rtol \
					 -width 10 -relief sunken
		  bind $w.rtol.entry <Any-Enter> {set sub_helpm $message(sub_pc_bs_rtol)}
		  bind $w.rtol.entry <Any-Leave> {set sub_helpm ""}
		  pack $w.rtol.lbl -side left
		  pack $w.rtol.entry -side right	 
		  
		  frame $w.preopt
		  bind $w.preopt <Any-Enter> {set sub_helpm $message(sub_pc_bs)}
		  bind $w.preopt <Any-Leave> {set sub_helpm ""}
		  label $w.preopt.lbl -text "Preconditioner options:"
		  menubutton $w.preopt.preopt -textvariable sub_pc_bs -menu \
					 $w.preopt.preopt.menu -fg red -relief raised
		  menu $w.preopt.preopt.menu
		  $w.preopt.preopt.menu add radiobutton -label "None" -variable \
					 sub_pc_bs -value None
		  $w.preopt.preopt.menu add radiobutton -label "SSOR" -variable \
					 sub_pc_bs -value SSOR
		  $w.preopt.preopt.menu add radiobutton -label "Block Jacobi" -variable \
					 sub_pc_bs -value "Block Jacobi"
		  $w.preopt.preopt.menu add radiobutton -label "Diagonal" -variable \
					 sub_pc_bs -value "Diagonal"
		  pack $w.preopt.lbl -side left
		  pack $w.preopt.preopt -side right

		  pack $w.maxits $w.bs $w.rtol $w.preopt -side top -fill x
	}

}
proc Display_PC_Specific_Options {w} {
	 global pc_type

	 destroy $w
	 frame $w
	 pack $w -fill both -expand 1
	 
	 if {[string compare "SOR" $pc_type] == 0} {
		  frame $w.omega
		  label $w.omega.lbl -text "Relaxation factor:"
		  entry $w.omega.entry -textvariable pc_sor_omega \
					 -width 10 -relief sunken
		  bind $w.omega.entry <Any-Enter> {set helpm $message(pc_sor_omega)}
		  bind $w.omega.entry <Any-Leave> {set helpm ""}
		  pack $w.omega.lbl -side left
		  pack $w.omega.entry -side right
		  
		  frame $w.maxits
		  label $w.maxits.lbl -text "Max. iterations:"
		  entry $w.maxits.entry -textvariable pc_sor_its \
					 -width 10 -relief sunken
		  bind $w.maxits.entry <Any-Enter> {set helpm $message(pc_sor_its)}
		  bind $w.maxits.entry <Any-Leave> {set helpm ""}
		  pack $w.maxits.lbl -side left
		  pack $w.maxits.entry -side right
		  
		  frame $w.dir
		  bind $w.dir <Any-Enter> {set helpm $message(pc_sor)}
		  bind $w.dir <Any-Leave> {set helpm ""}
		  label $w.dir.lbl -text "Direction:"
		  menubutton $w.dir.entry -textvariable pc_sor -menu \
					 $w.dir.entry.menu -fg red -relief raised
		  menu $w.dir.entry.menu
		  $w.dir.entry.menu add radiobutton -label "Default" -variable \
					 pc_sor -value Default
		  $w.dir.entry.menu add radiobutton -label "Backward" -variable \
					 pc_sor -value Backward
		  $w.dir.entry.menu add radiobutton -label "Symmetric" -variable \
					 pc_sor -value Symmetric
		  $w.dir.entry.menu add radiobutton -label "Local Forward" -variable \
					 pc_sor -value "Local forward"
		  $w.dir.entry.menu add radiobutton -label "Local backward" -variable \
					 pc_sor -value "Local Backward"
		  $w.dir.entry.menu add radiobutton -label "Local Symmetric" -variable \
					 pc_sor -value "Local Symmetric"
		  pack $w.dir.lbl -side left
		  pack $w.dir.entry -side right
		  
		  pack $w.omega $w.maxits $w.dir -side top -fill x
	 } elseif {[string compare "LU" $pc_type] == 0} {
		  checkbutton $w.ip -text "Do in-place Factorization" -variable \
					 pc_lu_in_place -relief flat
		  bind $w.ip <Any-Enter> {set helpm $message(pc_lu_in_place)}
		  bind $w.ip <Any-Leave> {set helpm ""}
#		  bind $w.ip <Button-1> "$w.ip invoke"

		  frame $w.ord
		  bind $w.ord <Any-Enter> {set helpm $message(pc_lu_ordering)}
		  bind $w.ord <Any-Leave> {set help ""}
		  label $w.ord.lbl -text "Matrix Orderings:"
		  menubutton $w.ord.ord -textvariable pc_lu_ordering -menu \
					 $w.ord.ord.menu -fg red -relief raised
		  menu $w.ord.ord.menu
		  $w.ord.ord.menu add radiobutton -label "Default" -variable \
					 pc_lu_ordering -value Default
		  $w.ord.ord.menu add radiobutton -label "Natural" -variable \
					 pc_lu_ordering -value Natural
		  $w.ord.ord.menu add radiobutton -label "Nested Dissection" -variable \
					 pc_lu_ordering -value "Nested Dissection"
		  $w.ord.ord.menu add radiobutton -label "One-way Dissection" -variable \
					 pc_lu_ordering -value "One-way Dissection"
		  $w.ord.ord.menu add radiobutton -label "Reverse Cuthill-McGee" \
					 -variable pc_lu_ordering -value "Reverse Cuthill-McGee"
		  $w.ord.ord.menu add radiobutton -label "Quotient Minimum Degree" \
					 -variable pc_lu_ordering -value "Quotient Minimum Degree"
		  pack $w.ord.lbl -side left
		  pack $w.ord.ord -side right 

		  pack $w.ip -side top -anchor w
		  pack $w.ord -side top -fill x 
		} elseif {[string compare "ILU" $pc_type] == 0} {
		  frame $w.levels
		 
		  label $w.levels.lbl -text "Levels of fill:"
		  entry $w.levels.entry -textvariable pc_ilu_levels \
					 -width 10 -relief sunken
		  bind $w.levels.entry <Any-Enter> {set helpm $message(pc_ilu_levels)}
		  bind $w.levels.entry <Any-Leave> {set helpm ""}

		  pack $w.levels.lbl -side left
		  pack $w.levels.entry -side right
                  checkbutton  $w.inplace -text "Factor in Place" -variable \
                          pc_ilu_in_place  -relief flat
                  bind $w.inplace <Any-Enter> {set helpm $message(pc_ilu_in_place)}
                  bind $w.inplace <Any-Leave> {set helpm ""}
#                  bind $w.inplace <Button-1> "$w.inplace invoke"
	
                  checkbutton $w.fpw -text "Factor Pointwise" -variable \
                          pc_ilu_factorpointwise  -relief flat
                  bind $w.fpw <Any-Enter> {set helpm \
                          $message(pc_ilu_factorpointwise)}
                  bind $w.fpw <Any-Leave> {set helpm ""}
#                  bind $w.fpw <Button-1> "$w.fpw invoke"
	
		  pack $w.inplace  $w.fpw
	

		  frame $w.ord
		  bind $w.ord <Any-Enter> {set helpm $message(pc_ilu_ordering)}
		  bind $w.ord <Any-Leave> {set helpm ""}
		  label $w.ord.lbl -text "Matrix Orderings:"
		  menubutton $w.ord.ord -textvariable pc_ilu_ordering -menu \
					 $w.ord.ord.menu -fg red -relief raised
		  menu $w.ord.ord.menu
		  $w.ord.ord.menu add radiobutton -label "Default" -variable \
					 pc_ilu_ordering -value Default
		  $w.ord.ord.menu add radiobutton -label "Natural" -variable \
					 pc_ilu_ordering -value Natural
		  $w.ord.ord.menu add radiobutton -label "Nested Dissection" -variable \
					 pc_ilu_ordering -value "Nested Dissection"
		  $w.ord.ord.menu add radiobutton -label "One-way Dissection" -variable \
					 pc_ilu_ordering -value "One-way Dissection"
		  $w.ord.ord.menu add radiobutton -label "Reverse Cuthill-McGee" \
					 -variable pc_ilu_ordering -value "Reverse Cuthill-McGee"
		  $w.ord.ord.menu add radiobutton -label "Quotient Minimum Degree" \
					 -variable pc_ilu_ordering -value "Quotient Minimum Degree"
		  pack $w.ord.lbl -side left
		  pack $w.ord.ord -side right 

		  pack $w.levels -side top -fill x
		  pack $w.ord -side top -fill x 
	 } elseif {[string compare "Block Jacobi" $pc_type] == 0} {
		  toplevel $w.bj
		  wm title $w.bj "Block Jacobi Options"

		  frame $w.bj.blocks -bd 2
		  label $w.bj.blocks.lbl -text "Number of blocks:"
		  entry $w.bj.blocks.entry -textvariable pc_bjacobi_blocks \
					 -width 10 -relief sunken
		  bind $w.bj.blocks.entry <Any-Enter> {set sub_helpm \
		     $message(pc_bjacobi_blocks)}
		  bind $w.bj.blocks.entry <Any-Leave> {set sub_helpm ""}

                  checkbutton $w.bj.truelocal -text "Use Local Matrix" -variable \
                          pc_bjacobi_truelocal -relief flat
		  bind $w.bj.truelocal <Any-Enter> {set sub_helpm \
		     $message(pc_bjacobi_truelocal)}
		  bind $w.bj.truelocal <Any-Leave> {set sub_helpm ""}
#                  bind $w.bj.truelocal <Button-1> "$w.bj.truelocal invoke"

		  pack $w.bj.blocks.lbl $w.bj.blocks.entry -side left
		  pack $w.bj.blocks -side top -anchor w
                  pack $w.bj.truelocal -side top -anchor w

		  frame $w.bj.help
		  label $w.bj.help.help -textvariable sub_helpm
		  pack $w.bj.help.help -side left -anchor w
		  pack $w.bj.help -side bottom -fill x

		  frame $w.bj.pcopts -bd 2 -relief groove
		  frame $w.bj.kspopts -bd 2 -relief groove
		  
		  Display_PC_BJacobi_Options $w.bj
		  Display_KSP_BJacobi_Options $w.bj

		  pack $w.bj.blocks $w.bj.pcopts $w.bj.kspopts -side top -fill both
	  } elseif {[string compare "ICC" $pc_type] == 0} {
		  frame $w.maxits
		  label $w.maxits.lbl -text "Maximum iterations:"
		  entry $w.maxits.entry -textvariable pc_bs_max_it \
					 -width 10 -relief sunken
		  bind $w.maxits.entry <Any-Enter> {set helpm $message(pc_bs_max_it)}
		  bind $w.maxits.entry <Any-Leave> {set helpm ""}
		  pack $w.maxits.lbl -side left
		  pack $w.maxits.entry -side right

		  frame $w.bs
		  label $w.bs.lbl -text "Blocksize:"
		  entry $w.bs.entry -textvariable pc_bs_blocksize \
					 -width 10 -relief sunken
		  bind $w.bs.entry <Any-Enter> {set helpm $message(pc_bs_blocksize)}
		  bind $w.bs.entry <Any-Leave> {set helpm ""}
		  pack $w.bs.lbl -side left
		  pack $w.bs.entry -side right

		  frame $w.rtol
		  label $w.rtol.lbl -text "Relative tolerance:"
		  entry $w.rtol.entry -textvariable pc_bs_rtol \
					 -width 10 -relief sunken
		  bind $w.rtol.entry <Any-Enter> {set helpm $message(pc_bs_rtol)}
		  bind $w.rtol.entry <Any-Leave> {set helpm ""}
		  pack $w.rtol.lbl -side left
		  pack $w.rtol.entry -side right	 
		  
		  frame $w.preopt
		  bind $w.preopt <Any-Enter> {set helpm $message(pc_bs)}
		  bind $w.preopt <Any-Leave> {set helpm ""}
		  label $w.preopt.lbl -text "Preconditioner options:"
		  menubutton $w.preopt.preopt -textvariable pc_bs -menu \
					 $w.preopt.preopt.menu -fg red -relief raised
		  menu $w.preopt.preopt.menu
		  $w.preopt.preopt.menu add radiobutton -label "None" -variable \
					 pc_bs -value None
		  $w.preopt.preopt.menu add radiobutton -label "SSOR" -variable \
					 pc_bs -value SSOR
		  $w.preopt.preopt.menu add radiobutton -label "Block Jacobi" -variable \
					 pc_bs -value "Block Jacobi"
		  $w.preopt.preopt.menu add radiobutton -label "Diagonal" -variable \
					 pc_bs -value "Diagonal"
		  pack $w.preopt.lbl -side left
		  pack $w.preopt.preopt -side right

		  pack $w.maxits $w.bs $w.rtol $w.preopt -side top -fill x

              } elseif {[string compare "BGS" $pc_type] == 0} {

                  
              } elseif {[string compare "ASM" $pc_type] == 0} {
         }

}


#
# KSP Options
#
proc Display_KSP_BJacobi_Options {w} {
	$w.kspopts configure -relief groove

	frame $w.kspopts.1 -bd 4
	frame $w.kspopts.2 -bd 4
	frame $w.kspopts.3 -bd 4

	frame $w.kspopts.1.1
	bind $w.kspopts.1.1 <Any-Enter> {set sub_helpm $message(sub_ksp_type)}
	bind $w.kspopts.1.1 <Any-Leave> {set sub_helpm ""}
	label $w.kspopts.1.1.label -text "KSP Type:"
	menubutton $w.kspopts.1.1.type -textvariable sub_ksp_type \
		-menu $w.kspopts.1.1.type.menu -fg red -relief raised
	menu $w.kspopts.1.1.type.menu 
	$w.kspopts.1.1.type.menu add radiobutton -label "Default" -variable \
		sub_ksp_type -value Default -command \
		"Display_KSP_BJacobi_Specific_Options $w.kspopts.3.specopts" 
	$w.kspopts.1.1.type.menu add radiobutton -label "Richardson" -variable \
		sub_ksp_type -value Richardson -command \
		"Display_KSP_BJacobi_Specific_Options $w.kspopts.3.specopts"
	$w.kspopts.1.1.type.menu add radiobutton -label "Chebychev" -variable \
		sub_ksp_type -value Chebychev -command \
		"Display_KSP_BJacobi_Specific_Options $w.kspopts.3.specopts"
	$w.kspopts.1.1.type.menu add radiobutton -label "CG" \
		-variable  sub_ksp_type -value "CG" -command \
		"Display_KSP_BJacobi_Specific_Options $w.kspopts.3.specopts"
	$w.kspopts.1.1.type.menu add radiobutton -label "GMRES" -variable \
		sub_ksp_type -value GMRES -command \
		"Display_KSP_BJacobi_Specific_Options $w.kspopts.3.specopts"
	$w.kspopts.1.1.type.menu add radiobutton -label "Bi-CG-stab" -variable \
		sub_ksp_type -value "Bi-CG-stab" -command \
		"Display_KSP_BJacobi_Specific_Options $w.kspopts.3.specopts"
	$w.kspopts.1.1.type.menu add radiobutton -label "TFQMR" -variable \
		sub_ksp_type -value TFQMR -command \
		"Display_KSP_BJacobi_Specific_Options $w.kspopts.3.specopts"
	$w.kspopts.1.1.type.menu add radiobutton -label "TCQMR" -variable \
		sub_ksp_type -value TCQMR -command \
		"Display_KSP_BJacobi_Specific_Options $w.kspopts.3.specopts"
	$w.kspopts.1.1.type.menu add radiobutton -label "CGS" -variable \
	 	sub_ksp_type -value CGS -command \
		"Display_KSP_BJacobi_Specific_Options $w.kspopts.3.specopts"
	$w.kspopts.1.1.type.menu add radiobutton -label "CR" -variable \
		sub_ksp_type -value CR -command \
		"Display_KSP_BJacobi_Specific_Options $w.kspopts.3.specopts"
	$w.kspopts.1.1.type.menu add radiobutton -label "Least Squares" -variable\
		sub_ksp_type -value "Least Squares" -command \
		"Display_KSP_BJacobi_Specific_Options $w.kspopts.3.specopts"
	$w.kspopts.1.1.type.menu add radiobutton -label "Precond. Only" -variable\
		sub_ksp_type -value "Precond. Only" -command \
		"Display_KSP_BJacobi_Specific_Options $w.kspopts.3.specopts"
	pack $w.kspopts.1.1.label -side left
	pack $w.kspopts.1.1.type -side right 

	frame $w.kspopts.1.2
	label $w.kspopts.1.2.label -text "Max. Iterations:          "
	entry $w.kspopts.1.2.maxits -relief sunken -textvariable sub_ksp_max_it \
		-width 10
	bind $w.kspopts.1.2.maxits <Any-Enter> {set sub_helpm \
		$message(sub_ksp_max_it)}
	bind $w.kspopts.1.2.maxits <Any-Leave> {set sub_helpm ""}

	pack $w.kspopts.1.2.label -side left
	pack $w.kspopts.1.2.maxits -side right

	frame $w.kspopts.1.3
	label $w.kspopts.1.3.label -text "Relative tolerance:"
	entry $w.kspopts.1.3.rtol -relief sunken -textvariable sub_ksp_rtol \
		-width 10
	bind $w.kspopts.1.3.rtol <Any-Enter> {set sub_helpm $message(sub_ksp_rtol)}
	bind $w.kspopts.1.3.rtol <Any-Leave> {set sub_helpm ""}
	
	pack $w.kspopts.1.3.label -side left
	pack $w.kspopts.1.3.rtol -side right

	frame $w.kspopts.1.4
	label $w.kspopts.1.4.label -text "Absolute tolerance:"
	entry $w.kspopts.1.4.atol -relief sunken -textvariable sub_ksp_atol \
		-width 10
	bind $w.kspopts.1.4.atol <Any-Enter> {set sub_helpm $message(sub_ksp_atol)}
	bind $w.kspopts.1.4.atol <Any-Leave> {set sub_helpm ""}
	
	pack $w.kspopts.1.4.label -side left
	pack $w.kspopts.1.4.atol -side right

	frame $w.kspopts.1.5
	label $w.kspopts.1.5.label -text "Divergence Tolerance:"
	entry $w.kspopts.1.5.divtol -relief sunken -textvariable sub_ksp_divtol \
		-width 10
	bind $w.kspopts.1.5.divtol <Any-Enter> {set sub_helpm \
		$message(sub_ksp_divtol)}
	bind $w.kspopts.1.5.divtol <Any-Leave> {set sub_helpm ""}

	pack $w.kspopts.1.5.label -side left
	pack $w.kspopts.1.5.divtol -side right

	checkbutton $w.kspopts.1.6 -text "Use preconditioned residual" \
		-relief flat -variable sub_ksp_preres
	bind $w.kspopts.1.6 <Any-Enter> {set sub_helpm $message(sub_ksp_preres)}
	bind $w.kspopts.1.6 <Any-Leave> {set sub_helpm ""}
#	bind $w.kspopts.1.6 <Button-1> "$w.kspopts.1.6 invoke"

	pack $w.kspopts.1.1 $w.kspopts.1.2 $w.kspopts.1.3 $w.kspopts.1.4 \
		$w.kspopts.1.5  -fill x -side top
	pack $w.kspopts.1.6 -side top -anchor w


	label $w.kspopts.2.monlbl -text "Monitoring Convergence:    "

	checkbutton $w.kspopts.2.monitor -text "Use text-monitor" -relief flat \
		-variable sub_ksp_monitor -command {set sub_ksp_xmonitor(switch) 0}
	bind $w.kspopts.2.monitor <Any-Enter> {set sub_helpm \
		$message(sub_ksp_monitor)}
	bind $w.kspopts.2.monitor <Any-Leave> {set sub_helpm ""}
#	bind $w.kspopts.2.monitor <Button-1> "$w.kspopts.2.monitor invoke"

	checkbutton $w.kspopts.2.xmonitor -text "Use X-monitor" -relief flat \
		-variable sub_ksp_xmonitor(switch) -command {set sub_ksp_monitor 0}
	bind $w.kspopts.2.xmonitor <Any-Enter> {set sub_helpm \
		$message(sub_ksp_xmonitor_switch)}
	bind $w.kspopts.2.xmonitor <Any-Leave> {set sub_helpm ""}
#	bind $w.kspopts.2.xmonitor <Button-1> "$w.kspopts.2.xmonitor invoke"
 
	label $w.kspopts.2.xlbl -text "X-monitor Settings:"

	frame $w.kspopts.2.pos
	label $w.kspopts.2.pos.posxlbl -text "x  pos:"
	entry $w.kspopts.2.pos.posx -relief sunken -textvariable \
		sub_ksp_xmonitor(x) -width 4
	bind $w.kspopts.2.pos.posx <Any-Enter> {set sub_helpm \
		$message(sub_ksp_xmonitor_x)}
	bind $w.kspopts.2.pos.posx <Any-Leave> {set sub_helpm ""}
	label $w.kspopts.2.pos.posylbl -text "y pos:"
	entry $w.kspopts.2.pos.posy -relief sunken -textvariable \
		sub_ksp_xmonitor(y) -width 4
	bind $w.kspopts.2.pos.posy <Any-Enter> {set sub_helpm \
		$message(sub_ksp_xmonitor_y)}
	bind $w.kspopts.2.pos.posy <Any-Leave> {set sub_helpm ""}
	pack $w.kspopts.2.pos.posxlbl $w.kspopts.2.pos.posx -side left
	pack $w.kspopts.2.pos.posy $w.kspopts.2.pos.posylbl -side right

	frame $w.kspopts.2.wh
	label $w.kspopts.2.wh.hlbl -text "height:"
	entry $w.kspopts.2.wh.h -relief sunken -textvariable sub_ksp_xmonitor(h) \
		-width 4 
	bind $w.kspopts.2.wh.h <Any-Enter> {set sub_helpm \
		$message(sub_ksp_xmonitor_h)}
	bind $w.kspopts.2.wh.h <Any-Leave> {set sub_helpm ""}
	label $w.kspopts.2.wh.wlbl -text "width:"
	entry $w.kspopts.2.wh.w -relief sunken -textvariable sub_ksp_xmonitor(w) \
		-width 4
	bind $w.kspopts.2.wh.w <Any-Enter> {set sub_helpm \
		$message(sub_ksp_xmonitor_w)}
	bind $w.kspopts.2.wh.w <Any-Leave> {set sub_helpm ""}
	pack $w.kspopts.2.wh.hlbl $w.kspopts.2.wh.h -side left 
	pack $w.kspopts.2.wh.w $w.kspopts.2.wh.wlbl -side right

	pack $w.kspopts.2.monlbl $w.kspopts.2.monitor $w.kspopts.2.xmonitor \
		$w.kspopts.2.xlbl $w.kspopts.2.pos $w.kspopts.2.wh -side top -anchor w

	
	checkbutton $w.kspopts.3.1 -text "Use right preconditioner" -relief flat \
		-variable sub_ksp_right_pc
	bind $w.kspopts.3.1 <Any-Enter> {set sub_helpm $message(sub_ksp_right_pc)}
	bind $w.kspopts.3.1 <Any-Leave> {set sub_helpm ""}
#	bind $w.kspopts.3.1 <Button-1> "$w.kspopts.3.1 invoke"

	checkbutton $w.kspopts.3.2 -text "Calculate eigenvalues" -relief flat \
		-variable sub_ksp_eigen
	bind $w.kspopts.3.2 <Any-Enter> {set sub_helpm $message(sub_ksp_eigen)}
	bind $w.kspopts.3.2 <Any-Leave> {set sub_helpm ""}
#	bind $w.kspopts.3.2 <Button-1> "$w.kspopts.3.2 invoke"

	label $w.kspopts.3.lbl -text "Type-Specific Options:              "
	
	frame $w.kspopts.3.specopts
	
	pack $w.kspopts.3.1 $w.kspopts.3.2 $w.kspopts.3.lbl $w.kspopts.3.specopts\
		-side top -anchor w

	pack $w.kspopts.1 $w.kspopts.2 $w.kspopts.3 -side left -fill both -expand 1
	Display_KSP_BJacobi_Specific_Options $w.kspopts.3.specopts
}
proc Display_KSP_Options {} {

	frame .kspopts.1 -bd 4
	frame .kspopts.2 -bd 4
	frame .kspopts.3 -bd 4

	frame .kspopts.1.1
	bind .kspopts.1.1 <Any-Enter> {set helpm $message(ksp_type)}
	bind .kspopts.1.1 <Any-Leave> {set helpm ""}
	label .kspopts.1.1.label -text "KSP Type:"
	menubutton .kspopts.1.1.type -textvariable ksp_type \
		-menu .kspopts.1.1.type.menu -fg red -relief raised 
	menu .kspopts.1.1.type.menu 
	.kspopts.1.1.type.menu add radiobutton -label "Default" -variable \
		ksp_type -value Default -command \
		"Display_KSP_Specific_Options .kspopts.3.specopts" 
	.kspopts.1.1.type.menu add radiobutton -label "Richardson" -variable \
		ksp_type -value Richardson -command \
		"Display_KSP_Specific_Options .kspopts.3.specopts"
	.kspopts.1.1.type.menu add radiobutton -label "Chebychev" -variable \
		ksp_type -value Chebychev -command \
		"Display_KSP_Specific_Options .kspopts.3.specopts"
	.kspopts.1.1.type.menu add radiobutton -label "CG" \
		-variable  ksp_type -value "CG" -command \
		"Display_KSP_Specific_Options .kspopts.3.specopts"
	.kspopts.1.1.type.menu add radiobutton -label "GMRES" -variable \
		ksp_type -value GMRES -command \
		"Display_KSP_Specific_Options .kspopts.3.specopts"
	.kspopts.1.1.type.menu add radiobutton -label "Bi-CG-stab" -variable \
		ksp_type -value "Bi-CG-stab" -command \
		"Display_KSP_Specific_Options .kspopts.3.specopts"
	.kspopts.1.1.type.menu add radiobutton -label "TFQMR" -variable \
		ksp_type -value TFQMR -command \
		"Display_KSP_Specific_Options .kspopts.3.specopts"
	.kspopts.1.1.type.menu add radiobutton -label "TCQMR" -variable \
		ksp_type -value TCQMR -command \
		"Display_KSP_Specific_Options .kspopts.3.specopts"
	.kspopts.1.1.type.menu add radiobutton -label "CGS" -variable \
	 	ksp_type -value CGS -command \
		"Display_KSP_Specific_Options .kspopts.3.specopts"
	.kspopts.1.1.type.menu add radiobutton -label "CR" -variable \
		ksp_type -value CR -command \
		"Display_KSP_Specific_Options .kspopts.3.specopts"
	.kspopts.1.1.type.menu add radiobutton -label "Least Squares" -variable\
		ksp_type -value "Least Squares" -command \
		"Display_KSP_Specific_Options .kspopts.3.specopts"
	.kspopts.1.1.type.menu add radiobutton -label "Precond. Only" -variable\
		ksp_type -value "Precond. Only" -command \
		"Display_KSP_Specific_Options .kspopts.3.specopts"
	pack .kspopts.1.1.label -side left
	pack .kspopts.1.1.type -side right 

	frame .kspopts.1.2
	label .kspopts.1.2.label -text "Max. Iterations:          "
	entry .kspopts.1.2.maxits -relief sunken -textvariable ksp_max_it \
		-width 10
	bind .kspopts.1.2.maxits <Any-Enter> {set helpm $message(ksp_max_it)}
	bind .kspopts.1.2.maxits <Any-Leave> {set helpm ""}
	pack .kspopts.1.2.label -side left
	pack .kspopts.1.2.maxits -side right

	frame .kspopts.1.3
	label .kspopts.1.3.label -text "Relative tolerance:"
	entry .kspopts.1.3.rtol -relief sunken -textvariable ksp_rtol -width 10
	bind .kspopts.1.3.rtol <Any-Enter> {set helpm $message(ksp_rtol)}
	bind .kspopts.1.3.rtol <Any-Leave> {set helpm ""}
	pack .kspopts.1.3.label -side left
	pack .kspopts.1.3.rtol -side right

	frame .kspopts.1.4
	label .kspopts.1.4.label -text "Absolute tolerance:"
	entry .kspopts.1.4.atol -relief sunken -textvariable ksp_atol -width 10
	bind .kspopts.1.4.atol <Any-Enter> {set helpm $message(ksp_atol)}
	bind .kspopts.1.4.atol <Any-Leave> {set helpm ""} 
	pack .kspopts.1.4.label -side left
	pack .kspopts.1.4.atol -side right

	frame .kspopts.1.5
	label .kspopts.1.5.label -text "Divergence tolerance:"
	entry .kspopts.1.5.divtol -relief sunken -textvariable ksp_divtol \
		-width 10
	bind .kspopts.1.5.divtol <Any-Enter> {set helpm $message(ksp_divtol)}
	bind .kspopts.1.5.divtol <Any-Leave> {set helpm ""}
	pack .kspopts.1.5.label -side left
	pack .kspopts.1.5.divtol -side right

	checkbutton .kspopts.1.6 -text "Use preconditioned residual" \
		-relief flat -variable ksp_preres
	bind .kspopts.1.6 <Any-Enter> {set helpm $message(ksp_preres)}
	bind .kspopts.1.6 <Any-Leave> {set helpm ""}
#	bind .kspopts.1.6 <Button-1> ".kspopts.1.6 invoke"

	pack .kspopts.1.1 .kspopts.1.2 .kspopts.1.3 .kspopts.1.4 \
		.kspopts.1.5 -side top -fill x
	pack .kspopts.1.6 -side top -anchor w
	

	label .kspopts.2.monlbl -text "Monitoring Convergence:       "

	checkbutton .kspopts.2.monitor -text "Use text-monitor" -relief flat \
		-variable ksp_monitor -command {set ksp_xmonitor(switch) 0}
	bind .kspopts.2.monitor <Any-Enter> {set helpm $message(ksp_monitor)}
	bind .kspopts.2.monitor <Any-Leave> {set helpm ""}
#	bind .kspopts.2.monitor <Button-1> ".kspopts.2.monitor invoke"

	checkbutton .kspopts.2.xmonitor -text "Use X-monitor" -relief flat \
		-variable ksp_xmonitor(switch) -command {set ksp_monitor 0}
	bind .kspopts.2.xmonitor <Any-Enter> {set helpm \
		$message(ksp_xmonitor_switch)}
	bind .kspopts.2.xmonitor <Any-Leave> {set helpm ""}
#	bind .kspopts.2.xmonitor <Button-1> ".kspopts.2.xmonitor invoke"

	label .kspopts.2.xlbl -text "X-monitor Settings:"

	frame .kspopts.2.pos
	label .kspopts.2.pos.posxlbl -text "x  pos:"
	entry .kspopts.2.pos.posx -relief sunken -textvariable ksp_xmonitor(x) \
		-width 4
	bind .kspopts.2.pos.posx <Any-Enter> {set helpm $message(ksp_xmonitor_x)}
	bind .kspopts.2.pos.posx <Any-Leave> {set helpm ""}
	label .kspopts.2.pos.posylbl -text "y pos:"
	entry .kspopts.2.pos.posy -relief sunken -textvariable ksp_xmonitor(y) \
		-width 4
	bind .kspopts.2.pos.posy <Any-Enter> {set helpm $message(ksp_xmonitor_y)}
	bind .kspopts.2.pos.posy <Any-Leave> {set helpm ""}
	pack .kspopts.2.pos.posxlbl .kspopts.2.pos.posx -side left
	pack .kspopts.2.pos.posy .kspopts.2.pos.posylbl -side right

	frame .kspopts.2.wh
	label .kspopts.2.wh.hlbl -text "height:"
	entry .kspopts.2.wh.h -relief sunken -textvariable ksp_xmonitor(h) \
		-width 4 
	bind .kspopts.2.wh.h <Any-Enter> {set helpm $message(ksp_xmonitor_h)}
	bind .kspopts.2.wh.h <Any-Leave> {set helpm ""}
	label .kspopts.2.wh.wlbl -text "width:"
	entry .kspopts.2.wh.w -relief sunken -textvariable ksp_xmonitor(w) \
		-width 4
	bind .kspopts.2.wh.w <Any-Enter> {set helpm $message(ksp_xmonitor_w)}
	bind .kspopts.2.wh.w <Any-Leave> {set helpm ""}
	pack .kspopts.2.wh.hlbl .kspopts.2.wh.h -side left 
	pack .kspopts.2.wh.w .kspopts.2.wh.wlbl -side right

	pack .kspopts.2.monlbl .kspopts.2.monitor .kspopts.2.xmonitor \
		.kspopts.2.xlbl .kspopts.2.pos .kspopts.2.wh -side top -anchor w

	
	checkbutton .kspopts.3.1 -text "Use right preconditioner" -relief flat \
 		-variable ksp_right_pc
	bind .kspopts.3.1 <Any-Enter> {set helpm $message(ksp_right_pc)}
	bind .kspopts.3.1 <Any-Leave> {set helpm ""}
#	bind .kspopts.3.1 <Button-1> ".kspopts.3.1 invoke"

	checkbutton .kspopts.3.2 -text "Calculate eigenvalues" -relief flat \
		-variable ksp_eigen
	bind .kspopts.3.2 <Any-Enter> {set helpm $message(ksp_eigen)}
	bind .kspopts.3.2 <Any-Leave> {set helpm ""}
#	bind .kspopts.3.2 <Button-1> ".kspopts.3.2 invoke"

	label .kspopts.3.lbl -text "Type-Specific Options:             "
	
	frame .kspopts.3.specopts
	
	pack .kspopts.3.1 .kspopts.3.2 .kspopts.3.lbl \
		.kspopts.3.specopts -side top -anchor w

	pack .kspopts.1 .kspopts.2 .kspopts.3 -side left -fill both -expand 1
}

proc Display_KSP_BJacobi_Specific_Options {w} {
	 global sub_ksp_type

	 destroy $w
	 frame $w
	 pack $w -side top

	 if {[string compare "GMRES" $sub_ksp_type] == 0} {
		  checkbutton $w.ugs -text "Unmodified Gramm-Schmidt" -variable \
					 sub_ksp_gmres_unmodifiedgrammschmidt -relief flat
		  bind $w.ugs <Any-Enter> {set sub_helpm \
		     $message(sub_ksp_gmres_unmodifiedgrammschmidt)}
		  bind $w.ugs <Any-Leave> {set sub_helpm ""}
#		  bind $w.ugs <Button-1> "$w.ugs invoke"

		  frame $w.restart
		  label $w.restart.lbl -text "Restart value:"
		  entry $w.restart.val -relief sunken -width 10 -textvariable \
			sub_ksp_gmres_restart
		  bind $w.restart.val <Any-Enter> {set sub_helpm \
		     $message(sub_ksp_gmres_restart)}
		  bind $w.restart.val <Any-Leave> {set sub_helpm ""}

		  pack $w.restart.lbl -side left 
		  pack $w.restart.val -side right
		  pack $w.ugs -side top -anchor w 
		  pack $w.restart -side top -fill x
	 }	
}
proc Display_KSP_Specific_Options {w} {
	 global ksp_type

	 destroy $w
	 frame $w
	 pack $w -side top

	 if {[string compare "GMRES" $ksp_type] == 0} {
		  checkbutton $w.ugs -text "Unmodified Gramm-Schmidt" -variable \
					 ksp_gmres_unmodifiedgrammschmidt -relief flat
		  bind $w.ugs <Any-Enter> {set helpm \
		     $message(ksp_gmres_unmodifiedgrammschmidt)}
		  bind $w.ugs <Any-Leave> {set helpm ""}
#		  bind $w.ugs <Button-1> "$w.ugs invoke"		  

		  frame $w.restart
		  label $w.restart.lbl -text "Restart value:"
		  entry $w.restart.val -relief sunken -width 10 -textvariable \
			ksp_gmres_restart
		  bind $w.restart.val <Any-Enter> {set helpm $message(ksp_gmres_restart)}
		  bind $w.restart.val <Any-Leave> {set helpm ""}

		  pack $w.restart.lbl -side left 
		  pack $w.restart.val -side right
		  pack $w.ugs -side top -anchor w 
		  pack $w.restart -side top -fill x
	 }	
}

#
# SLES Options
#
proc Display_SLES_Options {} {
	.slesopts configure -relief groove
	checkbutton .slesopts.view -text "View SLES data structure" -relief flat\
		-variable sles_view
	bind .slesopts.view <Any-Enter> {set helpm $message(sles_view)}
	bind .slesopts.view <Any-Leave> {set helpm ""}
#	bind .slesopts.view <Button-1> ".slesopts.view invoke"
	pack .slesopts.view -side left -padx 4
}
#
# SNES Options
#
proc Display_SNES_Options {} {
	.snesopts configure -relief groove
	frame .snesopts.1 -bd 4
	frame .snesopts.2 -bd 4
	frame .snesopts.3 -bd 4

	frame .snesopts.1.1
	bind .snesopts.1.1 <Any-Enter> {set helpm $message(snes_type)}
	bind .snesopts.1.1 <Any-Leave> {set helpm ""}
	label .snesopts.1.1.label -text "SNES Type:"
	menubutton .snesopts.1.1.type -textvariable snes_type \
		-menu .snesopts.1.1.type.menu -fg red -relief raised
	menu .snesopts.1.1.type.menu 
	.snesopts.1.1.type.menu add radiobutton -label "Default" -variable \
		snes_type -value "Default" -command Display_SNES_Specific_Options
	.snesopts.1.1.type.menu add radiobutton -label "Line Search" -variable \
		snes_type -value "Line Search" -command Display_SNES_Specific_Options
	.snesopts.1.1.type.menu add radiobutton -label "Trust Region" -variable \
		snes_type -value "Trust Region" -command Display_SNES_Specific_Options
	.snesopts.1.1.type.menu add radiobutton -label "Evaluate Jacobian only" \
		-variable snes_type -value "Test" \
		-command Display_SNES_Specific_Options
	pack .snesopts.1.1.label -side left
	pack .snesopts.1.1.type -side right

	frame .snesopts.1.2
	label .snesopts.1.2.label -text "Max. Iterations:"
	entry .snesopts.1.2.maxits -relief sunken -textvariable snes_max_it \
		-width 10
	bind .snesopts.1.2.maxits <Any-Enter> {set helpm $message(snes_max_it)}
	bind .snesopts.1.2.maxits <Any-Leave> {set helpm ""}
	pack .snesopts.1.2.label -side left
	pack .snesopts.1.2.maxits -side right

	frame .snesopts.1.3
	label .snesopts.1.3.label -text "Max. function evals:"
	entry .snesopts.1.3.maxits -relief sunken -textvariable snes_max_funcs \
		-width 10
	bind .snesopts.1.3.maxits <Any-Enter> {set helpm $message(snes_max_funcs)}
	bind .snesopts.1.3.maxits <Any-Leave> {set helpm ""}
	pack .snesopts.1.3.label -side left
	pack .snesopts.1.3.maxits -side right

	frame .snesopts.1.4
	label .snesopts.1.4.label -text "Step tolerance:"
	entry .snesopts.1.4.rtol -relief sunken -textvariable snes_stol -width 10
	bind .snesopts.1.4.rtol <Any-Enter> {set helpm $message(snes_stol)}
	bind .snesopts.1.4.rtol <Any-Leave> {set helpm ""}
	pack .snesopts.1.4.label -side left
	pack .snesopts.1.4.rtol -side right

	frame .snesopts.1.5
	label .snesopts.1.5.label -text "Absolute tolerance:"
	entry .snesopts.1.5.atol -relief sunken -textvariable snes_atol -width 10
	bind .snesopts.1.5.atol <Any-Enter> {set helpm $message(snes_atol)}
	bind .snesopts.1.5.atol <Any-Leave> {set helpm ""}
	pack .snesopts.1.5.label -side left
	pack .snesopts.1.5.atol -side right

	frame .snesopts.1.6
	label .snesopts.1.6.label -text "Relative tolerance:"
	entry .snesopts.1.6.rtol -relief sunken -textvariable snes_rtol -width 10
	bind .snesopts.1.6.rtol <Any-Enter> {set helpm $message(snes_rtol)}
	bind .snesopts.1.6.rtol <Any-Leave> {set helpm ""}
	pack .snesopts.1.6.label -side left
	pack .snesopts.1.6.rtol -side right

	frame .snesopts.1.7
	label .snesopts.1.7.label -text "Truncation tolerance:   "
	entry .snesopts.1.7.ttol -relief sunken -textvariable snes_ttol -width 10
	bind .snesopts.1.7.ttol <Any-Enter> {set helpm $message(snes_ttol)}
	bind .snesopts.1.7.ttol <Any-Leave> {set helpm ""}
	pack .snesopts.1.7.label -side left
	pack .snesopts.1.7.ttol -side right

	pack .snesopts.1.1 .snesopts.1.2 .snesopts.1.3 .snesopts.1.4 .snesopts.1.5 \
		.snesopts.1.6 .snesopts.1.7 -side top -fill x -anchor w

	
	label .snesopts.2.monlbl -text "Monitoring Convergence:       "

	checkbutton .snesopts.2.monitor -text "Use text-monitor" -relief flat \
		-variable snes_monitor -command {set snes_xmonitor(switch) 0}
	bind .snesopts.2.monitor <Any-Enter> {set helpm $message(snes_monitor)}
	bind .snesopts.2.monitor <Any-Leave> {set helpm ""}
#	bind .snesopts.2.monitor <Button-1> ".snesopts.2.monitor invoke"

	checkbutton .snesopts.2.xmonitor -text "Use X-monitor" -relief flat \
		-variable snes_xmonitor(switch) -command {set snes_monitor 0}
	bind .snesopts.2.xmonitor <Any-Enter> {set helpm \
		$message(snes_xmonitor_switch)}
	bind .snesopts.2.xmonitor <Any-Leave> {set helpm ""}
#	bind .snesopts.2.xmonitor <Button-1> ".snesopts.2.xmonitor invoke"

	label .snesopts.2.xlbl -text "X-monitor Settings:"

	frame .snesopts.2.pos
	label .snesopts.2.pos.posxlbl -text "x  pos:"
	entry .snesopts.2.pos.posx -relief sunken -textvariable snes_xmonitor(x) \
		-width 4
	bind .snesopts.2.pos.posx <Any-Enter> {set helpm \
		$message(snes_xmonitor_x)}
	bind .snesopts.2.pos.posx <Any-Leave> {set helpm ""}
	label .snesopts.2.pos.posylbl -text "y pos:"
	entry .snesopts.2.pos.posy -relief sunken -textvariable snes_xmonitor(y) \
		-width 4
	bind .snesopts.2.pos.posy <Any-Enter> {set helpm \
		$message(snes_xmonitor_y)}
	bind .snesopts.2.pos.posy <Any-Leave> {set helpm ""}
	pack .snesopts.2.pos.posxlbl .snesopts.2.pos.posx -side left
	pack .snesopts.2.pos.posy .snesopts.2.pos.posylbl -side right

	frame .snesopts.2.wh
	label .snesopts.2.wh.hlbl -text "height:"
	entry .snesopts.2.wh.h -relief sunken -textvariable snes_xmonitor(h) \
		-width 4 
	bind .snesopts.2.wh.h <Any-Enter> {set helpm $message(snes_xmonitor_h)}
	bind .snesopts.2.wh.h <Any-Leave> {set helpm ""}
	label .snesopts.2.wh.wlbl -text "width:"
	entry .snesopts.2.wh.w -relief sunken -textvariable snes_xmonitor(w) \
		-width 4
	bind .snesopts.2.wh.w <Any-Enter> {set helpm $message(snes_xmonitor_w)}
	bind .snesopts.2.wh.w <Any-Leave> {set helpm ""}
	pack .snesopts.2.wh.hlbl .snesopts.2.wh.h -side left 
	pack .snesopts.2.wh.w .snesopts.2.wh.wlbl -side right
	
	checkbutton .snesopts.2.view -text "View SNES data structure" -relief flat \
		-variable snes_view
	bind .snesopts.2.view <Any-Enter> {set helpm $message(snes_view)}
	bind .snesopts.2.view <Any-Leave> {set helpm ""}
#	bind .snesopts.2.view <Button-1> ".snesopts.2.view invoke"

	pack .snesopts.2.monlbl .snesopts.2.monitor .snesopts.2.xmonitor \
		.snesopts.2.xlbl .snesopts.2.pos .snesopts.2.wh .snesopts.2.view \
		-side top -anchor w

	checkbutton .snesopts.3.1 -text "Use Finite-differences" -variable \
		snes_fd -relief flat -command {set snes_mf 0}
	bind .snesopts.3.1 <Any-Enter> {set helpm $message(snes_fd)}
	bind .snesopts.3.1 <Any-Leave> {set helpm ""}
#	bind .snesopts.3.1 <Button-1> ".snesopts.3.1 invoke"

	checkbutton .snesopts.3.2 -text "Use matrix-free variants" -variable \
		snes_mf -relief flat -command {set snes_fd 0}
	bind .snesopts.3.2 <Any-Enter> {set helpm $message(snes_mf)}
	bind .snesopts.3.2 <Any-Leave> {set helpm ""}
#	bind .snesopts.3.2 <Button-1> ".snesopts.3.2 invoke"

	label .snesopts.3.3 -text "Type-Specific Options:             "

	frame .snesopts.3.specopts

	pack .snesopts.3.1 .snesopts.3.2 .snesopts.3.3 .snesopts.3.specopts \
		-side top -anchor w

	pack .snesopts.1 .snesopts.2 .snesopts.3 -side left -fill both -expand 1
}

proc Display_SNES_Specific_Options {} {
	global snes_type

	 set w .snesopts.3.specopts

	 destroy $w
	 frame $w
	 pack $w -side top -fill both

	 if {[string compare "Line Search" $snes_type] == 0} {
		  
		  frame $w.line
		  bind $w.line <Any-Enter> {set helpm $message(snes_line_search)}
		  bind $w.line <Any-Leave> {set helpm ""}
		  label $w.line.lbl -text "Line search:"
		  menubutton $w.line.entry -textvariable snes_line_search -menu \
					 $w.line.entry.menu
		  menu $w.line.entry.menu
		  $w.line.entry.menu add radiobutton -label "Default" -variable \
					 snes_line_search -value Default
		  $w.line.entry.menu add radiobutton -label "Basic" -variable \
					 snes_line_search -value Basic
		  $w.line.entry.menu add radiobutton -label "Quadratic" -variable \
					 snes_line_search -value Quadratic
		  $w.line.entry.menu add radiobutton -label "Cubic" -variable \
					 snes_line_search -value Cubic
		  pack $w.line.lbl -side left
		  pack $w.line.entry -side right
		  
		  frame $w.alpha
		  label $w.alpha.lbl -text "Alpha:"
		  entry $w.alpha.entry -textvariable snes_line_search_alpha \
					 -width 10 -relief sunken
		  bind $w.alpha.entry <Any-Enter> {set helpm \
		     $message(snes_line_search_alpha)}
		  bind $w.alpha.entry <Any-Leave> {set help ""}
		  pack $w.alpha.lbl -side left
		  pack $w.alpha.entry -side right
		  
		  frame $w.maxstep
		  label $w.maxstep.lbl -text "Max. step:"
		  entry $w.maxstep.entry -textvariable snes_line_search_maxstep \
					 -width 10 -relief sunken
		  bind $w.maxstep.entry <Any-Enter> {set helpm \
		     $message(snes_line_search_maxstep)}
		  bind $w.maxstep.entry <Any-Leave> {set help ""}
		  pack $w.maxstep.lbl -side left
		  pack $w.maxstep.entry -side right

		  frame $w.steptol
		  label $w.steptol.lbl -text "Step tolerance:"
		  entry $w.steptol.entry -textvariable snes_line_search_steptol \
					 -width 10 -relief sunken
		  bind $w.steptol.entry <Any-Enter> {set helpm \
		     $message(snes_line_search_steptol)}
		  bind $w.steptol.entry <Any-Leave> {set helpm ""}
		  pack $w.steptol.lbl -side left
		  pack $w.steptol.entry -side right

		  pack $w.line $w.alpha $w.maxstep $w.steptol -side top -fill x
	 }	
}

#
# Graphics Options
#
proc Display_Graphics_Options {} {
	.graphopts config -relief groove
	frame .graphopts.1
	frame .graphopts.2
	checkbutton .graphopts.1.nox -text "Don't Display graphics" -relief flat \
		-variable nox
	bind .graphopts.1.nox <Any-Enter> {set helpm $message(nox)}
	bind .graphopts.1.nox <Any-Leave> {set helpm ""}
#	bind .graphopts.1.nox <Button-1> ".graphopts.1.nox invoke"
	pack .graphopts.1.nox -side top -fill x

	frame .graphopts.2.pause
	label .graphopts.2.pause.lbl -text "Second to pause between events:"
	entry .graphopts.2.pause.entry -relief sunken -width 5 -textvariable \
		pause
	bind .graphopts.2.pause.entry <Any-Enter> {set helpm $message(pause)}
	bind .graphopts.2.pause.entry <Any-Leave> {set helpm ""}
	pack .graphopts.2.pause.lbl -side left -fill x
	pack .graphopts.2.pause.entry -side right
	pack .graphopts.2.pause -side top -fill x

	pack .graphopts.1 -side left -padx 4 -fill x
	pack .graphopts.2 -side right -padx 4 -fill x
}

##############################################################################
#
##############################################################################
proc Select_Open_File {} {
	global filename

	if {[file isfile $filename]} {
		set button [Dialog .fileloaded "File Already Loaded" \
			"File already loaded, do you want to save current settings before \
			new file is loaded?" warning.bit 0 "Save" "Don't Save"]
		if {$button == 0} {	
			Write_PETSc_Options $filename
		}
	}
	fileselect Read_PETSc_Options "Read File:" {*.* .petscrc*} .fileSelectWindow fileselect.default.errorHandler
} 
proc Select_Save_File {} {
	fileselect Write_PETSc_Options "Write to File:" {*.* .petscrc*} .fileSelectWindow fileselect.default.errorHandler
}

proc Exit {} {
	global filename env 
	
	if {[file exists $env(HOME)/.petscrcbak]} {
		set button [Dialog .savefile "Save File Before Exiting"  "A back-up copy of .petscrc exists.  Would you like to use write current settings or back-up settings to .petscrc?" warning.bit 0 "Use Back-up" "Use current" "Use neither" "Cancel"]
		if {$button == 0} {
			catch {exec mv -f $env(HOME)/.petscrcbak $env(HOME)/.petscrc}
		} elseif {$button == 1} {
			catch {exec rm -f $env(HOME)/.petscrcbak}
			Write_PETSc_Options $filename
		} elseif {$button == 2} {
			catch {exec rm -f $env(HOME)/.petscrcbak}
		} elseif {$button == 3} {
			return
		}
	} else {
		set button [Dialog .savefile "Save File Before Exiting" "Would you like to save \"$filename\" before exiting.  Saving will affect future runs!!" warning.bit 0 "Save" "Don't Save" "Cancel"]
		if {$button == 0} {
			Write_PETSc_Options $filename
		}
		if {$button == 2} {
			return
		}
	}
	exit
}



##############################################################################
#
##############################################################################
proc Read_PETSc_Options {file} {
	global filename
# general options
	global help version on_error_attach_debugger
	global start_in_debugger debugger_type display
        global no_signal_handler fp_trap trdump trmalloc 
        global trinfo trdebug on_error_abort info log_history 
        global log_mpe mpelogfile
	global optionstable optionsleft log log_all logfile log_summary
# preconditioner options
	global pc_type pc_sor_omega pc_sor_its pc_sor pc_lu_in_place
	global pc_lu_ordering pc_ilu_ordering pc_ilu_levels pc_bjacobi_blocks
        global pc_bjacobi_truelocal pc_ilu_in_place pc_ilu_factorpointwise
	global pc_bs_max_it pc_bs_blocksize pc_bs_rtol pc_bs
# ksp options
   global ksp_type ksp_max_it ksp_rtol ksp_atol ksp_divtol 
   global ksp_preres ksp_right_pc ksp_eigen 
	global ksp_monitor ksp_xmonitor ksp_gmres_restart
	global ksp_gmres_unmodifiedgrammschmidt
# sub preconditioner options
	global sub_pc_type sub_pc_sor_omega sub_pc_sor_its sub_pc_sor
	global sub_pc_lu_in_place sub_pc_lu_ordering sub_pc_ilu_ordering 
	global sub_pc_ilu_levels sub_pc_bs_max_it sub_pc_ilu_in_place
        global sub_pc_ilu_factorpointwise
	global sub_pc_bs_blocksize sub_pc_bs_rtol sub_pc_bs
# sub ksp options
   global sub_ksp_type sub_ksp_max_it sub_ksp_rtol sub_ksp_atol 
	global sub_ksp_divtol sub_ksp_preres sub_ksp_right_pc sub_ksp_eigen 
	global sub_ksp_monitor sub_ksp_xmonitor sub_ksp_gmres_restart
	global sub_ksp_gmres_unmodifiedgrammschmidt
# sles options
	global sles_view
# snes options 
	global snes_view snes_type snes_max_it snes_max_funcs snes_stol snes_atol
	global snes_rtol snes_ttol snes_monitor snes_xmonitor 
	global snes_fd snes_mf snes_line_search snes_line_search_alpha
	global snes_line_search_maxstep snes_line_search_steptol
# graphics options
	global pause nox

	set fd [open $file r]

	while {[gets $fd aline] != -1} {
# general options
		if {![string compare "-h" [lindex $aline 0]]} {
			set help 1 
		} elseif {![string compare "-help" [lindex $aline 0]]} {
			set help 1
		} elseif {![string compare "-v" [lindex $aline 0]]} {
			set version 1
		} elseif {![string compare "-version" [lindex $aline 0]]} {
			set version 1
		} elseif {![string compare "-on_error_attach_debugger" [lindex $aline \
			0]]} {
			set on_error_attach_debugger 1 ; set start_in_debugger 0
			set debugger_type [lindex $aline 1]
                } elseif {![string compare "-on_error_abort" [lindex $aline 0]]} {
			set on_error_abort 1
		} elseif {![string compare "-start_in_debugger" [lindex $aline 0]]} {
			set start_in_debugger 1 ; set on_error_attach_debugger 0
			set debugger_type [lindex $aline 1]
		} elseif {![string compare "-display" [lindex $aline 0]]} {
			set display [lindex $aline 1]
		} elseif {![string compare "-no_signal_handler" [lindex $aline 0]]} { 
			set no_signal_handler 1
		} elseif {![string compare "-fp_trap" [lindex $aline 0]]} {
			set fp_trap 1
		} elseif {![string compare "-trdump" [lindex $aline 0]]} {
			set trdump 1
		} elseif {![string compare "-trmalloc" [lindex $aline 0]]} {
			set trmalloc 1
		} elseif {![string compare "-notrmalloc" [lindex $aline 0]]} {
			set trmalloc 0
                } elseif {![string compare "-trinfo" [lindex $aline 0]]} {
                        set trinfo 1
                } elseif {![string compare "-trdebug" [lindex $aline 0]]} {
                        set trdebug 1
		} elseif {![string compare "-optionstable" [lindex $aline 0]]} {
			set optionstable 1
		} elseif {![string compare "-optionsleft" [lindex $aline 0]]} {
			set optionsleft 1 
		} elseif {![string compare "-log" [lindex $aline 0]]} { 
			set log 1 ; set log_all 0
			if {[llength $aline] == 2} {
				set logfile [lindex $aline 1]
			}
		} elseif {![string compare "-log_all" [lindex $aline 0]]} {
			set log_all 1 ; set log 0
			if {[llength $aline] == 2} {
				set logfile [lindex $aline 1]
			}
		} elseif {![string compare "-log_summary" [lindex $aline 0]]} {
			set log_summary 1
                } elseif {![string compare "-info" [lindex $aline 0]]} {
			set info 1
                } elseif {![string compare "-log_history" [lindex $aline 0]]} {
			set log_history 1
                } elseif {![string compare "-log_mpe" [lindex $aline 0]]} { 
			set log_mpe 1 
			if {[llength $aline] == 2} {
				set mpelogfile [lindex $aline 1]
                        }
# ksp options
		} elseif {![string compare "-ksp_type" [lindex $aline 0]]} {
			set type [lindex $aline 1]
			if {![string compare "richardson" $type]} {
				set ksp_type "Richardson"
			} elseif {![string compare "chebychev" $type]} {
				set ksp_type "Chebychev"
			} elseif {![string compare "cg" $type]} {
				set ksp_type "CG"
			} elseif {![string compare "gmres" $type]} {
				set ksp_type "GMRES"
			} elseif {![string compare "bcgs" $type]} {
				set ksp_type "Bi-CG-stab"
			} elseif {![string compare "tfqmr"]} {
				set ksp_type "TFQMR"
			} elseif {![string compare "tcqmr"]} {
				set ksp_type "TCQMR"
			} elseif {![string compare "cgs"]} {
				set ksp_type "CGS"
			} elseif {![string compare "cr"]} {
				set ksp_type "CR"
			} elseif {![string compare "lsqr"} {
				set ksp_type "Least Squares"
			} elseif {![string compare "preonly"} {
				set ksp_type "Precond. Only"
			}
		} elseif {[string compare "-ksp_max_it" [lindex $aline 0]] == 0} {
			set ksp_max_it [lindex $aline 1]
		} elseif {[string compare "-ksp_rtol" [lindex $aline 0]] == 0} {
			set ksp_rtol [lindex $aline 1]
		} elseif {[string compare "-ksp_atol" [lindex $aline 0]] == 0} {
			set ksp_atol [lindex $aline 1]
		} elseif {[string compare "-ksp_divtol" [lindex $aline 0]] == 0} {
			set ksp_divtol [lindex $aline 1]
		} elseif {[string compare "-ksp_preres" [lindex $aline 0]] == 0} {
			set ksp_preres 1
		} elseif {[string compare "-ksp_right_pc" [lindex $aline 0]] == 0} {
			set ksp_right_pc 1
		} elseif {[string compare "-ksp_eigen" [lindex $aline 0]] == 0} {
			set ksp_eigen 1
		} elseif {[string compare "-ksp_monitor" [lindex $aline 0]] == 0} {
			set ksp_monitor 1
		} elseif {[string compare "-ksp_xmonitor" [lindex $aline 0]] == 0} {
			set ksp_xmonitor(switch) 1
			if {[llength $aline] == 2} {
				set configuration [split [lindex $aline 1] ,]
				set ksp_xmonitor(x) [lindex $configuration 0]
				set ksp_xmonitor(y) [lindex $configuration 1]
				set ksp_xmonitor(w) [lindex $configuration 2]
				set ksp_xmonitor(h) [lindex $configuration 3]
			}
		} elseif {[string compare "-ksp_gmres_restart" [lindex $aline 0]] == 0} {
			set ksp_gmres_restart [lindex $aline 1]
		} elseif {[string compare "-ksp_gmres_unmodifiedgrammschmidt" [lindex \
			$aline 0]] == 0} {
			set ksp_gmres_unmodifiedgrammschmidt 1
# pc options		
		} elseif {[string compare "-pc_type" [lindex $aline 0]] == 0} {
			set type [lindex $aline 1]
			if {![string compare "none" $type]} {
				set pc_type "None"
			} elseif {![string compare "jacobi" $type]} {
				set pc_type "Jacobi"
			} elseif {![string compare "bjacobi" $type]} {
				set pc_type "Block Jacobi"
			} elseif {![string compare "sor" $type]} {
				set pc_type "SOR"
			} elseif {![string compare "icc" $type]} {
				set pc_type "ICC"
			} elseif {![string compare "ilu" $type]} {
				set pc_type "ILU"
			} elseif {![string compare "lu" $type]} {
				set pc_type "LU"
                        } elseif {![string compare "bgs" $type]} {
                               set pc_type "BGS"
                        } elseif {![string compare "ASM" $type]} {
				set pc_type "ASM"
			} elseif {![string compare "shell" $type]} {
				set pc_type "Shell"
			}
		} elseif {[string compare "-pc_sor_omega" [lindex $aline 0]] == 0} {
			set pc_sor_omega [lindex $aline 1]
		} elseif {[string compare "-pc_sor_its" [lindex $aline 0]] == 0} {
			set pc_sor_its [lindex $aline 1]
		} elseif {[string compare "-pc_sor_backward" [lindex $aline 0]] == 0} {
			set pc_sor "Backward"
		} elseif {[string compare "-pc_sor_symmetric" [lindex $aline 0]] == 0} {
			set pc_sor "Symmetric"
		} elseif {[string compare "-pc_sor_local_forward" [lindex $aline 0]] \
			== 0} {
			set pc_sor "Local forward"
		} elseif {[string compare "-pc_sor_local_backward" [lindex $aline 0]] \
			== 0} {
			set pc_sor "Local backward"
		} elseif {[string compare "-pc_sor_local_symmetric" [lindex $aline 0]] \
			== 0} {
			set pc_sor "Local symmetric"
		} elseif {[string compare "-pc_lu_in_place" [lindex $aline 0]] == 0} {
			set pc_lu_in_place 1
		} elseif {[string compare "-pc_lu_ordering" [lindex $aline 0]] == 0} {
			set ord [lindex $aline 1]
			if {![string compare "natural" $ord]} {
				set pc_lu_ordering "Natural"
			} elseif {![string compare "nd" $ord]} {
				set pc_lu_ordering "Nested Dissection"
			} elseif {![string compare "1wd" $ord]} {
				set pc_lu_ordering "One-way Dissection"
			} elseif {![string compare "rcm" $ord]} {
				set pc_lu_ordering "Reverse Cuthill-McGee"
			} elseif {![string compare "qmd" $ord]} {
				set pc_lu_ordering "Quotient Minimum Degree"
			}
		} elseif {[string compare "-pc_ilu_levels" [lindex $aline 0]] == 0} {
			set pc_ilu_levels [lindex $aline 1]
                } elseif {[string compare "-pc_ilu_in_place" [lindex $aline 0]] == 0} {
			set pc_ilu_in_place 1
                } elseif {[string compare "-pc_ilu_factorpointwise" [lindex $aline 0]] \
                        == 0} {
			set pc_ilu_factorpointwise 1
		} elseif {[string compare "-pc_ilu_ordering" [lindex $aline 0]] == 0} {
			set ord [lindex $aline 1]
			if {![string compare "natural" $ord]} {
				set pc_ilu_ordering "Natural"
			} elseif {![string compare "nd" $ord]} {
				set pc_ilu_ordering "Nested Dissection"
			} elseif {![string compare "1wd" $ord]} {
				set pc_ilu_ordering "One-way Dissection"
			} elseif {![string compare "rcm" $ord]} {
				set pc_ilu_ordering "Reverse Cuthill-McGee"
			} elseif {![string compare "qmd" $ord]} {
				set pc_ilu_ordering "Quotient Minimum Degree"
			}
		} elseif {[string compare "-pc_bjacobi_blocks" [lindex $aline 0]] \
			== 0} {
			set pc_bjacobi_blocks [lindex $aline 1]
                } elseif {[string compare "-pc_bjacobi_truelocal" [lindex $aline 0]] \
			== 0} {
			set pc_bjacobi_truelocal 1
		} elseif {[string compare "-pc_bs_max_it" [lindex $aline 0]] == 0} {
			set pc_bs_max_it [lindex $aline 1]
		} elseif {[string compare "-pc_bs_blocksize" [lindex $aline 0]] == 0} {
			set pc_bs_blocksize [lindex $aline 1]
		} elseif {[string compare "-pc_bs_rtol" [lindex $aline 0]] == 0} {
			set pc_bs_rtol [lindex $aline 0]
		} elseif {[string compare "-pc_bs_ssor" [lindex $aline 0]] == 0} {
			set pc_bs "SSOR"
		} elseif {[string compare "-pc_bs_bjacobi" [lindex $aline 0]] == 0} {
			set pc_bs "Block Jacobi"
		} elseif {[string compare "-pc_bs_diag" [lindex $aline 0]] == 0} {
			set pc_bs "Diagonal"
# sub ksp options		
		} elseif {[string compare "-sub_ksp_type" [lindex $aline 0]] == 0} {
			set type [lindex $aline 1]
			if {![string compare "richardson" $type]} {
				set sub_ksp_type "Richardson"
			} elseif {![string compare "chebychev" $type]} {
				set sub_ksp_type "Chebychev"
			} elseif {![string compare "cg" $type]} {
				set sub_ksp_type "CG"
			} elseif {![string compare "gmres" $type]} {
				set sub_ksp_type "GMRES"
			} elseif {![string compare "bcgs" $type]} {
				set sub_ksp_type "Bi-CG-stab"
			} elseif {![string compare "tfqmr"]} {
				set sub_ksp_type "TFQMR"
			} elseif {![string compare "tcqmr"]} {
				set sub_ksp_type "TCQMR"
			} elseif {![string compare "cgs"]} {
				set sub_ksp_type "CGS"
			} elseif {![string compare "cr"]} {
				set sub_ksp_type "CR"
			} elseif {![string compare "lsqr"} {
				set sub_ksp_type "Least Squares"
			} elseif {![string compare "preonly"} {
				set sub_ksp_type "Precond. Only"
			}
		} elseif {[string compare "-sub_ksp_max_it" [lindex $aline 0]] == 0} {
			set sub_ksp_max_it [lindex $aline 1]
		} elseif {[string compare "-sub_ksp_rtol" [lindex $aline 0]] == 0} {
			set sub_ksp_rtol [lindex $aline 1]
		} elseif {[string compare "-sub_ksp_atol" [lindex $aline 0]] == 0} {
			set sub_ksp_atol [lindex $aline 1]
		} elseif {[string compare "-sub_ksp_divtol" [lindex $aline 0]] == 0} {
			set sub_ksp_divtol [lindex $aline 1]
		} elseif {[string compare "-sub_ksp_preres" [lindex $aline 0]] == 0} {
			set sub_ksp_preres 1
		} elseif {[string compare "-sub_ksp_right_pc" [lindex $aline 0]] == 0} {
			set sub_ksp_right_pc 1
		} elseif {[string compare "-sub_ksp_eigen" [lindex $aline 0]] == 0} {
			set sub_ksp_eigen 1
		} elseif {[string compare "-sub_ksp_monitor" [lindex $aline 0]] == 0} {
			set sub_ksp_monitor 1
		} elseif {[string compare "-sub_ksp_xmonitor" [lindex $aline 0]] == 0} {
			set sub_ksp_xmonitor(switch) 1
			if {[llength $aline] == 2} {
				set configuration [split [lindex $aline 1] ,]
				set sub_ksp_xmonitor(x) [lindex $configuration 0]
				set sub_ksp_xmonitor(y) [lindex $configuration 1]
				set sub_ksp_xmonitor(w) [lindex $configuration 2]
				set sub_ksp_xmonitor(h) [lindex $configuration 3]
			}
		} elseif {[string compare "-sub_ksp_gmres_restart" [lindex $aline 0]]\
			== 0} {
			set sub_ksp_gmres_restart [lindex $aline 1]
		} elseif {[string compare "-sub_ksp_gmres_unmodifiedgrammschmidt" \
			[lindex $aline 0]] == 0} {
			set sub_ksp_gmres_unmodifiedgrammschmidt 1
# sub pc type		
		} elseif {[string compare "-sub_pc_type" [lindex $aline 0]] == 0} {
			set type [lindex $aline 1]
			if {![string compare "none" $type]} {
				set sub_pc_type "None"
			} elseif {![string compare "jacobi" $type]} {
				set sub_pc_type "Jacobi"
			} elseif {![string compare "bjacobi" $type]} {
				set sub_pc_type "Block Jacobi"
			} elseif {![string compare "sor" $type]} {
				set sub_pc_type "SOR"
			} elseif {![string compare "icc" $type]} {
				set sub_pc_type "ICC"
			} elseif {![string compare "ilu" $type]} {
				set sub_pc_type "ILU"
			} elseif {![string compare "lu" $type]} {
				set sub_pc_type "LU"
			} elseif {![string compare "shell" $type]} {
				set sub_pc_type "Shell"
			}
		} elseif {[string compare "-sub_pc_sor_omega" [lindex $aline 0]] == 0} {
			set sub_pc_sor_omega [lindex $aline 1]
		} elseif {[string compare "-sub_pc_sor_its" [lindex $aline 0]] == 0} {
			set sub_pc_sor_its [lindex $aline 1]
		} elseif {[string compare "-sub_pc_sor_backward" [lindex $aline 0]] \
			== 0} {
			set sub_pc_sor "Backward"
		} elseif {[string compare "-sub_pc_sor_symmetric" [lindex $aline 0]] \
			== 0} {
			set sub_pc_sor "Symmetric"
		} elseif {[string compare "-sub_pc_sor_local_forward" [lindex $aline 0]]\
			== 0} {
			set sub_pc_sor "Local forward"
		} elseif {[string compare "-sub_pc_sor_local_backward" [lindex \
			$aline 0]] == 0} {
			set sub_pc_sor "Local backward"
		} elseif {[string compare "-sub_pc_sor_local_symmetric" [lindex \
			$aline 0]] == 0} {
			set sub_pc_sor "Local symmetric"
		} elseif {[string compare "-sub_pc_lu_in_place" [lindex \
			$aline 0]] == 0} {
			set sub_pc_lu_in_place 1
		} elseif {[string compare "-sub_pc_lu_ordering" [lindex $aline 0]] \
			== 0} {
			set ord [lindex $aline 1]
			if {![string compare "natural" $ord]} {
				set sub_pc_lu_ordering "Natural"
			} elseif {![string compare "nd" $ord]} {
				set sub_pc_lu_ordering "Nested Dissection"
			} elseif {![string compare "1wd" $ord]} {
				set sub_pc_lu_ordering "One-way Dissection"
			} elseif {![string compare "rcm" $ord]} {
				set sub_pc_lu_ordering "Reverse Cuthill-McGee"
			} elseif {![string compare "qmd" $ord]} {
				set sub_pc_lu_ordering "Quotient Minimum Degree"
			}
		} elseif {[string compare "-sub_pc_ilu_levels" [lindex $aline 0]] \
                        == 0} {
			set sub_pc_ilu_levels [lindex $aline 1]
		} elseif {[string compare "-sub_pc_ilu_in_place" [lindex $aline 0]] \
                        == 0} {
			set sub_pc_ilu_in_place 1
		} elseif {[string compare "-sub_pc_ilu_factorpointwise" \
                        [lindex $aline 0]] == 0} {
			set sub_pc_ilu_factorpointwise 1
		} elseif {[string compare "-sub_pc_ilu_ordering" [lindex $aline 0]] \
			== 0} {
			set ord [lindex $aline 1]
			if {![string compare "natural" $ord]} {
				set sub_pc_ilu_ordering "Natural"
			} elseif {![string compare "nd" $ord]} {
				set sub_pc_ilu_ordering "Nested Dissection"
			} elseif {![string compare "1wd" $ord]} {
				set sub_pc_ilu_ordering "One-way Dissection"
			} elseif {![string compare "rcm" $ord]} {
				set sub_pc_ilu_ordering "Reverse Cuthill-McGee"
			} elseif {![string compare "qmd" $ord]} {
				set sub_pc_ilu_ordering "Quotient Minimum Degree"
			}
		} elseif {[string compare "-sub_pc_bjacobi_blocks" [lindex $aline 0]] \
			== 0} {
			set sub_pc_bjacobi_blocks [lindex $aline 1]
                } elseif {[string compare "-sub_pc_bjacobi_truelocal" \
                        [lindex $aline 0]] == 0} {
			set sub_pc_bjacobi_truelocal 1
		} elseif {[string compare "-sub_pc_bs_max_it" [lindex $aline 0]] == 0} {
			set sub_pc_bs_max_it [lindex $aline 1]
		} elseif {[string compare "-sub_pc_bs_blocksize" [lindex $aline 0]] \
			== 0} {
			set sub_pc_bs_blocksize [lindex $aline 1]
		} elseif {[string compare "-sub_pc_bs_rtol" [lindex $aline 0]] == 0} {
			set sub_pc_bs_rtol [lindex $aline 1]
		} elseif {[string compare "-sub_pc_bs_ssor" [lindex $aline 0]] == 0} {
			set sub_pc_bs "SSOR"
		} elseif {[string compare "-sub_pc_bs_bjacobi" [lindex $aline 0]] == 0} {
			set sub_pc_bs "Block Jacobi"
		} elseif {[string compare "-sub_pc_bs_diag" [lindex $aline 0]] == 0} {
			set sub_pc_bs "Diagonal"
# sles options
		} elseif {[string compare "-sles_view" [lindex $aline 0]] == 0} {
			set sles_view 1
# snes options
		} elseif {[string compare "-snes_view" [lindex $aline 0]] == 0} {
			set snes_view 1
		} elseif {[string compare "-snes_type" [lindex $aline 0]] == 0} {
			set type [lindex $aline 1]
			if {![string compare "ls" $type]} {
				set snes_type "Line Search"
			} elseif {![string compare "tr" $type]} {	
				set snes_type "Trust Region"
			} elseif {![string compare "test" $type]} {
				set snes_type "Test"
			}
		} elseif {[string compare "-snes_max_it" [lindex $aline 0]] == 0} {
			set snes_max_it [lindex $aline 1]
		} elseif {[string compare "-snes_max_funcs" [lindex $aline 0]] == 0} {
			set snes_max_funcs [lindex $aline 1]
		} elseif {[string compare "-snes_stol" [lindex $aline 0]] == 0} {
			set snes_stol [lindex $aline 1]
		} elseif {[string compare "-snes_atol" [lindex $aline 0]] == 0} {
			set snes_atol [lindex $aline 1]
		} elseif {[string compare "-snes_rtol" [lindex $aline 0]] == 0} {
			set snes_rtol [lindex $aline 1]
		} elseif {[string compare "-snes_ttol" [lindex $aline 0]] == 0} {
			set snes_ttol [lindex $aline 1]
		} elseif {[string compare "-snes_monitor" [lindex $aline 0]] == 0} {
		 	set snes_monitor 1
		} elseif {[string compare "-snes_xmonitor" [lindex $aline 0]] == 0} {
			set snes_xmonitor(switch) 1
			if {[llength $aline] == 2} {
				set configuration [split [lindex $aline 1] ,]
				set snes_xmonitor(x) [lindex $configuration 0]
				set snes_xmonitor(y) [lindex $configuration 1]
				set snes_xmonitor(w) [lindex $configuration 2]
				set snes_xmonitor(h) [lindex $configuration 3]
			}
		} elseif {[string compare "-snes_fd" [lindex $aline 0]] == 0} {
			set snes_fd 1 ; set snes_mf 0 
		} elseif {[string compare "-snes_mf" [lindex $aline 0]] == 0} {
			set snes_mf 1 ; set snes_fd 0
		} elseif {[string compare "-snes_line_search" [lindex $aline 0]] == 0} {
			set type [lindex $aline 1]
			if {![string compare "basic" $type]} {
				set snes_line_search "Basic"
			} elseif {![string compare "quadratic" $type]} {
				set snes_line_search "Quadratic"
			} elseif {![string compare "cubic" $type]} {	
				set snes_line_search "Cubic"
			}
		} elseif {[string compare "-snes_line_search_alpha" [lindex $aline 0]]\
			== 0} {
			set snes_line_search_alpha [lindex $aline 1]
		} elseif {[string compare "-snes_line_search_maxstep" [lindex $aline 0]]\
			== 0} {
			set snes_line_search_maxstep [lindex $aline 1]
		} elseif {[string compare "-snes_line_search_steptol" [lindex $aline 0]]\
			== 0} {
			set snes_line_search_steptol [lindex $aline 1]
# graphics options
		} elseif {[string compare "-pause" [lindex $aline 0]] == 0} {
			set pause [lindex $aline 1]
		} elseif {[string compare "-nox" [lindex $aline 0]] == 0} {
			set nox 1
		}
	}
	close $fd
	set filename $file
	wm title . "PETSc Options - $filename"
	Display_PC_Specific_Options .pcopts.2.specopts
 	Display_KSP_Specific_Options .kspopts.3.specopts
	Display_SNES_Specific_Options
}
proc Write_PETSc_Options {file} {
	global filename
# general options
	global help version on_error_attach_debugger
	global start_in_debugger debugger_type display
	global no_signal_handler fp_trap trdump trmalloc
        global trinfo trdebug on_error_abort info log_history
        global log_mpe mpelogfile
	global optionstable optionsleft log log_all logfile log_summary
# preconditioner options
	global pc_type pc_sor_omega pc_sor_its pc_sor pc_lu_in_place
	global pc_lu_ordering pc_ilu_ordering pc_ilu_levels pc_bjacobi_blocks
        global pc_bjacobi_truelocal pc_ilu_in_place pc_ilu_factorpointwise
	global pc_bs_max_it pc_bs_blocksize pc_bs_rtol pc_bs
# ksp options
   global ksp_type ksp_max_it ksp_rtol ksp_atol ksp_divtol 
   global ksp_preres ksp_right_pc ksp_eigen 
	global ksp_monitor ksp_xmonitor ksp_gmres_restart
	global ksp_gmres_unmodifiedgrammschmidt
# sub preconditioner options
	global sub_pc_type sub_pc_sor_omega sub_pc_sor_its sub_pc_sor
	global sub_pc_lu_in_place sub_pc_lu_ordering sub_pc_ilu_ordering 
	global sub_pc_ilu_levels sub_pc_bs_max_it sub_pc_ilu_in_place 
        global sub_pc_ilu_factorpointwise
	global sub_pc_bs_blocksize sub_pc_bs_rtol sub_pc_bs
# sub ksp options
   global sub_ksp_type sub_ksp_max_it sub_ksp_rtol sub_ksp_atol 
	global sub_ksp_divtol sub_ksp_preres sub_ksp_right_pc sub_ksp_eigen 
	global sub_ksp_monitor sub_ksp_xmonitor sub_ksp_gmres_restart
	global sub_ksp_gmres_unmodifiedgrammschmidt
# sles options
	global sles_view
# snes options 
	global snes_view snes_type snes_max_it snes_max_funcs snes_stol snes_atol
	global snes_rtol snes_ttol snes_monitor snes_xmonitor 
	global snes_fd snes_mf snes_line_search snes_line_search_alpha
	global snes_line_search_maxstep snes_line_search_steptol
# graphics options
	global pause nox

	if {[string compare $file $filename] && [file isfile $file]} {
		set button [Dialog .fileexists "File Exists" "File \"$file\" aready exists.  Are you sure that you want to overwrite it?" warning.bit 0 "Overwrite" "Don't Overwrite"]
		if {$button == 1} {
			return
		}
	}

	set fd [open $file w]

# general options
	if {$help == 1} {puts $fd "-help"} 
	if {$version == 1} {puts $fd "-version"} 
	if {$on_error_attach_debugger == 1} {
		puts $fd "-on_error_attach_debugger $debugger_type"
	} 
	if {$start_in_debugger == 1} {
		puts $fd "-start_in_debugger $debugger_type"
	}
        if {$on_error_abort == 1} {puts $fd "-on_error_abort"} 
	if {[string compare $display ":0.0"]} {puts $fd "-display $display"}
	if {$no_signal_handler == 1} {puts $fd "-no_signal_handler"} 
	if {$fp_trap == 1} {puts $fd "-fp_trap"} 
	if {$trdump == 1} {puts $fd "-trdump"} 
	if {$trmalloc == 1} {puts $fd "-trmalloc"} 
        if {$trinfo == 1} {puts $fd "-trinfo"}
        if {$trdebug == 1} {puts $fd "-trdebug"}
	if {$trmalloc == 0} {puts $fd "-notrmalloc"} 
	if {$optionstable == 1} {puts $fd "-optionstable"} 	
	if {$optionsleft == 1} {puts $fd "-optionsleft"} 
	if {$log == 1} {
		if {[string compare $logfile "Log"]} {
			puts $fd "-log $logfile"
		} else {
			puts $fd "-log"
		}
	} 
	if {$log_all == 1} {
		if {[string compare $logfile "Log"]} {
			puts $fd "-log_all $logfile"
		} else {
			puts $fd "-log_all"
		} 
	}
	if {$log_summary == 1} {puts $fd "-log_summary"}
	if {$info == 1} {puts $fd "-info"}
	if {$log_history == 1} {puts $fd "-log_history"}
 	if {$log_mpe == 1} {
		if {[string compare $mpelogfile "mpe.log"]} {
			puts $fd "-log_mpe $mpelogfile"
		} else {
			puts $fd "-log_mpe"
		} 
	}  

# preconditioner options
	if {![string compare "Jacobi" $pc_type]} {
		puts $fd "-pc_type jacobi"
	} elseif {![string compare "SOR" $pc_type]} {
		puts $fd "-pc_type sor"
		if {$pc_sor_omega != 1.0} {puts $fd "-pc_sor_omega $pc_sor_omega"}
		if {$pc_sor_its != 1} {puts $fd "-pc_sor_its $pc_sor_its"}
		if {![string compare "Backward" $pc_sor]} {
			puts $fd "-pc_sor_backward"
		} elseif {![string compare "Symmetric" $pc_sor]} {
			puts $fd "-pc_sor_symmetric"
		} elseif {![string compare "Local forward" $pc_sor]} {
			puts $fd "-pc_sor_local_forward"
		} elseif {![string compare "Local backward" $pc_sor]} {
			puts $fd "-pc_sor_local_backward"
		} elseif {![string compare "Local symmetric" $pc_sor]} {
			puts $fd "-pc_sor_local_symmetric"
		}
	} elseif {![string compare "Block Jacobi" $pc_type]} {
		puts $fd "-pc_type bjacobi"
		if {$pc_bjacobi_blocks != 0} {
			puts $fd "-pc_bjacobi_blocks $pc_bjacobi_blocks"
		}
                if {$pc_bjacobi_truelocal != 0} {
			puts $fd "-pc_bjacobi_truelocal"
		} 

	} elseif {![string compare "LU" $pc_type]} {
		puts $fd "-pc_type lu"
		if {$pc_lu_in_place == 1} {
			puts $fd "-pc_lu_in_place"
		}
		if {![string compare "Natural" $pc_lu_ordering]} {
			puts $fd "-pc_lu_ordering natural"
		} elseif {![string compare "Nested Dissection" $pc_lu_ordering]} {
			puts $fd "-pc_lu_ordering nd"
		} elseif {![string compare "One-way Dissection" $pc_lu_ordering]} {
			puts $fd "-pc_lu_ordering 1wd"
		} elseif {![string compare "Reverse Cuthill-McGee" $pc_lu_ordering]} {
			puts $fd "-pc_lu_ordering rcm"
		} elseif {![string compare "Quotient Minimum Degree" $pc_lu_ordering]} {
			puts $fd "-pc_lu_ordering qmd"
		}
	} elseif {![string compare "ILU" $pc_type]} {
		puts $fd "-pc_type ilu"
		if {$pc_ilu_levels != 0} {
			puts $fd "-pc_ilu_levels $pc_ilu_levels"
		}
                if {$pc_ilu_in_place != 0} {
                    puts $fd "-pc_ilu_in_place" 
                }
                if {$pc_ilu_factorpointwise!= 0} {
                    puts $fd "-pc_ilu_factorpointwise"
                }
                if {![string compare "Natural" $pc_ilu_ordering]} {
			puts $fd "-pc_ilu_ordering natural"
		} elseif {![string compare "Nested Dissection" $pc_ilu_ordering]} {
			puts $fd "-pc_ilu_ordering nd"
		} elseif {![string compare "One-way Dissection" $pc_ilu_ordering]} {
			puts $fd "-pc_ilu_ordering 1wd"
		} elseif {![string compare "Reverse Cuthill-McGee" $pc_ilu_ordering]} {
			puts $fd "-pc_ilu_ordering rcm"
		} elseif {![string compare "Quotient Minimum Degree" $pc_ilu_ordering]} {
			puts $fd "-pc_ilu_ordering qmd"
		}
	} elseif {![string compare "ICC" $pc_type]} {
		puts $fd "-pc_type icc"
		if {$pc_bs_max_it != 10000} {puts $fd "-pc_bs_max_it $pc_bs_max_it"}
		if {$pc_bs_blocksize != 1} {
			puts $fd "-pc_bs_blocksize $pc_ps_blocksize"
		} 
		if {$pc_bs_rtol != 1.e-5} {puts $fd "-pc_bs_rtol $pc_bs_rtol"}
		if {![string compare "SSOR" $pc_bs]} {
			puts $fd "-pc_bs_ssor"
		} elseif {![string compare "Block Jacobi" $pc_bs]} {
			puts $fd "-pc_bs_bjacobi"
		} elseif {![string compare "Diagonal" $pc_bs]} {
			puts $fd "-pc_bs_diag"
		}
	} elseif {![string compare "BGS" $pc_type]} {

	} elseif {![string compare "ASM" $pc_type]} {

	} elseif {![string compare "Shell" $pc_type]} {
		puts $fd "-pc_type shell"
	} elseif {![string compare "None" $pc_type]} {
		puts $fd "-pc_type none"
	}
	
# ksp options
 	if {![string compare "Richardson" $ksp_type]} {
		puts $fd "-ksp_type richardson"
	} elseif {![string compare "Chebychev" $ksp_type]} {
		puts $fd "-ksp_type chebychev"
	} elseif {![string compare "CG" $ksp_type]} {
		puts $fd "-ksp_type cg"
	} elseif {![string compare "GMRES" $ksp_type]} {
		puts $fd "-ksp_type gmres"
		if {$ksp_gmres_restart != 30} {
			puts $fd "-ksp_gmres_restart $ksp_gmres_restart"
		}
		if {$ksp_gmres_unmodifiedgrammschmidt == 1} {
			puts $fd "-ksp_gmres_unmodifiedgrammschmidt"
		}
	} elseif {![string compare "Bi-CG-stab" $ksp_type]} {
		puts $fd "-ksp_type bcgs"
	} elseif {![string compare "TFQMR" $ksp_type]} {
		puts $fd "-ksp_type tfqmr"
	} elseif {![string compare "TCQMR" $ksp_type]} {
		puts $fd "-ksp_type tcqmr"
	} elseif {![string compare "CGS" $ksp_type]} {
		puts $fd "-ksp_type cgs"
	} elseif {![string compare "CR" $ksp_type]} {
		puts $fd "-ksp_type cr"
	} elseif {![string compare "Least Squares" $ksp_type]} {
		puts $fd "-ksp_type lsqr"
	} elseif {![string compare "Precond. Only" $ksp_type]} {
		puts $fd "-ksp_type preonly"
	}
	if {$ksp_max_it != 10000} {puts $fd "-ksp_max_it $ksp_max_it"}
	if {$ksp_rtol != 1.e-5} {puts $fd "-ksp_rtol $ksp_rtol"}
	if {$ksp_atol != 1.e-50} {puts $fd "-ksp_atol $ksp_atol"}
	if {$ksp_divtol != 1.e4} {puts $fd "-ksp_divtol $ksp_divtol"}
	if {$ksp_preres == 1} {puts $fd "-ksp_preres"}
	if {$ksp_right_pc == 1} {puts $fd "-ksp_right_pc"}
	if {$ksp_eigen == 1} {puts $fd "-ksp_eigen"}
	if {$ksp_monitor == 1} {puts $fd "-ksp_monitor"}
	if {$ksp_xmonitor(switch) == 1} {
		puts $fd "-ksp_xmonitor $ksp_xmonitor(x),$ksp_xmonitor(y),$ksp_xmonitor(w),$ksp_xmonitor(h)"
	}

# sub preconditioner options
	if {![string compare "Jacobi" $sub_pc_type]} {
		puts $fd "-sub_pc_type jacobi"
	} elseif {![string compare "SOR" $sub_pc_type]} {
		puts $fd "-sub_pc_type sor"
		if {$sub_pc_sor_omega != 1.0} {
			puts $fd "-sub_pc_sor_omega $sub_pc_sor_omega"
		}
		if {$sub_pc_sor_its != 1} {puts $fd "-sub_pc_sor_its $sub_pc_sor_its"}
		if {![string compare "Backward" $sub_pc_sor]} {
			puts $fd "-sub_pc_sor_backward"
		} elseif {![string compare "Symmetric" $sub_pc_sor]} {
			puts $fd "-sub_pc_sor_symmetric"
		} elseif {![string compare "Local forward" $sub_pc_sor]} {
			puts $fd "-sub_pc_sor_local_forward"
		} elseif {![string compare "Local backward" $sub_pc_sor]} {
			puts $fd "-sub_pc_sor_local_backward"
		} elseif {![string compare "Local symmetric" $sub_pc_sor]} {
			puts $fd "-sub_pc_sor_local_symmetric"
		}
	} elseif {![string compare "LU" $sub_pc_type]} {
		puts $fd "-sub_pc_type lu"
		if {$sub_pc_lu_in_place == 1} {
			puts $fd "-sub_pc_lu_in_place"
		}
		if {![string compare "Natural" $sub_pc_lu_ordering]} {
			puts $fd "-sub_pc_lu_ordering natural"
		} elseif {![string compare "Nested Dissection" $sub_pc_lu_ordering]} {
			puts $fd "-sub_pc_lu_ordering nd"
		} elseif {![string compare "One-way Dissection" $sub_pc_lu_ordering]} {
			puts $fd "-sub_pc_lu_ordering 1wd"
		} elseif {![string compare "Reverse Cuthill-McGee" $sub_pc_lu_ordering]}\
			{
			puts $fd "-sub_pc_lu_ordering rcm"
		} elseif {![string compare "Quotient Minimum Degree" \
			$sub_pc_lu_ordering]} {
			puts $fd "-sub_pc_lu_ordering qmd"
		}
	} elseif {![string compare "ILU" $sub_pc_type]} {
		puts $fd "-sub_pc_type ilu"
		if {$sub_pc_ilu_levels != 0} {
			puts $fd "-sub_pc_ilu_levels $sub_pc_ilu_levels"
		}
                if {$sub_pc_ilu_in_place != 0} {
                    puts $fd "-sub_pc_ilu_in_place" 
                }
                if {$sub_pc_ilu_factorpointwise!= 0} {
                    puts $fd "-sub_pc_ilu_factorpointwise"
                }
		if {![string compare "Natural" $sub_pc_ilu_ordering]} {
			puts $fd "-sub_pc_ilu_ordering natural"
		} elseif {![string compare "Nested Dissection" $sub_pc_ilu_ordering]} {
			puts $fd "-sub_pc_ilu_ordering nd"
		} elseif {![string compare "One-way Dissection" $sub_pc_ilu_ordering]} {
			puts $fd "-sub_pc_ilu_ordering 1wd"
		} elseif {![string compare "Reverse Cuthill-McGee" \
			$sub_pc_ilu_ordering]} {
			puts $fd "-sub_pc_ilu_ordering rcm"
		} elseif {![string compare "Quotient Minimum Degree" \
			$sub_pc_ilu_ordering]} {
			puts $fd "-sub_pc_ilu_ordering qmd"
		}
	} elseif {![string compare "ICC" $sub_pc_type]} {
		puts $fd "-sub_pc_type icc"
		if {$sub_pc_bs_max_it != 10000} {
			puts $fd "-sub_pc_bs_max_it $sub_pc_bs_max_it"
		}
		if {$sub_pc_bs_blocksize != 1} {
			puts $fd "-sub_pc_bs_blocksize $sub_pc_bs_blocksize"
		} 
		if {$sub_pc_bs_rtol != 1.e-5} {
			puts $fd "-sub_pc_bs_rtol $sub_pc_bs_rtol"
		}
		if {![string compare "SSOR" $sub_pc_bs]} {
			puts $fd "-sub_pc_bs_ssor"
		} elseif {![string compare "Diagonal" $sub_pc_bs]} {
			puts $fd "-sub_pc_bs_diag"
		} elseif {![string compare "Block Jacobi" $sub_pc_bs]} {
			puts $fd "-sub_pc_bs_bjacobi"
		}
	} elseif {![string compare "Shell" $sub_pc_type]} {
		puts $fd "-sub_pc_type shell"
	} elseif {![string compare "None" $sub_pc_type]} {
		puts $fd "-sub_pc_type none"
	}
	
# sub ksp options
 	if {![string compare "Richardson" $sub_ksp_type]} {
		puts $fd "-sub_ksp_type richardson"
	} elseif {![string compare "Chebychev" $sub_ksp_type]} {
		puts $fd "-sub_ksp_type chebychev"
	} elseif {![string compare "CG" $sub_ksp_type]} {
		puts $fd "-sub_ksp_type cg"
	} elseif {![string compare "GMRES" $sub_ksp_type]} {
		puts $fd "-sub_ksp_type gmres"
		if {$sub_ksp_gmres_restart != 30} {
			puts $fd "-sub_ksp_gmres_restart $sub_ksp_gmres_restart"
		}
		if {$sub_ksp_gmres_unmodifiedgrammschmidt == 1} {
			puts $fd "-sub_ksp_gmres_unmodifiedgrammschmidt"
		}
	} elseif {![string compare "Bi-CG-stab" $sub_ksp_type]} {
		puts $fd "-sub_ksp_type bcgs"
	} elseif {![string compare "TFQMR" $sub_ksp_type]} {
		puts $fd "-sub_ksp_type tfqmr"
	} elseif {![string compare "TCQMR" $sub_ksp_type]} {
		puts $fd "-sub_ksp_type tcqmr"
	} elseif {![string compare "CGS" $sub_ksp_type]} {
		puts $fd "-sub_ksp_type cgs"
	} elseif {![string compare "CR" $sub_ksp_type]} {
		puts $fd "-sub_ksp_type cr"
	} elseif {![string compare "Least Squares" $sub_ksp_type]} {
		puts $fd "-sub_ksp_type lsqr"
	} elseif {![string compare "Precond. Only" $sub_ksp_type]} {
		puts $fd "-sub_ksp_type preonly"
	}
	if {$sub_ksp_max_it != 10000} {
		puts $fd "-sub_ksp_max_it $sub_ksp_max_it"
	}
	if {$sub_ksp_rtol != 1.e-5} {puts $fd "-sub_ksp_rtol $sub_ksp_rtol"}
	if {$sub_ksp_atol != 1.e-50} {puts $fd "-sub_ksp_atol $sub_ksp_atol"}
	if {$sub_ksp_divtol != 1.e4} {puts $fd "-sub_ksp_divtol $sub_ksp_divtol"}
	if {$sub_ksp_preres == 1} {puts $fd "-sub_ksp_preres"}
	if {$sub_ksp_right_pc == 1} {puts $fd "-sub_ksp_right_pc"}
	if {$sub_ksp_eigen == 1} {puts $fd "-sub_ksp_eigen"}
	if {$sub_ksp_monitor == 1} {puts $fd "-sub_ksp_monitor"}
	if {$sub_ksp_xmonitor(switch) == 1} {
		puts $fd "-sub_ksp_xmonitor $sub_ksp_xmonitor(x),$sub_ksp_xmonitor(y),$sub_ksp_xmonitor(w),$sub_ksp_xmonitor(h)"
	}

# sles options
	if {$sles_view == 1} {puts $fd "-sles_view"}

# snes options
	if {$snes_view == 1} {puts $fd "-snes_view"}
	if {![string compare "Line Search" $snes_type]} {
		puts $fd "-snes_type ls"
		if {![string compare "Basic" $snes_line_search]} {
			puts $fd "-snes_line_search basic"
		} elseif {![string compare "Quadratic" $snes_line_search]} {
			puts $fd "-snes_line_search quadratic"
		} elseif {![string compare "Cubic" $snes_line_search]} {
			puts $fd "-snes_line_search cubic
		}
		if {$snes_line_search_alpha != 1.e-4} {	
			puts $fd "-snes_line_search_alpha $snes_line_search_alpha"
		}
		if {$snes_line_search_maxstep != 1.e8} {
			puts $fd "-snes_line_search_maxstep $snes_line_search_maxstep"
		}
		if {$snes_line_search_steptol != 1.e-12} {
			puts $fd "-snes_line_search_steptol $snes_line_search_steptol"
		}
	} elseif {![string compare "Trust Region" $snes_type]} {
		puts $fd "-snes_type tr"
	 } elseif {![string compare "Test" $snes_type]} {
		puts $fd "-snes_type test
	}
	if {$snes_max_it != 50} {puts $fd "-snes_max_it $snes_max_it"}
	if {$snes_max_funcs != 1000} {puts $fd "-snes_max_funcs $snes_max_funcs"}
	if {$snes_stol != 1.e-8} {puts $fd "-snes_stol $snes_stol"}
	if {$snes_atol != 1.e-50} {puts $fd "-snes_atol $snes_atol"}
	if {$snes_rtol != 1.e-8} {puts $fd "-snes_rtol $snes_rtol"}
	if {$snes_ttol != 1.e-12} {puts $fd "-snes_ttol $snes_ttol"}
	if {$snes_monitor == 1} {puts $fd "-snes_monitor"}
	if {$snes_xmonitor(switch) == 1} {
		puts $fd "-snes_xmonitor $snes_xmonitor(x),$snes_xmonitor(y),$snes_xmonitor(w),$snes_xmonitor(h)"
	}
	if {$snes_fd == 1} {puts $fd "-snes_fd"}
	if {$snes_mf == 1} {puts $fd "-snes_mf"}
	

# graphics
	if {$nox == 1} {puts $fd "-nox"}
	if {$pause != 0} {puts $fd "-pause $pause"}

	close $fd
	set filename $file
	wm title . "PETSc Options - $filename"
}
proc PETSc_Defaults {} {
	global env
# general options
	global help version on_error_attach_debugger
	global start_in_debugger debugger_type display
	global no_signal_handler fp_trap trdump trmalloc
        global trinfo trdebug on_error_abort info log_history
        global log_mpe mpelogfile
	global optionstable optionsleft log log_all logfile log_summary
# preconditioner options
	global pc_type pc_sor_omega pc_sor_its pc_sor pc_lu_in_place
	global pc_lu_ordering pc_ilu_ordering pc_ilu_levels pc_bjacobi_blocks
        global pc_bjacobi_truelocal pc_ilu_in_place pc_ilu_factorpointwise
	global pc_bs_max_it pc_bs_blocksize pc_bs_rtol pc_bs
# ksp options
   global ksp_type ksp_max_it ksp_rtol ksp_atol ksp_divtol 
   global ksp_preres ksp_right_pc ksp_eigen 
	global ksp_monitor ksp_xmonitor ksp_gmres_restart
	global ksp_gmres_unmodifiedgrammschmidt
# sub preconditioner options
	global sub_pc_type sub_pc_sor_omega sub_pc_sor_its sub_pc_sor
	global sub_pc_lu_in_place sub_pc_lu_ordering sub_pc_ilu_ordering 
	global sub_pc_ilu_levels sub_pc_bs_max_it 
        global sub_pc_ilu_in_place sub_pc_ilu_factorpointwise
	global sub_pc_bs_blocksize sub_pc_bs_rtol sub_pc_bs
# sub ksp options
   global sub_ksp_type sub_ksp_max_it sub_ksp_rtol sub_ksp_atol 
	global sub_ksp_divtol sub_ksp_preres sub_ksp_right_pc sub_ksp_eigen 
	global sub_ksp_monitor sub_ksp_xmonitor sub_ksp_gmres_restart
	global sub_ksp_gmres_unmodifiedgrammschmidt
# sles options
	global sles_view
# snes options 
	global snes_view snes_type snes_max_it snes_max_funcs snes_stol snes_atol
	global snes_rtol snes_ttol snes_monitor snes_xmonitor 
	global snes_fd snes_mf snes_line_search snes_line_search_alpha
	global snes_line_search_maxstep snes_line_search_steptol
# graphics options
	global pause nox

# general options
	set help 0
	set version 0
	set on_error_attach_debugger 0
        set on_error_abort 0
	set start_in_debugger 0
	set debugger_type "gdb"
	set display ":0.0"
	set no_signal_handler 0
	set fp_trap 0
	set trdump 0
	set trmalloc 0
        set trinfo 0
        set trdebug 0
	set optionstable 0
	set optionsleft 0
	set log 0
	set log_all 0
	set logfile Log
        set info 0
        set log_history 0
        set log_mpe 0
        set mpelogfile mpe.log
	set log_summary 0

# preconditioner options
	set pc_type "Default"
	
	set pc_sor_omega 1.0
	set pc_sor_its 1
	set pc_sor "Default"
	
	set pc_lu_in_place 0
	set pc_lu_ordering "Default"
	
	set pc_ilu_ordering "Default"
	set pc_ilu_levels 0
	set pc_ilu_in_place 0
	set pc_ilu_factorpointwise 0
    
	
	set pc_bjacobi_blocks 0
	set pc_bjacobi_truelocal 0

	set pc_bs_max_it 10000
	set pc_bs_blocksize 1
	set pc_bs_rtol 1.e-5
	set pc_bs "None"

# ksp options
	set ksp_type "Default"
	set ksp_preres 0
	set ksp_right_pc 0
	set ksp_eigen 0
	set ksp_max_it 10000
	set ksp_rtol 1.e-5
	set ksp_atol 1.e-50
	set ksp_divtol 1.e4
	set ksp_monitor 0
	set ksp_xmonitor(switch) 0
	set ksp_xmonitor(x) 0
	set ksp_xmonitor(y) 0
	set ksp_xmonitor(w) 300
	set ksp_xmonitor(h) 300
	set ksp_gmres_restart 30 
	set ksp_gmres_unmodifiedgrammschmidt 0
	
# sub preconditioner options
	set sub_pc_type "Default"
	set sub_pc_sor_omega 1.0
	set sub_pc_sor_its 1
	set sub_pc_sor "Default"
	set sub_pc_lu_in_place 0
	set sub_pc_lu_ordering "Default"
	set sub_pc_ilu_ordering "Default"
	set sub_pc_ilu_levels 0
	set sub_pc_ilu_in_place 0
	set sub_pc_ilu_factor_pointwise 0
	set sub_pc_bs_max_it 10000
	set sub_pc_bs_blocksize 1
	set sub_pc_bs_rtol 1.e-5
	set sub_pc_bs "None"
# sub ksp options
	set sub_ksp_type "Default"
	set sub_ksp_preres 0
	set sub_ksp_right_pc 0
	set sub_ksp_eigen 0
	set sub_ksp_max_it 10000
	set sub_ksp_rtol 1.e-5
	set sub_ksp_atol 1.e-50
	set sub_ksp_divtol 1.e4
	set sub_ksp_monitor 0
	set sub_ksp_xmonitor(switch) 0
	set sub_ksp_xmonitor(x) 0
	set sub_ksp_xmonitor(y) 0
	set sub_ksp_xmonitor(w) 300
	set sub_ksp_xmonitor(h) 300
	set sub_ksp_gmres_restart 30 
	set sub_ksp_gmres_unmodifiedgrammschmidt 0
	
# sles options
	set sles_view 0

# snes options
	set snes_view 0
	set snes_type "Default"
	set snes_max_it 50
	set snes_max_funcs 1000 
	set snes_stol 1.e-8
	set snes_ttol 1.e-12
	set snes_atol 1.e-50
	set snes_rtol 1.e-8
	set snes_monitor 0
	set snes_xmonitor(switch) 0
	set snes_xmonitor(x) 0
	set snes_xmonitor(y) 0
	set snes_xmonitor(w) 300
	set snes_xmonitor(h) 300
	set snes_fd 0
	set snes_mf 0
	set snes_line_search "Default"
	set snes_line_search_alpha 1.e-4
	set snes_line_search_maxstep 1.e8
	set snes_line_search_steptol 1.e-12
	
# graphics options
	set pause 0
	set nox 0

	Display_PC_Specific_Options .pcopts.2.specopts
 	Display_KSP_Specific_Options .kspopts.3.specopts
	Display_SNES_Specific_Options
}
##############################################################################
# Utility procedures
##############################################################################
##############################################################################
#	Procedure name: Dialog {w title text bitmap default args}
#	Author: John K. Ousterhout
#	Date:
#	Purpose:
##############################################################################
proc Dialog {w title text bitmap default args} {
	global env button

	toplevel $w -class Dialog
	wm title $w $title
	wm iconname $w Dialog

	frame $w.top -relief raised -bd 1
	pack $w.top -side top -fill both
	frame $w.bot -relief raised -bd 1
	pack $w.bot -side bottom -fill both

	message $w.top.msg -width 3i -text $text \
		-font -Adobe-Times-Medium-R-Normal-*-180-*
	pack $w.top.msg -side right -expand 1 -fill both \
		-padx 3m -pady 3m
	if {$bitmap != ""} {
		label $w.top.bitmap -bitmap @$env(PETSC_DIR)/bin/bitmaps/$bitmap
		pack $w.top.bitmap -side left -padx 3m -pady 3m
	}

	set i 0
	foreach but $args {
		button $w.bot.button$i -text $but -command\
			"set button $i"
		if {$i == $default} {
			frame $w.bot.default -relief sunken -bd 1
			raise $w.bot.button$i
			pack $w.bot.default -side left -expand 1\
				-padx 3m -pady 2m
			pack $w.bot.button$i -in $w.bot.default\
				-side left -padx 2m -pady 2m\
				-ipadx 2m -ipady 2m
		} else {
			pack $w.bot.button$i -side left -expand 1\
				-padx 3m -pady 3m -ipadx 2m -ipady 1m
		}
		incr i
	}
	
	if {$default >= 0} {
		bind $w <Return> "$w.bot.button$default flash; \
			set button $default"
	}
	set oldfocus [focus]
	focus $w
	grab set $w

	tkwait variable button
	destroy $w
	focus $oldfocus
	return $button
}  
#
# fileselect.tcl --
# simple file selector.
#
# Mario Jorge Silva			          msilva@cs.Berkeley.EDU
# University of California Berkeley                 Ph:    +1(510)642-8248
# Computer Science Division, 571 Evans Hall         Fax:   +1(510)642-5775
# Berkeley CA 94720                                 
# 
# Layout:
#
#  file:                  +----+
#  ____________________   | OK |
#                         +----+
#
#  +------------------+    Cancel
#  | ..               |S
#  | file1            |c
#  | file2            |r
#  |                  |b
#  | filen            |a
#  |                  |r
#  +------------------+
#  currrent-directory
#
# Copyright 1993 Regents of the University of California
# Permission to use, copy, modify, and distribute this
# software and its documentation for any purpose and without
# fee is hereby granted, provided that this copyright
# notice appears in all copies.  The University of California
# makes no representations about the suitability of this
# software for any purpose.  It is provided "as is" without
# express or implied warranty.
#


# names starting with "fileselect" are reserved by this module
# no other names used.

# use the "option" command for further configuration

option add *Listbox*font \
    "-*-helvetica-medium-r-normal-*-12-*-*-*-p-*-iso8859-1" startupFile
option add *Entry*font \
    "-*-helvetica-medium-r-normal-*-12-*-*-*-p-*-iso8859-1" startupFile
option add *Label*font \
    "-*-helvetica-medium-r-normal-*-12-*-*-*-p-*-iso8859-1" startupFile


# this is the default proc  called when "OK" is pressed
# to indicate yours, give it as the first arg to "fileselect"

proc fileselect.default.cmd {f} {
  	global filename

	puts stderr "selected file $f"
	return $filename
}


# this is the default proc called when error is detected
# indicate your own pro as an argument to fileselect

proc fileselect.default.errorHandler {errorMessage} {
	 Dialog .fileerror "Error" "error: $errorMessage" warning.bit 0 "OK"
    catch{ cd ~ }
}

# this is the proc that creates the file selector box

proc fileselect {cmd purpose filematch w errorHandler} {

    catch {destroy $w}

    toplevel $w
    grab set $w
    wm title $w "Select File"
    global select_format

    # path independent names for the widgets
    global fileselect

    set fileselect(entry) $w.file.eframe.entry
    set fileselect(list) $w.file.sframe.list
    set fileselect(scroll) $w.file.sframe.scroll
    set fileselect(ok) $w.bframe.okframe.ok
    set fileselect(cancel) $w.bframe.cancel
    set fileselect(dirlabel) $w.file.dirlabel

    # widgets
    frame $w.file -bd 10 
    frame $w.bframe -bd 10
    pack append $w \
        $w.bframe {right frame n} \
        $w.file {left expand fill}

    frame $w.file.eframe
    frame $w.file.sframe
    label $w.file.dirlabel -anchor e -width 24 -text [pwd] 

    pack append $w.file \
        $w.file.eframe {top frame w fillx} \
	$w.file.sframe {top fill expand} \
	$w.file.dirlabel {top frame w fillx}

    label $w.file.eframe.label -anchor w -width 24 -text $purpose
    entry $w.file.eframe.entry -relief sunken

    pack append $w.file.eframe \
		$w.file.eframe.label {top expand frame w} \
                $w.file.eframe.entry {top fillx frame w} 


    scrollbar $w.file.sframe.yscroll -relief sunken \
	 -command "$w.file.sframe.list yview"
    listbox $w.file.sframe.list -relief sunken \
	-yscroll "$w.file.sframe.yscroll set" 

    pack append $w.file.sframe \
        $w.file.sframe.yscroll {right filly} \
 	$w.file.sframe.list {left expand fill} 

    # buttons
    frame $w.bframe.okframe -borderwidth 2 -relief sunken
 
    button $w.bframe.okframe.ok -text OK -relief raised -padx 10 \
        -command "fileselect.ok.cmd $w $cmd {$filematch} $errorHandler"

    button $w.bframe.cancel -text cancel -relief raised -padx 10 \
        -command "fileselect.cancel.cmd $w"

    pack append $w.bframe.okframe $w.bframe.okframe.ok {padx 10 pady 10}

    pack append $w.bframe $w.bframe.okframe {expand padx 20 pady 20}\
                          $w.bframe.cancel {top}
	
    # Fill the listbox with a list of the files in the directory (run
    # the "/bin/ls" command to get that information).
    # to not display the "." files, remove the -a option and fileselect
    # will still work

    foreach file [lsort [eval glob -nocomplain \
	  $filematch]] {
       $fileselect(list) insert end "$file [file size $file]"
    }

    $fileselect(list) insert end "../"
    foreach directory [lsort [eval glob -nocomplain */]] {
        $fileselect(list) insert end $directory
    }
    
    update
    wm minsize $w \
	  [expr "[winfo reqwidth  $w.bframe] + [winfo reqwidth  $w.file]"] \
	  [winfo reqheight $w.bframe]


   # Set up bindings for the browser.
    bind $fileselect(entry) <Return> {eval $fileselect(ok) invoke}
    bind $fileselect(entry) <Control-c> {eval $fileselect(cancel) invoke}

    bind $w <Control-c> {eval $fileselect(cancel) invoke}
    bind $w <Return> {eval $fileselect(ok) invoke}


#    tk_listboxSingleSelect $fileselect(list)


    bind $fileselect(list) <Button-1> [format {
       # puts stderr "button 1 release"
       %%W select set [%%W nearest %%y]
       $fileselect(entry) delete 0 end
       $fileselect(entry) insert 0 [lindex [%%W get [%%W nearest %%y]] 0]
       set select_format(%s) [$fileselect(entry) get]
    } $w]

    bind $fileselect(list) <Key> {
       %W select from [%W nearest %y]
       $fileselect(entry) delete 0 end
       $fileselect(entry) insert 0 [lindex [%W get [%W nearest %y]] 0]
    }

    bind $fileselect(list) <Double-ButtonPress-1> {
       # puts stderr "double button 1"
       %W select from [%W nearest %y]
       $fileselect(entry) delete 0 end
       $fileselect(entry) insert 0 [lindex [%W get [%W nearest %y]] 0]
       $fileselect(ok) invoke
    }

    bind $fileselect(list) <Return> {
       %W select from [%W nearest %y]
       $fileselect(entry) delete 0 end
       $fileselect(entry) insert 0 [lindex [%W get [%W nearest %y]] 0]
       $fileselect(ok) invoke
    }

    # set kbd focus to entry widget
    focus $fileselect(entry)
	 tkwait window $w
}


# auxiliary button procedures

proc fileselect.cancel.cmd {w} {
   # puts stderr "Cancel"
   destroy $w
}

proc fileselect.ok.cmd {w cmd filematch errorHandler} {
    global fileselect filename

    set selected [$fileselect(entry) get]

    # some nasty file names may cause "file isdirectory" to return an error
    set sts [catch { 
	file isdirectory $selected
    }  errorMessage ]

    if { $sts != 0 } then {
	$errorHandler $errorMessage
	destroy $w
	return

    }

    # clean the text entry and prepare the list
    $fileselect(entry) delete 0 end
    $fileselect(list) delete 0 end


    if {[string length $selected] && [file isdirectory $selected] != 0} {
       cd $selected
       set dir [pwd]
       $fileselect(dirlabel) configure -text $dir

       foreach file [lsort [eval glob -nocomplain $filematch]] {
	  $fileselect(list) insert end "$file [file size $file]"
       }

       $fileselect(list) insert end "../"
       foreach directory [lsort [glob -nocomplain */]] {
	  $fileselect(list) insert end $directory
       }
       return
    }
    destroy $w
	 $cmd $selected
}
##############################################################################
#
##############################################################################

Display_General_Options
Display_PC_Options 
Display_KSP_Options 
Display_SLES_Options 
Display_SNES_Options
Display_Graphics_Options

PETSc_Defaults

if {$argc >= 1} {
	if {([file exists [lindex $argv 0]]} {
			Read_PETSc_Options [lindex $argv 0]
	}
} else {
	if {[file exists $env(HOME)/.petscrc]} {
		Read_PETSc_Options $env(HOME)/.petscrc
		catch {exec cp $env(HOME)/.petscrc $env(HOME)/.petscrcbak}
	} else {		
		set filename $env(HOME)/.petscrc
	}
}



proc PV_Introduction {} {
  global petsc_dir
  toplevel .txtdemo
  wm title .txtdemo "PETScOpts Introduction"
#  wm geometry .txtdemo 355x500+0+0

  text .txtdemo.scrn -wrap word -width 45 -height 20 -padx 5m\
     -yscrollcommand ".txtdemo.scroll set"\
     -font *-times-medium-r-normal--*-140-*-*-*-*-*-*
#  text .txtdemo.scrn -wrap word -width 55 -height 63 -padx 5m\
#     -yscrollcommand ".txtdemo.scroll set"\
#     -font *-times-medium-r-normal--*-140-*-*-*-*-*-*
  scrollbar .txtdemo.scroll -command ".txtdemo.scrn yview"
  pack .txtdemo.scroll -side right -fill y
  pack .txtdemo.scrn

  frame .txtdemo.mbar -relief raised -bd 2
  pack .txtdemo.mbar -side top -fill x -expand 1
  button .txtdemo.mbar.exit -text "Exit" -command {destroy .txtdemo; return}
  pack .txtdemo.mbar.exit -side left

  proc loadFile file {
        .txtdemo.scrn delete 1.0 end
        set f [open $file]
        while {![eof $f]} {
                .txtdemo.scrn insert end [read $f 1000]
        }
        close $f
  }
  loadFile $petsc_dir/bin/petscoptsinfo.text

  proc forAllMatches {w pattern script} {
     scan [$w index end] %d numLines
     for {set i 1} {$i < $numLines} {incr i} {
         $w mark set last $i.0
         while {[regexp -indices $pattern \
              [$w get last "last lineend"] indices]} {
           $w mark set first \
              "last + [lindex $indices 0] chars"
           $w mark set last "last + 1 chars \
              + [lindex $indices 1] chars"
           uplevel $script
         }
     }
  }
        
  forAllMatches .txtdemo.scrn PETSc {
    .txtdemo.scrn tag add big first last
  }
  forAllMatches .txtdemo.scrn PETScView {
    .txtdemo.scrn tag add big first last
  }
  forAllMatches .txtdemo.scrn PETScOpts {
    .txtdemo.scrn tag add big first last
  }
  forAllMatches .txtdemo.scrn http://www.mcs.anl.gov/petsc/petsc.html {
    .txtdemo.scrn tag add big first last
  }
  forAllMatches .txtdemo.scrn Example {
    .txtdemo.scrn tag add big first last
  }
  forAllMatches .txtdemo.scrn {Performance Statistics} {
    .txtdemo.scrn tag add big first last
  }
  .txtdemo.scrn tag configure big \
     -font *-times-bold-r-normal--*-140-*-*-*-*-*-*

  .txtdemo.scrn configure -state disabled
}