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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
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
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
357
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
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
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
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
|
# Copyright (C) 1999-2018
# Smithsonian Astrophysical Observatory, Cambridge, MA, USA
# For conditions of distribution and use, see copyright notice in "copyright"
package provide DS9 1.0
proc PlotAddDataSet {varname dim data} {
upvar #0 $varname var
global $varname
switch -- $dim {
4 {
# first data set
PlotDataSetOne $varname "4.1" $data
# second data set
PlotDataSetOne $varname "4.2" $data
}
5 {
# first data set
PlotDataSetOne $varname "5.1" $data
# second data set
PlotDataSetOne $varname "5.2" $data
}
default {
PlotDataSetOne $varname $dim $data
}
}
}
proc PlotDataSetOne {varname dim data} {
upvar #0 $varname var
global $varname
set cc $var(graph,current)
# look for no data
if {[string length $data] == 0} {
return
}
# total length
set ll [llength $data]
# incr count
incr ${varname}($cc,data,total)
set nn $var($cc,data,total)
set var($cc,data,current) $nn
# init new state
global pap
set var(graph,ds,show) $pap(graph,ds,show)
set var(graph,ds,smooth) $pap(graph,ds,smooth)
set var(graph,ds,color) $pap(graph,ds,color)
set var(graph,ds,fill) $pap(graph,ds,fill)
set var(graph,ds,fill,color) $pap(graph,ds,fill,color)
set var(graph,ds,width) $pap(graph,ds,width)
set var(graph,ds,dash) $pap(graph,ds,dash)
set var(graph,ds,shape,symbol) $pap(graph,ds,shape,symbol)
set var(graph,ds,shape,fill) $pap(graph,ds,shape,fill)
set var(graph,ds,shape,color) $pap(graph,ds,shape,color)
set var(graph,ds,error) $pap(graph,ds,error)
set var(graph,ds,error,cap) $pap(graph,ds,error,cap)
set var(graph,ds,error,color) $pap(graph,ds,error,color)
set var(graph,ds,error,width) $pap(graph,ds,error,width)
set var(graph,ds,bar,relief) $pap(graph,ds,bar,relief)
# new vector names
set xdata ap${varname}graph${cc}xx${nn}
set ydata ap${varname}graph${cc}yy${nn}
set xedata ap${varname}graph${cc}xe${nn}
set yedata ap${varname}graph${cc}ye${nn}
# basics
set var(graph,ds,manage) 1
set var(graph,ds,name) "Dataset $nn"
# vectors
set var(graph,ds,xdata) $xdata
set var(graph,ds,ydata) $ydata
set var(graph,ds,xedata) {}
set var(graph,ds,yedata) {}
global $var(graph,ds,xdata) $var(graph,ds,ydata)
blt::vector create $var(graph,ds,xdata) $var(graph,ds,ydata)
# substitute all separtors
regsub -all {[\n\r\t, ]+} $data { } data
# remove all non-numeric data
regsub -all {[^0-9.e\- ]+} $data {} data
set x {}
set y {}
set xe {}
set ye {}
switch -- $dim {
2 -
xy {
set var(graph,ds,dim) xy
for {set ii 0} {$ii<$ll} {incr ii 2} {
lappend x [lindex $data $ii]
lappend y [lindex $data [expr $ii+1]]
}
$var(graph,ds,xdata) set $x
$var(graph,ds,ydata) set $y
}
xyex {
set var(graph,ds,dim) xyex
set var(graph,ds,xedata) $xedata
global $var(graph,ds,xedata)
blt::vector create $var(graph,ds,xedata)
for {set ii 0} {$ii<$ll} {incr ii 3} {
lappend x [lindex $data $ii]
lappend y [lindex $data [expr $ii+1]]
lappend xe [lindex $data [expr $ii+2]]
}
$var(graph,ds,xdata) set $x
$var(graph,ds,ydata) set $y
$var(graph,ds,xedata) set $xe
}
3 -
xyey {
set var(graph,ds,dim) xyey
set var(graph,ds,yedata) $yedata
global $var(graph,ds,yedata)
blt::vector create $var(graph,ds,yedata)
for {set ii 0} {$ii<$ll} {incr ii 3} {
lappend x [lindex $data $ii]
lappend y [lindex $data [expr $ii+1]]
lappend ye [lindex $data [expr $ii+2]]
}
$var(graph,ds,xdata) set $x
$var(graph,ds,ydata) set $y
$var(graph,ds,yedata) set $ye
}
xyexey {
set var(graph,ds,dim) xyexey
set var(graph,ds,xedata) $xedata
set var(graph,ds,yedata) $yedata
global $var(graph,ds,xedata) $var(graph,ds,yedata)
blt::vector create $var(graph,ds,xedata) $var(graph,ds,yedata)
for {set ii 0} {$ii<$ll} {incr ii 4} {
lappend x [lindex $data $ii]
lappend y [lindex $data [expr $ii+1]]
lappend xe [lindex $data [expr $ii+2]]
lappend ye [lindex $data [expr $ii+3]]
}
$var(graph,ds,xdata) set $x
$var(graph,ds,ydata) set $y
$var(graph,ds,xedata) set $xe
$var(graph,ds,yedata) set $ye
}
4.1 {
set var(graph,ds,dim) xyey
set var(graph,ds,yedata) $yedata
global $var(graph,ds,yedata)
blt::vector create $var(graph,ds,yedata)
for {set ii 0} {$ii<$ll} {incr ii 4} {
lappend x [lindex $data $ii]
lappend y [lindex $data [expr $ii+1]]
lappend ye [lindex $data [expr $ii+2]]
}
$var(graph,ds,xdata) set $x
$var(graph,ds,ydata) set $y
$var(graph,ds,yedata) set $ye
}
4.2 {
set var(graph,ds,dim) xy
for {set ii 0} {$ii<$ll} {incr ii 4} {
lappend x [lindex $data $ii]
lappend y [lindex $data [expr $ii+3]]
}
$var(graph,ds,xdata) set $x
$var(graph,ds,ydata) set $y
}
5.1 {
set var(graph,ds,dim) xyey
set var(graph,ds,yedata) $yedata
global $var(graph,ds,yedata)
blt::vector create $var(graph,ds,yedata)
for {set ii 0} {$ii<$ll} {incr ii 5} {
lappend x [lindex $data $ii]
lappend y [lindex $data [expr $ii+1]]
lappend ye [lindex $data [expr $ii+2]]
}
$var(graph,ds,xdata) set $x
$var(graph,ds,ydata) set $y
$var(graph,ds,yedata) set $ye
}
5.2 {
set var(graph,ds,dim) xyey
set var(graph,ds,yedata) $yedata
global $var(graph,ds,yedata)
blt::vector create $var(graph,ds,yedata)
for {set ii 0} {$ii<$ll} {incr ii 5} {
lappend x [lindex $data $ii]
lappend y [lindex $data [expr $ii+3]]
lappend ye [lindex $data [expr $ii+4]]
}
$var(graph,ds,xdata) set $x
$var(graph,ds,ydata) set $y
$var(graph,ds,yedata) set $ye
}
}
PlotAddElement $varname
}
proc PlotDupDataSet {varname mm} {
upvar #0 $varname var
global $varname
set cc $var(graph,current)
if {$var($cc,data,total) == 0} {
return
}
# incr count
incr ${varname}($cc,data,total)
set nn $var($cc,data,total)
set pp [expr $nn-1]
# new vector names
set xdata ap${varname}graph${cc}xx${nn}
set ydata ap${varname}graph${cc}yy${nn}
set xedata ap${varname}graph${cc}xe${nn}
set yedata ap${varname}graph${cc}ye${nn}
# basics
set var($cc,$nn,manage) 1
set var($cc,$nn,name) "Dataset $nn"
set var($cc,$nn,xdata) $xdata
set var($cc,$nn,ydata) $ydata
set var($cc,$nn,xedata) $xedata
set var($cc,$nn,yedata) $yedata
global $var($cc,$mm,xdata) $var($cc,$mm,ydata) \
$var($cc,$mm,xedata) $var($cc,$mm,yedata)
global $var($cc,$nn,xdata) $var($cc,$nn,ydata) \
$var($cc,$nn,xedata) $var($cc,$nn,yedata)
$var($cc,$mm,xdata) dup $var($cc,$nn,xdata)
$var($cc,$mm,ydata) dup $var($cc,$nn,ydata)
if {$var($cc,$mm,xedata) != {}} {
$var($cc,$mm,xedata) dup $var($cc,$nn,xedata)
} else {
set var($cc,$nn,xedata) {}
}
if {$var($cc,$mm,yedata) != {}} {
$var($cc,$mm,yedata) dup $var($cc,$nn,yedata)
} else {
set var($cc,$nn,yedata) {}
}
set var($cc,$nn,dim) $var($cc,$mm,dim)
set var($cc,$nn,show) $var($cc,$mm,show)
set var($cc,$nn,smooth) $var($cc,$mm,smooth)
set var($cc,$nn,color) $var($cc,$mm,color)
set var($cc,$nn,fill) $var($cc,$mm,fill)
set var($cc,$nn,fill,color) $var($cc,$mm,fill,color)
set var($cc,$nn,width) $var($cc,$mm,width)
set var($cc,$nn,dash) $var($cc,$mm,dash)
set var($cc,$nn,shape,symbol) $var($cc,$mm,shape,symbol)
set var($cc,$nn,shape,fill) $var($cc,$mm,shape,fill)
set var($cc,$nn,shape,color) $var($cc,$mm,shape,color)
set var($cc,$nn,error) $var($cc,$mm,error)
set var($cc,$nn,error,cap) $var($cc,$mm,error,cap)
set var($cc,$nn,error,color) $var($cc,$mm,error,color)
set var($cc,$nn,error,width) $var($cc,$mm,error,width)
set var($cc,$nn,bar,relief) $var($cc,$mm,bar,relief)
# make current
set var($cc,data,current) $nn
PlotRestoreState $varname
PlotAddElement $varname
PlotStats $varname
PlotList $varname
}
proc PlotLoadData {varname} {
upvar #0 $varname var
global $varname
set filename [OpenFileDialog apdatafbox]
if {$filename != {}} {
set dim xy
if {[PlotDataFormatDialog dim]} {
PlotLoadDataFile $varname $filename $dim
}
}
}
# used by backup
proc PlotLoadDataFile {varname filename dim} {
upvar #0 $varname var
global $varname
set ch [open $filename]
set data [read $ch]
close $ch
PlotRaise $varname
PlotAddDataSet $varname $dim $data
PlotStats $varname
PlotList $varname
}
proc PlotSaveData {varname} {
upvar #0 $varname var
global $varname
if {$var(graph,ds,xdata) == {}} {
return
}
PlotSaveDataFile $varname [SaveFileDialog apdatafbox]
}
proc PlotSaveDataFile {varname filename} {
upvar #0 $varname var
global $varname
if {$var(graph,ds,xdata) == {}} {
return
}
if {$filename == {}} {
return
}
global $var(graph,ds,xdata) $var(graph,ds,ydata) \
$var(graph,ds,xedata) $var(graph,ds,yedata)
set ll [$var(graph,ds,xdata) length]
set xx [$var(graph,ds,xdata) range]
set yy [$var(graph,ds,ydata) range]
set ch [open $filename w]
switch $var(graph,ds,dim) {
xy {
for {set ii 0} {$ii<$ll} {incr ii} {
puts $ch "[lindex $xx $ii] [lindex $yy $ii]"
}
}
xyex {
set xe [$var(graph,ds,xedata) range]
for {set ii 0} {$ii<$ll} {incr ii} {
puts $ch "[lindex $xx $ii] [lindex $yy $ii] [lindex $xe $ii]"
}
}
xyey {
set ye [$var(graph,ds,yedata) range]
for {set ii 0} {$ii<$ll} {incr ii} {
puts $ch "[lindex $xx $ii] [lindex $yy $ii] [lindex $ye $ii]"
}
}
xyexey {
set xe [$var(graph,ds,xedata) range]
set ye [$var(graph,ds,yedata) range]
for {set ii 0} {$ii<$ll} {incr ii} {
puts $ch "[lindex $xx $ii] [lindex $yy $ii] [lindex $xe $ii] [lindex $ye $ii]"
}
}
}
close $ch
PlotRaise $varname
}
proc PlotDeleteDataSet {varname} {
upvar #0 $varname var
global $varname
global ds9
set cc $var(graph,current)
set nn $var(graph,data,current)
if {$var($cc,data,total) == 0} {
return
}
if {$var($cc,$nn,manage)} {
# delete elements
foreach el [$var(graph) element names] {
set f [split $el -]
if {[lindex $f 1] == $nn} {
$var(graph) element delete $el
}
}
# destroy vectors
blt::vector destroy $var($cc,$nn,xdata) $var($cc,$nn,ydata)
switch $var($cc,$nn,dim) {
xy {}
xyex {blt::vector destroy $var($cc,$nn,xedata)}
xyey {blt::vector destroy $var($cc,$nn,yedata)}
xyexey {blt::vector destroy \
$var($cc,$nn,xedata) $var($cc,$nn,yedata)}
}
foreach vv [array names $varname] {
set ds [split $vv ,]
if {([lindex $ds 1] == $nn)} {
unset ${varname}($ds)
}
}
incr ${varname}($cc,data,total) -1
set ${varname}($cc,data,current) 0
}
}
proc PlotDeleteAllDataSet {varname} {
upvar #0 $varname var
global $varname
global ds9
set cc $var(graph,current)
if {$var($cc,data,total) == 0} {
return
}
# first set can be external
set clear $var($cc,1,manage)
for {set nn 1} {$nn<=$var($cc,data,total)} {incr nn} {
if {$var($cc,$nn,manage)} {
# delete elements
foreach el [$var(graph) element names] {
set f [split $el -]
if {[lindex $f 1] == $nn} {
$var(graph) element delete $el
}
}
# destroy vectors
blt::vector destroy \
$var($cc,$nn,xdata) $var($cc,$nn,ydata)
switch $var($cc,$nn,dim) {
xy {}
xyex {blt::vector destroy $var($cc,$nn,xedata)}
xyey {blt::vector destroy $var($cc,$nn,yedata)}
xyexey {blt::vector destroy \
$var($cc,$nn,xedata) $var($cc,$nn,yedata)}
}
foreach x [array names $varname] {
set f [split $x ,]
if {([lindex $f 0] == $nn)} {
unset ${varname}($x)
}
}
}
}
if {$clear} {
set var($cc,data,total) 0
set var($cc,data,current) 0
set var(graph,ds,name) {}
set var(graph,ds,xdata) {}
set var(graph,ds,ydata) {}
set var(graph,ds,xedata) {}
set var(graph,ds,yedata) {}
# reset other variables
set var($cc,axis,x,auto) 1
set var($cc,axis,x,min) {}
set var($cc,axis,x,max) {}
set var($cc,axis,x,format) {}
set var($cc,axis,y,auto) 1
set var($cc,axis,y,min) {}
set var($cc,axis,y,max) {}
set var($cc,axis,y,format) {}
$var(mb).graph.select delete $ds9(menu,start) end
$var(proc,updategraph) $varname
PlotStats $varname
PlotList $varname
} else {
set var($cc,data,total) 1
set var($cc,data,current) 1
$var(mb).graph.select delete [expr $ds9(menu,start)+1] end
PlotCurrentDataSet $varname
$var(proc,updategraph) $varname
}
}
|