Subversion Repositories f9daq

Rev

Blame | Last modification | View Log | RSS feed

#!/usr/bin/wish
#!/bin/sh
# the next line restarts using wish \
#  exec wish "$0" ${1+"$@"}


#***************************************************************
#      loading BLT package
#***************************************************************
lappend auto_path "/usr/lib/blt2.4"
if [ catch {package require BLT}] exit
if { $tcl_version >= 8.0 } {
    catch {namespace import blt::*}
   } else {
    catch { import add blt } }

#***************************************************************
#      loading EVD package
#***************************************************************
puts [ info nameofexecutable ]
puts [ info script ]
lappend auto_path [ file dirname [ info script ] ]
package require Evd

#***************************************************************
#      setting global variables (machine dependent)
#***************************************************************

set dump_dir "."
set data_dir "./data"
set config_dir "./config/rich00A"
set qapmt_dir "./pmtdb"


# hiding main window
wm withdraw .

set new_scan 0
set jmove 0
set m4color "#80FF80"
set m16color "#FFBBBB"
set evcolor "#000000"
set evrescan 0
set evnorm 1
set evm4norm 0
set evreverse 0
set evhot 0
set evmask 1
set evmap 1
set evprwin 0
set sreset 1


array set PSfontmap {"10x20" {"Helvetica-Bold" 12}
                     "6x12"  {"Helvetica-Bold" 8}}
lappend paltags c0 c1 c2 c3 c4 c5 c6 c7 c8 c9 c10 c11 c12 c13 c14 c15
set ovftag c16
set ovfcol "#FF0000"
lappend BWpal "#000000" "#111111" "#222222" "#333333" \
              "#444444" "#555555" "#666666" "#777777" \
              "#888888" "#999999" "#AAAAAA" "#BBBBBB" \
              "#CCCCCC" "#DDDDDD" "#EEEEEE" "#FFFFFF"
lappend BRpal "#0022FF" "#1122EE" "#2222DD" "#3322CC" \
              "#4422BB" "#5522AA" "#662299" "#772288" \
              "#882277" "#992266" "#AA2255" "#BB2244" \
              "#CC2233" "#DD2222" "#EE2211" "#FF2200"

#*** EVENT_DISPLAY window definitions

toplevel .ev
wm title .ev  "RICH Event Display"
wm protocol .ev WM_DELETE_WINDOW " "
   set evmag 2.
   set oldevmag 2.
   set tfont "10x20"
   wm geometry .ev 1016x760+10+10


#*** DETECTOR canvas definition

canvas .ev.det \
    -scrollregion "0 0 [expr $evmag*350] [expr $evmag*300]" \
    -background "#000080" \
    -cursor draft_small \
    -yscrollcommand { .ev.detvs set } \
    -xscrollcommand { .ev.deths set }
scrollbar .ev.detvs -orient vertical -command { .ev.det yview }
scrollbar .ev.deths -orient horizontal -command { .ev.det xview }
bind .ev.det <1> {set chout [open ch.dat a]
                  puts $chout [evstatl 0 \
                       [.ev.det canvasx %x] [.ev.det canvasy %y] $evmag]
                  close $chout}
bind .ev.det <Motion> {.ev.mapping configure -text [evstatl 0 \
                       [.ev.det canvasx %x] [.ev.det canvasy %y] $evmag]}

#*** GRAPH canvas definition

canvas .ev.gr \
    -background "#000000" \
    -yscrollcommand { .ev.grvs set } \
    -xscrollcommand { .ev.grhs set }
scrollbar .ev.grvs -orient vertical -command { .ev.gr yview }
scrollbar .ev.grhs -orient horizontal -command { .ev.gr xview }
set grm .ev.gr

#*** FED canvas definition

canvas .ev.fed \
    -scrollregion {0 0 280 738} \
    -background "#667788" \
    -cursor draft_small \
    -yscrollcommand { .ev.fedvs set } \
    -xscrollcommand { .ev.fedhs set }

scrollbar .ev.fedvs -orient vertical -command { .ev.fed yview }
scrollbar .ev.fedhs -orient horizontal -command { .ev.fed xview }
bind .ev.fed <Motion> {.ev.mapping configure -text [evstatl 1 \
                       [.ev.fed canvasx %x] [.ev.fed canvasy %y] ]}


#*** VECTORS

