Skip to content
Snippets Groups Projects
runstats.tcl 5.30 KiB
#!/usr/bin/wish -f
#This is a Tcl script that reads the contents of a data file.
#It reads every few seconds (defined by readinterval)
#The file is assumed to consist of two entries per line 
#separated by a colon (no blank lines!). 
#Note also that the wish path is different
#for different machines;  Usually /usr/local/bin/wish
#
#Sep 1995 Derek van Westrum  (vanwestr@colorado.edu)
#

#First check to see if filename and run# given as arguments...

if {$argc == 1} {
#    puts stderr "Wrong number of arguments."
#    puts stderr "Usage:  'runstats filename run#'"
#    puts stderr "Trying something..."
    puts stderr "Num of arguments: $argc"
    puts stderr "Value of argument: $argv"
    if {$argc == 1} {
	set file [lindex $argv 0]
	if ![file exist $file] {
	    after 2000
	}
	if [catch {open $file r} FileId] {
	    puts stderr "Cannot find file: $file"
	    puts stderr "Check file name and path."
	    puts stderr "Trying 'stats.txt'..."
	    set file "scalers/stats$file.txt"
	    if [catch {open $file r} FileId] {
		puts stderr "Nope. 'stats.txt' not there.  Exiting..."
		puts stderr "What file? $file"
		exit
	    } else {
		set FileId [open $file r]
		set fileline [split [read $FileId] \n:] 
		puts stdout "Setting Run Number to 0000..."
		set runnum "0000"
	    }
	} else {
	    set FileId [open $file r]
	    set fileline [split [read $FileId] \n:] 
	    puts stdout "Setting Run Number to 0000..."
	    set runnum "0000"
	}
    } else {
	set file "stats.txt"
	if [catch {open $file r} FileId] {
	    puts stderr "Nope. 'stats.txt' not there.  Exiting..."
	    exit
	} else {
	    set FileId [open $file r]
	    set fileline [split [read $FileId] \n:] 
	    puts stdout "Setting Run Number to 0000..."
	    set runnum "0000"
	}
    }
}
#Now set the file name as the 1st argument in the command line...
if {$argc == 2} {
    set file [lindex $argv 0]
    set runnum [lindex $argv 1]
    if [catch {open $file r} FileId] {
	puts stderr "Cannot find file: $file"
	puts stderr "Check file name and path."
	    puts stderr "Trying 'stats.txt'..."
	    set file "stats.txt"
	    if [catch {open $file r} FileId] {
		puts stderr "Nope.  'stats.txt' not there.  Exiting..."
		exit