Changeset 1214 for trunk


Ignore:
Timestamp:
Nov 13, 2008, 3:11:08 PM (16 years ago)
Author:
dkearney
Message:

updating help, and fixing simsim so it does all the stuff it says it does in the help menu. need to make some tcltests for this

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gui/apps/simsim.in

    r1210 r1214  
    22# ======================================================================
    33#  AUTHOR:  Derrick S. Kearney, Purdue University
    4 #  Copyright (c) 2004-2007  Purdue Research Foundation
     4#  Copyright (c) 2004-2008  Purdue Research Foundation
    55#
    66#  See the file "license.terms" for information on usage and
     
    1010RAPPTURE_INSTALL_DIR=@prefix@ ; \
    1111. $RAPPTURE_INSTALL_DIR/bin/rappture.env ; \
    12 exec wish $0 $*
     12exec wish "$0" $*
    1313
    1414package require Rappture
     
    241241
    242242    while {[llength $childList]} {
    243 #foreach c $childList {
    244 #    puts "c = [$c element -as path]"
    245 #}
    246 #puts "-------------------------------------------"
    247243
    248244        set child [lrange $childList 0 0]
    249245        set childList [lreplace $childList 0 0]
    250246
    251 #puts [$child element -as path]
    252247        set cpath [cleanPath [$child element -as path]]
    253248
     
    264259
    265260            # if the value was set on a current node, then set a preset flag
    266             set lastdot [string last "." $iPath]
    267             if {$lastdot > 0} {
    268                 incr lastdot 1
    269                 set tailNode [string range $iPath $lastdot end]
    270                 if {"current" == $tailNode} {
    271                     incr lastdot -2
    272                     set headNode [string range $iPath 0 $lastdot]
    273                     $child put $headNode.simset "yes"
    274                 }
     261            if {"current" == $iPath} {
     262                $child put simset "yes"
    275263            }
    276264        }
     
    385373
    386374proc printHelp {} {
    387     puts "simsim [OPTIONS]"
    388     puts ""
    389     puts "simulator simulator - simulate simulation"
    390     puts ""
    391     puts "OPTIONS:"
    392     puts " --tool <path>        - use the tool.xml file specified at <path>"
    393     puts " --values <valtype>   - choose the type of values to use for input."
    394     puts "                        valid <valtype>'s include:"
    395     puts "                        \"default\",\"current\",\"random\"."
    396     puts " --driver <path>      - write a driver file to <path>."
    397     puts " --compare <path>     - compare the results with the run.xml"
    398     puts "                        file at <path>."
    399     puts " --nosim              - no simulation."
    400     puts " --help               - print this help menu."
    401     puts ""
    402     puts "EXAMPLES:"
    403     puts "simulate using ./tool.xml, default values, no comparisons or driver"
    404     puts "simsim"
    405     puts ""
    406     puts "simulate using ./tool.xml, random values, no comparisons or driver"
    407     puts "simsim --values randomize"
    408     puts ""
    409     puts "from ./tool.xml, create a driver file named \"mydriverfile.xml\""
    410     puts "with random values"
    411     puts "simsim --values randomize --nosim --driver mydriverfile.xml"
    412     puts ""
    413     puts "run a simulation using the current values from driver.xml"
    414     puts "simsim --tool driver.xml --values current"
    415     puts ""
    416     puts "compare two xml file, don't do a simulation, don't print a driver.xml"
    417     puts "simsim --tool driver.xml --compare previousrun.xml --nosim"
    418     puts ""
    419     puts ""
     375    set help {
     376simsim [OPTIONS] [CONST]
     377
     378simulator simulator - simulate simulation
     379
     380OPTIONS:
     381 -tool <path>        - use the tool.xml file specified at <path>
     382 -values <valtype>   - choose the type of values to use for input.
     383                       valid <valtype>'s include:
     384                       "default","current","random".
     385 -driver <path>      - write a driver file to <path>.
     386 -compare <path>     - compare the results with the run.xml
     387                       file at <path>.
     388 -nosim              - no simulation.
     389 -help               - print this help menu.
     390
     391CONST:
     392 when -values is set to random, constant values can be set for
     393 specific inputs. the general form for constant values is:
     394
     395   xmlpath(id)=value
     396
     397 where xmlpath is the path of the element in the xml tree,
     398 id is the id of the xml node and value is the constant value
     399 you want to place in the element. the following the constant
     400 will set input.number(Ef).current to the value "2eV":
     401
     402   input.number(Ef)=2eV
     403
     404EXAMPLES:
     405simulate using ./tool.xml, default values, no comparisons or driver
     406    simsim
     407
     408simulate using ./tool.xml, random values, no comparisons or driver
     409    simsim -values random
     410
     411from ./tool.xml, create a driver file named "mydriverfile.xml"
     412with default values
     413    simsim -nosim -driver mydriverfile.xml
     414
     415from ./tool.xml, create a driver file named "mydriverfile.xml"
     416with random values
     417    simsim -values random -nosim -driver mydriverfile.xml
     418
     419from ./tool.xml, simulate with random values but set
     420input.number(Ef) to "2eV"
     421    simsim -values random input.number(Ef).current=2eV
     422
     423run a simulation using the current values from driver.xml
     424    simsim -tool driver.xml -values current
     425
     426compare two xml file, don't do a simulation, don't print a driver.xml
     427    simsim -tool driver.xml -compare previousrun.xml -nosim
     428
     429run a simulation and compare the result to previousrun.xml
     430    simsim -compare previousrun.xml
     431
     432}
     433    puts $help
    420434    exit 0
    421435}
     
    565579}
    566580
    567 
    568 # keep the wish window from popping up
    569 wm withdraw .
    570 
    571 # set default values
    572 array set presets []
    573 set i 0
    574 set oParams {}
    575 
    576 array set params {
    577     --compare ""
    578     --values default
    579     --nosim true
    580     --driver ""
    581     --tool "./tool.xml"
    582 }
    583 
    584 # parse command line arguments
    585 set argc [llength $argv]
    586 for {set i 0} {$i < $argc} {incr i} {
    587     set opt [lindex $argv $i]
    588     if {("-t" == $opt) || ("--tool" == $opt)} {
    589         if {[expr {$i + 1}] < $argc} {
    590             incr i
    591             set params(--tool) [lindex $argv $i]
    592             # need to check to see if file exists, if not raise error
    593         } else {
    594             printHelp
    595         }
    596     } elseif {("-d" == $opt) || ("--driver" == $opt)} {
    597         if {[expr {$i + 1}] < $argc} {
    598             incr i
    599             set params(--driver) [lindex $argv $i]
    600             # need to check to see if file exists, if not raise error
    601         } else {
    602             printHelp
    603         }
    604     } elseif {("-v" == $opt) || ("--values" == $opt)} {
    605         if {[expr {$i + 1}] < $argc} {
    606             incr i
    607             set params(--value) [lindex $argv $i]
    608             if {"default" == $params(--values)} {
    609                 continue
    610             } elseif {"current" == $params(--values)} {
    611                 continue
    612             } elseif {"random" == $params(--values)} {
    613                 continue
     581proc parseOptions {listVar returnVar} {
     582    upvar $listVar argv
     583    upvar $returnVar params
     584
     585    # parse command line arguments
     586    set argc [llength $argv]
     587    for {set i 0} {$i < $argc} {incr i} {
     588        set opt [lindex $argv $i]
     589        if {("-t" == $opt) || ("-tool" == $opt) || ("--tool" == $opt)} {
     590            if {[expr {$i + 1}] < $argc} {
     591                incr i
     592                set params(--tool) [lindex $argv $i]
     593                # need to check to see if file exists, if not raise error
    614594            } else {
    615595                printHelp
    616596            }
     597        } elseif {  ("-d" == $opt)      ||
     598                    ("-driver" == $opt) ||
     599                    ("--driver" == $opt)    } {
     600            if {[expr {$i + 1}] < $argc} {
     601                incr i
     602                set params(--driver) [lindex $argv $i]
     603                # need to check to see if file exists, if not raise error
     604            } else {
     605                printHelp
     606            }
     607        } elseif {  ("-v" == $opt)      ||
     608                    ("-values" == $opt) ||
     609                    ("--values" == $opt)    } {
     610            if {[expr {$i + 1}] < $argc} {
     611                incr i
     612                set valuesFlag [lindex $argv $i]
     613                if {("default" == $valuesFlag) ||
     614                    ("current" == $valuesFlag) ||
     615                    ("random" == $valuesFlag)  } {
     616                    set params(--values) $valuesFlag
     617                } else {
     618                    printHelp
     619                }
     620            } else {
     621                printHelp
     622            }
     623        } elseif {  ("-c" == $opt)      ||
     624                    ("-compare" == $opt)||
     625                    ("--compare" == $opt)   } {
     626            if {[expr {$i + 1}] < $argc} {
     627                incr i
     628                set params(--compare) [lindex $argv $i]
     629                # need to check to see if file exists, if not raise error
     630            } else {
     631                printHelp
     632            }
     633        } elseif {  ("-n" == $opt)      ||
     634                    ("-nosim" == $opt)  ||
     635                    ("--nosim" == $opt)     } {
     636            set params(--nosim) true
     637        } elseif {  ("-h" == $opt)      ||
     638                    ("-help" == $opt)   ||
     639                    ("--help" == $opt)      } {
     640            printHelp
    617641        } else {
    618             printHelp
    619         }
    620     } elseif {("-c" == $opt) || ("--compare" == $opt)} {
    621         if {[expr {$i + 1}] < $argc} {
    622             incr i
    623             set params(--compare) [lindex $argv $i]
    624             # need to check to see if file exists, if not raise error
     642            # place all extra params in the params array
     643            lappend params(oParams) $opt
     644        }
     645    }
     646}
     647
     648proc main {argv} {
     649    # set default values
     650    array set presets []
     651    set i 0
     652
     653    array set params {
     654        --compare ""
     655        --values default
     656        --nosim false
     657        --driver ""
     658        --tool "./tool.xml"
     659        oParams {}
     660    }
     661
     662    parseOptions argv params
     663
     664    # keep the wish window from popping up
     665    wm withdraw .
     666
     667    # parse out path=val combinations from the list of orphaned parameters
     668    parsePathVal params(oParams) presets
     669    if {0 != [llength $params(oParams)]} {
     670        puts "Could not understand the following parameters"
     671        puts "params(oParams) = $params(oParams)"
     672        puts "length params(oParams) = [llength $params(oParams)]"
     673    }
     674
     675    set err ""
     676    if {! [file exists $params(--tool)]} {
     677        append err "\ntool file \""
     678        append err $params(--tool)
     679        append err "\" does not exist, use -t option\n"
     680        puts $err
     681        printHelp
     682    }
     683
     684    set xmlobj [Rappture::library $params(--tool)]
     685    set installdir [file dirname $params(--tool)]
     686
     687    # need a better way to do this,
     688    # maybe just take xmldiff functionality out of simsim
     689    if {(!$params(--nosim)) || ("" != $params(--driver))} {
     690        switch -- $params(--values) {
     691            random      { randomize presets $xmlobj $installdir }
     692            current     { }
     693            default     { defaultize $xmlobj $installdir }
     694        }
     695    }
     696
     697    if {"" != $params(--driver)} {
     698        set fid [open $params(--driver) w]
     699        puts $fid {<?xml version="1.0"?>}
     700        puts $fid [$xmlobj xml]
     701        close $fid
     702    }
     703
     704    if {$params(--nosim)} {
     705        if {"" != $params(--compare)} {
     706            compare $xmlobj $params(--compare)
     707        }
     708        exit 0
     709    }
     710
     711    set tool [Rappture::Tool ::#auto $xmlobj $installdir]
     712
     713    # read the run.xml file.
     714    # from analyzer.tcl:
     715
     716    set result ""
     717    # execute the job
     718    foreach {status result} [eval $tool run] break
     719
     720    # read back the result from run.xml
     721    if {$status == 0 && $result != "ABORT"} {
     722        if {[Rappture::library isvalid $result]} {
     723            # do comparison if user chose to compare with other results
     724            if {"" != $params(--compare)} {
     725                compare $params(--compare) $result
     726            }
    625727        } else {
    626             printHelp
    627         }
    628     } elseif {("-n" == $opt) || ("--nosim" == $opt)} {
    629         set params(--nosim) true
    630     } elseif {("-h" == $opt) || ("--help" == $opt)} {
    631         printHelp
    632     } else {
    633         # puts "bad value: $argv"
    634         # printHelp
    635         # place all extra params in the params array
    636         lappend oParams $opt
    637     }
    638 }
    639 
    640 # parse out path=val combinations from the list of orphaned parameters
    641 parsePathVal oParams presets
    642 if {0 != [llength $oParams]} {
    643     puts "Could not understand the following parameters"
    644     puts "oParams = $oParams"
    645     puts "length oParams = [llength $oParams]"
    646 }
    647 
    648 set err ""
    649 if {! [file exists $params(--tool)]} {
    650     append err "\ntool file \""
    651     append err $params(--tool)
    652     append err "\" does not exist, use -t option\n"
    653     puts $err
    654     printHelp
    655 }
    656 
    657 set xmlobj [Rappture::library $params(--tool)]
    658 set installdir [file dirname $params(--tool)]
    659 
    660 # need a better way to do this,
    661 # maybe just take xmldiff functionality out of simsim
    662 if {(!$params(--nosim)) || ("" != $params(--driver))} {
    663     switch -- $params(--values) {
    664         random      { randomize presets $xmlobj $installdir }
    665         current     { continue }
    666         default     { defaultize $xmlobj $installdir }
    667     }
    668 }
    669 
    670 if {"" != $params(--driver)} {
    671     set fid [open $params(--driver) w]
    672     puts $fid [$xmlobj xml]
    673     close $fid
    674 }
    675 
    676 if {$params(--nosim)} {
    677     if {"" != $params(--compare)} {
    678         compare $xmlobj $params(--compare)
    679     }
    680     exit 0
    681 }
    682 
    683 set tool [Rappture::Tool ::#auto $xmlobj $installdir]
    684 
    685 # read the run.xml file.
    686 # from analyzer.tcl:
    687 
    688 # execute the job
    689 foreach {status result} [eval $tool run] break
    690 
    691 # read back the result from run.xml
    692 if {$status == 0 && $result != "ABORT"} {
    693     if {[regexp {=RAPPTURE-RUN=>([^\n]+)} $result match file]} {
    694         set resultxmlobj [Rappture::library $file]
    695 
    696         # do comparison if user chose to compare with other results
    697         if {"" != $params(--compare)} {
    698             compare $params(--compare) $resultxmlobj
    699         }
    700     } else {
    701         set status 1
    702         puts "Can't find result file in output.\nDid you call Rappture::result in your simulator?"
    703     }
    704 } else {
    705     puts $result
    706 }
    707 
     728            set status 1
     729            puts "Can't find result file in output.\nDid you call Rappture::result in your simulator?"
     730        }
     731    } else {
     732        puts $result
     733    }
     734}
     735
     736main $argv
    708737exit 0
Note: See TracChangeset for help on using the changeset viewer.