source: trunk/lang/tcl/scripts/result.tcl

Last change on this file was 3730, checked in by ldelgass, 11 years ago

Merge version/build variables for Tcl from 1.3 release branch.

  • Property svn:keywords set to Date Rev
File size: 2.7 KB
Line 
1# ----------------------------------------------------------------------
2#  COMPONENT: result - use this to report results
3#
4#  This utility makes it easy to report results at the end of a
5#  run within a simulator.  It takes the XML object containing the
6#  inputs and outputs and writes it out to a "run" file with an
7#  automatically generated name.  Then, it writes out the name
8#  of the run file as "=RAPPTURE-RUN=>name" so the Rappture GUI
9#  knows the name of the result file.
10# ======================================================================
11#  AUTHOR:  Michael McLennan, Purdue University
12#  Copyright (c) 2004-2012  HUBzero Foundation, LLC
13#
14#  See the file "license.terms" for information on usage and
15#  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
16# ======================================================================
17
18namespace eval Rappture { # forward declaration }
19
20# ----------------------------------------------------------------------
21# USAGE: result <libraryObj> ?<status>?
22#
23# This utility takes the <libraryObj> representing a run (driver file
24# plus outputs) and writes it out to the run file.  It should be called
25# within a simulator at the end of simulation, to communicate back
26# the results.
27#
28# If the optional <status> is specified, then it represents the exit
29# status code for the tool.  "0" means "ok" and anything non-zero means
30# "failed".
31# ----------------------------------------------------------------------
32proc Rappture::result {libobj {status 0}} {
33    global tcl_platform
34
35    $libobj put output.time [clock format [clock seconds]]
36    if {$status != 0} {
37        $libobj put output.status "failed"
38    } else {
39        $libobj put output.status "ok"
40    }
41
42    # I can't stand that there are two versions of this.  I spend more time
43    # tracking down problems that exist in the one version but not the other.
44    # For example, it matters if the tool is running TCL or some other
45    # language.
46
47    $libobj put tool.version.rappture.version $::Rappture::version
48    $libobj put tool.version.rappture.revision $::Rappture::build
49    $libobj put tool.version.rappture.modified "\$LastChangedDate: 2013-06-29 22:43:27 +0000 (Sat, 29 Jun 2013) $"
50    $libobj put tool.version.rappture.language "tcl"
51
52    if {[info exists tcl_platform(user)]} {
53        $libobj put output.user $tcl_platform(user)
54    }
55
56    # fake milliseconds by using clock clicks
57    # fake microseconds by using 000
58    # this will be fixed when tcl uses C bindings
59    set timestamp [format %d%03d%03d [clock seconds] [expr [clock clicks -milliseconds]%1000] 0]
60    set oname "run$timestamp.xml"
61    set fid [open $oname w]
62    puts $fid "<?xml version=\"1.0\"?>"
63    puts $fid [$libobj xml]
64    close $fid
65
66    if {$status == 0} {
67        puts "=RAPPTURE-RUN=>$oname"
68    }
69}
Note: See TracBrowser for help on using the repository browser.