vector create nhx(2000)
nhx seq 5. 19995. 10.
vector create nhy(2000)
set nhy(:) 0.
vector create nbxx(220)
nbxx seq 0.5 219.5 1.
vector create nbxy(220)
set nhy(:) 0.
vector create hbxy(220)
set hbxy(:) 0.
vector create ncox(101)
ncox seq 0.5 100.5 1.
vector create nco4y(101)
set nco4y(:) 0.
vector create nco16y(101)
set nco16y(:) 0.
vector create nrepx(100)
nrepx seq 0.5 99.5 1.
vector create nrepy(100)
set nrepy(:) 0.
vector create nrep64y(100)
set nrep64y(:) 0.

#*** BARCHARTS

option add *Barchart.legend.hide yes
option add *Barchart.tickfont -*-helvetica-medium-r-normal-*-8-*
option add *Barchart.Element.relief flat
option add *Barchart.Element.foreground "#808080"

barchart $grm.nh -rightmargin 10 -title "Hits per event"
$grm.nh element create nh1 -xdata nhx -ydata nhy
$grm.nh configure -barwidth 10.
$grm.nh axis configure x -stepsize 5000.
Blt_ZoomStack $grm.nh
Blt_Crosshairs $grm.nh

barchart $grm.nbx -rightmargin 10 -title "Events per bunch"
$grm.nbx element create nbx1 -xdata nbxx -ydata nbxy
$grm.nbx configure -barwidth 1.
$grm.nbx axis configure x -stepsize 20.
Blt_ZoomStack $grm.nbx
Blt_Crosshairs $grm.nbx

barchart $grm.hbx -rightmargin 10 -title "Average hits per bunch"
$grm.hbx element create hbx1 -xdata nbxx -ydata hbxy
$grm.hbx configure -barwidth 1.
$grm.hbx axis configure x -stepsize 20.
Blt_ZoomStack $grm.hbx
Blt_Crosshairs $grm.hbx
lappend hdata hbx1
#array set hbxa { "n" [ nbxx length ] "x" "nbxx" "y" "hbxy" }

barchart $grm.nco -rightmargin 10 -title "Channel occupancy"
$grm.nco element create nco1 -xdata ncox -ydata nco4y -foreground $m4color
$grm.nco element create nco2 -xdata ncox -ydata nco16y -foreground $m16color
$grm.nco configure -barwidth 1. -barmode overlap
$grm.nco axis configure x -stepsize 10.
Blt_ZoomStack $grm.nco
Blt_Crosshairs $grm.nco

barchart $grm.nrep -rightmargin 10 -title "Repetition freq."
$grm.nrep element create nrep1 \
    -xdata nrepx -ydata nrepy -foreground "#a0a000"
$grm.nrep element create nrep2 \
    -xdata nrepx -ydata nrep64y -foreground "#00a0a0"
$grm.nrep configure -barwidth 1. -barmode overlap
$grm.nrep axis configure x -stepsize 10.
Blt_ZoomStack $grm.nrep
Blt_Crosshairs $grm.nrep

.ev.gr create window 2 1 -window $grm.nh -width 276 -height 198 -anchor nw
.ev.gr create window 2 201 -window $grm.nbx -width 276 -height 198 -anchor nw
.ev.gr create window 2 401 -window $grm.hbx -width 276 -height 198 -anchor nw
.ev.gr create window 2 601 -window $grm.nco -width 276 -height 198 -anchor nw
.ev.gr create window 2 801 -window $grm.nrep -width 276 -height 198 -anchor nw
.ev.gr configure  -scrollregion {0 0 280 1000}


#MENUBAR definitions

