Index: /trunk/gui/scripts/Makefile.in
===================================================================
--- /trunk/gui/scripts/Makefile.in	(revision 1462)
+++ /trunk/gui/scripts/Makefile.in	(revision 1463)
@@ -101,4 +101,5 @@
 		$(srcdir)/tuples.tcl \
 		$(srcdir)/unirect2d.tcl \
+		$(srcdir)/unirect3d.tcl \
 		$(srcdir)/units.tcl \
 		$(srcdir)/utils.tcl \
Index: /trunk/gui/scripts/field.tcl
===================================================================
--- /trunk/gui/scripts/field.tcl	(revision 1462)
+++ /trunk/gui/scripts/field.tcl	(revision 1463)
@@ -47,4 +47,5 @@
     private variable _comp2dx    ;# maps component name => OpenDX data
     private variable _comp2unirect2d ;# maps component name => unirect2d obj
+    private variable _comp2unirect3d ;# maps component name => unirect3d obj
     private variable _comp2style ;# maps component name => style settings
     private variable _comp2cntls ;# maps component name => x,y control points
@@ -190,7 +191,9 @@
     }
     if {[info exists _comp2unirect2d($what)]} {
+	set mobj [lindex $_comp2unirect2d($what) 0]
 	return [$mobj mesh]
     }
     if {[info exists _comp2unirect3d($what)]} {
+	set mobj [lindex $_comp2unirect3d($what) 0]
 	return [$mobj mesh]
     }
@@ -222,5 +225,5 @@
     }
     if {[info exists _comp2unirect3d($what)]} {
-	return [$_comp2unirect3d($what) values]
+	return [$_comp2unirect3d($what) blob]
     }
     error "bad option \"$what\": should be [join [lsort [array names _comp2dims]] {, }]"
@@ -247,4 +250,8 @@
     if {[info exists _comp2unirect2d($what)]} {
 	set mobj $_comp2unirect2d($what)
+	return [$mobj blob]
+    }
+    if {[info exists _comp2unirect3d($what)]} {
+	set mobj $_comp2unirect3d($what)
 	return [$mobj blob]
     }
