# Author: Alex Koubarovski
# Date:   10/02/00
#
# $Id: examine.tcl,v 1.4 2000/11/21 22:17:37 alex_k Exp $
#
# Front-end GUI for SMT Examine
#



wm geometry . 800x200+200+200
wm title . "SMT Subdetecor EXAMINE"
wm minsize . 1 1

# --------------------------------------------------------
# Frames: 
# --------------------------------------------------------

frame .topmenu1 -relief raised -bd 2
frame .mbar   -relief sunken -bd 2      
frame .cmode   -relief raised -bd 2    
frame .mode   -relief raised -bd 2     
frame .panel  -relief raised -bd 2    

pack .topmenu1 .cmode .mode .mbar .panel -side top -fill x -expand 1

global crID hdi_type pvrbID hdit
global b3 bl3 
global bIDm crIDm vIDm cIDm chips lay_m lad_m
global fIDm fchips wed_m f0d
global mode1 mode2 mode5 mode3 mode4 mode10
global test_chips
global fn1
global btype rname hname iname
global ex_text raw_text ch_text sp_text u_text
set mode1 3
set mode2 1
set mode3 2
set mode4 2
set mode5 1
set hname "examine.hbook"
set rname "examine.root"
set btype "ROOT"
set iname "input"
set u_text "TRUE"
set ch_text "FALSE"
set sp_text "FALSE"
set ex_text "TRUE"
set raw_text "STATIC"




set fb [open barrel_mapping_global.txt r]
for {set i 1} {$i<=72} {incr i 1} {
  gets $fb str
scan $str "%d %d %d %d %d %d" crIDm vIDm cIDm chipm laym ladm

set chips($vIDm,$cIDm) $chipm 
set lay_m($vIDm,$cIDm) $laym
set lad_m($vIDm,$cIDm) $ladm  
set bIDm($vIDm,$cIDm) 4  
#  puts $vIDm
#  puts $cIDm
#  puts $lad_m($vIDm,$cIDm)  
#  puts $lay_m($vIDm,$cIDm)
#  puts $chips($vIDm,$cIDm)  
 
#puts $chips(30,0)

}

set fd [open fdisk_mapping_global.txt r]
for {set j 1} {$j<=24} {incr j 1} {
  gets $fd str
scan $str "%d %d %d %d %d %d %d" crIDm vIDm cIDm fchipm fwedm fdm fdiskm

set fchips($vIDm,$cIDm) $fchipm 
set wed_m($vIDm,$cIDm) $fwedm
set f0d($vIDm,$cIDm) $fdm  
set fIDm($vIDm,$cIDm) $fdiskm  
#  puts $vIDm
#  puts $cIDm
#  puts $lad_m($vIDm,$cIDm)  
#  puts $lay_m($vIDm,$cIDm)
#  puts $chips($vIDm,$cIDm)  
 
#puts $chips(30,0)

}





close $fb
set b3 1
set bl3 1


set hdit(1) L3
set hdit(2) L6
set hdit(3) L9
set hdit(4) FW6
set hdit(5) FW8
set hdit(6) HW6
set hdit(7) On
set hdit(8) Off 
set hdit(9) On_

for {set i 0} {$i<=8} {incr i 1} {
    set vrbID($i) 0
    for {set j 0} {$j<=7} {incr j 1} {
	set hdi_type($i,$j) $hdit(7)
    }
}

for {set i 9} {$i<=12} {incr i 1} {
    set vrbID($i) 0
    for {set j 0} {$j<=7} {incr j 1} {
	set hdi_type($i,$j) $hdit(9)
    }
}


set fn1 -adobe-helvetica-bold-o-normal--14-*-*-*-*-*-*-*
set fni -adobe-courier-bold-o-normal--17-*-*-*-*-*-*-*
set fn -adobe-times-bold-r-normal--14-*-*-*-*-*-*-*
set crID 63

menubutton .topmenu1.help -text Help -underline 0 -menu .topmenu1.help.menu

pack .topmenu1.help -side right

menu .topmenu1.help.menu
.topmenu1.help.menu add command -label "Help" -command {help} 
.topmenu1.help.menu add command -label "About"

set mod "FILE MODE"
set mod_text "FILE MODE"


button .panel.exit -relief raised  -text "EXIT" -command exit -bg royalblue2 -bd 4 \
	-fg snow -activebackground lightskyblue1 -width 12
label .panel.lab -text "in" -width 2
button .panel.mod  -text $mod_text -width 7 -relief raised  \
-bd 4 -bg deepskyblue -activebackground lightskyblue1 -font $fni \
    -command {
	if {$mod_text == $mod } {
	    set mod_text "NET MODE"
	    set mode3 1
            .panel.mod configure -text $mod_text
	} else { 
	    set mod_text "FILE MODE"
	    set mode3 2
	    .panel.mod configure -text $mod_text
	}
    }
 

button .panel.save -relief raised  -text "Save Config" -bg royalblue2 -bd 4 \
    -fg snow -activebackground lightskyblue1 -width 12 -command { 

write_file
}


button .panel.start -relief raised  -text "START EXAMINE" -bg royalblue2 -bd 4 \
    -fg snow -activebackground lightskyblue1 -width 12 -command { 





#puts $hdi_type(0,0)
#puts $hdi_type(0,1)




	write_file
	wm iconify .

	#puts "Starting SMT Examine as batch process in queue smt (type bjobs to watch it)"
	puts "Starting SMT Examine..."
	exec rm -f $hname

	if {$mode3 == 2} then {
	    
	exec -keepnewline testSmtExamine -rcp frameworkFILE.rcp 
        } else {
	    
	exec -keepnewline testSmtExamine -rcp frameworkNET.rcp &
    }


}
  
menubutton .mbar.vrb0 -text VRB0 -relief raised  \
-bd 4 -bg deepskyblue -activebackground lightskyblue1 -font $fni -menu .mbar.vrb0.menu
menu .mbar.vrb0.menu
.mbar.vrb0.menu add radiobutton -label "Ladder" -command {hdis .vrb0 0 1 $crIDm}
.mbar.vrb0.menu add radiobutton -label "F-Wedge" -command {hdis .vrb0 0 2 $crIDm}
.mbar.vrb0.menu add radiobutton -label "h-Wedge" -command {hdis .vrb0 0 3 $crIDm}
     
menubutton .mbar.vrb1 -text VRB1 -relief raised  \
-bd 4 -bg deepskyblue -activebackground lightskyblue1 -font $fni -menu .mbar.vrb1.menu
menu .mbar.vrb1.menu
.mbar.vrb1.menu add radiobutton -label "Ladder" -command {hdis .vrb1 1 1 $crIDm}
.mbar.vrb1.menu add radiobutton -label "F-Wedge" -command {hdis .vrb1 1 2 $crIDm}
.mbar.vrb1.menu add radiobutton -label "h-Wedge" -command {hdis .vrb1 1 3 $crIDm}
     
menubutton .mbar.vrb2 -text VRB2 -relief raised  \
-bd 4 -bg deepskyblue -activebackground lightskyblue1 -font $fni -menu .mbar.vrb2.menu
menu .mbar.vrb2.menu
.mbar.vrb2.menu add radiobutton -label "Ladder" -command {hdis .vrb2 2 1 $crIDm}
.mbar.vrb2.menu add radiobutton -label "F-Wedge" -command {hdis .vrb2 2 2 $crIDm}
.mbar.vrb2.menu add radiobutton -label "h-Wedge" -command {hdis .vrb2 2 3 $crIDm}
     
menubutton .mbar.vrb3 -text VRB3 -relief raised  \
-bd 4 -bg deepskyblue -activebackground lightskyblue1 -font $fni -menu .mbar.vrb3.menu
menu .mbar.vrb3.menu
.mbar.vrb3.menu add radiobutton -label "Ladder" -command {hdis .vrb3 3 1 $crIDm}
.mbar.vrb3.menu add radiobutton -label "F-Wedge" -command {hdis .vrb3 3 2 $crIDm}
.mbar.vrb3.menu add radiobutton -label "h-Wedge" -command {hdis .vrb3 3 3 $crIDm}
     
menubutton .mbar.vrb4 -text VRB4 -relief raised  \
-bd 4 -bg deepskyblue -activebackground lightskyblue1 -font $fni -menu .mbar.vrb4.menu
menu .mbar.vrb4.menu
.mbar.vrb4.menu add radiobutton -label "Ladder" -command {hdis .vrb4 4 1 $crIDm}
.mbar.vrb4.menu add radiobutton -label "F-Wedge" -command {hdis .vrb4 4 2 $crIDm}
.mbar.vrb4.menu add radiobutton -label "h-Wedge" -command {hdis .vrb4 4 3 $crIDm}

menubutton .mbar.vrb5 -text VRB5 -relief raised  \
-bd 4 -bg deepskyblue -activebackground lightskyblue1 -font $fni -menu .mbar.vrb5.menu
menu .mbar.vrb5.menu
.mbar.vrb5.menu add radiobutton -label "Ladder" -command {hdis .vrb5 5 1 $crIDm}
.mbar.vrb5.menu add radiobutton -label "F-Wedge" -command {hdis .vrb5 5 2 $crIDm}
.mbar.vrb5.menu add radiobutton -label "h-Wedge" -command {hdis .vrb5 5 3 $crIDm}