menu .ev.mb -type menubar -font $tfont -relief raised

  menu .ev.mb.f -font $tfont
    .ev.mb.f add command -label "Open" -command { set sreset 1 ; evopenp } \
                         -underline 0
    lappend open_disable ".ev.mb.f entryconfigure Open"
    .ev.mb.f add command -label "Append" -command { set sreset 0 ; evopenp } \
                         -underline 0
    lappend open_disable ".ev.mb.f entryconfigure Append"
    .ev.mb.f add command -label "Close" -command { evclosep 0 } \
                         -underline 0 -state disabled
    lappend open_enable ".ev.mb.f entryconfigure Close"
    .ev.mb.f add command -label "CloseGzip" -command { evclosep 1 } \
                         -underline 5 -state disabled
    lappend open_enable ".ev.mb.f entryconfigure CloseGzip"
    .ev.mb.f add separator
    .ev.mb.f add command -label "Print" -underline 0 \
          -command { if { $evprwin } {
         .ev.det postscript -file det.ps -pagewidth 17c -fontmap PSfontmap
        } else {
         .ev.det postscript -file det.ps -rotate 1 -x 0 -y 0 -pagewidth 25c \
                            -width [expr $evmag*350] \
                            -height [expr $evmag*300] -fontmap PSfontmap } }
    .ev.mb.f add separator
    .ev.mb.f add command -label "Exit" -command { evexit } -underline 0

  menu .ev.mb.t -font $tfont
    .ev.mb.t add command -label "Scan" -command evscanp -underline 0 \
                         -state disabled
    lappend open_enable ".ev.mb.t entryconfigure Scan"
    .ev.mb.t add command -label "Dump" -command evdumpp -underline 0 \
                         -state disabled
    lappend open_enable ".ev.mb.t entryconfigure Dump"
    menu .ev.mb.t.h -font $tfont
      foreach hname $hdata {
        .ev.mb.t.h add command -label $hname -command {
            set hid [ open hist.dat w ]
            set nl 0
            foreach i [ $grm.hbx element cget hbx1 -data ] {
              if $nl { puts $hid $i } else { puts -nonewline $hid "$i "}
              set nl [ expr ! $nl ] }
            close $hid } }
    .ev.mb.t add cascade -menu .ev.mb.t.h -label "Hout" -underline 0
  menu .ev.mb.tb -font $tfont

  menu .ev.mb.o -font $tfont
    menu .ev.mb.o.c -font $tfont
      foreach cfd [ split [ glob [file join [file dirname $config_dir] \
                   "*" ] ] " " ] {
        if [ file isdirectory $cfd] {
          .ev.mb.o.c add radiobutton -label [ file tail $cfd ] \
                     -value $cfd -variable config_dir \
                     -command evinitp }}
    .ev.mb.o add cascade -menu .ev.mb.o.c -label "Config" -underline 0
    lappend open_disable ".ev.mb.o entryconfigure Config"
    menu .ev.mb.o.mag -font $tfont
      .ev.mb.o.mag add radiobutton -value 1. -variable evmag -label "1x" \
               -command mag -underline 0
      .ev.mb.o.mag add radiobutton -value 2. -variable evmag -label "2x" \
               -command mag -underline 0
      .ev.mb.o.mag add radiobutton -value 4. -variable evmag -label "4x" \
               -command mag -underline 0
      .ev.mb.o.mag add radiobutton -value 8. -variable evmag -label "8x" \
               -command mag -underline 0
    .ev.mb.o add cascade -menu .ev.mb.o.mag -label "Magnification" -underline 0
    menu .ev.mb.o.pal -font $tfont
      .ev.mb.o.pal add command -label "BWpal" -underline 0 -command {
         foreach ctag $paltags cval $BWpal {
           .ev.det itemconfigure $ctag -fill $cval }}
      .ev.mb.o.pal add command -label "BRpal" -underline 1 -command {
         foreach ctag $paltags cval $BRpal {
           .ev.det itemconfigure $ctag -fill $cval }}
    .ev.mb.o add cascade -menu .ev.mb.o.pal -label "Palette" -underline 0

  .ev.mb add cascade -menu .ev.mb.f -label "File" -underline 0
  .ev.mb add cascade -menu .ev.mb.t -label "Tools" -underline 0
  .ev.mb add cascade -menu .ev.mb.tb -label "Toolbar" -underline 4
  .ev.mb add cascade -menu .ev.mb.o -label "Options" -underline 0


# TOOLBAR definitions

frame .ev.tb -height [expr $evmag*14] -background "#00AA00"

# OPEN & CLOSE button
button .ev.tb.opcl -text "Open" -command { set sreset 1 ; evopenp } \
                   -font $tfont
pack .ev.tb.opcl -side left -padx 2 -pady 2

# PREVIOUS event
button .ev.tb.prev -text "<" -command evprevplotp -state disabled \
       -font $tfont -width 0
lappend open_enable ".ev.tb.prev configure"
pack .ev.tb.prev -side left  -pady 2
bind .ev.tb.prev <2> { set curev [expr [.ev.tb.curev get]-10]
                       evgoto [expr [expr $curev>0]?$curev:1]
                       evplotp}
