source: branches/1.3/lang/tcl/scripts/simulate.tcl @ 4828

Last change on this file since 4828 was 4828, checked in by dkearney, 6 years ago

adding a -simulate flag to rappture command.

rappture -simulate <driverFile>

accepts a driver.xml file and silently runs a simulation, returning a run.xml file.

  • Property svn:executable set to *
File size: 2.4 KB
Line 
1#!/bin/sh
2# -*- mode: Tcl -*-
3# ----------------------------------------------------------------------
4#  RAPPTURE SIMULATE
5#
6#  This program will run a driver.xml file and return a run.xml file.
7#  No graphical user interface will be launched.
8#
9#  USAGE: simulate.tcl -driver driver.xml
10# ======================================================================
11#  AUTHOR:  Derrick S. Kearney, Purdue University
12#  Copyright (c) 2004-2014  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#\
18exec tclsh "$0" $*
19# ----------------------------------------------------------------------
20# tclsh executes everything from here on...
21
22package require Rappture
23#package require RapptureGUI
24
25proc storeoutput {data} {
26    global _d
27    append _d $data
28}
29
30proc main {argv} {
31
32    Rappture::getopts argv params {
33        value -driver ""
34        value -tooldir ""
35        value -runfile ""
36    }
37
38    # keep the wish window from popping up
39    catch {wm withdraw .}
40
41    set xmlobj [Rappture::library $params(-driver)]
42
43    set installdir $params(-tooldir)
44    if {$installdir == ""} {
45        # tooldir not provided
46        # try looking inside driver.xml for tooldir
47        set installdir [$xmlobj get "tool.version.application.directory(tool)"]
48        if {$installdir == ""} {
49            # default to the current working directory
50            set installdir [pwd]
51        }
52    }
53
54    # set tool [Rappture::Tool ::#auto $xmlobj $installdir]
55    set task [Rappture::Task ::#auto $xmlobj $installdir]
56    $task configure -jobstats ""
57
58
59    set result ""
60    # execute the job
61    foreach {status result} [eval $task run -output storeoutput] break
62
63    # if run was successful, check to see if we should rename the file
64    if {$status == 0 && $result != "ABORT"} {
65        global _d
66        if {[regexp {=RAPPTURE-RUN=>([^\n]+)} $_d match result]} {
67            if {[string compare "" $params(-runfile)] != 0} {
68                if {[catch {file rename -force -- $result $params(-runfile)} out]} {
69                    puts stderr "while moving $result to $params(-runfile): $out"
70                }
71            }
72        } else {
73            set status 1
74            puts "Can't find result file in output.\nDid you call Rappture::result in your simulator?"
75        }
76    } else {
77        puts $result
78    }
79}
80
81main $argv
82exit 0
Note: See TracBrowser for help on using the repository browser.