menubutton .mbar.vrb6 -text VRB6 -relief raised  \
-bd 4 -bg deepskyblue -activebackground lightskyblue1 -font $fni -menu .mbar.vrb6.menu
menu .mbar.vrb6.menu
.mbar.vrb6.menu add radiobutton -label "Ladder" -command {hdis .vrb6 6 1 $crIDm}
.mbar.vrb6.menu add radiobutton -label "F-Wedge" -command {hdis .vrb6 6 2 $crIDm}
.mbar.vrb6.menu add radiobutton -label "h-Wedge" -command {hdis .vrb6 6 3 $crIDm}

menubutton .mbar.vrb7 -text VRB7 -relief raised  \
-bd 4 -bg deepskyblue -activebackground lightskyblue1 -font $fni -menu .mbar.vrb7.menu
menu .mbar.vrb7.menu
.mbar.vrb7.menu add radiobutton -label "Ladder" -command {hdis .vrb7 7 1 $crIDm}
.mbar.vrb7.menu add radiobutton -label "F-Wedge" -command {hdis .vrb7 7 2 $crIDm}
.mbar.vrb7.menu add radiobutton -label "h-Wedge" -command {hdis .vrb7 7 3 $crIDm}

menubutton .mbar.vrb8 -text VRB8 -relief raised  \
-bd 4 -bg deepskyblue -activebackground lightskyblue1 -font $fni -menu .mbar.vrb8.menu
menu .mbar.vrb8.menu
.mbar.vrb8.menu add radiobutton -label "Ladder" -command {hdis .vrb8 8 1 $crIDm}
.mbar.vrb8.menu add radiobutton -label "F-Wedge" -command {hdis .vrb8 8 2 $crIDm}
.mbar.vrb8.menu add radiobutton -label "h-Wedge" -command {hdis .vrb8 8 3 $crIDm}
                         
menubutton .mbar.vrb9 -text VRB9 -relief raised  \
-bd 4 -bg deepskyblue -activebackground lightskyblue1 -font $fni -menu .mbar.vrb9.menu
menu .mbar.vrb9.menu
.mbar.vrb9.menu add radiobutton -label "Ladder" -command {hdis .vrb9 9 1 $crIDm}
.mbar.vrb9.menu add radiobutton -label "F-Wedge" -command {hdis .vrb9 9 2 $crIDm}
.mbar.vrb9.menu add radiobutton -label "h-Wedge" -command {hdis .vrb9 9 3 $crIDm}

menubutton .mbar.vrb10 -text VRB10 -relief raised  \
-bd 4 -bg deepskyblue -activebackground lightskyblue1 -font $fni -menu .mbar.vrb10.menu
menu .mbar.vrb10.menu
.mbar.vrb10.menu add radiobutton -label "Ladder" -command {hdis .vrb10 10 1 $crIDm}
.mbar.vrb10.menu add radiobutton -label "F-Wedge" -command {hdis .vrb10 10 2 $crIDm}
.mbar.vrb10.menu add radiobutton -label "h-Wedge" -command {hdis .vrb10 10 3 $crIDm}

menubutton .mbar.vrb11 -text VRB11 -relief raised  \
-bd 4 -bg deepskyblue -activebackground lightskyblue1 -font $fni -menu .mbar.vrb11.menu
menu .mbar.vrb11.menu
.mbar.vrb11.menu add radiobutton -label "Ladder" -command {hdis .vrb11 11 1 $crIDm}
.mbar.vrb11.menu add radiobutton -label "F-Wedge" -command {hdis .vrb11 11 2 $crIDm}
.mbar.vrb11.menu add radiobutton -label "h-Wedge" -command {hdis .vrb11 11 3 $crIDm}





set gcrID 0x$crID
label .cmode.lab -relief raised  -text " CrateID: " -bg royalblue2 -bd 1 -fg snow	
entry .cmode.crate -relief sunken -width 4 -bd 1 -font $fn1 -bg lightskyblue1 -textvariable gcrID 

set h_text "SELECTED"
set hm "SELECTED"
set mode5 1

label .mode.hlab -relief raised  -text " Histos mode: " -bg royalblue2 -bd 1 -fg snow
button .mode.type  -text $h_text -width 9 -relief raised   \
-bd 4 -bg deepskyblue -activebackground lightskyblue1 -font $fni \
-command { 
	if {$h_text == $hm } {
	    set h_text "FULL"
	    set mode5 2
            .mode.type configure -text $h_text
	} else { 
	    set h_text "SELECTED"
	    set mode5 1
	    .mode.type configure -text $h_text
	}
    }
button .mode.setup  -text "Histos and I/O  setup" -width 19 -relief raised   \
-bd 4 -bg deepskyblue -activebackground lightskyblue1 -font $fni -command { histo_setup }


pack .cmode.lab .cmode.crate  -padx 0.5m -side left

pack  .mode.type .mode.hlab -padx 0.5m -side right
pack .mode.setup -padx 0.5m -side left
pack .mbar.vrb0 .mbar.vrb1 .mbar.vrb2 .mbar.vrb3 .mbar.vrb4 .mbar.vrb5 .mbar.vrb6 .mbar.vrb7 .mbar.vrb8 .mbar.vrb9 .mbar.vrb10 .mbar.vrb11 \
-padx 0.5m -side left 
pack .panel.save .panel.start .panel.lab .panel.mod .panel.exit -padx 0.5m -side left  
pack .panel.exit -padx 0.5m -side right 

#puts $hdi_type(0,0)