bind .ev.tb.prev <3> { set curev [expr [.ev.tb.curev get]-100]
                       evgoto [expr [expr $curev>0]?$curev:1]
                       evplotp}

# CURENT event
entry .ev.tb.curev -width 5 -font $tfont -state disabled
lappend open_enable ".ev.tb.curev configure"
pack .ev.tb.curev -side left  -pady 2
bind .ev.tb.curev <KeyPress-Return> { evgoto [.ev.tb.curev get]
                        evplotp}

# NEXT event
button .ev.tb.next -text ">" -command evplotp -state disabled \
       -font $tfont -width 0
lappend open_enable ".ev.tb.next configure"
pack .ev.tb.next -side left  -pady 2
bind .ev.tb.next <2> { evgoto [expr [.ev.tb.curev get]+10]
                       evplotp}
bind .ev.tb.next <3> { evgoto [expr [.ev.tb.curev get]+100]
                       evplotp}

# SCAN events
button .ev.tb.scan -text "Scan" -command { evscanp ; evscanplotp } \
       -state disabled -font $tfont -width 4
lappend open_enable ".ev.tb.scan configure"
pack .ev.tb.scan -side left -padx 2 -pady 2

# MAXIMUM of the scan
entry .ev.tb.scmax -width 3 -font $tfont
.ev.tb.scmax insert 0 "100"
pack .ev.tb.scmax -side left -padx 2 -pady 2

# JOIN & SPLIT detectors
button .ev.tb.join -text "Join" -command evjoin -font $tfont
pack .ev.tb.join -side left -padx 2 -pady 2

# AMOUNT of chenels to move
entry .ev.tb.jmove -width 3 -font $tfont
.ev.tb.jmove insert 0 "80"
pack .ev.tb.jmove -side left -padx 2 -pady 2

# PRINT button
button .ev.tb.print -text "Print" -font $tfont \
          -command { if { $evprwin } {
         .ev.det postscript -file det.ps -pagewidth 17c -fontmap PSfontmap
         .ev.fed postscript -file fed.ps -pageheight 25c
        } else {
         .ev.det postscript -file det.ps -rotate 1 -x 0 -y 0 -pagewidth 25c \
                            -width [expr $evmag*350] \
                            -height [expr $evmag*300] -fontmap PSfontmap
         .ev.fed postscript -file fed.ps -x 0 -y 0 -pageheight 25c \
                 -width 280 -height 738 }
         $grm.nh postscript output g1.eps -width 560 -height 400
         $grm.nbx postscript output g2.eps -width 560 -height 400
         $grm.hbx postscript output g3.eps -width 560 -height 400
         $grm.nco postscript output g4.eps -width 560 -height 400
         canvas .eps
         .eps create eps 4 4 -file g1.eps -showimage no
         .eps create eps 4 404 -file g2.eps -showimage no
         .eps create eps 564 4 -file g3.eps -showimage no
         .eps create eps 564 404 -file g4.eps -showimage no
         .eps postscript -file gr.ps -x 0 -y 0 -pagewidth 16c \
                         -width 1120 -height 800
         destroy .eps
         }
pack .ev.tb.print -side left -padx 2 -pady 2


# OPTIONS menu
menubutton .ev.tb.opt -menu .ev.tb.opt.m -text "Opt" -relief raised \
                      -font $tfont
menu .ev.tb.opt.m -font $tfont
.ev.tb.opt.m add checkbutton -variable evrescan -label "allways rescan"
.ev.tb.opt.m add checkbutton -variable evnorm -label "norm. to events"
.ev.tb.opt.m add checkbutton -variable evm4norm -label "norm. M4 channels"
.ev.tb.opt.m add checkbutton -variable evreverse -label "reverse scale"
.ev.tb.opt.m add checkbutton -variable evhot -label "rescan hot"
.ev.tb.opt.m add checkbutton -variable evmask -label "remove hot"
.ev.tb.opt.m add separator
.ev.tb.opt.m add checkbutton -variable evmap -label "focal plane map" \
                             -command { evinitp }
.ev.tb.opt.m add separator
.ev.tb.opt.m add checkbutton -variable evprwin -label "print only visible"
pack .ev.tb.opt -side right -padx 2 -pady 2


# MAGNIFICATION menu
menubutton .ev.tb.mag -menu .ev.tb.mag.m -text "Mag" -relief raised \
                      -font $tfont
