Index: /branches/uq/Makefile.in
===================================================================
--- /branches/uq/Makefile.in	(revision 5028)
+++ /branches/uq/Makefile.in	(revision 5029)
@@ -40,5 +40,5 @@
 endif
 ifneq ($(ENABLE_GUI),)
-  TARGETS += gui builder tester examples 
+  TARGETS += gui builder tester examples puq
 endif
 ifneq ($(HAVE_FFMPEG),)
@@ -57,10 +57,10 @@
 	$(MAKE) -C test all
 
-install: 
+install:
 	for i in $(TARGETS) ; do \
 	  $(MAKE) -C $$i install || exit 1 ;\
 	done
 
-clean: 
+clean:
 	for i in $(TARGETS) ; do \
 	  $(MAKE) -C $$i clean || exit 1 ;\
@@ -73,8 +73,8 @@
 	done
 
-package: 
+package:
 	tar -C $(pkg_path) -czlf $(rappture_binary_tarfile) $(pkg_name)
 
-distrib: 
+distrib:
 	$(RM) -r exported
 	$(MKDIR_P) -m 0755 exported
Index: /branches/uq/configure
===================================================================
--- /branches/uq/configure	(revision 5028)
+++ /branches/uq/configure	(revision 5029)
@@ -10213,5 +10213,5 @@
 
 
-ac_config_files="$ac_config_files Makefile packages/Makefile src/Makefile src/core/Makefile src/core2/Makefile src/objects/Makefile src/objects/RpHash.h gui/Makefile gui/apps/Makefile gui/apps/about gui/apps/copy_rappture_examples gui/apps/encodedata gui/apps/rappture gui/apps/rappture-csh.env gui/apps/rappture.env gui/apps/rappture.use gui/apps/rerun gui/apps/simsim gui/apps/xmldiff gui/pkgIndex.tcl gui/scripts/Makefile gui/src/Makefile builder/Makefile builder/pkgIndex.tcl builder/scripts/Makefile tester/Makefile tester/pkgIndex.tcl tester/scripts/Makefile lang/Makefile lang/java/Makefile lang/java/rappture/Makefile lang/perl/Makefile lang/perl/Makefile.PL lang/python/Makefile lang/python/setup.py lang/matlab/Makefile lang/octave/Makefile lang/octave/octave2/Makefile lang/octave/octave3/Makefile lang/R/Makefile lang/ruby/Makefile lang/ruby/build.rb lang/tcl/Makefile lang/tcl/pkgIndex.tcl lang/tcl/scripts/Makefile lang/tcl/src/Makefile lang/tcl/tests/Makefile lib/Makefile examples/3D/Makefile examples/Makefile examples/app-fermi/2.0/Makefile examples/app-fermi/Makefile examples/app-fermi/cee/Makefile examples/app-fermi/fortran/Makefile examples/app-fermi/java/Makefile examples/app-fermi/matlab/Makefile examples/app-fermi/matlab/compiled/Makefile examples/app-fermi/matlab/uncompiled/Makefile examples/app-fermi/octave/octave2/Makefile examples/app-fermi/octave/octave3/Makefile examples/app-fermi/octave/Makefile examples/app-fermi/perl/Makefile examples/app-fermi/python/Makefile examples/app-fermi/ruby/Makefile examples/app-fermi/tcl/Makefile examples/app-fermi/wrapper/Makefile examples/app-fermi/wrapper/cee/Makefile examples/app-fermi/wrapper/perl/Makefile examples/app-fermi/wrapper/python/Makefile examples/app-fermi/wrapper/tcl/Makefile examples/app-fermi/R/Makefile examples/c-example/Makefile examples/canvas/Makefile examples/demo.bash examples/flow/Makefile examples/flow/demo1/Makefile examples/flow/demo2/Makefile examples/flow/demo3/Makefile examples/graph/Makefile examples/objects/Makefile examples/objects/axis/Makefile examples/objects/curve/Makefile examples/objects/dxWriter/Makefile examples/objects/floatBuffer/Makefile examples/objects/histogram/Makefile examples/objects/library/Makefile examples/objects/number/Makefile examples/objects/path/Makefile examples/objects/plot/Makefile examples/objects/scatter/Makefile examples/objects/string/Makefile examples/objects/tree/Makefile examples/objects/xmlparser/Makefile examples/zoo/Makefile examples/zoo/binary/Makefile examples/zoo/boolean/Makefile examples/zoo/choice/Makefile examples/zoo/curve/Makefile examples/zoo/drawing/Makefile examples/zoo/enable/Makefile examples/zoo/field/Makefile examples/zoo/group/Makefile examples/zoo/histogram/Makefile examples/zoo/image/Makefile examples/zoo/image/docs/Makefile examples/zoo/image/examples/Makefile examples/zoo/integer/Makefile examples/zoo/integer2/Makefile examples/zoo/loader/Makefile examples/zoo/loader/examples/Makefile examples/zoo/log/Makefile examples/zoo/mesh/Makefile examples/zoo/note/Makefile examples/zoo/note/docs/Makefile examples/zoo/number/Makefile examples/zoo/number2/Makefile examples/zoo/parallelepiped/Makefile examples/zoo/periodicelement/Makefile examples/zoo/phase/Makefile examples/zoo/sequence/Makefile examples/zoo/sequence/examples/Makefile examples/zoo/string/Makefile examples/zoo/structure/Makefile examples/zoo/structure/examples/Makefile examples/zoo/table/Makefile video/Makefile video/pkgIndex.tcl oldtest/Makefile oldtest/src/Makefile"
+ac_config_files="$ac_config_files Makefile packages/Makefile src/Makefile src/core/Makefile src/core2/Makefile src/objects/Makefile src/objects/RpHash.h gui/Makefile gui/apps/Makefile gui/apps/about gui/apps/copy_rappture_examples gui/apps/encodedata gui/apps/rappture gui/apps/rappture-csh.env gui/apps/rappture.env gui/apps/rappture.use gui/apps/rerun gui/apps/simsim gui/apps/xmldiff gui/pkgIndex.tcl gui/scripts/Makefile gui/src/Makefile builder/Makefile builder/pkgIndex.tcl builder/scripts/Makefile tester/Makefile tester/pkgIndex.tcl tester/scripts/Makefile lang/Makefile lang/java/Makefile lang/java/rappture/Makefile lang/perl/Makefile lang/perl/Makefile.PL lang/python/Makefile lang/python/setup.py lang/matlab/Makefile lang/octave/Makefile lang/octave/octave2/Makefile lang/octave/octave3/Makefile lang/R/Makefile lang/ruby/Makefile lang/ruby/build.rb lang/tcl/Makefile lang/tcl/pkgIndex.tcl lang/tcl/scripts/Makefile lang/tcl/src/Makefile lang/tcl/tests/Makefile lib/Makefile examples/3D/Makefile examples/Makefile examples/app-fermi/2.0/Makefile examples/app-fermi/Makefile examples/app-fermi/cee/Makefile examples/app-fermi/fortran/Makefile examples/app-fermi/java/Makefile examples/app-fermi/matlab/Makefile examples/app-fermi/matlab/compiled/Makefile examples/app-fermi/matlab/uncompiled/Makefile examples/app-fermi/octave/octave2/Makefile examples/app-fermi/octave/octave3/Makefile examples/app-fermi/octave/Makefile examples/app-fermi/perl/Makefile examples/app-fermi/python/Makefile examples/app-fermi/ruby/Makefile examples/app-fermi/tcl/Makefile examples/app-fermi/wrapper/Makefile examples/app-fermi/wrapper/cee/Makefile examples/app-fermi/wrapper/perl/Makefile examples/app-fermi/wrapper/python/Makefile examples/app-fermi/wrapper/tcl/Makefile examples/app-fermi/R/Makefile examples/c-example/Makefile examples/canvas/Makefile examples/demo.bash examples/flow/Makefile examples/flow/demo1/Makefile examples/flow/demo2/Makefile examples/flow/demo3/Makefile examples/graph/Makefile examples/objects/Makefile examples/objects/axis/Makefile examples/objects/curve/Makefile examples/objects/dxWriter/Makefile examples/objects/floatBuffer/Makefile examples/objects/histogram/Makefile examples/objects/library/Makefile examples/objects/number/Makefile examples/objects/path/Makefile examples/objects/plot/Makefile examples/objects/scatter/Makefile examples/objects/string/Makefile examples/objects/tree/Makefile examples/objects/xmlparser/Makefile examples/zoo/Makefile examples/zoo/binary/Makefile examples/zoo/boolean/Makefile examples/zoo/choice/Makefile examples/zoo/curve/Makefile examples/zoo/drawing/Makefile examples/zoo/enable/Makefile examples/zoo/field/Makefile examples/zoo/group/Makefile examples/zoo/histogram/Makefile examples/zoo/image/Makefile examples/zoo/image/docs/Makefile examples/zoo/image/examples/Makefile examples/zoo/integer/Makefile examples/zoo/integer2/Makefile examples/zoo/loader/Makefile examples/zoo/loader/examples/Makefile examples/zoo/log/Makefile examples/zoo/mesh/Makefile examples/zoo/note/Makefile examples/zoo/note/docs/Makefile examples/zoo/number/Makefile examples/zoo/number2/Makefile examples/zoo/parallelepiped/Makefile examples/zoo/periodicelement/Makefile examples/zoo/phase/Makefile examples/zoo/sequence/Makefile examples/zoo/sequence/examples/Makefile examples/zoo/string/Makefile examples/zoo/structure/Makefile examples/zoo/structure/examples/Makefile examples/zoo/table/Makefile video/Makefile video/pkgIndex.tcl oldtest/Makefile oldtest/src/Makefile puq/Makefile"
 
 cat >confcache <<\_ACEOF
@@ -11037,4 +11037,5 @@
     "oldtest/Makefile") CONFIG_FILES="$CONFIG_FILES oldtest/Makefile" ;;
     "oldtest/src/Makefile") CONFIG_FILES="$CONFIG_FILES oldtest/src/Makefile" ;;
+    "puq/Makefile") CONFIG_FILES="$CONFIG_FILES puq/Makefile" ;;
 
   *) as_fn_error $? "invalid argument: \`$ac_config_target'" "$LINENO" 5;;
Index: /branches/uq/configure.in
===================================================================
--- /branches/uq/configure.in	(revision 5028)
+++ /branches/uq/configure.in	(revision 5029)
@@ -43,8 +43,8 @@
 AC_PROG_MAKE_SET
 
-# Check for C, C++, and FORTRAN 
+# Check for C, C++, and FORTRAN
 AC_PROG_CC
 AC_PROG_CXX
-# Avoid g95 
+# Avoid g95
 AC_PROG_F77([g77 gfortran f77 fort77 f90 xlf xlf90 fl32])
 
@@ -146,5 +146,5 @@
 for dir in \
  ${exec_prefix} \
- ${exec_prefix}/lib ; do 
+ ${exec_prefix}/lib ; do
   tclconfig="${dir}/tclConfig.sh"
   if test -f "$tclconfig" ; then
@@ -171,7 +171,7 @@
 if test "${with_tclsh}" != "no" ; then
   tclsh="tclsh${TCL_VERSION}"
-  if test "${with_tclsh}" = "yes" ; then 
+  if test "${with_tclsh}" = "yes" ; then
     AC_PATH_PROG(TCLSH, ${tclsh}, [], [${exec_prefix}/bin:${PATH}])
-  else 
+  else
     AC_PATH_PROG(TCLSH, ${tclsh}, [], [${with_tclsh}/bin:${with_tclsh}])
   fi
@@ -188,5 +188,5 @@
     [AS_HELP_STRING([--with-vtk[=version]],
         [VTK library version @<:@default=6.0@:>@])],
-    [], 
+    [],
     [with_vtk=yes])
 
@@ -230,5 +230,5 @@
     [AS_HELP_STRING([--enable-vtkdicom],
         [Use vtkDICOM package @<:@default=no@:>@])],
-    [], 
+    [],
     [enable_vtkdicom=no])
 
@@ -296,9 +296,9 @@
 #--------------------------------------------------------------------
 if test "${with_ffmpeg}" != "no" ; then
-  if test "${with_ffmpeg}" = "yes" ; then 
+  if test "${with_ffmpeg}" = "yes" ; then
     AC_PATH_PROG(FFMPEG, ffmpeg, [], $PATH)
-  else 
+  else
     AC_PATH_PROG(FFMPEG, ffmpeg, [], [${with_ffmpeg}/bin:${with_ffmpeg}])
-  fi 
+  fi
   if test "${FFMPEG}x" != "x" ; then
     AC_DEFINE(HAVE_FFMPEG, 1, [Render servers can use ffmpeg])
@@ -342,5 +342,5 @@
   AC_CHECK_FUNCS(av_close_input_file)
   AC_CHECK_FUNCS(avformat_close_input)
-	
+
   AC_CHECK_FUNC(avcodec_find_decoder,,
     AC_MSG_ERROR(oops! no av_codec_find_decoder ?!?))
@@ -598,5 +598,6 @@
     oldtest/Makefile
     oldtest/src/Makefile
+    puq/Makefile
 ])
 AC_OUTPUT
-	
+
Index: /branches/uq/gui/apps/launcher.tcl
===================================================================
--- /branches/uq/gui/apps/launcher.tcl	(revision 5028)
+++ /branches/uq/gui/apps/launcher.tcl	(revision 5029)
@@ -107,7 +107,7 @@
 # Note: We're sourcing the driver file "main.tcl" rather than exec-ing
 #       wish because we want to see stderr and stdout messages when they
-#	are written, rather than when the program completes.  It also 
-#	eliminates one process waiting for the other to complete. If 
-#	"exec" is needed, then the following could be replaced with 
+#	are written, rather than when the program completes.  It also
+#	eliminates one process waiting for the other to complete. If
+#	"exec" is needed, then the following could be replaced with
 #	blt::bgexec.  It doesn't try to redirect stderr into a file.
 set argv $alist
@@ -116,2 +116,3 @@
 }
 source  $mainscript
+puts "Done with launcher"
Index: /branches/uq/gui/scripts/Makefile.in
===================================================================
--- /branches/uq/gui/scripts/Makefile.in	(revision 5028)
+++ /branches/uq/gui/scripts/Makefile.in	(revision 5029)
@@ -95,4 +95,5 @@
 		$(srcdir)/periodictable.tcl \
 		$(srcdir)/postern.tcl \
+		$(srcdir)/probdisteditor.tcl \
 		$(srcdir)/progress.tcl \
 		$(srcdir)/pushbutton.tcl \