proc hdis { vrb_num1 vrb1 int_det_type gcrID} {
global vrb_num vrb hdi_type
set vrb_num $vrb_num1
set vrb $vrb1
toplevel $vrb_num
wm geometry $vrb_num 800x70-380+430 
wm minsize      $vrb_num 1 1
wm title  $vrb_num VRB$vrb
wm iconname $vrb_num "VRB Setup"

frame $vrb_num.chains -relief raised
pack $vrb_num.chains

set hdisk H-Disk
set fdisk F-disk
#puts $vrb_num
   


global gvrbT gvrb vrbID pvrbID det_type gint_det_type hdit

set gvrb $vrb
set ggvrb $vrb
    if {$vrb == 10} {set ggvrb A}
    if {$vrb == 11} {set ggvrb B}
set gint_det_type($gvrb) $int_det_type
set gvrbT [expr $gcrID -60]

#puts $int_det_type
#puts $gint_det_type($gvrb)
if {$gint_det_type($gvrb) == 1} {

    set vrbT  $gvrbT
    if {$vrbT == 10} {set vrbT A}
    if {$vrbT == 11} {set vrbT B}
    set det_type($gvrb) Barrel
    set vrbID($gvrb) $vrbT$ggvrb
    set pvrbID($gvrb) 0x$vrbT$ggvrb
    set jbegin 1
    set jend 3
    for {set l 0} {$l <=7} {incr l 1} {
#     set hdi_type($vrb,$l) 0
    }


}
if {$gint_det_type($gvrb) == 2} {

    set vrbT  [expr $gvrbT+4]
#    if {$vrbT == 10} {set vrbT A}
#    if {$vrbT == 11} {set vrbT B}
    set det_type($gvrb) Barrel
    set vrbID($gvrb) $vrbT$ggvrb
    set pvrbID($gvrb) $vrbT$ggvrb
    set jbegin 4
    set jend 5
    for {set l 0} {$l <=7} {incr l 1} {
#     set hdi_type($vrb,$l) 0
    }

set det_type($gvrb) F-Disk
}
if {$gint_det_type($gvrb) == 3} {
set det_type($gvrb) H-Disk

    set vrbT  [expr $gvrbT+7]
    if {$vrbT == 10} {set vrbT A}
    if {$vrbT == 11} {set vrbT B}
    set det_type($gvrb) H-Disk
    set vrbID($gvrb) $vrbT$ggvrb
    set pvrbID($gvrb) 0x$vrbT$ggvrb
    set jbegin 6
    set jend 6
    for {set l 0} {$l <=7} {incr l 1} {
#     set hdi_type($vrb,$l) 0
    }


}

#puts $vrbID($gvrb)





entry $vrb_num.entrdet -relief sunken -width 7 -bd 1 -bg  \
lightskyblue1 -textvariable det_type($gvrb) 


label $vrb_num.lab -relief raised -text "VRB Address: " -bg royalblue2 -bd 1 -fg snow	
entry $vrb_num.add -relief sunken -width 7 -bd 1 -bg lightskyblue1 -textvariable pvrbID($gvrb) 



global chain hdi_type_cur list

set list {$vrb_num.chains.hdi0 $vrb_num.chains.hdi1 $vrb_num.chains.hdi2 $vrb_num.chains.hdi3 \
$vrb_num.chains.hdi4 $vrb_num.chains.hdi5 $vrb_num.chains.hdi6  $vrb_num.chains.hdi7}

menubutton  $vrb_num.chains.hdi0 -relief raised -text Chain0:  -width 7 \
-bg Pink -activebackground MistyRose  -menu $vrb_num.chains.hdi0.menu
menu $vrb_num.chains.hdi0.menu -bg MistyRose 
entry $vrb_num.chains.entr0 -relief sunken -width 4 -bd 1 -bg \
lightskyblue1 -textvariable hdi_type($vrb,0)
if {$gint_det_type($gvrb) == 1} {

$vrb_num.chains.hdi0.menu add radiobutton -label $hdit(7) -variable hdi_type($vrb,0) \
-value $hdit(7) -command {
$vrb_num.chains.entr0 configure -textvariable hdi_type($vrb,0)
puts$hdi_type($vrb,0)
}
$vrb_num.chains.hdi0.menu add radiobutton -label $hdit(8) -variable hdi_type($vrb,0) \
-value 0 -command {
$vrb_num.chains.entr0 configure -textvariable hdi_type($vrb,0)
#puts$hdi_type($vrb,0)
}



$vrb_num.chains.hdi0.menu add radiobutton -label $hdit(1) -variable hdi_type($vrb,0) \
-value $hdit(1) -command {
$vrb_num.chains.entr0 configure -textvariable hdi_type($vrb,0)
#puts$hdi_type($vrb,0)
}
$vrb_num.chains.hdi0.menu add radiobutton -label $hdit(2) -variable hdi_type($vrb,0) \
-value $hdit(2) -command { 
$vrb_num.chains.entr0 configure -textvariable hdi_type($vrb,0)
#puts$hdi_type($vrb,0)
}
$vrb_num.chains.hdi0.menu add radiobutton -label $hdit(3) -variable hdi_type($vrb,0) \
-value $hdit(3) -command {
$vrb_num.chains.entr0 configure -textvariable hdi_type($vrb,0)
#puts$hdi_type($vrb,0)
}
}
if {$gint_det_type($gvrb) == 2} {
$vrb_num.chains.hdi0.menu add radiobutton -label $hdit(9) -variable hdi_type($vrb,0) \
-value $hdit(9) -command {
$vrb_num.chains.entr0 configure -textvariable hdi_type($vrb,0)
#puts$hdi_type($vrb,0)
}
$vrb_num.chains.hdi0.menu add radiobutton -label $hdit(8) -variable hdi_type($vrb,0) \
-value 0 -command {
$vrb_num.chains.entr0 configure -textvariable hdi_type($vrb,0)
#puts$hdi_type($vrb,0)
}    
$vrb_num.chains.hdi0.menu add radiobutton -label $hdit(4) -variable hdi_type($vrb,0) \
-value $hdit(4) -command {
$vrb_num.chains.entr0 configure -textvariable hdi_type($vrb,0)
#puts$hdi_type($vrb,0)
}
$vrb_num.chains.hdi0.menu add radiobutton -label $hdit(5) -variable hdi_type($vrb,0) \
-value $hdit(5) -command {
$vrb_num.chains.entr0 configure -textvariable hdi_type($vrb,0)
#puts$hdi_type($vrb,0)
}
}
if {$gint_det_type($gvrb) == 3} {
$vrb_num.chains.hdi0.menu add radiobutton -label $hdit(7) -variable hdi_type($vrb,0) \
-value $hdit(7) -command {
$vrb_num.chains.entr0 configure -textvariable hdi_type($vrb,0)
#puts$hdi_type($vrb,0)
}
$vrb_num.chains.hdi0.menu add radiobutton -label $hdit(8) -variable hdi_type($vrb,0) \
-value 0 -command {
$vrb_num.chains.entr0 configure -textvariable hdi_type($vrb,0)
#puts$hdi_type($vrb,0)
}

$vrb_num.chains.hdi0.menu add radiobutton -label $hdit(6) -variable hdi_type($vrb,0) \
-value $hdit(6) -command {
$vrb_num.chains.entr0 configure -textvariable hdi_type($vrb,0)
#puts$hdi_type($vrb,0)
}
}



menubutton  $vrb_num.chains.hdi1 -relief raised -text Chain1:  -width 7 \
-bg Pink -activebackground MistyRose  -menu $vrb_num.chains.hdi1.menu
menu $vrb_num.chains.hdi1.menu -bg MistyRose 
entry $vrb_num.chains.entr1 -relief sunken -width 4 -bd 1 -bg \
lightskyblue1 -textvariable hdi_type($vrb,1)
if {$gint_det_type($gvrb) == 1} {
$vrb_num.chains.hdi1.menu add radiobutton -label $hdit(7) -variable hdi_type($vrb,1) \
-value $hdit(7) -command {
$vrb_num.chains.entr1 configure -textvariable hdi_type($vrb,1)
#puts$hdi_type($vrb,1)
}
$vrb_num.chains.hdi1.menu add radiobutton -label $hdit(8) -variable hdi_type($vrb,1) \
-value 0 -command {
$vrb_num.chains.entr1 configure -textvariable hdi_type($vrb,1)
#puts$hdi_type($vrb,1)
}


$vrb_num.chains.hdi1.menu add radiobutton -label $hdit(1) -variable hdi_type($vrb,1) \
-value $hdit(1) -command {
$vrb_num.chains.entr1 configure -textvariable hdi_type($vrb,1)
#puts$hdi_type($vrb,1)
}
$vrb_num.chains.hdi1.menu add radiobutton -label $hdit(2) -variable hdi_type($vrb,1) \
-value $hdit(2) -command { 
$vrb_num.chains.entr1 configure -textvariable hdi_type($vrb,1)
#puts$hdi_type($vrb,1)
}
$vrb_num.chains.hdi1.menu add radiobutton -label $hdit(3) -variable hdi_type($vrb,1) \
-value $hdit(3) -command {
$vrb_num.chains.entr1 configure -textvariable hdi_type($vrb,1)
#puts$hdi_type($vrb,1)
}
}
if {$gint_det_type($gvrb) == 2} {
$vrb_num.chains.hdi1.menu add radiobutton -label $hdit(9) -variable hdi_type($vrb,1) \
-value $hdit(9) -command {
$vrb_num.chains.entr1 configure -textvariable hdi_type($vrb,1)
#puts$hdi_type($vrb,1)
}
$vrb_num.chains.hdi1.menu add radiobutton -label $hdit(8) -variable hdi_type($vrb,1) \
-value 0 -command {
$vrb_num.chains.entr1 configure -textvariable hdi_type($vrb,1)
#puts$hdi_type($vrb,1)
}    
$vrb_num.chains.hdi1.menu add radiobutton -label $hdit(4) -variable hdi_type($vrb,1) \
-value $hdit(4) -command {
$vrb_num.chains.entr1 configure -textvariable hdi_type($vrb,1)
#puts$hdi_type($vrb,1)
}
$vrb_num.chains.hdi1.menu add radiobutton -label $hdit(5) -variable hdi_type($vrb,1) \
-value $hdit(5) -command {
$vrb_num.chains.entr1 configure -textvariable hdi_type($vrb,1)
#puts$hdi_type($vrb,1)
}
}
if {$gint_det_type($gvrb) == 3} {
$vrb_num.chains.hdi1.menu add radiobutton -label $hdit(7) -variable hdi_type($vrb,1) \
-value $hdit(7) -command {
$vrb_num.chains.entr1 configure -textvariable hdi_type($vrb,1)
#puts$hdi_type($vrb,1)
}
$vrb_num.chains.hdi1.menu add radiobutton -label $hdit(8) -variable hdi_type($vrb,1) \
-value 0 -command {
$vrb_num.chains.entr1 configure -textvariable hdi_type($vrb,1)
#puts$hdi_type($vrb,1)
}
$vrb_num.chains.hdi1.menu add radiobutton -label $hdit(6) -variable hdi_type($vrb,1) \
-value $hdit(6) -command {
$vrb_num.chains.entr1 configure -textvariable hdi_type($vrb,1)
#puts$hdi_type($vrb,1)
}
}


menubutton  $vrb_num.chains.hdi2 -relief raised -text Chain2:  -width 7 \
-bg Pink -activebackground MistyRose  -menu $vrb_num.chains.hdi2.menu
menu $vrb_num.chains.hdi2.menu -bg MistyRose 
entry $vrb_num.chains.entr2 -relief sunken -width 4 -bd 1 -bg \
lightskyblue1 -textvariable hdi_type($vrb,2)
if {$gint_det_type($gvrb) == 1} {
$vrb_num.chains.hdi2.menu add radiobutton -label $hdit(7) -variable hdi_type($vrb,2) \
-value $hdit(7) -command {
$vrb_num.chains.entr2 configure -textvariable hdi_type($vrb,2)
#puts$hdi_type($vrb,2)
}
$vrb_num.chains.hdi2.menu add radiobutton -label $hdit(8) -variable hdi_type($vrb,2) \
-value 0 -command {
$vrb_num.chains.entr2 configure -textvariable hdi_type($vrb,2)
#puts$hdi_type($vrb,2)
}
$vrb_num.chains.hdi2.menu add radiobutton -label $hdit(1) -variable hdi_type($vrb,2) \
-value $hdit(1) -command {
$vrb_num.chains.entr2 configure -textvariable hdi_type($vrb,2)
#puts$hdi_type($vrb,2)
}
$vrb_num.chains.hdi2.menu add radiobutton -label $hdit(2) -variable hdi_type($vrb,2) \
-value $hdit(2) -command { 
$vrb_num.chains.entr2 configure -textvariable hdi_type($vrb,2)
#puts$hdi_type($vrb,2)
}
$vrb_num.chains.hdi2.menu add radiobutton -label $hdit(3) -variable hdi_type($vrb,2) \
-value $hdit(3) -command {
$vrb_num.chains.entr2 configure -textvariable hdi_type($vrb,2)
#puts$hdi_type($vrb,2)
}
}
if {$gint_det_type($gvrb) == 2} {
$vrb_num.chains.hdi2.menu add radiobutton -label $hdit(9) -variable hdi_type($vrb,2) \
-value $hdit(9) -command {
$vrb_num.chains.entr2 configure -textvariable hdi_type($vrb,2)
#puts$hdi_type($vrb,2)
}
$vrb_num.chains.hdi2.menu add radiobutton -label $hdit(8) -variable hdi_type($vrb,2) \
-value 0 -command {
$vrb_num.chains.entr2 configure -textvariable hdi_type($vrb,2)
#puts$hdi_type($vrb,2)
}    
$vrb_num.chains.hdi2.menu add radiobutton -label $hdit(4) -variable hdi_type($vrb,2) \
-value $hdit(4) -command {
$vrb_num.chains.entr2 configure -textvariable hdi_type($vrb,2)
#puts$hdi_type($vrb,2)
}
$vrb_num.chains.hdi2.menu add radiobutton -label $hdit(5) -variable hdi_type($vrb,2) \
-value $hdit(5) -command {
$vrb_num.chains.entr2 configure -textvariable hdi_type($vrb,2)
#puts$hdi_type($vrb,2)
}
}
if {$gint_det_type($gvrb) == 3} {
$vrb_num.chains.hdi2.menu add radiobutton -label $hdit(7) -variable hdi_type($vrb,2) \
-value $hdit(7) -command {
$vrb_num.chains.entr2 configure -textvariable hdi_type($vrb,2)
#puts$hdi_type($vrb,2)
}
$vrb_num.chains.hdi2.menu add radiobutton -label $hdit(8) -variable hdi_type($vrb,2) \
-value 0 -command {
$vrb_num.chains.entr2 configure -textvariable hdi_type($vrb,2)
#puts$hdi_type($vrb,2)
}
$vrb_num.chains.hdi2.menu add radiobutton -label $hdit(6) -variable hdi_type($vrb,2) \
-value $hdit(6) -command {
$vrb_num.chains.entr2 configure -textvariable hdi_type($vrb,2)
#puts$hdi_type($vrb,2)
}
}


menubutton  $vrb_num.chains.hdi3 -relief raised -text Chain3:  -width 7 \
-bg Pink -activebackground MistyRose  -menu $vrb_num.chains.hdi3.menu
menu $vrb_num.chains.hdi3.menu -bg MistyRose 
entry $vrb_num.chains.entr3 -relief sunken -width 4 -bd 1 -bg \
lightskyblue1 -textvariable hdi_type($vrb,3)
if {$gint_det_type($gvrb) == 1} {

$vrb_num.chains.hdi3.menu add radiobutton -label $hdit(7) -variable hdi_type($vrb,3) \
-value $hdit(7) -command {
$vrb_num.chains.entr3 configure -textvariable hdi_type($vrb,3)
#puts$hdi_type($vrb,3)
}
$vrb_num.chains.hdi3.menu add radiobutton -label $hdit(8) -variable hdi_type($vrb,3) \
-value 0 -command {
$vrb_num.chains.entr3 configure -textvariable hdi_type($vrb,3)
#puts$hdi_type($vrb,3)
}
$vrb_num.chains.hdi3.menu add radiobutton -label $hdit(1) -variable hdi_type($vrb,3) \
-value $hdit(1) -command {
$vrb_num.chains.entr3 configure -textvariable hdi_type($vrb,3)
#puts$hdi_type($vrb,3)
}
$vrb_num.chains.hdi3.menu add radiobutton -label $hdit(2) -variable hdi_type($vrb,3) \
-value $hdit(2) -command { 
$vrb_num.chains.entr3 configure -textvariable hdi_type($vrb,3)
#puts$hdi_type($vrb,3)
}
$vrb_num.chains.hdi3.menu add radiobutton -label $hdit(3) -variable hdi_type($vrb,3) \
-value $hdit(3) -command {
$vrb_num.chains.entr3 configure -textvariable hdi_type($vrb,3)
#puts$hdi_type($vrb,3)
}
}
if {$gint_det_type($gvrb) == 2} {
$vrb_num.chains.hdi3.menu add radiobutton -label $hdit(9) -variable hdi_type($vrb,3) \
-value $hdit(9) -command {
$vrb_num.chains.entr3 configure -textvariable hdi_type($vrb,3)
#puts$hdi_type($vrb,3)
}
$vrb_num.chains.hdi3.menu add radiobutton -label $hdit(8) -variable hdi_type($vrb,3) \
-value 0 -command {
$vrb_num.chains.entr3 configure -textvariable hdi_type($vrb,3)
#puts$hdi_type($vrb,3)
}    
$vrb_num.chains.hdi3.menu add radiobutton -label $hdit(4) -variable hdi_type($vrb,3) \
-value $hdit(4) -command {
$vrb_num.chains.entr3 configure -textvariable hdi_type($vrb,3)
#puts$hdi_type($vrb,3)
}
$vrb_num.chains.hdi3.menu add radiobutton -label $hdit(5) -variable hdi_type($vrb,3) \
-value $hdit(5) -command {
$vrb_num.chains.entr3 configure -textvariable hdi_type($vrb,3)
#puts$hdi_type($vrb,3)
}
}
if {$gint_det_type($gvrb) == 3} {
$vrb_num.chains.hdi3.menu add radiobutton -label $hdit(7) -variable hdi_type($vrb,3) \
-value $hdit(7) -command {
$vrb_num.chains.entr3 configure -textvariable hdi_type($vrb,3)
#puts$hdi_type($vrb,3)
}
$vrb_num.chains.hdi3.menu add radiobutton -label $hdit(8) -variable hdi_type($vrb,3) \
-value 0 -command {
$vrb_num.chains.entr3 configure -textvariable hdi_type($vrb,3)
#puts$hdi_type($vrb,3)
}
$vrb_num.chains.hdi3.menu add radiobutton -label $hdit(6) -variable hdi_type($vrb,3) \
-value $hdit(6) -command {
$vrb_num.chains.entr3 configure -textvariable hdi_type($vrb,3)
#puts$hdi_type($vrb,3)
}
}

menubutton  $vrb_num.chains.hdi4 -relief raised -text Chain4:  -width 7 \
-bg Pink -activebackground MistyRose  -menu $vrb_num.chains.hdi4.menu
menu $vrb_num.chains.hdi4.menu -bg MistyRose 
entry $vrb_num.chains.entr4 -relief sunken -width 4 -bd 1 -bg \
lightskyblue1 -textvariable hdi_type($vrb,4)
if {$gint_det_type($gvrb) == 1} {
$vrb_num.chains.hdi4.menu add radiobutton -label $hdit(7) -variable hdi_type($vrb,4) \
-value $hdit(7) -command {
$vrb_num.chains.entr4 configure -textvariable hdi_type($vrb,4)
#puts$hdi_type($vrb,4)
}
$vrb_num.chains.hdi4.menu add radiobutton -label $hdit(8) -variable hdi_type($vrb,4) \
-value 0 -command {
$vrb_num.chains.entr4 configure -textvariable hdi_type($vrb,4)
#puts$hdi_type($vrb,4)
}
$vrb_num.chains.hdi4.menu add radiobutton -label $hdit(1) -variable hdi_type($vrb,4) \
-value $hdit(1) -command {
$vrb_num.chains.entr4 configure -textvariable hdi_type($vrb,4)
#puts$hdi_type($vrb,4)
}
$vrb_num.chains.hdi4.menu add radiobutton -label $hdit(2) -variable hdi_type($vrb,4) \
-value $hdit(2) -command { 
$vrb_num.chains.entr4 configure -textvariable hdi_type($vrb,4)
#puts$hdi_type($vrb,4)
}
$vrb_num.chains.hdi4.menu add radiobutton -label $hdit(3) -variable hdi_type($vrb,4) \
-value $hdit(3) -command {
$vrb_num.chains.entr4 configure -textvariable hdi_type($vrb,4)
#puts$hdi_type($vrb,4)
}
}
if {$gint_det_type($gvrb) == 2} {
$vrb_num.chains.hdi4.menu add radiobutton -label $hdit(9) -variable hdi_type($vrb,4) \
-value $hdit(9) -command {
$vrb_num.chains.entr4 configure -textvariable hdi_type($vrb,4)
#puts$hdi_type($vrb,4)
}
$vrb_num.chains.hdi4.menu add radiobutton -label $hdit(8) -variable hdi_type($vrb,4) \
-value 0 -command {
$vrb_num.chains.entr4 configure -textvariable hdi_type($vrb,4)
#puts$hdi_type($vrb,4)
}    
$vrb_num.chains.hdi4.menu add radiobutton -label $hdit(4) -variable hdi_type($vrb,4) \
-value $hdit(4) -command {
$vrb_num.chains.entr4 configure -textvariable hdi_type($vrb,4)
#puts$hdi_type($vrb,4)
}
$vrb_num.chains.hdi4.menu add radiobutton -label $hdit(5) -variable hdi_type($vrb,4) \
-value $hdit(5) -command {
$vrb_num.chains.entr4 configure -textvariable hdi_type($vrb,4)
#puts$hdi_type($vrb,4)
}
}
if {$gint_det_type($gvrb) == 3} {
$vrb_num.chains.hdi4.menu add radiobutton -label $hdit(7) -variable hdi_type($vrb,4) \
-value $hdit(7) -command {
$vrb_num.chains.entr4 configure -textvariable hdi_type($vrb,4)
#puts$hdi_type($vrb,4)
}
$vrb_num.chains.hdi4.menu add radiobutton -label $hdit(8) -variable hdi_type($vrb,4) \
-value 0 -command {
$vrb_num.chains.entr4 configure -textvariable hdi_type($vrb,4)
#puts$hdi_type($vrb,4)
}
$vrb_num.chains.hdi4.menu add radiobutton -label $hdit(6) -variable hdi_type($vrb,4) \
-value $hdit(6) -command {
$vrb_num.chains.entr4 configure -textvariable hdi_type($vrb,4)
#puts$hdi_type($vrb,4)
}
}

menubutton  $vrb_num.chains.hdi5 -relief raised -text Chain5:  -width 7 \
-bg Pink -activebackground MistyRose  -menu $vrb_num.chains.hdi5.menu
menu $vrb_num.chains.hdi5.menu -bg MistyRose 
entry $vrb_num.chains.entr5 -relief sunken -width 4 -bd 1 -bg \
lightskyblue1 -textvariable hdi_type($vrb,5)
if {$gint_det_type($gvrb) == 1} {
$vrb_num.chains.hdi5.menu add radiobutton -label $hdit(7) -variable hdi_type($vrb,5) \
-value $hdit(7) -command {
$vrb_num.chains.entr5 configure -textvariable hdi_type($vrb,5)
#puts$hdi_type($vrb,5)
}
$vrb_num.chains.hdi5.menu add radiobutton -label $hdit(8) -variable hdi_type($vrb,5) \
-value 0 -command {
$vrb_num.chains.entr5 configure -textvariable hdi_type($vrb,5)
#puts$hdi_type($vrb,5)
}
$vrb_num.chains.hdi5.menu add radiobutton -label $hdit(1) -variable hdi_type($vrb,5) \
-value $hdit(1) -command {
$vrb_num.chains.entr5 configure -textvariable hdi_type($vrb,5)
#puts$hdi_type($vrb,5)
}
$vrb_num.chains.hdi5.menu add radiobutton -label $hdit(2) -variable hdi_type($vrb,5) \
-value $hdit(2) -command { 
$vrb_num.chains.entr5 configure -textvariable hdi_type($vrb,5)
#puts$hdi_type($vrb,5)
}
$vrb_num.chains.hdi5.menu add radiobutton -label $hdit(3) -variable hdi_type($vrb,5) \
-value $hdit(3) -command {
$vrb_num.chains.entr5 configure -textvariable hdi_type($vrb,5)
#puts$hdi_type($vrb,5)
}
}
if {$gint_det_type($gvrb) == 2} {
$vrb_num.chains.hdi5.menu add radiobutton -label $hdit(9) -variable hdi_type($vrb,5) \
-value $hdit(9) -command {
$vrb_num.chains.entr5 configure -textvariable hdi_type($vrb,5)
#puts$hdi_type($vrb,5)
}
$vrb_num.chains.hdi5.menu add radiobutton -label $hdit(8) -variable hdi_type($vrb,5) \
-value 0 -command {
$vrb_num.chains.entr5 configure -textvariable hdi_type($vrb,5)
#puts$hdi_type($vrb,5)
}    
$vrb_num.chains.hdi5.menu add radiobutton -label $hdit(4) -variable hdi_type($vrb,5) \
-value $hdit(4) -command {
$vrb_num.chains.entr5 configure -textvariable hdi_type($vrb,5)
#puts$hdi_type($vrb,5)
}
$vrb_num.chains.hdi5.menu add radiobutton -label $hdit(5) -variable hdi_type($vrb,5) \
-value $hdit(5) -command {
$vrb_num.chains.entr5 configure -textvariable hdi_type($vrb,5)
#puts$hdi_type($vrb,5)
}
}
if {$gint_det_type($gvrb) == 3} {
$vrb_num.chains.hdi5.menu add radiobutton -label $hdit(7) -variable hdi_type($vrb,5) \
-value $hdit(7) -command {
$vrb_num.chains.entr5 configure -textvariable hdi_type($vrb,5)
#puts$hdi_type($vrb,5)
}
$vrb_num.chains.hdi5.menu add radiobutton -label $hdit(8) -variable hdi_type($vrb,5) \
-value 0 -command {
$vrb_num.chains.entr5 configure -textvariable hdi_type($vrb,5)
#puts$hdi_type($vrb,5)
}
$vrb_num.chains.hdi5.menu add radiobutton -label $hdit(6) -variable hdi_type($vrb,5) \
-value $hdit(6) -command {
$vrb_num.chains.entr5 configure -textvariable hdi_type($vrb,5)
#puts$hdi_type($vrb,5)
}
}


menubutton  $vrb_num.chains.hdi6 -relief raised -text Chain6:  -width 7 \
-bg Pink -activebackground MistyRose  -menu $vrb_num.chains.hdi6.menu
menu $vrb_num.chains.hdi6.menu -bg MistyRose 
entry $vrb_num.chains.entr6 -relief sunken -width 4 -bd 1 -bg \
lightskyblue1 -textvariable hdi_type($vrb,6)
if {$gint_det_type($gvrb) == 1} {
$vrb_num.chains.hdi6.menu add radiobutton -label $hdit(7) -variable hdi_type($vrb,6) \
-value $hdit(7) -command {
$vrb_num.chains.entr6 configure -textvariable hdi_type($vrb,6)
#puts$hdi_type($vrb,6)
}
$vrb_num.chains.hdi6.menu add radiobutton -label $hdit(8) -variable hdi_type($vrb,6) \
-value 0 -command {
$vrb_num.chains.entr6 configure -textvariable hdi_type($vrb,6)
#puts$hdi_type($vrb,6)
}
$vrb_num.chains.hdi6.menu add radiobutton -label $hdit(1) -variable hdi_type($vrb,6) \
-value $hdit(1) -command {
$vrb_num.chains.entr6 configure -textvariable hdi_type($vrb,6)
#puts$hdi_type($vrb,6)
}
$vrb_num.chains.hdi6.menu add radiobutton -label $hdit(2) -variable hdi_type($vrb,6) \
-value $hdit(2) -command { 
$vrb_num.chains.entr6 configure -textvariable hdi_type($vrb,6)
#puts$hdi_type($vrb,6)
}
$vrb_num.chains.hdi6.menu add radiobutton -label $hdit(3) -variable hdi_type($vrb,6) \
-value $hdit(3) -command {
$vrb_num.chains.entr6 configure -textvariable hdi_type($vrb,6)
#puts$hdi_type($vrb,6)
}
}
if {$gint_det_type($gvrb) == 2} {
$vrb_num.chains.hdi6.menu add radiobutton -label $hdit(9) -variable hdi_type($vrb,6) \
-value $hdit(9) -command {
$vrb_num.chains.entr6 configure -textvariable hdi_type($vrb,6)
#puts$hdi_type($vrb,6)
}
$vrb_num.chains.hdi6.menu add radiobutton -label $hdit(8) -variable hdi_type($vrb,6) \
-value 0 -command {
$vrb_num.chains.entr6 configure -textvariable hdi_type($vrb,6)
#puts$hdi_type($vrb,6)
}    
$vrb_num.chains.hdi6.menu add radiobutton -label $hdit(4) -variable hdi_type($vrb,6) \
-value $hdit(4) -command {
$vrb_num.chains.entr6 configure -textvariable hdi_type($vrb,6)
#puts$hdi_type($vrb,6)
}
$vrb_num.chains.hdi6.menu add radiobutton -label $hdit(5) -variable hdi_type($vrb,6) \
-value $hdit(5) -command {
$vrb_num.chains.entr6 configure -textvariable hdi_type($vrb,6)
#puts$hdi_type($vrb,6)
}
}
if {$gint_det_type($gvrb) == 3} {
$vrb_num.chains.hdi6.menu add radiobutton -label $hdit(7) -variable hdi_type($vrb,6) \
-value $hdit(7) -command {
$vrb_num.chains.entr6 configure -textvariable hdi_type($vrb,6)
#puts$hdi_type($vrb,6)
}
$vrb_num.chains.hdi6.menu add radiobutton -label $hdit(8) -variable hdi_type($vrb,6) \
-value 0 -command {
$vrb_num.chains.entr6 configure -textvariable hdi_type($vrb,6)
#puts$hdi_type($vrb,6)
}
$vrb_num.chains.hdi6.menu add radiobutton -label $hdit(6) -variable hdi_type($vrb,6) \
-value $hdit(6) -command {
$vrb_num.chains.entr6 configure -textvariable hdi_type($vrb,6)
#puts$hdi_type($vrb,6)
}
}


menubutton  $vrb_num.chains.hdi7 -relief raised -text Chain7:  -width 7 \
-bg Pink -activebackground MistyRose  -menu $vrb_num.chains.hdi7.menu
menu $vrb_num.chains.hdi7.menu -bg MistyRose 
entry $vrb_num.chains.entr7 -relief sunken -width 4 -bd 1 -bg \
lightskyblue1 -textvariable hdi_type($vrb,7)
if {$gint_det_type($gvrb) == 1} {
$vrb_num.chains.hdi7.menu add radiobutton -label $hdit(7) -variable hdi_type($vrb,7) \
-value $hdit(7) -command {
$vrb_num.chains.entr7 configure -textvariable hdi_type($vrb,7)
#puts$hdi_type($vrb,7)
}
$vrb_num.chains.hdi7.menu add radiobutton -label $hdit(8) -variable hdi_type($vrb,7) \
-value 0 -command {
$vrb_num.chains.entr7 configure -textvariable hdi_type($vrb,7)
#puts$hdi_type($vrb,7)
}
$vrb_num.chains.hdi7.menu add radiobutton -label $hdit(1) -variable hdi_type($vrb,7) \
-value $hdit(1) -command {
$vrb_num.chains.entr7 configure -textvariable hdi_type($vrb,7)
#puts$hdi_type($vrb,7)
}
$vrb_num.chains.hdi7.menu add radiobutton -label $hdit(2) -variable hdi_type($vrb,7) \
-value $hdit(2) -command { 
$vrb_num.chains.entr7 configure -textvariable hdi_type($vrb,7)
#puts$hdi_type($vrb,7)
}
$vrb_num.chains.hdi7.menu add radiobutton -label $hdit(3) -variable hdi_type($vrb,7) \
-value $hdit(3) -command {
$vrb_num.chains.entr7 configure -textvariable hdi_type($vrb,7)
#puts$hdi_type($vrb,7)
}
}
if {$gint_det_type($gvrb) == 2} {
$vrb_num.chains.hdi7.menu add radiobutton -label $hdit(9) -variable hdi_type($vrb,7) \
-value $hdit(9) -command {
$vrb_num.chains.entr7 configure -textvariable hdi_type($vrb,7)
#puts$hdi_type($vrb,7)
}
$vrb_num.chains.hdi7.menu add radiobutton -label $hdit(8) -variable hdi_type($vrb,7) \
-value 0 -command {
$vrb_num.chains.entr7 configure -textvariable hdi_type($vrb,7)
#puts$hdi_type($vrb,7)
}    
$vrb_num.chains.hdi7.menu add radiobutton -label $hdit(4) -variable hdi_type($vrb,7) \
-value $hdit(4) -command {
$vrb_num.chains.entr7 configure -textvariable hdi_type($vrb,7)
#puts$hdi_type($vrb,7)
}
$vrb_num.chains.hdi7.menu add radiobutton -label $hdit(5) -variable hdi_type($vrb,7) \
-value $hdit(5) -command {
$vrb_num.chains.entr7 configure -textvariable hdi_type($vrb,7)
#puts$hdi_type($vrb,7)
}
}
if {$gint_det_type($gvrb) == 3} {
$vrb_num.chains.hdi7.menu add radiobutton -label $hdit(7) -variable hdi_type($vrb,7) \
-value $hdit(7) -command {
$vrb_num.chains.entr7 configure -textvariable hdi_type($vrb,7)
#puts$hdi_type($vrb,7)
}
$vrb_num.chains.hdi7.menu add radiobutton -label $hdit(8) -variable hdi_type($vrb,7) \
-value 0 -command {
$vrb_num.chains.entr7 configure -textvariable hdi_type($vrb,7)
#puts$hdi_type($vrb,7)
}
$vrb_num.chains.hdi7.menu add radiobutton -label $hdit(6) -variable hdi_type($vrb,7) \
-value $hdit(6) -command {
$vrb_num.chains.entr7 configure -textvariable hdi_type($vrb,7)
#puts$hdi_type($vrb,7)
}
}




button $vrb_num.but -relief raised -text "Setup VRB" -bg royalblue2 -bd 4 \
    -fg snow -activebackground lightskyblue1 -width 12 -command {


destroy $vrb_num
return hdi_type 

}





#puts$det_type($gvrb)


#puts$vrb_num

#pack $vrb_num.chains.hdi0 $vrb_num.chains.entr0 $vrb_num.chains.hdi1 $vrb_num.chains.entr1  -side left
pack $vrb_num.chains.hdi0 $vrb_num.chains.entr0 \
$vrb_num.chains.hdi1 $vrb_num.chains.entr1  \
$vrb_num.chains.hdi2 $vrb_num.chains.entr2  \
$vrb_num.chains.hdi3 $vrb_num.chains.entr3  \
$vrb_num.chains.hdi4 $vrb_num.chains.entr4  \
$vrb_num.chains.hdi5 $vrb_num.chains.entr5  \
$vrb_num.chains.hdi6 $vrb_num.chains.entr6  \
$vrb_num.chains.hdi7 $vrb_num.chains.entr7  -side left

pack $vrb_num.entrdet $vrb_num.lab $vrb_num.add  -side left
pack $vrb_num.but -side right

#return hdi_type

}

