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
|
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
|
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
+
+
+
+
|
Nx=`mtt_getsize ${sys} x`
Ny=`mtt_getsize ${sys} y`
## write header
cat <<EOF > ${out}
#!/bin/sh
# Next line replaces shell with wish\\
# -*-tcl-*- Next line replaces shell with wish\\
exec wish "\$0" "\$@"
## main window
wm title . "MTT Viewer: ${sys}"
# menu bar
canvas .menubar
menubutton .menubar.file -text "File" -underline 0 -menu .menubar.file.menu
menu .menubar.file.menu
.menubar.file.menu add command -label "Open (Gnuplot template)" -underline 0 -command open_plotfile
.menubar.file.menu add command -label "Save (Gnuplot template)" -underline 0 -command save_plotfile
.menubar.file.menu add separator
.menubar.file.menu add command -label "Print (PostScript)" -underline 0 -command print_postscript
.menubar.file.menu add separator
.menubar.file.menu add command -label "Quit" -underline 0 -command exit
menubutton .menubar.edit -text "Edit" -underline 0 -menu .menubar.edit.menu
menu .menubar.edit.menu
.menubar.edit.menu add cascade -label "Axes" -underline 0 -menu .menubar.edit.menu.axes
.menubar.edit.menu add cascade -label "Contour (3D)" -underline 0 -menu .menubar.edit.menu.contour
.menubar.edit.menu add cascade -label "Grid" -underline 0 -menu .menubar.edit.menu.grid
.menubar.edit.menu add cascade -label "Key" -underline 0 -menu .menubar.edit.menu.key
.menubar.edit.menu add cascade -label "Timestamp" -underline 0 -menu .menubar.edit.menu.time
menu .menubar.edit.menu.axes
.menubar.edit.menu.axes add command -label "Cartesian" -underline 0 -command { puts "set nopolar ; replot" }
.menubar.edit.menu.axes add command -label "Polar" -underline 0 -command { puts "set polar ; replot" }
.menubar.edit.menu.axes add cascade -label "Ranges" -underline 0 -menu .menubar.edit.menu.axes.range
menu .menubar.edit.menu.axes.range
.menubar.edit.menu.axes.range add command -label "Set X" -underline 4 -command { puts "set xrange \[[get_value "X axis range? min:max" "*:*"]\]" }
.menubar.edit.menu.axes.range add command -label "Set Y" -underline 4 -command { puts "set yrange \[[get_value "Y axis range? min:max" "*:*"]\]" }
.menubar.edit.menu.axes.range add command -label "Set Z" -underline 4 -command { puts "set zrange \[[get_value "Z axis range? min:max" "*:*"]\]" }
menu .menubar.edit.menu.contour
.menubar.edit.menu.contour add command -label "Show Contour" -underline 0 -command { puts "set dgrid3d ; set contour ; replot" }
.menubar.edit.menu.contour add command -label "Hide Contour" -underline 0 -command { puts "set nodgrid3d ; set nocontour ; replot" }
.menubar.edit.menu.contour add cascade -label "Surface" -underline 0 -menu .menubar.edit.menu.contour.surface
menu .menubar.edit.menu.contour.surface
.menubar.edit.menu.contour.surface add command -label "Show Surface" -underline 0 -command { puts "set surface ; replot" }
.menubar.edit.menu.contour.surface add command -label "Hide Surface" -underline 0 -command { puts "set nosurface ; replot" }
menu .menubar.edit.menu.grid
.menubar.edit.menu.grid add cascade -label "Show" -underline 0 -menu .menubar.edit.menu.grid.show
.menubar.edit.menu.grid add cascade -label "Hide" -underline 0 -menu .menubar.edit.menu.grid.hide
.menubar.edit.menu.grid add command -label "Show Grid" -underline 0 -command { puts "set grid ; replot" }
.menubar.edit.menu.grid add command -label "Hide Grid" -underline 0 -command { puts "set nogrid ; replot" }
menu .menubar.edit.menu.grid.show
.menubar.edit.menu.grid.show add command -label "Show all ticks" -underline 5 -command { puts "set grid xtics ytics ztics ; replot" }
.menubar.edit.menu.grid.show add command -label "Show X ticks" -underline 5 -command { puts "set grid xtics ; replot" }
.menubar.edit.menu.grid.show add command -label "Show Y ticks" -underline 5 -command { puts "set grid ytics ; replot" }
.menubar.edit.menu.grid.show add command -label "Show Z ticks" -underline 5 -command { puts "set grid ztics ; replot" }
menu .menubar.edit.menu.grid.hide
.menubar.edit.menu.grid.hide add command -label "Hide all ticks" -underline 5 -command { puts "set grid noxtics noytics noztics ; replot" }
.menubar.edit.menu.grid.hide add command -label "Hide X ticks" -underline 5 -command { puts "set grid noxtics ; replot" }
.menubar.edit.menu.grid.hide add command -label "Hode Y ticks" -underline 5 -command { puts "set grid noytics ; replot" }
.menubar.edit.menu.grid.hide add command -label "Hide Z ticks" -underline 5 -command { puts "set grid noztics ; replot" }
menu .menubar.edit.menu.key
.menubar.edit.menu.key add command -label "Show Key" -underline 0 -command { puts "set key ; replot" }
.menubar.edit.menu.key add command -label "Hide Key" -underline 0 -command { puts "set nokey ; replot" }
.menubar.edit.menu.key add command -label "Show Key" -underline 0 -command { puts "set key ; replot" }
.menubar.edit.menu.key add command -label "Hide Key" -underline 0 -command { puts "set nokey ; replot" }
.menubar.edit.menu.key add cascade -label "Position" -underline 0 -menu .menubar.edit.menu.key.posn
menu .menubar.edit.menu.key.posn
.menubar.edit.menu.key.posn add command -label "Left" -underline 0 -command { puts "set key left ; replot" }
.menubar.edit.menu.key.posn add command -label "Right" -underline 0 -command { puts "set key right ; replot" }
.menubar.edit.menu.key.posn add command -label "Top" -underline 0 -command { puts "set key top ; replot" }
.menubar.edit.menu.key.posn add command -label "Bottom" -underline 0 -command { puts "set key bottom ; replot" }
.menubar.edit.menu.key.posn add command -label "Outside" -underline 0 -command { puts "set key outside ; replot" }
.menubar.edit.menu.key.posn add command -label "Below" -underline 3 -command { puts "set key below ; replot" }
menu .menubar.edit.menu.time
.menubar.edit.menu.time add command -label "Show Timestamp" -underline 0 -command { puts "set timestamp ; replot" }
.menubar.edit.menu.time add command -label "Hide Timestamp" -underline 0 -command { puts "set notimestamp ; replot" }
menubutton .menubar.tool -text "Tools" -underline 0 -menu .menubar.tool.menu
menu .menubar.tool.menu
.menubar.tool.menu add cascade -label "Sort List" -underline 0 -menu .menubar.tool.menu.sort
.menubar.tool.menu add command -label "X-MTT" -underline 0 -command { exec xmtt & }
menu .menubar.tool.menu.sort
.menubar.tool.menu.sort add command -label "Left to Right" -underline 0 -command {
|
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
|
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
|
+
+
+
|
pack .plotbar.dim -expand false -fill x -side right
pack .plotbar.plot -expand false -fill x -side right
pack .plotbar.select -expand false -fill x -side right
# button bar
canvas .buttonbar
button .buttonbar.replot -text "Refresh" -relief raised -command { puts "replot" }
button .buttonbar.newwin -text "New Plot" -relief raised -command {
set windownum [expr 1 + \$windownum]
puts "set term x11 \$windownum"
}
pack .buttonbar.newwin -expand false -side right
pack .buttonbar.replot -expand false -side right
## parameter list canvas
canvas .parameters
listbox .parameters.list -background oldlace -foreground black
scrollbar .parameters.yscrollbar -orient v
## configure scrollbars
|
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
|
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
|
-
-
+
+
-
-
-
+
|
foreach name [split \$temp_list \$delim] {
set list \$list\$delim[reverse_name \$name]
}
return \$list
}
proc "sort_list" "list sortorder" {
if ("\$sortorder"=="normal") {
return [lsort -ascii \$list]
switch -- \$sortorder {
normal { return [lsort -ascii \$list] }
}
if ("\$sortorder"=="reverse") {
return [reverse_sort \$list]
reverse { return [reverse_sort \$list] }
}
}
EOF
## create states and outputs lists
gawk '
|
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
|
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
|
+
-
-
-
-
-
-
+
+
+
+
+
-
-
+
+
+
+
-
-
-
-
-
+
+
+
+
+
-
-
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
+
+
+
+
+
|
pack .buttonbar -expand false -fill x -side bottom
pack .parameters.yscrollbar -expand false -fill y -side right
pack .parameters.list -expand true -fill both -side left
pack .parameters -expand true -fill both
## map names to column numbers
proc "get_state_column" "title" {
switch -- \$title {
EOF
gawk '
($1 == "state") {
printf "if (\"%s\"==\"%s\") { return %d }\n", Title, $4, $2+2+Ny;
}
' Title=\$title Ny=${Ny} ${struc} >> ${out}
gawk '($1 == "state") {
printf "\t\t%s\t{ return %d }\n", $4, $2+2+Ny;
}
' Ny=${Ny} ${struc} >> ${out}
cat <<EOF >> ${out}
}
}
}
proc "get_output_column" "title" {
switch -- \$title {
EOF
gawk '
($1 == "output") {
printf "if (\"%s\"==\"%s\") { return %d }\n", Title, $4, $2+1;
}
' Title=\$title Ny=${Ny} ${struc} >> ${out}
gawk '($1 == "output") {
printf "\t\t%s\t{ return %d }\n", $4, $2+1;
}
' Title=\$title Ny=${Ny} ${struc} >> ${out}
cat <<EOF >> ${out}
}
}
proc "plot" "title" {
global select
global view
global xcolumn
global ycolumn
global zcolumn
global xtitle
global ytitle
global ztitle
if {"\$title" == "Time"} {
set column 1
} elseif {"\$view" == "states"} {
set column [get_state_column \$title]
} else {
switch -- \$view {
states { set column [get_state_column \$title] }
} elseif {"\$view" == "outputs"} {
set column [get_output_column \$title]
}
if {"\$select" == "Select X"} {
set xcolumn \$column
set xtitle \$title
} elseif {"\$select" == "Select Y"} {
set ycolumn \$column
set ytitle \$title
} elseif {"\$select" == "Select Z"} {
set zcolumn \$column
set ztitle \$title
outputs { set column [get_output_column \$title] }
}
}
switch -- \$select {
"Select X" {
set xcolumn \$column
set xtitle \$title
}
"Select Y" {
set ycolumn \$column
set ytitle \$title
}
"Select Z" {
set zcolumn \$column
set ztitle \$title
}
}
plot_var
}
## call gnuplot
proc "plot_var" "" {
global xcolumn
global ycolumn
global zcolumn
global xtitle
global ytitle
global ztitle
global dimension
global plottype
global lastplot
if {"\$dimension" == "2D"} {
if {"\$plottype" == "Single"} {
puts "set xlabel '\$xtitle'"
puts "set ylabel '\$ytitle'"
puts "set nokey"
puts "plot '${dat2}' using \$xcolumn:\$ycolumn title 'y:\$ytitle x:\$xtitle' with lines"
} elseif {"\$plottype" == "Multi"} {
puts "set xlabel ''"
puts "set ylabel ''"
puts "set key"
if {"\$lastplot" != "2D"} {
puts "plot '${dat2}' using \$xcolumn:\$ycolumn title 'y:\$ytitle x:\$xtitle' with lines"
} else {
puts "replot '${dat2}' using \$xcolumn:\$ycolumn title 'y:\$ytitle x:\$xtitle' with lines"
}
}
set lastplot "2D"
switch -- \$dimension {
2D {
switch -- \$plottype {
Single {
puts "set xlabel '\$xtitle'"
puts "set ylabel '\$ytitle'"
puts "set nokey"
puts "plot '${dat2}' using \$xcolumn:\$ycolumn title 'y:\$ytitle x:\$xtitle' with lines"
}
Multi {
puts "set xlabel ''"
puts "set ylabel ''"
puts "set key"
if {"\$lastplot" != "2D"} {
puts "plot '${dat2}' using \$xcolumn:\$ycolumn title 'y:\$ytitle x:\$xtitle' with lines"
} else {
puts "replot '${dat2}' using \$xcolumn:\$ycolumn title 'y:\$ytitle x:\$xtitle' with lines"
}
}
}
}
3D {
switch -- \$plottype {
} elseif {"\$dimension" == "3D"} {
if {"\$plottype" == "Single"} {
puts "set xlabel '\$xtitle'"
puts "set ylabel '\$ytitle'"
puts "set zlabel '\$ztitle'"
puts "set nokey"
puts "splot '${dat2}' using \$xcolumn:\$ycolumn:\$zcolumn title 'z:\$ztitle y:\$ytitle x:\$xtitle' with lines"
} elseif {"\$plottype" == "Multi"} {
puts "set xlabel ''"
puts "set ylabel ''"
puts "set zlabel ''"
puts "set key"
if {"\$lastplot" != "3D"} {
puts "splot '${dat2}' using \$xcolumn:\$ycolumn:\$zcolumn title 'z:\$ztitle y:\$ytitle x:\$xtitle' with lines"
} else {
puts "replot '${dat2}' using \$xcolumn:\$ycolumn:\$zcolumn title 'z:\$ztitle y:\$ytitle x:\$xtitle' with lines"
}
}
Single {
puts "set xlabel '\$xtitle'"
puts "set ylabel '\$ytitle'"
puts "set zlabel '\$ztitle'"
puts "set nokey"
puts "splot '${dat2}' using \$xcolumn:\$ycolumn:\$zcolumn title 'z:\$ztitle y:\$ytitle x:\$xtitle' with lines"
}
Multi {
puts "set xlabel ''"
puts "set ylabel ''"
puts "set zlabel ''"
puts "set key"
if {"\$lastplot" != "3D"} {
puts "splot '${dat2}' using \$xcolumn:\$ycolumn:\$zcolumn title 'z:\$ztitle y:\$ytitle x:\$xtitle' with lines"
} else {
puts "replot '${dat2}' using \$xcolumn:\$ycolumn:\$zcolumn title 'z:\$ztitle y:\$ytitle x:\$xtitle' with lines"
}
}
set lastplot "3D"
}
}
}
}
}
set lastplot \$dimension
}
## open gnuplot plot file
proc "open_plotfile" "" {
global parameter
if {"\$parameter"==""} {
set name "${sys}.plt"
} else {
set name "\$parameter.plt"
|
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
|
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
|
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
puts "set term postscript"
puts "set output '\$filename'"
puts "replot"
tk_dialog ".printed" "Graph Printed!" "PostScript saved as \$filename" "" "0" "Close"
}
}
}
proc "get_value" "string initial" {
frame .f
frame .f.buttons
global get_value_retval
global get_value_status
set get_value_retval ""
set get_value_status ""
button .f.buttons.ok -text "ok" -command {
set get_value_status "ok"
set get_value_retval [.f.entry get ]
destroy .f
}
button .f.buttons.cancel -text "Cancel" -command {
set get_value_status "cancel"
destroy .f
}
entry .f.entry
label .f.label -text "\$string"
.f.entry insert 0 "\$initial"
pack .f.buttons.ok -side left -expand false
pack .f.buttons.cancel -side left -expand false
pack .f.label -side top -expand false
pack .f.entry -side top -expand false
pack .f.buttons -side top -expand false
place .f -in .parameters -relx 0 -rely 0 -relwidth 1 -relheight 1 -anchor nw -bordermode outside
tkwait variable get_value_retval
if {"\$get_value_status" == "ok"} {
return "\$get_value_retval"
} else {
return ""
}
}
proc "get_scale" "string min max" {
frame .f
frame .f.buttons
global get_scale_retval
global get_scale_status
set get_scale_retval ""
set get_scale_status ""
button .f.buttons.ok -text "ok" -command {
set get_scale_status "ok"
set get_scale_retval [.f.scale get ]
destroy .f
}
button .f.buttons.cancel -text "Cancel" -command {
set get_scale_status "cancel"
destroy .f
}
scale .f.scale -orient h -label "\$string" -from "\$min" -to "\$max"
pack .f.buttons.ok -side left -expand false
pack .f.buttons.cancel -side left -expand false
pack .f.scale -side top -expand false
pack .f.buttons -side top -expand false
place .f -in .parameters -relx 0 -rely 0 -relwidth 1 -relheight 1 -anchor nw -bordermode outside
tkwait variable get_value_retval
if {"\$get_scale_status" == "ok"} {
return "\$get_scale_retval"
} else {
return ""
}
}
# Defaults
set parameter ""
set windownum 0
set view outputs
set lastplot ""
set select "Select Y"
set xcolumn 1 ; set xtitle "Time"
set ycolumn 1 ; set ytitle "Time"
set zcolumn 1 ; set ztitle "Time"
puts "set timestamp"
puts "set grid"
puts "set nopolar"
puts "set term X11 0"
puts "set key"
EOF
chmod +x ${out}
|