File: cplot.tcl

package info (click to toggle)
ns2 2.35%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 78,796 kB
  • sloc: cpp: 172,923; tcl: 107,130; perl: 6,391; sh: 6,143; ansic: 5,846; makefile: 816; awk: 525; csh: 355
file content (121 lines) | stat: -rw-r--r-- 2,995 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#
# cplot -- "cooked" plot
#	merge multiple cooked trace files together, eventually
#	to produce a final plot:
#
# Usage: cplot package graph-title cfile1 cname1 [cfile2 cname 2] ...
#
# this will take cooked trace files cfile{1,2,...}
# and merge them into a combined graph of the type defined in
# "package".  for now, package is either xgraph or gnuplot
#
# Sources for gnuplot, as of 10/20/97:
# 	gnuplot3.5: ftp://ftp.dartmouth.edu/pub/gnuplot/
#	gnuplot3.6beta: ftp://cmpc1.phys.soton.ac.uk/pub
#	gnuplot3.6beta-mirror: http://www.nas.nasa.gov/~woo/gnuplot/beta/

set labelproc(xgraph) xgraph_label
set labelproc(gnuplot) gnuplot_label
set headerproc(xgraph) xgraph_header
set headerproc(gnuplot) gnuplot_header
set filext(xgraph) xgr
set filext(gnuplot) plt

set package default; # graphics package to use

if { $argc < 4 || [expr $argc & 1] } {
	puts stderr "Usage: tclsh cplot graphics-package graph-title cfile1 cname1 \[cfile2 cname2\] ..."
	exit 1
}

proc init {} {
	global tmpchan tmpfile
	set tmpfile /tmp/[pid].tmp
	set tmpchan [open $tmpfile w+]
}

proc cleanup {} {
	global tmpchan tmpfile package filext
	seek $tmpchan 0 start
	exec cat <@ $tmpchan >@ stdout
	close $tmpchan
	exec rm -f $tmpfile
}

proc run {} {
	global labelproc headerproc package argv tmpchan
	init
	set package [lindex $argv 0]
	set title [lindex $argv 1]
	if { ![info exists labelproc($package)] } {
		puts stderr "cplot: invalid output package $package, known packages: [array names labelproc]"
		exit 1
	}
	set ifile 2
	set iname 3
	$headerproc($package) $tmpchan $title
	while {1} {
		set fname [lindex $argv $ifile]
		set label [lindex $argv $iname]
		if { $fname == "" || $label == "" } {
			break
		}
		do_file $fname $label $package $tmpchan
		incr ifile 2
		incr iname 2
	}
	cleanup
}

proc do_file { fname label graphtype tmpchan } {
	global labelproc
	$labelproc($graphtype) $tmpchan $label $fname
}

#
# xgraph-specific stuff
#

proc xgraph_header { tmpchan title } {
        puts $tmpchan "TitleText: $title"
        puts $tmpchan "Device: Postscript"
	puts $tmpchan "BoundBox: true"
	puts $tmpchan "Ticks: true"
	puts $tmpchan "Markers: true"
	puts $tmpchan "NoLines: true"
	puts $tmpchan "XUnitText: time"
	puts $tmpchan "YUnitText: sequence/ack number"
}

proc xgraph_label { tmpchan label fname } {
	puts $tmpchan \n\"$label
	exec cat $fname >@ $tmpchan
}

#
# gnuplot-specific stuff
#

proc gnuplot_header { tmpchan title } {
	puts $tmpchan "set title '$title'"
	puts $tmpchan "set xlabel 'time'"
	puts $tmpchan "set ylabel 'sequence/ack number'"
	puts $tmpchan "set grid"

	global gnu_first_time gnu_label_index
	set gnu_first_time 1
	set gnu_label_index 1
}

proc gnuplot_label { tmpchan label fname } {
	global gnu_first_time gnu_label_index
	if { $gnu_first_time } {
		puts $tmpchan "plot '$fname' title '$label' w points $gnu_label_index 2"
		set gnu_first_time 0
	} else {
		puts $tmpchan "replot '$fname' title '$label' w points $gnu_label_index 2"
	}
	incr gnu_label_index
}

run