menu .ev.tb.mag.m -font $tfont
.ev.tb.mag.m add radiobutton -value 1. -variable evmag -label "1x" -command mag
.ev.tb.mag.m add radiobutton -value 2. -variable evmag -label "2x" -command mag
.ev.tb.mag.m add radiobutton -value 4. -variable evmag -label "4x" -command mag
.ev.tb.mag.m add radiobutton -value 8. -variable evmag -label "8x" -command mag
pack .ev.tb.mag -side right -padx 2 -pady 2

frame .ev.tb1 -height [expr $evmag*14] -background "#0000AA"

# EXIT button
button .ev.tb1.ex -text {exit} -command { evexit } -font $tfont
pack .ev.tb1.ex -side right -padx 2 -pady 2


#*** STATUSLINE definitions

label .ev.mapping -relief ridge -anchor w -text "" -font $tfont
label .ev.evdata -relief ridge -anchor w -text "" -font $tfont
label .ev.status -relief ridge -anchor w -text "" -font $tfont

button .ev.yy -background "#000000"


#*** GEOMETRY MANAGER
  table .ev \
    0,0 .ev.mb -fill both -cspan 4 \
    1,0 .ev.tb -fill both -cspan 2 \
    1,2 .ev.tb1 -fill both -cspan 2 \
    2,0 .ev.det -fill both \
    2,1 .ev.detvs -fill both \
    3,0 .ev.deths -fill both \
    4,0 .ev.mapping -fill both -cspan 2 \
    5,0 .ev.evdata -fill both -cspan 2 -rspan 2 \
    2,2 .ev.gr -fill both -rspan 4 \
    6,2 .ev.grhs -fill both \
    2,3 .ev.grvs -fill both -rspan 4 \
    6,3 .ev.yy -fill both \
    7,0 .ev.status -fill both -cspan 4
  table configure .ev c1 c2 c3 r0 r1 r3 r4 r5 r6 r7 -resize none
  table configure .ev c2 -width [expr $evmag*140]
  table configure .ev c1 c3 -width [expr 8+$evmag*5]
  table configure .ev r3 r6 -height [expr 8+$evmag*5]
  table configure .ev r0 r1 -height [expr 10+$evmag*12]
  table configure .ev r2 -height { 100 1000 } -resize both
  table configure .ev c0 -width { 100 1200 } -resize both
  table arrange .ev



#*** display initialisation procedure

proc evinitp {} {
  global evmap evmag m4color m16color tfont config_dir
  .ev.det delete all
  .ev.fed delete all
  set xy [expr $evmag*10]
  if $evmap {
    .ev.det create text $xy $xy -text "FOCAL PLANE MAP" -fill "#00AA00" \
            -anchor w -font $tfont -tags t
    catch {table forget .ev.fed .ev.fedvs .ev.fedhs}
    table .ev \
    2,2 .ev.gr -fill both -rspan 4 \
    6,2 .ev.grhs -fill both \
    2,3 .ev.grvs -fill both -rspan 4
    } else {
    .ev.det create text $xy $xy -text "PMT PLANE MAP" -fill "#AA0000" \
            -anchor w -font $tfont -tags t
    catch {table forget .ev.gr .ev.grvs .ev.grhs}
    table .ev \
    2,2 .ev.fed -fill both -rspan 4 \
    6,2 .ev.fedhs -fill both \
    2,3 .ev.fedvs -fill both -rspan 4
    }
  puts  " $config_dir  $evmag"
  evinit .ev.det .ev.fed $evmag 
  .ev.det lower m4 m16
}
evinitp

#*** FILE open procedure

proc evopenp {} {
  global data_dir evmag new_scan evfile tfont evhot open_enable open_disable
  set new_scan 1
  if ![file isdirectory $data_dir] { set data_dir "." }
      set evfile [tk_getOpenFile -initialdir $data_dir -parent .ev \
          -filetypes { \
                      {"all data" {.dat .dat.gz .daq .daq.gz \
                                   .daq1 .daq1.gz .dst .dst.gz \
                                   .ric .ric.gz}} \
                      {"old data format" {.dat .dat.gz}} \
                      {"common-daq" {.daq .daq.gz}} \
                      {"mare-daq+rec" {.daq1 .daq1.gz}} \
                      {"common-dst" {.dst .dst.gz}} \
                      {"rich" {.ric .ric.gz}} \
                      {"all" {*}} \
                     }]
  if { $evfile != "" } {
    if { [set ztip [string last ".gz" $evfile]] != -1 } {
      exec gunzip $evfile
      set evfile [string range $evfile 0 [expr $ztip-1]]
    }
    set data_dir [file dirname $evfile]
    evopen $evfile
    foreach com $open_enable { eval $com -state normal }
    foreach com $open_disable { eval $com -state disabled }
    .ev.tb.opcl configure -text "Close" -command {evclosep 0}
    .ev.tb.curev delete 0 end
    .ev.det delete ev sc
    .ev.fed delete sc
    .ev.det delete tf
    .ev.det create text [expr $evmag*10] [expr $evmag*293] \
            -text [file tail $evfile] -fill "#00c0c0" \
            -anchor w -font $tfont -tags tf
    bind .ev.tb.opcl <2> {evclosep 1}
  }
}