@@ -307,4 +314,8 @@
 		if {[info exists _comp2unirect2d($comp)]} {
 		    set limits [$_comp2unirect2d($comp) limits $which]
+		    foreach {vmin vmax} $limits break
+		    set axis vaxis
+		} elseif {[info exists _comp2unirect3d($comp)]} {
+		    set limits [$_comp2unirect3d($comp) limits $which]
 		    foreach {vmin vmax} $limits break
 		    set axis vaxis
@@ -528,4 +539,7 @@
     foreach name [array names _comp2unirect2d] {
 	eval itcl::delete object $_comp2unirect2d($name)
+    }
+    foreach name [array names _comp2unirect3d] {
+	eval itcl::delete object $_comp2unirect3d($name)
     }
     catch {unset _comp2xy}
@@ -625,4 +639,5 @@
 	    if {[$_xmlobj element $path] != ""} {
 		set element [$_xmlobj element -as type $path]
+		puts stderr "element is $element"
 		if { $element == "unirect2d" } {
 		    set _comp2dims($cname) "2D"
@@ -843,8 +858,15 @@
 	set max 0
 	foreach cname [$_field children -type component] {
-	    if { [info exists _comp2extents($cname)] } {
-		if { $max < $_comp2extents($cname) } {
-		    set max $_comp2extents($cname)
-		}
+	    if { [info exists _comp2unirect3d($cname)] } {
+		set value [$_comp2unirect3d($cname) components]
+	    } elseif { [info exists _comp2unirect2d($cname)] } {
+		set value [$_comp2unirect2d($cname) components]
+	    } elseif { [info exists _comp2extents($cname)] } {
+		set value $_comp2extents($cname)
+	    } else {
+		continue
+	    }
+	    if { $max < $value } {
+		set max $value
 	    }
 	}
@@ -853,5 +875,11 @@
     if { $what == "component0"} {
 	set what [lindex [components -name] 0]
-	return $_comp2extents($what)
+	if { [info exists _comp2unirect3d($what)] } {
+	    return [$_comp2unirect3d($what) components]
+	} elseif { [info exists _comp2unirect2d($what)] } {
+	    return [$_comp2unirect2d($what) components]
+	} elseif { [info exists _comp2extents($what)] } {
+	    return $_comp2extents($what)
+	}
     }
     return $_comp2extents($what)
Index: /trunk/gui/scripts/field2dresult.tcl
===================================================================
--- /trunk/gui/scripts/field2dresult.tcl	(revision 1462)
+++ /trunk/gui/scripts/field2dresult.tcl	(revision 1463)
@@ -55,14 +55,29 @@
     }
     array set flags $args
-    if { $flags(-mode) == "heightmap" } {
-	set servers [Rappture::VisViewer::GetServerList "nanovis"]
-	if { $servers == "" } {
-	    error "No nanovis servers available"
+    set servers [Rappture::VisViewer::GetServerList "nanovis"]
+    if {"" != $servers && $flags(-mode) != "vtk"} {
+	switch -- $flags(-mode) {
+	    "auto" - "heightmap" {
+		itk_component add renderer {
+		    Rappture::HeightmapViewer $itk_interior.ren $servers
+		}
+	    }
+	    "flowvis" {
+		itk_component add renderer {
+		    Rappture::FlowvisViewer $itk_interior.ren $servers
+		}
+	    }
+	    default {
+		puts stderr "unknown render mode \"$flags(-mode)\""
+	    }
+	}		
+	pack $itk_component(renderer) -expand yes -fill both
+	# can't connect to rendering farm?  then fall back to older viewer
+	if {![$itk_component(renderer) isconnected]} {
+	    destroy $itk_component(renderer)
 	}
-	itk_component add renderer {
-	    Rappture::HeightmapViewer $itk_interior.ren $servers
-	}
-	pack $itk_component(renderer) -expand yes -fill both
-    } else {
+    } 
+
+    if {![info exists itk_component(renderer)]} {
 	itk_component add renderer {
 	    Rappture::ContourResult $itk_interior.ren
Index: /trunk/gui/scripts/flowvisviewer.tcl
===================================================================
--- /trunk/gui/scripts/flowvisviewer.tcl	(revision 1462)
+++ /trunk/gui/scripts/flowvisviewer.tcl	(revision 1463)
@@ -894,5 +894,5 @@
         foreach comp [$dataobj components] {
             # Send the data as one huge base64-encoded mess -- yuck!
-            set data [$dataobj values $comp]
+            set data [$dataobj blob $comp]
             set nbytes [string length $data]
 	    set extents [$dataobj extents $comp]
Index: /trunk/gui/scripts/heightmapviewer.tcl
===================================================================
--- /trunk/gui/scripts/heightmapviewer.tcl	(revision 1462)
+++ /trunk/gui/scripts/heightmapviewer.tcl	(revision 1463)
@@ -63,4 +63,5 @@
     protected method Connect {}
     protected method Disconnect {}
+    public method isconnected {}
 
     protected method SendCmd {string}
@@ -461,4 +462,13 @@
 }
 
+#
+# isconnected --
+#
+#       Indicates if we are currently connected to the visualization server.
+#
+itcl::body Rappture::HeightmapViewer::isconnected {} {
+    return [VisViewer::IsConnected]
+}
+
 # ----------------------------------------------------------------------
 # USAGE: Connect ?<host:port>,<host:port>...?
@@ -503,5 +513,5 @@
 #       sent later.
 #
-itcl::body Rappture::NanovisViewer::SendCmd {string} {
+itcl::body Rappture::HeightmapViewer::SendCmd {string} {
     if { $_buffering } {
 	append _outbuf $string "\n"
@@ -1219,5 +1229,4 @@
 
 itcl::body Rappture::HeightmapViewer::Resize { w h } {
-    #puts stderr "w=$w h=$h" 
     SendCmd "screen $w $h"
 }
Index: /trunk/gui/scripts/resultviewer.tcl
===================================================================
--- /trunk/gui/scripts/resultviewer.tcl	(revision 1462)
+++ /trunk/gui/scripts/resultviewer.tcl	(revision 1463)
@@ -244,4 +244,8 @@
 			    set resultMode "vtk"
 			}
+			set extents [$dataobj extents]
+			if { $extents > 1 } {
+			    set resultMode "flowvis"
+			}
 			set w $itk_interior.contour
 			Rappture::Field2DResult $w -mode $resultMode
@@ -255,5 +259,5 @@
 			set fmt [expr {("" != $mesh) ? "vtk" : "nanovis"}]
 			set extents [$dataobj extents]
-			if { $extents == 3 } {
+			if { $extents > 1 } {
 			    set fmt "flowvis"
 			}
Index: /trunk/gui/scripts/unirect2d.tcl
===================================================================
--- /trunk/gui/scripts/unirect2d.tcl	(revision 1462)
+++ /trunk/gui/scripts/unirect2d.tcl	(revision 1463)
@@ -27,11 +27,19 @@
     public method values {}
     public method hints {{keyword ""}} 
-
-    private variable _xmax 0
-    private variable _xmin 0
-    private variable _xnum 0
-    private variable _ymax 0
-    private variable _ymin 0
-    private variable _ynum 0
+    public method components {} {
+	return $_components;
+    }
+    private method GetString { obj path varName }
+    private method GetValue { obj path varName }
+    private method GetSize { obj path varName }
+
+    private variable _axisOrder	 "x y"
+    private variable _xMax 0
+    private variable _xMin 0
+    private variable _xNum 0
+    private variable _yMax 0
+    private variable _yMin 0
+    private variable _yNum 0
+    private variable _components 1 
     private variable _values "";	# BLT vector containing the z-values 
     private variable _hints
@@ -47,11 +55,12 @@
     set path [$field get $cname.mesh]
 
-    set mobj [$xmlobj element -as object $path]
-    set _xmin [$mobj get "xaxis.min"]
-    set _xmax [$mobj get "xaxis.max"]
-    set _xnum [$mobj get "xaxis.numpoints"]
-    set _ymin [$mobj get "yaxis.min"]
-    set _ymax [$mobj get "yaxis.max"]
-    set _ynum [$mobj get "yaxis.numpoints"]
+    set m [$xmlobj element -as object $path]
+    GetSize $m "components" _components
+    GetValue $m "xaxis.min" _xMin
+    GetValue $m "xaxis.max" _xMax
+    GetSize $m "xaxis.numpoints" _xNum
+    GetValue $m "yaxis.min" _yMin
+    GetValue $m "yaxis.max" _yMax
+    GetSize $m "yaxis.numpoints" _yNum
     
     foreach {key path} {
@@ -74,10 +83,10 @@
 	ymax    yaxis.max
     } {
-	set str [$mobj get $path]
+	set str [$m get $path]
 	if {"" != $str} {
 	    set _hints($key) $str
 	}
     }
-    foreach {key} { extents axisorder } {
+    foreach {key} { components axisorder } {
 	set str [$field get $cname.$key]
 	if {"" != $str} {
@@ -85,5 +94,5 @@
 	}
     }
-    itcl::delete object $mobj
+    itcl::delete object $m
     
     set _values [blt::vector create \#auto]
@@ -112,8 +121,9 @@
 itcl::body Rappture::Unirect2d::blob {} {
     set data "unirect2d"
-    lappend data "xmin" $_xmin "xmax" $_xmax "xnum" $_xnum
-    lappend data "ymin" $_ymin "ymax" $_ymax "ynum" $_ynum
-    lappend data "xmin" $_xmin "ymin" $_ymin "xmax" $_xmax "ymax" $_ymax
-    foreach key { axisorder extents xunits yunits units } {
+    lappend data "xmin" $_xMin "xmax" $_xMax "xnum" $_xNum
+    lappend data "ymin" $_yMin "ymax" $_yMax "ynum" $_yNum
+    lappend data "xmin" $_xMin "ymin" $_yMin "xmax" $_xMax "ymax" $_yMax
+    lappend data "components" $_components 
+    foreach key { axisorder xunits yunits units } {
 	set hint [hints $key]
 	if { $hint != "" } {
@@ -124,5 +134,5 @@
 	lappend data "values" [$_values range 0 end]
     }
-    return [Rappture::encoding::encode -as zb64 $data]
+    return [Rappture::encoding::encode -as zb64 "$data"]
 }
 
@@ -134,10 +144,10 @@
 # ----------------------------------------------------------------------
 itcl::body Rappture::Unirect2d::mesh {} {
-    set dx [expr {($_xmax - $_xmin) / double($_xnum)}]
-    set dy [expr {($_ymax - $_ymin) / double($_ynum)}]
-    for { set i 0 } { $i < $_xnum } { incr i } {
-	set x [expr {$_xmin + (double($i) * $dx)}]
-	for { set j 0 } { $j < $_ynum } { incr j } {
-	    set y [expr {$_ymin + (double($i) * $dy)}]
+    set dx [expr {($_xMax - $_xMin) / double($_xNum)}]
+    set dy [expr {($_yMax - $_yMin) / double($_yNum)}]
+    for { set i 0 } { $i < $_xNum } { incr i } {
+	set x [expr {$_xMin + (double($i) * $dx)}]
+	for { set j 0 } { $j < $_yNum } { incr j } {
+	    set y [expr {$_yMin + (double($i) * $dy)}]
 	    lappend data $x $y
 	}
@@ -170,11 +180,11 @@
     switch -- $which {
 	x - xlin - xlog {
-	    set min $_xmin
-	    set max $_xmax
+	    set min $_xMin
+	    set max $_xMax
 	    set axis "xaxis"
 	}
 	y - ylin - ylog {
-	    set min $_ymin
-	    set max $_ymax
+	    set min $_yMin
+	    set max $_yMax
 	    set axis "yaxis"
 	}
@@ -241,2 +251,32 @@
     return [array get _hints]
 }
+
+
+itcl::body Rappture::Unirect2d::GetSize { obj path varName } {
+    set string [$obj get $path]
+    if { [scan $string "%d" value] != 1 || $value < 0 } {
+	puts stderr "can't get size \"$string\" of \"$path\""
+	return
+    }
+    upvar $varName size
+    set size $value
+}
+
+itcl::body Rappture::Unirect2d::GetValue { obj path varName } {
+    set string [$obj get $path]
+    if { [scan $string "%g" value] != 1 } {
+	return
+    }
+    upvar $varName number
+    set number $value
+}
+
+itcl::body Rappture::Unirect2d::GetString { obj path varName } {
+    set string [$obj get $path]
+    if { $string == "" } {
+	puts stderr "can't get string \"$string\" of \"$path\""
+	return
+    }
+    upvar $varName str
+    set str $string
+}
Index: /trunk/gui/scripts/unirect3d.tcl
===================================================================
--- /trunk/gui/scripts/unirect3d.tcl	(revision 1462)
+++ /trunk/gui/scripts/unirect3d.tcl	(revision 1463)
@@ -28,20 +28,24 @@
     public method hints {{keyword ""}} 
     public method order {} {
-	return _order;
-    }
-    public method dimensions {} {
-	return _dim;
-    }
-    private variable _order	 "x y z"
-    private variable _dimensions 1
-    private variable _xmax	 0
-    private variable _xmin	 0
-    private variable _xnum	 0
-    private variable _ymax	 0
-    private variable _ymin	 0
-    private variable _ynum	 0
-    private variable _zmax	 0
-    private variable _zmin	 0
-    private variable _znum	 0
+	return _axisOrder;
+    }
+    public method components {} {
+	return _components;
+    }
+    private method GetString { obj path varName }
+    private method GetValue { obj path varName }
+    private method GetSize { obj path varName }
+
+    private variable _axisOrder	 "x y z"
+    private variable _xMax	 0
+    private variable _xMin	 0
+    private variable _xNum	 0
+    private variable _yMax	 0
+    private variable _yMin	 0
+    private variable _yNum	 0
+    private variable _zMax	 0
+    private variable _zMin	 0
+    private variable _zNum	 0
+    private variable _components 1
     private variable _values	 ""; # BLT vector containing the z-values 
     private variable _hints
@@ -56,24 +60,17 @@
     }
     set path [$field get $cname.mesh]
-
-    set mobj [$xmlobj element -as object $path]
-    set order [$mobj get "axisorder"]
-    if { $order != "" } {
-	set _order $order
-    }
-    set dim [$mobj get "dimensions"]
-    if { $dim != "" } {
-	set _dimensions $dim
-    }
-    set _xmin [$mobj get "xaxis.min"]
-    set _xmax [$mobj get "xaxis.max"]
-    set _xnum [$mobj get "xaxis.numpoints"]
-    set _ymin [$mobj get "yaxis.min"]
-    set _ymax [$mobj get "yaxis.max"]
-    set _ynum [$mobj get "yaxis.numpoints"]
-    set _zmin [$mobj get "zaxis.min"]
-    set _zmax [$mobj get "zaxis.max"]
-    set _znum [$mobj get "zaxis.numpoints"]
-    itcl::delete object $mobj
+    set m [$xmlobj element -as object $path]
+    puts stderr [$m children]
+    GetValue $m "xaxis.max" _xMax
+    GetValue $m "xaxis.min" _xMin
+    GetValue $m "yaxis.max" _yMax
+    GetValue $m "yaxis.min" _yMin
+    GetValue $m "zaxis.max" _zMax
+    GetValue $m "zaxis.min" _zMin
+    GetSize $m "xaxis.numpoints" _xNum
+    GetSize $m "yaxis.numpoints" _yNum
+    GetSize $m "zaxis.numpoints" _zNum
+    GetSize $m "components" _components
+    itcl::delete object $m
 
     set _values [blt::vector create #auto]
@@ -97,14 +94,14 @@
 # ----------------------------------------------------------------------
 itcl::body Rappture::Unirect3d::blob {} {
-    set data "unirect3d"
-    lappend data "xmin" $_xmin "xmax" $_xmax "xnum" $_xnum
-    lappend data "ymin" $_ymin "ymax" $_ymax "ynum" $_ynum
-    lappend data "zmin" $_zmin "zmax" $_zmax "znum" $_znum
-    lappend data "axisorder" $_axisorder
-    lappend data "dimensions" $_dim
+    lappend data "unirect3d"
+    lappend data "xmin" $_xMin "xmax" $_xMax "xnum" $_xNum
+    lappend data "ymin" $_yMin "ymax" $_yMax "ynum" $_yNum
+    lappend data "zmin" $_zMin "zmax" $_zMax "znum" $_zNum
+    lappend data "axisorder" $_axisOrder
+    lappend data "components" $_components
     if { [$_values length] > 0 } {
 	lappend data "values" [$_values range 0 end]
     }
-    return [Rappture::encoding::encode -as zb64 $data]
+    return [Rappture::encoding::encode -as zb64 "$data"]
 }
 
@@ -116,14 +113,14 @@
 # ----------------------------------------------------------------------
 itcl::body Rappture::Unirect3d::mesh {} {
-    set dx [expr {($_xmax - $_xmin) / double($_xnum)}]
-    set dy [expr {($_ymax - $_ymin) / double($_ynum)}]
-    set dz [expr {($_zmax - $_zmin) / double($_znum)}]
-    foreach {a b c} $_axisorder break
-    for { set i 0 } { $i < [set _${a}num] } { incr i } {
-	set v1 [expr {[set _${a}min] + (double($i) * [set d${a}])}]
-	for { set j 0 } { $j < [set _${b}num] } { incr j } {
-	    set v2 [expr {[set _${b}min] + (double($i) * [set d${b}])}]
-	    for { set k 0 } { $k < [set _{$c}num] } { incr k } {
-		set v3 [expr {[set _${c}min] + (double($i) * [set d${c}])}]
+    set dx [expr {($_xMax - $_xMin) / double($_xNum)}]
+    set dy [expr {($_yMax - $_yMin) / double($_yNum)}]
+    set dz [expr {($_zMax - $_zMin) / double($_zNum)}]
+    foreach {a b c} $_axisOrder break
+    for { set i 0 } { $i < [set _${a}Num] } { incr i } {
+	set v1 [expr {[set _${a}Min] + (double($i) * [set d${a}])}]
+	for { set j 0 } { $j < [set _${b}Num] } { incr j } {
+	    set v2 [expr {[set _${b}Min] + (double($i) * [set d${b}])}]
+	    for { set k 0 } { $k < [set _${c}Num] } { incr k } {
+		set v3 [expr {[set _${c}Min] + (double($i) * [set d${c}])}]
 		lappend data $v1 $v2 $v3
 	    }
@@ -157,16 +154,16 @@
     switch -- $which {
 	x - xlin - xlog {
-	    set min $_xmin
-	    set max $_xmax
+	    set min $_xMin
+	    set max $_xMax
 	    set axis "xaxis"
 	}
 	y - ylin - ylog {
-	    set min $_ymin
-	    set max $_ymax
+	    set min $_yMin
+	    set max $_yMax
 	    set axis "yaxis"
 	}
 	z - zlin - zlog {
-	    set min $_zmin
-	    set max $_zmax
+	    set min $_zMin
+	    set max $_zMax
 	    set axis "zaxis"
 	}
@@ -216,5 +213,4 @@
 	    zunits  zaxis.units
 	    zscale  zaxis.scale
-	    dim     about.dimension 
 	    order   about.axisorder 
 	} {
@@ -250,2 +246,32 @@
     return [array get _hints]
 }
+
+itcl::body Rappture::Unirect3d::GetSize { obj path varName } {
+    set string [$obj get $path]
+    if { [scan $string "%d" value] != 1 || $value < 0 } {
+	puts stderr "can't get size \"$string\" of \"$path\""
+	return
+    }
+    upvar $varName size
+    set size $value
+}
+
+itcl::body Rappture::Unirect3d::GetValue { obj path varName } {
+    set string [$obj get $path]
+    if { [scan $string "%g" value] != 1 } {
+	puts stderr "can't get value \"$string\" of \"$path\""
+	return
+    }
+    upvar $varName number
+    set number $value
+}
+
+itcl::body Rappture::Unirect3d::GetString { obj path varName } {
+    set string [$obj get $path]
+    if { $string == "" } {
+	puts stderr "can't get string \"$string\" of \"$path\""
+	return
+    }
+    upvar $varName str
+    set str $string
+}