proc write_file {} {

global hdi_type vrbID crID hdit b3 bl3
global bIDm crIDm vIDm cIDm chips lay_m lad_m
global fIDm fchips wed_m f0d
global mode1 mode2 mode3 mode4 mode5 mode7 mode10
global hname iname 
set f1 [open cfg.dat w]
set f2 [open translation.map w]
set f3 [open ../../smt_examine/rcp/smt_examine.rcp w]
set smt_fe " SMT_FE "
set smt " SMT"
set space " "

set b3 1
set bl3 1
set bldr3 1
set b6 2
set bl6 1
set bldr6 1
set b9 1
set bl9 3
set bldr9 1
set f6 1
set fw6 1
set f8 1
set f0 0
set fw8 1
set h6 1
set hw6 1
set hside 1
set fl 0
set ffl 0
set hfl 0
set ladders 0
set fwedges 0
set hwedges 0
puts " "
puts $f1 [format "%s" "//"] 
set nvrb 0
for {set i 0} {$i<=11} {incr i 1} {
    if {$vrbID($i)!=0} then { incr nvrb 1}
}


set cri 0x$crID
set cfg2 0x$crID$smt_fe$nvrb
puts $f1 $cfg2
set strlad "string Ladders = (\""
set strladf "string FWedges = (\"" 
set strladh "string HWedges = (\""
set cf1 "\",\""
set cf2 "\")"
#puts $strlad

for {set i 0} {$i<=11} {incr i 1} {
    if {$vrbID($i)!=0} then {

    set cfg3 0x$vrbID($i)$smt 

    puts $f1 $cfg3
    for {set j 0} {$j<=7} {incr j 1} {
	
	if {$hdi_type($i,$j) != 0} {

	#puts$hdi_type($i,$j)


	if {$hdi_type($i,$j) == $hdit(1)} {

	    

            
	    set ladders 1

           set bside 1
	   set fchip 0x80
	    set tchip 3
	   set barl 0x$vrbID($i)$space$j$space$fchip$space$tchip$space$b3$space$bl3$space$bldr3$space$bside 
	   
	   #puts$fl
	   if {$fl == 1} {
	       
	       set strlad $strlad$cf1
	       set strlad $strlad$b3$space$bl3$space$bldr3$space$bside
	      
	   } else {
	       set fl 1
	       set strlad $strlad$b3$space$bl3$space$bldr3$space$bside
	    
	   }

	   puts $f2 $barl
 
	
	   if {$bl3<4} then {

	       if {$bldr3<6} then {

	       incr bldr3 1
	       } elseif {$bldr3>=6} then {
	           set bldr3 1
		   switch $bl3 {1 {set bl3 2} 2 {set bl3 5} 5 {set bl3 6}} 
	       }
   	   } elseif {$bl3>=4} then {
	       if {$bldr3 <12} then {
	       incr bldr3 1
	       } elseif {$bldr3>=12} then {
	       set bldr3 1

		   switch $bl3 {1 {set bl3 2} 2 {set bl3 5} 5 {set bl3 6}} 	       
	   }
	   
       



	   }




	} elseif {$hdi_type($i,$j) == $hdit(2)} {
	   
	   set ladders 1

           set pbside 1
	   set nbside 2
	   set pfchip 0x80
	   set nfchip 0x83
	   set tchip 3
	   set pbarl 0x$vrbID($i)$space$j$space$pfchip$space$tchip$space$b6$space$bl6$space$bldr6$space$pbside 
	   set nbarl 0x$vrbID($i)$space$j$space$nfchip$space$tchip$space$b6$space$bl6$space$bldr6$space$nbside
	   #puts$fl
	   if {$fl == 1} {
	       
	       set strlad $strlad$cf1
	       set strlad $strlad$b6$space$bl6$space$bldr6$space$nbside
	      
	   } else {
	       set fl 1
	       set strlad $strlad$b6$space$bl6$space$bldr6$space$nbside
	    
	   }

	   puts $f2 $pbarl
	   puts $f2 $nbarl
 
	
	   if {$bl6<4} then {

	       if {$bldr6<6} then {

	       incr bldr6 1
	       } elseif {$bldr6>=6} then {
	           set bldr6 1
		   switch $bl6 {1 {set bl6 2} 2 {set bl6 5} 5 {set bl6 6}} 
	       }
	   
	   } elseif {$bl6>=4} then {
	       if {$bldr6 <12} then {
	       incr bldr6 1
	       } elseif {$bldr6>=12} then {
	       set bldr6 1
		   switch $bl6 {1 {set bl6 2} 2 {set bl6 5} 5 {set bl6 6}} 	       
	   }
	   
       





	   }

       } elseif {$hdi_type($i,$j) == $hdit(3)} {

	   set ladders 1
	   
           set pbside 1
	   set nbside 2
	   set pfchip 0x80
	   set nfchip 0x85
	   set ptchip 5
	   set ntchip 4
	   set pbarl 0x$vrbID($i)$space$j$space$pfchip$space$ptchip$space$b9$space$bl9$space$bldr9$space$pbside 
	   set nbarl 0x$vrbID($i)$space$j$space$nfchip$space$ntchip$space$b9$space$bl9$space$bldr9$space$nbside
#	   puts $fl
	   if {$fl == 1} {
	       
	       set strlad $strlad$cf1
	       set strlad $strlad$b9$space$bl9$space$bldr9$space$nbside
	      
	   } else {
	       set fl 1
	       set strlad $strlad$b9$space$bl9$space$bldr9$space$nbside
	    
	   }

	   puts $f2 $pbarl
	   puts $f2 $nbarl
 
	
	   if {$bl9<4} then {

	       if {$bldr9<6} then {

	       incr bldr9 1
	   } elseif {$bldr9>=6} then {
	           set bldr9 1
		   switch $bl9 {3 {set bl9 4} 4 {set bl9 7} 7 {set bl9 8}} 
	   }
	   
	   } elseif {$bl9>=4} then {
	       if {$bldr9 <12} then {
	       incr bldr9 1
	       } elseif {$bldr9>=12} then {
	       set bldr9 1
		   switch $bl9 {1 {set bl9 2} 2 {set bl9 5} 5 {set bl9 6}} 	       
	       }
	   
	       
	   }
       } elseif {$hdi_type($i,$j) == $hdit(4)} {

	   set fwedges 1
	   set dtype 2
           set fside 2
	   set fchip 0x80
	   set tchip 6
	   set fbarl 0x$vrbID($i)$space$j$space$fchip$space$tchip$space$dtype$space$f6$space$fw6$space$f0$space$fside 
	   puts $ffl
	   if {$ffl == 1} {
	       
	       set strladf $strladf$cf1
	       set strladf $strladf$f6$space$fw6$space$fside
	       
	      
	   } else {
	       set ffl 1
	       set strladf $strladf$f6$space$fw6$space$fside
	    
	   }

	   puts $f2 $fbarl

 
	
	   if {$fw6<12} then {
	       incr fw6 1

	   
	   } else {
	    	       
	    set fw6 1
	    incr f6 1
	   
       
	}


       } elseif {$hdi_type($i,$j) == $hdit(5)} {

	   set fwedges 1
	   set dtype 2
           set fside 1
	   set fchip 0x80
	   set tchip 8
	   set fbarl 0x$vrbID($i)$space$j$space$fchip$space$tchip$space$dtype$space$f8$space$fw8$space$f0$space$fside 

	   #puts$ffl
	   if {$ffl == 1} {
	       
	       set strladf $strladf$cf1
	       set strladf $strladf$f8$space$fw8$space$fside
       
	      
	   } else {
	       set ffl 1
	       set strladf $strladf$f8$space$fw8$space$fside
	    
	   }

	   puts $f2 $fbarl
	  
 
	
	   if {$fw8<12} then {
	       incr fw8 1

	   
	   } else {
	    	       
	    set fw8 1
	    incr f8 1
	   
       
	}

       } elseif {$hdi_type($i,$j) == $hdit(6)} {

	   set hwedges 1
           set dtype 3
	   set hside 1
	   set fchip 0x80
	   set hchip 6
	   set hbarl 0x$vrbID($i)$space$j$space$hchip$space$fchip$space$space$dtype$h6$space$hw6$space$f0$space$hside 

	   #puts$hfl
	   if {$hfl == 1} {
	       
	       set strladh $strladh$cf1
	       set strladh $strladh$h6$space$hw6$space$hside

	      
	   } else {
	       set hfl 1
	       set strladh $strladh$h6$space$hw6$space$hside
	    
	   }

	   puts $f2 $hbarl
	
	
	   if {$hw6<12} then {
	     incr hw6 1
	       
	   
	     } else {
	      
	    set hw6 1
	    incr h6 1
	}


       } elseif {$hdi_type($i,$j) == $hdit(9)} {

 	   if {$vrbID($i) == "79"} {set vrbID($i) 79}	  

	   if {$vrbID($i) == "7A"} {set vrbID($i) 70}
	   if {$vrbID($i) == "7B"} {set vrbID($i) 71}

 	   set vID $vrbID($i)
	   set cID $j
	   if {$fchips($vID,$cID) == 6} {	   
      
 	   set fwedges 1
	   set dtype 2
           set fside 2
	   set fchip 0x80
	   set tchip 6
	   set f6 $fIDm($vID,$cID)
	   set fw6 $wed_m($vID,$cID)
	   set f0 $f0d($vID,$cID)
	   




	   set fbarl 0x$vrbID($i)$space$j$space$fchip$space$tchip$space$dtype$space$f6$space$fw6$space$f0$space$fside 
	   puts $ffl
	   if {$ffl == 1} {
	       
	       set strladf $strladf$cf1
	       set strladf $strladf$f6$space$fw6$space$fside
	       
	      
	   } else {
	       set ffl 1
	       set strladf $strladf$f6$space$fw6$space$fside
	    
	   }

	   puts $f2 $fbarl

       }

	   
	   if {$fchips($vID,$cID) == 8} {	   
      
 	   set fwedges 1
	   set dtype 2
           set fside 1
	   set fchip 0x80
	   set tchip 8
	   set f8 $fIDm($vID,$cID)
	   set fw8 $wed_m($vID,$cID)
	   set f0 $f0d($vID,$cID)
	   




	   set fbarl 0x$vrbID($i)$space$j$space$fchip$space$tchip$space$dtype$space$f8$space$fw8$space$f0$space$fside 
	   puts $ffl
	   if {$ffl == 1} {
	       
	       set strladf $strladf$cf1
	       set strladf $strladf$f8$space$fw8$space$fside
	       
	      
	   } else {
	       set ffl 1
	       set strladf $strladf$f8$space$fw8$space$fside
	    
	   }

	   puts $f2 $fbarl

       }
	

 } elseif {$hdi_type($i,$j) == $hdit(7)} {
     
     
	   set ladders 1
	   set vID $vrbID($i)
	   set cID $j

	   set dtype 1    


	   if {$chips($vID,$cID) == 9} {
	   

	   set b9 $bIDm($vID,$cID)
	   set bl9 $lay_m($vID,$cID)
	   set bldr9 $lad_m($vID,$cID)


           set pbside 1
	   set nbside 2
	   set pfchip 0x80
	   set nfchip 0x85
	   set ptchip 5
	   set ntchip 4
	   set pbarl 0x$vrbID($i)$space$j$space$pfchip$space$ptchip$space$dtype$space$b9$space$bl9$space$bldr9$space$pbside 
	   set nbarl 0x$vrbID($i)$space$j$space$nfchip$space$ntchip$space$dtype$space$b9$space$bl9$space$bldr9$space$nbside
	   puts $pbarl
	   puts $nbarl


	   if {$fl == 1} {
	       
	       set strlad $strlad$cf1
	       set strlad $strlad$b9$space$bl9$space$bldr9$space$pbside
	       set strlad $strlad$cf1
	       set strlad $strlad$b9$space$bl9$space$bldr9$space$nbside
	      
	   } else {
	       set fl 1
	       set strlad $strlad$b9$space$bl9$space$bldr9$space$pbside
	       set strlad $strlad$cf1
	       set strlad $strlad$b9$space$bl9$space$bldr9$space$nbside
	      
	    
	   }

	   puts $f2 $pbarl
	   puts $f2 $nbarl
       

       } elseif {$chips($vID,$cID) == 6} {

	   set ladders 1

	   set b6 $bIDm($vID,$cID)
	   set bl6 $lay_m($vID,$cID)
	   set bldr6 $lad_m($vID,$cID)



           set pbside 1
	   set nbside 2
	   set pfchip 0x80
	   set nfchip 0x83
	   set tchip 3
	   set pbarl 0x$vrbID($i)$space$j$space$pfchip$space$tchip$space$dtype$space$b6$space$bl6$space$bldr6$space$pbside 
	   set nbarl 0x$vrbID($i)$space$j$space$nfchip$space$tchip$space$dtype$space$b6$space$bl6$space$bldr6$space$nbside
	   #puts$fl
	   if {$fl == 1} {
	       
	       set strlad $strlad$cf1
	       set strlad $strlad$b6$space$bl6$space$bldr6$space$pbside
	       set strlad $strlad$cf1
	       set strlad $strlad$b6$space$bl6$space$bldr6$space$nbside	      
	   } else {
	       set fl 1
	       set strlad $strlad$b6$space$bl6$space$bldr6$space$pbside
	       set strlad $strlad$cf1
	       set strlad $strlad$b6$space$bl6$space$bldr6$space$nbside	    
	   }

	   puts $f2 $pbarl
	   puts $f2 $nbarl
 
	


       
       
       

       } elseif {$chips($vID,$cID) == 3} {

#	   puts "aaa"

#	   puts $vID
#	   puts $cID
	   set dtype 1    
	   set b3 $bIDm($vID,$cID)
	   set bl3 $lay_m($vID,$cID)
	   set bldr3 $lad_m($vID,$cID)

#	   puts $lay_m($vID,$cID)
#           puts $lad_m($vID,$cID)  
         set bside 1
	   set fchip 0x80
	    set tchip 3
	   set barl 0x$vrbID($i)$space$j$space$fchip$space$tchip$space$dtype$space$b3$space$bl3$space$bldr3$space$bside 
	   
#	   puts $fl
	   if {$fl == 1} {
	       
	       set strlad $strlad$cf1
	       set strlad $strlad$b3$space$bl3$space$bldr3$space$bside
	      
	   } else {
	       set fl 1
	       set strlad $strlad$b3$space$bl3$space$bldr3$space$bside
	    
	   }
	   puts $barl
	   puts $f2 $barl
 



       }

       }

       }

       
       
       


       
       
    }

    }
}    


puts "Configuring Examine RCPs..."
puts [exec ./chrcp.sh $mode1 ../../smtraw/rcp/SmtRawUnp2Data.rcp]


puts $f1 [format "%s" "//"]
set strlad $strlad$cf2
set strladf $strladf$cf2
set strladh $strladh$cf2
puts $f3 "// Author: Alex Koubarovski"
puts $f3 "// Date:     05/08/00"
puts $f3 "//"
puts $f3 "// \$Id: examine.tcl,v 1.4 2000/11/21 22:17:37 alex_k Exp $"
puts $f3 "//___________________________________________________________"
puts $f3 "// required by SmtExamine package, generated automaticaly by TCL script"
puts $f3 "//"

puts $f3 "string PackageName = \"SmtExamine\""

if {$mode10 == 1} {
puts $f3 "// We use Root"
puts $f3 "bool Root_Hist = true"
} else {
puts $f3 "//We use Histoscope"
puts $f3 "bool Root_Hist = false"
}

set q "\""
set hn "string hbk_file=\"" 
puts $f3 $hn$hname$q
set hn1 "string root_file=\"" 
puts $f3 $hn1$hname$q
puts $f3 "int Debug_Level = 1"

if {$mode2 == 1} {
puts $f3 "bool AccumulateADC = true"
} else {
puts $f3 "bool AccumulateADC = false"
}
if {$mode3 == 1} {
puts $f3 "bool testChips = true"
} else {
puts $f3 "bool testChips = false"
}

if {$mode4 == 1} {
puts $f3 "bool spReadout = true"
} else {
puts $f3 "bool spReadout = false"
}

if {$mode5 == 1} {
    puts $f3  "bool SelectedHistos = true"
    puts $f3  "bool BarrelHistos = false"
    puts $f3  "bool FDiskHistos = false"
    puts $f3  "bool HDiskHistos = false"

} else {

    puts $f3  "bool SelectedHistos = false"
    puts $f3  "bool BarrelHistos = true"
    puts $f3  "bool FDiskHistos = true"
    puts $f3  "bool HDiskHistos = true"
 
}



if {$ladders == 1} {
    set conf1 "bool testLadders = true"
    puts $f3 $conf1
    puts $f3 $strlad
} else {
    set conf1 "bool testLadders = false"
    puts $f3 $conf1
}
if {$fwedges == 1} {
    set conf1 "bool testFWedges = true"
    puts $f3 $conf1
    puts $f3 $strladf
} else {
    set conf1 "bool testFWedges = false"
    puts $f3 $conf1
}
if {$hwedges == 1} {
    set conf1 "bool testHWedges = true"
    puts $f3 $conf1
    puts $f3 $strladh
} else {
    set conf1 "bool testHWedges = false"
    puts $f3 $conf1
}
#puts $strlad
#puts $strladf
#puts $strladh
close $f1
close $f2
close $f3
}
proc help {} {

global f


set string "  "
set f [toplevel .help -borderwidth 10]
wm geometry $f 400x600+100+100
message $f.msg -text $string -width 300 -justify left
frame $f.buttons -bd 10
pack $f.msg $f.buttons -side top -fill x
button $f.buttons.ok -text OK -command { destroy $f }
pack $f.buttons.ok
return 0
}


