proc plotControl {} {

	global Pcolours Have_BLT outRes 
	global Sheet Plotting VecCt Data X Y Vdata DataCount UserLabels

	if {!$Have_BLT} {
		puts stderr "Sorry, could not load BLT library.  Plots unavailable."
		return
	}

        set w .pCFG
	catch {destroy $w}
        toplevel $w -class Dialog
        wm title $w "Wisql BLT Plot"
        wm iconname $w "PLOTCFG"

#	Clean up from any previous launch of plotting.
	loop v 0 $VecCt {
		upvar #0 V$v V$v
		catch {vector destroy V$v}
	}
	set VecCt 0
	catch {unset Data}
	catch {unset X}
	catch {unset Y}
	catch {unset UserLabels}
	catch {unset Vdata}
	set DataCount 0

	set Plotting 1

#	set outRes 0

        frame $w.f1 -background antiquewhite

        grid columnconfigure $w.f1 0 -minsize 30
        grid columnconfigure $w.f1 1 -minsize 100
        grid columnconfigure $w.f1 2 -minsize 100
        grid columnconfigure $w.f1 3 -minsize 100
        grid columnconfigure $w.f1 4 -minsize 30
        grid columnconfigure $w.f1 5 -minsize 30
        grid columnconfigure $w.f1 6 -minsize 100

#	Labels first

        label $w.f1.lab -width 20 -justify left -text "Plot Control" \
		-background antiquewhite
        grid $w.f1.lab -row 0 -column 0 -in $w.f1 -columnspan 2
	button $w.f1.help -text Help -background lavender \
		-activebackground lavender -activeforeground magenta2 \
		-command "ezHelp wisqlPlot"
	grid $w.f1.help -row 0 -column 6 -in $w.f1

	button $w.f1.sdata -width 20 -text "Get Data from Sheet" \
		-background lavender  -activebackground lavender \
		-activeforeground magenta2 \
                -command "sheetData"
	grid $w.f1.sdata -row 0 -column 2 -in $w.f1 -columnspan 2

	label $w.f1.cnam -width 20 -text "ColumnName" -justify left \
		-background antiquewhite
	label $w.f1.vnam -width 20 -text "VectorID" -justify left \
		-background antiquewhite
	label $w.f1.unam -width 20 -text "UserLabel" -justify left \
		-background antiquewhite
	label $w.f1.bnam -width 8 -text "Assign" -justify left \
		-background antiquewhite
	label $w.f1.dnam -width 8 -text "Clear" -justify left \
		-background antiquewhite
	grid $w.f1.cnam -row 1 -column 1 -in $w.f1
	grid $w.f1.vnam -row 1 -column 2 -in $w.f1
	grid $w.f1.unam -row 1 -column 3 -in $w.f1
	grid $w.f1.bnam -row 1 -column 4 -in $w.f1
	grid $w.f1.dnam -row 1 -column 5 -in $w.f1

	label $w.f1.xl -width 3 -justify left -text "X:" \
		-background antiquewhite
	label $w.f1.xn -width 20 -justify left -text "" -relief groove \
                -background antiquewhite
	entry $w.f1.xu -width 20 -background ivory -relief sunken \
		-textvariable UserLabels(X)
	label $w.f1.xv -width 10 -justify left -text "" -relief groove \
                -background antiquewhite
	button $w.f1.xp -text V -command "pickVector X $w.f1 1" \
                -foreground black -background gray90 \
                -activebackground black -activeforeground white
	grid $w.f1.xl -row 2 -column 0 -in $w.f1 
	grid $w.f1.xn -row 2 -column 1 -in $w.f1 
	grid $w.f1.xv -row 2 -column 2 -in $w.f1 
	grid $w.f1.xu -row 2 -column 3 -in $w.f1 
	grid $w.f1.xp -row 2 -column 4 -in $w.f1 

	loop i 0 8 {
	label $w.f1.yl$i -width 3 -justify left -text "Y$i:" \
		-background antiquewhite 
	label $w.f1.yn$i -width 20 -justify left -text "" -relief groove \
		-background antiquewhite
	label $w.f1.yv$i -width 10 -justify left -text "" -relief groove \
		-background antiquewhite
	entry $w.f1.yu$i -width 20 -background ivory -relief sunken \
		-textvariable UserLabels(Y$i)
	button $w.f1.yp$i -text V -command "pickVector Y$i $w.f1 1" \
		-foreground $Pcolours($i) -background gray90 \
		-activebackground $Pcolours($i) -activeforeground black
	button $w.f1.yd$i -text c -command "pickVector Y$i $w.f1 0" \
		-foreground $Pcolours($i) -background gray90 \
		-activebackground $Pcolours($i) -activeforeground black
	grid $w.f1.yl$i -row [expr $i + 3] -column 0 -in $w.f1
	grid $w.f1.yn$i -row [expr $i + 3] -column 1 -in $w.f1
	grid $w.f1.yv$i -row [expr $i + 3] -column 2 -in $w.f1
	grid $w.f1.yu$i -row [expr $i + 3] -column 3 -in $w.f1
	grid $w.f1.yp$i -row [expr $i + 3] -column 4 -in $w.f1
	grid $w.f1.yd$i -row [expr $i + 3] -column 5 -in $w.f1
	}
	
	frame $w.f1.lb
	set font [getFont {} mediumcou]
	listbox $w.f1.lb.vecl -background ivory -width 20 \
		-yscroll "$w.f1.lb.sv set" -height 12 -font "$font"
	scrollbar $w.f1.lb.sv -relief sunken -orient vertical \
		-command "$w.f1.lb.vecl yview" -background ivory \
		-activebackground mistyrose -troughcolor bisque \
		-width 20
	bind $w.f1.lb.vecl <ButtonRelease-1> "set SelVector \[selection get\]"
	pack $w.f1.lb.vecl -side left -expand true -fill both
	pack $w.f1.lb.sv -side right -expand true -fill y
	button $w.f1.doc -text "Info" -command "infoData" \
		-background azure -activebackground azure -activeforeground orange
	button $w.f1.plt -text "Plot" -command "mkwPlot" \
		-background azure -activebackground azure -activeforeground orange
	button $w.f1.bye -text "Quit" -command "set Plotting 0; destroy $w" \
		-background white -foreground red -activebackground black \
		-activeforeground yellow
	grid $w.f1.doc -row 1 -column 6 -in $w.f1
	grid $w.f1.plt -row 2 -column 6 -in $w.f1
	grid $w.f1.lb -row 3 -column 6 -in $w.f1 -rowspan 7
#	grid $w.f1.sv -row 3 -column 6 -in $w.f1 -rowspan 2
	grid $w.f1.bye -row 10 -column 6 -in $w.f1

	pack $w.f1
}