@@ -158,12 +159,12 @@
 		--outfile tclIndex
 
-install: all install_scripts install_images 
+install: all install_scripts install_images
 
-install_scripts: 
+install_scripts:
 	$(MKDIR_P) -m 0755 $(destdir)
 	@for i in $(FILES); do \
 	    echo "Installing $$i" ; \
 	    $(INSTALL) -m 0444 $$i $(destdir) ; \
-	done 
+	done
 	$(INSTALL) -m 0444 tclIndex $(destdir)
 
@@ -173,5 +174,5 @@
 	    echo "Installing $$i" ; \
 	    $(INSTALL) -m 0444 $$i $(destdir)/images ; \
-	done 
+	done
 
 clean:
Index: /branches/uq/gui/scripts/analyzer.tcl
===================================================================
--- /branches/uq/gui/scripts/analyzer.tcl	(revision 5028)
+++ /branches/uq/gui/scripts/analyzer.tcl	(revision 5029)
@@ -1,3 +1,3 @@
-# -*- mode: tcl; indent-tabs-mode: nil -*- 
+# -*- mode: tcl; indent-tabs-mode: nil -*-
 # ----------------------------------------------------------------------
 #  COMPONENT: analyzer - output area for Rappture
@@ -50,9 +50,9 @@
     itk_option define -notebookpage notebookPage NotebookPage ""
 
