Changeset 6021 for trunk


Ignore:
Timestamp:
Feb 18, 2016 4:13:14 PM (8 years ago)
Author:
ldelgass
Message:

Merge UQ and fixes from 1.4 branch

Location:
trunk
Files:
1 deleted
46 edited
21 copied

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/Makefile.in

    r5811 r6021  
    4040endif
    4141ifneq ($(ENABLE_GUI),)
    42   TARGETS += gui builder tester examples
     42  TARGETS += gui builder tester examples puq
    4343endif
    4444ifneq ($(HAVE_FFMPEG),)
     
    5757        $(MAKE) -C test all
    5858
    59 install: 
     59install:
    6060        for i in $(TARGETS) ; do \
    6161          $(MAKE) -C $$i install || exit 1 ;\
    6262        done
    6363
    64 clean: 
     64clean:
    6565        for i in $(TARGETS) ; do \
    6666          $(MAKE) -C $$i clean || exit 1 ;\
     
    7373        done
    7474
    75 package: 
     75package:
    7676        tar -C $(pkg_path) -czlf $(rappture_binary_tarfile) $(pkg_name)
    7777
    78 distrib: 
     78distrib:
    7979        $(RM) -r exported
    8080        $(MKDIR_P) -m 0755 exported
  • trunk/configure

    r5999 r6021  
    1021610216
    1021710217
    10218 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"
     10218ac_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"
    1021910219
    1022010220cat >confcache <<\_ACEOF
     
    1104011040    "oldtest/Makefile") CONFIG_FILES="$CONFIG_FILES oldtest/Makefile" ;;
    1104111041    "oldtest/src/Makefile") CONFIG_FILES="$CONFIG_FILES oldtest/src/Makefile" ;;
     11042    "puq/Makefile") CONFIG_FILES="$CONFIG_FILES puq/Makefile" ;;
    1104211043
    1104311044  *) as_fn_error $? "invalid argument: \`$ac_config_target'" "$LINENO" 5;;
  • trunk/configure.in

    r5999 r6021  
    343343  AC_CHECK_FUNCS(av_close_input_file)
    344344  AC_CHECK_FUNCS(avformat_close_input)
    345        
     345
    346346  AC_CHECK_FUNC(avcodec_find_decoder,,
    347347    AC_MSG_ERROR(oops! no av_codec_find_decoder ?!?))
     
    600600    oldtest/Makefile
    601601    oldtest/src/Makefile
     602    puq/Makefile
    602603])
    603604AC_OUTPUT
    604        
     605
  • trunk/examples/app-fermi/python/fermi.py

    r5681 r6021  
    3838# y-axis label, and y-axis units
    3939f12 = rx['output.curve(f12)']  # a shortcut to save typing
    40 f12['label'] = 'Fermi-Dirac Factor'
     40f12['about.label'] = 'Fermi-Dirac Factor'
    4141f12['xaxis.label'] = 'Fermi-Dirac Factor'
    4242f12['yaxis.label'] = 'Energy'
  • trunk/examples/zoo/boolean/Makefile.in

    r3471 r6021  
    1616
    1717FILES           = \
     18                $(srcdir)/boolean.py \
    1819                $(srcdir)/boolean.tcl \
    1920                $(srcdir)/boolean.gif \
  • trunk/examples/zoo/boolean/tool.xml

    r1076 r6021  
    1111  </about>
    1212  <command>
    13     tclsh @tool/boolean.tcl @driver
     13    python @tool/boolean.py @driver
    1414  </command>
    1515</tool>
  • trunk/examples/zoo/enable/Makefile.in

    r3471 r6021  
    1616
    1717FILES           = \
     18                $(srcdir)/enable.py \
    1819                $(srcdir)/enable.tcl \
    1920                $(srcdir)/tool.xml \
  • trunk/examples/zoo/enable/tool.xml

    r1594 r6021  
    1010  </about>
    1111  <command>
    12     tclsh @tool/enable.tcl @driver
     12    python @tool/enable.py @driver
    1313  </command>
    1414</tool>
  • trunk/examples/zoo/field/tool.xml

    r5693 r6021  
    1010  </about>
    1111  <command>
    12     python @tool/field.py @driver
     12    tclsh @tool/field.tcl @driver
    1313  </command>
    1414  <limits>
  • trunk/examples/zoo/group/Makefile.in

    r3471 r6021  
    1616
    1717FILES           = \
     18                $(srcdir)/group.py \
    1819                $(srcdir)/group.tcl \
    1920                $(srcdir)/group1.gif \
  • trunk/examples/zoo/group/tool.xml

    r3642 r6021  
    1212  </about>
    1313  <command>
    14     tclsh @tool/group.tcl @driver
     14    python @tool/group.py @driver
    1515  </command>
    1616</tool>
  • trunk/examples/zoo/image/Makefile.in

    r3471 r6021  
    1616
    1717FILES           = \
     18                $(srcdir)/image.py \
    1819                $(srcdir)/image.tcl \
    1920                $(srcdir)/image1.gif \
  • trunk/examples/zoo/image/tool.xml

    r3645 r6021  
    1010  </about>
    1111  <command>
    12     tclsh @tool/image.tcl @driver
     12    python @tool/image.py @driver
    1313  </command>
    1414</tool>
     
    2828      <diffs>ignore</diffs>
    2929    </about>
    30     <convert>bmp</convert>
    3130  </image>
    3231  <number id="angle">
  • trunk/examples/zoo/integer/Makefile.in

    r3471 r6021  
    1717FILES           = \
    1818                $(srcdir)/integer.gif \
     19                $(srcdir)/integer.py \
    1920                $(srcdir)/integer.tcl \
    2021                $(srcdir)/tool.xml
  • trunk/examples/zoo/integer/tool.xml

    r1587 r6021  
    1111  </about>
    1212  <command>
    13     tclsh @tool/integer.tcl @driver
     13    python @tool/integer.py @driver
    1414  </command>
    1515</tool>
  • trunk/examples/zoo/integer2/Makefile.in

    r3471 r6021  
    1616
    1717FILES           = \
     18                $(srcdir)/integer.py \
    1819                $(srcdir)/integer.tcl \
    1920                $(srcdir)/tool.xml
  • trunk/examples/zoo/integer2/tool.xml

    r1075 r6021  
    77  </about>
    88  <command>
    9     tclsh @tool/integer.tcl @driver
     9    python @tool/integer.py @driver
    1010  </command>
    1111</tool>
  • trunk/examples/zoo/loader/Makefile.in

    r3471 r6021  
    1717FILES           = \
    1818                $(srcdir)/loader.gif \
     19                $(srcdir)/loader.py \
    1920                $(srcdir)/loader.tcl \
    2021                $(srcdir)/loader2.gif \
  • trunk/examples/zoo/loader/tool.xml

    r711 r6021  
    1212  </about>
    1313  <command>
    14     tclsh @tool/loader.tcl @driver
     14    python @tool/loader.py @driver
    1515  </command>
    1616</tool>
  • trunk/examples/zoo/number/tool.xml

    r5681 r6021  
    1010When you click the Simulate button, the input numbers will be used to generate output numbers.
    1111  </about>
     12  <uq>off</uq>
    1213  <command>
    1314    python @tool/number.py @driver
  • trunk/examples/zoo/number2/tool.xml

    r5681 r6021  
    66Each number object has a different color range.
    77  </about>
     8  <uq>false</uq>
    89  <command>
    910    python @tool/number.py @driver
  • trunk/examples/zoo/parallelepiped/Makefile.in

    r3471 r6021  
    1616
    1717FILES           = \
     18                $(srcdir)/parallelepiped.py \
    1819                $(srcdir)/parallelepiped.tcl \
    1920                $(srcdir)/tool.xml
  • trunk/examples/zoo/parallelepiped/tool.xml

    r1957 r6021  
    33    <tool>
    44        <about>Press Simulate to view results.</about>
    5         <command>tclsh @tool/parallelepiped.tcl @driver</command>
     5        <command>python @tool/parallelepiped.py @driver</command>
    66    </tool>
    77    <input>
  • trunk/examples/zoo/sequence/Makefile.in

    r3471 r6021  
    1616
    1717FILES           = \
     18                $(srcdir)/sequence.py \
    1819                $(srcdir)/sequence.tcl \
    1920                $(srcdir)/sequence2.tcl \
  • trunk/examples/zoo/sequence/tool.xml

    r998 r6021  
    1010  </about>
    1111  <command>
    12     tclsh @tool/sequence.tcl @driver
     12    python @tool/sequence.py @driver
    1313  </command>
    1414</tool>
  • trunk/examples/zoo/string/Makefile.in

    r3471 r6021  
    1616
    1717FILES           = \
     18                $(srcdir)/string_test.py \
    1819                $(srcdir)/string.tcl \
    1920                $(srcdir)/string1.gif \
  • trunk/examples/zoo/string/tool.xml

    r1587 r6021  
    1111  </about>
    1212  <command>
    13     tclsh @tool/string.tcl @driver
     13    python @tool/string_test.py @driver
    1414  </command>
    1515</tool>
  • trunk/gui/apps/rappture.use.in

    r4657 r6021  
    11
    22conflict RAPPTURE_CHOICE
     3
     4use -r -e anaconda-2.3.0
     5use -r -e puq-2.2.14
    36
    47desc "The Rappture tool environment (released version)."
  • trunk/gui/scripts/Makefile.in

    r5959 r6021  
    9494                $(srcdir)/periodictable.tcl \
    9595                $(srcdir)/postern.tcl \
     96                $(srcdir)/probdisteditor.tcl \
    9697                $(srcdir)/progress.tcl \
    9798                $(srcdir)/pushbutton.tcl \
    9899                $(srcdir)/radiodial.tcl \
    99100                $(srcdir)/resultset.tcl \
     101                $(srcdir)/response.tcl \
     102                $(srcdir)/responseviewer.tcl \
    100103                $(srcdir)/resultselector.tcl \
    101104                $(srcdir)/resultviewer.tcl \
     
    121124                $(srcdir)/units.tcl \
    122125                $(srcdir)/utils.tcl \
     126                $(srcdir)/uq.tcl \
     127                $(srcdir)/uqcurve.tcl \
     128                $(srcdir)/uqinfo.tcl \
     129                $(srcdir)/uqnotebook.tcl \
    123130                $(srcdir)/valueresult.tcl \
    124131                $(srcdir)/videochooser.tcl \
     
    157164                --outfile tclIndex
    158165
    159 install: all install_scripts install_images 
     166install: all install_scripts install_images
    160167
    161 install_scripts: 
     168install_scripts:
    162169        $(MKDIR_P) -m 0755 $(destdir)
    163170        @for i in $(FILES); do \
    164171            echo "Installing $$i" ; \
    165172            $(INSTALL) -m 0444 $$i $(destdir) ; \
    166         done 
     173        done
    167174        $(INSTALL) -m 0444 tclIndex $(destdir)
    168175
     
    172179            echo "Installing $$i" ; \
    173180            $(INSTALL) -m 0444 $$i $(destdir)/images ; \
    174         done 
     181        done
    175182
    176183clean:
  • trunk/gui/scripts/analyzer.tcl

    r5880 r6021  
    7979    protected method _lammpsToSequence {xmlobj path id child data}
    8080    protected method _trajToSequence {xmlobj {path ""}}
     81    protected method _pop_uq_dialog {win}
     82    protected method _setWaitVariable {state}
     83    protected method _adjust_level {win}
    8184
    8285    private variable _tool ""          ;# belongs to this tool
     
    9295    private variable _lastPlot
    9396    private common job                 ;# array var used for blt::bgexec jobs
     97    private variable _uq_active 0      ;# a UQ variables has been used
     98    private variable _wait_uq 0
    9499}
    95100
     
    328333    }
    329334    pack $itk_component(resultpages) -expand yes -fill both
    330 
    331     set f [$itk_component(results) insert end -fraction 0.1]
     335   set f [$itk_component(results) insert end -fraction 0.1]
    332336    itk_component add resultselector {
    333337        Rappture::ResultSelector $f.rsel -resultset $_resultset \
     
    395399# ----------------------------------------------------------------------
    396400itcl::body Rappture::Analyzer::simulate {args} {
    397     if {$args == "-ifneeded"} {
     401    #puts "simulate args='$args'"
     402
     403    set uq [$_tool get_uq -uq_type smolyak -uq_args 2]
     404
     405    # pop up UQ window
     406    if {[$uq num_runs] > 1} {
     407        set _uq_active 1
     408        set status [$uq run_dialog $itk_component(simulate)]
     409        if {$status == 0} {
     410            # cancelled
     411            return
     412        }
     413        lappend args -uq_type [$uq type]
     414        lappend args -uq_args [$uq args]
     415        # Need to put these UQ values into the driver file
     416        # so the call to resultset::contains will be correct.
     417        set _xml [$_tool xml object]
     418        $_xml put uq.type.current [$uq type]
     419        $_xml put uq.args.current [$uq args]
     420        $_xml put uq.args.about.label "level"
     421        $_xml put uq.args.about.description "Polynomial Degree of Smolyak GPC method."
     422    }
     423    #puts "simulate args=$args"
     424
     425    if {[lindex $args 0] == "-ifneeded"} {
    398426        # check to see if simulation is really needed
    399427        $_tool sync
     
    404432            return
    405433        }
    406         set args ""
     434        set args [lreplace $args 0 0]
    407435    }
    408436
     
    427455
    428456    # execute the job
     457    #puts "$_tool run $args"
     458
    429459    foreach {status result} [eval $_tool run $args] break
    430460
     
    470500}
    471501
     502
    472503# ----------------------------------------------------------------------
    473504# USAGE: reset ?-eventually|-now?
     
    515546        clear
    516547    }
     548    #puts "Analyzer::load"
    517549    $_resultset add $xmlobj
    518550
     
    652684# ----------------------------------------------------------------------
    653685itcl::body Rappture::Analyzer::_plot {args} {
     686    #puts "analyzer::_plot"
    654687    set _plotlist $args
    655688
     
    755788    } elseif {$page != ""} {
    756789        set _lastlabel $name
    757         set win [winfo toplevel $itk_component(hull)]
    758790        $itk_component(resultpages) current $page
    759791        set f [$itk_component(resultpages) page $page]
    760 
    761792        # We don't want to replot if we're using an existing viewer with the
    762793        # the same list of objects to plot.  So track the viewer and the list.
    763794        if { ![info exists _lastPlot($f)] || $_plotlist != $_lastPlot($f) } {
    764795            set _lastPlot($f) $_plotlist
     796            set win [winfo toplevel $itk_component(hull)]
    765797            blt::busy hold $win
     798            #puts "rviewer = $f.rviewer"
     799            #puts "_plotlist = $_plotlist"
    766800            $f.rviewer plot clear
    767801            eval $f.rviewer plot add $_plotlist
    768             blt::busy release [winfo toplevel $itk_component(hull)]
     802            blt::busy release $win
    769803        }
    770804        Rappture::Logger::log output $_label2item($name)
     
    782816# ----------------------------------------------------------------------
    783817itcl::body Rappture::Analyzer::_fixResultSet {args} {
     818    #puts "Analyzer::_fixResultSet $args"
    784819    array set eventData $args
    785820    switch -- $eventData(op) {
     
    794829            set haveresults 0
    795830            foreach item [_reorder [$xmlobj children output]] {
    796                 switch -glob -- $item {
    797                     log* {
    798                         _autoLabel $xmlobj output.$item "Output Log" counters
    799                     }
    800                     number* {
    801                         _autoLabel $xmlobj output.$item "Number" counters
    802                     }
    803                     integer* {
    804                         _autoLabel $xmlobj output.$item "Integer" counters
    805                     }
    806                     mesh* {
    807                         _autoLabel $xmlobj output.$item "Mesh" counters
    808                     }
    809                     string* {
    810                         _autoLabel $xmlobj output.$item "String" counters
    811                     }
    812                     histogram* - curve* - field* {
    813                         _autoLabel $xmlobj output.$item "Plot" counters
    814                     }
    815                     map* {
    816                         _autoLabel $xmlobj output.$item "Map" counters
    817                     }
    818                     drawing* {
    819                         _autoLabel $xmlobj output.$item "Drawing" counters
    820                     }
    821                     structure* {
    822                         _autoLabel $xmlobj output.$item "Structure" counters
    823                     }
    824                     table* {
    825                         _autoLabel $xmlobj output.$item "Energy Levels" counters
    826                     }
    827                     sequence* {
    828                         _autoLabel $xmlobj output.$item "Sequence" counters
     831                if {[$xmlobj get output.$item.about.uqtype] == ""} {
     832                    switch -glob -- $item {
     833                        log* {
     834                            _autoLabel $xmlobj output.$item "Output Log" counters
     835                        }
     836                        number* {
     837                            _autoLabel $xmlobj output.$item "Number" counters
     838                        }
     839                        integer* {
     840                            _autoLabel $xmlobj output.$item "Integer" counters
     841                        }
     842                        mesh* {
     843                            _autoLabel $xmlobj output.$item "Mesh" counters
     844                        }
     845                        string* {
     846                            _autoLabel $xmlobj output.$item "String" counters
     847                        }
     848                        histogram* - curve* - field* {
     849                            _autoLabel $xmlobj output.$item "Plot" counters
     850                        }
     851                        drawing* {
     852                            _autoLabel $xmlobj output.$item "Drawing" counters
     853                        }
     854                        structure* {
     855                            _autoLabel $xmlobj output.$item "Structure" counters
     856                        }
     857                        table* {
     858                            _autoLabel $xmlobj output.$item "Energy Levels" counters
     859                        }
     860                        sequence* {
     861                            _autoLabel $xmlobj output.$item "Sequence" counters
     862                        }
    829863                    }
    830864                }
     
    853887                    }
    854888                    set hidden [$xmlobj get output.$item.hide]
    855                     if { $hidden == "" } {
     889                    if {$hidden == ""} {
    856890                        set hidden 0
    857891                    }
    858892                    if {"" != $label && !$hidden} {
     893                        set uq_part [$xmlobj get output.$item.about.uqtype]
     894
     895                        #puts "label=$label uq_part=$uq_part"
     896
    859897                        if {![info exists _label2page($label)]} {
     898                            #puts "Adding label: '$label'"
    860899                            set name "page[incr _pages]"
     900                            #puts "Inserting $name into resultpages"
    861901                            set page [$itk_component(resultpages) \
    862902                                insert end $name]
     
    884924                            set reset($page) 1
    885925                        }
    886                         $page.rviewer add $index $xmlobj output.$item
     926                        $page.rviewer add $index $xmlobj output.$item $label $uq_part
    887927                    }
    888928                }
     
    10371077        configure -simcontrolcolor $simcbg
    10381078
    1039         $itk_component(simulate) configure -state disabled
     1079        if {$_uq_active == 0} {
     1080            $itk_component(simulate) configure -state disabled
     1081        }
    10401082        $itk_component(abort) configure -state normal
    10411083
     
    10651107    # Scan through and pick out any =RAPPTURE-PROGRESS=> messages first.
    10661108    #
     1109
    10671110    while {[regexp -indices \
    10681111               {=RAPPTURE-PROGRESS=> *([-+]?[0-9]+) +([^\n]*)(\n|$)} $message \
     
    10801123        foreach {i0 i1} $match break
    10811124        set message [string replace $message $i0 $i1]
     1125    }
     1126
     1127    #
     1128    # Now handle SUBMIT-PROGRESS
     1129    #
     1130    while {[regexp -indices {=SUBMIT-PROGRESS=> aborted=([0-9]+) finished=([0-9]+) failed=([0-9]+) executing=([0-9]+)\
     1131        waiting=([0-9]+) setting_up=([0-9]+) setup=([0-9]+) %done=([0-9.]+) timestamp=([0-9.]+)(\n|$)} $message \
     1132        match aborted finished failed executing waiting setting_up setup percent ts mesg]} {
     1133
     1134        set mesg ""
     1135        foreach {i0 i1} $percent break
     1136        set percent [string range $message $i0 $i1]
     1137        foreach {i0 i1} $failed break
     1138        set failed [string range $message $i0 $i1]
     1139        foreach {i0 i1} $match break
     1140        set message [string replace $message $i0 $i1]
     1141
     1142        if {$failed != 0} {set mesg "$failed jobs failed!"}
     1143        if {$percent >= 100} { set mesg "Jobs finished.  Analyzing results..."}
     1144
     1145        pack $itk_component(progress) -fill x -padx 10 -pady 10
     1146        $itk_component(progress) settings -percent $percent -message $mesg
    10821147    }
    10831148
  • trunk/gui/scripts/gauge.tcl

    r5659 r6021  
    4242    itk_option define -sampleheight sampleHeight SampleHeight 0
    4343    itk_option define -log log Log ""
     44    itk_option define -varname varname Varname ""
     45    itk_option define -label label Label ""
    4446    itk_option define -validatecommand validateCommand ValidateCommand ""
     47    itk_option define -uq uq Uq no
    4548
    4649    constructor {args} { # defined below }
     
    5760    protected method _layout {}
    5861    protected method _log {event args}
     62    protected method _change_param_type {choice}
     63    protected method _pop_uq {win}
     64    protected method _pop_uq_deactivate {}
    5965
    6066    private variable _value 0  ;# value for this widget
     67    private variable _mode exact ;# current mode
     68    private variable _pde ""   ;# ProbDistEditor
     69    private variable _val ""   ;# value choice combobox
     70    private variable uq no
    6171
    6272    blt::bitmap define GaugeArrow {
     
    7787# ----------------------------------------------------------------------
    7888itcl::body Rappture::Gauge::constructor {args} {
     89    # puts "GAUGE CONS: $args"
     90    array set attrs $args
     91
    7992    itk_option remove hull.borderwidth hull.relief
    8093    component hull configure -borderwidth 0
     
    90103    bind $itk_component(icon) <Configure> [itcl::code $this _redraw]
    91104
     105    if {[info exists attrs(-uq)]} {
     106        set uq $attrs(-uq)
     107        if {[string is true $uq]} {
     108            set uq 1
     109            itk_component add uq {
     110                button $itk_interior.uq -image [Rappture::icon UQ] \
     111                    -command [itcl::code $this _pop_uq $itk_interior]
     112            }
     113            pack $itk_component(uq) -side right -padx 10
     114        } else {
     115            set uq 0
     116        }
     117    } else {
     118        set uq 0
     119    }
     120
    92121    itk_component add -protected vframe {
    93122        frame $itk_interior.vframe
     
    97126
    98127    itk_component add value {
    99         label $itk_component(vframe).value -width 7 \
     128        label $itk_component(vframe).value -width 20 \
    100129            -borderwidth 1 -relief flat -textvariable [itcl::scope _value]
    101130    } {
     
    199228# ----------------------------------------------------------------------
    200229itcl::body Rappture::Gauge::value {args} {
    201     set onlycheck 0
     230    #puts "Gauge value: $args"
     231
     232    # Query.  Just return the current value.
     233    if {[llength $args] == 0} {
     234        return $_value
     235    }
     236
    202237    set i [lsearch -exact $args -check]
    203238    if {$i >= 0} {
    204239        set onlycheck 1
    205240        set args [lreplace $args $i $i]
    206     }
    207 
    208     if {[llength $args] == 1} {
    209         #
    210         # If this gauge has -units, try to convert the incoming
    211         # value to that system of units.  Also, make sure that
    212         # the value is bound by any min/max value constraints.
    213         #
    214         # Keep track of the inputted units so we can give a
    215         # response about min and max values in familiar units.
    216         #
    217         set newval [set nv [string trim [lindex $args 0]]]
    218         set units $itk_option(-units)
    219         if {"" != $units} {
    220             set newval [Rappture::Units::convert $newval -context $units]
    221             set nvUnits [Rappture::Units::Search::for $newval]
    222             if { "" == $nvUnits} {
    223                 set msg [Rappture::Units::description $units]
    224                 error "unrecognized units in value \"$newval\": should be value with units of $msg"
    225             }
    226             set nv [Rappture::Units::convert $nv \
    227                 -context $units -to $units -units off]
    228 
    229             # Normalize the units name
    230             set newval [Rappture::Units::convert $newval -units off]$nvUnits
    231         }
    232 
    233         switch -- $itk_option(-type) {
    234             integer {
    235                 if { [scan $nv "%g" value] != 1 || int($nv) != $value } {
    236                     error "bad value \"$nv\": should be an integer value"
    237                 }
    238             }
    239             real {
    240                 # "scan" will reject the number if the string is "NaN" or
    241                 # "Inf" or the empty string.  It also is accepts large numbers
    242                 # (e.g. 111111111111111111111) that "string is double"
    243                 # rejects.  The problem with "scan" is that it doesn't care if
    244                 # there are extra characters trailing the number (eg. "123a").
    245                 # The extra %s substitution is used to detect this case.
    246                 if { [scan $nv "%g%s" dummy1 dummy2] != 1 } {
    247                     error "bad value \"$nv\": should be a real number"
    248                 }
    249             }
    250         }
    251 
    252         if {"" != $itk_option(-minvalue)} {
    253             set convMinVal [set minv $itk_option(-minvalue)]
    254             if {"" != $units} {
    255                 set minv [Rappture::Units::convert $minv \
    256                     -context $units -to $units -units off]
    257                 set convMinVal [Rappture::Units::convert \
    258                     $itk_option(-minvalue) -context $units -to $nvUnits]
    259             } else {
    260                 set newval [format "%g" $newval]
    261             }
    262 
    263             # fix for the case when the user tries to
    264             # compare values like minv=-500 nv=-0600
    265             set nv [format "%g" $nv]
    266             set minv [format "%g" $minv]
    267 
    268             if {$nv < $minv} {
    269                 error "minimum value allowed here is $convMinVal"
    270             }
    271         }
    272 
    273         if {"" != $itk_option(-maxvalue)} {
    274             set convMaxVal [set maxv $itk_option(-maxvalue)]
    275             if {"" != $units} {
    276                 set maxv [Rappture::Units::convert $maxv \
    277                     -context $units -to $units -units off]
    278                 set convMaxVal [Rappture::Units::convert \
    279                     $itk_option(-maxvalue) -context $units -to $nvUnits]
    280             } else {
    281                 set newval [format "%g" $newval]
    282             }
    283 
    284             # fix for the case when the user tries to
    285             # compare values like maxv=500 nv=0600
    286             set nv [format "%g" $nv]
    287             set maxv [format "%g" $maxv]
    288 
    289             if {$nv > $maxv} {
    290                 error "maximum value allowed here is $convMaxVal"
    291             }
    292         }
    293 
    294         #
    295         # If there's a -validatecommand option, then invoke the code
    296         # now to check the new value.
    297         #
    298         if {[string length $itk_option(-validatecommand)] > 0} {
    299             set cmd "uplevel #0 [list $itk_option(-validatecommand) [list $newval]]"
    300             set result [eval $cmd]
    301         }
    302 
    303         if {$onlycheck} {
    304             return
    305         }
    306 
    307         set _value $newval
    308 
    309         _redraw
    310         event generate $itk_component(hull) <<Value>>
    311 
    312     } elseif {[llength $args] != 0} {
     241    } else {
     242        set onlycheck 0
     243    }
     244
     245    if {[llength $args] != 1} {
    313246        error "wrong # args: should be \"value ?-check? ?newval?\""
     247    }
     248
     249    set newval [Rappture::Units::mcheck_range [lindex $args 0] \
     250    $itk_option(-minvalue) $itk_option(-maxvalue) $itk_option(-units)]
     251
     252    set newmode [lindex $newval 0]
     253    switch -- $newmode {
     254        uniform -
     255        gaussian {
     256            set _mode $newmode
     257        }
     258        exact -
     259        default {
     260            set _mode exact
     261        }
     262    }
     263
     264    switch -- $itk_option(-type) {
     265        integer {
     266            if { [scan $newval "%g" value] != 1 || int($newval) != $value } {
     267                error "bad value \"$newval\": should be an integer value"
     268            }
     269        }
     270    }
     271
     272    #
     273    # If there's a -validatecommand option, then invoke the code
     274    # now to check the new value.
     275    #
     276    if {[string length $itk_option(-validatecommand)] > 0} {
     277        set cmd "uplevel #0 [list $itk_option(-validatecommand) [list $newval]]"
     278        set result [eval $cmd]
     279    }
     280
     281    if {$onlycheck} {
     282        return
     283    }
     284
     285    set _value $newval
     286    $itk_component(value) configure -width [string length $_value]
     287    _redraw
     288    event generate $itk_component(hull) <<Value>>
     289
     290    if {"" != $_pde} {
     291        set val [$_val translate [$_val value]]
     292        $_val value $_mode
     293        $_pde value $_value
     294
    314295    }
    315296    return $_value
     
    494475# ----------------------------------------------------------------------
    495476itcl::body Rappture::Gauge::_editor {option args} {
     477    # puts "Gauge::editor option=$option args=$args"
    496478    if {$itk_option(-state) == "disabled"} {
    497479        return  ;# disabled? then bail out here!
     
    515497            }
    516498            set val [lindex $args 0]
    517 
    518499            if {[catch {value -check $val} result]} {
    519500                if {[regexp {allowed here is (.+)} $result match newval]} {
     
    597578    }
    598579
     580    if {$itk_option(-type) != "integer" && $uq} {
     581        pack $itk_component(uq) -side right -padx 10
     582    }
     583
    599584    array set side2anchor {
    600585        left   e
     
    744729    }
    745730}
     731
     732itcl::body Rappture::Gauge::_pop_uq {win} {
     733    # puts "min=$itk_option(-minvalue) max=$itk_option(-maxvalue) units=$itk_option(-units)"
     734    set varname $itk_option(-varname)
     735    set popup .pop_uq_$varname
     736    if { ![winfo exists $popup] } {
     737        Rappture::Balloon $popup -title $itk_option(-label)
     738        set inner [$popup component inner]
     739        frame $inner.type
     740        pack $inner.type -side top -fill x
     741        label $inner.type.l -text "Parameter Value:"
     742        pack $inner.type.l -side left
     743
     744        set _val [Rappture::Combobox $inner.type.val -width 20 -editable no]
     745        pack $_val -side left -expand yes -fill x
     746        $_val choices insert end exact "Exact Value"
     747        $_val choices insert end uniform "Uniform Distribution"
     748        $_val choices insert end gaussian "Gaussian Distribution"
     749        bind $_val <<Value>> [itcl::code $this _change_param_type $inner]
     750
     751        set _pde [Rappture::ProbDistEditor $inner.entry \
     752        $itk_option(-minvalue) $itk_option(-maxvalue) $itk_option(-units) $_value]
     753        $_val value $_mode
     754        $_pde value $_value
     755        pack $inner.entry -expand yes -fill both -pady {10 0}
     756
     757        $popup configure \
     758        -deactivatecommand [itcl::code $this _pop_uq_deactivate]
     759    }
     760    update
     761    $popup activate $win right
     762}
     763
     764itcl::body Rappture::Gauge::_pop_uq_deactivate {} {
     765    # puts "deactivate [$_pde value]"
     766    value [$_pde value]
     767}
     768
     769itcl::body Rappture::Gauge::_change_param_type {inner} {
     770    set val [$_val translate [$_val value]]
     771    $_pde mode $val
     772}
  • trunk/gui/scripts/main.tcl

    r5659 r6021  
    9797}
    9898
     99proc ReadToolParameters { numTries } {
     100    incr numTries -1
     101    if { $numTries < 0 } {
     102        return
     103    }
     104    global env
     105    set paramsFile $env(TOOL_PARAMETERS)
     106    if { ![file readable $paramsFile] } {
     107        after 500 ReadToolParmeters $numTries
     108        return
     109    }
     110    catch {
     111        set f [open $paramsFile "r"]
     112        set contents [read $f]
     113        close $f
     114        set pattern {^file\((.*)\):(.*)$}
     115        foreach line [split $contents "\n"] {
     116            if { [regexp $pattern $line match path rest] } {
     117                set ::Rappture::parameters($path) $rest
     118            }
     119        }
     120    }
     121}
     122
     123if { [info exists env(TOOL_PARAMETERS)] } {
     124    ReadToolParameters 10
     125}
     126
    99127set loadobjs {}
    100128foreach runfile $params(-load) {
     
    163191set installdir [file normalize [file dirname $params(-tool)]]
    164192$xmlobj put tool.version.application.directory(tool) $installdir
    165 
    166193set tool [Rappture::Tool ::#auto $xmlobj $installdir]
    167194
  • trunk/gui/scripts/numberentry.tcl

    r5659 r6021  
    2525    public method label {}
    2626    public method tooltip {}
    27 
    2827    protected method _newValue {}
    2928
     
    4342# ----------------------------------------------------------------------
    4443itcl::body Rappture::NumberEntry::constructor {owner path args} {
     44    set varname [lindex [split $path ()] end-1]
    4545    if {[catch {$owner isa Rappture::ControlOwner} valid] != 0 || !$valid} {
    4646        error "bad object \"$owner\": should be Rappture::ControlOwner"
     
    6868    }
    6969
     70    # check for number UQ flag
     71    set use_uq [$_owner xml get $path.uq]
     72    if {$use_uq == ""} {
     73        # check for global UQ flag
     74        set use_uq [[$_owner tool] xml get tool.uq]
     75    }
     76
     77    if {$use_uq == ""} {
     78        set use_uq no
     79    } else {
     80        set use_uq [string trim $use_uq]
     81    }
     82
    7083    #
    7184    # Create the widget and configure it properly based on other
     
    7386    #
    7487    itk_component add gauge {
    75         $class $itk_interior.gauge -units $units -presets $presets -log $path
     88        $class $itk_interior.gauge -uq $use_uq -units $units -presets $presets \
     89            -log $path -varname $varname -label [label]
    7690    }
    7791    pack $itk_component(gauge) -expand yes -fill both
  • trunk/gui/scripts/probdisteditor.tcl

    r5120 r6021  
    5050# CONSTRUCTOR
    5151# ----------------------------------------------------------------------
    52 itcl::body Rappture::ProbDistEditor::constructor {min max} {
     52itcl::body Rappture::ProbDistEditor::constructor {min max units default} {
    5353    # create a dispatcher for events
    54     puts "PDE::constructor $min $max"
     54    #puts "PDE::constructor $min $max $default"
    5555
    5656    # These are the tool min and max values.  May be empty.
    5757    set _umin $min
    5858    set _umax $max
    59     set _units [Rappture::Units::Search::for $_umin]
     59    set _units $units
     60    set _uvalue(central) $default
    6061
    6162    Rappture::dispatcher _dispatcher
     
    199200# ----------------------------------------------------------------------
    200201itcl::body Rappture::ProbDistEditor::value {{newval ""}} {
    201     puts "PDE::value $newval"
     202    # puts "PDE::value $newval"
    202203
    203204    #FIXME: _value has numerical values _uvalue has value with units
     
    243244            if {"" != $_umin} {
    244245                if {"" != $units} {
    245                     set tmp(min) [Rappture::Units::convert $_umin -to $units -units off]
     246                    set tmp(min) [Rappture::Units::convert $_umin -to $units -context $units -units off]
    246247                } else {
    247248                    set tmp(min) $_umin
     
    250251            if {"" != $_umax} {
    251252                if {"" != $units} {
    252                     set tmp(max) [Rappture::Units::convert $_umax -to $units -units off]
     253                    set tmp(max) [Rappture::Units::convert $_umax -to $units -context $units -units off]
    253254                } else {
    254255                    set tmp(max) $_umax
     
    285286# ----------------------------------------------------------------------
    286287itcl::body Rappture::ProbDistEditor::mode {{newval ""}} {
    287     puts "PDE::mode mode=$newval min=$_umin max=$_umax units=$_units"
     288    # puts "PDE::mode mode=$newval min=$_umin max=$_umax units=$_units"
    288289
    289290    set modes {exact uniform gaussian custom}
     
    291292        return $modes
    292293    }
     294
     295    set check 0
     296    if {$newval == "check"} {
     297        set newval $_mode
     298        set check 1
     299    }
     300
    293301    if {[lsearch $modes $newval] < 0} {
    294302        error "bad value \"$newval\": should be [join $modes {, }]"
     
    303311            set min ""
    304312        } else {
    305             set min [Rappture::Units::convert $_umin -units off]
     313            set min [Rappture::Units::convert $_umin -context $_units -units off]
    306314        }
    307315        if {$_umax == ""} {
    308316            set max ""
    309317        } else {
    310             set max [Rappture::Units::convert $_umax -units off]
     318            set max [Rappture::Units::convert $_umax -context $_units -units off]
    311319        }
    312320    }
     
    326334        uniform {
    327335            if {![info exists _value(min)] || ![info exists _value(max)]} {
    328                 # puts "UNIFORM min=$min max=$max"
    329                 if {$min != "" && $max != ""} {
    330                     set _value(min) $min
    331                     set _value(max) $max
    332                 } elseif {$min != ""} {
    333                     set _value(min) $min
    334                     set _value(max) [expr $min + 1]
    335                 } elseif {$max != ""} {
    336                     set _value(max) $max
    337                     set _value(min) [expr $max - 1]
     336                set _value(max) [expr $_value(central) * 1.1]
     337                set _value(min) [expr $_value(central) * 0.9]
     338                if {$_value(central) == 0.0} {
     339                    set _value(max) 1.0
     340                }
     341                if {$min != ""} {
     342                    if {$_value(min) < $min} {
     343                        set $_value(min) $min
     344                    }
     345                }
     346                if {$max != ""} {
     347                    if {$_value(max) > $max} {
     348                        set $_value(max) $max
     349                    }
    338350                }
    339351                set _uvalue(min) $_value(min)$_units
     
    342354        }
    343355        gaussian {
    344             # puts "GAUSSIAN min=$min max=$max"
     356            #puts "GAUSSIAN min=$min max=$max"
    345357            if {![info exists _value(central)]} {
    346358                if {[info exists _value(min)] && [info exists _value(max)]} {
     
    350362                }
    351363            }
    352             # puts "central=$_value(central)"
     364            #puts "central=$_value(central)"
    353365            if {![info exists _value(stddev)]} {
    354                 if {[info exists _value(min)] && [info exists _value(max)]} {
    355                     set _value(stddev) [expr {0.3*($_value(max) - $_value(min))}]
    356                 } elseif {$min != "" && $max != ""} {
    357                     set _value(stddev) [expr {0.3*($max - $min)}]
    358                 } else {
    359                     set _value(stddev)  [expr $_value(central) * 0.10]
    360                 }
     366                set _value(stddev)  [expr $_value(central) * 0.10]
    361367            }
    362368            if {$_value(stddev) <= 0} {
    363369                set _value(stddev) 1.0
    364370            }
    365             # puts "stddev=$_value(stddev)"
     371            #puts "stddev=$_value(stddev)"
    366372            # lower bound is -3 deviations or tool min
    367373            set trunc [expr {$_value(central) - 3*$_value(stddev)}]
     
    387393    }
    388394
     395    if {$check == 1} {
     396        return
     397    }
    389398    # pop up the panel of editing options for this mode
    390399    foreach w [pack slaves $itk_component(vals)] {
     
    452461# ----------------------------------------------------------------------
    453462itcl::body Rappture::ProbDistEditor::_redraw {} {
     463    #puts "PDE::_redraw"
     464
    454465    set g $itk_component(graph)
    455466    eval $g element delete [$g element names]
     
    486497        }
    487498        gaussian {
     499            #puts "min=$_value(min) max=$_value(max)"
     500            #puts "mean=$_value(central) dev=$_value(stddev)"
     501
    488502            set min $_value(min)
    489503            set max $_value(max)
     
    592606# ----------------------------------------------------------------------
    593607itcl::body Rappture::ProbDistEditor::_apply {op {widget ""}} {
    594     puts "_apply $op $widget"
     608    #puts "PDE::_apply $op $widget"
    595609    if {$op != "bindings"} {
    596610        # need this for value/finalize
     
    640654                set newval [Rappture::Units::convert [$widget get] -context $_units]
    641655            }
    642             puts "widget=$widget"
    643656            set itk $itk_component(gaussianvals).stddev
    644             puts "itk=$itk"
    645657            if {$widget != $itk && [catch {Rappture::Units::mcheck_range $newval $_umin $_umax $_units} err]} {
    646658                # oops! value is bad -- edit again
     
    658670            set $uvar $newval
    659671
     672            #if {$widget == $itk_component(gaussianvals).mean} {
     673                # need new min and max
     674                #set $_uvalue(min)
     675                #set $_uvalue(max) ...
     676            #}
     677
    660678            if {[catch {Rappture::Units::convert $newval -units off} nvar]} {
    661679                set nvar $newval
     
    663681            set $var $nvar
    664682
     683            mode check
    665684            $_dispatcher event -idle !redraw
    666685        }
  • trunk/gui/scripts/responseviewer.tcl

    r5849 r6021  
    167167
    168168    if {$var1 == $var2} {
     169        set path "output.curve(scatter)"
     170        set _dobj [Rappture::Curve ::#auto $xmlobj $path]
     171        Rappture::XyResult $w
     172        $w add $_dobj {-color red}
     173
    169174        set path "output.curve(response)"
    170175        set _dobj [Rappture::Curve ::#auto $xmlobj $path]
    171         Rappture::XyResult $w
     176
    172177    } else {
    173178        set path "output.field(f2d)"
  • trunk/gui/scripts/resultviewer.tcl

    r5659 r6021  
    2626
    2727    constructor {args} {
    28         # defined below
     28        # defined below
    2929    }
    3030    destructor {
    3131        # defined below
    3232    }
    33     public method add {index xmlobj path}
     33    public method add {index xmlobj path label {uq_part ""}}
    3434    public method clear {{index ""}}
    3535    public method value {xmlobj}
     
    4040    protected method _plotAdd {xmlobj {settings ""}}
    4141    protected method _fixScale {args}
    42     protected method _xml2data {xmlobj path}
     42    protected method _xml2data {xmlobj path label {uq_part ""}}
    4343    protected method _cleanIndex {index}
    4444
     
    5858# ----------------------------------------------------------------------
    5959itcl::body Rappture::ResultViewer::constructor {args} {
     60    #puts "Creating RV $args"
    6061    # create a dispatcher for events
    6162    Rappture::dispatcher _dispatcher
     
    8485# Data is taken from the <xmlobj> object at the <path>.
    8586# ----------------------------------------------------------------------
    86 itcl::body Rappture::ResultViewer::add {index xmlobj path} {
     87itcl::body Rappture::ResultViewer::add {index xmlobj path label {uq_part ""}} {
     88    #puts "RV add index=$index path=$path label=$label uq_part=$uq_part"
    8789    set index [_cleanIndex $index]
    88     set dobj [_xml2data $xmlobj $path]
     90    set dobj [_xml2data $xmlobj $path $label $uq_part]
    8991
    9092    #
     
    9597        lappend _dataslots ""
    9698    }
     99
    97100    set slot [lindex $_dataslots $index]
    98     lappend slot $dobj
    99     set _dataslots [lreplace $_dataslots $index $index $slot]
    100 
    101     $_dispatcher event -idle !scale
     101
     102    # only add dobj if it isn't already there.
     103    if {[lsearch -exact $slot $dobj] < 0} {
     104        lappend slot $dobj
     105        #puts "slot=$slot"
     106        set _dataslots [lreplace $_dataslots $index $index $slot]
     107        $_dispatcher event -idle !scale
     108    }
    102109}
    103110
     
    112119# ----------------------------------------------------------------------
    113120itcl::body Rappture::ResultViewer::clear {{index ""}} {
     121    #puts "RV::clear $index"
    114122    if {$index ne ""} {
    115123        # clear one result
     
    191199# ----------------------------------------------------------------------
    192200itcl::body Rappture::ResultViewer::plot {option args} {
     201    #puts "RV plot option=$option args=$args"
    193202    switch -- $option {
    194203        add {
     
    250259# ----------------------------------------------------------------------
    251260itcl::body Rappture::ResultViewer::_plotAdd {dataobj {settings ""}} {
     261    #puts "RV _plotAdd $dataobj : [$dataobj info class] : $settings"
    252262    switch -- [$dataobj info class] {
     263        ::Rappture::UqInfo {
     264            set mode "uq"
     265            if {![info exists _mode2widget($mode)]} {
     266                set w $itk_interior.uq
     267                Rappture::UqNotebook $w
     268                set _mode2widget($mode) $w
     269            }
     270        }
    253271        ::Rappture::DataTable {
    254272            set mode "datatable"
     
    411429    }
    412430
    413     if {$mode != $_mode && $_mode != ""} {
    414         set nactive [llength [$_mode2widget($_mode) get]]
    415         if {$nactive > 0} {
    416             return  ;# mixing data that doesn't mix -- ignore it!
    417         }
    418     }
    419431    # Are we plotting in a new mode? then change widgets
    420432    if {$_mode2widget($mode) != [pack slaves $itk_interior]} {
     
    442454    if {"" != $_mode} {
    443455        set dlist ""
     456        set objclass ""
    444457        foreach slot $_dataslots {
    445458            foreach dobj $slot {
     459                if {$objclass == ""} {
     460                    set objclass [$dobj info class]
     461                } else {
     462                    if {$objclass != [$dobj info class]} {
     463                        # If some of the objects are different classes
     464                        # then we cannot use the same scale, so give up.
     465                        return
     466                    }
     467                }
    446468                lappend dlist $dobj
    447469            }
     
    474496# specified <path> in the <xmlobj>.
    475497# ----------------------------------------------------------------------
    476 itcl::body Rappture::ResultViewer::_xml2data {xmlobj path} {
    477     if {[info exists _xml2data($xmlobj-$path)]} {
     498itcl::body Rappture::ResultViewer::_xml2data {xmlobj path label {uq_part ""}} {
     499    #puts "RV:_xml2data $path ([$xmlobj element -as type $path]) label=$label uq_part=$uq_part"
     500
     501    if {$uq_part != ""} {
     502        if {[info exists _xml2data($xmlobj-$label)]} {
     503            $_xml2data($xmlobj-$label) add $xmlobj $path $uq_part
     504            return $_xml2data($xmlobj-$label)
     505        }
     506    } elseif {[info exists _xml2data($xmlobj-$path]} {
    478507        return $_xml2data($xmlobj-$path)
    479508    }
    480509
    481     set type [$xmlobj element -as type $path]
     510    if {$uq_part != ""} {
     511        set type "UQ"
     512    } else {
     513        set type [$xmlobj element -as type $path]
     514    }
     515
    482516    switch -- $type {
     517        UQ {
     518            set dobj [Rappture::UqInfo ::#auto $xmlobj $path $uq_part]
     519            set path $label
     520        }
    483521        curve {
    484522            set dobj [Rappture::Curve ::#auto $xmlobj $path]
  • trunk/gui/scripts/spectrum.tcl

    r5659 r6021  
    199199
    200200    set value [lindex $args 0]
    201     if {$units != ""} {
    202         set value [Rappture::Units::convert $value \
    203             -context $units -to $units -units off]
     201
     202    switch -- [lindex $value 0] {
     203        gaussian {
     204            set value [lindex $value 1]
     205            if {$units != ""} {
     206                set value [Rappture::Units::convert $value \
     207                -context $units -to $units -units off]
     208            }
     209        }
     210        uniform {
     211            set min [lindex $value 1]
     212            set max [lindex $value 2]
     213            if {$units != ""} {
     214                set min [Rappture::Units::convert $min \
     215                -context $units -to $units -units off]
     216                set max [Rappture::Units::convert $max \
     217                -context $units -to $units -units off]
     218            }
     219            set value [expr {0.5 * ($min + $max)}]
     220        }
     221        default {
     222            if {$units != ""} {
     223                set value [Rappture::Units::convert $value \
     224                -context $units -to $units -units off]
     225            }
     226        }
    204227    }
    205228
  • trunk/gui/scripts/tempgauge.tcl

    r5659 r6021  
    2626    inherit Rappture::Gauge
    2727
    28     constructor {args} { # defined below }
    29 
     28    constructor {args} {
     29        array set attrs $args
     30        Rappture::Gauge::constructor -uq $attrs(-uq)
     31    } {
     32        eval itk_initialize -spectrum $_spectrum -units K $args
     33    }
    3034    protected method _redraw {}
    3135    protected method _resize {}
     
    4044
    4145itk::usual TemperatureGauge {
    42 }
    43 
    44 # ----------------------------------------------------------------------
    45 # CONSTRUCTOR
    46 # ----------------------------------------------------------------------
    47 itcl::body Rappture::TemperatureGauge::constructor {args} {
    48     eval itk_initialize -spectrum $_spectrum -units K $args
    4946}
    5047
  • trunk/gui/scripts/tool.tcl

    r5659 r6021  
    2828    public method installdir {} {
    2929        return [$_task installdir]
     30    }
     31    public method get_uq {args} {
     32        sync  ;# sync all widget values to XML
     33        return [eval $_task get_uq $args]
    3034    }
    3135    public method run {args} {
  • trunk/gui/scripts/units.tcl

    r5659 r6021  
    6161}
    6262
     63
     64# ----------------------------------------------------------------------
     65# USAGE: mcheck_range value {min ""} {max ""}
     66#
     67# Checks a value or PDF to determine if is is in a required range.
     68# Automatically does unit conversion if necessary.
     69# Returns value if OK.  Error if out-of-range
     70# Examples:
     71#    [mcheck_range "gaussian 0C 1C" 200K 500K] returns 1
     72#    [mcheck_range "uniform 100 200" 150 250] returns 0
     73#    [mcheck_range 100 0 200] returns 1
     74# ----------------------------------------------------------------------
     75
     76proc Rappture::Units::_check_range {value min max units} {
     77    # puts "_check_range $value min=$min max=$max units=$units"
     78    # make sure the value has units
     79    if {$units != ""} {
     80        set value [Rappture::Units::convert $value -context $units]
     81        # for comparisons, remove units
     82        set nv [Rappture::Units::convert $value -context $units -units off]
     83        # get the units for the value
     84        set newunits [Rappture::Units::Search::for $value]
     85    } else {
     86        set nv $value
     87    }
     88
     89    if {"" != $min} {
     90        if {"" != $units} {
     91            # compute the minimum in the new units
     92            set minv [Rappture::Units::convert $min -to $newunits -context $units  -units off]
     93            # same, but include units for printing
     94            set convMinVal [Rappture::Units::convert $min -to $newunits -context $units]
     95        } else {
     96            set minv $min
     97            set convMinVal $min
     98        }
     99        if {$nv < $minv} {
     100            error "Minimum value allowed here is $convMinVal"
     101        }
     102    }
     103    if {"" != $max} {
     104        if {"" != $units} {
     105            # compute the maximum in the new units
     106            set maxv [Rappture::Units::convert $max -to $newunits -context $units -units off]
     107            # same, but include units for printing
     108            set convMaxVal [Rappture::Units::convert $max -to $newunits -context $units ]
     109        } else {
     110            set maxv $max
     111            set convMaxVal $max
     112        }
     113        if {$nv > $maxv} {
     114            error "Maximum value allowed here is $convMaxVal"
     115        }
     116    }
     117    return $value
     118}
     119
     120proc Rappture::Units::mcheck_range {value {min ""} {max ""} {units ""}} {
     121    # puts "mcheck_range $value min=$min max=$max units=$units"
     122
     123    switch -- [lindex $value 0] {
     124        normal -
     125        gaussian {
     126            # get the mean
     127            set mean [_check_range [lindex $value 1] $min $max $units]
     128            if {$units == ""} {
     129                set dev [lindex $value 2]
     130                set ndev $dev
     131            } else {
     132                set dev [Rappture::Units::convert [lindex $value 2] -context $units]
     133                set ndev [Rappture::Units::convert $dev -units off]
     134            }
     135            if {$ndev <= 0} {
     136                error "Deviation must be positive."
     137            }
     138            return [list gaussian $mean $dev]
     139        }
     140        uniform {
     141            set min [_check_range [lindex $value 1] $min $max $units]
     142            set max [_check_range [lindex $value 2] $min $max $units]
     143            return [list uniform $min $max]
     144        }
     145        exact  {
     146            return [_check_range [lindex $value 1] $min $max $units]
     147        }
     148        default {
     149            return [_check_range [lindex $value 0] $min $max $units]
     150        }
     151    }
     152}
     153
     154# ----------------------------------------------------------------------
     155# USAGE: mconvert value ?-context units? ?-to units? ?-units on/off?
     156#
     157# This version of convert() converts multiple values.  Used when the
     158# value could be a range or probability density function (PDF).
     159# Examples:
     160#    gaussian 100k 1k
     161#    uniform 0eV 10eV
     162#    42
     163#    exact 42
     164# ----------------------------------------------------------------------
     165
     166proc Rappture::Units::mconvert {value args} {
     167    # puts "mconvert $value : $args"
     168    array set opts {
     169        -context ""
     170        -to ""
     171        -units "on"
     172    }
     173
     174    set value [split $value]
     175
     176    switch -- [lindex $value 0] {
     177        normal - gaussian {
     178            set valtype gaussian
     179            set vals [lrange $value 1 2]
     180            set convtype {0 1}
     181        }
     182        uniform {
     183            set valtype uniform
     184            set vals [lrange $value 1 2]
     185            set convtype {0 0}
     186        }
     187        exact  {
     188            set valtype ""
     189            set vals [lindex $value 1]
     190            set convtype {0}
     191        }
     192        default {
     193            set valtype ""
     194            set vals $value
     195            set convtype {0}
     196        }
     197    }
     198
     199    foreach {key val} $args {
     200        if {![info exists opts($key)]} {
     201            error "bad option \"$key\": should be [join [lsort [array names opts]] {, }]"
     202        }
     203        set opts($key) $val
     204    }
     205
     206    set newval $valtype
     207    foreach val $vals ctype $convtype {
     208        if {$ctype == 1} {
     209            # This code handles unit conversion for deltas (changes).
     210            # For example, if we want a standard deviation of 10C converted
     211            # to Kelvin, that is 10K, NOT a standard deviation of 283.15K.
     212            set units [Rappture::Units::Search::for $val]
     213            set base [eval Rappture::Units::convert 0$units $args -units off]
     214            set new [eval Rappture::Units::convert $val $args -units off]
     215            set delta [expr $new - $base]
     216            set val $delta$opts(-to)
     217        }
     218        # tcl 8.5 allows us to do this:
     219        # lappend newval [Rappture::Units::convert $val {*}$args]
     220        # but we are using tcl8.4 so we use eval :^(
     221        lappend newval [eval Rappture::Units::convert $val $args]
     222    }
     223    return $newval
     224}
     225
    63226# ----------------------------------------------------------------------
    64227# USAGE: convert value ?-context units? ?-to units? ?-units on/off?
     
    70233# current system.
    71234# ----------------------------------------------------------------------
    72 proc Rappture::Units::convert {value args} {
    73     array set opts {
    74         -context ""
    75         -to ""
    76         -units "on"
    77     }
    78     foreach {key val} $args {
    79         if {![info exists opts($key)]} {
    80             error "bad option \"$key\": should be [join [lsort [array names opts]] {, }]"
    81         }
    82         set opts($key) $val
    83     }
    84 
    85     #
    86     # Parse the value into the number part and the units part.
    87     #
    88     set value [string trim $value]
    89     if {![regexp {^([-+]?[0-9]+\.?([0-9]+)?([eEdD][-+]?[0-9]+)?) *(/?[a-zA-Z]+[0-9]*)?$} $value match number dummy1 dummy2 units]} {
    90         set mesg "bad value \"$value\": should be real number with units"
    91         if {$opts(-context) != ""} {
    92             append mesg " of [Rappture::Units::description $opts(-context)]"
    93         }
    94         error $mesg
    95     }
    96     if {$units == ""} {
    97         set units $opts(-context)
    98     }
    99 
    100     #
    101     # Try to find the object representing the current system of units.
    102     #
    103     set units [Rappture::Units::System::regularize $units]
    104     set oldsys [Rappture::Units::System::for $units]
    105     if {$oldsys == ""} {
    106         set mesg "value \"$value\" has unrecognized units"
    107         if {$opts(-context) != ""} {
    108             append mesg ".\nShould be units of [Rappture::Units::description $opts(-context)]"
    109         }
    110         error $mesg
    111     }
    112 
    113     #
    114     # Convert the number to the new system of units.
    115     #
    116     if {$opts(-to) == ""} {
    117         # no units -- return the number as is
    118         return "$number$units"
    119     }
    120     return [$oldsys convert "$number$units" $opts(-to) $opts(-units)]
    121 }
     235# proc Rappture::Units::convert {value args} {}
     236# Actual implementation is in rappture/lang/tcl/src/RpUnitsTclInterface.cc.
     237
    122238
    123239# ----------------------------------------------------------------------
     
    128244# along with a list of all compatible systems.
    129245# ----------------------------------------------------------------------
    130 proc Rappture::Units::description {units} {
    131     set sys [Rappture::Units::System::for $units]
    132     if {$sys == ""} {
    133         return ""
    134     }
    135     set mesg [$sys cget -type]
    136     set ulist [Rappture::Units::System::all $units]
    137     if {"" != $ulist} {
    138         append mesg " ([join $ulist {, }])"
    139     }
    140     return $mesg
    141 }
     246# proc Rappture::Units::description {units} {}
     247# Actual implementation is in rappture/lang/tcl/src/RpUnitsTclInterface.cc.
     248
    142249
    143250# ----------------------------------------------------------------------
     
    154261    private variable _system ""  ;# this system of units
    155262
    156     public proc for {units}
    157     public proc all {units}
     263    # These are in rappture/lang/tcl/src/RpUnitsTclInterface.cc.
     264    # public proc for {units}
     265    # public proc all {units}
     266
    158267    public proc regularize {units}
    159268
     
    361470# if there is no system that matches the units string.
    362471# ----------------------------------------------------------------------
    363 itcl::body Rappture::Units::System::for {units} {
    364     #
    365     # See if the units are a recognized system.  If not, then try to
    366     # extract any metric prefix and see if what's left is a recognized
    367     # system.  If all else fails, see if we can find a system without
    368     # the exact capitalization.  The user might say "25c" instead of
    369     # "25C".  Try to allow that.
    370     #
    371     if {[info exists _base($units)]} {
    372         return $_base($units)
    373     } else {
    374         set orig $units
    375         if {[regexp {^(/?)[cCmMuUnNpPfFaAkKgGtT](.+)$} $units match slash tail]} {
    376             set base "$slash$tail"
    377             if {[info exists _base($base)]} {
    378                 set sys $_base($base)
    379                 if {[$sys cget -metric]} {
    380                     return $sys
    381                 }
    382             }
    383 
    384             # check the base part for improper capitalization below...
    385             set units $base
    386         }
    387 
    388         set matching ""
    389         foreach u [array names _base] {
    390             if {[string equal -nocase $u $units]} {
    391                 lappend matching $_base($u)
    392             }
    393         }
    394         if {[llength $matching] == 1} {
    395             set sys [lindex $matching 0]
    396             #
    397             # If we got rid of a metric prefix above, make sure
    398             # that the system is metric.  If not, then we don't
    399             # have a match.
    400             #
    401             if {[string equal $units $orig] || [$sys cget -metric]} {
    402                 return $sys
    403             }
    404         }
    405     }
    406     return ""
    407 }
     472# itcl::body Rappture::Units::System::for {units} {}
     473# Actual implementation is in rappture/lang/tcl/src/RpUnitsTclInterface.cc.
     474
    408475
    409476# ----------------------------------------------------------------------
     
    414481# relationships that lead to the same base system.
    415482# ----------------------------------------------------------------------
    416 itcl::body Rappture::Units::System::all {units} {
    417     set sys [Rappture::Units::System::for $units]
    418     if {$sys == ""} {
    419         return ""
    420     }
    421 
    422     if {"" != [$sys cget -basis]} {
    423         set basis [lindex [$sys cget -basis] 0]
    424     } else {
    425         set basis $units
    426     }
    427 
    428     set ulist $basis
    429     foreach u [array names _base] {
    430         set obj $_base($u)
    431         set b [lindex [$obj cget -basis] 0]
    432         if {$b == $basis} {
    433             lappend ulist $u
    434         }
    435     }
    436     return $ulist
    437 }
     483# itcl::body Rappture::Units::System::all {units} {}
     484# Actual implementation is in rappture/lang/tcl/src/RpUnitsTclInterface.cc.
     485
    438486
    439487# ----------------------------------------------------------------------
  • trunk/gui/scripts/uq.tcl

    r5120 r6021  
    44itcl::class Rappture::UQ {
    55
    6     constructor {varlist type uqargs} {
    7         puts "Rappture::UQ constructor $varlist:$type:$uqargs"
     6    constructor {varlist num type uqargs} {
     7        #puts "Rappture::UQ constructor $varlist:$type:$uqargs"
    88        set _varlist $varlist
    99        set _type $type
    1010        set _args $uqargs
     11        set _num $num
    1112    }
    1213
     
    3031    private variable _num_pts {}
    3132    private variable _go ""
     33    private variable _num 0
    3234}
    3335
     
    6466        label $fr.text
    6567
    66 
    6768        #     bind $_val <<Value>> [itcl::code $this _change_param_type $inner]
    6869
    6970        button $fr.cancel -text Cancel -command  [itcl::code $this _setWaitVariable 0]
    7071        set _go $fr.go
    71         button $_go -text Continue -command  [itcl::code $this _setWaitVariable 1]
     72        button $_go -text "Launch Jobs" -command  [itcl::code $this _setWaitVariable 1]
    7273        _set_text $inner
    7374
     
    119120
    120121itcl::body Rappture::UQ::num_runs {} {
    121     set numvars  [llength $_varlist]
    122     puts "UQ num_runs $numvars $_type $_args"
     122    #puts "varlist=$_varlist"
     123    set numvars  $_num
     124    #puts "UQ num_runs $numvars $_type $_args"
    123125    if {![array exists _num_pts]} { _init_num_pts_array }
    124126    switch $_type {
  • trunk/gui/scripts/xyresult.tcl

    r5659 r6021  
    249249    }
    250250    if { $color == "auto" || $color == "autoreset" } {
    251 #        if { $color == "autoreset" } {
    252 #            set _nextColorIndex 0
    253 #        }
     251        if { $color == "autoreset" } {
     252            set _nextColorIndex 0
     253        }
    254254        set color [lindex $itk_option(-autocolors) $_nextColorIndex]
    255255        if { "" == $color} {
  • trunk/lang/tcl/scripts/library.tcl

    r4181 r6021  
    7070        }
    7171        set fname [file join $Rappture::installdir lib library.xml]
    72 
    73         set fid [::open $fname r]
    74         set info [read $fid]
    75         close $fid
    76 
     72        if { [catch {
     73            set fid [::open $fname r]
     74            set info [read $fid]
     75            close $fid
     76        } errs] != 0 } {
     77            puts stderr "can't open \"$fname\": errs=$errs errorInfo=$errorInfo"
     78        }
    7779        set stdlib [Rappture::LibraryObj ::#auto $info]
    7880        return $stdlib
     
    8385    } else {
    8486        # otherwise, try to open the file and create its LibraryObj
    85         set fid [::open $fname r]
    86         set info [read $fid]
    87         close $fid
     87        if { [catch {
     88            set fid [::open $fname r]
     89            set info [read $fid]
     90            close $fid
     91        } errs] != 0 } {
     92            puts stderr "can't open \"$fname\": errs=$errs errorInfo=$errorInfo"
     93        }
    8894    }
    8995
     
    215221    public method remove {{path ""}}
    216222    public method xml {{path ""}}
     223    public method uq_get_vars {{tfile ""}}
    217224
    218225    public method diff {libobj}
     
    228235    private variable _root 0       ;# non-zero => this obj owns document
    229236    private variable _document ""  ;# XML DOM tree
    230     private variable _node ""      ;# node within 
     237    private variable _node ""      ;# node within
    231238}
    232239
     
    696703    set otherv [Rappture::entities $libobj input]
    697704
     705    # add UQ checking
     706    lappend thisv uq.type uq.args
     707    lappend otherv uq.type uq.args
     708
    698709    # scan through values for this object, and compare against other one
    699710    foreach path $thisv {
     
    717728        lappend rlist + $path "" $oraw
    718729    }
     730
    719731    return $rlist
    720732}
     
    771783                set units [$libobj get $path.units]
    772784                if {"" != $units} {
    773                     set val [Rappture::Units::convert $val \
     785                    set val [Rappture::Units::mconvert $val \
    774786                        -context $units -to $units -units off]
    775787                }
     
    10381050    return $rlist
    10391051}
     1052
     1053# ----------------------------------------------------------------------
     1054# USAGE: uq_get_vars [$tfile]
     1055#
     1056# Scans number nodes in the input section for UQ parameters.
     1057#
     1058# Returns a string in JSON so it can easily be passed to PUQ. Strips units
     1059# because PUQ does not need or recognize them.
     1060#
     1061# For example, 2 parameters, one gaussian and one uniform might return:
     1062# [["height","m",["gaussian",100,10,{"min":0}]],["velocity","m/s",["uniform",80,90]]]
     1063#
     1064# Returns "" if there are no UQ parameters.
     1065#
     1066# If tfile is specified, write a template file out.
     1067# ----------------------------------------------------------------------
     1068itcl::body Rappture::LibraryObj::uq_get_vars {{tfile ""}} {
     1069    set varout \[
     1070    set varlist []
     1071
     1072    if {$tfile == ""} {
     1073        set node $_node
     1074    } else {
     1075        set fid [::open $tfile r]
     1076        set doc [dom parse [read $fid]]
     1077        set node [$doc documentElement]
     1078        close $fid
     1079    }
     1080
     1081    set count 0
     1082    set n [$node selectNodes /run/input//number]
     1083    foreach _n $n {
     1084        set x [$_n selectNodes current/text()]
     1085        set val [$x nodeValue]
     1086        if {[string equal -length 8 $val "uniform "] ||
     1087            [string equal -length 9 $val "gaussian "]} {
     1088
     1089            set vname [$_n getAttribute id]
     1090            if {[lsearch $varlist $vname] >= 0} {
     1091                continue
     1092            } else {
     1093                lappend varlist $vname
     1094            }
     1095
     1096            if {$count > 0} {
     1097                append varout ,
     1098            }
     1099            incr count
     1100
     1101            set units ""
     1102            set unode [$_n selectNodes units/text()]
     1103            if {"" != $unode} {
     1104                set units [$unode nodeValue]
     1105                set val [Rappture::Units::mconvert $val \
     1106                -context $units -to $units -units off]
     1107            }
     1108
     1109            set v \[\"$vname\",\"$units\",
     1110            set fmt "\[\"%s\",%.16g,%.16g"
     1111            set val [format $fmt [lindex $val 0] [lindex $val 1] [lindex $val 2]]
     1112            append v $val
     1113
     1114            if {[string equal -length 9 [$x nodeValue] "gaussian "]} {
     1115                set minv ""
     1116                set min_node [$_n selectNodes min/text()]
     1117                if {"" != $min_node} {
     1118                    set minv [$min_node nodeValue]
     1119                    if {$units != ""} {
     1120                        set minv [Rappture::Units::convert $minv -context $units -units off]
     1121                    }
     1122                }
     1123
     1124                set maxv ""
     1125                set max_node [$_n selectNodes max/text()]
     1126                if {"" != $max_node} {
     1127                    set maxv [$max_node nodeValue]
     1128                    if {$units != ""} {
     1129                        set maxv [Rappture::Units::convert $maxv -context $units -units off]
     1130                    }
     1131                }
     1132
     1133                if {$minv != "" || $maxv != ""} {
     1134                    append v ",{"
     1135                    if {$minv != ""} {
     1136                        append v "\"min\":$minv"
     1137                        if {$maxv != ""} {append v ,}
     1138                    }
     1139                    if {$maxv != ""} {
     1140                        append v "\"max\":$maxv"
     1141                    }
     1142                    append v "}"
     1143                }
     1144            }
     1145
     1146            if {$tfile != ""} {
     1147                $x nodeValue @@[$_n getAttribute id]
     1148            }
     1149            append varout $v\]\]
     1150        }
     1151    }
     1152    append varout \]
     1153
     1154    if {$tfile != ""} {
     1155        set fid [open $tfile w]
     1156        puts $fid "<?xml version=\"1.0\"?>"
     1157        puts $fid [$node asXML]
     1158        close $fid
     1159        $doc delete
     1160    }
     1161    if {$varout == "\[\]"} {set varout ""}
     1162    #puts "uq_get_vars returning $varout"
     1163    return [list $varout $count]
     1164}
  • trunk/lang/tcl/scripts/task.tcl

    r4970 r6021  
    1 # -*- mode: tcl; indent-tabs-mode: nil -*- 
     1# -*- mode: tcl; indent-tabs-mode: nil -*-
    22# ----------------------------------------------------------------------
    33#  COMPONENT: task - represents the executable part of a tool
     
    2929
    3030    public method run {args}
     31    public method get_uq {args}
    3132    public method abort {}
    3233    public method reset {}
     
    3738    protected method _output {data}
    3839    protected method _log {args}
     40    protected method _build_submit_cmd {cmd tfile params_file}
     41    protected method _get_params {varlist uq_type uq_args}
    3942
    4043    private variable _xmlobj ""      ;# XML object with inputs/outputs
     
    114117    }
    115118    return ""
     119}
     120
     121itcl::body Rappture::Task::get_uq {args} {
     122    foreach {path val} $args {
     123        if {$path == "-uq_type"} {
     124            set uq_type $val
     125        } elseif {$path == "-uq_args"} {
     126            set uq_args $val
     127        }
     128    }
     129    #set varlist [$_xmlobj uq_get_vars]
     130    foreach {varlist num} [$_xmlobj uq_get_vars] break
     131    return [Rappture::UQ ::#auto $varlist $num $uq_type $uq_args]
    116132}
    117133
     
    156172    # if there are any args, use them to override parameters
    157173    set _outputcb ""
     174    set uq_type ""
    158175    foreach {path val} $args {
    159176        if {$path == "-output"} {
    160177            set _outputcb $val
     178        } elseif {$path == "-uq_type"} {
     179            set uq_type $val
     180        } elseif {$path == "-uq_args"} {
     181            set uq_args $val
    161182        } else {
    162183            $_xmlobj put $path.current $val
     
    165186
    166187    foreach item {control output error} { set job($item) "" }
    167 
    168     # write out the driver.xml file for the tool
    169     set file "driver[pid].xml"
    170     set status [catch {
    171         set fid [open $file w]
    172         puts $fid "<?xml version=\"1.0\"?>"
    173         puts $fid [$_xmlobj xml]
    174         close $fid
    175     } result]
    176188
    177189    # Set limits for cpu time
     
    187199            set limit 10;               # lower bound is 10 seconds.
    188200        }
    189     }
    190     Rappture::rlimit set cputime $limit 
     201    }
     202    Rappture::rlimit set cputime $limit
     203
     204    # write out the driver.xml file for the tool
     205    set file "driver[pid].xml"
     206    set status [catch {
     207        set fid [open $file w]
     208        puts $fid "<?xml version=\"1.0\"?>"
     209        puts $fid [$_xmlobj xml]
     210        close $fid
     211    } result]
     212
     213    if {$uq_type != ""} {
     214        # Copy xml into a new file
     215        set tfile "template[pid].xml"
     216        set fid [open $tfile w]
     217        puts $fid "<?xml version=\"1.0\"?>"
     218        puts $fid [$_xmlobj xml]
     219        close $fid
     220
     221        # Return a list of the UQ variables and their PDFs.
     222        # Also turns $tfile into a template file.
     223        set uq_varlist [lindex [$_xmlobj uq_get_vars $tfile] 0]
     224    }
     225
     226
    191227    # execute the tool using the path from the tool description
    192228    if {$status == 0} {
    193229        set cmd [$_xmlobj get tool.command]
    194230        regsub -all @tool $cmd $_installdir cmd
    195         regsub -all @driver $cmd $file cmd
    196         regsub -all {\\} $cmd {\\\\} cmd
    197231        set cmd [string trimleft $cmd " "]
    198         if { $cmd == "" } {
    199             puts stderr "cmd is empty"
    200             return [list 1 "Command is empty.\n\nThere is no command specified by\n\n <command>\n </command>\n\nin the tool.xml file."]
    201         }
    202 
    203         switch -glob -- [resources -jobprotocol] {
    204             "submit*" {
    205                 # if job_protocol is "submit", then use use submit command
    206                 set cmd "submit --local $cmd"
    207             }
    208             "mx" {
    209                 # metachory submission
    210                 set cmd "mx $cmd"
    211             }
    212             "exec" {
    213                 # default -- nothing special
    214             }
    215         }
    216         $_xmlobj put tool.execute $cmd
     232
     233        if { $cmd == "" } {
     234            puts stderr "cmd is empty"
     235            return [list 1 "Command is empty.\n\nThere is no command specified by\n\n <command>\n </command>\n\nin the tool.xml file."]
     236        }
     237
     238        if {$uq_type == ""} {
     239            regsub -all @driver $cmd $file cmd
     240
     241            switch -glob -- [resources -jobprotocol] {
     242                "submit*" {
     243                    # if job_protocol is "submit", then use use submit command
     244                    set cmd "submit --local $cmd"
     245                }
     246                "mx" {
     247                    # metachory submission
     248                    set cmd "mx $cmd"
     249                }
     250                "exec" {
     251                    # default -- nothing special
     252                }
     253            }
     254        } else {
     255            set params_file [_get_params $uq_varlist $uq_type $uq_args]
     256            set cmd [_build_submit_cmd $cmd $tfile $params_file]
     257            file delete -force puq
     258        }
     259
     260        $_xmlobj put tool.execute $cmd
    217261
    218262        # starting job...
     
    223267        if {0 == [string compare -nocase -length 5 $cmd "ECHO "] } {
    224268            set status 0;
    225             set job(output) [string range $cmd 5 end] 
     269            set job(output) [string range $cmd 5 end]
    226270        } else {
    227271            set status [catch {
    228                 set ::Rappture::Task::job(control) ""
    229                 eval blt::bgexec \
    230                     ::Rappture::Task::job(control) \
    231                     -keepnewline yes \
    232                     -killsignal SIGTERM \
    233                     -onoutput [list [itcl::code $this _output]] \
    234                     -output ::Rappture::Task::job(output) \
    235                     -error ::Rappture::Task::job(error) \
    236                     $cmd
    237             } result]
     272                set ::Rappture::Task::job(control) ""
     273                eval blt::bgexec \
     274                ::Rappture::Task::job(control) \
     275                -keepnewline yes \
     276                -killsignal SIGTERM \
     277                -onoutput [list [itcl::code $this _output]] \
     278                -output ::Rappture::Task::job(output) \
     279                -error ::Rappture::Task::job(error) \
     280                $cmd
     281            } result]
    238282
    239283            if { $status != 0 } {
    240                 # We're here because the exec-ed program failed
    241                 set logmesg $result
    242                 if { $::Rappture::Task::job(control) ne "" } {
    243                     foreach { token pid code mesg } \
    244                         $::Rappture::Task::job(control) break
    245                     if { $token == "EXITED" } {
    246                         # This means that the program exited normally but
    247                         # returned a non-zero exitcode.  Consider this an
    248                         # invalid result from the program.  Append the stderr
    249                         # from the program to the message.
    250                         set logmesg "Program finished: exit code is $code"
    251                         set result "$logmesg\n\n$::Rappture::Task::job(error)"
    252                     } elseif { $token == "abort" }  {
    253                         # The user pressed the abort button.
     284                # We're here because the exec-ed program failed
     285                set logmesg $result
     286                if { $::Rappture::Task::job(control) ne "" } {
     287                    foreach { token pid code mesg } \
     288                    $::Rappture::Task::job(control) break
     289                    if { $token == "EXITED" } {
     290                       # This means that the program exited normally but
     291                       # returned a non-zero exitcode.  Consider this an
     292                       # invalid result from the program.  Append the stderr
     293                       # from the program to the message.
     294                       set logmesg "Program finished: exit code is $code"
     295                       set result "$logmesg\n\n$::Rappture::Task::job(error)"
     296                    } elseif { $token == "abort" }  {
     297                        # The user pressed the abort button.
    254298                        set logmesg "Program terminated by user."
    255                         set result "$logmesg\n\n$::Rappture::Task::job(output)"
    256                     } else {
    257                         # Abnormal termination
    258                         set logmesg "Abnormal program termination: $mesg"
    259                         set result "$logmesg\n\n$::Rappture::Task::job(output)"
    260                     }
    261                 }
     299                        set result "$logmesg\n\n$::Rappture::Task::job(output)"
     300                    } else {
     301                        # Abnormal termination
     302                        set logmesg "Abnormal program termination: $mesg"
     303                        set result "$logmesg\n\n$::Rappture::Task::job(output)"
     304                    }
     305                }
    262306                _log run failed [list $logmesg]
    263                 return [list $status $result]
     307                return [list $status $result]
    264308            }
    265309        }
     
    279323            if {[string length $jobstats] > 0} {
    280324                uplevel #0 $jobstats [list job [incr jobnum] \
    281                     event $simulation start $times(start) \
    282                     walltime $times(walltime) cputime $times(cputime) \
    283                     status $status]
     325                event $simulation start $times(start) \
     326                walltime $times(walltime) cputime $times(cputime) \
     327                status $status]
    284328            }
    285329
     
    340384    }
    341385    if {$status == 0} {
    342         file delete -force -- $file
     386        # file delete -force -- $file
    343387    }
    344388
     
    353397    # a reference to the run.xml file containing results.
    354398    #
     399
    355400    if {$status == 0} {
    356401        set result [string trim $job(output)]
     402
     403        if {$uq_type != ""} {
     404            # UQ. Collect data from all jobs and put it in one xml run file.
     405            file delete -force -- run_uq.xml
     406            if {[catch {exec puq_analyze.py puq_[pid].hdf5} res]} {
     407                set fp [open "uq_debug.err" r]
     408                set rdata [read $fp]
     409                close $fp
     410                puts "PUQ analysis failed: $res\n$rdata"
     411                error "UQ analysis failed: $res\n$rdata"
     412            } else {
     413                append result "\n" $res
     414            }
     415        }
    357416        if {[regexp {=RAPPTURE-RUN=>([^\n]+)} $result match file]} {
    358417            set _lastrun $file
     
    389448
    390449    return [list $status $result]
     450}
     451
     452# ----------------------------------------------------------------------
     453#  Turn the command string from tool.xml into the proper syntax to use
     454#  with a submit parameter sweep with a temlate file.  Proper quoting
     455# of the template file is necessary to prevent submit from being too smart
     456# and converting it to a full pathname.
     457# ----------------------------------------------------------------------
     458itcl::body Rappture::Task::_build_submit_cmd {cmd tfile params_file} {
     459    set quote_next 0
     460    set newcmd "submit --progress submit --runName=puq -l -i @:$tfile -d $params_file"
     461    set cmds [split $cmd " "]
     462    for {set i 0} {$i < [llength $cmds]} {incr i} {
     463        set arg [lindex $cmds $i]
     464        if {$quote_next == 1} {
     465            set nc [string range $arg 0 0]
     466            if {$nc != "\""} {
     467                set arg "\"\\\"$arg\\\"\""
     468            }
     469        }
     470        if {$arg == "--eval"} {
     471            set quote_next 1
     472        } else {
     473            set quote_next 0
     474        }
     475        if {$arg == "@driver"} {
     476            set arg "\"\\\"$tfile\\\"\""
     477        }
     478        append newcmd " " $arg
     479    }
     480    regsub -all @driver $newcmd $tfile newcmd
     481    return $newcmd
    391482}
    392483
     
    550641    puts stderr $line
    551642}
     643
     644
     645#
     646# Send the list of parameters to a python program so it can call PUQ
     647# and get a CSV file containing the parameter values to use for the runs.
     648itcl::body Rappture::Task::_get_params {varlist uq_type uq_args} {
     649    set pid [pid]
     650    # puts "get_params.py $pid $varlist $uq_type $uq_args"
     651    if {[catch {exec get_params.py $pid $varlist $uq_type $uq_args}]} {
     652        set fp [open "uq_debug.err" r]
     653        set rdata [read $fp]
     654        close $fp
     655        puts "get_params.py failed: $rdata"
     656        error "get_params.py: $rdata"
     657    }
     658    return params[pid].csv
     659}
  • trunk/lang/tcl/scripts/units.tcl

    r3362 r6021  
     1# -*- mode: tcl; indent-tabs-mode: nil -*-
    12# ----------------------------------------------------------------------
    23#  COMPONENT: units - mechanism for converting numbers with units
     
    6061}
    6162
     63
     64# ----------------------------------------------------------------------
     65# USAGE: mcheck_range value {min ""} {max ""}
     66#
     67# Checks a value or PDF to determine if is is in a required range.
     68# Automatically does unit conversion if necessary.
     69# Returns value if OK.  Error if out-of-range
     70# Examples:
     71#    [mcheck_range "gaussian 0C 1C" 200K 500K] returns 1
     72#    [mcheck_range "uniform 100 200" 150 250] returns 0
     73#    [mcheck_range 100 0 200] returns 1
     74# ----------------------------------------------------------------------
     75
     76proc Rappture::Units::_check_range {value min max units} {
     77    # puts "_check_range $value min=$min max=$max units=$units"
     78    # make sure the value has units
     79    if {$units != ""} {
     80        set value [Rappture::Units::convert $value -context $units]
     81        # for comparisons, remove units
     82        set nv [Rappture::Units::convert $value -context $units -units off]
     83        # get the units for the value
     84        set newunits [Rappture::Units::Search::for $value]
     85    } else {
     86        set nv $value
     87    }
     88
     89    if {"" != $min} {
     90        if {"" != $units} {
     91            # compute the minimum in the new units
     92            set minv [Rappture::Units::convert $min -to $newunits -context $units  -units off]
     93            # same, but include units for printing
     94            set convMinVal [Rappture::Units::convert $min -to $newunits -context $units]
     95        } else {
     96            set minv $min
     97            set convMinVal $min
     98        }
     99        if {$nv < $minv} {
     100            error "Minimum value allowed here is $convMinVal"
     101        }
     102    }
     103    if {"" != $max} {
     104        if {"" != $units} {
     105            # compute the maximum in the new units
     106            set maxv [Rappture::Units::convert $max -to $newunits -context $units -units off]
     107            # same, but include units for printing
     108            set convMaxVal [Rappture::Units::convert $max -to $newunits -context $units ]
     109        } else {
     110            set maxv $max
     111            set convMaxVal $max
     112        }
     113        if {$nv > $maxv} {
     114            error "Maximum value allowed here is $convMaxVal"
     115        }
     116    }
     117    return $value
     118}
     119
     120proc Rappture::Units::mcheck_range {value {min ""} {max ""} {units ""}} {
     121    # puts "mcheck_range $value min=$min max=$max units=$units"
     122
     123    switch -- [lindex $value 0] {
     124        normal - gaussian {
     125            # get the mean
     126            set mean [_check_range [lindex $value 1] $min $max $units]
     127            if {$units == ""} {
     128                set dev [lindex $value 2]
     129                set ndev $dev
     130            } else {
     131                set dev [Rappture::Units::convert [lindex $value 2] -context $units]
     132                set ndev [Rappture::Units::convert $dev -units off]
     133            }
     134            if {$ndev <= 0} {
     135                error "Deviation must be positive."
     136            }
     137            return [list gaussian $mean $dev]
     138        }
     139        uniform {
     140            set min [_check_range [lindex $value 1] $min $max $units]
     141            set max [_check_range [lindex $value 2] $min $max $units]
     142            return [list uniform $min $max]
     143        }
     144        exact  {
     145            return [_check_range [lindex $value 1] $min $max $units]
     146        }
     147        default {
     148            return [_check_range [lindex $value 0] $min $max $units]
     149        }
     150    }
     151}
     152
     153# ----------------------------------------------------------------------
     154# USAGE: mconvert value ?-context units? ?-to units? ?-units on/off?
     155#
     156# This version of convert() converts multiple values.  Used when the
     157# value could be a range or probability density function (PDF).
     158# Examples:
     159#    gaussian 100k 1k
     160#    uniform 0eV 10eV
     161#    42
     162#    exact 42
     163# ----------------------------------------------------------------------
     164
     165proc Rappture::Units::mconvert {value args} {
     166    # puts "mconvert $value : $args"
     167    array set opts {
     168        -context ""
     169        -to ""
     170        -units "on"
     171    }
     172
     173    set value [split $value]
     174
     175    switch -- [lindex $value 0] {
     176        normal - gaussian {
     177            set valtype gaussian
     178            set vals [lrange $value 1 2]
     179            set convtype {0 1}
     180        }
     181        uniform {
     182            set valtype uniform
     183            set vals [lrange $value 1 2]
     184            set convtype {0 0}
     185        }
     186        exact  {
     187            set valtype ""
     188            set vals [lindex $value 1]
     189            set convtype {0}
     190        }
     191        default {
     192            set valtype ""
     193            set vals $value
     194            set convtype {0}
     195        }
     196    }
     197
     198    foreach {key val} $args {
     199        if {![info exists opts($key)]} {
     200            error "bad option \"$key\": should be [join [lsort [array names opts]] {, }]"
     201        }
     202        set opts($key) $val
     203    }
     204
     205    set newval $valtype
     206    foreach val $vals ctype $convtype {
     207        if {$ctype == 1} {
     208            # This code handles unit conversion for deltas (changes).
     209            # For example, if we want a standard deviation of 10C converted
     210            # to Kelvin, that is 10K, NOT a standard deviation of 283.15K.
     211            set units [Rappture::Units::Search::for $val]
     212            set base [eval Rappture::Units::convert 0$units $args -units off]
     213            set new [eval Rappture::Units::convert $val $args -units off]
     214            set delta [expr $new - $base]
     215            set val $delta$opts(-to)
     216        }
     217        # tcl 8.5 allows us to do this:
     218        # lappend newval [Rappture::Units::convert $val {*}$args]
     219        # but we are using tcl8.4 so we use eval :^(
     220        lappend newval [eval Rappture::Units::convert $val $args]
     221    }
     222    return $newval
     223}
     224
    62225# ----------------------------------------------------------------------
    63226# USAGE: convert value ?-context units? ?-to units? ?-units on/off?
     
    69232# current system.
    70233# ----------------------------------------------------------------------
    71 proc Rappture::Units::convert {value args} {
    72     array set opts {
    73         -context ""
    74         -to ""
    75         -units "on"
    76     }
    77     foreach {key val} $args {
    78         if {![info exists opts($key)]} {
    79             error "bad option \"$key\": should be [join [lsort [array names opts]] {, }]"
    80         }
    81         set opts($key) $val
    82     }
    83 
    84     #
    85     # Parse the value into the number part and the units part.
    86     #
    87     set value [string trim $value]
    88     if {![regexp {^([-+]?[0-9]+\.?([0-9]+)?([eEdD][-+]?[0-9]+)?) *(/?[a-zA-Z]+[0-9]*)?$} $value match number dummy1 dummy2 units]} {
    89         set mesg "bad value \"$value\": should be real number with units"
    90         if {$opts(-context) != ""} {
    91             append mesg " of [Rappture::Units::description $opts(-context)]"
    92         }
    93         error $mesg
    94     }
    95     if {$units == ""} {
    96         set units $opts(-context)
    97     }
    98 
    99     #
    100     # Try to find the object representing the current system of units.
    101     #
    102     set units [Rappture::Units::System::regularize $units]
    103     set oldsys [Rappture::Units::System::for $units]
    104     if {$oldsys == ""} {
    105         set mesg "value \"$value\" has unrecognized units"
    106         if {$opts(-context) != ""} {
    107             append mesg ".\nShould be units of [Rappture::Units::description $opts(-context)]"
    108         }
    109         error $mesg
    110     }
    111 
    112     #
    113     # Convert the number to the new system of units.
    114     #
    115     if {$opts(-to) == ""} {
    116         # no units -- return the number as is
    117         return "$number$units"
    118     }
    119     return [$oldsys convert "$number$units" $opts(-to) $opts(-units)]
    120 }
     234# proc Rappture::Units::convert {value args} {}
     235# Actual implementation is in rappture/lang/tcl/src/RpUnitsTclInterface.cc.
     236
    121237
    122238# ----------------------------------------------------------------------
     
    127243# along with a list of all compatible systems.
    128244# ----------------------------------------------------------------------
    129 proc Rappture::Units::description {units} {
    130     set sys [Rappture::Units::System::for $units]
    131     if {$sys == ""} {
    132         return ""
    133     }
    134     set mesg [$sys cget -type]
    135     set ulist [Rappture::Units::System::all $units]
    136     if {"" != $ulist} {
    137         append mesg " ([join $ulist {, }])"
    138     }
    139     return $mesg
    140 }
     245# proc Rappture::Units::description {units} {}
     246# Actual implementation is in rappture/lang/tcl/src/RpUnitsTclInterface.cc.
     247
    141248
    142249# ----------------------------------------------------------------------
     
    153260    private variable _system ""  ;# this system of units
    154261
    155     public proc for {units}
    156     public proc all {units}
     262    # These are in rappture/lang/tcl/src/RpUnitsTclInterface.cc.
     263    # public proc for {units}
     264    # public proc all {units}
     265
    157266    public proc regularize {units}
    158267
     
    360469# if there is no system that matches the units string.
    361470# ----------------------------------------------------------------------
    362 itcl::body Rappture::Units::System::for {units} {
    363     #
    364     # See if the units are a recognized system.  If not, then try to
    365     # extract any metric prefix and see if what's left is a recognized
    366     # system.  If all else fails, see if we can find a system without
    367     # the exact capitalization.  The user might say "25c" instead of
    368     # "25C".  Try to allow that.
    369     #
    370     if {[info exists _base($units)]} {
    371         return $_base($units)
    372     } else {
    373         set orig $units
    374         if {[regexp {^(/?)[cCmMuUnNpPfFaAkKgGtT](.+)$} $units match slash tail]} {
    375             set base "$slash$tail"
    376             if {[info exists _base($base)]} {
    377                 set sys $_base($base)
    378                 if {[$sys cget -metric]} {
    379                     return $sys
    380                 }
    381             }
    382 
    383             # check the base part for improper capitalization below...
    384             set units $base
    385         }
    386 
    387         set matching ""
    388         foreach u [array names _base] {
    389             if {[string equal -nocase $u $units]} {
    390                 lappend matching $_base($u)
    391             }
    392         }
    393         if {[llength $matching] == 1} {
    394             set sys [lindex $matching 0]
    395             #
    396             # If we got rid of a metric prefix above, make sure
    397             # that the system is metric.  If not, then we don't
    398             # have a match.
    399             #
    400             if {[string equal $units $orig] || [$sys cget -metric]} {
    401                 return $sys
    402             }
    403         }
    404     }
    405     return ""
    406 }
     471# itcl::body Rappture::Units::System::for {units} {}
     472# Actual implementation is in rappture/lang/tcl/src/RpUnitsTclInterface.cc.
     473
    407474
    408475# ----------------------------------------------------------------------
     
    413480# relationships that lead to the same base system.
    414481# ----------------------------------------------------------------------
    415 itcl::body Rappture::Units::System::all {units} {
    416     set sys [Rappture::Units::System::for $units]
    417     if {$sys == ""} {
    418         return ""
    419     }
    420 
    421     if {"" != [$sys cget -basis]} {
    422         set basis [lindex [$sys cget -basis] 0]
    423     } else {
    424         set basis $units
    425     }
    426 
    427     set ulist $basis
    428     foreach u [array names _base] {
    429         set obj $_base($u)
    430         set b [lindex [$obj cget -basis] 0]
    431         if {$b == $basis} {
    432             lappend ulist $u
    433         }
    434     }
    435     return $ulist
    436 }
     482# itcl::body Rappture::Units::System::all {units} {}
     483# Actual implementation is in rappture/lang/tcl/src/RpUnitsTclInterface.cc.
     484
    437485
    438486# ----------------------------------------------------------------------
  • trunk/puq/Makefile.in

    r5030 r6021  
    2222SCRIPTS = $(srcdir)/get_params.py \
    2323        $(srcdir)/puq_analyze.py \
    24         $(srcdir)/uq.py
     24        $(srcdir)/get_response.py
    2525
    2626.PHONY: all install clean distclean
  • trunk/puq/get_params.py

    r5029 r6021  
    11#!/usr/bin/env python
    2 from puq import *
    3 import csv, sys, os
     2"""
     3This script takes some uq parameters from the command line
     4and starts up a PUQ session using them.  The RapptureHost()
     5class will not actually execute any jobs.  Job parameters
     6are instead saved to a CSV file named params[pid].csv.
     7PUQ status is saved into an hdf5 file, as usual.
     8"""
     9
     10from __future__ import print_function
     11import sys
     12import os
     13from puq import NormalParameter, UniformParameter, Sweep, RapptureHost, Smolyak
    414import numpy as np
    515from puq.jpickle import unpickle
    616
    7 dfile, pid, varlist, uq_type, args = sys.argv[1:]
     17# Redirect stdout and stderr to files for debugging.
     18sys.stdout = open("uq_debug.out", 'w')
     19sys.stderr = open("uq_debug.err", 'w')
     20
     21print(sys.argv)
     22pid, varlist, uq_type, args = sys.argv[1:]
     23
     24dfile = "driver%s.xml" % pid
    825cvsname = "params%s.csv" % pid
    926hname = "puq_%s.hdf5" % pid
    1027
    11 
    12 sys.stdout = open("gp.log", 'w')
    13 sys.stderr = open("gp.err", 'w')
    14 
    15 print sys.argv[1:]
    1628varlist = unpickle(varlist)
    17 print "varlist=", varlist
    18 print type(varlist)
     29print("varlist=", varlist)
    1930
    2031v = {}
     32units = {}
    2133for p in varlist:
    22     name, dist = p
     34    name, _units, dist = p
    2335    name = str(name)
    24     print "name=", name
    25     print "dist=", dist
     36    units[name] = str(_units)
    2637    if dist[0] == u'gaussian':
    27         v[name] = NormalParameter(name, name, mean=dist[1], dev=dist[2])
     38        try:
     39            kwargs = dist[3]
     40        except:
     41            kwargs = {}
     42        v[name] = NormalParameter(name, name, mean=dist[1], dev=dist[2], **kwargs)
     43        print(v[name])
    2844    elif dist[0] == u'uniform':
    2945        v[name] = UniformParameter(name, name, min=dist[1], max=dist[2])
    3046    else:
    31         print "ERROR: Unknown distribution type: %s" % dist[0]
     47        print("ERROR: Unknown distribution type: %s" % dist[0])
    3248        sys.exit(1)
    3349if uq_type == "smolyak":
    3450    uq = Smolyak(v.values(), args)
    3551else:
    36     print "ERROR: Unknown UQ type: %s" % uq_type
     52    print("ERROR: Unknown UQ type: %s" % uq_type)
    3753    os.chdir('..')
    3854    sys.exit(1)
    3955
    40 vals = np.column_stack([p.values for p in uq.params])
    41 names = ['@@'+str(p.name) for p in uq.params]
    42 np.savetxt(cvsname, vals, delimiter=',', header=','.join(names), comments='')
     56# save parameter values to CSV file
     57with open(cvsname, 'w') as f:
     58    print(','.join(['@@'+str(p.name) for p in uq.params]), file=f)
     59    for i in range(len(uq.params[0].values)):
     60        print(','.join(['%.16g%s' % (p.values[i], units[p.name]) for p in uq.params]), file=f)
    4361
    44 sw = Sweep(uq, RapptureHost('puq', dfile), 'test/vel_add.py')
     62# This just saves PUQ state into HDF5 file, so later we can have PUQ analyze
     63# the results and it knows about the input parameters, UQ method, etc.
     64host = RapptureHost('puq', dfile)
     65sw = Sweep(uq, host, None)
     66host.psweep = sw.psweep
    4567sw.run(hname, overwrite=True)
     68
     69print("Finished with get_params.py\n")
  • trunk/puq/get_response.py

    r5849 r6021  
    4040    resp = unpickle(resp)
    4141    var = None
     42
    4243    for index, p in enumerate(resp.params):
    4344        if p.name == name:
     
    5051
    5152    data = resp.data
    52     print ("vars=", resp.vars)
    53     print("data=", data)
    54     print("my data=", data.T[index])
    55     print("my data=", data[:, index])
     53    print('data=', repr(data))
     54    for ind, p in enumerate(resp.params):
     55        if ind == index:
     56            continue
     57        m = p.pdf.mean
     58        means = np.isclose(m, data[:, ind], rtol=1e-6, atol=1e-12)
     59        data = data[means]
     60
     61    print("vars=", resp.vars)
     62    print("data=", repr(data))
    5663
    5764    curve = xml.SubElement(dout, 'curve', {'id': 'response'})
     
    7481        else:
    7582            allpts[:, i] = np.mean(v.pdf.mean)
    76     print("allpts=", allpts)
     83
    7784    pts = resp.evala(allpts)
    78     print("pts=", pts)
    7985    xy = '\n'.join([' '.join(map(repr, a)) for a in zip(x, pts)])
    8086    comp = xml.SubElement(curve, 'component')
     
    8288
    8389    # scatter plot sampled data on response surface
    84     # curve = io['output.curve(response-%s-scatter)' % name]
    85     # curve['about.label'] = 'Data Points'
    86     # curve['about.group'] = title
    87     # curve['about.type'] = 'scatter'
    88     # curve['xaxis.label'] = varlist[0]
    89     # curve['yaxis.label'] = tname
    90     # curve['component.xy'] = (xdata, ydata)
     90    curve = xml.SubElement(dout, 'curve', {'id': 'scatter'})
     91    about = xml.SubElement(curve, 'about')
     92    xml.SubElement(about, 'label').text = 'Data Points'
     93    xml.SubElement(about, 'group').text = rlabel
     94    xml.SubElement(about, 'type').text = 'scatter'
     95    comp = xml.SubElement(curve, 'component')
     96    xy = '\n'.join([' '.join(map(repr, a)) for a in zip(data[:, index], data[:, -1])])
     97    xml.SubElement(comp, 'xy').text = xy
    9198
    9299
  • trunk/puq/puq_analyze.py

    r5103 r6021  
    11#!/usr/bin/env python
     2"""
     3Once submit has finished with the jobs, this function is called to have PUQ
     4process the results.
     5"""
     6from __future__ import print_function
    27import sys
    3 sys.stdout = open("analyze.out", 'w')
    4 sys.stderr = open("analyze.err", 'w')
    5 
     8import os
     9import numpy as np
     10import h5py
     11import re
    612import puq
    7 import csv
    8 import numpy as np
    9 import os, h5py
    1013from puq.jpickle import unpickle
    11 import xml.etree.ElementTree as xml
    12 
    13 
     14import Rappture
     15import StringIO
     16from scipy.spatial import ConvexHull
     17# geometry library
     18from shapely.geometry import Polygon
     19from shapely.ops import unary_union
     20
     21# Redirect stdout and stderr to files for debugging.
     22# Append to the files created in get_params.py
     23sys.stdout = open("uq_debug.out", 'a')
     24sys.stderr = open("uq_debug.err", 'a')
     25
     26
     27# Restore the state of a PUQ session from a HDF5 file.
    1428def load_from_hdf5(name):
    1529    h5 = h5py.File(name, 'r+')
     
    2438    return sw
    2539
    26 sw = load_from_hdf5(sys.argv[1])
    27 sw.analyze()
    28 
    29 h5 = h5py.File(sys.argv[1], 'r+')
    30 
    31 
    32 dtree = xml.parse('run_uq.xml')
    33 droot = dtree.getroot()
    34 dout = droot.find('output')
    35 
    36 uqtype = h5.attrs['UQtype']
    37 for v in h5[uqtype]:
    38     print 'PDF', v
    39     rs = unpickle(h5['/%s/%s/response' % (uqtype, v)].value)
    40     pdf = rs.pdf(fit=False)
    41 
    42     id = '%s PDF' % v
    43     elem = xml.SubElement(dout, 'curve', {'id': id})
    44     about = xml.SubElement(elem, 'about')
    45     label = xml.SubElement(about, 'label')
    46     label.text = id
    47     desc = xml.SubElement(about, 'description')
    48     desc.text = "PDF for %s" % id
    49     yaxis = xml.SubElement(elem, 'yaxis')
    50     label = xml.SubElement(yaxis, 'label')
    51     label.text = 'Probability'
    52 
    53     component = xml.SubElement(elem, 'component')
    54     xy = xml.SubElement(component, 'xy')
     40
     41# Plots probability curves
     42def plot_pdf_curve(io, h5, xvals, vname, percent):
     43    print('plot_pdf_curve %s %s' % (vname, percent))
     44    # compute upper and lower percentiles
     45    pm = (100 - percent)/200.0
     46    pp = 1 - pm
     47
     48    label = None
     49
     50    # collect data into an array
     51    xarr = np.empty(len(xvals[vname]))
     52    yp = np.empty(len(xvals[vname]))
     53    ym = np.empty(len(xvals[vname]))
     54
     55    for vindex in sorted(xvals[vname].keys()):
     56        if label is None:
     57            label = h5['/output/data/%s[%d]' % (vname, vindex)].attrs['label']
     58        xarr[vindex] = xvals[vname][vindex]
     59        yp[vindex] = pcurves[vname][vindex].ppf(pp)
     60        ym[vindex] = pcurves[vname][vindex].ppf(pm)
     61
     62    curve = io['output.curve(curve_pdf-%s-%s)' % (vname, percent)]
     63    if percent == 0:
     64        curve['about.label'] = "mean"
     65    else:
     66        curve['about.label'] = "middle %s%%" % percent
     67    curve['about.group'] = label
     68    curve['about.uqtype'] = 'Probability'
     69
     70    pts = ""
     71    for x, y in zip(xarr, yp):
     72        pts += "%s %s " % (x, y)
     73    if percent == 0:
     74        pts += '\n'
     75    else:
     76        for x, y in reversed(zip(xarr, ym)):
     77            pts += "%s %s " % (x, y)
     78        pts += "%s %s\n" % (xarr[0], yp[0])
     79
     80    curve['component.xy'] = pts
     81
     82
     83def add_pts(f1, percent):
     84    # compute upper and lower percentiles
     85    pm = (100 - percent) / 200.0
     86    pp = 1 - pm
     87    prob = np.linspace(pm, pp, 31)
     88    x, y = f1.eval(prob)
     89    return np.array(zip(x, y))
     90
     91
     92def plot_pdf_acurve(io, h5, acurves, vname, percent):
     93    """
     94    This function plots the probability curves for parametric
     95    PDFs.
     96    """
     97    print('plot_pdf_acurve %s %s' % (vname, percent))
     98
     99    label = None
     100    prev_pts = None  # last set of points
     101
     102    poly = []
     103    for vindex in sorted(acurves[vname].keys()):
     104        if label is None:
     105            label = h5['/output/data/%s[%d]' % (vname, vindex)].attrs['label']
     106        f1 = unpickle(h5['/output/data/%s[%d]' % (vname, vindex)].attrs['curve'])
     107        bpts = add_pts(f1, percent)
     108
     109        # first data set? Just remember it.
     110        if prev_pts is None:
     111            prev_pts = bpts
     112            continue
     113
     114        pts = np.array((prev_pts, bpts)).ravel().reshape(-1, 2)
     115        hull = ConvexHull(pts, qhull_options='Pp')
     116        p1 = Polygon([hull.points[v] for v in hull.vertices])
     117        poly.append(p1)
     118        prev_pts = bpts
     119
     120    u = unary_union(poly)
     121
     122    curve = io['output.curve(curve_pdf-%s-%s)' % (vname, percent)]
     123    if percent == 0:
     124        curve['about.label'] = "mean"
     125    else:
     126        curve['about.label'] = "middle %s%%" % percent
     127    curve['about.group'] = label
     128    curve['about.uqtype'] = 'Probability'
     129    curve['component.xy'] = np.array(u.exterior.xy)
     130
     131
     132def plot_pdf(io, v, pdf, desc):
     133    print("plot_pdf %s desc=%s" % (v, desc))
     134    p = io['output.curve(pdf-%s)' % v]
     135    p['about.label'] = desc
     136    p['about.uqtype'] = "PDF"
     137    p['yaxis.label'] = 'Probability'
     138
    55139    pts = "%s 0\n" % pdf.x[0]
    56140    for x, y in zip(pdf.x, pdf.y):
    57141        pts += "%s %s\n" % (x, y)
    58142    pts += "%s 0\n" % pdf.x[-1]
    59     xy.text = pts
    60 
    61 with open('run_uq.xml', 'w') as f:
    62     f.write("<?xml version=\"1.0\"?>\n")
    63     dtree.write(f)
    64 
    65 
     143    p['component.xy'] = pts
     144
     145
     146def write_responses(io, h5):
     147    uqtype = h5.attrs['UQtype']
     148    for v in h5[uqtype]:
     149        print("write_responses", v)
     150        if '[' in v:
     151            # It is a curve. Ignore.
     152            continue
     153        try:
     154            desc = h5['%s/%s' % (uqtype, v)].attrs['description']
     155        except:
     156            desc = ''
     157        try:
     158            label = h5['%s/%s' % (uqtype, v)].attrs['label']
     159        except:
     160            label = ''
     161
     162        rsp = h5['/%s/%s/response' % (uqtype, v)].value
     163        rout = io['output.response(%s)' % v]
     164        rout['value'] = rsp
     165        rout['about.description'] = desc
     166        rout['about.label'] = label
     167        rout['about.uqtype'] = 'Response'
     168
     169        rs = unpickle(rsp)
     170        rout['variables'] = ' '.join([str(p.name) for p in rs.params])
     171        labels = ' '.join([repr(str(p.label)) for p in rs.params])
     172        rout['labels'] = labels.replace("'", '"')
     173
     174        if type(rs) == puq.response.ResponseFunc:
     175            rout['equation'] = rs.eqn
     176            rout['rmse'] = "{:6.3g}".format(rs.rmse()[1])
     177
     178        rout['data'] = rs.data
     179
     180
     181def write_params(h5, out):
     182    params = map(str, h5['/input/params'].keys())
     183    print('#' * 80, file=out)
     184    print('INPUT PARAMETERS', file=out)
     185
     186    for pname in params:
     187        print('-' * 80, file=out)
     188        p = puq.unpickle(h5['/input/params/' + pname].value)
     189        cname = p.__class__.__name__[:-9]
     190        pdf_str = '%s [%s - %s] mean=%s dev=%s mode=%s' % (cname, p.pdf.range[0], p.pdf.range[1], p.pdf.mean, p.pdf.dev, p.pdf.mode)
     191
     192        print("Name:", p.name, file=out)
     193        try:
     194            print("Label:", p.label, file=out)
     195        except:
     196            pass
     197        print("Desc:", p.description, file=out)
     198        print('Value:', pdf_str, file=out)
     199    print('#' * 80, file=out)
     200    print(file=out)
     201
     202
     203def write_summary(io, h5):
     204    outstr = StringIO.StringIO()
     205    write_params(h5, outstr)
     206    uqtype = h5.attrs['UQtype']
     207    for v in h5[uqtype]:
     208        if '[' in v:
     209            # It is a curve. Ignore.
     210            continue
     211        desc = h5['%s/%s' % (uqtype, v)].attrs['description']
     212        print("QoI: %s (%s)" % (v, desc), file=outstr)
     213        rs = unpickle(h5['/%s/%s/response' % (uqtype, v)].value)
     214        if type(rs) == puq.response.ResponseFunc:
     215            print("\nv=%s\n" % rs.eqn, file=outstr)
     216            print("SURROGATE MODEL ERROR:{:6.3g}%".format(rs.rmse()[1]), file=outstr)
     217        sens = puq.unpickle(h5['/%s/%s/sensitivity' % (uqtype, v)].value)
     218        max_name_len = max(map(len, [p[0] for p in sens]))
     219        print("\nSENSITIVITY:", file=outstr)
     220        print("Var%s     u*          dev" % (' '*(max_name_len)), file=outstr)
     221        print('-'*(28+max_name_len), file=outstr)
     222        for item in sens:
     223            pad = ' '*(max_name_len - len(item[0]))
     224            print("{}{}  {:10.4g}  {:10.4g}".format(pad, item[0],
     225                item[1]['ustar'], item[1]['std']), file=outstr)
     226        print('-'*(28+max_name_len), file=outstr)
     227        print(file=outstr)
     228    iostr = io['output.string(UQ Summary)']
     229    iostr['about.label'] = 'UQ Summary'
     230    iostr['current'] = outstr.getvalue()
     231    outstr.close()
     232
     233
     234def write_sensitivity(io, h5):
     235    # If more than one variable, display sensitivity.
     236    # Curves have indexed variables, so skip them.
     237    if len(h5['/input/params']) > 1 and ['[' in x for x in h5[uqtype]].count(False):
     238        for v in h5[uqtype]:
     239            if '[' in v:
     240                # curve. skip it.
     241                continue
     242            desc = h5['/output/data/%s' % v].attrs['label']
     243            sens = unpickle(h5['/%s/%s/sensitivity' % (uqtype, v)].value)
     244
     245            hist = io['output.histogram(sens-%s)' % v]
     246            hist['about.label'] = desc
     247            hist['about.uqtype'] = 'Sensitivity'
     248            hist['about.type'] = 'scatter'
     249            hist['xaxis.label'] = 'Parameters'
     250            hist['yaxis.label'] = 'Sensitivity'
     251            pts = ''
     252            for name in sens:
     253                n = name[0]
     254                try:
     255                    n = h5['/input/params/%s' % n].attrs['label']
     256                except:
     257                    pass
     258                pts += "\"%s\" %s\n" % (n, name[1]['ustar'])
     259            hist['component.xy'] = pts
     260
     261sw = load_from_hdf5(sys.argv[1])
     262sw.analyze()
     263
     264h5 = h5py.File(sys.argv[1], 'r+')
     265io = Rappture.PyXml('run_uq.xml')
     266
     267# curves built from pdfs
     268pcurves = {}
     269xvals = {}
     270acurves = {}
     271
     272reg1 = re.compile('([ \da-zA-Z_]+)\[([ \d]+)\]')
     273
     274uqtype = h5.attrs['UQtype']
     275for v in h5[uqtype]:
     276    print('v=', v)
     277    rsp = h5['/%s/%s/response' % (uqtype, v)].value
     278    rs = unpickle(rsp)
     279    pdf = rs.pdf(fit=False)
     280    odata = h5['/output/data/%s' % v]
     281
     282    # For curves built from pdfs, just put them in a dict for now
     283    if 'x' in odata.attrs:
     284        matches = reg1.findall(v)
     285        vname, vindex = matches[0]
     286        print('CURVE: vname=%s   vindex=%s' % (vname, vindex))
     287        vindex = int(vindex)
     288        if vname not in pcurves:
     289            pcurves[vname] = {}
     290            xvals[vname] = {}
     291        xvals[vname][vindex] = odata.attrs['x']
     292        pcurves[vname][vindex] = pdf
     293    elif 'curve' in odata.attrs:
     294        matches = reg1.findall(v)
     295        vname, vindex = matches[0]
     296        print('ACURVE: %s - %s' % (vname, vindex))
     297        if vname not in acurves:
     298            acurves[vname] = {}
     299        acurves[vname][int(vindex)] = pdf
     300    else:
     301        desc = h5['/output/data/%s' % v].attrs['label']
     302        plot_pdf(io, v, pdf, desc)
     303
     304# now do probability curves
     305for vname in xvals:
     306    plot_pdf_curve(io, h5, xvals, vname, 95)
     307    plot_pdf_curve(io, h5, xvals, vname, 50)
     308
     309for vname in acurves:
     310    try:
     311        plot_pdf_acurve(io, h5, acurves, vname, 95)
     312    except:
     313        pass
     314    try:
     315        plot_pdf_acurve(io, h5, acurves, vname, 50)
     316    except:
     317        pass
     318
     319write_sensitivity(io, h5)
     320write_responses(io, h5)
     321write_summary(io, h5)
     322
     323io.close()
    66324h5.close()
Note: See TracChangeset for help on using the changeset viewer.