# 7/24/97 (saw) Modified to use a wish with a prebuilt in BLT 1.9. # 7/29/97 (bickley) Patches applied based on errors reported by rom. # 8/6/97 (saw) Clear changes the start time/date to the next shift. # 8/7/97 (saw) Read the experiment from the .def file and put it next # to the hall name. # 3/5/98 (bickley) Added date input from menu buttons, and some date checking. # 7/2/98 (bickley) Changes to support revamped definitions # 8/3/1998 (saw) Strip the 0's from the hour and date retrieved with the system # date command. (Fixes H8C problem). # 4/4/2001 (rom) Add calculations of MCC ABU's ala S. Wood's implementation. #package require Blt #import add blt proc HelpButton { } { ViewFile HallAccount.help } proc JulianDay { day month year } { global monthdays set daynum $day set smon [ NumToMonth $month ] set leap1 [ expr $year / 4 ] set leap2 [ expr [ expr $year + 3 ] / 4 ] if { $leap1 == $leap2 } { set monthdays "31 29 31 30 31 30 31 31 30 31 30 31" } else { set monthdays "31 28 31 30 31 30 31 31 30 31 30 31" } set months "Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec" foreach mn { 0 1 2 3 4 5 6 7 8 9 10 11 } { set wmon [lindex $months $mn] if { $wmon == $smon } break set daynum [ expr $daynum + [lindex $monthdays $mn ] ] } return $daynum } proc ViewFile { filename } { global Vtop normal_background set Vtop .viewer toplevel $Vtop wm title $Vtop "View file $filename" label $Vtop.view button $Vtop.quit -text "Done" -command "destroy $Vtop" -bg \ $normal_background pack $Vtop.view $Vtop.quit -side top text $Vtop.view.text -relief raised -bd 2 -yscrollcommand \ "$Vtop.view.scroll set" -bg $normal_background scrollbar $Vtop.view.scroll -command "$Vtop.view.text yview" pack $Vtop.view.scroll -side right -fill y pack $Vtop.view.text -side left $Vtop.view.text delete 1.0 end set f [ open $filename ] while { ![eof $f]} { $Vtop.view.text insert end [ read $f 1000 ] } close $f } proc CheckAccelColumn { hour } { global root normal_background ok_background bad_background accel_column set coltot 0 set av [ $root.avail$hour get ] set coltot [ expr $coltot + [ CheckValue $av $root.avail$hour ] ] set ac [ $root.accept$hour get ] set coltot [ expr $coltot + [ CheckValue $ac $root.accept$hour ] ] set no [ $root.nobeam$hour get ] set coltot [ expr $coltot + [ CheckValue $no $root.nobeam$hour ] ] set cc [ $root.aconfig$hour get ] set coltot [ expr $coltot + [ CheckValue $cc $root.aconfig$hour ] ] if { $coltot == 60 } { $root.accept$hour configure -bg $ok_background $root.avail$hour configure -bg $ok_background $root.nobeam$hour configure -bg $ok_background $root.aconfig$hour configure -bg $ok_background set accel_column($hour) ok } elseif { $coltot > 60 } { $root.accept$hour configure -bg $bad_background $root.avail$hour configure -bg $bad_background $root.nobeam$hour configure -bg $bad_background $root.aconfig$hour configure -bg $bad_background set accel_column($hour) high } else { $root.accept$hour configure -bg $normal_background $root.avail$hour configure -bg $normal_background $root.nobeam$hour configure -bg $normal_background $root.aconfig$hour configure -bg $normal_background set accel_column($hour) low } } proc CheckHallColumn { hour } { global root normal_background ok_background bad_background hall_column set coltot 0 set re [ $root.ready$hour get ] set coltot [ expr $coltot + [ CheckValue $re $root.ready$hour ] ] set co [ $root.config$hour get ] set coltot [ expr $coltot + [ CheckValue $co $root.config$hour ] ] set nr [ $root.nready$hour get ] set coltot [ expr $coltot + [ CheckValue $nr $root.nready$hour ] ] if { $coltot == 60 } { $root.ready$hour configure -bg $ok_background $root.config$hour configure -bg $ok_background $root.nready$hour configure -bg $ok_background set hall_column($hour) ok } elseif { $coltot > 60 } { $root.ready$hour configure -bg $bad_background $root.config$hour configure -bg $bad_background $root.nready$hour configure -bg $bad_background set hall_column($hour) high } else { $root.ready$hour configure -bg $normal_background $root.config$hour configure -bg $normal_background $root.nready$hour configure -bg $normal_background set hall_column($hour) low } } proc SetAccelSum { } { global root nobeamsum acceptsum availsum ok_background bad_background global normal_background accelsum aconfigsum accel_column set accelsum $nobeamsum set accelsum [ expr $acceptsum + $accelsum ] set accelsum [ expr $availsum + $accelsum ] set accelsum [ expr $aconfigsum + $accelsum ] $root.sumsum configure -text $accelsum if { $accelsum == 8 } { $root.sumsum configure -bg $ok_background } elseif { $accelsum == 0 } { $root.sumsum configure -bg $normal_background } else { $root.sumsum configure -bg $ok_background foreach hour { 1 2 3 4 5 6 7 8 } { if { $accel_column($hour) != "ok" } { $root.sumsum configure -bg $bad_background } } } } proc SetHallSum { } { global root readysum nreadysum configsum ok_background bad_background global normal_background hallsum hall_column set hallsum $readysum set hallsum [ expr $nreadysum + $hallsum ] set hallsum [ expr $configsum + $hallsum ] $root.hsumsum configure -text $hallsum if { $hallsum == 8 } { $root.hsumsum configure -bg $ok_background } elseif { $hallsum == 0 } { $root.hsumsum configure -bg $normal_background } else { $root.hsumsum configure -bg $ok_background foreach hour { 1 2 3 4 5 6 7 8 } { if { $hall_column($hour) != "ok" } { $root.hsumsum configure -bg $bad_background } } } } proc CheckValue { value widget } { if { $value == "" } { return 0 } elseif { [ regexp "^\[0-9.\]*$" $value ] == 1 } { if { $value <= 1.0 } { return [ expr $value * 60 ] } elseif { $value > 1.0 } { return $value } } else { $widget delete 0 end return 0 } } proc SetNotReady { line } { global modified submitted root set modified yes set submitted no set sum 0 foreach hour { 1 2 3 4 5 6 7 8 } { set value [ $root.notready$line$hour get ] set checkval [ CheckValue $value $root.notready$line$hour ] if { $checkval != "" } { set sum [ expr $sum + $checkval ] } } set sum [ expr $sum / 60.0 ] $root.notreadysum$line configure -text $sum } proc SetNoBeam { hour } { global nobeam nobeamsum root mode modified submitted set modified yes set submitted no set value [ $root.nobeam$hour get ] set nobeam($hour) [ CheckValue $value $root.nobeam$hour ] set sum 0 foreach ihour { 1 2 3 4 5 6 7 8 } { if { $nobeam($ihour) != "" } { set sum [ expr $sum + $nobeam($ihour) ] } } set sum [ expr $sum / 60.0 ] set nobeamsum $sum $root.nobeamsum configure -text $sum CheckAccelColumn $hour SetAccelSum writeabustuff } proc SetAccept { hour } { global accept acceptsum root mode modified submitted set modified yes set submitted no set value [ $root.accept$hour get ] set accept($hour) [ CheckValue $value $root.accept$hour ] set sum 0 foreach ihour { 1 2 3 4 5 6 7 8 } { if { $accept($ihour) != "" } { set sum [ expr $sum + $accept($ihour) ] } } set sum [ expr $sum / 60.0 ] set acceptsum $sum $root.acceptsum configure -text $sum CheckAccelColumn $hour SetAccelSum } proc SetAvail { hour } { global avail availsum root mode modified submitted set modified yes set submitted no set value [ $root.avail$hour get ] set avail($hour) [ CheckValue $value $root.avail$hour ] set sum 0 foreach ihour { 1 2 3 4 5 6 7 8 } { if { $avail($ihour) != "" } { set sum [ expr $sum + $avail($ihour) ] } } set sum [ expr $sum / 60.0 ] set availsum $sum $root.availsum configure -text $sum CheckAccelColumn $hour SetAccelSum } proc SetAccConfig { hour } { global aconfig aconfigsum root mode modified submitted set modified yes set submitted no set value [ $root.aconfig$hour get ] set aconfig($hour) [ CheckValue $value $root.aconfig$hour ] set sum 0 foreach ihour { 1 2 3 4 5 6 7 8 } { if { $aconfig($ihour) != "" } { set sum [ expr $sum + $aconfig($ihour) ] } } set sum [ expr $sum / 60.0 ] set aconfigsum $sum $root.aconfigsum configure -text $sum CheckAccelColumn $hour SetAccelSum } proc SetReady { hour } { global ready readysum root mode modified submitted set modified yes set submitted no set value [ $root.ready$hour get ] set ready($hour) [ CheckValue $value $root.ready$hour ] set sum 0 foreach ihour { 1 2 3 4 5 6 7 8 } { if { $ready($ihour) != "" } { set sum [ expr $sum + $ready($ihour) ] } } set sum [ expr $sum / 60.0 ] set readysum $sum $root.readysum configure -text $sum CheckHallColumn $hour SetHallSum } proc SetNready { hour } { global nready nreadysum root mode modified submitted set modified yes set submitted no set value [ $root.nready$hour get ] set nready($hour) [ CheckValue $value $root.nready$hour ] set sum 0 foreach ihour { 1 2 3 4 5 6 7 8 } { if { $nready($ihour) != "" } { set sum [ expr $sum + $nready($ihour) ] } } set sum [ expr $sum / 60.0 ] set nreadysum $sum $root.nreadysum configure -text $sum CheckHallColumn $hour SetHallSum } proc SetConfig { hour } { global config configsum root mode modified submitted set modified yes set submitted no set value [ $root.config$hour get ] set config($hour) [ CheckValue $value $root.config$hour ] set sum 0 foreach ihour { 1 2 3 4 5 6 7 8 } { if { $config($ihour) != "" } { set sum [ expr $sum + $config($ihour) ] } } set sum [ expr $sum / 60.0 ] set configsum $sum $root.configsum configure -text $sum CheckHallColumn $hour SetHallSum } proc SetTaking { hour } { global taking takingsum root mode modified takingsum submitted set modified yes set submitted no set value [ $root.taking$hour get ] set taking($hour) [ CheckValue $value $root.taking$hour ] set sum 0 foreach ihour { 1 2 3 4 5 6 7 8 } { if { $taking($ihour) != "" } { set sum [ expr $sum + $taking($ihour) ] } } set sum [ expr $sum / 60.0 ] set takingsum $sum $root.takingsum configure -text $sum } proc SetHall { hallname } { global root hall_name experiment set hall_name $hallname $root.hallname configure -text "Hall $hallname/$experiment" } proc add_hall { hall } { foreach hallname { A B C } { $hall add command -label "Hall $hallname" -command "SetHall $hallname" } } proc SetTime { 24hour hour segment } { global shift_start_time root modified submitted set modified yes set submitted no set shift_start_time $24hour $root.starttime configure -text "$hour $segment" # Relabel the hour labels foreach thishour { 1 2 3 4 5 6 7 8 } { set hournum [ expr $24hour + $thishour - 1] if { $hournum > 23 } { set hournum [ expr $hournum - 24 ] } if { $hournum == 0 } { set hourname "12 AM (Midnight)" } elseif { $hournum == 12 } { set hourname "12 PM (Noon)" } else { if { $hournum > 12 } { set hournum [ expr $hournum - 12 ] set suffix PM } else { set suffix AM } set hourname "$hournum $suffix" } $root.hour$thishour configure -text $hourname } } proc SetDay { day } { global shift_start_day modified root shift_start_month shift_start_year set modified yes set shift_start_day $day $root.startday configure -text "$day" } proc MonthToNum { month } { if { $month == "Jan" } { return 1 } if { $month == "Feb" } { return 2 } if { $month == "Mar" } { return 3 } if { $month == "Apr" } { return 4 } if { $month == "May" } { return 5 } if { $month == "Jun" } { return 6 } if { $month == "Jul" } { return 7 } if { $month == "Aug" } { return 8 } if { $month == "Sep" } { return 9 } if { $month == "Oct" } { return 10 } if { $month == "Nov" } { return 11 } if { $month == "Dec" } { return 12 } } proc SetMonth { month } { global shift_start_day modified root shift_start_month shift_start_year set modified yes set shift_start_month [ MonthToNum $month ] $root.startmonth configure -text "$month" } proc NumToMonth { month } { if { [ expr $month == 1 ] } { return Jan } if { [ expr $month == 2 ] } { return Feb } if { [ expr $month == 3 ] } { return Mar } if { [ expr $month == 4 ] } { return Apr } if { [ expr $month == 5 ] } { return May } if { [ expr $month == 6 ] } { return Jun } if { [ expr $month == 7 ] } { return Jul } if { [ expr $month == 8 ] } { return Aug } if { [ expr $month == 9 ] } { return Sep } if { [ expr $month == 10 ] } { return Oct } if { [ expr $month == 11 ] } { return Nov } if { [ expr $month == 12 ] } { return Dec } } proc SetYear { year } { global shift_start_day modified root shift_start_month shift_start_year set modified yes set shift_start_year $year $root.startyear configure -text "$year" } proc add_time { timeset } { foreach segment { "AM" "PM" } { if { $segment == "PM" } { set startseg 12 } else { set startseg 0 } foreach hour { 12 1 2 3 4 5 6 7 8 9 10 11 } { set starttime [ expr $startseg + $hour ] if { $starttime == 12 } { set starttime 0 } if { $starttime == 24 } { set starttime 12 } $timeset add command -label "$hour $segment" \ -command "SetTime $starttime $hour $segment" } } } proc add_days { dayset } { foreach day { 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 } { $dayset add command -label "$day" -command "SetDay $day" } } proc add_months { monthset } { foreach month { Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec } { $monthset add command -label "$month" -command "SetMonth $month" } } proc add_years { yearset } { foreach year { 2000 2001 2002 2003 2004 2005 2006 2007 } { $yearset add command -label "$year" -command "SetYear $year" } } proc writeabustuff { } { global lastshiftlastabu accept root set first7 0 if {$lastshiftlastabu >= 0} { # All but last hour foreach ihour { 1 2 3 4 5 6 7 } { # puts $accept($ihour) if { $accept($ihour) != "" } { set first7 [ expr $first7 + $accept($ihour) ] } } set first7 [expr $first7/60.0] set last1 [expr $lastshiftlastabu/60.0] set sum [expr $last1+$first7] $root.abuvalue configure -text "$last1+$first7=$sum" } } proc add_first_lines { } { global root table_title normal_background accel_column hall_column global leaderline headerline hallline hallname experiment inbg global nobeam accept avail ready nready config taking aconfig wm title $root $table_title label $root.title -text $table_title -bg $normal_background blt_table $root $root.title 0,2 -cspan 5 blt_table row $root configure 0 -height 0.5i # Shift leader entry label $root.leader -text "Shift leader:" -bg $normal_background blt_table $root $root.leader $leaderline,0 entry $root.leadername -width 20 -bg $normal_background \ -insertbackground $inbg blt_table $root $root.leadername $leaderline,1 -cspan 3 blt_table configure $root.leadername -anchor w # Shift worker entry label $root.worker -text "Shift workers:" -bg $normal_background blt_table $root $root.worker [ expr $leaderline + 1],0 -rspan 2 # Frame for workerss frame $root.wframe -bg $normal_background blt_table $root $root.wframe [ expr $leaderline + 1],1 -cspan 3 -rspan 2 blt_table configure $root.wframe -anchor w text $root.wframe.workers -bd 2 -width 20 -height 3 -wrap word \ -yscrollcommand "$root.wframe.workerscroll set" -bg $normal_background \ -insertbackground $inbg scrollbar $root.wframe.workerscroll -command "$root.wframe.workers yview" \ -bg $normal_background pack $root.wframe.workers $root.wframe.workerscroll -side left \ -expand true -fill y # Hall name entry set hallentryline $leaderline label $root.hall -text "Hall/Exp:" -bg $normal_background blt_table $root $root.hall $hallentryline,5 -cspan 2 if { $hallname != "" } { label $root.hallname -text "$hallname/$experiment" -bg $normal_background } else { menubutton $root.hallname -text "Hall name" -menu $root.hallname.menu \ -relief raised -width 12 -bg $normal_background menu $root.hallname.menu -bg $normal_background add_hall $root.hallname.menu } blt_table $root $root.hallname $hallentryline,7 -cspan 2 # Start time entry set startline [ expr $leaderline + 1] label $root.start -text "Start time:" -bg $normal_background blt_table $root $root.start $startline,5 -cspan 2 menubutton $root.starttime -text "Time" -menu $root.starttime.menu \ -relief raised -width 12 -bg $normal_background blt_table $root $root.starttime $startline,7 -cspan 2 menu $root.starttime.menu -bg $normal_background add_time $root.starttime.menu # Start date entry set dateline [ expr $leaderline + 2] label $root.date -text "Start date:" -bg $normal_background blt_table $root $root.date $dateline,5 -cspan 2 # Start month menu button menubutton $root.startmonth -text "Month" -menu $root.startmonth.menu \ -relief raised -width 5 -bg $normal_background blt_table $root $root.startmonth $dateline,7 -cspan 1 menu $root.startmonth.menu -bg $normal_background add_months $root.startmonth.menu # Start day menu button menubutton $root.startday -text "Day" -menu $root.startday.menu \ -relief raised -width 5 -bg $normal_background blt_table $root $root.startday $dateline,8 -cspan 1 menu $root.startday.menu -bg $normal_background add_days $root.startday.menu # Start year menu button menubutton $root.startyear -text "Year" -menu $root.startyear.menu \ -relief raised -width 5 -bg $normal_background blt_table $root $root.startyear $dateline,9 -cspan 1 menu $root.startyear.menu -bg $normal_background add_years $root.startyear.menu foreach hour { 1 2 3 4 5 6 7 8 } { label $root.hour$hour -text "Hour $hour" -width 5 -bg $normal_background blt_table $root $root.hour$hour $headerline,$hour blt_table configure $root.hour$hour -anchor w blt_table column $root configure $hour -width 0.85i set accel_column($hour) low set hall_column($hour) low } label $root.hoursum -text "Sum (hours)" -bg $normal_background blt_table $root $root.hoursum $headerline,9 # Acceptable beam line label $root.accept -text "Acceptable\nbeam in use" \ -bg $normal_background blt_table $root $root.accept [ expr $headerline + 1 ],0 foreach hour { 1 2 3 4 5 6 7 8 } { entry $root.accept$hour -bg $normal_background -insertbackground $inbg bind $root.accept$hour "SetAccept $hour" blt_table $root $root.accept$hour [ expr $headerline + 1 ],$hour set accept($hour) "" } label $root.acceptsum -text "0.0" -bg $normal_background blt_table $root $root.acceptsum [ expr $headerline + 1],9 # Beam available line label $root.avail -text "Beam available\nbut not in use" \ -bg $normal_background blt_table $root $root.avail [ expr $headerline + 2 ],0 foreach hour { 1 2 3 4 5 6 7 8 } { entry $root.avail$hour -bg $normal_background -insertbackground $inbg bind $root.avail$hour "SetAvail $hour" blt_table $root $root.avail$hour [ expr $headerline + 2 ],$hour set avail($hour) "" } label $root.availsum -text "0.0" -bg $normal_background blt_table $root $root.availsum [ expr $headerline + 2],9 # No beam line label $root.nobeam -text "Beam not available\nor unacceptable" \ -bg $normal_background blt_table $root $root.nobeam [ expr $headerline + 3 ],0 foreach hour { 1 2 3 4 5 6 7 8 } { entry $root.nobeam$hour -bg $normal_background -insertbackground $inbg bind $root.nobeam$hour "SetNoBeam $hour" blt_table $root $root.nobeam$hour [ expr $headerline + 3 ],$hour set nobeam($hour) "" } label $root.nobeamsum -text "0.0" -bg $normal_background blt_table $root $root.nobeamsum [ expr $headerline + 3 ],9 # Accelerator configuration change label $root.aconfig -text "Accelerator con-\nfiguration change" \ -bg $normal_background blt_table $root $root.aconfig [ expr $headerline + 4 ],0 foreach hour { 1 2 3 4 5 6 7 8 } { entry $root.aconfig$hour -bg $normal_background -insertbackground $inbg bind $root.aconfig$hour "SetAccConfig $hour" blt_table $root $root.aconfig$hour [ expr $headerline + 4 ],$hour set aconfig($hour) "" } label $root.aconfigsum -text "0.0" -bg $normal_background blt_table $root $root.aconfigsum [ expr $headerline + 4 ],9 # Sum line label $root.sum -text "Sum:" -bg $normal_background blt_table $root $root.sum [ expr $headerline + 5 ],0 label $root.sumsum -text "0.0" -bg $normal_background blt_table $root $root.sumsum [ expr $headerline + 5 ],9 # Skip a line blt_table row $root configure [ expr $headerline + 6 ] -height 0.25i # Hall status lines # Hall ready line label $root.ready -text "Experiment ready" -bg $normal_background blt_table $root $root.ready $hallline,0 foreach hour { 1 2 3 4 5 6 7 8 } { entry $root.ready$hour -bg $normal_background -insertbackground $inbg bind $root.ready$hour "SetReady $hour" blt_table $root $root.ready$hour $hallline,$hour set ready($hour) "" } label $root.readysum -text "0.0" -bg $normal_background blt_table $root $root.readysum $hallline,9 # Configuration change line label $root.config -text "Planned config-\nuration change" \ -bg $normal_background blt_table $root $root.config [ expr $hallline + 1 ],0 foreach hour { 1 2 3 4 5 6 7 8 } { entry $root.config$hour -bg $normal_background -insertbackground $inbg bind $root.config$hour "SetConfig $hour" blt_table $root $root.config$hour [ expr $hallline + 1 ],$hour set config($hour) "" } label $root.configsum -text "0.0" -bg $normal_background blt_table $root $root.configsum [ expr $hallline + 1 ],9 # Hall not ready line label $root.nready -text "Unplanned ex-\nperiment down" \ -bg $normal_background blt_table $root $root.nready [ expr $hallline + 2 ],0 foreach hour { 1 2 3 4 5 6 7 8 } { entry $root.nready$hour -bg $normal_background -insertbackground $inbg bind $root.nready$hour "SetNready $hour" blt_table $root $root.nready$hour [ expr $hallline + 2 ],$hour set nready($hour) "" } label $root.nreadysum -text "0.0" -bg $normal_background blt_table $root $root.nreadysum [ expr $hallline + 2],9 # Hall sum line label $root.hsum -text "Sum:" -bg $normal_background blt_table $root $root.hsum [ expr $hallline + 3 ],0 label $root.hsumsum -text "0.0" -bg $normal_background blt_table $root $root.hsumsum [ expr $hallline + 3 ],9 # Skip a line blt_table row $root configure [ expr $hallline + 4 ] -height 0.25i # Data taking line # label $root.taking -text "Data\ntaking" -bg $normal_background # blt_table $root $root.taking [ expr $hallline + 5 ],0 # foreach hour { 1 2 3 4 5 6 7 8 } { # entry $root.taking$hour -bg $normal_background # bind $root.taking$hour "SetTaking $hour" # blt_table $root $root.taking$hour [ expr $hallline + 5 ],$hour # set taking($hour) "" # } # label $root.takingsum -text "0.0" -bg $normal_background # blt_table $root $root.takingsum [ expr $hallline + 5 ],9 # Skip a line blt_table row $root configure [ expr $hallline + 6 ] -height 0.25i } proc read_hall_data { inputfile } { global normal_background printer rundir # Read definition of this hall's reasons global table_title hallname experiment notready notreadynum # Read blt_tabletitle set table_title "Hall Time Account Entry Table" set notreadynum 0 if { [ file exists $inputfile ] } { set newfile [ open $inputfile r 0666 ] gets $newfile line while { "$line" != "End File" } { switch $line { Hallname: { # Read hall name gets $newfile hallname } Experiment: { # Read experiment name gets $newfile experiment } Reasons: { # Read row labels gets $newfile reason while { "$reason" != "End Reasons" } { set notready([ expr $notreadynum + 1 ]) $reason set notreadynum [ expr $notreadynum + 1 ] gets $newfile reason } } Printer: { gets $newfile printer } Directory: { gets $newfile rundir } } gets $newfile line } } } proc WriteFile { filename } { global root shift_start_time accept avail nobeam ready nready config taking global aconfig global shift_start_day shift_start_month shift_start_year global comments modified notreadynum global lastshiftlastabu set newfile [ open $filename w 0666 ] puts $newfile "Leader" puts $newfile [ $root.leadername get ] puts $newfile "Author" puts $newfile [ $root.author get ] puts $newfile "Workers" puts $newfile [ $root.wframe.workers get 0.0 end ] puts $newfile "End Workers" puts $newfile "Starttime" puts $newfile $shift_start_time puts $newfile "Startdate" puts $newfile "$shift_start_month/$shift_start_day/$shift_start_year" if { $lastshiftlastabu >= 0 } { puts $newfile "Lastshiftlastabu" puts $newfile $lastshiftlastabu } puts $newfile "Data" foreach hour { 1 2 3 4 5 6 7 8 } { set val [ $root.accept$hour get ] if { "$val" == "" } { puts -nonewline $newfile 0 } else { puts -nonewline $newfile $val } set val [ $root.avail$hour get ] if { "$val" == "" } { puts -nonewline $newfile " | 0" } else { puts -nonewline $newfile " | $val" } set val [ $root.nobeam$hour get ] if { "$val" == "" } { puts -nonewline $newfile " | 0" } else { puts -nonewline $newfile " | $val" } set val [ $root.aconfig$hour get ] if { "$val" == "" } { puts -nonewline $newfile " | 0" } else { puts -nonewline $newfile " | $val" } set val [ $root.ready$hour get ] if { "$val" == "" } { puts -nonewline $newfile " | 0" } else { puts -nonewline $newfile " | $val" } set val [ $root.config$hour get ] if { "$val" == "" } { puts -nonewline $newfile " | 0" } else { puts -nonewline $newfile " | $val" } set val [ $root.nready$hour get ] if { "$val" == "" } { puts $newfile " | 0" } else { puts $newfile " | $val" } # set val [ $root.taking$hour get ] # if { "$val" == "" } { puts $newfile " | 0" # } else { puts $newfile " | $val" } } puts $newfile "End Data" puts $newfile "Comments" puts $newfile [ $root.cframe.comments get 0.0 end ] puts $newfile "End Comments" puts $newfile "HallData" set ctr 0 while { $ctr < $notreadynum } { foreach hour { 1 2 3 4 5 6 7 8 } { set val [ $root.notready$ctr$hour get ] if { "$val" == "" } { puts -nonewline $newfile " 0 |" } else { puts -nonewline $newfile " $val |" } } puts $newfile " " set ctr [ expr $ctr + 1 ] } puts $newfile "End HallData" puts $newfile "BeamScheduled" puts $newfile " 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 |" puts $newfile "End File" close $newfile set modified no } proc restore_data { filename } { global root shift_start_time accept avail nobeam ready nready config taking global comments modified notreadynum init_filename oldfile submitted global shift_start_day shift_start_month shift_start_year global lastshiftlastabu if { [ file exists $filename ] } { set oldfile [ open $filename r 0666 ] gets $oldfile line while { "$line" != "End File" } { switch $line { Leader { # Read hall name gets $oldfile leader $root.leadername insert 0 $leader } BeamScheduled { gets $oldfile tmp } Workers { # Read workers gets $oldfile workerline while { "$workerline" != "End Workers" } { if { "$workerline" != "" } { $root.wframe.workers insert end "$workerline\n" } gets $oldfile workerline } } Starttime { # Read start time gets $oldfile start #$root.leadername insert $start $root.starttime.menu invoke [ expr $start + 1 ] } Startdate { # Read start date gets $oldfile dateline scan "$dateline" "%d/%d/%d" month day year SetMonth [ NumToMonth $month ] SetYear $year SetDay $day } Lastshiftlastabu { # Read abu from last hour of last shift gets $oldfile lastshiftlastabu writeabustuff } Author { # Read start date gets $oldfile date $root.author insert 0 $date } Comments { # Read workers gets $oldfile commentline while { "$commentline" != "End Comments" } { if { "$commentline" != "" } { $root.cframe.comments insert end "$commentline\n" } gets $oldfile commentline } } Data { foreach hour { 1 2 3 4 5 6 7 8 } { gets $oldfile dataline scan "$dataline" "%f | %f | %f | %f | %f | %f | %f" \ acc avl nob acf rdy cfg nrd if { $acc != 0 } { $root.accept$hour insert 0 $acc } if { $avl != 0 } { $root.avail$hour insert 0 $avl } if { $nob != 0 } { $root.nobeam$hour insert 0 $nob } if { $acf != 0 } { $root.aconfig$hour insert 0 $acf } if { $rdy != 0 } { $root.ready$hour insert 0 $rdy } if { $cfg != 0 } { $root.config$hour insert 0 $cfg } if { $nrd != 0 } { $root.nready$hour insert 0 $nrd } #if { $tkg != 0 } { $root.taking$hour insert 0 $tkg } SetAccept $hour SetAvail $hour SetNoBeam $hour SetAccConfig $hour SetReady $hour SetNready $hour SetConfig $hour # SetTaking $hour } gets $oldfile dataline while { "$dataline" != "End Data" } { puts $dataline gets $oldfile dataline } } HallData { ReadHallData } default { puts "Error in input file $filename. email bickley@jlab.org" puts $line } } gets $oldfile line } close $oldfile set modified no set submitted no } } proc ReadHallData { } { global root notreadynum oldfile init_filename set ctr 0 while { $ctr < $notreadynum } { gets $oldfile dataline if { "$dataline" == "End HallData" } { tk_dialog .baddata "Data shortage" \ "Warning:\n\nThere was less data in the saved file \ than specified in the hall's definition file, \ $init_filename. This means that the data restored to \ the 'hall not ready' lines (below the 'Data taking' \ line) may be wrong." {} 0 { Ok } return; } scan "$dataline" "%f | %f | %f | %f | %f | %f | %f | %f" \ hr1 hr2 hr3 hr4 hr5 hr6 hr7 hr8 if { $hr1 != 0 } { $root.notready${ctr}1 insert 0 $hr1 } if { $hr2 != 0 } { $root.notready${ctr}2 insert 0 $hr2 } if { $hr3 != 0 } { $root.notready${ctr}3 insert 0 $hr3 } if { $hr4 != 0 } { $root.notready${ctr}4 insert 0 $hr4 } if { $hr5 != 0 } { $root.notready${ctr}5 insert 0 $hr5 } if { $hr6 != 0 } { $root.notready${ctr}6 insert 0 $hr6 } if { $hr7 != 0 } { $root.notready${ctr}7 insert 0 $hr7 } if { $hr8 != 0 } { $root.notready${ctr}8 insert 0 $hr8 } set ctr [ expr $ctr + 1 ] } gets $oldfile dataline set dialog_shown no while { "$dataline" != "End HallData" } { # Get rid of any extraneous lines gets $oldfile dataline if { $dialog_shown == "no" } { tk_dialog .baddata "Data excess" \ "Warning:\n\nThere was more data in the saved file \ than specified in the hall's definition file, \ $init_filename. This means that the data restored to \ the 'hall not ready' lines (below the 'Data taking' \ line) may be wrong." {} 0 { Ok } set dialog_shown yes } } return } proc ClearData { } { global root modified accept avail nobeam ready nready config taking aconfig global nobeamsum acceptsum availsum notreadynum aconfigsum global readysum nreadysum configsum shift_start_time global shift_start_day shift_start_month shift_start_year global submitted global lastshiftlastabu set answer [ tk_dialog .exitquery "Clear dialog window" \ "Are you sure you want to clear the data in the table?" \ {} 0 { Clear } { Don't clear } ] if { $answer == 0 } { set lastshiftlastabu $accept(8) foreach hour { 1 2 3 4 5 6 7 8 } { $root.accept$hour delete 0 end set accept($hour) "" $root.avail$hour delete 0 end set avail($hour) "" $root.nobeam$hour delete 0 end set nobeam($hour) "" $root.aconfig$hour delete 0 end set aconfig($hour) "" $root.ready$hour delete 0 end set ready($hour) "" $root.config$hour delete 0 end set config($hour) "" $root.nready$hour delete 0 end set nready($hour) "" # $root.taking$hour delete 0 end # set taking($hour) "" CheckAccelColumn $hour CheckHallColumn $hour set ctr 0 while { $ctr < $notreadynum } { $root.notready$ctr$hour delete 0 end set ctr [ expr $ctr + 1 ] } } writeabustuff $root.acceptsum configure -text 0.0 $root.availsum configure -text 0.0 $root.nobeamsum configure -text 0.0 $root.aconfigsum configure -text 0.0 $root.readysum configure -text 0.0 $root.nreadysum configure -text 0.0 $root.configsum configure -text 0.0 # $root.takingsum configure -text 0.0 $root.leadername delete 0 end $root.wframe.workers delete 0.0 end $root.cframe.comments delete 0.0 end $root.author delete 0 end # $root.setdate delete 0 end # $root.starttime.menu invoke 100 # $root.starttime configure -text "Time" # foreach hour { 1 2 3 4 5 6 7 8 } { # $root.hour$hour configure -text "Hour $hour" # } # Check to see if next shift will be a new day. Do all the right stuff # for month, year, and millenium rollovers # if { [expr ($shift_start_time + 8)%24] < $shift_start_time } { incr shift_start_day 1 set monlen [lindex {31 28 31 30 31 30 31 31 30 31 30 31} \ [expr $shift_start_month-1]] if {$shift_start_month == 2} { if { [expr $shift_start_year%4] == 0 } { incr monlen 1} } if {$shift_start_day > $monlen} { set shift_start_day 1 incr shift_start_month 1 if {$shift_start_month > 12} { set shift_start_month 1 incr shift_start_year 1 SetYear $shift_start_year } SetMonth [ NumToMonth $shift_start_month ] } SetDay $shift_start_day } # Add 8 hours to the start time. $root.starttime.menu invoke [ expr ($shift_start_time + 8)%24 + 1 ] set nobeamsum 0 set aconfigsum 0 set acceptsum 0 set availsum 0 set readysum 0 set nreadysum 0 set configsum 0 SetAccelSum SetHallSum $root.sumsum configure -text 0.0 $root.hsumsum configure -text 0.0 set modified yes set submitted no } } proc add_hall_lines { } { global notreadyline commentsline root comments notready notreadynum global buttonline normal_background inbg global lastshiftlastabu set ctr 0 while { $ctr < $notreadynum } { # Hall not ready lines label $root.notready$ctr -text "$notready([expr $ctr + 1])" \ -bg $normal_background blt_table $root $root.notready$ctr [expr $notreadyline + $ctr],0 foreach hour { 1 2 3 4 5 6 7 8 } { entry $root.notready$ctr$hour -bg $normal_background \ -insertbackground $inbg bind $root.notready$ctr$hour \ "SetNotReady $ctr" blt_table $root $root.notready$ctr$hour [expr $notreadyline + $ctr],$hour } label $root.notreadysum$ctr -text "0.0" -bg $normal_background blt_table $root $root.notreadysum$ctr [expr $notreadyline + $ctr],9 set ctr [ expr $ctr + 1 ] } set commentsline [ expr $notreadyline + $ctr + 1] set buttonline [ expr $commentsline + 2 ] # Add comments line label $root.comment -text "Comments:" -bg $normal_background blt_table $root $root.comment $commentsline,0 blt_table row $root configure $commentsline -height 1.5i # Frame for comments frame $root.cframe -bg $normal_background blt_table $root $root.cframe $commentsline,1 -cspan 9 blt_table configure $root.cframe -anchor w text $root.cframe.comments -bd 2 -width 60 -height 5 -wrap word \ -yscrollcommand "$root.cframe.commentscroll set" -bg $normal_background \ -insertbackground $inbg $root.cframe.comments insert 0.0 "$comments" scrollbar $root.cframe.commentscroll \ -command "$root.cframe.comments yview" -bg $normal_background pack $root.cframe.comments $root.cframe.commentscroll -side left \ -expand true -fill y # Add a place for the author of the data to be entered label $root.authlabel -text "Table author:" -bg $normal_background blt_table $root $root.authlabel [ expr $commentsline + 1 ],0 entry $root.author -bg $normal_background -insertbackground $inbg blt_table $root $root.author [ expr $commentsline + 1 ],1 -cspan 2 blt_table row $root configure [expr $commentsline + 1] -height .5i # Show ABU's from last hour of last shift label $root.abulabel -text "ABU sum:" -bg $normal_background blt_table $root $root.abulabel [ expr $commentsline + 1 ],4 label $root.abuvalue -text "0.0" -bg $normal_background blt_table $root $root.abuvalue [ expr $commentsline + 1 ],5 -cspan 3 } proc dismissbutton { } { global root nobeam modified savefilename if { $modified == "no" } { exit } set answer [ tk_dialog .exitquery "Dismiss Dialog Window" \ "Values in the table have been modified. \ Do you want to save before dismissing the window?" \ {} 0 { Save } { Cancel } { Don't save } ] if { $answer == 0 } { WriteFile $savefilename exit } elseif { $answer == 1 } { # } elseif { $answer == 2 } { exit } } proc Submit { } { global printer table_title accelsum hallsum bad_background takingsum global acceptsum readysum hall_column accel_column normal_background global shift_start_day shift_start_month shift_start_year shift_start_time global root savefilename submitted global accept ready global lastabusavefilename set errormessage "Can't submit this data because:\n\n" foreach hour { 1 2 3 4 5 6 7 8 } { SetAccept $hour SetAvail $hour SetNoBeam $hour SetAccConfig $hour SetReady $hour SetNready $hour SetConfig $hour } if { $submitted == "yes" } { tk_dialog .badsubmit "Error resubmitting" \ "$errormessage This report was already submitted." {} 0 { Ok } return } # Check that every hour sum is < 60 minutes foreach hour { 1 2 3 4 5 6 7 8 } { if { $hall_column($hour) != "ok" } { if { $hall_column($hour) == "low" } { set background $normal_background } else { set background $bad_background } tk_dialog .badsubmit "Error in table" \ "$errormessage Column number $hour in the experiment \ status rows does not sum to 1 hour. The column is highlighted \ in $background." {} 0 { Ok } return } if { $accel_column($hour) != "ok" } { if { $accel_column($hour) == "low" } { set background $normal_background } else { set background $bad_background } tk_dialog .badsubmit "Error in table" \ "$errormessage Column number $hour in the accelerator \ status rows does not sum to 1 hour. The column is highlighted \ in $background." {} 0 { Ok } return } # Check that Acceptable beam in use is <= Experiment ready if { $accept($hour) > $ready($hour) } { tk_dialog .badsubmit "Error in table" \ "$errormessage In column number $hour, the value for the \ \"Acceptable \ beam in use\" category is larger than the value in \ the \"Experiment ready\" \ category. \n\n\"Experiment ready\" must not be smaller than \ \"Acceptable beam in use\"" {} 0 { Ok } return } } # Check the total number of accelerator hours # if { $accelsum != 8 } { # tk_dialog .badsubmit "Error in table" \ # "$errormessage The total number of hours in the \ # accelerator status rows is not equal to 8. The total is highlighted \ # in $bad_background." {} 0 { Ok } # return # } # Check the total number of hall hours # if { $hallsum != 8 } { # tk_dialog .badsubmit "Error in table" \ # "$errormessage The total number of hours in the \ # hall status rows is not equal to 8. The total is highlighted \ # in $bad_background." {} 0 { Ok } # return # } # Check that data taking <= beam acceptable # if { $takingsum > $acceptsum } { # tk_dialog .badsubmit "Error in table" \ # "$errormessage The total number of hours of data taking \ # is greater than the number of hours of acceptable beam." {} 0 { Ok } # return # } # Check that data taking <= experiment ready # if { $takingsum > $readysum } { # tk_dialog .badsubmit "Error in table" \ # "$errormessage The total number of hours of data taking \ # is greater than the number of hours the experiment was ready." \ # {} 0 { Ok } # return # } # Check that the shift leader is filled out if { [ $root.leadername get ] == "" } { tk_dialog .badsubmit "Error in table" \ "$errormessage The name of the shift leader must be entered \ before the data in the table can be submitted." \ {} 0 { Ok } return } # Check that the author is filled out if { [ $root.author get ] == "" } { tk_dialog .badsubmit "Error in table" \ "$errormessage The name of the person filling out this form must be \ entered before the data in the table can be submitted." \ {} 0 { Ok } return } # Check that the date and time of entry are not too far off set hournum [ exec date "+%H" ] regsub "^0" $hournum "" hournum set daynum [ exec date "+%j" ] regsub "^0*" $daynum "" daynum set yearnum [ exec date "+%Y" ] set jday [ JulianDay $shift_start_day $shift_start_month $shift_start_year ] # Get the "julian hour" of shift data submittal set jhoursubmit [ expr 24 * $daynum + $hournum ] # Get the "julian hour" of shift start time, and add 10 hours # (This gives the shift staff 2 hours to submit the data) set jhourshift [ expr 24 * $jday + $shift_start_time + 10 ] set jhourshiftstart [ expr 24 * $jday + $shift_start_time + 6 ] set daywarning no if { $jhoursubmit > $jhourshift } { set daywarning yes } elseif { $jhoursubmit < $jhourshiftstart} { set daywarning yes } elseif { $jday > $daynum} { set daywarning yes } if { $daywarning != "no" } { set charmonth [ NumToMonth $shift_start_month ] set answer [ tk_dialog .exitquery "Submit Dialog Window" \ "You are trying to submit data for the date \ $charmonth $shift_start_day, $shift_start_year. \ Is this date correct?" \ {} 0 { Submit } { Don't submit } ] if { $answer == 0 } { # } elseif { $answer == 1 } { return } } WriteFile $savefilename set filename [ exec date "+%y-%m-%d-%H:%M" ].had WriteFile $filename # exec xwd -name "$table_title" | xpr -device ps -rv | lp -d$printer >> /dev/null& exec HallAccount.pl set submitted yes exec lp -d $printer HallAccount.report tk_dialog .goodsubmit "OK" \ "Submission successful:\n\nClick OK to continue." \ {} 0 { Ok } } proc Reprint { } { global printer exec lp -d $printer HallAccount.report } proc add_buttons { } { global buttonline root savefilename normal_background button $root.submit -text Submit -command Submit -bg $normal_background blt_table $root $root.submit $buttonline,1 button $root.save -text Save -command "WriteFile $savefilename" \ -bg $normal_background blt_table $root $root.save $buttonline,2 button $root.clear -text Clear -command ClearData -bg $normal_background blt_table $root $root.clear $buttonline,3 button $root.dismiss -text Dismiss -command dismissbutton \ -bg $normal_background blt_table $root $root.dismiss $buttonline,6 button $root.help -text Help -command HelpButton -bg $normal_background blt_table $root $root.help $buttonline,7 button $root.reprint -text Reprint -command Reprint -bg $normal_background blt_table $root $root.reprint $buttonline,8 label $root.email -text "Comments or suggestions? Direct them to:\ R. Michaels (rom@jlab.org)" -bg $normal_background blt_table $root $root.email [ expr $buttonline + 1],0 -cspan 10 } set normal_background white #set normal_background black set ok_background green set bad_background red set inbg yellow set root .table toplevel $root -bg $normal_background wm withdraw . blt_table $root set leaderline 1 set headerline 5 set hallline 12 set notreadyline 19 set commentsline 23 set buttonline 24 set mode hours set aconfigsum 0 set nobeamsum 0 set acceptsum 0 set availsum 0 set readysum 0 set nreadysum 0 set notreadynum 0 set configsum 0 set accelsum 0 set hallsum 0 #set normal_background [ $root cget -bg ] set modified no set submitted no set comments "" set savefilename HallAccount.sav set lastabusavefilename HallAccount.lastabu set shift_start_time "" set hallname "" set experiment "" set printer putyourfavoriteprinterqueuenamehere set rundir bad_dir set lastshiftlastabu -1 set shift_start_day 1 set shift_start_month 1 set shift_start_year 1998 if { $argc != 1 } { set init_filename HallAccount.def } else { set init_filename [lindex $argv 0] } read_hall_data $init_filename if { [ file isdirectory $rundir ] } { cd $rundir } else { if { $rundir == "bad_dir" } { tk_dialog .baddir "No run directory" \ "No running directory was not set in $init_filename \ The directory must be set in order for this script to run." \ {} 0 { Ok } exit } else { tk_dialog .baddir "Bad run directory" \ "The execution directory $rundir (which is specified in the file \ $init_filename) does not exist. \ The directory must exist in order for this script to run." \ {} 0 { Ok } exit } } add_first_lines add_hall_lines add_buttons restore_data $savefilename