#*** FILE close procedure

proc evclosep {gzipit} {
  global evfile gzip_stat withBLT open_enable open_disable
  set gzip_stat {}
# use of middle button will gzip file after close
  bind .ev.tb.opcl <2> {}
  evclose
  foreach com $open_enable { eval $com -state disabled }
  foreach com $open_disable { eval $com -state normal }
  if { $gzipit } {
    .ev.tb.opcl configure -state disabled
      if { $withBLT } {
        bgexec gzip_stat gzip $evfile } else {
        exec gzip $evfile }
    .ev.tb.opcl configure -state normal }
  .ev.tb.opcl configure -text "Open" -command evopenp
}

#*** FILE dump procedure

proc evdumpp {} {
  global dump_dir
  if ![file isdirectory $dump_dir] { set dump_dir "." }
      set dumpfile [tk_getSaveFile -initialdir $dump_dir -parent .ev \
          -filetypes { \
                      {"rich" {.ric}} \
                      {"all" {*}} \
                     }]
  if { $dumpfile != "" } {
    set dump_dir [file dirname $dumpfile]
    evdump $dumpfile
  }
}

#*** procedure to produce occupancy plot

proc evscanp {} {
  global evmag new_scan evrescan evnorm evreverse evmask
#  global nhy nbxy hbxy nco4y nco16y nrepy nrep64y
    if { $new_scan || $evrescan} {
      uplevel #0 { evscan }
      set new_scan 0
    }
}

proc evscanplotp {} {
  .ev.det delete ev sc
  .ev.fed delete ev sc
  .ev.status configure -text \
     [ uplevel #0 { evscanplot .ev.det $evmag [ .ev.tb.scmax get ] .ev.fed } ]
}

#*** procedure to join detector halfs

proc evjoin {} {
  global evmag jmove
  .ev.tb.jmove configure -state disabled
  .ev.tb.scan configure -state disabled
  set jmove [.ev.tb.jmove get]
  .ev.det addtag ld enclosed 0 [expr $evmag*150] [expr $evmag*350] \
          [expr $evmag*300]
  .ev.det move ld 0 [expr -$evmag*$jmove]
  .ev.tb.join configure -text "Split" -command evsplit
}

#*** procedure to split detector halfs

proc evsplit {} {
  global evmag jmove
  .ev.tb.jmove configure -state normal
  .ev.tb.scan configure -state normal
  .ev.det move ld 0 [expr $evmag*$jmove]
  set jmove 0
  .ev.tb.join configure -text "Join" -command evjoin
}

#*** procedure to plot previose event

proc evprevplotp {} {
  set curev [expr [.ev.tb.curev get]-1]
  evgoto [expr [expr $curev>0]?$curev:1]
  evplotp
}

#*** procedure to plot next event

proc evplotp {} {
  global evmag evcolor jmove tfont evmask
  .ev.det delete ev sc ri
  .ev.fed delete ev sc
  .ev.evdata configure -text [evplot .ev.det $evmag .ev.fed]
}

#*** called when magnification factor is changed

proc mag {} {
  global evmag oldevmag
  set sc [expr $evmag/$oldevmag]
  set xf [lindex [.ev.det xview] 0]
  set yf [lindex [.ev.det yview] 0]
  .ev.det configure -scrollregion "0 0 [expr $evmag*350] [expr $evmag*300]"
  .ev.det xview moveto $xf
  .ev.det yview moveto $yf
  .ev.det scale all 0 0 $sc $sc
  set oldevmag $evmag
}

proc evexit {} {
  exit
}

proc center {x y} {
  puts [table cget .ev c0 -width]
}