proc histo_setup {} {


global st ac ch sp um
global ex_text raw_text ch_text sp_text u_text
global mode1 mode2 mode3
global mode4 mode7 mode10
global btype rname hname iname
toplevel .hist
wm geometry .hist 250x350+400+200
wm title .hist "Histos and I/O Setup"
wm minsize .hist 1 1

frame .hist.1  -relief raised -bd 2  
frame .hist.2  -relief raised -bd 2  
frame .hist.3  -relief raised -bd 2  
frame .hist.4 -relief raised -bd 2  
frame .hist.5 -relief raised -bd 2  
frame .hist.6 -relief raised -bd 2  
frame .hist.7 -relief raised -bd 2  
frame .hist.8 -relief raised -bd 2  
frame .hist.9 -relief raised -bd 2  
frame .hist.10 -relief raised -bd 2 
 
pack .hist.1 .hist.2  .hist.3 .hist.4  .hist.5 .hist.6 .hist.7 .hist.8 .hist.9 -side top -fill x -expand 1

pack .hist.10 -side bottom
set fn1 -adobe-helvetica-bold-o-normal--14-*-*-*-*-*-*-*
set fni -adobe-courier-bold-o-normal--17-*-*-*-*-*-*-*
set fn -adobe-times-bold-r-normal--14-*-*-*-*-*-*-*

set st "STATIC"
set mode1 1

label .hist.1.rawlab -relief raised -font $fn1 -text " Mode:                   ->" -bg royalblue2 -bd 1 -fg snow
button .hist.1.rawrcp  -text $raw_text -width 7 -relief raised   \
-bd 4 -bg deepskyblue -activebackground lightskyblue1 -font $fni \
    -command {
	if {$raw_text == $st } {
	    set raw_text DYNAMIC
	    set mode1 4
            .hist.1.rawrcp configure -text $raw_text
	} else { 
	    set raw_text STATIC
	    set mode1 3
	    .hist.1.rawrcp configure -text $raw_text
	}
    }

set ac "TRUE"
set mode2 1
label .hist.2.exlab -relief raised -font $fn1 -text " Accumulate ADC ->" -bg royalblue2 -bd 1 -fg snow
button .hist.2.exrcp  -text $ex_text -width 7 -relief raised   \
-bd 4 -bg deepskyblue -activebackground  lightskyblue1 -font $fni \
    -command {
	if {$ex_text == $ac } {
	    set ex_text "FALSE"
	    set mode2 2
            .hist.2.exrcp configure -text $ex_text
	} else { 
	    set ex_text "TRUE"
	    set mode2 1
	    .hist.2.exrcp configure -text $ex_text
	}
    }

set ch "TRUE"
set mode3 1
label .hist.3.chlab -relief raised -font $fn1 -text " Chip Level            ->" -bg royalblue2 -bd 1 -fg snow
button .hist.3.chrcp  -text $ch_text -width 7 -relief raised   \
-bd 4 -bg deepskyblue -activebackground  lightskyblue1 -font $fni \
    -command {
	if {$ch_text == $ch } {
	    set ch_text "FALSE"
	    set mode3 2
            .hist.3.chrcp configure -text $ch_text
	} else { 
	    set ch_text "TRUE"
	    set mode3 1
	    .hist.3.chrcp configure -text $ch_text
	}
    }

set sp "TRUE"
set mode4 1

label .hist.4.splab -relief raised -font $fn1 -text " Sparse Readout   ->" -bg royalblue2 -bd 1 -fg snow
button .hist.4.sprcp  -text $ch_text -width 7 -relief raised   \
-bd 4 -bg deepskyblue -activebackground  lightskyblue1 -font $fni \
    -command {
	if {$sp_text == $sp } {
	    set sp_text "FALSE"
	    set mode4 2
            .hist.4.sprcp configure -text $sp_text
	} else { 
	    set sp_text "TRUE"
	    set mode4 1
	    .hist.4.sprcp configure -text $sp_text
	}
    }

set um "TRUE"
set mode7 1

label .hist.5.ulab -relief raised -font $fn1 -text " Use MAP               ->" -bg royalblue2 -bd 1 -fg snow
button .hist.5.urcp  -text $u_text -width 7 -relief raised   \
-bd 4 -bg deepskyblue -activebackground  lightskyblue1 -font $fni \
    -command {
	if {$u_text == $um } {
	    set u_text "FALSE"
	    set mode7 2
            .hist.5.urcp configure -text $u_text
	} else { 
	    set u_text "TRUE"
	    set mode7 1
	    .hist.5.urcp configure -text $u_text
	}
    }


set bt "TRUE"
set mode10 1

label .hist.6.bt -relief raised -font $fn1 -text " Use Root               ->" -bg royalblue2 -bd 1 -fg snow
button .hist.6.bbt  -text $u_text -width 7 -relief raised   \
-bd 4 -bg deepskyblue -activebackground  lightskyblue1 -font $fni \
    -command {
	if {$b_text == $btyp } {
	    set b_text "FALSE"
	    set mode10 2
            .hist.6.bt configure -text $b_text
	} else { 
	    set b_text "TRUE"
	    set mode10 1
	    .hist.6.bt configure -text $b_text
	}
    }






label .hist.7.ifile -text "INPUT file name:"
entry .hist.7.iefile -width 20 -relief sunken -bd 2 -textvariable iname




label .hist.8.hfile -text "HBOOK file name:"
entry .hist.8.ehfile -width 20 -relief sunken -bd 2 -textvariable hname

label .hist.9.rfile -text "ROOT file name:"
entry .hist.9.erfile -width 20 -relief sunken -bd 2 -textvariable rname

button .hist.10.but -relief raised -text "OK" -bg royalblue2 -bd 4 \
    -fg snow -activebackground lightskyblue1 -width 24 -command {


destroy .hist
return  

}
pack  .hist.1.rawlab .hist.1.rawrcp -padx 0.5m -side left

pack  .hist.2.exlab .hist.2.exrcp -padx 0.5m -side left
pack  .hist.3.chlab .hist.3.chrcp -padx 0.5m -side left
pack  .hist.4.splab .hist.4.sprcp -padx 0.5m -side left
pack  .hist.5.ulab .hist.5.urcp -padx 0.5m -side left
pack  .hist.6.bt .hist.6.bbt -padx 0.5m -side left
pack  .hist.7.ifile  .hist.7.iefile -padx 0.5m -side left
pack  .hist.8.hfile  .hist.8.ehfile -padx 0.5m -side left
pack  .hist.9.rfile  .hist.9.erfile -padx 0.5m -side left

pack .hist.10.but
}