-    constructor {tool args} { 
-        # defined below 
-    }
-    destructor { 
-        # defined below 
+    constructor {tool args} {
+        # defined below
+    }
+    destructor {
+        # defined below
     }
 
@@ -103,5 +103,5 @@
 itcl::body Rappture::Analyzer::constructor {tool args} {
     set _tool $tool
-
+    puts "Analyzer init"
     # use this to store all simulation results
     set _resultset [Rappture::ResultSet ::\#auto]
@@ -391,4 +391,5 @@
 # ----------------------------------------------------------------------
 itcl::body Rappture::Analyzer::simulate {args} {
+    puts "simulate $args"
     if {$args == "-ifneeded"} {
         # check to see if simulation is really needed
@@ -401,6 +402,6 @@
         }
         set args ""
-    } 
-
+    }
+    puts "simulation needed"
     # simulation is needed -- go to simulation page
     $itk_component(notebook) current simulate
@@ -423,4 +424,6 @@
 
     # execute the job
+    puts "$_tool run $args"
+
     foreach {status result} [eval $_tool run $args] break
 
@@ -443,5 +446,5 @@
     if {$status != 0} {
         $itk_component(runinfo) configure -state normal
-        # Don't erase program error messages. 
+        # Don't erase program error messages.
         # $itk_component(runinfo) delete 1.0 end
         $itk_component(runinfo) insert end "\n\nProblem launching job:\n\n" text
@@ -585,5 +588,5 @@
                     $popup activate $widget below
                 } else {
-                    download now $widget 
+                    download now $widget
                 }
             } else {
@@ -1282,5 +1285,5 @@
             set frame ${sequence}.element($frameNum)
             $xmlobj put ${frame}.index $frameNum
-            
+
             set molecule ${frame}.structure.components.molecule
             $xmlobj put ${molecule}.pdb $contents
@@ -1325,9 +1328,9 @@
                 set frame ${sequence}.element($frameNum)
                 $xmlobj put ${frame}.index $frameNum
-                
+
                 set molecule ${frame}.structure.components.molecule
                 $xmlobj put ${molecule}.lammps $frameContents
                 $xmlobj put ${molecule}.lammpstypemap $typemap
-                
+
                 incr frameNum
                 set frameContents ""
@@ -1345,5 +1348,5 @@
         set frame ${sequence}.element($frameNum)
         $xmlobj put ${frame}.index $frameNum
-        
+
         set molecule ${frame}.structure.components.molecule
         $xmlobj put ${molecule}.lammps $frameContents
@@ -1355,10 +1358,10 @@
 # USAGE: _trajToSequence <xmlobj> ?<path>?
 #
-#       Check for PDB and LAMMPS trajectories in molecule data and rewrite 
-#       the individual models as a sequence of molecules.  Used internally 
+#       Check for PDB and LAMMPS trajectories in molecule data and rewrite
+#       the individual models as a sequence of molecules.  Used internally
 #       to detect any molecule output elements that contain trajectory data.
 #       Trajectories will be converted into sequences of individual molecules.
 #       All other elements will be unaffected. Scans the entire xml tree if a
-#       starting path is not specified.  
+#       starting path is not specified.
 #
 # ----------------------------------------------------------------------
Index: /branches/uq/gui/scripts/controlOwner.tcl
===================================================================
--- /branches/uq/gui/scripts/controlOwner.tcl	(revision 5028)
+++ /branches/uq/gui/scripts/controlOwner.tcl	(revision 5029)
@@ -1,3 +1,3 @@
-# -*- mode: tcl; indent-tabs-mode: nil -*- 
+# -*- mode: tcl; indent-tabs-mode: nil -*-
 # ----------------------------------------------------------------------
 #  COMPONENT: owner - manages Rappture controls
Index: /branches/uq/gui/scripts/gauge.tcl
===================================================================
--- /branches/uq/gui/scripts/gauge.tcl	(revision 5028)
+++ /branches/uq/gui/scripts/gauge.tcl	(revision 5029)
@@ -1,3 +1,3 @@
-# -*- mode: tcl; indent-tabs-mode: nil -*- 
+# -*- mode: tcl; indent-tabs-mode: nil -*-
 # ----------------------------------------------------------------------
 #  COMPONENT: gauge - compact readout for real values
@@ -42,4 +42,6 @@
     itk_option define -sampleheight sampleHeight SampleHeight 0
     itk_option define -log log Log ""
+    itk_option define -varname varname Varname ""
+    itk_option define -label label Label ""
 
     constructor {args} { # defined below }
@@ -56,6 +58,12 @@
     protected method _layout {}
     protected method _log {event args}
+    protected method _change_param_type {choice}
+    protected method _pop_uq {win}
+    protected method _pop_uq_deactivate {}
 
     private variable _value 0  ;# value for this widget
+    private variable _mode exact ;# current mode
+    private variable _pde ""   ;# ProbDistEditor
+    private variable _val ""   ;# value choice combobox
 
     blt::bitmap define GaugeArrow {
@@ -66,5 +74,5 @@
     }
 }
-                                                                                
+
 itk::usual Gauge {
     keep -cursor -font -foreground -background
@@ -76,4 +84,5 @@
 # ----------------------------------------------------------------------
 itcl::body Rappture::Gauge::constructor {args} {
+
     itk_option remove hull.borderwidth hull.relief
     component hull configure -borderwidth 0
@@ -89,4 +98,11 @@
     bind $itk_component(icon) <Configure> [itcl::code $this _redraw]
 
+    itk_component add uq {
+        button $itk_interior.uq -image [Rappture::icon UQ] \
+            -command [itcl::code $this _pop_uq $itk_interior]
+    }
+
+    pack $itk_component(uq) -side right -padx 10
+
     itk_component add -protected vframe {
         frame $itk_interior.vframe
@@ -96,5 +112,5 @@
 
     itk_component add value {
-        label $itk_component(vframe).value -width 7 \
+        label $itk_component(vframe).value -width 20 \
             -borderwidth 1 -relief flat -textvariable [itcl::scope _value]
     } {
@@ -197,108 +213,58 @@
 # ----------------------------------------------------------------------
 itcl::body Rappture::Gauge::value {args} {
-    set onlycheck 0
+    # puts "Gauge value: $args"
+
+    # Query.  Just return the current value.
+    if {[llength $args] == 0} {
+        return $_value
+    }
+
     set i [lsearch -exact $args -check]
     if {$i >= 0} {
         set onlycheck 1
         set args [lreplace $args $i $i]
-    }
-
-    if {[llength $args] == 1} {
-        #
-        # If this gauge has -units, try to convert the incoming
-        # value to that system of units.  Also, make sure that
-        # the value is bound by any min/max value constraints.
-        #
-        # Keep track of the inputted units so we can give a 
-        # response about min and max values in familiar units.
-        #
-        set newval [set nv [string trim [lindex $args 0]]]
-        set units $itk_option(-units)
-        if {"" != $units} {
-            set newval [Rappture::Units::convert $newval -context $units]
-            set nvUnits [Rappture::Units::Search::for $newval]
-            if { "" == $nvUnits} {
-                set msg [Rappture::Units::description $units]
-                error "unrecognized units in value \"$newval\": should be value with units of $msg"
-            }
-            set nv [Rappture::Units::convert $nv \
-                -context $units -to $units -units off]
-
-            # Normalize the units name
-            set newval [Rappture::Units::convert $newval -units off]$nvUnits
-        }
-
-        switch -- $itk_option(-type) {
-            integer {
-                if { [scan $nv "%g" value] != 1 || int($nv) != $value } {
-                    error "bad value \"$nv\": should be an integer value"
-                }
-            }
-            real {
-		# "scan" will reject the number if the string is "NaN" or
-		# "Inf" or the empty string.  It also is accepts large numbers
-		# (e.g. 111111111111111111111) that "string is double"
-		# rejects.  The problem with "scan" is that it doesn't care if
-		# there are extra characters trailing the number (eg. "123a").
-		# The extra %s substitution is used to detect this case.
-                if { [scan $nv "%g%s" dummy1 dummy2] != 1 } {
-                    error "bad value \"$nv\": should be a real number"
-                }
-            }
-        }
-
-        if {"" != $itk_option(-minvalue)} {
-            set convMinVal [set minv $itk_option(-minvalue)]
-            if {"" != $units} {
-                set minv [Rappture::Units::convert $minv \
-                    -context $units -to $units -units off]
-                set convMinVal [Rappture::Units::convert \
-                    $itk_option(-minvalue) -context $units -to $nvUnits]
-            } else {
-                set newval [format "%g" $newval]
-            }
-
-            # fix for the case when the user tries to
-            # compare values like minv=-500 nv=-0600
-            set nv [format "%g" $nv]
-            set minv [format "%g" $minv]
-
-            if {$nv < $minv} {
-                error "minimum value allowed here is $convMinVal"
-            }
-        }
-
-        if {"" != $itk_option(-maxvalue)} {
-            set convMaxVal [set maxv $itk_option(-maxvalue)]
-            if {"" != $units} {
-                set maxv [Rappture::Units::convert $maxv \
-                    -context $units -to $units -units off]
-                set convMaxVal [Rappture::Units::convert \
-                    $itk_option(-maxvalue) -context $units -to $nvUnits]
-            } else {
-                set newval [format "%g" $newval]
-            }
-
-            # fix for the case when the user tries to
-            # compare values like maxv=500 nv=0600
-            set nv [format "%g" $nv]
-            set maxv [format "%g" $maxv]
-
-            if {$nv > $maxv} {
-                error "maximum value allowed here is $convMaxVal"
-            }
-        }
-
-        if {$onlycheck} {
-            return
-        }
-
-        set _value $newval
-
-        _redraw
-        event generate $itk_component(hull) <<Value>>
-
-    } elseif {[llength $args] != 0} {
+    } else {
+        set onlycheck 0
+    }
+
+    if {[llength $args] != 1} {
         error "wrong # args: should be \"value ?-check? ?newval?\""
+    }
+
+    set newval [Rappture::Units::mcheck_range [lindex $args 0] \
+    $itk_option(-minvalue) $itk_option(-maxvalue) $itk_option(-units)]
+
+    set newmode [lindex $newval 0]
+    switch -- $newmode {
+        uniform -
+        gaussian {
+            set _mode $newmode
+        }
+        exact -
+        default {
+            set _mode exact
+        }
+    }
+
+    if {$itk_option(-type) == "integer"} {
+        if { [scan $newval "%g" value] != 1 || int($newval) != $value } {
+            error "bad value \"$newval\": should be an integer value"
+        }
+    }
+
+    if {$onlycheck} {
+        return
+    }
+
+    set _value $newval
+    $itk_component(value) configure -width [string length $_value]
+    _redraw
+    event generate $itk_component(hull) <<Value>>
+
+    if {"" != $_pde} {
+        set val [$_val translate [$_val value]]
+        $_val value $_mode
+        $_pde value $_value
+
     }
     return $_value
@@ -483,4 +449,5 @@
 # ----------------------------------------------------------------------
 itcl::body Rappture::Gauge::_editor {option args} {
+    # puts "Gauge::editor option=$option args=$args"
     if {$itk_option(-state) == "disabled"} {
         return  ;# disabled? then bail out here!
@@ -504,5 +471,4 @@
             }
             set val [lindex $args 0]
-
             if {[catch {value -check $val} result]} {
                 if {[regexp {allowed here is (.+)} $result match newval]} {
@@ -586,4 +552,8 @@
     }
 
+    if {$itk_option(-type) != "integer"} {
+        pack $itk_component(uq) -side right -padx 10
+    }
+
     array set side2anchor {
         left   e
@@ -733,2 +703,44 @@
     }
 }
+
+itcl::body Rappture::Gauge::_pop_uq {win} {
+    # puts "min=$itk_option(-minvalue) max=$itk_option(-maxvalue) units=$itk_option(-units)"
+    set varname $itk_option(-varname)
+    set popup .pop_uq_$varname
+    if { ![winfo exists $popup] } {
+        Rappture::Balloon $popup -title $itk_option(-label)
+        set inner [$popup component inner]
+        frame $inner.type
+        pack $inner.type -side top -fill x
+        label $inner.type.l -text "Parameter Value:"
+        pack $inner.type.l -side left
+
+        set _val [Rappture::Combobox $inner.type.val -width 20 -editable no]
+        pack $_val -side left -expand yes -fill x
+        $_val choices insert end exact "Exact Value"
+        $_val choices insert end uniform "Uniform Distribution"
+        $_val choices insert end gaussian "Gaussian Distribution"
+        bind $_val <<Value>> [itcl::code $this _change_param_type $inner]
+
+        set _pde [Rappture::ProbDistEditor $inner.entry \
+        $itk_option(-minvalue) $itk_option(-maxvalue)]
+        $_val value $_mode
+        $_pde value $_value
+        pack $inner.entry -expand yes -fill both -pady {10 0}
+
+        $popup configure \
+        -deactivatecommand [itcl::code $this _pop_uq_deactivate]
+    }
+    update
+    $popup activate $win right
+}
+
+itcl::body Rappture::Gauge::_pop_uq_deactivate {} {
+    # puts "deactivate [$_pde value]"
+    value [$_pde value]
+}
+
+itcl::body Rappture::Gauge::_change_param_type {inner} {
+    set val [$_val translate [$_val value]]
+    $_pde mode $val
+}
Index: /branches/uq/gui/scripts/main.tcl
===================================================================
--- /branches/uq/gui/scripts/main.tcl	(revision 5028)
+++ /branches/uq/gui/scripts/main.tcl	(revision 5029)
@@ -1,3 +1,3 @@
-# -*- mode: tcl; indent-tabs-mode: nil -*- 
+# -*- mode: tcl; indent-tabs-mode: nil -*-
 #!/bin/sh
 # ----------------------------------------------------------------------
@@ -96,6 +96,10 @@
 }
 
+# mmh
+puts "main.tcl $argv"
+parray params
+
 proc ReadToolParameters { numTries } {
-    incr numTries -1 
+    incr numTries -1
     if { $numTries < 0 } {
 	return
@@ -107,9 +111,9 @@
 	return
     }
-    catch { 
+    catch {
         set f [open $paramsFile "r"]
         set contents [read $f]
         close $f
-        set pattern {^file\((.*)\):(.*)$} 
+        set pattern {^file\((.*)\):(.*)$}
         foreach line [split $contents "\n"] {
             if { [regexp $pattern $line match path rest] } {
@@ -178,5 +182,4 @@
 set installdir [file normalize [file dirname $params(-tool)]]
 $xmlobj put tool.version.application.directory(tool) $installdir
-
 set tool [Rappture::Tool ::#auto $xmlobj $installdir]
 
@@ -358,9 +361,9 @@
     set arrangement [$win.pager cget -arrangement]
     if { $type == "" } {
-        if { $arrangement != "side-by-side" } { 
+        if { $arrangement != "side-by-side" } {
            set type auto
         }
     }
-    if { $arrangement != "side-by-side" && 
+    if { $arrangement != "side-by-side" &&
             ($type == "manual" || $type == "manual-resim" ||
 	     $type == "auto" || $style == "wizard") } {
@@ -389,4 +392,4 @@
     $win.pager current analyzer
 }
-
+puts "DONE main.tcl"
 wm deiconify .main
Index: /branches/uq/gui/scripts/numberentry.tcl
===================================================================
--- /branches/uq/gui/scripts/numberentry.tcl	(revision 5028)
+++ /branches/uq/gui/scripts/numberentry.tcl	(revision 5029)
@@ -1,3 +1,3 @@
-# -*- mode: tcl; indent-tabs-mode: nil -*- 
+# -*- mode: tcl; indent-tabs-mode: nil -*-
 # ----------------------------------------------------------------------
 #  COMPONENT: NumberEntry - widget for entering numeric values
@@ -25,5 +25,4 @@
     public method label {}
     public method tooltip {}
-
     protected method _newValue {}
 
@@ -43,4 +42,7 @@
 # ----------------------------------------------------------------------
 itcl::body Rappture::NumberEntry::constructor {owner path args} {
+    puts "NumberEntry '$path' '$args'"
+    set varname [lindex [split $path ()] 1]
+
     if {[catch {$owner isa Rappture::ControlOwner} valid] != 0 || !$valid} {
         error "bad object \"$owner\": should be Rappture::ControlOwner"
@@ -48,5 +50,6 @@
     set _owner $owner
     set _path $path
-    
+
+    puts "LABEL=[label]"
     #
     # Figure out what sort of control to create
@@ -58,7 +61,8 @@
         lappend presets $value $label
     }
-    
+
     set class Rappture::Gauge
     set units [string trim [$_owner xml get $path.units]]
+    puts "units=$units"
     if {$units != ""} {
         set desc [Rappture::Units::description $units]
@@ -67,5 +71,5 @@
         }
     }
-    
+
     #
     # Create the widget and configure it properly based on other
@@ -73,17 +77,17 @@
     #
     itk_component add gauge {
-        $class $itk_interior.gauge -units $units -presets $presets -log $path
+        $class $itk_interior.gauge -units $units -presets $presets -log $path -varname $varname -label [label]
     }
     pack $itk_component(gauge) -expand yes -fill both
     bind $itk_component(gauge) <<Value>> [itcl::code $this _newValue]
-    
+
     set min [string trim [$_owner xml get $path.min]]
-    if {$min ne ""} { 
-        $itk_component(gauge) configure -minvalue $min 
-    }
-    
+    if {$min ne ""} {
+        $itk_component(gauge) configure -minvalue $min
+    }
+
     set max [string trim [$_owner xml get $path.max]]
-    if {$max ne ""} { 
-        $itk_component(gauge) configure -maxvalue $max 
+    if {$max ne ""} {
+        $itk_component(gauge) configure -maxvalue $max
     }
 
@@ -119,6 +123,7 @@
     #
     set str [string trim [$_owner xml get $path.default]]
-    if {$str ne ""} { 
-        $itk_component(gauge) value $str 
+    puts "Default=$str"
+    if {$str ne ""} {
+        $itk_component(gauge) value $str
     }
 }
Index: /branches/uq/gui/scripts/probdisteditor.tcl
===================================================================
--- /branches/uq/gui/scripts/probdisteditor.tcl	(revision 5029)
+++ /branches/uq/gui/scripts/probdisteditor.tcl	(revision 5029)
@@ -0,0 +1,665 @@
+# -*- mode: tcl; indent-tabs-mode: nil -*-
+# ----------------------------------------------------------------------
+#  COMPONENT: ProbDistEditor - probability distribution editor
+#
+#  This widget displays a probability distribution and lets the user
+#  edit it in various flavors.
+# ======================================================================
+#  AUTHOR:  Michael McLennan, Purdue University
+#  Copyright (c) 2004-2010  Purdue University
+#
+#  See the file "license.terms" for information on usage and
+#  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
+# ======================================================================
+package require Itk
+package require BLT
+
+option add *ProbDistEditor.fillColor blue widgetDefault
+option add *ProbDistEditor*Entry.background white widgetDefault
+option add *ProbDistEditor*Entry.width 10 widgetDefault
+
+    itcl::class Rappture::ProbDistEditor {
+    inherit itk::Widget
+
+    itk_option define -fillcolor fillColor FillColor ""
+
+    constructor {args} { # defined below }
+    public method value {{newval ""}}
+    public method mode {{newval ""}}
+    public method reset {}
+
+    protected method _redraw {}
+    protected method _axisLabels {which graph val}
+    protected method _apply {op {widget ""}}
+
+    protected variable _dispatcher ""   ;# dispatcher for !events
+    protected variable _mode ""         ;# type of distribution function
+    protected variable _value           ;# data values for mode-detail
+    protected variable _uvalue          ;# data values for mode-detail with units
+    protected variable _umin             ;# minimum allowed value for tool with units
+    protected variable _umax             ;# maximum allowed value for tool with units
+    protected variable _units           ;# units for min and max
+}
+
+itk::usual ProbDistEditor {
+    keep -cursor -font -foreground -background
+    keep -fillcolor
+}
+
+# ----------------------------------------------------------------------
+# CONSTRUCTOR
+# ----------------------------------------------------------------------
+itcl::body Rappture::ProbDistEditor::constructor {min max} {
+    # create a dispatcher for events
+    puts "PDE::constructor $min $max"
+
+    # These are the tool min and max values.  May be empty.
+    set _umin $min
+    set _umax $max
+    set _units [Rappture::Units::Search::for $_umin]
+
+    Rappture::dispatcher _dispatcher
+    $_dispatcher register !redraw
+    $_dispatcher dispatch $this !redraw "[itcl::code $this _redraw]; list"
+
+    itk_component add vals {
+        frame $itk_interior.vals
+    }
+    pack $itk_component(vals) -side left -fill both -padx {0 10}
+    #
+    # EXACT value options
+    #
+    itk_component add exactvals {
+        frame $itk_component(vals).exact
+    }
+    itk_component add evl {
+        label $itk_component(exactvals).l -text "Value:"
+    }
+    entry $itk_component(exactvals).val
+    _apply bindings $itk_component(exactvals).val
+    grid $itk_component(evl) -row 0 -column 0 -sticky e
+    grid $itk_component(exactvals).val -row 0 -column 1 -sticky ew -pady 2
+    grid rowconfigure $itk_component(exactvals) 1 -weight 1
+    #
+    # UNIFORM value options
+    #
+    itk_component add uniformvals {
+        frame $itk_component(vals).uniform
+    }
+    itk_component add uvl0 {
+        label $itk_component(uniformvals).l0 -text "Minimum:"
+    }
+    entry $itk_component(uniformvals).min
+    _apply bindings $itk_component(uniformvals).min
+    grid $itk_component(uvl0) -row 0 -column 0 -sticky e
+    grid $itk_component(uniformvals).min -row 0 -column 1 -sticky ew -pady 2
+
+    itk_component add uvl1 {
+        label $itk_component(uniformvals).l1 -text "Maximum:"
+    }
+    entry $itk_component(uniformvals).max
+    _apply bindings $itk_component(uniformvals).max
+    grid $itk_component(uvl1) -row 1 -column 0 -sticky e
+    grid $itk_component(uniformvals).max -row 1 -column 1 -sticky ew -pady 2
+    grid rowconfigure $itk_component(uniformvals) 2 -weight 1
+
+    #
+    # GAUSSIAN value options
+    #
+    itk_component add gaussianvals {
+        frame $itk_component(vals).gaussian
+    }
+    itk_component add gvlm {
+        label $itk_component(gaussianvals).lm -text "Mean:"
+    }
+    entry $itk_component(gaussianvals).mean
+    _apply bindings $itk_component(gaussianvals).mean
+    grid $itk_component(gvlm) -row 0 -column 0 -sticky e
+    grid $itk_component(gaussianvals).mean -row 0 -column 1 -sticky ew -pady 2
+
+    itk_component add gvls {
+        label $itk_component(gaussianvals).ls -text "Std Deviation:"
+    }
+    entry $itk_component(gaussianvals).stddev
+    _apply bindings $itk_component(gaussianvals).stddev
+    grid $itk_component(gvls) -row 1 -column 0 -sticky e
+    grid $itk_component(gaussianvals).stddev -row 1 -column 1 -sticky ew -pady 2
+
+    itk_component add gvl0 {
+        label $itk_component(gaussianvals).l0 -text "Minimum:" -state disabled
+    }
+    entry $itk_component(gaussianvals).min -state readonly
+    _apply bindings $itk_component(gaussianvals).min
+    grid $itk_component(gvl0) -row 2 -column 0 -sticky e
+    grid $itk_component(gaussianvals).min -row 2 -column 1 -sticky ew -pady 2
+
+    itk_component add gvl1 {
+        label $itk_component(gaussianvals).l1 -text "Maximum:" -state disabled
+    }
+    entry $itk_component(gaussianvals).max -state readonly
+    _apply bindings $itk_component(gaussianvals).max
+    grid $itk_component(gvl1) -row 3 -column 0 -sticky e
+    grid $itk_component(gaussianvals).max -row 3 -column 1 -sticky ew -pady 2
+    grid rowconfigure $itk_component(gaussianvals) 4 -weight 1
+
+    #
+    # Preview graph to display probability density function
+    #
+    itk_component add graph {
+        blt::graph $itk_interior.graph -width 2i -height 1i \
+            -plotborderwidth 1 -plotrelief solid -plotpadx 0 -plotpady 0 \
+            -highlightthickness 0
+    } {
+        keep -background -foreground -cursor -font
+    }
+    pack $itk_component(graph) -expand yes -fill both
+
+    $itk_component(graph) xaxis configure -ticklength 4 \
+        -command [itcl::code $this _axisLabels xaxis]
+    $itk_component(graph) yaxis configure -ticklength 4 \
+        -title "PDF" -command [itcl::code $this _axisLabels yaxis]
+    $itk_component(graph) grid off
+    $itk_component(graph) legend configure -hide yes
+
+    # start in exact mode with default values
+    mode "exact"
+
+    eval itk_initialize
+
+    #
+    # Figure out a good size for all panels of options and for the
+    # overall widget.
+    #
+    update idletasks
+    set maxw 0
+    set maxh 0
+    foreach panel {exact uniform gaussian} {
+        set w [winfo reqwidth $itk_component(${panel}vals)]
+        if {$w > $maxw} { set maxw $w }
+        set h [winfo reqheight $itk_component(${panel}vals)]
+        if {$h > $maxh} { set maxh $h }
+    }
+
+    pack propagate $itk_component(vals) off
+    $itk_component(vals) configure -width $maxw -height $maxh
+}
+
+# ----------------------------------------------------------------------
+# USAGE: value ?<setValue>?
+#
+# With no arguments, this returns the current value within the widget
+# as a list of key/value pairs:
+#   mode gaussian mean xxx stddev xxx min xxx max xxx
+#
+# Each value always has a "mode" that indicates its type, and other
+# values to characterize the type.
+#
+# If the value is specified, then it is interpreted as the sort of
+# value that is passed back, but used to set the value.
+# ----------------------------------------------------------------------
+itcl::body Rappture::ProbDistEditor::value {{newval ""}} {
+    puts "PDE::value $newval"
+
+    #FIXME: _value has numerical values _uvalue has value with units
+    if {"" == $newval} {
+        catch {_apply finalize}  ;# apply any outstanding changes
+
+        switch -- $_mode {
+            exact {
+                return $_uvalue(central)
+            }
+            uniform {
+                return [list uniform $_uvalue(min) $_uvalue(max)]
+            }
+            gaussian {
+                return [list gaussian $_uvalue(central) $_uvalue(stddev)]
+            }
+            default {
+                error "don't know how to format value for $_mode"
+            }
+        }
+    }
+
+    set newmode [lindex $newval 0]
+    switch -- $newmode {
+        uniform {
+            foreach {utmp(min) utmp(max)} [lrange $newval 1 2] break
+            if {[catch {Rappture::Units::convert $utmp(min) -units off} tmp(min)]} {
+                set tmp(min) $utmp(min)
+            }
+            if {[catch {Rappture::Units::convert $utmp(max) -units off} tmp(max)]} {
+                set tmp(max) $utmp(max)
+            }
+        }
+        gaussian {
+            foreach {utmp(central) utmp(stddev)} [lrange $newval 1 2] break
+            if {[catch {Rappture::Units::convert $utmp(central) -units off} tmp(central)]} {
+                set tmp(central) $utmp(central)
+            }
+            if {[catch {Rappture::Units::convert $utmp(stddev) -units off} tmp(stddev)]} {
+                set tmp(stddev) $utmp(stddev)
+            }
+            set units [Rappture::Units::Search::for $utmp(central)]
+            if {"" != $_umin} {
+                if {"" != $units} {
+                    set tmp(min) [Rappture::Units::convert $_umin -to $units -units off]
+                } else {
+                    set tmp(min) $_umin
+                }
+            }
+            if {"" != $_umax} {
+                if {"" != $units} {
+                    set tmp(max) [Rappture::Units::convert $_umax -to $units -units off]
+                } else {
+                    set tmp(max) $_umax
+                }
+            }
+        }
+        exact {
+            set utmp(central) [lindex $newval 1]
+            if {[catch {Rappture::Units::convert $utmp(central) -units off} tmp(central)]} {
+                set tmp(central) $utmp(central)
+            }
+        }
+        default {
+            set newmode exact
+            set utmp(central) [lindex $newval 0]
+            if {[catch {Rappture::Units::convert $utmp(central) -units off} tmp(central)]} {
+                set tmp(central) $utmp(central)
+            }
+        }
+    }
+    array set _value [array get tmp]
+    array set _uvalue [array get utmp]
+    mode $newmode  ;# assign this mode and copy in values for editing
+}
+
+# ----------------------------------------------------------------------
+# USAGE: mode ?<setMode>?
+#
+# With no arguments, this returns a list of allowed distribution
+# modes.  Otherwise, the value sets the mode of the distribution and
+# loads default or previous values for the distribution.  Note that
+# the mode is also reported as part of the "value" returned from
+# this widget.
+# ----------------------------------------------------------------------
+itcl::body Rappture::ProbDistEditor::mode {{newval ""}} {
+    puts "PDE::mode mode=$newval min=$_umin max=$_umax units=$_units"
+
+    set modes {exact uniform gaussian custom}
+    if {"" == $newval} {
+        return $modes
+    }
+    if {[lsearch $modes $newval] < 0} {
+        error "bad value \"$newval\": should be [join $modes {, }]"
+    }
+
+    # discard units from tool min/max
+    if {$_units == ""} {
+        set min $_umin
+        set max $_umax
+    } else {
+        set min [Rappture::Units::convert $_umin -units off]
+        set max [Rappture::Units::convert $_umax -units off]
+    }
+
+    # The mode was changed by the user.  Pick reasonable values.
+    switch -- $newval {
+        exact {
+            if {![info exists _value(central)]} {
+                if {$min != "" && $max != ""} {
+                    set _value(central) [expr {0.5*($max + $min)}]
+                } else {
+                    set _value(central) 0.5
+                }
+                set _uvalue(central) $_value(central)$_units
+            }
+        }
+        uniform {
+            if {![info exists _value(min)] || ![info exists _value(max)]} {
+                if {$min != "" && $max != ""} {
+                    set _value(min) $min
+                    set _value(max) $max
+                } elseif {[info exists _value(central)]} {
+                    if {$_value(central) == 0.0} {
+                        set delta 0.5
+                    } else {
+                        set delta [expr {0.5*$_value(central)}]
+                    }
+                    set _value(min) [expr {$_value(central) - $delta}]
+                    set _value(max) [expr {$_value(central) + $delta}]
+                } else {
+                    set _value(min) 0.1
+                    set _value(max) 0.9
+                }
+                set _uvalue(min) $_value(min)$_units
+                set _uvalue(max) $_value(max)$_units
+            }
+        }
+        gaussian {
+
+            if {![info exists _value(central)]} {
+                if {[info exists _value(min)] && [info exists _value(max)]} {
+                    set _value(central) [expr {0.5*($_value(max) + $_value(min))}]
+                } else {
+                    set _value(central) [expr {0.5*($max + $min)}]
+                }
+            }
+            if {![info exists _value(stddev)]} {
+                if {[info exists _value(min)] && [info exists _value(max)]} {
+                    set _value(stddev) [expr {0.3*($_value(max) - $_value(min))}]
+                } else {
+                    set _value(stddev) [expr {0.3*($max - $min)}]
+                }
+            }
+
+            # lower bound is -3 deviations or tool min
+            set trunc [expr {$_value(central) - 3*$_value(stddev)}]
+            if {$min == "" || $trunc > $min} {
+                set _value(min) $trunc
+            } else {
+                set _value(min) $min
+            }
+
+            # upper bound is +3 deviations or tool max
+            set trunc [expr {$_value(central) + 3*$_value(stddev)}]
+            if {$max == "" || $trunc < $max} {
+                set _value(max) $trunc
+            } else {
+                set _value(max) $max
+            }
+
+            set _uvalue(min) $_value(min)$_units
+            set _uvalue(max) $_value(max)$_units
+            set _uvalue(central) $_value(central)$_units
+            set _uvalue(stddev) $_value(stddev)$_units
+        }
+    }
+
+    # pop up the panel of editing options for this mode
+    foreach w [pack slaves $itk_component(vals)] {
+        pack forget $w
+    }
+    pack $itk_component(${newval}vals) -expand yes -fill both
+
+    switch -- $newval {
+        exact {
+            $itk_component(exactvals).val delete 0 end
+            $itk_component(exactvals).val insert end $_uvalue(central)
+            focus $itk_component(exactvals).val
+        }
+        uniform {
+            $itk_component(uniformvals).min delete 0 end
+            $itk_component(uniformvals).min insert end $_uvalue(min)
+            $itk_component(uniformvals).max delete 0 end
+            $itk_component(uniformvals).max insert end $_uvalue(max)
+            focus $itk_component(uniformvals).min
+        }
+        gaussian {
+            $itk_component(gaussianvals).mean delete 0 end
+            $itk_component(gaussianvals).mean insert end $_uvalue(central)
+            $itk_component(gaussianvals).stddev delete 0 end
+            $itk_component(gaussianvals).stddev insert end $_uvalue(stddev)
+
+            $itk_component(gaussianvals).min configure -state normal
+            $itk_component(gaussianvals).min delete 0 end
+            $itk_component(gaussianvals).min insert end $_uvalue(min)
+            $itk_component(gaussianvals).min configure -state readonly
+
+            $itk_component(gaussianvals).max configure -state normal
+            $itk_component(gaussianvals).max delete 0 end
+            $itk_component(gaussianvals).max insert end $_uvalue(max)
+            $itk_component(gaussianvals).max configure -state readonly
+
+            focus $itk_component(gaussianvals).mean
+        }
+    }
+
+    set _mode $newval
+    $_dispatcher event -idle !redraw
+}
+
+# ----------------------------------------------------------------------
+# USAGE: reset
+#
+# Clears all value information so that the next value application
+# starts from scratch.  Without a reset, the widget carries information
+# like the "central" value, in case the user changes modes and then
+# changes back.  Reset discards that info and starts fresh.
+# ----------------------------------------------------------------------
+itcl::body Rappture::ProbDistEditor::reset {} {
+    set _mode ""
+    catch {unset _value}
+    catch {unset _uvalue}
+    $_dispatcher event -idle !redraw
+}
+
+# ----------------------------------------------------------------------
+# USAGE: _redraw
+#
+# Used internally to reconfigure the graph to display the current
+# distribution plot.
+# ----------------------------------------------------------------------
+itcl::body Rappture::ProbDistEditor::_redraw {} {
+    set g $itk_component(graph)
+    eval $g element delete [$g element names]
+    eval $g mark delete [$g mark names]
+    switch -- $_mode {
+        exact {
+            $g xaxis configure -majorticks {} -min 0 -max 1 -stepsize 0.1
+            $g yaxis configure -min 0 -max 1
+            $g element create delta \
+                -xdata {0 0.48 0.49 0.50 0.51 0.52 1} \
+                -ydata {0    0 0.05 0.93 0.05    0 0} \
+                -color $itk_option(-foreground) -symbol "" \
+                -areaforeground $itk_option(-fillcolor) -areapattern solid
+            # $g marker create image -anchor nw -coords {0.5 0.95} \
+                -xoffset -6 -yoffset -3 -image [Rappture::icon delta]
+        }
+        uniform {
+            $g xaxis configure -majorticks {} -min 0 -max 1 -stepsize 0.1
+            $g yaxis configure -min 0 -max 1
+
+            # uniform distribution throughout
+            $g element create uniform \
+                -xdata {-0.1 -0.1 1.1 1.1} -ydata {-0.1 0.5 0.5 -0.1} \
+                -color $itk_option(-foreground) -symbol "" \
+                -areaforeground $itk_option(-fillcolor) -areapattern solid
+
+            # left/right limits
+            $g marker create polygon \
+                -coords {-0.1 -0.1 0.1 -0.1 0.1 1.1 -0.1 1.1} \
+                -outline gray -linewidth 1 -fill gray -stipple gray25
+            $g marker create polygon \
+                -coords {1.1 -0.1 0.9 -0.1 0.9 1.1 1.1 1.1} \
+                -outline gray -linewidth 1 -fill gray -stipple gray25
+        }
+        gaussian {
+            set min $_value(min)
+            set max $_value(max)
+            set dx [expr {$max - $min}]
+            set realmin [expr {$min - 0.1 * $dx}]
+            set realmax [expr {$max + 0.1 * $dx}]
+            set mean $_value(central)
+            set sig2 [expr {$_value(stddev) * $_value(stddev)}]
+            $g xaxis configure -min $realmin -max $realmax \
+                -majorticks [list $min $mean $max]
+            $g yaxis configure -min 0 -max 1.1
+            set xdata ""
+            set ydata ""
+            for {set n 0} {$n <= 50} {incr n} {
+                set x [expr {($realmax - $realmin) / 50.0 * $n + $realmin}]
+                lappend xdata $x
+                set expon [expr {-0.5 * ($x - $mean) * ($x - $mean) / $sig2}]
+                if {$expon < -200} {
+                    lappend ydata 0.0
+                } else {
+                    lappend ydata [expr {exp($expon)}]
+                }
+            }
+            $g element create bellcurve \
+                -xdata $xdata -ydata $ydata \
+                -color $itk_option(-foreground) -symbol "" \
+                -areaforeground $itk_option(-fillcolor) -areapattern solid
+
+            # left/right limits
+            set x0m [expr {$min - 0.2 * $dx}]
+            set x0 $min
+            set x1 $max
+            set x1p [expr {$max + 0.2 * $dx}]
+            $g marker create polygon \
+                -coords [list $x0m -0.1 $x0 -0.1 $x0 1.2 $x0m 1.2] \
+                -outline gray -linewidth 1 -fill gray -stipple gray25
+            $g marker create polygon \
+                -coords [list $x1p -0.1 $x1 -0.1 $x1 1.2 $x1p 1.2] \
+                -outline gray -linewidth 1 -fill gray -stipple gray25
+
+            # lines for standard deviation
+            set x0 [expr {$_value(central)-$_value(stddev)}]
+            set x1 [expr {$_value(central)+$_value(stddev)}]
+            $g marker create line \
+                -coords [list $x0 -0.1 $x0 1.2] -linewidth 1 \
+                -outline gray -dashes 2
+            $g marker create line \
+                -coords [list $x1 -0.1 $x1 1.2] -linewidth 1 \
+                -outline gray -dashes 2
+        }
+        custom {
+        }
+        default {
+            error "don't know how to redraw for mode \"$_mode\""
+        }
+    }
+}
+
+# ----------------------------------------------------------------------
+# USAGE: _axisLabels <which> <graph> <val>
+#
+# Used internally to generate axis labels for the x- and y-axes of
+# the graph.  The y-axis doesn't usually have labels since the values
+# aren't meaningful.  The x-axis should show values according to the
+# current mode of input.
+# ----------------------------------------------------------------------
+itcl::body Rappture::ProbDistEditor::_axisLabels {which graph val} {
+    switch -- $which {
+        xaxis {
+            switch -- $_mode {
+                exact {
+                    if {$val == 0.5} {
+                        return $_value(central)
+                    }
+                    return ""
+                }
+                uniform {
+                    if {$val == 0.1} {
+                        return [expr {$_value(min) < $_value(max)
+                            ? $_value(min) : $_value(max)}]
+                    } elseif {$val == 0.9} {
+                        return [expr {$_value(min) > $_value(max)
+                            ? $_value(min) : $_value(max)}]
+                    }
+                    return ""
+                }
+                gaussian {
+                    return $val
+                }
+            }
+        }
+        yaxis {
+            return ""  ;# no labels for y-axis values
+        }
+    }
+}
+
+# ----------------------------------------------------------------------
+# USAGE: _apply bindings <widget>
+# USAGE: _apply value <widget>
+# USAGE: _apply finalize
+#
+# Called automatically whenever a value is edited to check/apply the
+# value and redraw the PDF plot.  If the value is bad, then it is
+# reloaded for editing.  Otherwise, it is applied.
+# ----------------------------------------------------------------------
+itcl::body Rappture::ProbDistEditor::_apply {op {widget ""}} {
+    puts "_apply $op $widget"
+    if {$op != "bindings"} {
+        # need this for value/finalize
+        array set w2uvalue [list \
+            $itk_component(exactvals).val _uvalue(central) \
+            $itk_component(uniformvals).min _uvalue(min) \
+            $itk_component(uniformvals).max _uvalue(max) \
+            $itk_component(gaussianvals).mean _uvalue(central) \
+            $itk_component(gaussianvals).stddev _uvalue(stddev) \
+            $itk_component(gaussianvals).min _uvalue(min) \
+            $itk_component(gaussianvals).max _uvalue(max) \
+        ]
+        array set w2value [list \
+            $itk_component(exactvals).val _value(central) \
+            $itk_component(uniformvals).min _value(min) \
+            $itk_component(uniformvals).max _value(max) \
+            $itk_component(gaussianvals).mean _value(central) \
+            $itk_component(gaussianvals).stddev _value(stddev) \
+            $itk_component(gaussianvals).min _value(min) \
+            $itk_component(gaussianvals).max _value(max) \
+        ]
+    }
+
+    if {$op == "finalize"} {
+        # one of our widgets has focus?
+        set widget [focus]
+        if {![info exists w2value($widget)]} {
+            # nope -- nevermind, nothing to do
+            return
+        }
+        # yes -- continue onward trying to finalize the value in that widget
+        set op "value"
+    }
+
+    switch -- $op {
+        bindings {
+            bind $widget <KeyPress-Tab> [itcl::code $this _apply value %W]
+            bind $widget <KeyPress-Return> [itcl::code $this _apply value %W]
+            bind $widget <FocusOut> [itcl::code $this _apply value %W]
+        }
+        value {
+            set var $w2value($widget)
+            set uvar $w2uvalue($widget)
+            if {$_units == ""} {
+                set newval [$widget get]
+            } else {
+                set newval [Rappture::Units::convert [$widget get] -context $_units]
+            }
+            if {[catch {Rappture::Units::mcheck_range $newval $_umin $_umax $_units} err]} {
+                # oops! value is bad -- edit again
+                bell
+                Rappture::Tooltip::cue $widget $err
+                $widget delete 0 end
+                $widget insert end [set $var]
+                $widget select from 0
+                $widget select to end
+                focus $widget
+                return -code break  ;# stop other bindings like tab-traversal
+            }
+            $widget delete 0 end
+            $widget insert end $newval
+            set $uvar $newval
+
+            if {[catch {Rappture::Units::convert $newval -units off} nvar]} {
+                set nvar $newval
+            }
+            set $var $nvar
+
+            $_dispatcher event -idle !redraw
+        }
+        default {
+            error "bad option \"$opt\": should be bindings, value"
+        }
+    }
+}
+
+# ----------------------------------------------------------------------
+# CONFIGURATION OPTION: -fillcolor
+# ----------------------------------------------------------------------
+itcl::configbody Rappture::ProbDistEditor::fillcolor {
+    $_dispatcher event -idle !redraw
+}
Index: /branches/uq/gui/scripts/spectrum.tcl
===================================================================
--- /branches/uq/gui/scripts/spectrum.tcl	(revision 5028)
+++ /branches/uq/gui/scripts/spectrum.tcl	(revision 5029)
@@ -1,3 +1,3 @@
-# -*- mode: tcl; indent-tabs-mode: nil -*- 
+# -*- mode: tcl; indent-tabs-mode: nil -*-
 # ----------------------------------------------------------------------
 #  COMPONENT: spectrum - maps a range of real values onto a color
@@ -41,5 +41,5 @@
     private variable _specw0 0      ;# wavelength for minimum
 }
-                                                                                
+
 # ----------------------------------------------------------------------
 # CONSTRUCTOR
@@ -80,5 +80,5 @@
             set val1 [lindex $args 2]
             set color1 [string trimright [lindex $args 3] "nm"]
-            
+
             if {"" != $units} {
                 set val0 [Rappture::Units::convert $val0 \
@@ -176,4 +176,5 @@
 # ----------------------------------------------------------------------
 itcl::body Rappture::Spectrum::get {args} {
+    puts "Spectrum::get $args"
     if {[llength $args] == 0} {
         set rlist ""
@@ -199,9 +200,34 @@
 
     set value [lindex $args 0]
-    if {$units != ""} {
-        set value [Rappture::Units::convert $value \
-            -context $units -to $units -units off]
-    }
-
+
+    puts "SPECTRUN GET value=$value units=$units"
+
+    switch -- [lindex $value 0] {
+        gaussian {
+            set value [lindex $value 1]
+            if {$units != ""} {
+                set value [Rappture::Units::convert $value \
+                -context $units -to $units -units off]
+            }
+        }
+        uniform {
+            set min [lindex $value 1]
+            set max [lindex $value 2]
+            if {$units != ""} {
+                set min [Rappture::Units::convert $min \
+                -context $units -to $units -units off]
+                set max [Rappture::Units::convert $max \
+                -context $units -to $units -units off]
+            }
+            set value [expr {0.5 * ($min + $max)}]
+        }
+        default {
+            if {$units != ""} {
+                set value [Rappture::Units::convert $value \
+                -context $units -to $units -units off]
+            }
+        }
+    }
+    puts "SPECTRUN GET NEW value=$value what=$what"
     switch -- $what {
         -color {
Index: /branches/uq/gui/scripts/tempgauge.tcl
===================================================================
--- /branches/uq/gui/scripts/tempgauge.tcl	(revision 5028)
+++ /branches/uq/gui/scripts/tempgauge.tcl	(revision 5029)
@@ -1,3 +1,3 @@
-# -*- mode: tcl; indent-tabs-mode: nil -*- 
+# -*- mode: tcl; indent-tabs-mode: nil -*-
 # ----------------------------------------------------------------------
 #  COMPONENT: tempgauge - gauge for temperature values
@@ -73,5 +73,7 @@
 
     if {"" != $itk_option(-spectrum)} {
+        puts "TemperatureGauge"
         set color [$itk_option(-spectrum) get [value]]
+        puts "TemperatureGauge: color=$color"
         set frac [$itk_option(-spectrum) get -fraction [value]]
     } else {
Index: /branches/uq/gui/scripts/tool.tcl
===================================================================
--- /branches/uq/gui/scripts/tool.tcl	(revision 5028)
+++ /branches/uq/gui/scripts/tool.tcl	(revision 5029)
@@ -1,3 +1,3 @@
-# -*- mode: tcl; indent-tabs-mode: nil -*- 
+# -*- mode: tcl; indent-tabs-mode: nil -*-
 # ----------------------------------------------------------------------
 #  COMPONENT: tool - represents an entire tool
@@ -31,4 +31,5 @@
     public method run {args} {
         sync  ;# sync all widget values to XML
+        puts "Tool $_task run $args"
         eval $_task run $args
     }
@@ -52,4 +53,6 @@
 # ----------------------------------------------------------------------
 itcl::body Rappture::Tool::constructor {xmlobj installdir} {
+    puts "Tool Init"
+
     if {![Rappture::library isvalid $xmlobj]} {
         error "bad value \"$xmlobj\": should be Rappture::Library"
Index: /branches/uq/gui/scripts/units.tcl
===================================================================
--- /branches/uq/gui/scripts/units.tcl	(revision 5028)
+++ /branches/uq/gui/scripts/units.tcl	(revision 5029)
@@ -1,3 +1,3 @@
-# -*- mode: tcl; indent-tabs-mode: nil -*- 
+# -*- mode: tcl; indent-tabs-mode: nil -*-
 # ----------------------------------------------------------------------
 #  COMPONENT: units - mechanism for converting numbers with units
@@ -61,4 +61,167 @@
 }
 
+
+# ----------------------------------------------------------------------
+# USAGE: mcheck_range value {min ""} {max ""}
+#
+# Checks a value or PDF to determine if is is in a required range.
+# Automatically does unit conversion if necessary.
+# Returns value if OK.  Error if out-of-range
+# Examples:
+#    [mcheck_range "gaussian 0C 1C" 200K 500K] returns 1
+#    [mcheck_range "uniform 100 200" 150 250] returns 0
+#    [mcheck_range 100 0 200] returns 1
+# ----------------------------------------------------------------------
+
+proc Rappture::Units::_check_range {value min max units} {
+    # make sure the value has units
+    if {$units != ""} {
+        set value [Rappture::Units::convert $value -context $units]
+        # for comparisons, remove units
+        set nv [Rappture::Units::convert $value -units off]
+        # get the units for the value
+        set newunits [Rappture::Units::Search::for $value]
+    } else {
+        set nv $value
+    }
+
+    if {"" != $min} {
+        if {"" != $units} {
+            # compute the minimum in the new units
+            set minv [Rappture::Units::convert $min -to $newunits -units off]
+            # same, but include units for printing
+            set convMinVal [Rappture::Units::convert $min -to $newunits]
+        } else {
+            set minv $min
+            set convMinVal $min
+        }
+        if {$nv < $minv} {
+            error "Minimum value allowed here is $convMinVal"
+        }
+    }
+    if {"" != $max} {
+        if {"" != $units} {
+            # compute the maximum in the new units
+            set maxv [Rappture::Units::convert $max -to $newunits -units off]
+            # same, but include units for printing
+            set convMaxVal [Rappture::Units::convert $max -to $newunits]
+        } else {
+            set maxv $max
+            set convMaxVal $max
+        }
+        if {$nv > $maxv} {
+            error "Maximum value allowed here is $convMaxVal"
+        }
+    }
+    return $value
+}
+
+proc Rappture::Units::mcheck_range {value {min ""} {max ""} {units ""}} {
+    puts "mcheck_range $value min=$min max=$max units=$units"
+
+    switch -- [lindex $value 0] {
+        normal -
+        gaussian {
+            # get the mean
+            set mean [_check_range [lindex $value 1] $min $max $units]
+            if {$units == ""} {
+                set dev [lindex $value 2]
+                set ndev $dev
+            } else {
+                set dev [Rappture::Units::convert [lindex $value 2] -context $units]
+                set ndev [Rappture::Units::convert $dev -units off]
+            }
+            if {$ndev <= 0} {
+                error "Deviation must be positive."
+            }
+            return [list gaussian $mean $dev]
+        }
+        uniform {
+            set min [_check_range [lindex $value 1] $min $max $units]
+            set max [_check_range [lindex $value 2] $min $max $units]
+            return [list uniform $min $max]
+        }
+        exact  {
+            return [_check_range [lindex $value 1] $min $max $units]
+        }
+        default {
+            return [_check_range [lindex $value 0] $min $max $units]
+        }
+    }
+}
+
+# ----------------------------------------------------------------------
+# USAGE: mconvert value ?-context units? ?-to units? ?-units on/off?
+#
+# This version of convert() converts multiple values.  Used when the
+# value could be a range or probability density function (PDF).
+# Examples:
+#    gaussian 100k 1k
+#    uniform 0eV 10eV
+#    42
+#    exact 42
+# ----------------------------------------------------------------------
+
+proc Rappture::Units::mconvert {value args} {
+    puts "mconvert $value : $args"
+    array set opts {
+        -context ""
+        -to ""
+        -units "on"
+    }
+
+    set value [split $value]
+
+    switch [lindex $value 0] {
+        normal -
+        gaussian {
+            set valtype gaussian
+            set vals [lrange $value 1 2]
+            set convtype {0 1}
+        }
+        uniform {
+            set valtype uniform
+            set vals [lrange $value 1 2]
+            set convtype {0 0}
+        }
+        exact  {
+            set valtype ""
+            set vals [lindex $value 1]
+            set convtype {0}
+        }
+        default {
+            set valtype ""
+            set vals $value
+            set convtype {0}
+        }
+    }
+
+    foreach {key val} $args {
+        if {![info exists opts($key)]} {
+            error "bad option \"$key\": should be [join [lsort [array names opts]] {, }]"
+        }
+        set opts($key) $val
+    }
+
+    set newval $valtype
+    foreach val $vals ctype $convtype {
+        if {$ctype == 1} {
+            # This code handles unit conversion for deltas (changes).
+            # For example, if we want a standard deviation of 10C converted
+            # to Kelvin, that is 10K, NOT a standard deviation of 283.15K.
+            set units [Rappture::Units::Search::for $val]
+            set base [eval Rappture::Units::convert 0$units $args -units off]
+            set new [eval Rappture::Units::convert $val $args -units off]
+            set delta [expr $new - $base]
+            set val $delta$opts(-to)
+        }
+        # tcl 8.5 allows us to do this:
+        # lappend newval [Rappture::Units::convert $val {*}$args]
+        # but we are using tcl8.4 so we use eval :^(
+        lappend newval [eval Rappture::Units::convert $val $args]
+    }
+    return $newval
+}
+
 # ----------------------------------------------------------------------
 # USAGE: convert value ?-context units? ?-to units? ?-units on/off?
@@ -70,54 +233,7 @@
 # current system.
 # ----------------------------------------------------------------------
-proc Rappture::Units::convert {value args} {
-    array set opts {
-        -context ""
-        -to ""
-        -units "on"
-    }
-    foreach {key val} $args {
-        if {![info exists opts($key)]} {
-            error "bad option \"$key\": should be [join [lsort [array names opts]] {, }]"
-        }
-        set opts($key) $val
-    }
-
-    #
-    # Parse the value into the number part and the units part.
-    #
-    set value [string trim $value]
-    if {![regexp {^([-+]?[0-9]+\.?([0-9]+)?([eEdD][-+]?[0-9]+)?) *(/?[a-zA-Z]+[0-9]*)?$} $value match number dummy1 dummy2 units]} {
-        set mesg "bad value \"$value\": should be real number with units"
-        if {$opts(-context) != ""} {
-            append mesg " of [Rappture::Units::description $opts(-context)]"
-        }
-        error $mesg
-    }
-    if {$units == ""} {
-        set units $opts(-context)
-    }
-
-    #
-    # Try to find the object representing the current system of units.
-    #
-    set units [Rappture::Units::System::regularize $units]
-    set oldsys [Rappture::Units::System::for $units]
-    if {$oldsys == ""} {
-        set mesg "value \"$value\" has unrecognized units"
-        if {$opts(-context) != ""} {
-            append mesg ".\nShould be units of [Rappture::Units::description $opts(-context)]"
-        }
-        error $mesg
-    }
-
-    #
-    # Convert the number to the new system of units.
-    #
-    if {$opts(-to) == ""} {
-        # no units -- return the number as is
-        return "$number$units"
-    }
-    return [$oldsys convert "$number$units" $opts(-to) $opts(-units)]
-}
+# proc Rappture::Units::convert {value args} {}
+# Actual implementation is in rappture/lang/tcl/src/RpUnitsTclInterface.cc.
+
 
 # ----------------------------------------------------------------------
@@ -128,16 +244,7 @@
 # along with a list of all compatible systems.
 # ----------------------------------------------------------------------
-proc Rappture::Units::description {units} {
-    set sys [Rappture::Units::System::for $units]
-    if {$sys == ""} {
-        return ""
-    }
-    set mesg [$sys cget -type]
-    set ulist [Rappture::Units::System::all $units]
-    if {"" != $ulist} {
-        append mesg " ([join $ulist {, }])"
-    }
-    return $mesg
-}
+# proc Rappture::Units::description {units} {}
+# Actual implementation is in rappture/lang/tcl/src/RpUnitsTclInterface.cc.
+
 
 # ----------------------------------------------------------------------
@@ -154,6 +261,8 @@
     private variable _system ""  ;# this system of units
 
-    public proc for {units}
-    public proc all {units}
+    # These are in rappture/lang/tcl/src/RpUnitsTclInterface.cc.
+    # public proc for {units}
+    # public proc all {units}
+
     public proc regularize {units}
 
@@ -361,49 +470,7 @@
 # if there is no system that matches the units string.
 # ----------------------------------------------------------------------
-itcl::body Rappture::Units::System::for {units} {
-    #
-    # See if the units are a recognized system.  If not, then try to
-    # extract any metric prefix and see if what's left is a recognized
-    # system.  If all else fails, see if we can find a system without
-    # the exact capitalization.  The user might say "25c" instead of
-    # "25C".  Try to allow that.
-    #
-    if {[info exists _base($units)]} {
-        return $_base($units)
-    } else {
-        set orig $units
-        if {[regexp {^(/?)[cCmMuUnNpPfFaAkKgGtT](.+)$} $units match slash tail]} {
-            set base "$slash$tail"
-            if {[info exists _base($base)]} {
-                set sys $_base($base)
-                if {[$sys cget -metric]} {
-                    return $sys
-                }
-            }
-
-            # check the base part for improper capitalization below...
-            set units $base
-        }
-
-        set matching ""
-        foreach u [array names _base] {
-            if {[string equal -nocase $u $units]} {
-                lappend matching $_base($u)
-            }
-        }
-        if {[llength $matching] == 1} {
-            set sys [lindex $matching 0]
-            #
-            # If we got rid of a metric prefix above, make sure
-            # that the system is metric.  If not, then we don't
-            # have a match.
-            #
-            if {[string equal $units $orig] || [$sys cget -metric]} {
-                return $sys
-            }
-        }
-    }
-    return ""
-}
+# itcl::body Rappture::Units::System::for {units} {}
+# Actual implementation is in rappture/lang/tcl/src/RpUnitsTclInterface.cc.
+
 
 # ----------------------------------------------------------------------
@@ -414,26 +481,7 @@
 # relationships that lead to the same base system.
 # ----------------------------------------------------------------------
-itcl::body Rappture::Units::System::all {units} {
-    set sys [Rappture::Units::System::for $units]
-    if {$sys == ""} {
-        return ""
-    }
-
-    if {"" != [$sys cget -basis]} {
-        set basis [lindex [$sys cget -basis] 0]
-    } else {
-        set basis $units
-    }
-
-    set ulist $basis
-    foreach u [array names _base] {
-        set obj $_base($u)
-        set b [lindex [$obj cget -basis] 0]
-        if {$b == $basis} {
-            lappend ulist $u
-        }
-    }
-    return $ulist
-}
+# itcl::body Rappture::Units::System::all {units} {}
+# Actual implementation is in rappture/lang/tcl/src/RpUnitsTclInterface.cc.
+
 
 # ----------------------------------------------------------------------
Index: /branches/uq/lang/tcl/scripts/library.tcl
===================================================================
--- /branches/uq/lang/tcl/scripts/library.tcl	(revision 5028)
+++ /branches/uq/lang/tcl/scripts/library.tcl	(revision 5029)
@@ -215,4 +215,5 @@
     public method remove {{path ""}}
     public method xml {{path ""}}
+    public method uq_make_template {}
 
     public method diff {libobj}
@@ -228,5 +229,5 @@
     private variable _root 0       ;# non-zero => this obj owns document
     private variable _document ""  ;# XML DOM tree
-    private variable _node ""      ;# node within 
+    private variable _node ""      ;# node within
 }
 
@@ -1038,2 +1039,25 @@
     return $rlist
 }
+
+
+# FIXME: get units convert. change varlist to have no units
+itcl::body Rappture::LibraryObj::uq_make_template {} {
+    set varlist ""
+    set n [$_node selectNodes /run/input//number]
+    foreach _n $n {
+        set x [$_n selectNodes current/text()]
+        set val [$x nodeValue]
+        if {[string equal -length 8 $val "uniform "] ||
+            [string equal -length 9 $val "gaussian "]} {
+            set unode [$_n selectNodes units/text()]
+            if {"" != $unode} {
+                set units [$unode nodeValue]
+                set val [Rappture::Units::mconvert $val \
+                -context $units -to $units -units off]
+            }
+            $x nodeValue @@[$_n getAttribute id]
+            lappend varlist [list [$_n getAttribute id] $val]
+        }
+    }
+    return $varlist
+}
Index: /branches/uq/lang/tcl/scripts/task.tcl
===================================================================
--- /branches/uq/lang/tcl/scripts/task.tcl	(revision 5028)
+++ /branches/uq/lang/tcl/scripts/task.tcl	(revision 5029)
@@ -1,3 +1,3 @@
-# -*- mode: tcl; indent-tabs-mode: nil -*- 
+# -*- mode: tcl; indent-tabs-mode: nil -*-
 # ----------------------------------------------------------------------
 #  COMPONENT: task - represents the executable part of a tool
@@ -57,4 +57,6 @@
     # default method for -jobstats control
     public proc MiddlewareTime {args}
+
+    public method get_params {varlist csvname uq_type args}
 }
 
@@ -75,4 +77,5 @@
 # ----------------------------------------------------------------------
 itcl::body Rappture::Task::constructor {xmlobj installdir args} {
+    puts "Task Init"
     if {![Rappture::library isvalid $xmlobj]} {
         error "bad value \"$xmlobj\": should be Rappture::Library"
@@ -138,5 +141,5 @@
 itcl::body Rappture::Task::run {args} {
     global env errorInfo
-
+    puts "task run $args"
     #
     # Make sure that we save the proper application name.
@@ -164,13 +167,4 @@
     foreach item {control output error} { set job($item) "" }
 
-    # write out the driver.xml file for the tool
-    set file "driver[pid].xml"
-    set status [catch {
-        set fid [open $file w]
-        puts $fid "<?xml version=\"1.0\"?>"
-        puts $fid [$_xmlobj xml]
-        close $fid
-    } result]
-
     # Set limits for cpu time
     set limit [$_xmlobj get tool.limits.cputime]
@@ -185,121 +179,163 @@
             set limit 10;               # lower bound is 10 seconds.
         }
-    } 
-    Rappture::rlimit set cputime $limit  
+    }
+    Rappture::rlimit set cputime $limit
+
+    # write out the driver.xml file for the tool
+    set file "driver[pid].xml"
+    set status [catch {
+        set fid [open $file w]
+        puts $fid "<?xml version=\"1.0\"?>"
+        puts $fid [$_xmlobj xml]
+        close $fid
+    } result]
+
+    # This will turn the driver xml into a template
+    # and return a list of the UQ variables and their PDFs.
+    set uq_varlist [$_xmlobj uq_make_template]
+
+    if {$uq_varlist != ""} {
+        # write out the template file for submit
+        set tfile "template[pid].xml"
+        set status [catch {
+            set fid [open $tfile w]
+            puts $fid "<?xml version=\"1.0\"?>"
+            puts $fid [$_xmlobj xml]
+            close $fid
+        } result]
+    }
+
+
     # execute the tool using the path from the tool description
     if {$status == 0} {
         set cmd [$_xmlobj get tool.command]
+        puts "1. cmd=$cmd"
         regsub -all @tool $cmd $_installdir cmd
-        regsub -all @driver $cmd $file cmd
-        regsub -all {\\} $cmd {\\\\} cmd
+
+        if {$uq_varlist == ""} {
+            regsub -all @driver $cmd $file cmd
+        } else {
+            regsub -all @driver $cmd $tfile cmd
+        }
         set cmd [string trimleft $cmd " "]
-	if { $cmd == "" } {
-	    puts stderr "cmd is empty"
-	    return [list 1 "Command is empty.\n\nThere is no command specified by\n\n <command>\n </command>\n\nin the tool.xml file."]
-	}
-
-        switch -glob -- [resources -jobprotocol] {
-            "submit*" {
-                # if job_protocol is "submit", then use use submit command
-                set cmd "submit --local $cmd"
-            }
-            "mx" {
-                # metachory submission
-                set cmd "mx $cmd"
-            }
-            "exec" {
-                # default -- nothing special
-            }
-        }
+        puts "2. cmd=$cmd"
+        if { $cmd == "" } {
+            puts stderr "cmd is empty"
+            return [list 1 "Command is empty.\n\nThere is no command specified by\n\n <command>\n </command>\n\nin the tool.xml file."]
+        }
+
+        if {$uq_varlist == ""} {
+            switch -glob -- [resources -jobprotocol] {
+                "submit*" {
+                    # if job_protocol is "submit", then use use submit command
+                    set cmd "submit --local $cmd"
+                }
+                "mx" {
+                    # metachory submission
+                    set cmd "mx $cmd"
+                }
+                "exec" {
+                    # default -- nothing special
+                }
+            }
+        } else {
+            puts "uq_varlist=$uq_varlist"
+            # FIXME. Default to Smolyak level 2, but allow more later.
+            file delete -force puq
+            set params_file [get_params $file $uq_varlist "smolyak" 2]
+            set cmd "submit --runName=puq -l -d $params_file python uq.py $cmd @:$tfile"
+        }
+
 	$_xmlobj put tool.execute $cmd
 
-        # starting job...
-        _log run started
-        Rappture::rusage mark
-
-        if {0 == [string compare -nocase -length 5 $cmd "ECHO "] } {
-            set status 0;
-            set job(output) [string range $cmd 5 end] 
-        } else {
-            set status [catch {
-		set ::Rappture::Task::job(control) ""
-		eval blt::bgexec \
-		    ::Rappture::Task::job(control) \
-		    -keepnewline yes \
-		    -killsignal SIGTERM \
-		    -onoutput [list [itcl::code $this _output]] \
+    puts "cmd=$cmd"
+    # starting job...
+    _log run started
+    Rappture::rusage mark
+
+    if {0 == [string compare -nocase -length 5 $cmd "ECHO "] } {
+        set status 0;
+        set job(output) [string range $cmd 5 end]
+    } else {
+        set status [catch {
+            set ::Rappture::Task::job(control) ""
+            eval blt::bgexec \
+            ::Rappture::Task::job(control) \
+            -keepnewline yes \
+            -killsignal SIGTERM \
+            -onoutput [list [itcl::code $this _output]] \
 		    -output ::Rappture::Task::job(output) \
 		    -error ::Rappture::Task::job(error) \
 		    $cmd
-	    } result]
-
-            if { $status != 0 } {
-		# We're here because the exec-ed program failed 
-		set logmesg $result
-		if { $::Rappture::Task::job(control) ne "" } {
-		    foreach { token pid code mesg } \
-			$::Rappture::Task::job(control) break
-		    if { $token == "EXITED" } {
-			# This means that the program exited normally but
-			# returned a non-zero exitcode.  Consider this an
-			# invalid result from the program.  Append the stderr
-			# from the program to the message.
-                        set logmesg "Program finished: exit code is $code"
-			set result "$logmesg\n\n$::Rappture::Task::job(error)"
-		    } elseif { $token == "abort" }  {
-			# The user pressed the abort button.
-                        set logmesg "Program terminated by user."
-			set result "$logmesg\n\n$::Rappture::Task::job(output)"
-		    } else {
-			# Abnormal termination
-			set logmesg "Abnormal program termination: $mesg"
-			set result "$logmesg\n\n$::Rappture::Task::job(output)"
-		    }
-		}
-                _log run failed [list $logmesg]
-		return [list $status $result]
-            }
-        }
-        # ...job is finished
-        array set times [Rappture::rusage measure]
-
-        if {[resources -jobprotocol] ne "submit"} {
-            set id [$_xmlobj get tool.id]
-            set vers [$_xmlobj get tool.version.application.revision]
-            set simulation simulation
-            if { $id ne "" && $vers ne "" } {
-                set pid [pid]
-                set simulation ${pid}_${id}_r${vers}
-            }
-
-            # need to save job info? then invoke the callback
-            if {[string length $jobstats] > 0} {
-                uplevel #0 $jobstats [list job [incr jobnum] \
-                    event $simulation start $times(start) \
-                    walltime $times(walltime) cputime $times(cputime) \
-                    status $status]
-            }
-
-            #
-            # Scan through stderr channel and look for statements that
-            # represent grid jobs that were executed.  The statements
-            # look like this:
-            #
-            # MiddlewareTime: job=1 event=simulation start=3.001094 ...
-            #
-            set subjobs 0
-            while {[regexp -indices {(^|\n)MiddlewareTime:( +[a-z]+=[^ \n]+)+(\n|$)} $job(error) match]} {
-                foreach {p0 p1} $match break
-                if {[string index $job(error) $p0] == "\n"} { incr p0 }
-
-                catch {unset data}
-                array set data {
-                    job 1
-                    event simulation
-                    start 0
-                    walltime 0
-                    cputime 0
-                    status 0
-                }
+        } result]
+
+        if { $status != 0 } {
+            # We're here because the exec-ed program failed
+            set logmesg $result
+            if { $::Rappture::Task::job(control) ne "" } {
+                foreach { token pid code mesg } \
+                $::Rappture::Task::job(control) break
+                if { $token == "EXITED" } {
+                   # This means that the program exited normally but
+                   # returned a non-zero exitcode.  Consider this an
+                   # invalid result from the program.  Append the stderr
+                   # from the program to the message.
+                   set logmesg "Program finished: exit code is $code"
+                   set result "$logmesg\n\n$::Rappture::Task::job(error)"
+                } elseif { $token == "abort" }  {
+                    # The user pressed the abort button.
+                    set logmesg "Program terminated by user."
+                    set result "$logmesg\n\n$::Rappture::Task::job(output)"
+                } else {
+                    # Abnormal termination
+                    set logmesg "Abnormal program termination: $mesg"
+                    set result "$logmesg\n\n$::Rappture::Task::job(output)"
+                }
+            }
+            _log run failed [list $logmesg]
+            return [list $status $result]
+        }
+    }
+    # ...job is finished
+    array set times [Rappture::rusage measure]
+
+    if {[resources -jobprotocol] ne "submit"} {
+        set id [$_xmlobj get tool.id]
+        set vers [$_xmlobj get tool.version.application.revision]
+        set simulation simulation
+        if { $id ne "" && $vers ne "" } {
+            set pid [pid]
+            set simulation ${pid}_${id}_r${vers}
+        }
+
+        # need to save job info? then invoke the callback
+        if {[string length $jobstats] > 0} {
+            uplevel #0 $jobstats [list job [incr jobnum] \
+            event $simulation start $times(start) \
+            walltime $times(walltime) cputime $times(cputime) \
+            status $status]
+        }
+
+        #
+        # Scan through stderr channel and look for statements that
+        # represent grid jobs that were executed.  The statements
+        # look like this:
+        #
+        # MiddlewareTime: job=1 event=simulation start=3.001094 ...
+        #
+        set subjobs 0
+        while {[regexp -indices {(^|\n)MiddlewareTime:( +[a-z]+=[^ \n]+)+(\n|$)} $job(error) match]} {
+            foreach {p0 p1} $match break
+            if {[string index $job(error) $p0] == "\n"} { incr p0 }
+
+            catch {unset data}
+            array set data {
+                job 1
+                event simulation
+                start 0
+                walltime 0
+                cputime 0
+                status 0
+            }
                 foreach arg [lrange [string range $job(error) $p0 $p1] 1 end] {
                     foreach {key val} [split $arg =] break
@@ -337,5 +373,5 @@
     }
     if {$status == 0} {
-        file delete -force -- $file
+        # file delete -force -- $file
     }
 
@@ -350,8 +386,16 @@
     # a reference to the run.xml file containing results.
     #
+
     if {$status == 0} {
         set result [string trim $job(output)]
+        puts "result=$result"
+        if {$uq_varlist != ""} {
+            file delete -force -- new.xml
+            exec puq_analyze.py puq_[pid].hdf5
+            append result "\n" "=RAPPTURE-RUN=>new.xml"
+        }
         if {[regexp {=RAPPTURE-RUN=>([^\n]+)} $result match file]} {
             set status [catch {Rappture::library $file} result]
+            puts "STATUS=$status"
             if {$status == 0} {
                 # add cputime info to run.xml file
@@ -381,5 +425,5 @@
             if {$status == 0 && $rdir ne ""} {
                 catch {
-                    file delete -force -- $file
+                    # file delete -force -- $file
                     if {![file exists $rdir]} {
                         _mkdir $rdir
@@ -393,5 +437,5 @@
             } else {
                 # don't keep the file
-                file delete -force -- $file
+                # file delete -force -- $file
             }
         } else {
@@ -518,2 +562,43 @@
     puts stderr $line
 }
+
+
+#
+# Send the list of parameters to a python program so it can call PUQ
+# and get a CSV file containing the parameter values to use for the runs.
+itcl::body Rappture::Task::get_params {dfile varlist uq_type args} {
+
+    # convert tcl list of variables to json so python can read it
+    proc varlist2py {inlist} {
+        set ovar "\["
+        set first 1
+        foreach a $inlist {
+            foreach {var val} $a break
+            if {$first == 1} {
+                append ovar \[\"$var\",
+                set first 0
+            } else {
+                append ovar \],\[\"$var\",
+            }
+            switch [lindex $val 0] {
+                gaussian {
+                    append ovar "\[\"gaussian\",[lindex $val 1],[lindex $val 2]\]"
+                }
+                uniform {
+                    append ovar "\[\"uniform\",[lindex $val 1],[lindex $val 2]\]"
+                }
+                default {
+                    append ovar $val
+                }
+            }
+        }
+        append ovar "\]\]"
+        return $ovar
+    }
+
+    puts "varlist=$varlist"
+    set varlist [varlist2py $varlist]
+    set pid [pid]
+    exec get_params.py $dfile $pid $varlist $uq_type $args
+    return params[pid].csv
+}
Index: /branches/uq/lang/tcl/scripts/units.tcl
===================================================================
--- /branches/uq/lang/tcl/scripts/units.tcl	(revision 5028)
+++ /branches/uq/lang/tcl/scripts/units.tcl	(revision 5029)
@@ -1,2 +1,3 @@
+# -*- mode: tcl; indent-tabs-mode: nil -*-
 # ----------------------------------------------------------------------
 #  COMPONENT: units - mechanism for converting numbers with units
@@ -60,4 +61,167 @@
 }
 
+
+# ----------------------------------------------------------------------
+# USAGE: mcheck_range value {min ""} {max ""}
+#
+# Checks a value or PDF to determine if is is in a required range.
+# Automatically does unit conversion if necessary.
+# Returns value if OK.  Error if out-of-range
+# Examples:
+#    [mcheck_range "gaussian 0C 1C" 200K 500K] returns 1
+#    [mcheck_range "uniform 100 200" 150 250] returns 0
+#    [mcheck_range 100 0 200] returns 1
+# ----------------------------------------------------------------------
+
+proc Rappture::Units::_check_range {value min max units} {
+    # make sure the value has units
+    if {$units != ""} {
+        set value [Rappture::Units::convert $value -context $units]
+        # for comparisons, remove units
+        set nv [Rappture::Units::convert $value -units off]
+        # get the units for the value
+        set newunits [Rappture::Units::Search::for $value]
+    } else {
+        set nv $value
+    }
+
+    if {"" != $min} {
+        if {"" != $units} {
+            # compute the minimum in the new units
+            set minv [Rappture::Units::convert $min -to $newunits -units off]
+            # same, but include units for printing
+            set convMinVal [Rappture::Units::convert $min -to $newunits]
+        } else {
+            set minv $min
+            set convMinVal $min
+        }
+        if {$nv < $minv} {
+            error "Minimum value allowed here is $convMinVal"
+        }
+    }
+    if {"" != $max} {
+        if {"" != $units} {
+            # compute the maximum in the new units
+            set maxv [Rappture::Units::convert $max -to $newunits -units off]
+            # same, but include units for printing
+            set convMaxVal [Rappture::Units::convert $max -to $newunits]
+        } else {
+            set maxv $max
+            set convMaxVal $max
+        }
+        if {$nv > $maxv} {
+            error "Maximum value allowed here is $convMaxVal"
+        }
+    }
+    return $value
+}
+
+proc Rappture::Units::mcheck_range {value {min ""} {max ""} {units ""}} {
+    puts "mcheck_range $value min=$min max=$max units=$units"
+
+    switch -- [lindex $value 0] {
+        normal -
+        gaussian {
+            # get the mean
+            set mean [_check_range [lindex $value 1] $min $max $units]
+            if {$units == ""} {
+                set dev [lindex $value 2]
+                set ndev $dev
+            } else {
+                set dev [Rappture::Units::convert [lindex $value 2] -context $units]
+                set ndev [Rappture::Units::convert $dev -units off]
+            }
+            if {$ndev <= 0} {
+                error "Deviation must be positive."
+            }
+            return [list gaussian $mean $dev]
+        }
+        uniform {
+            set min [_check_range [lindex $value 1] $min $max $units]
+            set max [_check_range [lindex $value 2] $min $max $units]
+            return [list uniform $min $max]
+        }
+        exact  {
+            return [_check_range [lindex $value 1] $min $max $units]
+        }
+        default {
+            return [_check_range [lindex $value 0] $min $max $units]
+        }
+    }
+}
+
+# ----------------------------------------------------------------------
+# USAGE: mconvert value ?-context units? ?-to units? ?-units on/off?
+#
+# This version of convert() converts multiple values.  Used when the
+# value could be a range or probability density function (PDF).
+# Examples:
+#    gaussian 100k 1k
+#    uniform 0eV 10eV
+#    42
+#    exact 42
+# ----------------------------------------------------------------------
+
+proc Rappture::Units::mconvert {value args} {
+    puts "mconvert $value : $args"
+    array set opts {
+        -context ""
+        -to ""
+        -units "on"
+    }
+
+    set value [split $value]
+
+    switch [lindex $value 0] {
+        normal -
+        gaussian {
+            set valtype gaussian
+            set vals [lrange $value 1 2]
+            set convtype {0 1}
+        }
+        uniform {
+            set valtype uniform
+            set vals [lrange $value 1 2]
+            set convtype {0 0}
+        }
+        exact  {
+            set valtype ""
+            set vals [lindex $value 1]
+            set convtype {0}
+        }
+        default {
+            set valtype ""
+            set vals $value
+            set convtype {0}
+        }
+    }
+
+    foreach {key val} $args {
+        if {![info exists opts($key)]} {
+            error "bad option \"$key\": should be [join [lsort [array names opts]] {, }]"
+        }
+        set opts($key) $val
+    }
+
+    set newval $valtype
+    foreach val $vals ctype $convtype {
+        if {$ctype == 1} {
+            # This code handles unit conversion for deltas (changes).
+            # For example, if we want a standard deviation of 10C converted
+            # to Kelvin, that is 10K, NOT a standard deviation of 283.15K.
+            set units [Rappture::Units::Search::for $val]
+            set base [eval Rappture::Units::convert 0$units $args -units off]
+            set new [eval Rappture::Units::convert $val $args -units off]
+            set delta [expr $new - $base]
+            set val $delta$opts(-to)
+        }
+        # tcl 8.5 allows us to do this:
+        # lappend newval [Rappture::Units::convert $val {*}$args]
+        # but we are using tcl8.4 so we use eval :^(
+        lappend newval [eval Rappture::Units::convert $val $args]
+    }
+    return $newval
+}
+
 # ----------------------------------------------------------------------
 # USAGE: convert value ?-context units? ?-to units? ?-units on/off?
@@ -69,54 +233,7 @@
 # current system.
 # ----------------------------------------------------------------------
-proc Rappture::Units::convert {value args} {
-    array set opts {
-        -context ""
-        -to ""
-        -units "on"
-    }
-    foreach {key val} $args {
-        if {![info exists opts($key)]} {
-            error "bad option \"$key\": should be [join [lsort [array names opts]] {, }]"
-        }
-        set opts($key) $val
-    }
-
-    #
-    # Parse the value into the number part and the units part.
-    #
-    set value [string trim $value]
-    if {![regexp {^([-+]?[0-9]+\.?([0-9]+)?([eEdD][-+]?[0-9]+)?) *(/?[a-zA-Z]+[0-9]*)?$} $value match number dummy1 dummy2 units]} {
-        set mesg "bad value \"$value\": should be real number with units"
-        if {$opts(-context) != ""} {
-            append mesg " of [Rappture::Units::description $opts(-context)]"
-        }
-        error $mesg
-    }
-    if {$units == ""} {
-        set units $opts(-context)
-    }
-
-    #
-    # Try to find the object representing the current system of units.
-    #
-    set units [Rappture::Units::System::regularize $units]
-    set oldsys [Rappture::Units::System::for $units]
-    if {$oldsys == ""} {
-        set mesg "value \"$value\" has unrecognized units"
-        if {$opts(-context) != ""} {
-            append mesg ".\nShould be units of [Rappture::Units::description $opts(-context)]"
-        }
-        error $mesg
-    }
-
-    #
-    # Convert the number to the new system of units.
-    #
-    if {$opts(-to) == ""} {
-        # no units -- return the number as is
-        return "$number$units"
-    }
-    return [$oldsys convert "$number$units" $opts(-to) $opts(-units)]
-}
+# proc Rappture::Units::convert {value args} {}
+# Actual implementation is in rappture/lang/tcl/src/RpUnitsTclInterface.cc.
+
 
 # ----------------------------------------------------------------------
@@ -127,16 +244,7 @@
 # along with a list of all compatible systems.
 # ----------------------------------------------------------------------
-proc Rappture::Units::description {units} {
-    set sys [Rappture::Units::System::for $units]
-    if {$sys == ""} {
-        return ""
-    }
-    set mesg [$sys cget -type]
-    set ulist [Rappture::Units::System::all $units]
-    if {"" != $ulist} {
-        append mesg " ([join $ulist {, }])"
-    }
-    return $mesg
-}
+# proc Rappture::Units::description {units} {}
+# Actual implementation is in rappture/lang/tcl/src/RpUnitsTclInterface.cc.
+
 
 # ----------------------------------------------------------------------
@@ -153,6 +261,8 @@
     private variable _system ""  ;# this system of units
 
-    public proc for {units}
-    public proc all {units}
+    # These are in rappture/lang/tcl/src/RpUnitsTclInterface.cc.
+    # public proc for {units}
+    # public proc all {units}
+
     public proc regularize {units}
 
@@ -360,49 +470,7 @@
 # if there is no system that matches the units string.
 # ----------------------------------------------------------------------
-itcl::body Rappture::Units::System::for {units} {
-    #
-    # See if the units are a recognized system.  If not, then try to
-    # extract any metric prefix and see if what's left is a recognized
-    # system.  If all else fails, see if we can find a system without
-    # the exact capitalization.  The user might say "25c" instead of
-    # "25C".  Try to allow that.
-    #
-    if {[info exists _base($units)]} {
-        return $_base($units)
-    } else {
-        set orig $units
-        if {[regexp {^(/?)[cCmMuUnNpPfFaAkKgGtT](.+)$} $units match slash tail]} {
-            set base "$slash$tail"
-            if {[info exists _base($base)]} {
-                set sys $_base($base)
-                if {[$sys cget -metric]} {
-                    return $sys
-                }
-            }
-
-            # check the base part for improper capitalization below...
-            set units $base
-        }
-
-        set matching ""
-        foreach u [array names _base] {
-            if {[string equal -nocase $u $units]} {
-                lappend matching $_base($u)
-            }
-        }
-        if {[llength $matching] == 1} {
-            set sys [lindex $matching 0]
-            #
-            # If we got rid of a metric prefix above, make sure
-            # that the system is metric.  If not, then we don't
-            # have a match.
-            #
-            if {[string equal $units $orig] || [$sys cget -metric]} {
-                return $sys
-            }
-        }
-    }
-    return ""
-}
+# itcl::body Rappture::Units::System::for {units} {}
+# Actual implementation is in rappture/lang/tcl/src/RpUnitsTclInterface.cc.
+
 
 # ----------------------------------------------------------------------
@@ -413,26 +481,7 @@
 # relationships that lead to the same base system.
 # ----------------------------------------------------------------------
-itcl::body Rappture::Units::System::all {units} {
-    set sys [Rappture::Units::System::for $units]
-    if {$sys == ""} {
-        return ""
-    }
-
-    if {"" != [$sys cget -basis]} {
-        set basis [lindex [$sys cget -basis] 0]
-    } else {
-        set basis $units
-    }
-
-    set ulist $basis
-    foreach u [array names _base] {
-        set obj $_base($u)
-        set b [lindex [$obj cget -basis] 0]
-        if {$b == $basis} {
-            lappend ulist $u
-        }
-    }
-    return $ulist
-}
+# itcl::body Rappture::Units::System::all {units} {}
+# Actual implementation is in rappture/lang/tcl/src/RpUnitsTclInterface.cc.
+
 
 # ----------------------------------------------------------------------
Index: /branches/uq/puq/Makefile.in
===================================================================
--- /branches/uq/puq/Makefile.in	(revision 5029)
+++ /branches/uq/puq/Makefile.in	(revision 5029)
@@ -0,0 +1,40 @@
+
+SHELL		= @SHELL@
+TCLSH		= @TCLSH@
+srcdir		= @srcdir@
+prefix		= @prefix@
+exec_prefix	= @exec_prefix@
+bindir		= @bindir@
+libdir		= @libdir@
+datadir		= @datadir@
+datarootdir	= @datarootdir@
+mandir		= @mandir@
+includedir	= @includedir@
+
+pkgdatadir	= $(datadir)/$(PKG_DIR)
+pkglibdir	= $(libdir)/$(PKG_DIR)
+pkgincludedir	= $(includedir)/$(PKG_DIR)
+top_builddir	= .
+
+MKDIR_P		= @MKDIR_P@
+INSTALL		= @INSTALL@
+
+SCRIPTS	= $(srcdir)/get_params.py \
+        $(srcdir)/puq_analyze.py
+
+.PHONY: all install clean distclean
+
+all:
+
+install: all
+	$(MKDIR_P) -m 0755 $(bindir)
+	@for i in $(SCRIPTS); do \
+	    echo "Installing $$i" ; \
+	    $(INSTALL) -m 0555 $$i $(bindir) ; \
+	done
+
+clean:
+
+distclean: clean
+	$(RM) Makefile *~
+
Index: /branches/uq/puq/get_params.py
===================================================================
--- /branches/uq/puq/get_params.py	(revision 5029)
+++ /branches/uq/puq/get_params.py	(revision 5029)
@@ -0,0 +1,45 @@
+#!/usr/bin/env python
+from puq import *
+import csv, sys, os
+import numpy as np
+from puq.jpickle import unpickle
+
+dfile, pid, varlist, uq_type, args = sys.argv[1:]
+cvsname = "params%s.csv" % pid
+hname = "puq_%s.hdf5" % pid
+
+
+sys.stdout = open("gp.log", 'w')
+sys.stderr = open("gp.err", 'w')
+
+print sys.argv[1:]
+varlist = unpickle(varlist)
+print "varlist=", varlist
+print type(varlist)
+
+v = {}
+for p in varlist:
+    name, dist = p
+    name = str(name)
+    print "name=", name
+    print "dist=", dist
+    if dist[0] == u'gaussian':
+        v[name] = NormalParameter(name, name, mean=dist[1], dev=dist[2])
+    elif dist[0] == u'uniform':
+        v[name] = UniformParameter(name, name, min=dist[1], max=dist[2])
+    else:
+        print "ERROR: Unknown distribution type: %s" % dist[0]
+        sys.exit(1)
+if uq_type == "smolyak":
+    uq = Smolyak(v.values(), args)
+else:
+    print "ERROR: Unknown UQ type: %s" % uq_type
+    os.chdir('..')
+    sys.exit(1)
+
+vals = np.column_stack([p.values for p in uq.params])
+names = ['@@'+str(p.name) for p in uq.params]
+np.savetxt(cvsname, vals, delimiter=',', header=','.join(names), comments='')
+
+sw = Sweep(uq, RapptureHost('puq', dfile), 'test/vel_add.py')
+sw.run(hname, overwrite=True)
Index: /branches/uq/puq/puq_analyze.py
===================================================================
--- /branches/uq/puq/puq_analyze.py	(revision 5029)
+++ /branches/uq/puq/puq_analyze.py	(revision 5029)
@@ -0,0 +1,21 @@
+#!/usr/bin/env python
+from puq import *
+import csv
+import numpy as np
+import sys, os, h5py
+
+
+def load_from_hdf5(name):
+    h5 = h5py.File(name, 'r+')
+    sw = unpickle(h5['private/sweep'].value)
+    sw.fname = os.path.splitext(name)[0]
+    h5.close()
+
+    sw.psweep._sweep = sw
+
+    if hasattr(sw.psweep, 'reinit'):
+        sw.psweep.reinit()
+    return sw
+
+sw = load_from_hdf5(sys.argv[1])
+sw.analyze()
Index: /branches/uq/src/core/RpUnits.cc
===================================================================
--- /branches/uq/src/core/RpUnits.cc	(revision 5028)
+++ /branches/uq/src/core/RpUnits.cc	(revision 5029)
@@ -70,5 +70,5 @@
     exponent = 1;
 
-    // check to see if there is an exponent at the end 
+    // check to see if there is an exponent at the end
     // of the search string
     idx = RpUnits::grabExponent(searchStr, &exponent);
@@ -353,5 +353,5 @@
             }
 
-            // check to see if they are the same basis, 
+            // check to see if they are the same basis,
             // no need to list all of the metric conversions.
             if (basis) {
@@ -493,6 +493,6 @@
 
     // this is kinda the wrong way to get the job done...
-    // how do we only create 1 conversion object and share it between 
-    // atleast two RpUnits objs so that when the RpUnits objs are 
+    // how do we only create 1 conversion object and share it between
+    // atleast two RpUnits objs so that when the RpUnits objs are
     // deleted, we are not trying to delete already deleted memory.
     // so for the sake of safety we get the following few lines of code.
@@ -528,5 +528,5 @@
     // this is kinda the wrong way to get the job done...
     // how do we only create 1 conversion object and share it between at
-    // least two RpUnits objs so that when the RpUnits objs are deleted, 
+    // least two RpUnits objs so that when the RpUnits objs are deleted,
     // we are not trying to delete already deleted memory.
     // so for the sake of safety we get the following few lines of code.
@@ -640,5 +640,5 @@
 /// Retrieve the RpUnits object representing the basis of this object.
 /**
- * Returns a pointer to a RpUnits object which, on success, points to the 
+ * Returns a pointer to a RpUnits object which, on success, points to the
  * RpUnits object that is the basis of the calling object.
  */
@@ -808,7 +808,7 @@
  * across a unit that is unrecognized or can not be interpreted, then it
  * returns error (a non-zero value).
- * 
+ *
  * if &compatList == NULL, no compatible list of units will be generated.
- * this function does not do a good job of placing the available units 
+ * this function does not do a good job of placing the available units
  * back into the original formula. i still need to work on this.
  */
@@ -920,5 +920,5 @@
 
     if ((RPUNITS_ORIG_EXP & flags) == RPUNITS_STRICT_NAME) {
-        // if the user asks for strict naming, 
+        // if the user asks for strict naming,
         // always place the exponent on the name
         name << myExp;
@@ -1114,5 +1114,5 @@
 
         /*
-        // if the exponent != 1,-1 then do a second search 
+        // if the exponent != 1,-1 then do a second search
         // for the unit+exponent string that might be defined.
         // this is to cover the case were we have defined conversions
@@ -1397,5 +1397,5 @@
     // these are conditions where no conversion is needed
     if ( (fromUnitsName.empty()) || (toUnitsName == fromUnitsName) )  {
-        // there were no units in the input 
+        // there were no units in the input
         // string or no conversion needed
         // assume fromUnitsName = toUnitsName
@@ -1508,5 +1508,5 @@
                     toIter = toUnitsList.begin();
 
-                    // raise error that there was an 
+                    // raise error that there was an
                     // unrecognized conversion request
 
@@ -1651,5 +1651,5 @@
     }
 
-    return (std::string(unitText.str())); 
+    return (std::string(unitText.str()));
 
 }
@@ -1701,5 +1701,5 @@
     // trying to avoid the recursive way of converting to the basis.
     // need to rethink this.
-    // 
+    //
     if ( (basis) && (basis->getUnitsName() != toUnit->getUnitsName()) ) {
         value = convert(basis,value,&my_result);
@@ -1711,5 +1711,5 @@
     // find the toUnit in our dictionary.
     // if the toUnits has a basis, we need to search for the basis
-    // and convert between basis' and then convert again back to the 
+    // and convert between basis' and then convert again back to the
     // original unit.
     if ( (toBasis) && (toBasis->getUnitsName() != fromUnit->getUnitsName()) ) {
@@ -1755,13 +1755,13 @@
             // conversion for a two arg conv function pointer
             // need to make this simpler, more logical maybe only allow 2 arg
-            if (       (p->conv->convForwFxnPtr) 
+            if (       (p->conv->convForwFxnPtr)
                     && (! p->conv->convForwFxnPtrDD) ) {
 
                 value = p->conv->convForwFxnPtr(value);
             }
-            else if (  (p->conv->convForwFxnPtrDD) 
+            else if (  (p->conv->convForwFxnPtrDD)
                     && (! p->conv->convForwFxnPtr) ) {
 
-                value = 
+                value =
                     p->conv->convForwFxnPtrDD(value, fromUnit->getExponent());
             }
@@ -1770,5 +1770,5 @@
             // or to the requested unit's basis.
             // if we converted to the requested unit's basis. we need to
-            // do one last conversion from the requested unit's basis back 
+            // do one last conversion from the requested unit's basis back
             // to the requested unit.
             if ( (toBasis) && (toBasis->getUnitsName() != fromUnit->getUnitsName()) ) {
@@ -1783,6 +1783,6 @@
 
             // change the result code to zero, a conversion was performed
-            // (we think)... its ture that it is possible to get to this 
-            // point and have skipped the conversion because the 
+            // (we think)... its ture that it is possible to get to this
+            // point and have skipped the conversion because the
             // conversion object was not properly created...
             // ie. both fxn ptrs were null or neither fxn ptr was null
@@ -1803,13 +1803,13 @@
             // conversion for a two arg conv function pointer
             // need to make this simpler, more logical maybe only allow 2 arg
-            if (       (p->conv->convBackFxnPtr) 
+            if (       (p->conv->convBackFxnPtr)
                     && (! p->conv->convBackFxnPtrDD) ) {
 
                 value = p->conv->convBackFxnPtr(value);
             }
-            else if (  (p->conv->convBackFxnPtrDD) 
+            else if (  (p->conv->convBackFxnPtrDD)
                     && (! p->conv->convBackFxnPtr) ) {
 
-                value = 
+                value =
                     p->conv->convBackFxnPtrDD(value, fromUnit->getExponent());
             }
@@ -1818,5 +1818,5 @@
             // or to the requested unit's basis.
             // if we converted to the requested unit's basis. we need to
-            // do one last conversion from the requested unit's basis back 
+            // do one last conversion from the requested unit's basis back
             // to the requested unit.
             if ( (toBasis) && (toBasis->getUnitsName() != fromUnit->getUnitsName()) ) {
@@ -1831,6 +1831,6 @@
 
             // change the result code to zero, a conversion was performed
-            // (we think)... its ture that it is possible to get to this 
-            // point and have skipped the conversion because the 
+            // (we think)... its ture that it is possible to get to this
+            // point and have skipped the conversion because the
             // conversion object was not properly created...
             // ie. both fxn ptrs were null or neither fxn ptr was null
@@ -1911,5 +1911,5 @@
     // find the toUnit in our dictionary.
     // if the toUnits has a basis, we need to search for the basis
-    // and convert between basis' and then convert again back to the 
+    // and convert between basis' and then convert again back to the
     // original unit.
     if ( (toBasis) && (toBasis->getUnitsName() != fromUnit->getUnitsName()) ) {
@@ -1955,5 +1955,5 @@
             // or to the requested unit's basis.
             // if we converted to the requested unit's basis. we need to
-            // do one last conversion from the requested unit's basis back 
+            // do one last conversion from the requested unit's basis back
             // to the requested unit.
             if ( (toBasis) && (toBasis->getUnitsName() != fromUnit->getUnitsName()) ) {
@@ -1968,6 +1968,6 @@
 
             // change the result code to zero, a conversion was performed
-            // (we think)... its ture that it is possible to get to this 
-            // point and have skipped the conversion because the 
+            // (we think)... its ture that it is possible to get to this
+            // point and have skipped the conversion because the
             // conversion object was not properly created...
             // ie. both fxn ptrs were null or neither fxn ptr was null
@@ -1988,5 +1988,5 @@
             // or to the requested unit's basis.
             // if we converted to the requested unit's basis. we need to
-            // do one last conversion from the requested unit's basis back 
+            // do one last conversion from the requested unit's basis back
             // to the requested unit.
             if ( (toBasis) && (toBasis->getUnitsName() != fromUnit->getUnitsName()) ) {
@@ -2001,6 +2001,6 @@
 
             // change the result code to zero, a conversion was performed
-            // (we think)... its ture that it is possible to get to this 
-            // point and have skipped the conversion because the 
+            // (we think)... its ture that it is possible to get to this
+            // point and have skipped the conversion because the
             // conversion object was not properly created...
             // ie. both fxn ptrs were null or neither fxn ptr was null
@@ -2084,5 +2084,5 @@
     // find the toUnit in our dictionary.
     // if the toUnits has a basis, we need to search for the basis
-    // and convert between basis' and then convert again back to the 
+    // and convert between basis' and then convert again back to the
     // original unit.
     if ( (toBasis) && (toBasis->getUnitsName() != fromUnit->getUnitsName()) ) {
@@ -2148,5 +2148,5 @@
             // or to the requested unit's basis.
             // if we converted to the requested unit's basis. we need to
-            // do one last conversion from the requested unit's basis back 
+            // do one last conversion from the requested unit's basis back
             // to the requested unit.
             if ( (toBasis) && (toBasis->getUnitsName() != fromUnit->getUnitsName()) ) {
@@ -2166,5 +2166,5 @@
             // conversion for a two arg conv function pointer
             // need to make this simpler, more logical maybe only allow 2 arg
-            if (       (p->conv->convBackFxnPtr) 
+            if (       (p->conv->convBackFxnPtr)
                     && (! p->conv->convBackFxnPtrDD) ) {
 
@@ -2184,5 +2184,5 @@
             // or to the requested unit's basis.
             // if we converted to the requested unit's basis. we need to
-            // do one last conversion from the requested unit's basis back 
+            // do one last conversion from the requested unit's basis back
             // to the requested unit.
             if ( (toBasis) && (toBasis->getUnitsName() != fromUnit->getUnitsName()) ) {
@@ -2280,5 +2280,5 @@
 /// Place an RpUnits Object into the Rappture Units Dictionary.
 /**
- * Return whether the inserted key was new with a non-zero 
+ * Return whether the inserted key was new with a non-zero
  * value, or if the key already existed with a value of zero.
  */
@@ -2442,5 +2442,5 @@
 /**********************************************************************/
 // METHOD: addPresetPrefix()
-/// 
+///
 /**
  * Defines the following unit prefixes:
@@ -2543,8 +2543,8 @@
  *   days     (d)
  *
- *   month and year are not included because simple 
+ *   month and year are not included because simple
  *   day->month conversions may be misleading
  *   month->year conversions may be included in the future
- * 
+ *
  * Return codes: 0 success, anything else is error
  */
@@ -3229,5 +3229,5 @@
 /// Convert a std::list<std::string> into a comma delimited std::string
 /**
- * Iterates through a std::list<std::string> and returns a comma 
+ * Iterates through a std::list<std::string> and returns a comma
  * delimited std::string containing the elements of the inputted std::list.
  *
