proc LPL_ConfigureInfo {} {
    return "This is the top level procedure to configure everything in the LPL."
}

proc LPL_Configure {args} {
    set sectors "L1 L2 L3 L4 L5"
    foreach sector $sectors {
        set $sector 1
        #set suspend$sector 1
    }
    set L3 0
    set L6 0
    #set suspendL3 1
    #set suspendL1 1
    #set suspendL2 1
    #    set turnOnList [list L1:SC L1:QM L2:SC L2:QM L3:CHICANE L3:MATCHING L3:AM1T L4:SC L4:QM L5:SC L5:QM L5:AM] 
    #    set conditionList [list L1:SC L1:QM L2:SC L2:QM L3:CHICANE L3:MATCHING L3:AM1T L4:SC L4:QM L5:SC L5:QM L5:AM] 
    set turnOnList [list L1:H L1:V L1:Q L2:SC L2:QM L3:CHICANE L3:MATCHING L4:SC L4:QM L5:SC L5:QM L5:AM] 
    set conditionList [list L1:H L1:V L1:Q L2:SC L2:QM L3:CHICANE L3:MATCHING L4:SC L4:QM L5:SC L5:QM L5:AM] 
    set turnOffList ""
    set SCRFile ""
    set CathodeHeaterSetpoint ""
    set CathodeHeaterWatts ""
    set KLYFwdPwr ""
    set KickerSetpoint ""
    set resumeSmartMonitor 1
    set RFGUN 1
    set PowerSupplies 1
    set Modulators 1
    set startupLTP 1
    set startupPAR 0
    set PARrfSystems 0
    set PARPulsedPS 0
    set PARBM 1
    set startupPTB 1
    set startupPARBypass 1
    set conditionLTP 0
    set conditionLTPB1 0
    set conditionPAR 0
    set conditionPTB 0
    set conditionPARBypass 0
    set bypass 0
    set bypassEnergy 400
    set examineSCRFile 1
    set turnOffDownKlystron 1
    set mode startup
    set forceChangeGunOnly 0
    set parRFscr 0
    set includeFilament 0

    set DCPSLTP 1
    set DCPSPAR 1
    set DCPSPTB 1
    set DCPSPARBypass 1
    set rampedLTP 1
    set rampedPAR 1
    set rampedPTB 1
    set HLTP 1
    set HPARBypass 1
    set VLTP 1
    set VPARBypass 1
    set QLTP 1
    set QPARBypass 1
    set B1LTP 1
    set maxLTPB1Cycles 4
    set e325MeV 0
    set e375MeV 0

    global execMode

    if {$execMode == "Manual"} {
        set prefix "Press Continue to "
    } else {
        set prefix ""
    }
    if {[catch {APSLinkToLINACPVs} result]} {
        APSMpReturn error "LPL_Configure: $result"
    }
    
    if {[catch {APSDevSend \
                  -group LinacRFGun \
                  -operation ReadRFCurrentMode \
                  -deviceList 0} linacMode]} {
        APSMpReturn error "LPL_Configure: $linacMode"
    }
    set linacMode [join $linacMode]
    set modeVal $linacMode
    if {($linacMode == "K1 Down") || ($linacMode == "K2 Down")} {
        set L3 1
    }
    if {$modeVal == "K1 Down"} {
        set L1 0
        #set suspendL1 0
    } elseif {$modeVal == "K2 Down"} {
        set L2 0
        #set suspendL2 0
    } elseif {$modeVal == "K3 Down"} {
        set L3 0
        #set suspendL3 0
    }

    if {[catch {APSRFGUN_DetectSelectedGun} gun]} {
        APSMpReturn error "LPL_Configure: $gun"
    }
    if {[catch {APScavget -list=It:ByPassParC -num -pend=20} currentParState]} {
        APSMpReturn error "LPL_Configure: $currentParState"
    }
    if {$currentParState} {
        set bypass 1
    }

    if {[catch {APScavget -list=PAR:Fnd:SystemSelect} rf1amp]} {
        APSMpReturn error "LPL_Configure: Error reading the selected rf1 amplifier"
    }
    if {{"SYSTEM #1"} == $rf1amp} {
        set rf1amp 1
    } else {
        set rf1amp 2
    }
    if {[catch {APScavget -list=PAR:Har:SystemSelect} rf12amp]} {
        APSMpReturn error "LPL_Configure: Error reading the selected rf12 amplifier"
    }
    if {{"SYSTEM #1"} == $rf12amp} {
        set rf12amp 1
    } else {
        set rf12amp 2
    }


    APSParseArguments {bypass}

    if {$bypass} {
        #set startupLTP 1
        #set startupPAR 0
        set startupLTP 0
        set startupPAR 0
        set PARrfSystems 0
        set PARPulsedPS 0
        #set startupPTB 1
        #set startupPARBypass 1
        set startupPTB 0
        set startupPARBypass 0
        set conditionLTP 1
        set conditionLTPB1 1
        set conditionPAR 0
        set conditionPTB 1
        set conditionPARBypass 1
        set restoreBooster 1
    } else {
        #set startupLTP 1
        #set startupPAR 1
        set startupLTP 0
        set startupPAR 0
        set PARrfSystems 1
        set PARPulsedPS 1
        #set startupPTB 1
        #set startupPARBypass 0
        set startupPTB 0
        set startupPARBypass 0
        set conditionLTP 1
        set conditionLTPB1 1
        set conditionPAR 1
        set conditionPTB 1
        set conditionPARBypass 0
        set restoreBooster 0

    }

    APSParseArguments {gun CathodeHeaterSetpoint CathodeHeaterWatts KLYFwdPwr KickerSetpoint L1 L2 L3 L4 L5 L6 resumeSmartMonitor RFGUN PowerSupplies Modulators startupLTP startupPAR PARrfSystems PARPulsedPS PARBM startupPTB startupPARBypass bypassEnergy conditionLTP conditionLTPB1 conditionPAR conditionPTB conditionPARBypass examineSCRFile rf1amp rf12amp parRFscr restoreBooster modeVal turnOffDownKlystron mode DCPSLTP DCPSPAR DCPSPTB DCPSPARBypass rampedLTP rampedPAR rampedPTB HLTP HPARBypass VLTP VPARBypass QLTP QPARBypass B1LTP forceChangeGunOnly e325MeV e375MeV includeFilament}

    #    lappend turnOnList L1:RG2:SC L1:RG2:QM L1:RG2:LFA L1:RG1:SC L1:RG1:QM L1:RG1:LFA L1:RG2:LFA:TRM
    #    lappend conditionList L1:RG2:SC L1:RG2:QM L1:RG2:LFA L1:RG1:SC L1:RG1:QM L1:RG1:LFA L1:RG2:LFA:TRM
    if {$gun == "RG2"} {
        lappend turnOnList L1:RG2:H L1:RG2:V L1:RG2:Q L1:RG2:LFA
        lappend conditionList L1:RG2:H L1:RG2:V L1:RG2:Q L1:RG2:LFA
        set deviceList 2
    } elseif {$gun == "RG1"} {
        lappend turnOnList L1:RG1:H L1:RG1:V L1:RG1:Q L1:RG1:LFA L1:RG2:LFA:TRM
        lappend conditionList L1:RG1:H L1:RG1:V L1:RG1:Q L1:RG1:LFA L1:RG2:LFA:TRM
        set deviceList 1
    } else {
        APSMpReturn error "LPL_Configure: Unable to detect which Gun is selected. Check the LINAC RF Switching System State to ensure it is set to RUNNING and not LOCAL SWITCH or REMOTE SWITCH."
    }

    if 0 {
        if {$execMode != "Automatic"} {
            if {[catch {APScavget -list=ACIS:LAOL_INH_GUN,ACIS:LBL_GUN_INH,ACIS:LA_BP_MODE,ACIS:LB_BP_MD -num -pend=20} acisState]} {
                APSMpReturn error "LPL_Configure: $acisState"
            }
            if {([lindex $acisState 0] == 1) || ([lindex $acisState 1] == 1)} {
                if {[APSPEMTKDialog .warningDialog \
                       -text "Linac/PAR is in an acis inhibit state."] == 1} {
                    APSMpReturn error "LPL_Configure: Linac/PAR is in an acis inhibit state."
                }
            } elseif {([lindex $acisState 2] == 0) || ([lindex $acisState 3] == 0)} {
                if {[APSPEMTKDialog .warningDialog \
                       -text "Linac/PAR is in an acis trip state."] == 1} {
                    APSMpReturn error "LPL_Configure: Linac/PAR is in an acis trip state."
                }
            }
        }
    }

    APSParseArguments {turnOnList turnOffList conditionList SCRFile}
    global APSMpLControlPS
    
    set arrayName APSMpLControlPS
    APSLGenericPSArraySetup -arrayName $arrayName \
      -turnOnList $turnOnList \
      -turnOffList $turnOffList \
      -conditionList $conditionList \
      -SCRFile $SCRFile \
      -cycles 2

    if {$gun == "RG1"} {
        #	set APSMpLControlPS(TurnOn,L1:RG1:SC) 1
        #	set APSMpLControlPS(TurnOn,L1:RG1:QM) 1
        #	set APSMpLControlPS(TurnOn,L1:RG1:LFA) 1
        #	set APSMpLControlPS(TurnOn,L1:RG2:LFA:TRM) 1
        #	set APSMpLControlPS(TurnOn,L1:RG2:SC) 0
        #	set APSMpLControlPS(TurnOn,L1:RG2:QM) 0
        #	set APSMpLControlPS(TurnOn,L1:RG2:LFA) 0
        #	set APSMpLControlPS(StartConditioning,L1:RG1:SC) 1
        #	set APSMpLControlPS(StartConditioning,L1:RG1:QM) 1
        #	set APSMpLControlPS(StartConditioning,L1:RG1:LFA) 1
        #	set APSMpLControlPS(StartConditioning,L1:RG2:LFA:TRM) 1
        #	set APSMpLControlPS(StartConditioning,L1:RG2:SC) 0
        #	set APSMpLControlPS(StartConditioning,L1:RG2:QM) 0
        #	set APSMpLControlPS(StartConditioning,L1:RG2:LFA) 0
    } else {
        #	set APSMpLControlPS(TurnOn,L1:RG1:SC) 0
        #	set APSMpLControlPS(TurnOn,L1:RG1:QM) 0
        #	set APSMpLControlPS(TurnOn,L1:RG1:LFA) 0
        #	set APSMpLControlPS(TurnOn,L1:RG2:LFA:TRM) 0
        #	set APSMpLControlPS(TurnOn,L1:RG2:SC) 1
        #	set APSMpLControlPS(TurnOn,L1:RG2:QM) 1
        #	set APSMpLControlPS(TurnOn,L1:RG2:LFA) 1
        #	set APSMpLControlPS(StartConditioning,L1:RG1:SC) 0
        #	set APSMpLControlPS(StartConditioning,L1:RG1:QM) 0
        #	set APSMpLControlPS(StartConditioning,L1:RG1:LFA) 0
        #	set APSMpLControlPS(StartConditioning,L1:RG2:LFA:TRM) 0
        #	set APSMpLControlPS(StartConditioning,L1:RG2:SC) 1
        #	set APSMpLControlPS(StartConditioning,L1:RG2:QM) 1
        #	set APSMpLControlPS(StartConditioning,L1:RG2:LFA) 1
    }
    if {(![file exists $SCRFile]) && ($execMode == "Automatic")} {
        set execMode "Semi-Automatic"
    }
    
    global apsScaleUpSize
    incr apsScaleUpSize -1
    switch -- $apsScaleUpSize {
        -4 { option add *font -adobe-courier-medium-r-normal-*-6-*-*-*-*-*-*-*}
        -3 { option add *font -adobe-courier-medium-r-normal-*-8-*-*-*-*-*-*-*}
        -2 { option add *font -adobe-courier-medium-r-normal-*-10-*-*-*-*-*-*-*}
        -1 { option add *font -adobe-courier-medium-r-normal-*-12-*-*-*-*-*-*-*}
        0 { option add *font -adobe-courier-medium-r-normal-*-14-*-*-*-*-*-*-*}
        1 { option add *font -bitstream-courier-bold-r-normal-*-18-*-75-75-*-*-*-*}
        2 { option add *font -bitstream-courier-bold-r-normal-*-20-*-75-75-*-*-*-*}
        3 { option add *font -bitstream-courier-bold-r-normal-*-24-*-75-75-*-*-*-*}
        4 { option add *font -bitstream-courier-bold-r-normal-*-26-*-75-75-*-*-*-*}
    }

    APSMpStep init -promptDialog \
      "APSLGenericPSDialog -packProc LPL_ConfigurePackProc -packProcBottom LPL_ConfigurePackProcBottom -turnOn 1 -turnOff 1 -condition 1 -chooseSCR 1 -arrayName $arrayName -frame " -vars {L1 L2 L3 L4 L5 L6 RFGUN PowerSupplies Modulators startupLTP startupPAR PARrfSystems PARPulsedPS PARBM startupPTB startupPARBypass bypass bypassEnergy conditionLTP conditionLTPB1 conditionPAR conditionPTB conditionPARBypass rf1amp rf12amp parRFscr restoreBooster gun modeVal currentParState turnOffDownKlystron mode  DCPSLTP DCPSPAR DCPSPTB DCPSPARBypass rampedLTP rampedPAR rampedPTB HLTP HPARBypass VLTP VPARBypass QLTP QPARBypass B1LTP e325MeV e375MeV includeFilament}

    incr apsScaleUpSize 1
    switch -- $apsScaleUpSize {
        -4 { option add *font -adobe-courier-medium-r-normal-*-6-*-*-*-*-*-*-*}
        -3 { option add *font -adobe-courier-medium-r-normal-*-8-*-*-*-*-*-*-*}
        -2 { option add *font -adobe-courier-medium-r-normal-*-10-*-*-*-*-*-*-*}
        -1 { option add *font -adobe-courier-medium-r-normal-*-12-*-*-*-*-*-*-*}
        0 { option add *font -adobe-courier-medium-r-normal-*-14-*-*-*-*-*-*-*}
        1 { option add *font -bitstream-courier-bold-r-normal-*-18-*-75-75-*-*-*-*}
        2 { option add *font -bitstream-courier-bold-r-normal-*-20-*-75-75-*-*-*-*}
        3 { option add *font -bitstream-courier-bold-r-normal-*-24-*-75-75-*-*-*-*}
        4 { option add *font -bitstream-courier-bold-r-normal-*-26-*-75-75-*-*-*-*}
    }

    set SCRFile $APSMpLControlPS(Filename)
    set cycles $APSMpLControlPS(StartConditioningInfo,cycles)
    set turnOnList [APSLGenericPSArrayQuery -arrayName $arrayName -operation TurnOn]
    set turnOnListDetailed [APSMpLConvertDeviceNames -operation TurnOn -deviceList $turnOnList]
    set turnOnListDetailed [APSMpLConvertDetailedDeviceNames -operation TurnOn -deviceList $turnOnListDetailed -arrayName $arrayName]
    set turnOffList [APSLGenericPSArrayQuery -arrayName $arrayName -operation TurnOff]
    set turnOffListDetailed [APSMpLConvertDeviceNames -operation TurnOff -deviceList $turnOffList]
    set turnOffListDetailed [APSMpLConvertDetailedDeviceNames -operation TurnOff -deviceList $turnOffListDetailed -arrayName $arrayName]
    set conditionList [APSLGenericPSArrayQuery -arrayName $arrayName -operation StartConditioning]
    set conditionListDetailed [APSMpLConvertDeviceNames -operation StartConditioning -deviceList $conditionList]
    set conditionListDetailed [APSMpLConvertDetailedDeviceNames -operation StartConditioning -deviceList $conditionListDetailed -arrayName $arrayName]

    if {$mode == "startup"} {
        if {([llength $turnOnList] == 0) && ([llength $conditionList] == 0)} {
            set PowerSupplies 0
        }
    } else {
        if {([llength $turnOffList] == 0) && ([llength $conditionList] == 0)} {
            set PowerSupplies 0
        }
    }

    if {$mode == "startup"} {
        if {![file exists $SCRFile]} {
            APSMpReturn error "LPL_Configure: No SCR file selected"
        }
    } else {
        #Hard coding the SCR file. The conditioning PS for shutdown is being disabled so this is just a place holder.
        set SCRFile /home/helios/oagData/SCR/snapshots/LPL/LPL-SysRef_PAR_RF1_T2_RF12_T2.gz
        if {[llength $conditionList]} {
            if {![file exists $SCRFile]} {
                APSMpReturn error "LPL_Configure: No SCR file selected"
            }
        }
    }

    if {$mode == "startup"} {
        if {!$bypass} {
            if {$restoreBooster} {
                if {$e325MeV} {
                    set boosterSCRFile /home/helios/oagData/SCR/snapshots/Booster/Booster-Reference325.gz
                } elseif {$e375MeV} {
                    set boosterSCRFile /home/helios/oagData/SCR/snapshots/Booster/Booster-Reference375.gz
                } else {
                    set execMode "Manual"
                    APSMpStep init -promptDialog \
                      "APSMpGenericPSDialog -system Booster -chooseSCR 1 -arrayName $arrayName -frame " -vars {}
                    set execMode "Automatic"
                    set boosterSCRFile $APSMpLControlPS(Filename)
                }
                if {![file exists $boosterSCRFile]} {
                    APSMpReturn error "LPL_Configure: No Booster SCR file selected"
                }
            }
        }
    }

    set paramString ""
    foreach param {L1 L2 L3 L4 L5 L6 RFGUN PowerSupplies Modulators SCRFile turnOnList turnOffList conditionList startupLTP startupPAR PARrfSystems PARPulsedPS PARBM startupPTB startupPARBypass conditionLTP conditionLTPB1 conditionPAR conditionPTB conditionPARBypass bypass bypassEnergy rf1amp rf12amp parRFscr restoreBooster cycles gun modeVal mode  DCPSLTP DCPSPAR DCPSPTB DCPSPARBypass rampedLTP rampedPAR rampedPTB HLTP HPARBypass VLTP VPARBypass QLTP QPARBypass B1LTP} {
        if {[string length "${paramString}${param}=\"[set $param]\" "] < 1020} {
            append paramString "$param=\"[set $param]\" "
        }
    }
    catch {APSLogScriptAction -procedure LPL_Configure -action initialize -state ok -parameters $paramString}

    if {$mode == "shutdown"} {
        if {$RFGUN || $PowerSupplies || $Modulators} {
            set id1 [APSMpParallel -mode "Automatic" \
                       -procedure "RFGUN+LMOCS_ShutdownWithPS -RFGUN $RFGUN -PowerSupplies $PowerSupplies -turnOffList \"$turnOffList\" -conditionList \"$conditionList\" -turnOffListDetailed \"$turnOffListDetailed\" -conditionListDetailed \"$conditionListDetailed\" -Modulators $Modulators -L1 $L1 -L2 $L2 -L3 $L3 -L4 $L4 -L5 $L5 -L6 $L6  -includeFilament $includeFilament -SCRFile \"$SCRFile\""]
        }
        if {$startupPAR} {
            APSMpStep "${prefix}Shutdown PAR" -desc "Shutdown PAR"
            if {$rampedPAR} {
                set rampMode ramped
            } else {
                set rampMode abrupt
            }
            set id3 [APSMpParallel -mode "Automatic" \
                       -procedure "APSMpPARShutdown -mode $rampMode -DCPS $DCPSPAR -PulsedPS $PARPulsedPS -BM $PARBM -rfSystems $PARrfSystems"]
        }
        if {$startupPTB} {
            APSMpStep "${prefix}Shutdown PTB" -desc "Shutdown PTB"
            if {$rampedPTB} {
                set rampMode ramped
            } else {
                set rampMode abrupt
            }
            set id4 [APSMpParallel -mode "Automatic" \
                       -procedure "APSMpPTBShutdown -mode $rampMode -DCPS $DCPSPTB"]
        }
        if {$startupPARBypass} {
            APSMpStep "${prefix}Shutdown PAR Bypass" -desc "Shutdown PAR Bypass"
            set id5 [APSMpParallel -mode "Automatic" \
                       -procedure "APSMpParBypassShutdown -Q $QPARBypass -H $HPARBypass -V $VPARBypass -DCPS $DCPSPARBypass "]
        }
        #Need to finish shuting down modulators prior to turning off LTP B1
        if {$RFGUN || $PowerSupplies || $Modulators} {
            if {[catch {APSMpJoin $id1} results]} {
                if {[APSPEMTKDialog .warningDialog -text "Problem occured\nLPL_Configure: $results"] == 1} {
                    APSMpReturn error "LPL_Configure: $results"
                }
            }   
        }
        if {$startupLTP} {
            APSMpStep "${prefix}Shutdown LTP" -desc "Shutdown LTP"
            if {$rampedLTP} {
                set rampMode ramped
            } else {
                set rampMode abrupt
            }
            set id2 [APSMpParallel -mode "Automatic" \
                       -procedure "APSMpLTPShutdown -mode $rampMode -Q $QLTP -H $HLTP -V $VLTP -B1 $B1LTP -DCPS $DCPSLTP"]
        }

        if {$startupPARBypass} {
            if {[catch {APSMpJoin $id5} results]} {
                if {[APSPEMTKDialog .warningDialog -text "Problem occured PAR Bypass shutdown\nLPL_Configure: $results"] == 1} {
                    APSMpReturn error "LPL_Configure: $results"
                }
            }
        }
        if {$startupPTB} {
            if {[catch {APSMpJoin $id4} results]} {
                if {[APSPEMTKDialog .warningDialog -text "Problem occured PTB shutdown\nLPL_Configure: $results"] == 1} {
                    APSMpReturn error "LPL_Configure: $results"
                }
            } 
        }
        if {$startupPAR} {
            if {[catch {APSMpJoin $id3} results]} {
                if {[APSPEMTKDialog .warningDialog -text "Problem occured PAR shutdown\nLPL_Configure: $results"] == 1} {
                    APSMpReturn error "LPL_Configure: $results"
                }
            }   
        }
        if {$startupLTP} {
            if {[catch {APSMpJoin $id2} results]} {
                if {[APSPEMTKDialog .warningDialog -text "Problem occured LTP shutdown\nLPL_Configure: $results"] == 1} {
                    APSMpReturn error "LPL_Configure: $results"
                }
            }  
        }

        APSMpReturn ok
    }


    if {[catch {exec sdds2stream $SCRFile -parameter=SnapshotDescription -page=1 -noquotes} results]} {
        APSMpReturn error "LPL_Configure: Invalid SCR file"
    }
    if {[string first "Limited save:" $results] != -1} {
        if {[catch {exec sddssort $SCRFile -pipe=out -column=Beamline -unique | sdds2stream -pipe=in -col=Beamline} results]} {
            APSMpReturn error "LPL_Configure: Problem reading beamlines categories from the SCR file"
        }
        if {($RFGUN == 1) || ($PowerSupplies == 1) || ($Modulators == 1)} {
            if {([lsearch -exact $results L1] == -1) || \
                  ([lsearch -exact $results L2] == -1) || \
                  ([lsearch -exact $results L3] == -1) || \
                  ([lsearch -exact $results L4] == -1) || \
                  ([lsearch -exact $results L5] == -1) || \
                  ([lsearch -exact $results rfGun] == -1) || \
                  ([lsearch -exact $results rfGun1] == -1) || \
                  ([lsearch -exact $results rfGun2] == -1)} {
                APSMpReturn error "LPL_Configure: LIMITED SAVE SCR file does not include all the Linac and rfGun beamline categories"
            }
        }
        if {($startupLTP == 1)} {
            if {([lsearch -exact $results LTP] == -1) || \
                  ([lsearch -exact $results LTP1] == -1) || \
                  ([lsearch -exact $results LTP2] == -1)} {
                APSMpReturn error "LPL_Configure: LIMITED SAVE SCR file does not include all the LTP beamline categories"
            }
        }
        if {($startupPAR == 1)} {
            if {([lsearch -exact $results PAR] == -1)} {
                APSMpReturn error "LPL_Configure: LIMITED SAVE SCR file does not include all the PAR beamline categories"
            }
        }
        if {($startupPTB == 1)} {
            if {([lsearch -exact $results PTB] == -1) || \
                  ([lsearch -exact $results PTB1] == -1) || \
                  ([lsearch -exact $results PTB2] == -1) || \
                  ([lsearch -exact $results PTB3] == -1)} {
                APSMpReturn error "LPL_Configure: LIMITED SAVE SCR file does not include all the PTB beamline categories"
            }
        }
        if {($startupPARBypass == 1)} {
            if {([lsearch -exact $results PB] == -1)} {
                APSMpReturn error "LPL_Configure: LIMITED SAVE SCR file does not include all the PB beamline categories"
            }
        }
    }

    if {[catch {exec sddsselect $SCRFile /home/helios/oagData/pem/linac/filterFile -match=ControlName -pipe=out | \
                  sdds2stream -column=ControlName,ValueString -pipe=in} results]} {
        APSMpReturn error "LPL_Configure: Invalid SCR file"
    }
    set PTBCurrent 0
    set RFSwitchMode "Unknown"
    set SelectedGun "Unknown"
    set LTPB1 0
    set PTBB1 0
    set ItLSeqLenLo 25
    set LITMitsRfRate 30
    set LITMgunTrigCount 4
    foreach {controlName valueString} $results {
        if {[regexp -- L\[1-5\]:MO:PFNvAO $controlName]} {
            set L[string index $controlName 1]PFN $valueString
        } elseif {$controlName == "PTB:CM:qTotalAI"} {
            set PTBCurrent $valueString
        } elseif {$controlName == "LRFSCS:modeM"} {
            set RFSwitchMode $valueString
        } elseif {$controlName == "LRFSCS:gunM"} {
            set SelectedGun $valueString
        } elseif {$controlName == "LTP:B1:CurrentAO"} {
            set LTPB1 $valueString
        } elseif {$controlName == "PTB:B1:CurrentAO"} {
            set PTBB1 $valueString
        } elseif {$controlName == "It:L:seq_len_lo.VAL"} {
            set ItLSeqLenLo $valueString
        } elseif {$controlName == "LI:TM:itsRfRateCC"} {
            set LITMitsRfRate $valueString
        } elseif {$controlName == "LI:TM:gunTrigCountCC"} {
            set LITMgunTrigCount $valueString
        }
    }

    if {$bypass} {
        if {($LTPB1 > 51) || ($PTBB1 > 51)} {
            if {[APSPEMTKDialog .warningDialog -text "PAR Bypass is selected but the SCR file has values for the LTP and/or PTB B1 that are greater than 50"] == 1} {
                APSMpReturn error "LPL_Configure: PAR Bypass is selected but the SCR file has values for the LTP and/or PTB B1 that are greater than 50"
            }
        }
    } else {
        if {($LTPB1 < 51) || ($PTBB1 < 51)} {
            if {[APSPEMTKDialog .warningDialog -text "Include PAR is selected but the SCR file has values for the LTP and/or PTB B1 that are less than 50"] == 1} {
                APSMpReturn error "LPL_Configure: Include PAR is selected but the SCR file has values for the LTP and/or PTB B1 that are less than 50"
            }
        }
    }

    if {$RFGUN} {
        if {[catch {APSDevSend -group LinacRFGun -operation ReadCurrentGun -deviceList 0} linacGun]} {
            APSMpReturn error "LPL_Configure: $linacGun"
        }
        set SelectedGun [join $SelectedGun]
        set linacGun [join $linacGun]

    }
    if {($Modulators) || ($RFGUN)} {
        set RFSwitchMode [join $RFSwitchMode]
    }
    set changeBypassState 0
    if {$currentParState != $bypass} {
        set changeBypassState 1
        if {($startupPAR) && ($bypass)} {
            #Do not startup PAR if changing to direct injection
            set startupPAR 0
        }
    }
    if {$forceChangeGunOnly} {
        set changeBypassState 0
    }
    set changeGun 0
    if {$RFGUN} {
        if {$linacGun == "PG 1"} {
            if {[catch {APSMpPG1_SwitchToL3Down -gun $gun} results]} {
                APSMpReturn error "LPL_Configure: $results"
            }
            if {[catch {APSDevSend \
                          -group LinacRFGun \
                          -operation ReadRFCurrentMode \
                          -deviceList 0} linacMode]} {
                APSMpReturn error "LPL_Configure: $linacMode"
            }
            set linacMode [join $linacMode]
        } elseif {(($gun == "RG1") && ($linacGun != "RG 1")) || (($gun == "RG2") && ($linacGun != "RG 2"))} {
            set changeGun 1
        }
        if {$forceChangeGunOnly} {
            set changeGun 1
            if {$gun == "RG1"} {
                set gun RG2
            } else {
                set gun RG1
            }
        }
        set inPCgunMode 0
        if {[catch {exec cavget -list=LI:TM:pg1ConfigCC} inPCgunMode]} {
        }
        if {$inPCgunMode == 1} {
            catch {exec cavput -list=L1:PC1:GV2:closeCmdBO=1}
            after 1000
        }
    }
    #linacMode is the current value of LRFSCS:modeM
    #modeVal is the selected value from the dialog box
    set changeMode 0
    if {($Modulators) || ($RFGUN)} {
        if {($linacMode != $modeVal)} {
            set changeMode 1
        }
    }
    if {$forceChangeGunOnly} {
        set changeMode 0
    }
    if {$changeBypassState} {
        if {!$RFGUN} {
            APSMpReturn error "LPL_Configure: When changing the include/bypass PAR state, RFGUN must be selected"
        }
    }

    if {($Modulators) || ($RFGUN) || ($changeBypassState) || ($changeMode) || ($changeGun)} {
        set k1down 0
        set k2down 0
        if {($modeVal == "K1 Down")} {
            #set suspendL1 1
            set k1down 1
            set L1SectorSource 3
            set L2SectorSource 2
        } elseif {($modeVal == "K2 Down")} {
            #set suspendL2 1
            set k2down 1
            set L1SectorSource 1
            set L2SectorSource 3
        } else {
            set L1SectorSource 1
            set L2SectorSource 2
            if {$bypass} {
                set L3 0
            }
        }
    }
    if {$RFGUN} {
        if {!$Modulators} {
            set Modulators 1
            foreach sector $sectors {
                set $sector 0
                #set suspend$sector 1
            }
            if {$changeGun} {
                set L${L2SectorSource} 1
            }
        }
        set L${L1SectorSource} 1



        APSMpStep "${prefix}Reset Kicker Interlock" -desc "Reset Kicker Interlock"
        if {[catch {APSDevSend \
                      -group LinacRFGun \
                      -operation ResetKicker \
                      -deviceList $deviceList} result]} {
            if {[APSPEMTKDialog .warningDialog -text "Unable reset kicker interlocks.\nLPL_Configure: $result"] == 1} {
                APSMpReturn error "Unable reset kicker interlocks: LPL_Configure: $result"
            }
        }
        after 1000
        for {set resetPauseStep 0} {$resetPauseStep < 10} {incr resetPauseStep} {
            if {[catch {exec cavget -list=L1:RG${deviceList}:KIK:Bit1BI,L1:RG${deviceList}:KIK:Bit2BI -num -printErrors -pend=1} result]} {
                set result "1 1"
            }
            if {([lindex $result 0] == 0) && ([lindex $result 1] == 0)} {
                break
            } elseif {$resetPauseStep == 9} {
                if {[APSPEMTKDialog .warningDialog -text "RG${deviceList} kicker is not ready to turn-on. Make sure the supply is turned on locally."] == 1} {
                    return -code error "LPL_Configure: RG${deviceList} kicker is not ready to turn-on."
                }
            }
            after 1000
        }
    }

    if {$examineSCRFile} {
        if {$RFGUN} {
            #linacGun == current, gun == desired, SelectedGun == SCR value
            if {(($gun == "RG1") && ($SelectedGun != "RG 1")) || (($gun == "RG2") && ($SelectedGun != "RG 2"))} {
                if {[APSPEMTKDialog .warningDialog -text "The RF Gun selected is different from that in the SCR file.\n${SCRFile}\n(SCR file: ${SelectedGun})\n(User selected: ${gun})"] == 1} {
                    APSMpReturn error "LPL_Configure: The RF Gun selected is different from that in the SCR file."
                }
            }

            set LinacInjectionSequenceRate 0
            if {[catch {exec cavget -list=It:L:1HzNot2Hz_bo -num} LinacInjectionSequenceRate]} {
                APSMpReturn error "LPL_Configure: Cannot read It:L:1HzNot2Hz_bo \n$LinacInjectionSequenceRate"
            }
            if {$LinacInjectionSequenceRate == 0} {
                if {$ItLSeqLenLo != 25} {
                    if {[APSPEMTKDialog .warningDialog -text "The Linac Injection Sequence Rate is currently set to 2Hz but the SCR file appears to be different."] == 1} {
                        APSMpReturn error "LPL_Configure: The Linac Injection Sequence Rate is currently set to 2Hz but the SCR file appears to be different."
                    }
                }
            } else {
                if {$ItLSeqLenLo != 55} {
                    if {[APSPEMTKDialog .warningDialog -text "The Linac Injection Sequence Rate is currently set to 1Hz but the SCR file appears to be different."] == 1} {
                        APSMpReturn error "LPL_Configure: The Linac Injection Sequence Rate is currently set to 1Hz but the SCR file appears to be different."
                    }
                }
            }

        }

        if {$Modulators} {
            #linacMode == current, modeVal == desired, RFSwitchMode == SCR value
            if {$RFSwitchMode != $modeVal} {
                if {($RFSwitchMode=="Normal"    && $modeVal=="K3 Down") ||
                    ($RFSwitchMode=="Normal"    && $modeVal=="Test Room") ||
                    ($RFSwitchMode=="K3 Down"   && $modeVal=="Normal") ||
                    ($RFSwitchMode=="K3 Down"   && $modeVal=="Test Room") ||
                    ($RFSwitchMode=="Test Room" && $modeVal=="Normal") ||
                    ($RFSwitchMode=="Test Room" && $modeVal=="K3 Down")} {
                    APSMpStep "Note: SCR has $RFSwitchMode (not $modeVal), which is acceptable"
                } else {
                    if {[APSPEMTKDialog .warningDialog -text "The Linac RF Switching mode is different from that in the SCR file.\n${SCRFile}\n(SCR file: ${RFSwitchMode})\n(User selected value: ${modeVal})"] == 1} {
                        APSMpReturn error "LPL_Configure: The Linac RF Switching mode is different from that in the SCR file."
                    }
                }
            }
        }
    }

    if {$Modulators} {
        while {1} {
            APSMpStep "Checking Modulator Interlocks"
            if {[catch {CheckModulatorInterlocks} result]} {
                set answer [APSPEMTKDialog .warningDialog -text "Problem seen with interlocks. $result" -strings {Continue Recheck "Abort Procedure"}]
                if {$answer == 2} {
                    APSMpReturn error "LPL_Configure: Problem seen with interlocks. $result"
                }
                if {$answer == 0} {
                    break
                }
            } else {
                break
            }
        }

        if {!$forceChangeGunOnly} {
            foreach sector $sectors {
                if {[set $sector]} {
                    if {$sector == "L2"} {
                        continue
                    }
                    if {([set ${sector}PFN] < 5) || ([set ${sector}PFN] > 50)} {
                        if {[APSPEMTKDialog .warningDialog -text "Value for sector $sector PFN is [set ${sector}PFN] (not valid)\nIf you are sure this PFN value is correct\nyou may click continue"] == 1} {
                            APSMpReturn error "LPL_Configure: Value for sector $sector PFN is [set ${sector}PFN] (not valid)"
                        }
                    } 
                }
            }
        }
    }

    if {$bypass} {
        while {1} {
            APSMpStep "Check that the linac-to-LEUTL (double stop) is open"
            if [catch {APScavget -list=ACIS:LAO_LTB_2S_CLSD -num} result] {
                APSMpReturn error "LPL_Configure: $result"
            }
            if {$result != 0} {
                if {[APSPEMTKDialog .warningDialog -text "The Linac to LEUTL double stop is not open."] == 1} {
                    APSMpReturn error "LPL_Configure: the Linac to LEUTL double stop is not open"
                }
            } else {
                break
            }
        }
    }

    if {$startupPAR} {
        if {$PARPulsedPS} {
            APSMpStep "${prefix}Start PAR Pulsed PS" -desc "Start up PAR Pulsed PS"
            set parpps [APSMpParallel -mode "Automatic" \
                          -procedure "APSMpPARStartUp -rfSystems 0 -PulsedPS $PARPulsedPS -restoreFile [file tail $SCRFile] -DCPS 0 -restoreDCPS 0"]
        }
    }
    if {$startupLTP} {
        if {$conditionLTP} {
            APSMpStep "${prefix}Start LTP" -desc "Start up LTP"

            if {[catch {exec cavget -list=LTP:B1:StatusCALC} results]} {
                set maxLTPB1Cycles 8
            } else {
                if {$results != 0} {
                    set maxLTPB1Cycles 8
                }
            }

            set id4 [APSMpParallel -mode "Automatic" \
                       -procedure "APSMpLTPStartUp -conditioningTime [expr {$cycles * 2.5}] -standardizeB1 $conditionLTPB1 -maxLTPB1Cycles $maxLTPB1Cycles -restoreFile [file tail $SCRFile]"]
        } else {
            APSMpStep "LTP: Turn On DCPS" -proc APSMpLTPTurnOnDCPS 
            if [catch APSMpLTPTurnOnDCPS result] {
                if {[APSPEMTKDialog .warningDialog -text "Unable turn on LTP DCPS.\nLPL_Configure: $result"] == 1} {
                    APSMpReturn error "Unable turn on LTP DCPS: LPL_Configure: $result"
                }
            }
            APSMpStep "${prefix}Start LTP" -desc "Start up LTP"
            set id4 [APSMpParallel -mode "Automatic" \
                       -procedure "APSMpLTPStartUp -restoreFile [file tail $SCRFile] -DCPS 0"]
        }
    }
    if {$startupPTB} {
        if {$conditionPTB} {
            APSMpStep "${prefix}Start PTB" -desc "Start up PTB"
            set id5 [APSMpParallel -mode "Automatic" \
                       -procedure "APSMpPTBStartUp -conditioningTime [expr {$cycles * 2.5}] -restoreFile [file tail $SCRFile]"]
        } else {
            APSMpStep "PTB: Turn On DCPS" -proc "APSMpPTBTurnOnDCPS"
            if [catch APSMpPTBTurnOnDCPS result] {
                if {[APSPEMTKDialog .warningDialog -text "Unable turn on PTB DCPS.\nLPL_Configure: $result"] == 1} {
                    APSMpReturn error "Unable turn on PTB DCPS: LPL_Configure: $result"
                }
            }
            APSMpStep "${prefix}Start PTB" -desc "Start up PTB"
            set id5 [APSMpParallel -mode "Automatic" \
                       -procedure "APSMpPTBStartUp -restoreFile [file tail $SCRFile] -DCPS 0"]
        }
    }
    if {$startupPARBypass} {
        if {$conditionPARBypass} {
            APSMpStep "${prefix}Start PAR Bypass" -desc "Start up PAR Bypass"
            set id6 [APSMpParallel -mode "Automatic" \
                       -procedure "APSMpParBypassStartUp -conditioningTime [expr {$cycles * 2.5}] -restoreFile [file tail $SCRFile]"]
        } else {
            APSMpStep "ParBypass: Turn On DCPS" -proc APSMpParBypassTurnOnDCPS 
            if [catch APSMpParBypassTurnOnDCPS result] {
                if {[APSPEMTKDialog .warningDialog -text "Unable turn on PAR Bypass DCPS.\nLPL_Configure: $result"] == 1} {
                    APSMpReturn error "Unable turn on PAR Bypass DCPS: LPL_Configure: $result"
                }
            }
            APSMpStep "${prefix}Start PAR Bypass" -desc "Start up PAR Bypass"
            set id6 [APSMpParallel -mode "Automatic" \
                       -procedure "APSMpParBypassStartUp -restoreFile [file tail $SCRFile] -DCPS 0"]
        }
    }

    if {([llength $turnOnList] == 0) && ([llength $conditionList] == 0)} {
        set PowerSupplies 0
    }
    if {$PowerSupplies} {
        APSMpStep "${prefix}Start up power supplies" -desc "Start up power supplies" -proc APSMpLStartUpPS
        set id1 [APSMpParallel \
                   -procedure "APSMpLStartUpPS -turnOnList \"$turnOnList\" -conditionList \"$conditionList\" -turnOnListDetailed \"$turnOnListDetailed\" -conditionListDetailed \"$conditionListDetailed\" -SCRFile $SCRFile -cycles [set ${arrayName}(StartConditioningInfo,cycles)]" \
                   -mode "Automatic"]
    }

    set abortControllaw 1
    if {[file exists /home/helios/oagData/controllaw/linacBeamRfPhase/L1RFGun1_L2_L4_L5/linacBeamRfPhase-L1RFGun1-L2-L4-L5.def]} {
        if {[file exists /home/helios/oagData/controllaw/linacBeamRfPhase/L1RFGun2_L2_L4_L5/linacBeamRfPhase-L1RFGun2-L2-L4-L5.def]} {
            if {[file type /home/helios/oagData/controllaw/linacBeamRfPhase/L1RFGun1_L2_L4_L5/linacBeamRfPhase-L1RFGun1-L2-L4-L5.def] == "link"} {
                if {[file type /home/helios/oagData/controllaw/linacBeamRfPhase/L1RFGun2_L2_L4_L5/linacBeamRfPhase-L1RFGun2-L2-L4-L5.def] == "link"} {
                    set file1 [file readlink /home/helios/oagData/controllaw/linacBeamRfPhase/L1RFGun1_L2_L4_L5/linacBeamRfPhase-L1RFGun1-L2-L4-L5.def]
                    set file2 [file readlink /home/helios/oagData/controllaw/linacBeamRfPhase/L1RFGun2_L2_L4_L5/linacBeamRfPhase-L1RFGun2-L2-L4-L5.def]
                    if {($modeVal == "K1 Down")} {
                        if {$file1 == "/home/helios/oagData/controllaw/linacBeamRfPhase/L1RFGun1_L2_L4_L5/linacBeamRfPhase-L1RFGun1-L2-L4-L5_K1Dn.def"} {
                            if {$file2 == "/home/helios/oagData/controllaw/linacBeamRfPhase/L1RFGun2_L2_L4_L5/linacBeamRfPhase-L1RFGun2-L2-L4-L5_K1Dn.def"} {
                                set abortControllaw 0
                            }	
                        }
                    } elseif {($modeVal == "K2 Down")} {
                        if {$file1 == "/home/helios/oagData/controllaw/linacBeamRfPhase/L1RFGun1_L2_L4_L5/linacBeamRfPhase-L1RFGun1-L2-L4-L5_K2Dn.def"} {
                            if {$file2 == "/home/helios/oagData/controllaw/linacBeamRfPhase/L1RFGun2_L2_L4_L5/linacBeamRfPhase-L1RFGun2-L2-L4-L5_K2Dn.def"} {
                                set abortControllaw 0
                            }	
                        }
                    } else {
                        if {$file1 == "/home/helios/oagData/controllaw/linacBeamRfPhase/L1RFGun1_L2_L4_L5/linacBeamRfPhase-L1RFGun1-L2-L4-L5_K3Dn.def"} {
                            if {$file2 == "/home/helios/oagData/controllaw/linacBeamRfPhase/L1RFGun2_L2_L4_L5/linacBeamRfPhase-L1RFGun2-L2-L4-L5_K3Dn.def"} {
                                set abortControllaw 0
                            }	
                        }
                    }
                }
            }
        }
    }
    if {$abortControllaw} {
        APSMpStep "${prefix}Abort linac RF phase controllaw" -desc "Abort linac RF phase controllaw"
        if {[catch {APScavput -list=L:BPD:RFGUN1:L1L2L4L5RC.ABRT=1,L:BPD:RFGUN2:L1L2L4L5RC.ABRT=1} result]} {
            if {[APSPEMTKDialog .warningDialog -text "Problem aborting the linac RF phase controllaw\nLPL_Configure: $result"] == 1} {
                APSMpReturn error "Problem aborting the linac RF phase controllaw: LPL_Configure: $result"
            }
        }
        if {[catch {APScavput -list=L:BPD:RFGUN1RC.ABRT=1,L:BPD:RFGUN2RC.ABRT=1,L:BPD:RFGUN2K1DnRC.ABRT=1,L:BPD:RFGUN2K2DnRC.ABRT=1,L:BPD:L3P3:L4AS1RC.ABRT=1,L:BPD:L4P1:L5AS1RC.ABRT=1} result]} {
            if {[APSPEMTKDialog .warningDialog -text "Problem suspending the linac RF phase controllaw\nLPL_Configure: $result"] == 1} {
                APSMpReturn error "Problem suspending the linac RF phase controllaw: LPL_Configure: $result"
            }
        }
    }


    if {$changeMode} {
        APSMpStep "${prefix}Suspend fixedCurrent" -desc "Suspend fixedCurrent"
        if {[catch {APSMpLSuspendResumeRunControl \
                      -value "Suspend" \
                      -name FixedCurrent \
                      -group "LinacRFGun" \
                      -deviceList 0} result]} {
            if {[APSPEMTKDialog .warningDialog -text "Unable to suspend the hold current script\n$result"] == 1} {
                APSMpReturn error "LPL_Configure: $result"
            }
        }

        if {$k1down} {
            if {$turnOffDownKlystron} {
                set L1 1
            }
        } elseif {$k2down} {
            if {$turnOffDownKlystron} {
                set L2 1
            }
        } else {
            if {$turnOffDownKlystron} {
                set origL3 $L3
                set L3 1
            }
        }
        if {($linacMode=="Normal"    && $modeVal=="K3 Down") ||
            ($linacMode=="Normal"    && $modeVal=="Test Room") ||
            ($linacMode=="K3 Down"   && $modeVal=="Normal") ||
            ($linacMode=="K3 Down"   && $modeVal=="Test Room") ||
            ($linacMode=="Test Room" && $modeVal=="Normal") ||
            ($linacMode=="Test Room" && $modeVal=="K3 Down")} {
            if {[catch {LMOCS_Modulator_Shutdown -L3 1} result]} {
                if {[APSPEMTKDialog .warningDialog -text "Unable to shutdown the selected modulators\n$result"] == 1} {
                    APSMpReturn error "LPL_Configure: $result"
                }
            }
        } else {
            if {[catch {LMOCS_Modulator_Shutdown -L1 $L1 -L2 $L2 -L3 $L3 -includeFilament $includeFilament} result]} {
                if {[APSPEMTKDialog .warningDialog -text "Unable to shutdown the selected modulators\n$result"] == 1} {
                    APSMpReturn error "LPL_Configure: $result"
                }
            }
        }
        if {($modeVal == "K1 Down")} {
            if {$turnOffDownKlystron} {
                set L1 0
            }
        } elseif {($modeVal == "K2 Down")} {
            if {$turnOffDownKlystron} {
                set L2 0
            }
        } else {
            if {$turnOffDownKlystron} {
                set L3 $origL3
            }
        }

        if {$RFGUN} {
            APSMpStep "${prefix}Run RFGun_Shutdown PEM" -desc "Run RFGUN Shutdown PEM" -proc RFGUN_Shutdown
            if [catch {RFGUN_Shutdown -k1down $k1down -k2down $k2down -closeGateValves 0 -changeMode 1} result] {
                if {[APSPEMTKDialog .warningDialog -text "Problem running RFGUN Shutdown PEM\n$result"] == 1} {
                    APSMpReturn error "LPL_Configure: $result"
                }
            }
        }
        if 0 {
            APSMpStep "${prefix}Turn the kicker off" -desc "Turn the kicker off"
            if {$gun == "RG1"} {
                if {[catch {APSRFGUN_TurnKickerOnOff -deviceList 1 -value 0 -state "off"} result]} {
                    if {[APSPEMTKDialog .warningDialog -text "Unable to turn rfgun 1 kicker off\n$result"] == 1} {
                        APSMpReturn error "LPL_Configure: $result"
                    }
                }
            } elseif {$gun == "RG2"} {
                if {[catch {APSRFGUN_TurnKickerOnOff -deviceList 2 -value 0 -state "off"} result]} {
                    if {[APSPEMTKDialog .warningDialog -text "Unable to turn rfgun 2 kicker off\n$result"] == 1} {
                        APSMpReturn error "LPL_Configure: $result"
                    }
                }
            }
        }
        APSMpStep "${prefix}Abort linac RF phase controllaw" -desc "Abort linac RF phase controllaw"
        if {[catch {APScavput -list=L:BPD:RFGUN1:L1L2L4L5RC.ABRT=1,L:BPD:RFGUN2:L1L2L4L5RC.ABRT=1} result]} {
            if {[APSPEMTKDialog .warningDialog -text "Problem aborting the linac RF phase controllaw\nLPL_Configure: $result"] == 1} {
                APSMpReturn error "Problem aborting the linac RF phase controllaw: LPL_Configure: $result"
            }
        }
        if {[catch {APScavput -list=L:BPD:RFGUN1RC.ABRT=1,L:BPD:RFGUN2RC.ABRT=1,L:BPD:RFGUN2K1DnRC.ABRT=1,L:BPD:RFGUN2K2DnRC.ABRT=1,L:BPD:L3P3:L4AS1RC.ABRT=1,L:BPD:L4P1:L5AS1RC.ABRT=1} result]} {
            if {[APSPEMTKDialog .warningDialog -text "Problem suspending the linac RF phase controllaw\nLPL_Configure: $result"] == 1} {
                APSMpReturn error "Problem suspending the linac RF phase controllaw: LPL_Configure: $result"
            }
        }
        
        global apsScriptUser apsScriptHost
        
        set oldmethod 1
        if {$apsScriptUser == "asdops"} {
            set oldmethod 0
        } elseif {($apsScriptHost == "echo") || ($apsScriptHost == "echo.aps4.anl.gov") || \
                    ($apsScriptHost == "iris") || ($apsScriptHost == "iris.aps4.anl.gov") || \
                    ($apsScriptHost == "cadmus") || ($apsScriptHost == "cadmus.aps4.anl.gov") || \
                    ($apsScriptHost == "cyclops") || ($apsScriptHost == "cyclops.aps4.anl.gov") || \
                    ($apsScriptHost == "auric")  || ($apsScriptHost == "auric.aps4.anl.gov") || \
                    ($apsScriptHost == "demeter") || ($apsScriptHost == "demeter.aps4.anl.gov")} {
            set oldmethod 0
        }
        #	if {($linacMode == "Test Room")} {
        #	    set oldmethod 1
        #	}
        if {$oldmethod} {
            APSDialogBox .waveguidedialog -name "Operator Interaction"
            destroy .waveguidedialog.buttonRow.cancel.button
            pack [label .waveguidedialog.userFrame.label -text "Wait for operator to switch the LINAC RF mode to $modeVal"]
            bell
            while 1 {
                APSMpStep "${prefix}Switch the LINAC RF mode to $modeVal" \
                  -desc "Wait for operator to switch the LINAC RF mode"
                
                if {[catch {APSDevSend \
                              -group LinacRFGun \
                              -operation ReadRFRequestedMode \
                              -deviceList 0} result]} {
                    APSMpReturn error "LPL_Configure: $result"
                }
                if {[catch {APSDevSend \
                              -group LinacRFGun \
                              -operation ReadRFCurrentMode \
                              -deviceList 0} result2]} {
                    APSMpReturn error "LPL_Configure: $result2"
                }
                
                if {[catch {APSDevSend \
                              -group LinacRFGun \
                              -operation ReadRFSwitchState \
                              -deviceList 0} state]} {
                    APSMpReturn error "LPL_Configure: $state"
                }
                if {(($modeVal == [join $result2]) || (($modeVal == "Normal") && ([join $result2] == "K3 Down"))) &&
                    ($state == "RUNNING")} {
                    break
                }
                APSWaitWithUpdate -waitSeconds 10
            }
            destroy .waveguidedialog
        } else {

            APSMpStep "Requesting remote switch control"
            if {[catch {APScavput -list=LRFSCS:MCR:RemoteRequest=1 -pend=20} result]} {
                if {[APSPEMTKDialog .warningDialog -text "Problem requesting remote switching control: $result"] == 1} {
                    APSMpReturn error "Problem requesting remote switching control: $result"
                }
            }
            APSWaitWithUpdate -waitSeconds 5
            APSMpStep "Verifying remote switch control"
            if {[catch {APScavget -list=LRFSCS:MCR:RemoteEnabled -num -pend=20} result]} {
                APSMpReturn error "Problem verifying remote switch control"
            }
            if {$result != 1} {
                if {[APSPEMTKDialog .warningDialog -text "Problem requesting remote switching control"] == 1} {
                    APSMpReturn error "Problem requesting remote switching control"
                }
            }
            
            if {(($linacMode == "K1 Down") || ($linacMode == "K2 Down"))} {
                APSMpStep "Switch To Normal mode"
                if {[catch {APScavput -list=LRFSCS:MCR:SelectNormal=1 -pend=20} result]} {
                    if {[APSPEMTKDialog .warningDialog -text "Problem changing to Normal mode: $result"] == 1} {
                        APSMpReturn error "Problem changing to Normal mode: $result"
                    }
                }
            } elseif {($linacMode == "K3 Down") || ($linacMode == "Normal")} {
                APSMpStep "Switch To Normal mode"
                if {[catch {APScavput -list=LRFSCS:MCR:SelectNormalWater=1 -pend=20} result]} {
                    if {[APSPEMTKDialog .warningDialog -text "Problem changing to Normal mode: $result"] == 1} {
                        APSMpReturn error "Problem changing to Normal mode: $result"
                    }
                }
            } elseif {($linacMode == "Test Room")} {
                APSMpStep "Switch To Normal mode"
                if {[catch {APScavput -list=LRFSCS:MCR:SelectNormalTest=1 -pend=20} result]} {
                    if {[APSPEMTKDialog .warningDialog -text "Problem changing to Normal mode: $result"] == 1} {
                        APSMpReturn error "Problem changing to Normal mode: $result"
                    }
                }
            }
            APSMpStep "Verifying we are now in Normal mode"
            set tries 0
            while {$tries <= 25} {
                APSWaitWithUpdate -waitSeconds 1
                if {[catch {APScavget -list=LRFSCS:PLC:ModeState -num -pend=20} modestate]} {
                    APSMpReturn error "Problem getting the mode state: $modestate"
                }
                if {($modestate == 3) || ($modestate == 4) || ($modestate == 5)} {
                    break
                }
                incr tries
                if {$tries == 25} {
                    if {[APSPEMTKDialog .warningDialog -text "Unable to switch to Normal mode"] == 1} {
                        APSMpReturn error "Unable to switch to Normal mode"
                    }
                    set tries 0
                }
            }
            if {[catch {APScavget -list=LRFSCS:PLC:SwitchFault -num -pend=20} switchfault]} {
                APSMpReturn error "Problem getting the mode state: $switchfault"
            }
            if {($switchfault != 12)} {
                if {[APSPEMTKDialog .warningDialog -text "Switch faults seen while switching to Normal mode"] == 1} {
                    APSMpReturn error "Switch faults seen while switching to Normal mode"
                }
            }
            APSWaitWithUpdate -waitSeconds 5

            if {$modeVal == "K1 Down"} {
                APSMpStep "Switch To K1 Down mode"
                if {[catch {APScavput -list=LRFSCS:MCR:SelectK1Down=1 -pend=20} result]} {
                    if {[APSPEMTKDialog .warningDialog -text "Problem changing to K1 Down mode: $result"] == 1} {
                        APSMpReturn error "Problem changing to K1 Down mode: $result"
                    }
                }
                APSMpStep "Verifying we are now in K1 Down mode"
                set tries 0
                while {$tries <= 25} {
                    APSWaitWithUpdate -waitSeconds 1
                    if {[catch {APScavget -list=LRFSCS:PLC:ModeState -num -pend=20} modestate]} {
                        APSMpReturn error "Problem getting the mode state: $modestate"
                    }
                    if {($modestate != 2)} {
                        if {$tries == 25} {
                            if {[APSPEMTKDialog .warningDialog -text "Unable to switch to K1 Down mode"] == 1} {
                                APSMpReturn error "Unable to switch to K1 Down mode"
                            }
                        } else {
                            incr tries
                        }
                    } else {
                        break
                    }
                }
                if {[catch {APScavget -list=LRFSCS:PLC:SwitchFault -num -pend=20} switchfault]} {
                    APSMpReturn error "Problem getting the mode state: $switchfault"
                }
                if {($switchfault != 12)} {
                    if {[APSPEMTKDialog .warningDialog -text "Switch faults seen while switching to K1 Down mode"] == 1} {
                        APSMpReturn error "Switch faults seen while switching to K1 Down mode"
                    }
                }
            }
            if {$modeVal == "K2 Down"} {
                APSMpStep "Switch To K2 Down mode"
                if {[catch {APScavput -list=LRFSCS:MCR:SelectK2Down=1 -pend=20} result]} {
                    if {[APSPEMTKDialog .warningDialog -text "Problem changing to K2 Down mode: $result"] == 1} {
                        APSMpReturn error "Problem changing to K2 Down mode: $result"
                    }
                }
                APSMpStep "Verifying we are now in K2 Down mode"
                set tries 0
                while {$tries <= 25} {
                    APSWaitWithUpdate -waitSeconds 1
                    if {[catch {APScavget -list=LRFSCS:PLC:ModeState -num -pend=20} modestate]} {
                        APSMpReturn error "Problem getting the mode state: $modestate"
                    }
                    if {($modestate != 1)} {
                        if {$tries == 25} {
                            if {[APSPEMTKDialog .warningDialog -text "Unable to switch to K2 Down mode"] == 1} {
                                APSMpReturn error "Unable to switch to K2 Down mode"
                            }
                        } else {
                            incr tries
                        }
                    } else {
                        break
                    }
                }
                if {[catch {APScavget -list=LRFSCS:PLC:SwitchFault -num -pend=20} switchfault]} {
                    APSMpReturn error "Problem getting the mode state: $switchfault"
                }
                if {($switchfault != 12)} {
                    if {[APSPEMTKDialog .warningDialog -text "Switch faults seen while switching to K2 Down mode"] == 1} {
                        APSMpReturn error "Switch faults seen while switching to K2 Down mode"
                    }
                }
            }
            if {($modeVal == "K3 Down")} {
                APSMpStep "Switch To K3 Down (Condition) mode"
                if {[catch {APScavput -list=LRFSCS:MCR:SelectK3Down=1 -pend=20} result]} {
                    if {[APSPEMTKDialog .warningDialog -text "Problem changing to K3 Down (Condition) mode: $result"] == 1} {
                        APSMpReturn error "Problem changing to K3 Down mode: $result"
                    }
                }
                APSMpStep "Verifying we are now in K3 Down (Condition) mode"
                set tries 0
                while {$tries <= 25} {
                    APSWaitWithUpdate -waitSeconds 1
                    if {[catch {APScavget -list=LRFSCS:PLC:ModeState -num -pend=20} modestate]} {
                        APSMpReturn error "Problem getting the mode state: $modestate"
                    }
                    if {($modestate != 7)} {
                        if {$tries == 25} {
                            if {[APSPEMTKDialog .warningDialog -text "Unable to switch to K3 Down (Condition) mode"] == 1} {
                                APSMpReturn error "Unable to switch to K3 Down (Condition) mode"
                            }
                        } else {
                            incr tries
                        }
                    } else {
                        break
                    }
                }
                if {[catch {APScavget -list=LRFSCS:PLC:SwitchFault -num -pend=20} switchfault]} {
                    APSMpReturn error "Problem getting the mode state: $switchfault"
                }
                if {($switchfault != 12)} {
                    if {[APSPEMTKDialog .warningDialog -text "Switch faults seen while switching to K3 Down mode"] == 1} {
                        APSMpReturn error "Switch faults seen while switching to K3 Down mode"
                    }
                }
            }
            if {($modeVal == "Normal")} {
                #Already in normal RF mode
            }
            if {($modeVal == "Test Room")} {
                APSMpStep "Switch To Test Room mode"
                if {[catch {APScavput -list=LRFSCS:MCR:SelectTestroom=1 -pend=20} result]} {
                    if {[APSPEMTKDialog .warningDialog -text "Problem changing to Test Room mode: $result"] == 1} {
                        APSMpReturn error "Problem changing to Test Room mode: $result"
                    }
                }
                APSMpStep "Verifying we are now in Test Room mode"
                set tries 0
                while {$tries <= 25} {
                    APSWaitWithUpdate -waitSeconds 1
                    if {[catch {APScavget -list=LRFSCS:PLC:ModeState -num -pend=20} modestate]} {
                        APSMpReturn error "Problem getting the mode state: $modestate"
                    }
                    if {($modestate != 6)} {
                        if {$tries == 25} {
                            if {[APSPEMTKDialog .warningDialog -text "Unable to switch to Test Room mode DEBUG"] == 1} {
                                APSMpReturn error "Unable to switch to Test Room mode DEBUG"
                            }
                        } else {
                            incr tries
                        }
                    } else {
                        break
                    }
                }
                if {[catch {APScavget -list=LRFSCS:PLC:SwitchFault -num -pend=20} switchfault]} {
                    APSMpReturn error "Problem getting the mode state: $switchfault"
                }
                if {($switchfault != 12)} {
                    if {[APSPEMTKDialog .warningDialog -text "Switch faults seen while switching to Test Room mode"] == 1} {
                        APSMpReturn error "Switch faults seen while switching to Test Room mode"
                    }
                }
            }
            
            APSMpStep "Run mode switch"
            if {[catch {APScavput -list=LRFSCS:MCR:SelectRun=1 -pend=20} result]} {
                if {[APSPEMTKDialog .warningDialog -text "Problem running mode switch: $result"] == 1} {
                    APSMpReturn error "Problem running mode switch: $result"
                }
            }
        }


        if {($L4) || ($L5)} {
            APSMpStep "${prefix}Suspend X LTP ControlLaw" -desc "Suspend X LTP ControlLaw"
            if [catch {APSMpLSuspendResumeRunControl \
                         -value "Suspend" \
                         -name "LTPControlLaw" \
                         -group "RunControlGroup" \
                         -deviceList X} result] {
                if {[APSPEMTKDialog .warningDialog -text "Unable to suspend X LTP controllaw\n$result"] == 1} {
                    APSMpReturn error "LPL_Configure: $result"
                }
            }
            APSMpStep "${prefix}Suspend Y LTP ControlLaw" -desc "Suspend Y LTP ControlLaw"
            if [catch {APSMpLSuspendResumeRunControl \
                         -value "Suspend" \
                         -name "LTPControlLaw" \
                         -group "RunControlGroup" \
                         -deviceList Y} result] {
                if {[APSPEMTKDialog .warningDialog -text "Unable to suspend Y LTP controllaw\n$result"] == 1} {
                    APSMpReturn error "LPL_Configure: $result"
                }
            }
        }

        if {[string length $SCRFile]} {
            APSMpStep "Restoring Timing SCR Values" 
            set tmpFile /tmp/[APSTmpString]
            if {($modeVal == "K1 Down")} {
                set options "-match=column,Beamline=L2,Beamline=L3,|"
            } elseif {($modeVal == "K2 Down")} {
                set options "-match=column,Beamline=L1,Beamline=L3,|"
            } else {
                set options "-match=column,Beamline=L1,Beamline=L2,|,Beamline=L3,|"
            }
            if {[catch {eval exec sddsprocess $SCRFile $tmpFile \
                          -match=column,IsReadOnly=+n \
                          -match=column,IsProtected=+n \
                          -match=column,Category=Timing \
                          $options \
                          -match=col,ControlType=,! -match=col,ControlName=,!
                exec sddscasr -restore $tmpFile} result]} {
                APSPEMTKDialog .warningDialog -strings Continue -default 0 -text "Problem restoring SCR file: LPL_Configure: $result"
                catch {APSSendEMail -address soliday \
                         -subject "Problem restoring SCR file."  \
                         -message "Problem restore SCR file\nLPL_Configure\n$SCRFile\n$result"} 
            }
            file delete $tmpFile

            APSMpStep "Restoring L1-L5 RF SCR Values" 
            set tmpFile /tmp/[APSTmpString]
            if {($modeVal == "K1 Down")} {
                set options "-match=column,Beamline=L2,Beamline=L3,|,Beamline=L4,|,Beamline=L5,|"
            } elseif {($modeVal == "K2 Down")} {
                set options "-match=column,Beamline=L1,Beamline=L3,|,Beamline=L4,|,Beamline=L5,|"
            } else {
                set options "-match=column,Beamline=L1,Beamline=L2,|,Beamline=L3,|,Beamline=L4,|,Beamline=L5,|"
            }
            if {[catch {eval exec sddsprocess $SCRFile $tmpFile \
                          -match=column,IsReadOnly=+n \
                          -match=column,IsProtected=+n \
                          -match=column,Category=RF \
                          $options \
                          -match=col,ControlType=,! -match=col,ControlName=,!
                exec sddscasr -restore $tmpFile} result]} {
                APSPEMTKDialog .warningDialog -strings Continue -default 0 -text "Problem restoring SCR file: LPL_Configure: $result"
                catch {APSSendEMail -address soliday \
                         -subject "Problem restoring SCR file."  \
                         -message "Problem restore SCR file\nLPL_Configure\n$SCRFile\n$result"} 
            }
            file delete $tmpFile
        }
    } else {
        #Not changing modes
        #Still need to ensure the timing source matches the SCR values if the RFGUN or Modulators are selected
        if {(($Modulators) || ($RFGUN)) && !$forceChangeGunOnly} {
            set tmpFile /tmp/[APSTmpString]
            APSMpStep "Restoring L3 Timing Source" 
            if {[catch {eval exec sddsprocess $SCRFile $tmpFile -match=column,IsReadOnly=+n \
                          -match=column,IsProtected=+n -match=column,Category=Timing \
                          -match=column,Beamline=L3 -match=column,ControlName=LI:TM:L3TimingSourceC} result]} {
                APSPEMTKDialog .warningDialog -strings Continue -default 0 -text "Problem restoring SCR file: LPL_Configure: $result"
                catch {APSSendEMail -address soliday -subject "Problem restoring SCR file." -message "Problem restore SCR file\nLPL_Configure\n$SCRFile\n$result"} 
            }
            if {[catch {exec sddscasr -restore $tmpFile} result]} {
                APSPEMTKDialog .warningDialog -strings Continue -default 0 -text "Problem restoring SCR file: LPL_Configure: $result"
                catch {APSSendEMail -address soliday -subject "Problem restoring SCR file." -message "Problem restore SCR file\nLPL_Configure\n$SCRFile\n$result"} 
            }
            file delete $tmpFile
        }
    }

    if {($Modulators) || ($RFGUN)} {

        if {($modeVal == "K1 Down")} {
            #APSMpStep "${prefix}Set timing source to LI Beam (RFG) Rate" -desc "Set timing source to LI Beam (RFG) Rate"
            #if [catch {APSLINAC_SetTimingSource -state "LIBeamRFG" -deviceList 3} result] {
            #    if {[APSPEMTKDialog .warningDialog -text "Unable to set timing source to LI Beam (RFG) Rate\n$result"] == 1} {
            #        APSMpReturn error "LPL_Configure: $result"
            #    }
            #}
            catch {APScavput -list=L2:LL:lockSLEDonBO=1 -pend=10}
            catch {APScavput -list=L3:LL:lockSLEDoffBO=1 -pend=10}
            if {[catch {
                exec ln -fs /home/helios/oagData/controllaw/linacBeamRfPhase/L1RFGun1_L2_L4_L5/linacBeamRfPhase-L1RFGun1-L2-L4-L5_K1Dn.def /home/helios/oagData/controllaw/linacBeamRfPhase/L1RFGun1_L2_L4_L5/linacBeamRfPhase-L1RFGun1-L2-L4-L5.def
                exec ln -fs /home/helios/oagData/controllaw/linacBeamRfPhase/L1RFGun2_L2_L4_L5/linacBeamRfPhase-L1RFGun2-L2-L4-L5_K1Dn.def /home/helios/oagData/controllaw/linacBeamRfPhase/L1RFGun2_L2_L4_L5/linacBeamRfPhase-L1RFGun2-L2-L4-L5.def
                exec ln -fs /home/helios/oagData/controllaw/linacBeamRfPhase/L1RFGun1_L2_L4_L5/linacBeamRfPhase-L1RFGun1-L2-L4-L5_K1Dn.tests /home/helios/oagData/controllaw/linacBeamRfPhase/L1RFGun1_L2_L4_L5/linacBeamRfPhase-L1RFGun1-L2-L4-L5.tests
                exec ln -fs /home/helios/oagData/controllaw/linacBeamRfPhase/L1RFGun2_L2_L4_L5/linacBeamRfPhase-L1RFGun2-L2-L4-L5_K1Dn.tests /home/helios/oagData/controllaw/linacBeamRfPhase/L1RFGun2_L2_L4_L5/linacBeamRfPhase-L1RFGun2-L2-L4-L5.tests
            } result]} {
                if {[APSPEMTKDialog .warningDialog -text "Unable to relink phase controllaw input file for K1 down mode\n$result"] == 1} {
                    APSMpReturn error "LPL_Configure: $result"
                }
            }
        } elseif {($modeVal == "K2 Down")} {
            #APSMpStep "${prefix}Set timing source to LI Beam (RF) Rate" -desc "Set timing source to LI RF Rate"
            #if [catch {APSLINAC_SetTimingSource -state "LIRFRate" -deviceList 3} result] {
            #    if {[APSPEMTKDialog .warningDialog -text "Unable to set timing source to LI RF Rate\n$result"] == 1} {
            #        APSMpReturn error "LPL_Configure: $result"
            #    }
            #}
            catch {APScavput -list=L2:LL:lockSLEDoffBO=1 -pend=10}
            catch {APScavput -list=L3:LL:lockSLEDonBO=1 -pend=10}
            if {[catch {
                exec ln -fs /home/helios/oagData/controllaw/linacBeamRfPhase/L1RFGun1_L2_L4_L5/linacBeamRfPhase-L1RFGun1-L2-L4-L5_K2Dn.def /home/helios/oagData/controllaw/linacBeamRfPhase/L1RFGun1_L2_L4_L5/linacBeamRfPhase-L1RFGun1-L2-L4-L5.def
                exec ln -fs /home/helios/oagData/controllaw/linacBeamRfPhase/L1RFGun2_L2_L4_L5/linacBeamRfPhase-L1RFGun2-L2-L4-L5_K2Dn.def /home/helios/oagData/controllaw/linacBeamRfPhase/L1RFGun2_L2_L4_L5/linacBeamRfPhase-L1RFGun2-L2-L4-L5.def
                exec ln -fs /home/helios/oagData/controllaw/linacBeamRfPhase/L1RFGun1_L2_L4_L5/linacBeamRfPhase-L1RFGun1-L2-L4-L5_K2Dn.tests /home/helios/oagData/controllaw/linacBeamRfPhase/L1RFGun1_L2_L4_L5/linacBeamRfPhase-L1RFGun1-L2-L4-L5.tests
                exec ln -fs /home/helios/oagData/controllaw/linacBeamRfPhase/L1RFGun2_L2_L4_L5/linacBeamRfPhase-L1RFGun2-L2-L4-L5_K2Dn.tests /home/helios/oagData/controllaw/linacBeamRfPhase/L1RFGun2_L2_L4_L5/linacBeamRfPhase-L1RFGun2-L2-L4-L5.tests
            } result]} {
                if {[APSPEMTKDialog .warningDialog -text "Unable to relink phase controllaw input file for K2 down mode\n$result"] == 1} {
                    APSMpReturn error "LPL_Configure: $result"
                }
            }
        } elseif {($modeVal == "Normal") || ($modeVal == "K3 Down") || ($modeVal == "Test Room")} {
            #set timingsource LIRFRate
            #if {[catch {APScavget -list=LRFSCS:SW -list=3,4,5,9 -list=:P1M -num -pend=20} currentMode]} {
            #} else {
            #    if {([lindex $currentMode 0] == 1) && ([lindex $currentMode 1] == 1) && ([lindex $currentMode 2] == 1) && ([lindex $currentMode 3] == 1)} {
            #        set timingsource LIBeamPG1
            #    }
            #}

            #APSMpStep "${prefix}Set timing source to $timingsource" -desc "Set timing source"
            #if [catch {APSLINAC_SetTimingSource -state $timingsource -deviceList 3} result] {
            #    if {[APSPEMTKDialog .warningDialog -text "Unable to set timing source to $timingsource \n$result"] == 1} {
            #        APSMpReturn error "LPL_Configure: $result"
            #    }
            #}
            catch {APScavput -list=L2:LL:lockSLEDonBO=1 -pend=10}
            catch {APScavput -list=L3:LL:lockSLEDoffBO=1 -pend=10}
            if {[catch {
                exec ln -fs /home/helios/oagData/controllaw/linacBeamRfPhase/L1RFGun1_L2_L4_L5/linacBeamRfPhase-L1RFGun1-L2-L4-L5_K3Dn.def /home/helios/oagData/controllaw/linacBeamRfPhase/L1RFGun1_L2_L4_L5/linacBeamRfPhase-L1RFGun1-L2-L4-L5.def
                exec ln -fs /home/helios/oagData/controllaw/linacBeamRfPhase/L1RFGun2_L2_L4_L5/linacBeamRfPhase-L1RFGun2-L2-L4-L5_K3Dn.def /home/helios/oagData/controllaw/linacBeamRfPhase/L1RFGun2_L2_L4_L5/linacBeamRfPhase-L1RFGun2-L2-L4-L5.def
                exec ln -fs /home/helios/oagData/controllaw/linacBeamRfPhase/L1RFGun1_L2_L4_L5/linacBeamRfPhase-L1RFGun1-L2-L4-L5_K3Dn.tests /home/helios/oagData/controllaw/linacBeamRfPhase/L1RFGun1_L2_L4_L5/linacBeamRfPhase-L1RFGun1-L2-L4-L5.tests
                exec ln -fs /home/helios/oagData/controllaw/linacBeamRfPhase/L1RFGun2_L2_L4_L5/linacBeamRfPhase-L1RFGun2-L2-L4-L5_K3Dn.tests /home/helios/oagData/controllaw/linacBeamRfPhase/L1RFGun2_L2_L4_L5/linacBeamRfPhase-L1RFGun2-L2-L4-L5.tests
            } result]} {
                if {[APSPEMTKDialog .warningDialog -text "Unable to relink phase controllaw input file for K3 down mode\n$result"] == 1} {
                    APSMpReturn error "LPL_Configure: $result"
                }
            }
        }

    }


    if {$changeGun} {
        if {[catch {APSLSuspendResumeRFPowerControllaws -klystronList "1 2 3" -mode suspend} result]} {
            if {[APSPEMTKDialog .warningDialog -text "Failed to automatically suspend L1, L2, or L3 power control law."] == 1} {
                APSMpReturn error "LPL_Configure: $result"
            }
        }
        
        APSMpStep "${prefix}Ramp down the L1 and L3 LLRF" \
          -desc "Ramp down the L1 and L3 LLRF"
        if [catch {APSLReduceKlystronOutputPower -klystronList "1 3"} result] {
            if {[APSPEMTKDialog .warningDialog -text "Failed to automatically ramp down L1 and L3 LLRF"] == 1} {
                APSMpReturn error "LPL_Configure: $result"
            }
        }
        APSMpStep "${prefix}Select LLRF Off" -desc "Turn L1, L2, L3 LLRF off"
        if [catch {APSLINAC_LLRFOnOff -button "Off" -deviceList {1 2 3}} result] {
            if {[APSPEMTKDialog .warningDialog -text "Failed to automatically turn off L1 and L3 LLRF."] == 1} {
                APSMpReturn error "LPL_Configure: $result"
            }
        }
        APSMpStep "${prefix}Bring L2 down to standby mode"
        if [catch {TurnOffK400 -klystron K2 -leaveInStandby 1} result] {
            if {[APSPEMTKDialog .warningDialog -text "Failed to bring L2 down to standby mode."] == 1} {
                APSMpReturn error "LPL_Configure: $result"
            }
        }
        

        if {$changeMode} {
            #Gun already shutdown, kicker already off

            #The linacMode is the current state. If we already did the mode change then the current state has changed to the 
            #selected state. This is why linacMode has to be set to modeVal because modeVal is the selected state.
            set linacMode $modeVal

            APSMpStep "${prefix}Close gate valves" -desc "Close the gate valves"
            if {[catch {
                APSRFGUN_OpenCloseGateValve -deviceList "L1GV1 L1GV2 L1PG1GV2" -value Close -group LinacValves
                APSRFGUN_OpenCloseGateValve -deviceList "1 2" -value Close -group LinacRFGun
            } result]} {
                if {[APSPEMTKDialog .warningDialog -text "Unable to close the gate valves\n$result"] == 1} {
                    APSMpReturn error "LPL_COnfigure: $result"
                }
            }
            
        } else {
            APSMpStep "${prefix}Run RFGun_Shutdown PEM" -desc "Run RFGUN Shutdown PEM" -proc RFGUN_Shutdown
            if {[catch {RFGUN_Shutdown -k1down $k1down -k2down $k2down -changemode 1} result]} {
                if {[APSPEMTKDialog .warningDialog -text "Problem running the RFGUN Shutdown PEM\n$result"] == 1} {
                    APSMpReturn error "LPL_Configure: $result"
                }
            }
        }
        
        APSMpStep "${prefix}Turn the kicker off" -desc "Turn the kicker off"
        if {$gun == "RG1"} {
            if {[catch {APSRFGUN_TurnKickerOnOff -deviceList 1 -value 0 -state "off"} result]} {
                if {[APSPEMTKDialog .warningDialog -text "Unable to turn off rfgun 1 kicker\n$result"] == 1} {
                    APSMpReturn error "LPL_Configure: $result"
                }
            }
        } elseif {$gun == "RG2"} {
            if {[catch {APSRFGUN_TurnKickerOnOff -deviceList 2 -value 0 -state "off"} result]} {
                if {[APSPEMTKDialog .warningDialog -text "Unable to turn off rfgun 2 kicker\n$result"] == 1} {
                    APSMpReturn error "LPL_Configure: $result"
                }
            }
        }
        APSMpStep "${prefix}Ramp down PFN voltage" -desc "Ramp down PFN voltage"
        if {[catch {APSLRampPFNVoltage \
                      -klystronList "1 3" \
                      -rampTo 0.0 \
                      -steps 1} result]} {
            if {[APSPEMTKDialog .warningDialog -text "Unable to ramp down PFN voltage on modulators 1, 2, and 3\n$result"] == 1} {
                APSMpReturn error "LPL_Configure: $result"
            }
        }

        if {[catch {APSDevSend \
                      -group LinacKlystron \
                      -operation QueryPSEnableOn \
                      -deviceList 1} result]} {
            APSMpReturn error "LPL_Configure: $result"
        }
        if {$result} {
            APSMpStep "${prefix}Disable PS in L1" -desc "Disable PS if needed"
            if {[catch {APSDevSend \
                          -group LinacKlystron \
                          -operation ResetPowerSupplyEnable \
                          -deviceList 1} result]} {
                APSMpReturn error "LPL_Configure: $result"
            }
            after 510
            if {[catch {APSDevSend \
                          -group LinacKlystron \
                          -operation TogglePowerSupplyEnable \
                          -deviceList 1} result]} {
                APSMpReturn error "LPL_Configure: $result"
            }
            if {[catch {APSDevSend \
                          -group LinacKlystron \
                          -operation QueryPSEnableOn \
                          -deviceList 1 \
                          -returnPVList 1} result]} {
                APSMpReturn error "LPL_Configure: $result"
            }
            if {[catch {blt::bgexec apsLMOCSTurnOnAbortVariable cawait \
                          -interval=1 \
                          -waitFor=$result,equalto=0 \
                          -timeLimit=10} result]} {
                if {[APSPEMTKDialog .warningDialog -text ": Unable to disable PS in sector L1: $result"] == 1} {
                    APSMpReturn error "LPL_Configure: Unable to disable PS in sector L1: $result"
                }
            }
        }
        if {[catch {APSDevSend \
                      -group LinacKlystron \
                      -operation QueryPSEnableOn \
                      -deviceList 3} result]} {
            APSMpReturn error "LPL_Configure: $result"
        }
        if {$result} {
            APSMpStep "${prefix}Disable PS in L3" -desc "Disable PS if needed"
            if {[catch {APSDevSend \
                          -group LinacKlystron \
                          -operation ResetPowerSupplyEnable \
                          -deviceList 3} result]} {
                APSMpReturn error "LPL_Configure: $result"
            }
            after 510
            if {[catch {APSDevSend \
                          -group LinacKlystron \
                          -operation TogglePowerSupplyEnable \
                          -deviceList 3} result]} {
                APSMpReturn error "LPL_Configure: $result"
            }
            if {[catch {APSDevSend \
                          -group LinacKlystron \
                          -operation QueryPSEnableOn \
                          -deviceList 3 \
                          -returnPVList 1} result]} {
                APSMpReturn error "LPL_Configure: $result"
            }
            if {[catch {blt::bgexec apsLMOCSTurnOnAbortVariable cawait \
                          -interval=1 \
                          -waitFor=$result,equalto=0 \
                          -timeLimit=10} result]} {
                if {[APSPEMTKDialog .warningDialog -text ": Unable to disable PS in sector L3: $result"] == 1} {
                    APSMpReturn error "LPL_Configure: Unable to disable PS in sector L3: $result"
                }
            }
        }





        
        if {0} {
            if {[catch {APScavget -list=LI:TM:rfGunConfigCC} result]} {
                APSMpReturn error "LPL_Configure: $result"
            }
            if {$result == 0} {
                APSMpStep "${prefix}Change Timing to RF-Gun" \
                  -desc "Change Timing to RF-Gun" -proc "RFGUN_ChangeTiming"
                if [catch {RFGUN_ChangeTiming -includePar 1 -bypassPar 0} result] {
                    if {[APSPEMTKDialog .warningDialog -text "Unable to change RFGUN timing\n$result"] == 1} {
                        APSMpReturn error "LPL_Configure: $result"
                    }
                }
            }
        }



        global apsScriptUser apsScriptHost
        set oldmethod 1
        if {$apsScriptUser == "asdops"} {
            set oldmethod 0
        } elseif {($apsScriptHost == "echo") || ($apsScriptHost == "echo.aps4.anl.gov") || \
                    ($apsScriptHost == "iris") || ($apsScriptHost == "iris.aps4.anl.gov") || \
                    ($apsScriptHost == "cadmus") || ($apsScriptHost == "cadmus.aps4.anl.gov") || \
                    ($apsScriptHost == "cyclops") || ($apsScriptHost == "cyclops.aps4.anl.gov") || \
                    ($apsScriptHost == "auric")  || ($apsScriptHost == "auric.aps4.anl.gov") || \
                    ($apsScriptHost == "demeter") || ($apsScriptHost == "demeter.aps4.anl.gov")} {
            set oldmethod 0
        }
        #	if {($linacMode == "Test Room")} {
        #	    set oldmethod 1
        #	}
        if {$oldmethod} {
            APSDialogBox .waveguidedialog -name "Operator Interaction"
            destroy .waveguidedialog.buttonRow.cancel.button
            pack [label .waveguidedialog.userFrame.label -text "Wait for operator to switch the RFGun waveguide switch"]
            bell
            while 1 {
                APSMpStep "${prefix}Switch the RFGun waveguide switch" \
                  -desc "Wait for operator to switch the RFGun waveguide switch"
                
                if {[catch {APSRFGUN_DetectSelectedGun} gun2]} {
                    APSMpReturn error "LPL_Configure: $gun2"
                }
                if {[catch {APScavget -list=LRFSCS:gunM -num} CurrentGun]} {
                    APSMpReturn error "LPL_Configure: $CurrentGun"
                }
                if {$CurrentGun != 2} {
                    if {(($gun == "RG1") && ($gun2 == "RG1")) || 
                        (($gun == "RG2") && ($gun2 == "RG2"))} {
                        break
                    }
                }
                APSWaitWithUpdate -waitSeconds 10
            }
            destroy .waveguidedialog
        } else {
            APSMpStep "Requesting remote switch control"
            if {[catch {APScavput -list=LRFSCS:MCR:RemoteRequest=1 -pend=20} result]} {
                if {[APSPEMTKDialog .warningDialog -text "Problem requesting remote switching control: $result"] == 1} {
                    APSMpReturn error "Problem requesting remote switching control: $result"
                }
            }
            APSWaitWithUpdate -waitSeconds 5
            APSMpStep "Verifying remote switch control"
            if {[catch {APScavget -list=LRFSCS:MCR:RemoteEnabled -num -pend=20} result]} {
                APSMpReturn error "Problem verifying remote switch control"
            }
            if {$result != 1} {
                if {[APSPEMTKDialog .warningDialog -text "Problem requesting remote switching control"] == 1} {
                    APSMpReturn error "Problem requesting remote switching control"
                }
            }

            if {($linacMode == "Normal") || ($linacMode == "K1 Down") || ($linacMode == "K2 Down")} {
                #Do not switch modes
            }
            if {($linacMode == "K3 Down")} {
                APSMpStep "Switch To Normal mode"
                if {[catch {APScavput -list=LRFSCS:MCR:SelectNormalWater=1 -pend=20} result]} {
                    if {[APSPEMTKDialog .warningDialog -text "Problem changing to Normal mode: $result"] == 1} {
                        APSMpReturn error "Problem changing to Normal mode: $result"
                    }
                }
                APSMpStep "Verifying we are now in Normal mode"
                set tries 0
                while {$tries <= 25} {
                    APSWaitWithUpdate -waitSeconds 1
                    if {[catch {APScavget -list=LRFSCS:PLC:ModeState -num -pend=20} modestate]} {
                        APSMpReturn error "Problem getting the mode state: $modestate"
                    }
                    if {($modestate == 3) || ($modestate == 4) || ($modestate == 5)} {
                        break
                    }
                    incr tries
                    if {$tries == 25} {
                        if {[APSPEMTKDialog .warningDialog -text "Unable to switch to Normal mode"] == 1} {
                            APSMpReturn error "Unable to switch to Normal mode"
                        }
                        set tries 0
                    }
                }
                if {[catch {APScavget -list=LRFSCS:PLC:SwitchFault -num -pend=20} switchfault]} {
                    APSMpReturn error "Problem getting the mode state: $switchfault"
                }
                if {($switchfault != 12)} {
                    if {[APSPEMTKDialog .warningDialog -text "Switch faults seen while switching to Normal mode"] == 1} {
                        APSMpReturn error "Switch faults seen while switching to Normal mode"
                    }
                }
                APSWaitWithUpdate -waitSeconds 5
            }
            if {($linacMode == "Test Room")} {
                APSMpStep "Switch To Test Room mode"
                if {[catch {APScavput -list=LRFSCS:MCR:SelectNormalTest=1 -pend=20} result]} {
                    if {[APSPEMTKDialog .warningDialog -text "Problem changing to Normal mode: $result"] == 1} {
                        APSMpReturn error "Problem changing to Normal mode: $result"
                    }
                }
                APSMpStep "Verifying we are now in Normal mode"
                set tries 0
                while {$tries <= 25} {
                    APSWaitWithUpdate -waitSeconds 1
                    if {[catch {APScavget -list=LRFSCS:PLC:ModeState -num -pend=20} modestate]} {
                        APSMpReturn error "Problem getting the mode state: $modestate"
                    }
                    if {($modestate == 3) || ($modestate == 4) || ($modestate == 5)} {
                        break
                    }
                    incr tries
                    if {$tries == 25} {
                        if {[APSPEMTKDialog .warningDialog -text "Unable to switch to Normal mode"] == 1} {
                            APSMpReturn error "Unable to switch to Normal mode"
                        }
                        set tries 0
                    }
                }
                if {[catch {APScavget -list=LRFSCS:PLC:SwitchFault -num -pend=20} switchfault]} {
                    APSMpReturn error "Problem getting the mode state: $switchfault"
                }
                if {($switchfault != 12)} {
                    if {[APSPEMTKDialog .warningDialog -text "Switch faults seen while switching to Normal mode"] == 1} {
                        APSMpReturn error "Switch faults seen while switching to Normal mode"
                    }
                }
                APSWaitWithUpdate -waitSeconds 5
            }
            APSMpStep "Switch To $gun"
            if {[catch {APScavput -list=LRFSCS:MCR:Select${gun}=1 -pend=20} result]} {
                if {[APSPEMTKDialog .warningDialog -text "Problem changing to $gun: $result"] == 1} {
                    APSMpReturn error "Problem changing to $gun: $result"
                }
            }
            APSMpStep "Verifying we are now using $gun"
            set tries 0
            while {$tries <= 25} {
                APSWaitWithUpdate -waitSeconds 1
                if {[catch {APScavget -list=LRFSCS:PLC:GunState -num -pend=20} gunstate]} {
                    APSMpReturn error "Problem getting the gun state: $gunstate"
                }
                if {$gun == "RG1"} {
                    if {($gunstate != 0)} {
                        if {$tries == 25} {
                            if {[APSPEMTKDialog .warningDialog -text "Unable to switch to $gun"] == 1} {
                                APSMpReturn error "Unable to switch to $gun"
                            }
                        } else {
                            incr tries
                        }
                    } else {
                        break
                    }
                } elseif {$gun == "RG2"} {
                    if {($gunstate != 1)} {
                        if {$tries == 25} {
                            if {[APSPEMTKDialog .warningDialog -text "Unable to switch to $gun"] == 1} {
                                APSMpReturn error "Unable to switch to $gun"
                            }
                        } else {
                            incr tries
                        }
                    } else {
                        break
                    }
                }
            }
            if {[catch {APScavget -list=LRFSCS:PLC:SwitchFault -num -pend=20} switchfault]} {
                APSMpReturn error "Problem switching the selected gun: $switchfault"
            }
            if {($switchfault != 12)} {
                if {[APSPEMTKDialog .warningDialog -text "Switch faults seen while switching to $gun"] == 1} {
                    APSMpReturn error "Switch faults seen while switching to $gun"
                }
            }
            if {($modeVal == "K3 Down")} {
                APSWaitWithUpdate -waitSeconds 5
                if {[catch {APScavget -list=LRFSCS:PLC:ModeState -num -pend=20} modestate]} {
                    APSMpReturn error "Problem getting the mode state: $modestate"
                }
                APSMpStep "Switch To K3 Down (Condition) mode"
                if {[catch {APScavput -list=LRFSCS:MCR:SelectK3Down=1 -pend=20} result]} {
                    if {[APSPEMTKDialog .warningDialog -text "Problem changing to K3 Down (Condition) mode: $result"] == 1} {
                        APSMpReturn error "Problem changing to K3 Down mode: $result"
                    }
                }
                APSMpStep "Verifying we are now in K3 Down (Condition) mode"
                set tries 0
                while {$tries <= 25} {
                    APSWaitWithUpdate -waitSeconds 1
                    if {[catch {APScavget -list=LRFSCS:PLC:ModeState -num -pend=20} modestate]} {
                        APSMpReturn error "Problem getting the mode state: $modestate"
                    }
                    if {($modestate != 7)} {
                        if {$tries == 25} {
                            if {[APSPEMTKDialog .warningDialog -text "Unable to switch to K3 Down (Condition) mode"] == 1} {
                                APSMpReturn error "Unable to switch to K3 Down (Condition) mode"
                            }
                        } else {
                            incr tries
                        }
                    } else {
                        break
                    }
                }
                if {[catch {APScavget -list=LRFSCS:PLC:SwitchFault -num -pend=20} switchfault]} {
                    APSMpReturn error "Problem getting the mode state: $switchfault"
                }
                if {($switchfault != 12)} {
                    if {[APSPEMTKDialog .warningDialog -text "Switch faults seen while switching to K3 Down mode"] == 1} {
                        APSMpReturn error "Switch faults seen while switching to K3 Down mode"
                    }
                }
                
            }
            if {($modeVal == "Test Room")} {
                APSMpStep "Switch To Test Room mode"
                if {[catch {APScavput -list=LRFSCS:MCR:SelectTestroom=1 -pend=20} result]} {
                    if {[APSPEMTKDialog .warningDialog -text "Problem changing to Test Room mode: $result"] == 1} {
                        APSMpReturn error "Problem changing to Test Room mode: $result"
                    }
                }
                APSMpStep "Verifying we are now in Test Room mode"
                set tries 0
                while {$tries <= 25} {
                    APSWaitWithUpdate -waitSeconds 1
                    if {[catch {APScavget -list=LRFSCS:PLC:ModeState -num -pend=20} modestate]} {
                        APSMpReturn error "Problem getting the mode state: $modestate"
                    }
                    if {($modestate != 6)} {
                        if {$tries == 25} {
                            if {[APSPEMTKDialog .warningDialog -text "Unable to switch to Test Room mode"] == 1} {
                                APSMpReturn error "Unable to switch to Test Room mode"
                            }
                        } else {
                            incr tries
                        }
                    } else {
                        break
                    }
                }
                if {[catch {APScavget -list=LRFSCS:PLC:SwitchFault -num -pend=20} switchfault]} {
                    APSMpReturn error "Problem getting the mode state: $switchfault"
                }
                if {($switchfault != 12)} {
                    if {[APSPEMTKDialog .warningDialog -text "Switch faults seen while switching to Test Room mode"] == 1} {
                        APSMpReturn error "Switch faults seen while switching to Test Room mode"
                    }
                }
            }

            APSMpStep "Run mode switch"
            if {[catch {APScavput -list=LRFSCS:MCR:SelectRun=1 -pend=20} result]} {
                if {[APSPEMTKDialog .warningDialog -text "Problem running mode switch: $result"] == 1} {
                    APSMpReturn error "Problem running mode switch: $result"
                }
            }
        }
        

        ############################

        APSMpStep "${prefix}Abort linac controllaw" -desc "Abort linac controllaw"
        if {[catch {APScavput -list=Linac:ControlLawXRC.ABRT=1,Linac:ControlLawYRC.ABRT=1} result]} {
            if {[APSPEMTKDialog .warningDialog -text "Problem aborting the linac RF phase controllaw\nLPL_Configure: $result"] == 1} {
                APSMpReturn error "Problem aborting the linac RF phase controllaw: LPL_Configure: $result"
            }
        }
        if {[catch {
            exec ln -fs /home/helios/oagData/controllaw/LINAC/${gun}/xLinac.def /home/helios/oagData/controllaw/LINAC/xLinac.def
            exec ln -fs /home/helios/oagData/controllaw/LINAC/${gun}/xLinac.matrix /home/helios/oagData/controllaw/LINAC/xLinac.matrix
            exec ln -fs /home/helios/oagData/controllaw/LINAC/${gun}/xLinac.matrix.resp /home/helios/oagData/controllaw/LINAC/xLinac.matrix.resp
            exec ln -fs /home/helios/oagData/controllaw/LINAC/${gun}/xLinac.tests /home/helios/oagData/controllaw/LINAC/xLinac.tests
            exec ln -fs /home/helios/oagData/controllaw/LINAC/${gun}/yLinac.def /home/helios/oagData/controllaw/LINAC/yLinac.def
            exec ln -fs /home/helios/oagData/controllaw/LINAC/${gun}/yLinac.matrix /home/helios/oagData/controllaw/LINAC/yLinac.matrix
            exec ln -fs /home/helios/oagData/controllaw/LINAC/${gun}/yLinac.matrix.resp /home/helios/oagData/controllaw/LINAC/yLinac.matrix.resp
            exec ln -fs /home/helios/oagData/controllaw/LINAC/${gun}/yLinac.tests /home/helios/oagData/controllaw/LINAC/yLinac.tests
        } result]} {
            if {[APSPEMTKDialog .warningDialog -text "Unable to relink phase controllaw input file for LINAC ${gun}\n$result"] == 1} {
                APSMpReturn error "LPL_Configure: $result"
            }
        }
        if {[catch {APScavput -list=Linac:ControlLawXRC.SUSP=0,Linac:ControlLawYRC.SUSP=0} result]} {
            if {[APSPEMTKDialog .warningDialog -text "Problem aborting the linac controllaw\nLPL_Configure: $result"] == 1} {
                APSMpReturn error "Problem aborting the linac controllaw: LPL_Configure: $result"
            }
        }
        after 1000
        if {[catch {APScavput -list=Linac:ControlLawXRC.ABRT=1,Linac:ControlLawYRC.ABRT=1} result]} {
            if {[APSPEMTKDialog .warningDialog -text "Problem aborting the linac controllaw\nLPL_Configure: $result"] == 1} {
                APSMpReturn error "Problem aborting the linac controllaw: LPL_Configure: $result"
            }
        }
        after 3000
        if {[catch {APScavput -list=Linac:ControlLawXRC.CLR=1,Linac:ControlLawYRC.CLR=1} result]} {
            if {[APSPEMTKDialog .warningDialog -text "Problem aborting the linac controllaw\nLPL_Configure: $result"] == 1} {
                APSMpReturn error "Problem aborting the linac controllaw: LPL_Configure: $result"
            }
        }
        set dir [pwd]
        cd /home/helios/oagData/controllaw/LINAC
        if {[catch {exec ./xLinacOptions -rcPV Linac:ControlLawXRC} options]} {
            APSMpReturn error "Unable to start linac controllaw: $options"
        }
        if {[catch {eval exec sddscontrollaw $options >& /dev/null &} result]} {
            if {[APSPEMTKDialog .warningDialog -text "Unable to start linac controllaw: $result"] == 1} {
                APSMpReturn error "Unable to start linac controllaw: $result"
            }
        }
        if {[catch {exec ./yLinacOptions -rcPV Linac:ControlLawYRC} options]} {
            APSMpReturn error "Unable to start linac controllaw: $options"
        }
        if {[catch {eval exec sddscontrollaw $options >& /dev/null &} result]} {
            if {[APSPEMTKDialog .warningDialog -text "Unable to start linac controllaw: $result"] == 1} {
                APSMpReturn error "Unable to start linac controllaw: $result"
            }
        }
        cd $dir
        
        if {$changeMode} {
            #LTP controllaws already suspended
        } else {
            if {($L4) || ($L5)} {
                APSMpStep "${prefix}Suspend X LTP ControlLaw" -desc "Suspend X LTP ControlLaw"
                if [catch {APSMpLSuspendResumeRunControl \
                             -value "Suspend" \
                             -name "LTPControlLaw" \
                             -group "RunControlGroup" \
                             -deviceList X} result] {
                    if {[APSPEMTKDialog .warningDialog -text "Unable to suspend X LTP controllaw \n$result"] == 1} {
                        APSMpReturn error "LPL_Configure: $result"
                    }
                }
                APSMpStep "${prefix}Suspend Y LTP ControlLaw" -desc "Suspend X LTP ControlLaw"
                if [catch {APSMpLSuspendResumeRunControl \
                             -value "Suspend" \
                             -name "LTPControlLaw" \
                             -group "RunControlGroup" \
                             -deviceList Y} result] {
                    if {[APSPEMTKDialog .warningDialog -text "Unable to suspend Y LTP controllaw \n$result"] == 1} {
                        APSMpReturn error "LPL_Configure: $result"
                    }
                }
            }
        }
        
        if {$gun == "RG2"} {
            set pass 1
            APSMpStep "set RG1 alpha magnet current to zero"
            if [catch {exec cavput -list=L1:RG1:LFA:CurrentAO=0 -pend=5} result] {
                set pass 0
            }
            if {$pass} {
                APSMpStep "waiting for RG1 alpha magnet to reach zero."
                if [catch {exec cawait -waitFor=L1:RG1:LFA:CurrentAI,below=.01 -time=60} result] {
                    set pass 0
                }
            }
            if {$pass} {
                APSMpStep "turn off RG1 alpha magnet..."
                if [catch {exec cavput -list=L1:RG1:LFA:OffBO=1 -pend=5} result] {
                    set pass 0
                }
            }
            if {$pass} {
                APSMpStep "wait for RG1 alpha magnet to turn off..."
                if [catch {exec cawait -waitFor=L1:RG1:LFA:StatusCC,equal=2 -time=30} result] {
                    set pass 0
                }
            }
            if {$pass} {
                APSMpStep "set RG1 kicker voltage to zero"
                if [catch {exec cavput -list=L1:RG1:KIK:VoltSetSendAO=0 -pend=5} result] {
                    set pass 0
                }
            }
            if {$pass} {
                APSMpStep "waiting for RG1 kicker voltage to reach zero."
                if [catch {exec cawait -waitFor=L1:RG1:KIK:PFNVoltageAI,below=1.5 -time=60} result] {
                    set pass 0
                }
            }
            if {$pass} {
                APSMpStep "turn off RG1 kicker..."
                catch {exec cavput -list=L1:RG1:KIK:OnBO=0 -pend=5}
            }
        }
        
        APSMpStep "${prefix}Set gate valves" -desc "Set gate valves"
        if {[catch {
            APSRFGUN_OpenCloseGateValve -deviceList L1GV1 -value Close -group LinacValves
            APSRFGUN_OpenCloseGateValve -deviceList L1GV2 -value Open -group LinacValves
            if {$gun == "RG2"} {
                APSRFGUN_OpenCloseGateValve -deviceList 2 -value Open -group LinacRFGun
                APSRFGUN_OpenCloseGateValve -deviceList 1 -value Close -group LinacRFGun
            } else {
                APSRFGUN_OpenCloseGateValve -deviceList 2 -value Close -group LinacRFGun
                APSRFGUN_OpenCloseGateValve -deviceList 1 -value Open -group LinacRFGun
            }
        } result]} {
            if {[APSPEMTKDialog .warningDialog -text "Error while setting up the gate valves \n$result"] == 1} {
                APSMpReturn error "LPL_Configure: $result"
            }
        }
        
        if {$forceChangeGunOnly} {
            APSMpStep "Finished"
            APSMpReturn ok
        }


    }

    if {$RFGUN} {
        #RESTORE SOME PVS in case there was a GUN SWITCH or coming out of PG1 mode
        if {[string length $SCRFile]} {
            if {$startupPAR} {
                set tmpFile /tmp/[APSTmpString]
                if {$PARrfSystems} {
                    APSMpStep "Restoring SCR Values related to PAR RF timing" 
                    if {[catch {eval exec sddsprocess $SCRFile $tmpFile \
                                  -match=column,ControlName=PAR:LIST:PhsShft1Ch0_1,ControlName=PAR:RF12:PhsShft2Ch2_3AO,|,ControlName=PRF:Har:WT1:PulseDelayAO,|,ControlName=PRF:Har:WT1:PulseWidthAO,|,ControlName=PRF:Har:WT2:PulseDelayAO,|,ControlName=PRF:Har:WT2:PulseWidthAO,|,ControlName=P:DG1:aDelayAO,|,ControlName=P:DG1:cDelayAO,|
                        exec sddscasr -restore $tmpFile} result]} {
                        APSPEMTKDialog .warningDialog -strings Continue -default 0 -text "Problem restoring SCR file: LPL_Configure: $result"
                        catch {APSSendEMail -address soliday \
                                 -subject "Problem restoring SCR file."  \
                                 -message "Problem restore SCR file\nLPL_Configure\n$SCRFile\n$result"} 
                    }
                    file delete $tmpFile
                }
                if {$PARPulsedPS} {
                    APSMpStep "Restoring SCR Values related to PAR Pulsed PS timing" 
                    if {[catch {eval exec sddsprocess $SCRFile $tmpFile \
                                  -match=column,ControlName=It:LinacTrig2ParIpAO,ControlName=It:P1IKtrig2ParIpAO,|,ControlName=It:P2IKtrig2ParIpAO,|
                        exec sddscasr -restore $tmpFile} result]} {
                        APSPEMTKDialog .warningDialog -strings Continue -default 0 -text "Problem restoring SCR file: LPL_Configure: $result"
                        catch {APSSendEMail -address soliday \
                                 -subject "Problem restoring SCR file."  \
                                 -message "Problem restore SCR file\nLPL_Configure\n$SCRFile\n$result"} 
                    }
                    file delete $tmpFile
                }
                
                if {$bypass} {
                    set timingoption "-match=column,ControlName=It:L:B??_enb_bo*,! -match=column,ControlName=It:L:B??_rfenb_bo*,! -match=column,ControlName=It:L:seq_len_lo*,!"
                } else {
                    set timingoption ""
                }
                APSMpStep "Restoring PAR Timing Values" 
                if {[catch {eval exec sddsprocess $SCRFile $tmpFile -match=column,IsReadOnly=+n -match=column,IsProtected=+n -match=column,Category=Timing -match=column,Beamline=PAR -match=column,ControlName=It:LinacTrig2ParIpAO,! -match=column,ControlName=It:P1IKtrig2ParIpAO,! -match=column,ControlName=It:P2IKtrig2ParIpAO,!  $timingoption} result]} {
                    APSPEMTKDialog .warningDialog -strings Continue -default 0 -text "Problem restoring SCR file: LPL_Configure: $result"
                    catch {APSSendEMail -address soliday -subject "Problem restoring SCR file." -message "Problem restore SCR file\nLPL_Configure\n$SCRFile\n$result"} 
                }
                if {[catch {exec sddscasr -restore $tmpFile} result]} {
                    APSPEMTKDialog .warningDialog -strings Continue -default 0 -text "Problem restoring SCR file: LPL_Configure: $result"
                    catch {APSSendEMail -address soliday -subject "Problem restoring SCR file." -message "Problem restore SCR file\nLPL_Configure\n$SCRFile\n$result"} 
                }
                file delete $tmpFile
            }
        }

        if {0} {
            if {[catch {APScavget -list=LI:TM:rfGunConfigCC} result]} {
                APSMpReturn error "LPL_Configure: $result"
            }
            if {$result == 0} {
                APSMpStep "${prefix}Change Timing to RF-Gun" \
                  -desc "Change Timing to RF-Gun" -proc "RFGUN_ChangeTiming"
                if [catch {RFGUN_ChangeTiming -includePar 1 -bypassPar 0} result] {
                    if {[APSPEMTKDialog .warningDialog -text "Unable to change RFGUN timing\n$result"] == 1} {
                        APSMpReturn error "LPL_Configure: $result"
                }
                }
            }
        }
    }
    #APSMpReturn ok
    if {$changeBypassState} {
        APSMpStep "${prefix}Turn the kicker charge pulse off" -desc "Turn the kicker charge pulse off"
        if {[catch {APScavput -list=L1:RG1:KIK:chargeTrigC=0,L1:RG2:KIK:chargeTrigC=0 -num -pend=20} results]} {
            if {[APSPEMTKDialog .warningDialog -text "Error while turning the kicker charge pulse off \n$results"] == 1} {
                APSMpReturn error "LPL_Configure: $results"
            }
        }

        if {$bypass} {
            APSMpStep "${prefix}Turn Off Rf12" -desc "Turn Off Rf12" -proc "APSMpPARTurnOffRf12"
            if {[catch {APSMpPARTurnOffRf12} result]} {
                if {[APSPEMTKDialog .warningDialog -text "Unable to turn off the 12th harmonic RF system\n$result"] == 1} {
                    APSMpReturn error "LPL_Configure: Unable to turn off the 12th harmonic RF system: $result"
                }
            }
        }

        APSMpStep "${prefix}Suspend L${L1SectorSource} and L${L2SectorSource} Power Control Stabilizer" -desc "Suspend L1 and L2 power control stabilizers"
        if {[catch {APSLSuspendResumeRFPowerControllaws \
                      -klystronList "${L1SectorSource} ${L2SectorSource}" \
                      -mode suspend} result]} {
            if {[APSPEMTKDialog .warningDialog -text "Problem suspending the L${L1SectorSource} and L${L2SectorSource} power control stabilizers.\nLPL_Configure: $result"] == 1} {
                APSMpReturn error "Problem suspending the L${L1SectorSource} and L${L2SectorSource} power control stabilizers: LPL_Configure: $result"
            }
        }
        
        APSMpStep "${prefix}Suspend linac RF phase controllaw" -desc "Suspend linac RF phase controllaw"
        if {[catch {APScavput -list=L:BPD:RFGUN1:L1L2L4L5RC.SUSP=1,L:BPD:RFGUN2:L1L2L4L5RC.SUSP=1} result]} {
            if {[APSPEMTKDialog .warningDialog -text "Problem suspending the linac RF phase controllaw\nLPL_Configure: $result"] == 1} {
                APSMpReturn error "Problem suspending the linac RF phase controllaw: LPL_Configure: $result"
            }
        }
        if {[catch {APScavput -list=L:BPD:RFGUN1RC.ABRT=1,L:BPD:RFGUN2RC.ABRT=1,L:BPD:RFGUN2K1DnRC.ABRT=1,L:BPD:RFGUN2K2DnRC.ABRT=1,L:BPD:L3P3:L4AS1RC.ABRT=1,L:BPD:L4P1:L5AS1RC.ABRT=1} result]} {
            if {[APSPEMTKDialog .warningDialog -text "Problem suspending the linac RF phase controllaw\nLPL_Configure: $result"] == 1} {
                APSMpReturn error "Problem suspending the linac RF phase controllaw: LPL_Configure: $result"
            }
        }

        if {[catch {APSDevSend \
                      -group LinacKlystron \
                      -operation TurnOffLLRF \
                      -deviceList ${L1SectorSource}} result]} {
            if {[APSPEMTKDialog .warningDialog -text "Problem turning off L${L1SectorSource} LLRF.\nLPL_Configure: $result"] == 1} {
                APSMpReturn error "Problem turning off L${L1SectorSource} LLRF: LPL_Configure: $result"
            }
        }

        APSMpStep "${prefix}Switch the timing" -desc "Switch the timing"
        if {$bypass} {
            if {[catch {APScavput -list=It:ByPassParC=1 -num -pend=20} results]} {
                if {[APSPEMTKDialog .warningDialog -text "Unable to switch to Bypass Par.\nLPL_Configure: $results"] == 1} {
                    APSMpReturn error "Unable to switch to Bypass Par: LPL_Configure: $results"
                }
            }
        } else {
            if {[catch {APScavput -list=It:ByPassParC=0 -num -pend=20} results]} {
                if {[APSPEMTKDialog .warningDialog -text "Unable to switch to Include Par.\nLPL_Configure: $results"] == 1} {
                    APSMpReturn error "Unable to switch to Include Par: LPL_Configure: $results"
                }
            }
            #	    if {[catch {APSLINAC_SetBeamTriggerRate -state {{RFG 10hz}}} result]} {
            #                if {[APSPEMTKDialog .warningDialog -text "Unable to set beam trigger rate to RFG 10Hz.\nLPL_Configure: $result"] == 1} {
            #                    APSMpReturn error "Unable to set beam trigger rate to RFG 10Hz: LPL_Configure: $result"
            #                }
            #	    }
            APSWaitWithUpdate -waitSeconds 2
            catch {APScavput -list=It:L:B06_enb_bo.VAL=0,It:L:B08_enb_bo.VAL=0 -num -pend=20}
        }
        
        
        if {$bypass} {
            if {[catch {APSDevSend \
                          -group LinacPS \
                          -operation TurnOn \
                          -deviceList L5:AM1} result]} {
                if {[APSPEMTKDialog .warningDialog -text "Unable turn on L5:AM1.\nLPL_Configure: $result"] == 1} {
                    APSMpReturn error "Unable turn on L5:AM1: LPL_Configure: $result"
                }
            }
        }
    }

    if {$startupPAR} {
        if {$conditionPAR} {
            APSMpStep "${prefix}Start PAR" -desc "Start up PAR"
            set id7 [APSMpParallel -mode "Automatic" \
                       -procedure "APSMpPARStartUp -conditioningTime [expr {$cycles * 3.5}] -rf1amp $rf1amp -rf12amp $rf12amp -rfSystems $PARrfSystems -useSystemReference $parRFscr -PulsedPS 0 -restoreFile [file tail $SCRFile]"]
        } else {
            APSMpStep "PAR: Turn On DCPS" -proc APSMpPARTurnOnDCPS 
            if [catch APSMpPARTurnOnDCPS result] {
                if {[APSPEMTKDialog .warningDialog -text "Unable turn on PAR DCPS.\nLPL_Configure: $result"] == 1} {
                    APSMpReturn error "Unable turn on PAR DCPS: LPL_Configure: $result"
                }
            }
            APSMpStep "${prefix}Start PAR" -desc "Start up PAR"
            set id7 [APSMpParallel -mode "Automatic" \
                       -procedure "APSMpPARStartUp -rf1amp $rf1amp -rf12amp $rf12amp -rfSystems $PARrfSystems -useSystemReference $parRFscr -PulsedPS 0 -restoreFile [file tail $SCRFile] -DCPS 0"]
        }
    }

    if {$RFGUN} {
        APSMpStep "${prefix}Open gate valves" -desc "Open the gate valves"
        if {[catch {
            APSRFGUN_OpenCloseGateValve -deviceList "L2GV1 L3GV1 L4GV1 L5GV1" -value Open -group LinacValves
        } result]} {
            if {[APSPEMTKDialog .warningDialog -text "Unable open gate valves.\nLPL_Configure: $result"] == 1} {
                APSMpReturn error "Unable open gate valves: LPL_Configure: $result"
            }
        }
    }
    
    if {$Modulators} {
        set LMOCS_Selected 0
        foreach sector $sectors {
            if {[set $sector]} {
                set LMOCS_Selected 1
            }
        }
        if {$LMOCS_Selected} {
            if {[set L${L1SectorSource}]} {
                if {!$changeMode} {
                    APSMpStep "${prefix}Set cathode heater to standby current" -desc "Set cathode heater to standby current"
                    if {[catch {exec cavget -list=L1:RG${deviceList}:HTR:VoltageAO} cathodeHeaterVoltageValue]} {
                        set cathodeHeaterVoltageValue 0
                    }
                    if {$deviceList == 1} {
                        if {$cathodeHeaterVoltageValue < 4.1} {
                            if {[catch {APSRFGUN_SetCathodeHeaterStandbyCurrent -value 4.1 -deviceList $deviceList} result]} {
                                if {[APSPEMTKDialog .warningDialog -text "Unable to set cathode heater to standby current\n$result"] == 1} {
                                    APSMpReturn error "LPL_Configure: $result"
                                }
                            }
                        }
                    } else {
                        if {$cathodeHeaterVoltageValue < 3.1} {
                            if {[catch {APSRFGUN_SetCathodeHeaterStandbyCurrent -value 3.1 -deviceList $deviceList} result]} {
                                if {[APSPEMTKDialog .warningDialog -text "Unable to set cathode heater to standby current\n$result"] == 1} {
                                    APSMpReturn error "LPL_Configure: $result"
                                }
                            }
                        }
                    }
                }
            }

            APSMpStep "${prefix}Start up Modulators" -desc "Start up Modulators" -proc LMOCS_Modulator_Startup


            set id3 [APSMpParallel \
                       -procedure "LMOCS_Modulator_Startup -L1 $L1 -L2 $L2 -L3 $L3 -L4 $L4 -L5 $L5 -SCRFile $SCRFile" \
                       -mode "Automatic"]
            
            if {[catch {APSMpJoin $id3} results]} {
                if {[APSPEMTKDialog .warningDialog -text "Problem occured in modulator startup\nLPL_Configure: $results"] == 1} {
                    APSMpReturn error "LPL_Configure: $results"
                }
            }
        }

        foreach sector $sectors {
            if {[set $sector]} {
                set device [string range $sector 1 1]
                if {$device == 2} {
                } else {
                    APSMpStep "${prefix}Check if 400 watt amp is on" -desc "Check 400 watt amp"
                    if {[catch {APSDevSend \
                                  -group LinacKlystron \
                                  -operation QueryACISPermit400WAmp \
                                  -deviceList $device} permit]} {
                        APSMpReturn error "LPL_Configure: $permit"
                    }
                    if {[catch {APSDevSend \
                                  -group LinacKlystron \
                                  -operation QueryACISLatch400WAmp \
                                  -deviceList $device} latch]} {
                        APSMpReturn error "LPL_Configure: $latch"
                    }
                    if {(!$permit) || (!$latch)} {
                        if {[catch {APSDevSend \
                                      -group LinacKlystron \
                                      -operation ResetACIS400WAmp \
                                      -deviceList $device -releaseLinks 1} result]} {
                            APSMpReturn error "LPL_Configure: $result"
                        }
                        APSWaitWithUpdate -waitSeconds 2
                    }
                    if {[catch {APSDevSend \
                                  -group LinacKlystron \
                                  -operation Query400WAmpOn \
                                  -deviceList $device} result]} {
                        APSMpReturn error "LPL_Configure: $result"
                    }
                    if {!$result} {
                        APSMpStep "${prefix}Turn 400W RF Amp On" -desc "Reset 400 watt amp if needed"
                        if {[catch {APSDevSend \
                                      -group LinacKlystron \
                                      -operation Reset400WAmp \
                                      -deviceList $device -releaseLinks 1} result]} {
                            APSMpReturn error "LPL_Configure: $result"
                        }
                    }
                }
            }
        }
    }
    
    if {$RFGUN} {
        set options "-gun $gun "
        if {[llength $CathodeHeaterSetpoint]} { append options "-CathodeHeaterSetpoint $CathodeHeaterSetpoint " }
        if {[llength $CathodeHeaterWatts]} { append options "-CathodeHeaterWatts $CathodeHeaterWatts " }
        if {[llength $KLYFwdPwr]} { append options "-KLYFwdPwr $KLYFwdPwr " }
        if {[llength $KickerSetpoint]} { append options "-KickerSetpoint $KickerSetpoint " }
        if {$Modulators} {
            set resumeRFPowerControlLaws 0
            set skipLLRFChecks 1
        } else {
            set resumeRFPowerControlLaws 1
            set skipLLRFChecks 0
        }

        if {[catch {eval RFGUN_Startup $options -SCRFile $SCRFile -resumeSmartMonitor $resumeSmartMonitor -bypassMode $bypass -changeBypassState $changeBypassState -changeMode $changeMode -Modulators $Modulators -L1 $L1 -L2 $L2 -L3 $L3 -L4 $L4 -L5 $L5 -resumeRFPowerControlLaws $resumeRFPowerControlLaws -skipLLRFChecks $skipLLRFChecks} results]} {
            if {[APSPEMTKDialog .warningDialog -text "Problem occured in rfgun startup\nLPL_Configure: $results"] == 1} {
                APSMpReturn error "LPL_Configure: $results"
            }
        }
    }
    
    if {$Modulators} {

        #set resumeList ""
        #foreach sector $sectors num "1 2 3 4 5" {
        #    if {[set $sector]} {
        #        lappend resumeList $num
        #    }
        #}
        #if {[llength $resumeList]} {
        #    APSMpStep "Resume RF power controllaws"
        #    if {[catch {APSLSuspendResumeRFPowerControllaws -klystronList $resumeList -mode resume} result]} {
        #        APSMpReturn error "LPL_Configure: $result"
        #    }
        #}
        if {[catch {LMOCS_ResetAutoPhaseControl -SCRFile $SCRFile -L1 $L1 -L2 $L2 -L3 $L3 -L4 $L4 -L5 $L5} result]} {
            if {[APSPEMTKDialog .warningDialog -text "Unable to reset modulator phase controls\nLPL_Configure: $result"] == 1} {
                APSMpReturn error "Unable to reset modulator phase controls: LPL_Configure: $results"
            }
        }
        #APSMpStep "Wait for RF power errors to minimize" -proc LINAC_WaitForPowerControls
        #if {[catch {LINAC_WaitForPowerControls -L1 $L1 -L2 $L2 -L3 $L3 -L4 $L4 -L5 $L5} results]} {
        #    if {[APSPEMTKDialog .warningDialog -text "LPL_Configure: $results"] == 1} {
        #        APSMpReturn error "LPL_Configure: $results"
        #    }
        #}
        #if {[catch {LMOCS_PowerControlLawSetup -deviceList "L1 L2 L3 L4 L5" -mode low} result]} {
        #    if {[APSPEMTKDialog .warningDialog -text "Error while setting L1 L2 L3 L4 L5 power controllaws into low mode \n$result"] == 1} {
        #        APSMpReturn error "LPL_Configure: $result"
        #    }
        #}

        #APSMpStep "${prefix}Suspend selected power controls" -desc "Suspend selected power controls"
        #set suspendList ""
        #set resumeList ""
        #foreach sector $sectors num "1 2 3 4 5" {
        #    if {[set suspend$sector]} {
        #        lappend suspendList $num
        #    } elseif {[set $sector]} {
        #        lappend resumeList $num
        #    }
        #}
        #if {[llength $suspendList]} {
        #    if {[catch {APSLSuspendResumeRFPowerControllaws -klystronList $suspendList -mode suspend} result]} {
        #        APSMpReturn error "LPL_Configure: $result"
        #    }
        #}
        #if {[llength $resumeList]} {
        #    if {[catch {APSLSuspendResumeRFPowerControllaws -klystronList $resumeList -mode resume} result]} {
        #        APSMpReturn error "LPL_Configure: $result"
        #    }
        #}
        if {$abortControllaw} {
            if {!$RFGUN} {
                if {[catch {RestartLinacRFPhaseControllaw -SCRFile $SCRFile} result]} {
                    if {[APSPEMTKDialog .warningDialog -text "Error while restarting Linac RF Phase controllaw \n$result"] == 1} {
                        APSMpReturn error "LPL_Configure: $result"
                    }
                }
            }
        }
    }
    if {$PowerSupplies} {
        APSMpStep "${prefix}Waiting for Linac PS to finish conditioning" -desc "Waiting for Linac PS to finish conditioning"
        if {[catch {APSMpJoin $id1} results]} {
            if {[APSPEMTKDialog .warningDialog -text "Problem occured in power supply startup\nLPL_Configure: $results"] == 1} {
                APSMpReturn error "LPL_Configure: $results"
            }
        }
    }
    if {$startupLTP} {
        APSMpStep "${prefix}Waiting for LTP PS to finish conditioning" -desc "Waiting for LTP PS to finish conditioning"
        if {[catch {APSMpJoin $id4} results]} {
            if {[APSPEMTKDialog .warningDialog -text "Problem occured in LTP startup\nLPL_Configure: $results"] == 1} {
                APSMpReturn error "LPL_Configure: $results"
            }
        }
    }
    if {$startupPTB} {
        APSMpStep "${prefix}Waiting for PTB PS to finish conditioning" -desc "Waiting for PTB PS to finish conditioning"
        if {[catch {APSMpJoin $id5} results]} {
            if {[APSPEMTKDialog .warningDialog -text "Problem occured in PTB startup\nLPL_Configure: $results"] == 1} {
                APSMpReturn error "LPL_Configure: $results"
            }
        }
    }
    if {$startupPARBypass} {
        APSMpStep "${prefix}Waiting for PAR Bypass PS to finish conditioning" -desc "Waiting for PAR Bypass PS to finish conditioning"
        if {[catch {APSMpJoin $id6} results]} {
            if {[APSPEMTKDialog .warningDialog -text "Problem occured in PAR Bypass PS startup\nLPL_Configure: $results"] == 1} {
                APSMpReturn error "LPL_Configure: $results"
            }
        }
    }
    if {$startupPAR} {
        APSMpStep "${prefix}Waiting for PAR PS to finish conditioning" -desc "Waiting for PAR PS to finish conditioning"
        if {[catch {APSMpJoin $id7} results]} {
            if {[APSPEMTKDialog .warningDialog -text "Problem occured in PAR PS startup\nLPL_Configure: $results"] == 1} {
                APSMpReturn error "LPL_Configure: $results"
            }
        }
        if {$PARPulsedPS} {
            if {[catch {APSMpJoin $parpps} results]} {
                if {[APSPEMTKDialog .warningDialog -text "Problem occured in PAR kicker warmup\nLPL_Configure: $results"] == 1} {
                    APSMpReturn error "LPL_Configure: $results"
                }
            }
        }
    }

    if {$bypass} {
        APSMpStep "Check that the linac-to-LEUTL (double stop) is open"
        if [catch {APScavget -list=ACIS:LAO_LTB_2S_CLSD -num} result] {
            APSMpReturn error "LPL_Configure: $result"
        }
        if {$result != 0} {
            if {[APSPEMTKDialog .warningDialog -text "The Linac to LEUTL double stop is not open."] == 1} {
                APSMpReturn error "LPL_Configure: the Linac to LEUTL double stop is not open"
            }
        }
        
        set failed 1
        set step 0
        while {$failed} {
            APSMpStep "Turn off LTP and PTB dipoles"
            incr step
            if {$step > 4} {
                if {[APSPEMTKDialog .warningDialog -text "Unable to turn off LTP and PTB dipoles."] == 1} {
                    APSMpReturn error "LPL_Configure: Unable to turn off LTP and PTB dipoles"
                }
                break
            }
            if [catch {APSDevSend \
                         -releaseLinks 1 \
                         -group LTPToEndPSOps \
                         -operation SetCurrent \
                         -deviceList {"LTP:B1" "PTB:B1"} \
                         -valueList {0 0} \
                         -timeout 0} result] {
                APSMpReturn error "LPL_Configure: $result"
            }
            if [catch {APSDevSend \
                         -releaseLinks 1 \
                         -group LTPToEndPSOps \
                         -operation TurnOff \
                         -deviceList {"LTP:B1" "PTB:B1"} \
                         -timeout 0} result] {
                APSMpReturn error "LPL_Configure: $result"
            }
            APSWaitWithUpdate -waitSeconds 5
            if [catch {APSDevSend \
                         -releaseLinks 1 \
                         -group LTPToEndPSOps \
                         -operation QueryOn \
                         -deviceList {"LTP:B1" "PTB:B1"}} results] {
                APSMpReturn error "LPL_Configure: $results"
            }
            set failed 0
            foreach result $results {
                if {$result} {
                    set failed 1
                    break
                }
            }
        }
        APSMpStep "Restoring Booster SCR Values"
        set tmpFile /tmp/[APSTmpString]
        if {$bypassEnergy == 400} {
            set boosterSCRFile "/home/helios/oagData/SCR/snapshots/Booster/Booster-LowE2ReferenceDirInj400.gz"
        } elseif {$bypassEnergy == 425} {
            set boosterSCRFile "/home/helios/oagData/SCR/snapshots/Booster/Booster-LowE2ReferenceDirInj425.gz"
        } elseif {$bypassEnergy == 450} {
            set boosterSCRFile "/home/helios/oagData/SCR/snapshots/Booster/Booster-LowE2ReferenceDirInj450.gz"
        } else {
            if {[APSPEMTKDialog .warningDialog -text "Cannot restore Booster SCR file"] == 1} {
                APSMpReturn error "Cannot restore Booster SCR file"
            }
        }

        if {[catch {eval exec sddsprocess $boosterSCRFile $tmpFile \
                      -match=column,IsReadOnly=+n \
                      -match=column,IsProtected=+n \
                      -match=column,OpsIntervention=+n \
                      -match=column,Category=AFG,Category=BPM,|,Category=Bcontrol,|,Category=Diag,|,Category=ExtPulsedPS,|,Category=ExtTiming,|,Category=GlobalParameter,|,Category=InjPulsedPS,|,Category=InjTiming,|,Category=MainPS,|,Category=Readback,|,Category=Scrapers,|,Category=Setpoint,|,Category=Status,|,Category=SteeringPS,|,Category=SteeringSetpoint,|,Category=Timing,|,Category=TuneMeas,| \
                      -match=column,Beamline=BTS,Beamline=Booster,| \
                      -match=col,ControlType=,! -match=col,ControlName=,! 
            exec sddscasr -restore $tmpFile} result]} {
            APSPEMTKDialog .warningDialog -strings Continue -default 0 -text "Problem restoring SCR file: LPL_Configure: $result"
            catch {APSSendEMail -address soliday \
                     -subject "Problem restoring SCR file."  \
                     -message "Problem restore SCR file\nLPL_Configure\n$SCRFile\n$result"} 
        }
        file delete $tmpFile
    } else {
        if {$restoreBooster} {
            APSMpStep "Restoring Booster SCR Values"
            set tmpFile /tmp/[APSTmpString]
            
            if {[catch {eval exec sddsprocess $boosterSCRFile $tmpFile \
                          -match=column,IsReadOnly=+n \
                          -match=column,IsProtected=+n \
                          -match=column,OpsIntervention=+n \
                          -match=column,Category=AFG,Category=BPM,|,Category=Bcontrol,|,Category=Diag,|,Category=ExtPulsedPS,|,Category=ExtTiming,|,Category=GlobalParameter,|,Category=InjPulsedPS,|,Category=InjTiming,|,Category=MainPS,|,Category=Readback,|,Category=Scrapers,|,Category=Setpoint,|,Category=Status,|,Category=SteeringPS,|,Category=SteeringSetpoint,|,Category=Timing,|,Category=TuneMeas,| \
                          -match=column,Beamline=BTS,Beamline=Booster,| \
                          -match=col,ControlType=,! -match=col,ControlName=,! 
                exec sddscasr -restore $tmpFile} result]} {
                APSPEMTKDialog .warningDialog -strings Continue -default 0 -text "Problem restoring SCR file: LPL_Configure: $result"
                catch {APSSendEMail -address soliday \
                         -subject "Problem restoring SCR file."  \
                         -message "Problem restore SCR file\nLPL_Configure\n$SCRFile\n$result"} 
            }
            file delete $tmpFile
        }
    }
    
    if {$bypass} {
        APSMpStep "${prefix}Resume X Booster Direct Injection ControlLaw" -desc "Resume X Booster Direct Injection ControlLaw"
        if {[catch {APScavput -list=BoosterDirInj:ControlLawXRC.SUSP=0 -pend=20} result]} {
            if {[APSPEMTKDialog .warningDialog -text "Unable to resume X Booster Direct Injection controllaw\n$result"] == 1} {
                APSMpReturn error "LPL_Configure: $result"
            }
        }
        APSMpStep "${prefix}Resume Y Booster Direct Injection ControlLaw" -desc "Resume Y Booster Direct Injection ControlLaw"
        if {[catch {APScavput -list=BoosterDirInj:ControlLawYRC.SUSP=0 -pend=20} result]} {
            if {[APSPEMTKDialog .warningDialog -text "Unable to resume Y Booster Direct Injection controllaw\n$result"] == 1} {
                APSMpReturn error "LPL_Configure: $result"
            }
        }
        after 3000
        if {[catch [APScavget -noquote -list=BoosterDirInj:ControlLawXRC.PID] result]} {
        } else {
            if {[llength $result] != 1} {
                if {[APSPEMTKDialog .warningDialog -text "Unable to start X Booster Direct Injection controllaw"] == 1} {
                    APSMpReturn error "LPL_Configure: Unable to start X Booster Direct Injection controllaw"
                }
            }
        }
        if {[catch [APScavget -noquote -list=BoosterDirInj:ControlLawYRC.PID] result]} {
        } else {
            if {[llength $result] != 1} {
                if {[APSPEMTKDialog .warningDialog -text "Unable to start Y Booster Direct Injection controllaw"] == 1} {
                    APSMpReturn error "LPL_Configure: Unable to start Y Booster Direct Injection controllaw"
                }
            }
        }
    } else {
        if {($L4) || ($L5)} {
            APSMpStep "${prefix}Resume X LTP ControlLaw" -desc "Resume X LTP ControlLaw"
            if [catch {APSMpLSuspendResumeRunControl \
                         -value "Resume" \
                         -name "LTPControlLaw" \
                         -group "RunControlGroup" \
                         -deviceList X} result] {
                if {[APSPEMTKDialog .warningDialog -text "Unable to resume X LTP controllaw\n$result"] == 1} {
                    APSMpReturn error "LPL_Configure: $result"
                }
            }
            APSMpStep "${prefix}Resume Y LTP ControlLaw" -desc "Resume Y LTP ControlLaw"
            if [catch {APSMpLSuspendResumeRunControl \
                         -value "Resume" \
                         -name "LTPControlLaw" \
                         -group "RunControlGroup" \
                         -deviceList Y} result] {
                if {[APSPEMTKDialog .warningDialog -text "Unable to resume Y LTP controllaw\n$result"] == 1} {
                    APSMpReturn error "LPL_Configure: $result"
                }
            }
            APSMpStep "${prefix}Resume X PTB ControlLaw" -desc "Resume X PTB ControlLaw"
            if {[catch {APScavput -list=PTB:ControlLawXRC.SUSP=0 -pend=20} result]} {
                if {[APSPEMTKDialog .warningDialog -text "Unable to resume X PTB controllaw\n$result"] == 1} {
                    APSMpReturn error "LPL_Configure: $result"
                }
            }
            after 3000
            if {[catch [APScavget -noquote -list=LTP:ControlLawXRC.PID] result]} {
            } else {
                if {[llength $result] != 1} {
                    if {[APSPEMTKDialog .warningDialog -text "Unable to start X LTP controllaw"] == 1} {
                        APSMpReturn error "LPL_Configure: Unable to start X LTP controllaw"
                    }
                }
            }
            if {[catch [APScavget -noquote -list=LTP:ControlLawYRC.PID] result]} {
            } else {
                if {[llength $result] != 1} {
                    if {[APSPEMTKDialog .warningDialog -text "Unable to start Y LTP controllaw"] == 1} {
                        APSMpReturn error "LPL_Configure: Unable to start Y LTP controllaw"
                    }
                }
            }
            if {[catch [APScavget -noquote -list=PTB:ControlLawXRC.PID] result]} {
            } else {
                if {[llength $result] != 1} {
                    if {[APSPEMTKDialog .warningDialog -text "Unable to start X PTB controllaw"] == 1} {
                        APSMpReturn error "LPL_Configure: Unable to start X PTB controllaw"
                    }
                }
            }
        }
    }


    APSMpReturn ok
}

proc LPL_ConfigurePackProc {frame} {
    global LPL_Configure APSMpLControlPS apsInitialGunSelection
    #    set APSMpLControlPS(TurnOn,L1:PG1:SC) 1

    set apsInitialGunSelection $LPL_Configure(gun)

    pack [frame $frame.top]
    pack [frame $frame.top.left] -side left -anchor n
    pack [frame $frame.top.right] -side right -anchor n -padx 10

    pack [frame $frame.top.left.mode]

    radiobutton $frame.top.left.mode.startup \
      -text STARTUP \
      -indicatoron n \
      -variable LPL_Configure(mode) \
      -value startup \
      -command "$frame.top.left.startup configure -text Startup ; \
              pack forget $frame.fTurnOff ; \
              pack forget $frame.top.left.startup.ltp.dcps ; \
              pack forget $frame.top.left.startup.ltp.ramped ; \
              pack forget $frame.top.left.startup.ltp.h ; \
              pack forget $frame.top.left.startup.ltp.v ; \
              pack forget $frame.top.left.startup.ltp.q ; \
              pack forget $frame.top.left.startup.ltp.b1 ; \
              pack forget $frame.top.left.startup.par.dcps ; \
              pack forget $frame.top.left.startup.par.bm ; \
              pack forget $frame.top.left.startup.par.ramped ; \
              pack forget $frame.top.left.startup.ptb.dcps ; \
              pack forget $frame.top.left.startup.ptb.ramped ; \
              pack forget $frame.top.left.startup.parbypass.dcps ; \
              pack forget $frame.top.left.startup.parbypass.h ; \
              pack forget $frame.top.left.startup.parbypass.v ; \
              pack forget $frame.top.left.startup.parbypass.q ; \
              pack forget $frame.top.left.startup.mod.filament ; \
              pack forget $frame.scr ; \
              pack $frame.fStartConditioning -after $frame.top ; \
              pack $frame.fTurnOn -after $frame.top ; \
              pack $frame.top.left.startup.rg -fill x -padx 20 -after $frame.top.left.startup.rfgun ; \
              pack $frame.top.left.startup.mod3 -fill x -padx 20 -after $frame.top.left.startup.mod ; \
              pack $frame.top.left.startup.ltp.condition -side left -after $frame.top.left.startup.ltp.turnon ; \
              pack $frame.top.left.startup.ltp.conditionB1 -side left -after $frame.top.left.startup.ltp.condition ; \
              pack $frame.top.left.startup.par.condition -side left -after $frame.top.left.startup.par.turnon ; \
              pack $frame.top.left.startup.ptb.condition -side left -after $frame.top.left.startup.ptb.turnon ; \
              pack $frame.top.left.startup.parbypass.condition -side left -after $frame.top.left.startup.parbypass.turnon ; \
              pack $frame.top.right.ibpar -anchor nw -pady 5 ; \
              pack $frame.top.right.par -anchor nw -pady 5 ; \
              pack $frame.top.right.par.par1 -anchor nw -pady 5 -side left ; \
              pack $frame.top.right.par.par12 -anchor nw -pady 5 -side left ; \
              pack $frame.top.right.parSCR -anchor nw -pady 5 ; \
              pack $frame.scr ; \
              if !\[string compare \$LPL_Configure(gun) {RG1}\] \" \
                $frame.top.left.startup.rg.rg1 invoke \
              \" else \" \
                $frame.top.left.startup.rg.rg2 invoke \
              \" ; \
                set APSMpLControlPS(StartConditioning,L1:H) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L1:H1) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L1:H2) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L1:H3) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L1:H4) 1 ; \
                set APSMpLControlPS(StartConditioning,L1:V) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L1:V1) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L1:V2) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L1:V3) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L1:V4) 1 ; \
                set APSMpLControlPS(StartConditioning,L1:Q) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L1:Q1) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L1:Q2) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L1:Q3) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L1:Q4) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L1:Q5) 1 ; \
                set APSMpLControlPS(StartConditioning,L2:SC) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L2:SC1:HZ) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L2:SC1:VL) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L2:SC2:HZ) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L2:SC2:VL) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L2:SC3:HZ) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L2:SC3:VL) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L2:SC4:HZ) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L2:SC4:VL) 1 ; \
                set APSMpLControlPS(StartConditioning,L2:QM) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L2:QM1) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L2:QM2) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L2:QM3) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L2:QM4) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L2:QM5) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L2:QM6) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L2:QM7) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L2:QM8) 1 ; \
                set APSMpLControlPS(StartConditioning,L3:CHICANE) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L3:QM1) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L3:QM2) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L3:BM1) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L3:BM2) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L3:BM3) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L3:BM4) 1 ; \
                set APSMpLControlPS(StartConditioning,L3:MATCHING) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L3:SC1:HZ) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L3:SC1:VL) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L3:SC2:HZ) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L3:SC2:VL) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L3:QM3) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L3:QM4) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L3:QM5) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L3:QM6) 1 ; \
                set APSMpLControlPS(StartConditioning,L3:AM1T) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L3:AM1T) 1 ; \
                set APSMpLControlPS(StartConditioning,L4:SC) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L4:SC1:HZ) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L4:SC1:VL) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L4:SC2:HZ) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L4:SC2:VL) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L4:SC3:HZ) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L4:SC3:VL) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L4:SC4:HZ) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L4:SC4:VL) 1 ; \
                set APSMpLControlPS(StartConditioning,L4:QM) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L4:QM1) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L4:QM2) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L4:QM3) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L4:QM4) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L4:QM5) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L4:QM6) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L4:QM7) 1 ; \
                set APSMpLControlPS(StartConditioning,L5:SC) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L5:SC1:HZ) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L5:SC1:VL) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L5:SC2:HZ) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L5:SC2:VL) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L5:SC3:HZ) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L5:SC3:VL) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L5:SC4:HZ) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L5:SC4:VL) 1 ; \
                set APSMpLControlPS(StartConditioning,L5:QM) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L5:QM1) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L5:QM2) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L5:QM3) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L5:QM4) 1 ; \
                set APSMpLControlPS(StartConditioning,L5:AM) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L5:AM1) 1 ; \
                if !\[string compare \$LPL_Configure(L6) {1}\] \" \
                    $frame.top.left.startup.mod.k6 invoke \
                \" ; \
                $frame.top.left.startup.mod.k6 configure -state disable"

    radiobutton $frame.top.left.mode.shutdown \
      -text SHUTDOWN \
      -indicatoron n \
      -variable LPL_Configure(mode) \
      -value shutdown \
      -command "$frame.top.left.startup configure -text Shutdown ; \
                pack forget $frame.fTurnOn ; \
                pack forget $frame.fStartConditioning ; \
                pack $frame.fTurnOff -after $frame.top ; \
                pack forget $frame.top.left.startup.rg ; \
                pack forget $frame.top.left.startup.mod3 ; \
                pack forget $frame.top.left.startup.ltp.condition ; \
                pack forget $frame.top.left.startup.ltp.conditionB1 ; \
                pack forget $frame.top.left.startup.par.condition ; \
                pack forget $frame.top.left.startup.ptb.condition ; \
                pack forget $frame.top.left.startup.parbypass.condition ; \
                pack forget $frame.top.right.ibpar ; \
                pack forget $frame.top.right.par.par1 ; \
                pack forget $frame.top.right.par.par12 ; \
                pack forget $frame.top.right.par ; \
                pack forget $frame.top.right.parSCR ; \
                pack $frame.top.left.startup.mod.filament -side left ; \
                pack forget $frame.scr ; \
                pack $frame.top.left.startup.ltp.dcps -side left -after $frame.top.left.startup.ltp.turnon ; \
                pack $frame.top.left.startup.ltp.ramped -side left -after $frame.top.left.startup.ltp.dcps ; \
                pack $frame.top.left.startup.ltp.h -side left -after $frame.top.left.startup.ltp.ramped ; \
                pack $frame.top.left.startup.ltp.v -side left -after $frame.top.left.startup.ltp.h ; \
                pack $frame.top.left.startup.ltp.q -side left -after $frame.top.left.startup.ltp.v ; \
                pack $frame.top.left.startup.ltp.b1 -side left -after $frame.top.left.startup.ltp.q ; \
                pack $frame.top.left.startup.par.dcps -side left -after $frame.top.left.startup.par.turnon ; \
                pack $frame.top.left.startup.par.bm -side left -after $frame.top.left.startup.par.dcps ; \
                pack $frame.top.left.startup.par.ramped -side left -after $frame.top.left.startup.par.bm ; \
                pack $frame.top.left.startup.ptb.dcps -side left -after $frame.top.left.startup.ptb.turnon ; \
                pack $frame.top.left.startup.ptb.ramped -side left -after $frame.top.left.startup.ptb.dcps ; \
                pack $frame.top.left.startup.parbypass.dcps -side left -after $frame.top.left.startup.parbypass.turnon ; \
                pack $frame.top.left.startup.parbypass.h -side left -after $frame.top.left.startup.parbypass.dcps ; \
                pack $frame.top.left.startup.parbypass.v -side left -after $frame.top.left.startup.parbypass.h ; \
                pack $frame.top.left.startup.parbypass.q -side left -after $frame.top.left.startup.parbypass.v ; \
                set APSMpLControlPS(StartConditioning,L1:RG1:H) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L1:RG1:H1) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L1:RG1:H2) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L1:RG1:H3) 0 ; \
                set APSMpLControlPS(StartConditioning,L1:RG1:V) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L1:RG1:V1) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L1:RG1:V2) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L1:RG1:V3) 0 ; \
                set APSMpLControlPS(StartConditioning,L1:RG1:Q) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L1:RG1:Q1) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L1:RG1:Q2) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L1:RG1:Q3) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L1:RG1:Q4) 0 ; \
                set APSMpLControlPS(StartConditioning,L1:RG1:LFA) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L1:RG1:LFA) 0 ; \
                set APSMpLControlPS(StartConditioning,L1:RG2:LFA:TRM) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L1:RG2:LFA:TRM) 0 ; \
                set APSMpLControlPS(StartConditioning,L1:RG2:H) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L1:RG2:H2) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L1:RG2:H3) 0 ; \
                set APSMpLControlPS(StartConditioning,L1:RG2:V) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L1:RG2:V1) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L1:RG2:V2) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L1:RG2:V3) 0 ; \
                set APSMpLControlPS(StartConditioning,L1:RG2:Q) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L1:RG2:Q1) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L1:RG2:Q2) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L1:RG2:Q3) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L1:RG2:Q4) 0 ; \
                set APSMpLControlPS(StartConditioning,L1:RG2:LFA) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L1:RG2:LFA) 0 ; \
                set APSMpLControlPS(StartConditioning,L1:H) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L1:H1) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L1:H2) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L1:H3) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L1:H4) 0 ; \
                set APSMpLControlPS(StartConditioning,L1:V) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L1:V1) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L1:V2) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L1:V3) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L1:V4) 0 ; \
                set APSMpLControlPS(StartConditioning,L1:Q) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L1:Q1) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L1:Q2) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L1:Q3) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L1:Q4) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L1:Q5) 0 ; \
                set APSMpLControlPS(StartConditioning,L2:SC) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L2:SC1:HZ) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L2:SC1:VL) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L2:SC2:HZ) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L2:SC2:VL) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L2:SC3:HZ) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L2:SC3:VL) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L2:SC4:HZ) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L2:SC4:VL) 0 ; \
                set APSMpLControlPS(StartConditioning,L2:QM) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L2:QM1) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L2:QM2) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L2:QM3) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L2:QM4) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L2:QM5) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L2:QM6) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L2:QM7) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L2:QM8) 0 ; \
                set APSMpLControlPS(StartConditioning,L3:CHICANE) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L3:QM1) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L3:QM2) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L3:BM1) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L3:BM2) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L3:BM3) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L3:BM4) 0 ; \
                set APSMpLControlPS(StartConditioning,L3:MATCHING) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L3:SC1:HZ) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L3:SC1:VL) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L3:SC2:HZ) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L3:SC2:VL) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L3:QM3) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L3:QM4) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L3:QM5) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L3:QM6) 0 ; \
                set APSMpLControlPS(StartConditioning,L3:AM1T) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L3:AM1T) 0 ; \
                set APSMpLControlPS(StartConditioning,L4:SC) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L4:SC1:HZ) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L4:SC1:VL) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L4:SC2:HZ) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L4:SC2:VL) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L4:SC3:HZ) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L4:SC3:VL) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L4:SC4:HZ) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L4:SC4:VL) 0 ; \
                set APSMpLControlPS(StartConditioning,L4:QM) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L4:QM1) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L4:QM2) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L4:QM3) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L4:QM4) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L4:QM5) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L4:QM6) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L4:QM7) 0 ; \
                set APSMpLControlPS(StartConditioning,L5:SC) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L5:SC1:HZ) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L5:SC1:VL) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L5:SC2:HZ) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L5:SC2:VL) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L5:SC3:HZ) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L5:SC3:VL) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L5:SC4:HZ) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L5:SC4:VL) 0 ; \
                set APSMpLControlPS(StartConditioning,L5:QM) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L5:QM1) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L5:QM2) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L5:QM3) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L5:QM4) 0 ; \
                set APSMpLControlPS(StartConditioning,L5:AM) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L5:AM1) 0 ; \
                if !\$LPL_Configure(L3) \" \
                   $frame.top.left.startup.mod.k3 invoke ; \
                \" ; \
                if \$LPL_Configure(RFGUN) \" \
                   $frame.top.left.startup.rfgun invoke \
                \" ; \
                if \$LPL_Configure(PowerSupplies) \" \
                   $frame.top.left.startup.powersupplies invoke \
                \" ; \
                if \$LPL_Configure(Modulators) \" \
                   $frame.top.left.startup.modulators invoke \
                \" ; \
                if \$LPL_Configure(startupLTP) \" \
                   $frame.top.left.startup.ltp.turnon invoke \
                \" ; \
                if \$LPL_Configure(startupPAR) \" \
                   $frame.top.left.startup.par.turnon invoke \
                \" ; \
                if \$LPL_Configure(startupPTB) \" \
                   $frame.top.left.startup.ptb.turnon invoke \
                \" ; \
                if \$LPL_Configure(startupPARBypass) \" \
                   $frame.top.left.startup.parbypass.turnon invoke \
                \""

    pack $frame.top.left.mode.startup -side left
    pack $frame.top.left.mode.shutdown -side left

    # Startup frame
    labelframe $frame.top.left.startup -text Startup
    pack $frame.top.left.startup -pady 5

    checkbutton $frame.top.left.startup.rfgun \
      -text "RFGUN (including the supplying rf)" -variable LPL_Configure(RFGUN) -anchor w \
      -command "if !\$LPL_Configure(RFGUN) \" \
                    $frame.top.left.startup.rg.rg1 configure -state disable ; \
                    $frame.top.left.startup.rg.rg2 configure -state disable \
                \" else \"
                    $frame.top.left.startup.rg.rg1 configure -state normal ; \
                    $frame.top.left.startup.rg.rg2 configure -state normal \
                \""
    pack $frame.top.left.startup.rfgun -fill x

    frame $frame.top.left.startup.rg
    pack $frame.top.left.startup.rg -fill x -padx 20
    radiobutton $frame.top.left.startup.rg.rg1 \
      -text "RG1" -variable LPL_Configure(gun) -value "RG1" \
      -command "set APSMpLControlPS(TurnOn,L1:RG1:H) 1 ; \
                set APSMpLControlPS(TurnOnDetailed,L1:RG1:H1) 1 ; \
                set APSMpLControlPS(TurnOnDetailed,L1:RG1:H2) 1 ; \
                set APSMpLControlPS(TurnOnDetailed,L1:RG1:H3) 1 ; \
                set APSMpLControlPS(TurnOn,L1:RG1:V) 1 ; \
                set APSMpLControlPS(TurnOnDetailed,L1:RG1:V1) 1 ; \
                set APSMpLControlPS(TurnOnDetailed,L1:RG1:V2) 1 ; \
                set APSMpLControlPS(TurnOnDetailed,L1:RG1:V3) 1 ; \
                set APSMpLControlPS(TurnOn,L1:RG1:Q) 1 ; \
                set APSMpLControlPS(TurnOnDetailed,L1:RG1:Q1) 1 ; \
                set APSMpLControlPS(TurnOnDetailed,L1:RG1:Q2) 1 ; \
                set APSMpLControlPS(TurnOnDetailed,L1:RG1:Q3) 1 ; \
                set APSMpLControlPS(TurnOnDetailed,L1:RG1:Q4) 1 ; \
                set APSMpLControlPS(TurnOn,L1:RG1:LFA) 1 ; \
                set APSMpLControlPS(TurnOnDetailed,L1:RG1:LFA) 1 ; \
                set APSMpLControlPS(TurnOn,L1:RG2:LFA:TRM) 1 ; \
                set APSMpLControlPS(TurnOnDetailed,L1:RG2:LFA:TRM) 1 ; \
                set APSMpLControlPS(TurnOn,L1:RG2:H) 0 ; \
                set APSMpLControlPS(TurnOnDetailed,L1:RG2:H2) 0 ; \
                set APSMpLControlPS(TurnOnDetailed,L1:RG2:H3) 0 ; \
                set APSMpLControlPS(TurnOn,L1:RG2:V) 0 ; \
                set APSMpLControlPS(TurnOnDetailed,L1:RG2:V1) 0 ; \
                set APSMpLControlPS(TurnOnDetailed,L1:RG2:V2) 0 ; \
                set APSMpLControlPS(TurnOnDetailed,L1:RG2:V3) 0 ; \
                set APSMpLControlPS(TurnOn,L1:RG2:Q) 0 ; \
                set APSMpLControlPS(TurnOnDetailed,L1:RG2:Q1) 0 ; \
                set APSMpLControlPS(TurnOnDetailed,L1:RG2:Q2) 0 ; \
                set APSMpLControlPS(TurnOnDetailed,L1:RG2:Q3) 0 ; \
                set APSMpLControlPS(TurnOnDetailed,L1:RG2:Q4) 0 ; \
                set APSMpLControlPS(TurnOn,L1:RG2:LFA) 0 ; \
                set APSMpLControlPS(TurnOnDetailed,L1:RG2:LFA) 0 ; \
                set APSMpLControlPS(StartConditioning,L1:RG1:H) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L1:RG1:H1) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L1:RG1:H2) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L1:RG1:H3) 1 ; \
                set APSMpLControlPS(StartConditioning,L1:RG1:V) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L1:RG1:V1) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L1:RG1:V2) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L1:RG1:V3) 1 ; \
                set APSMpLControlPS(StartConditioning,L1:RG1:Q) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L1:RG1:Q1) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L1:RG1:Q2) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L1:RG1:Q3) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L1:RG1:Q4) 1 ; \
                set APSMpLControlPS(StartConditioning,L1:RG1:LFA) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L1:RG1:LFA) 1 ; \
                set APSMpLControlPS(StartConditioning,L1:RG2:LFA:TRM) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L1:RG2:LFA:TRM) 1 ; \
                set APSMpLControlPS(StartConditioning,L1:RG2:H) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L1:RG2:H2) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L1:RG2:H3) 0 ; \
                set APSMpLControlPS(StartConditioning,L1:RG2:V) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L1:RG2:V1) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L1:RG2:V2) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L1:RG2:V3) 0 ; \
                set APSMpLControlPS(StartConditioning,L1:RG2:Q) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L1:RG2:Q1) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L1:RG2:Q2) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L1:RG2:Q3) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L1:RG2:Q4) 0 ; \
                set APSMpLControlPS(StartConditioning,L1:RG2:LFA) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L1:RG2:LFA) 0 ; \
                set LPL_Configure(PowerSupplies) 0 ; \
                $frame.top.left.startup.powersupplies invoke "
    radiobutton $frame.top.left.startup.rg.rg2 \
      -text "RG2" -variable LPL_Configure(gun) -value "RG2" \
      -command "set APSMpLControlPS(TurnOn,L1:RG1:H) 0 ; \
                set APSMpLControlPS(TurnOnDetailed,L1:RG1:H1) 0 ; \
                set APSMpLControlPS(TurnOnDetailed,L1:RG1:H2) 0 ; \
                set APSMpLControlPS(TurnOnDetailed,L1:RG1:H3) 0 ; \
                set APSMpLControlPS(TurnOn,L1:RG1:V) 0 ; \
                set APSMpLControlPS(TurnOnDetailed,L1:RG1:V1) 0 ; \
                set APSMpLControlPS(TurnOnDetailed,L1:RG1:V2) 0 ; \
                set APSMpLControlPS(TurnOnDetailed,L1:RG1:V3) 0 ; \
                set APSMpLControlPS(TurnOn,L1:RG1:Q) 0 ; \
                set APSMpLControlPS(TurnOnDetailed,L1:RG1:Q1) 0 ; \
                set APSMpLControlPS(TurnOnDetailed,L1:RG1:Q2) 0 ; \
                set APSMpLControlPS(TurnOnDetailed,L1:RG1:Q3) 0 ; \
                set APSMpLControlPS(TurnOnDetailed,L1:RG1:Q4) 0 ; \
                set APSMpLControlPS(TurnOn,L1:RG1:LFA) 0 ; \
                set APSMpLControlPS(TurnOnDetailed,L1:RG1:LFA) 0 ; \
                set APSMpLControlPS(TurnOn,L1:RG2:LFA:TRM) 0 ; \
                set APSMpLControlPS(TurnOnDetailed,L1:RG2:LFA:TRM) 0 ; \
                set APSMpLControlPS(TurnOn,L1:RG2:H) 1 ; \
                set APSMpLControlPS(TurnOnDetailed,L1:RG2:H2) 1 ; \
                set APSMpLControlPS(TurnOnDetailed,L1:RG2:H3) 1 ; \
                set APSMpLControlPS(TurnOn,L1:RG2:V) 1 ; \
                set APSMpLControlPS(TurnOnDetailed,L1:RG2:V1) 1 ; \
                set APSMpLControlPS(TurnOnDetailed,L1:RG2:V2) 1 ; \
                set APSMpLControlPS(TurnOnDetailed,L1:RG2:V3) 1 ; \
                set APSMpLControlPS(TurnOn,L1:RG2:Q) 1 ; \
                set APSMpLControlPS(TurnOnDetailed,L1:RG2:Q1) 1 ; \
                set APSMpLControlPS(TurnOnDetailed,L1:RG2:Q2) 1 ; \
                set APSMpLControlPS(TurnOnDetailed,L1:RG2:Q3) 1 ; \
                set APSMpLControlPS(TurnOnDetailed,L1:RG2:Q4) 1 ; \
                set APSMpLControlPS(TurnOn,L1:RG2:LFA) 1 ; \
                set APSMpLControlPS(TurnOnDetailed,L1:RG2:LFA) 1 ; \
                set APSMpLControlPS(StartConditioning,L1:RG1:H) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L1:RG1:H1) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L1:RG1:H2) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L1:RG1:H3) 0 ; \
                set APSMpLControlPS(StartConditioning,L1:RG1:V) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L1:RG1:V1) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L1:RG1:V2) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L1:RG1:V3) 0 ; \
                set APSMpLControlPS(StartConditioning,L1:RG1:Q) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L1:RG1:Q1) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L1:RG1:Q2) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L1:RG1:Q3) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L1:RG1:Q4) 0 ; \
                set APSMpLControlPS(StartConditioning,L1:RG1:LFA) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L1:RG1:LFA) 0 ; \
                set APSMpLControlPS(StartConditioning,L1:RG2:LFA:TRM) 0 ; \
                set APSMpLControlPS(StartConditioningDetailed,L1:RG2:LFA:TRM) 0 ; \
                set APSMpLControlPS(StartConditioning,L1:RG2:H) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L1:RG2:H2) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L1:RG2:H3) 1 ; \
                set APSMpLControlPS(StartConditioning,L1:RG2:V) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L1:RG2:V1) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L1:RG2:V2) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L1:RG2:V3) 1 ; \
                set APSMpLControlPS(StartConditioning,L1:RG2:Q) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L1:RG2:Q1) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L1:RG2:Q2) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L1:RG2:Q3) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L1:RG2:Q4) 1 ; \
                set APSMpLControlPS(StartConditioning,L1:RG2:LFA) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L1:RG2:LFA) 1 ; \
                set LPL_Configure(PowerSupplies) 0 ; \
                $frame.top.left.startup.powersupplies invoke "
    pack $frame.top.left.startup.rg.rg1 $frame.top.left.startup.rg.rg2 -side left

    checkbutton $frame.top.left.startup.powersupplies \
      -text "Linac Power Supplies" -variable LPL_Configure(PowerSupplies) -anchor w \
      -command "if !\$LPL_Configure(PowerSupplies) \" \
                      .promptDialog.userFrame.fTurnOn.frame.cb1.frame.button1 configure -state disable ; \
                      .promptDialog.userFrame.fTurnOn.frame.cb1.frame.button2 configure -state disable ; \
                      .promptDialog.userFrame.fTurnOn.frame.cb1.frame.button3 configure -state disable ; \
                      .promptDialog.userFrame.fTurnOn.frame.cb1.frame.button4 configure -state disable ; \
                      .promptDialog.userFrame.fTurnOn.frame.cb1.frame.button5 configure -state disable ; \
                      .promptDialog.userFrame.fTurnOn.frame.cb1.frame.button6 configure -state disable ; \
                      .promptDialog.userFrame.fTurnOn.frame.cb1.frame.button7 configure -state disable ; \
                      .promptDialog.userFrame.fTurnOn.frame.cb1.frame.button8 configure -state disable ; \
                      .promptDialog.userFrame.fTurnOn.frame.cb1.frame.button9 configure -state disable ; \
                      .promptDialog.userFrame.fTurnOn.frame.cb1.frame.button10 configure -state disable ; \
                      .promptDialog.userFrame.fTurnOn.frame.cb1.frame.button11 configure -state disable ; \
                      .promptDialog.userFrame.fTurnOn.frame.cb1.frame.button12 configure -state disable ; \
                      .promptDialog.userFrame.fTurnOn.frame.cb1.frame.button13 configure -state disable ; \
                      .promptDialog.userFrame.fTurnOn.frame.cb1.frame.button14 configure -state disable ; \
                      .promptDialog.userFrame.fTurnOn.frame.cb1.frame.button15 configure -state disable ; \
                      .promptDialog.userFrame.fTurnOn.frame.cb1.frame.button16 configure -state disable ; \
                      .promptDialog.userFrame.fTurnOn.frame.cb1.frame.button17 configure -state disable ; \
                      .promptDialog.userFrame.fTurnOn.frame.cb1.frame.button18 configure -state disable ; \
                      .promptDialog.userFrame.fTurnOn.frame.cb1.frame.button19 configure -state disable ; \
                      .promptDialog.userFrame.fTurnOn.frame.cb1.frame.button20 configure -state disable ; \
                      .promptDialog.userFrame.fTurnOn.frame.cb1.frame.button21 configure -state disable ; \
                      .promptDialog.userFrame.fTurnOn.frame.cb1.frame.button22 configure -state disable ; \
                      .promptDialog.userFrame.fTurnOn.frame.cb1.frame.button23 configure -state disable ; \
                      .promptDialog.userFrame.fTurnOn.frame.cb1.frame.button24 configure -state disable ; \
                      .promptDialog.userFrame.fTurnOff.frame.cb1.frame.button1 configure -state disable ; \
                      .promptDialog.userFrame.fTurnOff.frame.cb1.frame.button2 configure -state disable ; \
                      .promptDialog.userFrame.fTurnOff.frame.cb1.frame.button3 configure -state disable ; \
                      .promptDialog.userFrame.fTurnOff.frame.cb1.frame.button4 configure -state disable ; \
                      .promptDialog.userFrame.fTurnOff.frame.cb1.frame.button5 configure -state disable ; \
                      .promptDialog.userFrame.fTurnOff.frame.cb1.frame.button6 configure -state disable ; \
                      .promptDialog.userFrame.fTurnOff.frame.cb1.frame.button7 configure -state disable ; \
                      .promptDialog.userFrame.fTurnOff.frame.cb1.frame.button8 configure -state disable ; \
                      .promptDialog.userFrame.fTurnOff.frame.cb1.frame.button9 configure -state disable ; \
                      .promptDialog.userFrame.fTurnOff.frame.cb1.frame.button10 configure -state disable ; \
                      .promptDialog.userFrame.fTurnOff.frame.cb1.frame.button11 configure -state disable ; \
                      .promptDialog.userFrame.fTurnOff.frame.cb1.frame.button12 configure -state disable ; \
                      .promptDialog.userFrame.fTurnOff.frame.cb1.frame.button13 configure -state disable ; \
                      .promptDialog.userFrame.fTurnOff.frame.cb1.frame.button14 configure -state disable ; \
                      .promptDialog.userFrame.fTurnOff.frame.cb1.frame.button15 configure -state disable ; \
                      .promptDialog.userFrame.fTurnOff.frame.cb1.frame.button16 configure -state disable ; \
                      .promptDialog.userFrame.fTurnOff.frame.cb1.frame.button17 configure -state disable ; \
                      .promptDialog.userFrame.fTurnOff.frame.cb1.frame.button18 configure -state disable ; \
                      .promptDialog.userFrame.fTurnOff.frame.cb1.frame.button19 configure -state disable ; \
                      .promptDialog.userFrame.fTurnOff.frame.cb1.frame.button20 configure -state disable ; \
                      .promptDialog.userFrame.fTurnOff.frame.cb1.frame.button21 configure -state disable ; \
                      .promptDialog.userFrame.fTurnOff.frame.cb1.frame.button22 configure -state disable ; \
                      .promptDialog.userFrame.fTurnOff.frame.cb1.frame.button23 configure -state disable ; \
                      .promptDialog.userFrame.fTurnOff.frame.cb1.frame.button24 configure -state disable ; \
                      .promptDialog.userFrame.fStartConditioning.frame.cb1.frame.button1 configure -state disable ; \
                      .promptDialog.userFrame.fStartConditioning.frame.cb1.frame.button2 configure -state disable ; \
                      .promptDialog.userFrame.fStartConditioning.frame.cb1.frame.button3 configure -state disable ; \
                      .promptDialog.userFrame.fStartConditioning.frame.cb1.frame.button4 configure -state disable ; \
                      .promptDialog.userFrame.fStartConditioning.frame.cb1.frame.button5 configure -state disable ; \
                      .promptDialog.userFrame.fStartConditioning.frame.cb1.frame.button6 configure -state disable ; \
                      .promptDialog.userFrame.fStartConditioning.frame.cb1.frame.button7 configure -state disable ; \
                      .promptDialog.userFrame.fStartConditioning.frame.cb1.frame.button8 configure -state disable ; \
                      .promptDialog.userFrame.fStartConditioning.frame.cb1.frame.button9 configure -state disable ; \
                      .promptDialog.userFrame.fStartConditioning.frame.cb1.frame.button10 configure -state disable ; \
                      .promptDialog.userFrame.fStartConditioning.frame.cb1.frame.button11 configure -state disable ; \
                      .promptDialog.userFrame.fStartConditioning.frame.cb1.frame.button12 configure -state disable ; \
                      .promptDialog.userFrame.fStartConditioning.frame.cb1.frame.button13 configure -state disable ; \
                      .promptDialog.userFrame.fStartConditioning.frame.cb1.frame.button14 configure -state disable ; \
                      .promptDialog.userFrame.fStartConditioning.frame.cb1.frame.button15 configure -state disable ; \
                      .promptDialog.userFrame.fStartConditioning.frame.cb1.frame.button16 configure -state disable ; \
                      .promptDialog.userFrame.fStartConditioning.frame.cb1.frame.button17 configure -state disable ; \
                      .promptDialog.userFrame.fStartConditioning.frame.cb1.frame.button18 configure -state disable ; \
                      .promptDialog.userFrame.fStartConditioning.frame.cb1.frame.button19 configure -state disable ; \
                      .promptDialog.userFrame.fStartConditioning.frame.cb1.frame.button20 configure -state disable ; \
                      .promptDialog.userFrame.fStartConditioning.frame.cb1.frame.button21 configure -state disable ; \
                      .promptDialog.userFrame.fStartConditioning.frame.cb1.frame.button22 configure -state disable ; \
                      .promptDialog.userFrame.fStartConditioning.frame.cb1.frame.button23 configure -state disable ; \
                      .promptDialog.userFrame.fStartConditioning.frame.cb1.frame.button24 configure -state disable \
                \" else \" \
                      .promptDialog.userFrame.fTurnOn.frame.cb1.frame.button1 configure -state normal ; \
                      .promptDialog.userFrame.fTurnOn.frame.cb1.frame.button2 configure -state normal ; \
                      .promptDialog.userFrame.fTurnOn.frame.cb1.frame.button3 configure -state normal ; \
                      .promptDialog.userFrame.fTurnOn.frame.cb1.frame.button4 configure -state normal ; \
                      .promptDialog.userFrame.fTurnOn.frame.cb1.frame.button5 configure -state normal ; \
                      .promptDialog.userFrame.fTurnOn.frame.cb1.frame.button6 configure -state normal ; \
                      .promptDialog.userFrame.fTurnOn.frame.cb1.frame.button7 configure -state normal ; \
                      .promptDialog.userFrame.fTurnOn.frame.cb1.frame.button8 configure -state normal ; \
                      .promptDialog.userFrame.fTurnOn.frame.cb1.frame.button9 configure -state normal ; \
                      .promptDialog.userFrame.fTurnOn.frame.cb1.frame.button10 configure -state normal ; \
                      .promptDialog.userFrame.fTurnOn.frame.cb1.frame.button11 configure -state normal ; \
                      .promptDialog.userFrame.fTurnOn.frame.cb1.frame.button12 configure -state normal ; \
                      .promptDialog.userFrame.fTurnOn.frame.cb1.frame.button13 configure -state normal ; \
                      .promptDialog.userFrame.fTurnOn.frame.cb1.frame.button14 configure -state normal ; \
                      .promptDialog.userFrame.fTurnOn.frame.cb1.frame.button15 configure -state normal ; \
                      .promptDialog.userFrame.fTurnOn.frame.cb1.frame.button16 configure -state normal ; \
                      .promptDialog.userFrame.fTurnOn.frame.cb1.frame.button17 configure -state normal ; \
                      .promptDialog.userFrame.fTurnOn.frame.cb1.frame.button18 configure -state normal ; \
                      .promptDialog.userFrame.fTurnOn.frame.cb1.frame.button19 configure -state normal ; \
                      .promptDialog.userFrame.fTurnOn.frame.cb1.frame.button20 configure -state normal ; \
                      .promptDialog.userFrame.fTurnOn.frame.cb1.frame.button21 configure -state normal ; \
                      .promptDialog.userFrame.fTurnOn.frame.cb1.frame.button22 configure -state normal ; \
                      .promptDialog.userFrame.fTurnOn.frame.cb1.frame.button23 configure -state normal ; \
                      .promptDialog.userFrame.fTurnOn.frame.cb1.frame.button24 configure -state normal ; \
                      .promptDialog.userFrame.fTurnOff.frame.cb1.frame.button1 configure -state normal ; \
                      .promptDialog.userFrame.fTurnOff.frame.cb1.frame.button2 configure -state normal ; \
                      .promptDialog.userFrame.fTurnOff.frame.cb1.frame.button3 configure -state normal ; \
                      .promptDialog.userFrame.fTurnOff.frame.cb1.frame.button4 configure -state normal ; \
                      .promptDialog.userFrame.fTurnOff.frame.cb1.frame.button5 configure -state normal ; \
                      .promptDialog.userFrame.fTurnOff.frame.cb1.frame.button6 configure -state normal ; \
                      .promptDialog.userFrame.fTurnOff.frame.cb1.frame.button7 configure -state normal ; \
                      .promptDialog.userFrame.fTurnOff.frame.cb1.frame.button8 configure -state normal ; \
                      .promptDialog.userFrame.fTurnOff.frame.cb1.frame.button9 configure -state normal ; \
                      .promptDialog.userFrame.fTurnOff.frame.cb1.frame.button10 configure -state normal ; \
                      .promptDialog.userFrame.fTurnOff.frame.cb1.frame.button11 configure -state normal ; \
                      .promptDialog.userFrame.fTurnOff.frame.cb1.frame.button12 configure -state normal ; \
                      .promptDialog.userFrame.fTurnOff.frame.cb1.frame.button13 configure -state normal ; \
                      .promptDialog.userFrame.fTurnOff.frame.cb1.frame.button14 configure -state normal ; \
                      .promptDialog.userFrame.fTurnOff.frame.cb1.frame.button15 configure -state normal ; \
                      .promptDialog.userFrame.fTurnOff.frame.cb1.frame.button16 configure -state normal ; \
                      .promptDialog.userFrame.fTurnOff.frame.cb1.frame.button17 configure -state normal ; \
                      .promptDialog.userFrame.fTurnOff.frame.cb1.frame.button18 configure -state normal ; \
                      .promptDialog.userFrame.fTurnOff.frame.cb1.frame.button19 configure -state normal ; \
                      .promptDialog.userFrame.fTurnOff.frame.cb1.frame.button20 configure -state normal ; \
                      .promptDialog.userFrame.fTurnOff.frame.cb1.frame.button21 configure -state normal ; \
                      .promptDialog.userFrame.fTurnOff.frame.cb1.frame.button22 configure -state normal ; \
                      .promptDialog.userFrame.fTurnOff.frame.cb1.frame.button23 configure -state normal ; \
                      .promptDialog.userFrame.fTurnOff.frame.cb1.frame.button24 configure -state normal ; \
                      .promptDialog.userFrame.fStartConditioning.frame.cb1.frame.button1 configure -state normal ; \
                      .promptDialog.userFrame.fStartConditioning.frame.cb1.frame.button2 configure -state normal ; \
                      .promptDialog.userFrame.fStartConditioning.frame.cb1.frame.button3 configure -state normal ; \
                      .promptDialog.userFrame.fStartConditioning.frame.cb1.frame.button4 configure -state normal ; \
                      .promptDialog.userFrame.fStartConditioning.frame.cb1.frame.button5 configure -state normal ; \
                      .promptDialog.userFrame.fStartConditioning.frame.cb1.frame.button6 configure -state normal ; \
                      .promptDialog.userFrame.fStartConditioning.frame.cb1.frame.button7 configure -state normal ; \
                      .promptDialog.userFrame.fStartConditioning.frame.cb1.frame.button8 configure -state normal ; \
                      .promptDialog.userFrame.fStartConditioning.frame.cb1.frame.button9 configure -state normal ; \
                      .promptDialog.userFrame.fStartConditioning.frame.cb1.frame.button10 configure -state normal ; \
                      .promptDialog.userFrame.fStartConditioning.frame.cb1.frame.button11 configure -state normal ; \
                      .promptDialog.userFrame.fStartConditioning.frame.cb1.frame.button12 configure -state normal ; \
                      .promptDialog.userFrame.fStartConditioning.frame.cb1.frame.button13 configure -state normal ; \
                      .promptDialog.userFrame.fStartConditioning.frame.cb1.frame.button14 configure -state normal ; \
                      .promptDialog.userFrame.fStartConditioning.frame.cb1.frame.button15 configure -state normal ; \
                      .promptDialog.userFrame.fStartConditioning.frame.cb1.frame.button16 configure -state normal ; \
                      .promptDialog.userFrame.fStartConditioning.frame.cb1.frame.button17 configure -state normal ; \
                      .promptDialog.userFrame.fStartConditioning.frame.cb1.frame.button18 configure -state normal ; \
                      .promptDialog.userFrame.fStartConditioning.frame.cb1.frame.button19 configure -state normal ; \
                      .promptDialog.userFrame.fStartConditioning.frame.cb1.frame.button20 configure -state normal ; \
                      .promptDialog.userFrame.fStartConditioning.frame.cb1.frame.button21 configure -state normal ; \
                      .promptDialog.userFrame.fStartConditioning.frame.cb1.frame.button22 configure -state normal ; \
                      .promptDialog.userFrame.fStartConditioning.frame.cb1.frame.button23 configure -state normal ; \
                      .promptDialog.userFrame.fStartConditioning.frame.cb1.frame.button24 configure -state normal \
                 \""

    pack $frame.top.left.startup.powersupplies -fill x

    checkbutton $frame.top.left.startup.modulators \
      -text "Linac Modulators" -variable LPL_Configure(Modulators) -anchor w \
      -command "if !\$LPL_Configure(Modulators) \" \
                    $frame.top.left.startup.mod.k1 configure -state disable ; \
                    $frame.top.left.startup.mod.k2 configure -state disable ; \
                    $frame.top.left.startup.mod.k3 configure -state disable ; \
                    $frame.top.left.startup.mod.k4 configure -state disable ; \
                    $frame.top.left.startup.mod.k5 configure -state disable ; \
                    $frame.top.left.startup.mod.k6 configure -state disable ; \
                    $frame.top.left.startup.mod.filament configure -state disable ; \
                    $frame.top.left.startup.mod3.frame.normal configure -state disable ; \
                    $frame.top.left.startup.mod3.frame.k1 configure -state disable ; \
                    $frame.top.left.startup.mod3.frame.k2 configure -state disable ; \
                    $frame.top.left.startup.mod3.frame.k3 configure -state disable ; \
                    $frame.top.left.startup.mod3.frame.testroom configure -state disable \
                \" else \" \
                    $frame.top.left.startup.mod3.frame.normal configure -state normal ; \
                    $frame.top.left.startup.mod3.frame.k1 configure -state normal ; \
                    $frame.top.left.startup.mod3.frame.k2 configure -state normal ; \
                    $frame.top.left.startup.mod3.frame.k3 configure -state normal ; \
                    $frame.top.left.startup.mod3.frame.testroom configure -state normal ; \
                    $frame.top.left.startup.mod.k1 configure -state normal ; \
                    $frame.top.left.startup.mod.k2 configure -state normal ; \
                    $frame.top.left.startup.mod.k3 configure -state normal ; \
                    $frame.top.left.startup.mod.k4 configure -state normal ; \
                    $frame.top.left.startup.mod.k5 configure -state normal ; \
                    $frame.top.left.startup.mod.filament configure -state normal \
                \" ; \
                if \"\$LPL_Configure(Modulators) && !\[string compare \$LPL_Configure(mode) {shutdown}\]\" \" \
                    $frame.top.left.startup.mod.k6 configure -state normal ; \
                 \" ; \
                if \"\$LPL_Configure(Modulators) && !\[string compare \$LPL_Configure(modeVal) {Normal}\] && \$LPL_Configure(bypass)\" \" \
                    $frame.top.left.startup.mod.k3 configure -state disable \
                \" ; \
                if \"\$LPL_Configure(Modulators) && !\[string compare \$LPL_Configure(modeVal) {K1 Down}\]\" \" \
                    $frame.top.left.startup.mod.k1 configure -state disable \
                \" ; \
                if \"\$LPL_Configure(Modulators) && !\[string compare \$LPL_Configure(modeVal) {K2 Down}\]\" \" \
                    $frame.top.left.startup.mod.k2 configure -state disable \
                \" ; \
                if \"\$LPL_Configure(Modulators) && !\[string compare \$LPL_Configure(mode) {shutdown}\]\" \" \
                    $frame.top.left.startup.mod.k1 configure -state normal ; \
                    $frame.top.left.startup.mod.k2 configure -state normal ; \
                    $frame.top.left.startup.mod.k3 configure -state normal ; \
                \""
    pack $frame.top.left.startup.modulators -fill x

    labelframe $frame.top.left.startup.mod -text Use
    pack $frame.top.left.startup.mod -fill x -padx 20
    checkbutton $frame.top.left.startup.mod.k1 \
      -text "K1" -variable LPL_Configure(L1)
    checkbutton $frame.top.left.startup.mod.k2 \
      -text "K2" -variable LPL_Configure(L2)
    checkbutton $frame.top.left.startup.mod.k3 \
      -text "K3" -variable LPL_Configure(L3)
    checkbutton $frame.top.left.startup.mod.k4 \
      -text "K4" -variable LPL_Configure(L4)
    checkbutton $frame.top.left.startup.mod.k5 \
      -text "K5" -variable LPL_Configure(L5)
    checkbutton $frame.top.left.startup.mod.k6 \
      -text "K6" -variable LPL_Configure(L6) -state disable
    checkbutton $frame.top.left.startup.mod.filament \
      -text "Include Filament" -variable LPL_Configure(includeFilament)
    pack $frame.top.left.startup.mod.k1 \
      $frame.top.left.startup.mod.k2 \
      $frame.top.left.startup.mod.k3 \
      $frame.top.left.startup.mod.k4 \
      $frame.top.left.startup.mod.k5 \
      $frame.top.left.startup.mod.k6 \
      -side left

    labelframe $frame.top.left.startup.mod3 -text "Linac RF Switch Mode"
    pack $frame.top.left.startup.mod3 -fill x -padx 20
    pack [frame $frame.top.left.startup.mod3.frame]

    radiobutton $frame.top.left.startup.mod3.frame.normal \
      -text "Normal" -variable LPL_Configure(modeVal) -value "Normal" \
      -command "set LPL_Configure(L1) 1 ; \
                  set LPL_Configure(L2) 1 ; \
                  set LPL_Configure(L3) 0 ; \
                  set LPL_Configure(L4) 0 ; \
                  set LPL_Configure(L5) 0 ; \
                  $frame.top.left.startup.mod.k1 configure -state normal ; \
                  $frame.top.left.startup.mod.k2 configure -state normal ; \
                  $frame.top.left.startup.mod.k3 configure -state normal ; \
                  set LPL_Configure(startupLTP) 0 ; \
                  $frame.top.left.startup.ltp.condition configure -state disable ; \
                  $frame.top.left.startup.ltp.conditionB1 configure -state disable ; \
                  set LPL_Configure(startupPAR) 0 ; \
                  $frame.top.left.startup.par.condition configure -state disable ; \
                  $frame.top.left.startup.par.rf configure -state disable ; \
                  $frame.top.left.startup.par.pulsedPS configure -state disable ; \
                    $frame.top.right.par.par1.system1 configure -state disable ; \
                    $frame.top.right.par.par1.system2 configure -state disable ; \
                    $frame.top.right.par.par12.system1 configure -state disable ; \
                    $frame.top.right.par.par12.system2 configure -state disable ; \
                    $frame.top.right.parSCR.scr1 configure -state disable ; \
                    $frame.top.right.parSCR.scr2 configure -state disable ; \
                  set LPL_Configure(startupPTB) 0 ; \
                  $frame.top.left.startup.ptb.condition configure -state disable ; \
                  if !\[string compare \$LPL_Configure(gun) \$apsInitialGunSelection \] \" \
                    set LPL_Configure(PowerSupplies) 1 ; \
                    $frame.top.left.startup.powersupplies invoke \
                  \" ; \
                  if \$LPL_Configure(bypass) \" \
                      $frame.top.left.startup.mod.k3 configure -state disable \
                  \" else \" \
                      $frame.top.left.startup.mod.k3 configure -state normal \
                  \""
    radiobutton $frame.top.left.startup.mod3.frame.k1 \
      -text "K1 Down" -variable LPL_Configure(modeVal) -value "K1 Down" \
      -command "set LPL_Configure(L1) 0 ; \
                  set LPL_Configure(L2) 1 ; \
                  set LPL_Configure(L3) 1 ; \
                  set LPL_Configure(L4) 0 ; \
                  set LPL_Configure(L5) 0 ; \
                  set LPL_Configure(startupLTP) 0 ; \
                  $frame.top.left.startup.ltp.condition configure -state disable ; \
                  $frame.top.left.startup.ltp.conditionB1 configure -state disable ; \
                  set LPL_Configure(startupPAR) 0 ; \
                  $frame.top.left.startup.par.condition configure -state disable ; \
                  $frame.top.left.startup.par.rf configure -state disable ; \
                  $frame.top.left.startup.par.pulsedPS configure -state disable ; \
                    $frame.top.right.par.par1.system1 configure -state disable ; \
                    $frame.top.right.par.par1.system2 configure -state disable ; \
                    $frame.top.right.par.par12.system1 configure -state disable ; \
                    $frame.top.right.par.par12.system2 configure -state disable ; \
                    $frame.top.right.parSCR.scr1 configure -state disable ; \
                    $frame.top.right.parSCR.scr2 configure -state disable ; \
                  set LPL_Configure(startupPTB) 0 ; \
                  $frame.top.left.startup.ptb.condition configure -state disable ; \
                  if !\[string compare \$LPL_Configure(gun) \$apsInitialGunSelection \] \" \
                    set LPL_Configure(PowerSupplies) 1 ; \
                    $frame.top.left.startup.powersupplies invoke \
                  \" ; \
                  $frame.top.left.startup.mod.k1 configure -state disable ; \
                  $frame.top.left.startup.mod.k2 configure -state normal ; \
                  $frame.top.left.startup.mod.k3 configure -state normal"
    radiobutton $frame.top.left.startup.mod3.frame.k2 \
      -text "K2 Down" -variable LPL_Configure(modeVal) -value "K2 Down" \
      -command "set LPL_Configure(L1) 1 ; \
                  set LPL_Configure(L2) 0 ; \
                  set LPL_Configure(L3) 1 ; \
                  set LPL_Configure(L4) 0 ; \
                  set LPL_Configure(L5) 0 ; \
                  set LPL_Configure(startupLTP) 0 ; \
                  $frame.top.left.startup.ltp.condition configure -state disable ; \
                  $frame.top.left.startup.ltp.conditionB1 configure -state disable ; \
                  set LPL_Configure(startupPAR) 0 ; \
                  $frame.top.left.startup.par.condition configure -state disable ; \
                  $frame.top.left.startup.par.rf configure -state disable ; \
                  $frame.top.left.startup.par.pulsedPS configure -state disable ; \
                    $frame.top.right.par.par1.system1 configure -state disable ; \
                    $frame.top.right.par.par1.system2 configure -state disable ; \
                    $frame.top.right.par.par12.system1 configure -state disable ; \
                    $frame.top.right.par.par12.system2 configure -state disable ; \
                    $frame.top.right.parSCR.scr1 configure -state disable ; \
                    $frame.top.right.parSCR.scr2 configure -state disable ; \
                  set LPL_Configure(startupPTB) 0 ; \
                  $frame.top.left.startup.ptb.condition configure -state disable ; \
                  if !\[string compare \$LPL_Configure(gun) \$apsInitialGunSelection \] \" \
                    set LPL_Configure(PowerSupplies) 1 ; \
                    $frame.top.left.startup.powersupplies invoke \
                  \" ; \
                  $frame.top.left.startup.mod.k1 configure -state normal ; \
                  $frame.top.left.startup.mod.k2 configure -state disable ; \
                  $frame.top.left.startup.mod.k3 configure -state normal"
    radiobutton $frame.top.left.startup.mod3.frame.k3 \
      -text "K3 Down" -variable LPL_Configure(modeVal) -value "K3 Down" \
      -command "set LPL_Configure(L1) 1 ; \
                  set LPL_Configure(L2) 1 ; \
                  set LPL_Configure(L3) 0 ; \
                  set LPL_Configure(L4) 0 ; \
                  set LPL_Configure(L5) 0 ; \
                  set LPL_Configure(startupLTP) 0 ; \
                  $frame.top.left.startup.ltp.condition configure -state disable ; \
                  $frame.top.left.startup.ltp.conditionB1 configure -state disable ; \
                  set LPL_Configure(startupPAR) 0 ; \
                  $frame.top.left.startup.par.condition configure -state disable ; \
                  $frame.top.left.startup.par.rf configure -state disable ; \
                  $frame.top.left.startup.par.pulsedPS configure -state disable ; \
                    $frame.top.right.par.par1.system1 configure -state disable ; \
                    $frame.top.right.par.par1.system2 configure -state disable ; \
                    $frame.top.right.par.par12.system1 configure -state disable ; \
                    $frame.top.right.par.par12.system2 configure -state disable ; \
                    $frame.top.right.parSCR.scr1 configure -state disable ; \
                    $frame.top.right.parSCR.scr2 configure -state disable ; \
                  set LPL_Configure(startupPTB) 0 ; \
                  $frame.top.left.startup.ptb.condition configure -state disable ; \
                  if !\[string compare \$LPL_Configure(gun) \$apsInitialGunSelection \] \" \
                    set LPL_Configure(PowerSupplies) 1 ; \
                    $frame.top.left.startup.powersupplies invoke \
                  \" ; \
                  $frame.top.left.startup.mod.k1 configure -state normal ; \
                  $frame.top.left.startup.mod.k2 configure -state normal ; \
                  $frame.top.left.startup.mod.k3 configure -state disable"
    radiobutton $frame.top.left.startup.mod3.frame.testroom \
      -text "Test Room" -variable LPL_Configure(modeVal) -value "Test Room" \
      -command "set LPL_Configure(L1) 1 ; \
                  set LPL_Configure(L2) 1 ; \
                  set LPL_Configure(L3) 0 ; \
                  set LPL_Configure(L4) 0 ; \
                  set LPL_Configure(L5) 0 ; \
                  $frame.top.left.startup.mod.k1 configure -state normal ; \
                  $frame.top.left.startup.mod.k2 configure -state normal ; \
                  $frame.top.left.startup.mod.k3 configure -state normal ; \
                  set LPL_Configure(startupLTP) 0 ; \
                  $frame.top.left.startup.ltp.condition configure -state disable ; \
                  $frame.top.left.startup.ltp.conditionB1 configure -state disable ; \
                  set LPL_Configure(startupPAR) 0 ; \
                  $frame.top.left.startup.par.condition configure -state disable ; \
                  $frame.top.left.startup.par.rf configure -state disable ; \
                  $frame.top.left.startup.par.pulsedPS configure -state disable ; \
                    $frame.top.right.par.par1.system1 configure -state disable ; \
                    $frame.top.right.par.par1.system2 configure -state disable ; \
                    $frame.top.right.par.par12.system1 configure -state disable ; \
                    $frame.top.right.par.par12.system2 configure -state disable ; \
                    $frame.top.right.parSCR.scr1 configure -state disable ; \
                    $frame.top.right.parSCR.scr2 configure -state disable ; \
                  set LPL_Configure(startupPTB) 0 ; \
                  $frame.top.left.startup.ptb.condition configure -state disable ; \
                  if !\[string compare \$LPL_Configure(gun) \$apsInitialGunSelection \] \" \
                    set LPL_Configure(PowerSupplies) 1 ; \
                    $frame.top.left.startup.powersupplies invoke \
                  \" ; \
                  if \$LPL_Configure(bypass) \" \
                      $frame.top.left.startup.mod.k3 configure -state disable \
                  \" else \" \
                      $frame.top.left.startup.mod.k3 configure -state normal \
                  \""
    pack $frame.top.left.startup.mod3.frame.normal \
      $frame.top.left.startup.mod3.frame.k1 \
      $frame.top.left.startup.mod3.frame.k2 \
      $frame.top.left.startup.mod3.frame.k3 \
      $frame.top.left.startup.mod3.frame.testroom \
      -side left
    #    checkbutton $frame.top.left.startup.mod3.turnoff -text "Turn off unused modulator if going\nto K1 or K2 down mode" -variable LPL_Configure(turnOffDownKlystron)
    #    pack $frame.top.left.startup.mod3.turnoff

    pack [frame $frame.top.left.startup.ltp] -fill x
    checkbutton $frame.top.left.startup.ltp.turnon \
      -text "LTP       " -variable LPL_Configure(startupLTP) -anchor w \
      -command "if !\$LPL_Configure(startupLTP) \" \
                    $frame.top.left.startup.ltp.dcps configure -state disable ; \
                    $frame.top.left.startup.ltp.ramped configure -state disable ; \
                    $frame.top.left.startup.ltp.h configure -state disable ; \
                    $frame.top.left.startup.ltp.v configure -state disable ; \
                    $frame.top.left.startup.ltp.q configure -state disable ; \
                    $frame.top.left.startup.ltp.b1 configure -state disable ; \
                    $frame.top.left.startup.ltp.condition configure -state disable ; \
                    $frame.top.left.startup.ltp.conditionB1 configure -state disable \
                \" else \" \
                    $frame.top.left.startup.ltp.dcps configure -state normal ; \
                    $frame.top.left.startup.ltp.ramped configure -state normal ; \
                    $frame.top.left.startup.ltp.h configure -state normal ; \
                    $frame.top.left.startup.ltp.v configure -state normal ; \
                    $frame.top.left.startup.ltp.q configure -state normal ; \
                    $frame.top.left.startup.ltp.b1 configure -state normal ; \
                    $frame.top.left.startup.ltp.condition configure -state normal ; \
                    $frame.top.left.startup.ltp.conditionB1 configure -state normal \
                \""
    pack $frame.top.left.startup.ltp.turnon -side left

    checkbutton $frame.top.left.startup.ltp.condition \
      -text "w/condition" -variable LPL_Configure(conditionLTP) -anchor w \
      -command "if !\$LPL_Configure(conditionLTP) \" \
                    $frame.top.left.startup.ltp.conditionB1 configure -state disable \
                \" else \" \
                    $frame.top.left.startup.ltp.conditionB1 configure -state normal \
                \""
    pack $frame.top.left.startup.ltp.condition -side left

    checkbutton $frame.top.left.startup.ltp.conditionB1 \
      -text "w/condition B1" -variable LPL_Configure(conditionLTPB1) -anchor w
    pack $frame.top.left.startup.ltp.conditionB1 -side left

    checkbutton $frame.top.left.startup.ltp.dcps \
      -text "DCPS" -variable LPL_Configure(DCPSLTP) -anchor w
    checkbutton $frame.top.left.startup.ltp.ramped \
      -text "Ramped" -variable LPL_Configure(rampedLTP) -anchor w
    checkbutton $frame.top.left.startup.ltp.h \
      -text "H" -variable LPL_Configure(HLTP) -anchor w
    checkbutton $frame.top.left.startup.ltp.v \
      -text "V" -variable LPL_Configure(VLTP) -anchor w
    checkbutton $frame.top.left.startup.ltp.q \
      -text "Q" -variable LPL_Configure(QLTP) -anchor w
    checkbutton $frame.top.left.startup.ltp.b1 \
      -text "B1" -variable LPL_Configure(B1LTP) -anchor w


    pack [frame $frame.top.left.startup.par] -fill x
    checkbutton $frame.top.left.startup.par.turnon \
      -text "PAR       " -variable LPL_Configure(startupPAR) -anchor w \
      -command "if !\$LPL_Configure(startupPAR) \" \
                    $frame.top.left.startup.par.condition configure -state disable ; \
                    $frame.top.left.startup.par.rf configure -state disable ; \
                    $frame.top.left.startup.par.pulsedPS configure -state disable ; \
                    $frame.top.left.startup.par.dcps configure -state disable ; \
                    $frame.top.left.startup.par.bm configure -state disable ; \
                    $frame.top.left.startup.par.ramped configure -state disable ; \
                    $frame.top.right.parSCR.scr1 configure -state disable ; \
                    $frame.top.right.parSCR.scr2 configure -state disable ; \
                    $frame.top.right.par.par1.system1 configure -state disable ; \
                    $frame.top.right.par.par1.system2 configure -state disable ; \
                    $frame.top.right.par.par12.system1 configure -state disable ; \
                    $frame.top.right.par.par12.system2 configure -state disable \
                \" else \" \
                    $frame.top.left.startup.par.condition configure -state normal ; \
                    $frame.top.left.startup.par.rf configure -state normal ; \
                    $frame.top.left.startup.par.pulsedPS configure -state normal ; \
                    $frame.top.left.startup.par.dcps configure -state normal ; \
                    $frame.top.left.startup.par.bm configure -state normal ; \
                    $frame.top.left.startup.par.ramped configure -state normal ; \
                    $frame.top.right.parSCR.scr1 configure -state normal ; \
                    $frame.top.right.parSCR.scr2 configure -state normal ; \
                    $frame.top.right.par.par1.system1 configure -state normal ; \
                    $frame.top.right.par.par1.system2 configure -state normal ; \
                    $frame.top.right.par.par12.system1 configure -state normal ; \
                    $frame.top.right.par.par12.system2 configure -state normal ; \
                    set LPL_Configure(PARrfSystems) 1 \
               \""
    pack $frame.top.left.startup.par.turnon -side left

    checkbutton $frame.top.left.startup.par.condition \
      -text "w/condition" -variable LPL_Configure(conditionPAR) -anchor w
    pack $frame.top.left.startup.par.condition -side left

    checkbutton $frame.top.left.startup.par.rf \
      -text "w/RF" -variable LPL_Configure(PARrfSystems) -anchor w \
      -command "if !\$LPL_Configure(PARrfSystems) \" \
                    $frame.top.right.parSCR.scr1 configure -state disable ; \
                    $frame.top.right.parSCR.scr2 configure -state disable ; \
                    $frame.top.right.par.par1.system1 configure -state disable ; \
                    $frame.top.right.par.par1.system2 configure -state disable ; \
                    $frame.top.right.par.par12.system1 configure -state disable ; \
                    $frame.top.right.par.par12.system2 configure -state disable \
                \" else \" \
                    $frame.top.right.parSCR.scr1 configure -state normal ; \
                    $frame.top.right.parSCR.scr2 configure -state normal ; \
                    $frame.top.right.par.par1.system1 configure -state normal ; \
                    $frame.top.right.par.par1.system2 configure -state normal ; \
                    $frame.top.right.par.par12.system1 configure -state normal ; \
                    $frame.top.right.par.par12.system2 configure -state normal \
                \""
    pack $frame.top.left.startup.par.rf -side left

    checkbutton $frame.top.left.startup.par.pulsedPS \
      -text "w/Pulsed PS" -variable LPL_Configure(PARPulsedPS) -anchor w
    pack $frame.top.left.startup.par.pulsedPS -side left

    checkbutton $frame.top.left.startup.par.dcps \
      -text "DCPS" -variable LPL_Configure(DCPSPAR) -anchor w
    checkbutton $frame.top.left.startup.par.bm \
      -text "BM" -variable LPL_Configure(PARBM) -anchor w
    checkbutton $frame.top.left.startup.par.ramped \
      -text "Ramped" -variable LPL_Configure(rampedPAR) -anchor w


    pack [frame $frame.top.left.startup.ptb] -fill x
    checkbutton $frame.top.left.startup.ptb.turnon \
      -text "PTB       " -variable LPL_Configure(startupPTB) -anchor w \
      -command "if !\$LPL_Configure(startupPTB) \" \
                    $frame.top.left.startup.ptb.dcps configure -state disable ; \
                    $frame.top.left.startup.ptb.ramped configure -state disable ; \
                    $frame.top.left.startup.ptb.condition configure -state disable \
                \" else \" \
                    $frame.top.left.startup.ptb.dcps configure -state normal ; \
                    $frame.top.left.startup.ptb.ramped configure -state normal ; \
                    $frame.top.left.startup.ptb.condition configure -state normal \
                \""
    pack $frame.top.left.startup.ptb.turnon -side left

    checkbutton $frame.top.left.startup.ptb.condition \
      -text "w/condition" -variable LPL_Configure(conditionPTB) -anchor w
    pack $frame.top.left.startup.ptb.condition -side left

    checkbutton $frame.top.left.startup.ptb.dcps \
      -text "DCPS" -variable LPL_Configure(DCPSPTB) -anchor w
    checkbutton $frame.top.left.startup.ptb.ramped \
      -text "Ramped" -variable LPL_Configure(rampedPTB) -anchor w


    pack [frame $frame.top.left.startup.parbypass] -fill x
    checkbutton $frame.top.left.startup.parbypass.turnon \
      -text "PAR Bypass" -variable LPL_Configure(startupPARBypass) -anchor w \
      -command "if !\$LPL_Configure(startupPARBypass) \" \
                    $frame.top.left.startup.parbypass.dcps configure -state disable ; \
                    $frame.top.left.startup.parbypass.h configure -state disable ; \
                    $frame.top.left.startup.parbypass.v configure -state disable ; \
                    $frame.top.left.startup.parbypass.q configure -state disable ; \
                    $frame.top.left.startup.parbypass.condition configure -state disable \
                \" else \" \
                    $frame.top.left.startup.parbypass.dcps configure -state normal ; \
                    $frame.top.left.startup.parbypass.h configure -state normal ; \
                    $frame.top.left.startup.parbypass.v configure -state normal ; \
                    $frame.top.left.startup.parbypass.q configure -state normal ; \
                    $frame.top.left.startup.parbypass.condition configure -state normal \
                \""
    pack $frame.top.left.startup.parbypass.turnon -side left

    checkbutton $frame.top.left.startup.parbypass.condition \
      -text "w/condition" -variable LPL_Configure(conditionPARBypass) -anchor w
    pack $frame.top.left.startup.parbypass.condition -side left

    checkbutton $frame.top.left.startup.parbypass.dcps \
      -text "DCPS" -variable LPL_Configure(DCPSPARBypass) -anchor w
    checkbutton $frame.top.left.startup.parbypass.h \
      -text "H" -variable LPL_Configure(HPARBypass) -anchor w
    checkbutton $frame.top.left.startup.parbypass.v \
      -text "V" -variable LPL_Configure(VPARBypass) -anchor w
    checkbutton $frame.top.left.startup.parbypass.q \
      -text "Q" -variable LPL_Configure(QPARBypass) -anchor w


    # 375MeV - 325MeV switch
    labelframe $frame.top.right.energyTransition -text "325MeV/375MeV Transition"
    pack $frame.top.right.energyTransition -anchor nw -pady 5

    checkbutton $frame.top.right.energyTransition.energy325 \
      -text "Transition to 325MeV" \
      -variable LPL_Configure(e325MeV) \
      -anchor w \
      -command "set LPL_Configure(e375MeV) 0 ; \
                if \$LPL_Configure(bypass) \" \
                   $frame.top.right.ibpar.includePAR invoke \
                \" ; \
                if !\$LPL_Configure(restoreBooster) \" \
                   $frame.top.right.ibpar.boosterSCR invoke \
                \" ; \
                if \$LPL_Configure(RFGUN) \" \
                   $frame.top.left.startup.rfgun invoke \
                \" ; \
                if !\$LPL_Configure(Modulators) \" \
                   $frame.top.left.startup.modulators invoke \
                \" ; \
                if \"\[string compare \$LPL_Configure(modeVal) {Normal}\]\" \" \
                   $frame.top.left.startup.mod3.frame.normal invoke \
                \" ; \
                if !\$LPL_Configure(PowerSupplies) \" \
                   puts \$LPL_Configure(PowerSupplies) ; \
                   $frame.top.left.startup.powersupplies invoke ; \
                   puts \$LPL_Configure(PowerSupplies) \
                \" ; \
                if \$LPL_Configure(L1) \" \
                   $frame.top.left.startup.mod.k1 invoke \
                \" ; \
                if \$LPL_Configure(L2) \" \
                   $frame.top.left.startup.mod.k2 invoke \
                \" ; \
                if \$LPL_Configure(L3) \" \
                   $frame.top.left.startup.mod.k3 invoke \
                \" ; \
                if !\$LPL_Configure(L4) \" \
                   $frame.top.left.startup.mod.k4 invoke \
                \" ; \
                if !\$LPL_Configure(L5) \" \
                   $frame.top.left.startup.mod.k5 invoke \
                \" ; \
                if !\$LPL_Configure(startupLTP) \" \
                   $frame.top.left.startup.ltp.turnon invoke \
                \" ; \
                if !\$LPL_Configure(conditionLTP) \" \
                   $frame.top.left.startup.ltp.condition invoke \
                \" ; \
                if !\$LPL_Configure(conditionLTPB1) \" \
                   $frame.top.left.startup.ltp.conditionB1 invoke \
                \" ; \
                if !\$LPL_Configure(startupPAR) \" \
                   $frame.top.left.startup.par.turnon invoke \
                \" ; \
                if !\$LPL_Configure(conditionPAR) \" \
                   $frame.top.left.startup.par.condition invoke \
                \" ; \
                if \$LPL_Configure(PARrfSystems) \" \
                   $frame.top.left.startup.par.rf invoke \
                \" ; \
                if !\$LPL_Configure(PARPulsedPS) \" \
                   $frame.top.left.startup.par.pulsedPS invoke \
                \" ; \
                if !\$LPL_Configure(startupPTB) \" \
                   $frame.top.left.startup.ptb.turnon invoke \
                \" ; \
                if !\$LPL_Configure(conditionPTB) \" \
                   $frame.top.left.startup.ptb.condition invoke \
                \" ; \
                if \$LPL_Configure(startupPARBypass) \" \
                   $frame.top.left.startup.parbypass.turnon invoke \
                \" ; \
                $frame.fStartConditioning.frame.cb1.frame.none.button invoke ; \
                set APSMpLControlPS(StartConditioning,L4:SC) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L4:SC1:HZ) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L4:SC1:VL) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L4:SC2:HZ) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L4:SC2:VL) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L4:SC3:HZ) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L4:SC3:VL) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L4:SC4:HZ) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L4:SC4:VL) 1 ; \
                set APSMpLControlPS(StartConditioning,L4:QM) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L4:QM1) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L4:QM2) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L4:QM3) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L4:QM4) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L4:QM5) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L4:QM6) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L4:QM7) 1 ; \
                set APSMpLControlPS(StartConditioning,L5:SC) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L5:SC1:HZ) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L5:SC1:VL) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L5:SC2:HZ) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L5:SC2:VL) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L5:SC3:HZ) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L5:SC3:VL) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L5:SC4:HZ) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L5:SC4:VL) 1 ; \
                set APSMpLControlPS(StartConditioning,L5:QM) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L5:QM1) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L5:QM2) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L5:QM3) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L5:QM4) 1 ; \
                set APSMpLControlPS(StartConditioning,L5:AM) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L5:AM1) 1 ; \
                $frame.scr.frame.apsSCRlist.frame.preflist.frame.list.lbox selection clear 0 end  ; \
                $frame.scr.frame.apsSCRlist.frame.preflist.frame.list.lbox see \[lsearch -exact \[$frame.scr.frame.apsSCRlist.frame.preflist.frame.list.lbox get 0 end\] \"Sys. Ref. High Charge \$LPL_Configure(gun)->PAR->BS 325MeV\" \]  ; \
                $frame.scr.frame.apsSCRlist.frame.preflist.frame.list.lbox selection set \[lsearch -exact \[$frame.scr.frame.apsSCRlist.frame.preflist.frame.list.lbox get 0 end\] \"Sys. Ref. High Charge \$LPL_Configure(gun)->PAR->BS 325MeV\" \]  ; \
                set APSMpLControlPS(Filename) /home/helios/oagData/SCR/snapshots/LPL/LPL-\[exec sddsprocess /home/helios/oagData/SCR/preferredChoices/LPL.sdds -pipe=out \"-match=column,ChoiceName=Sys. Ref. High Charge \$LPL_Configure(gun)->PAR->BS 325MeV\" | sdds2stream -pipe=in -column=Suffix \].gz ; \
                set APSMpLControlPS(Description) \[exec sdds2stream \$APSMpLControlPS(Filename) -param=SnapshotDescription -noquote\] ; \
                set APSMpLControlPS(ShortFilename) \[file tail \$APSMpLControlPS(Filename) \] ; \
"


    checkbutton $frame.top.right.energyTransition.energy375 \
      -text "Transition to 375MeV" \
      -variable LPL_Configure(e375MeV) \
      -anchor w \
      -command "set LPL_Configure(e325MeV) 0 ; \
                if \$LPL_Configure(bypass) \" \
                   $frame.top.right.ibpar.includePAR invoke \
                \" ; \
                if !\$LPL_Configure(restoreBooster) \" \
                   $frame.top.right.ibpar.boosterSCR invoke \
                \" ; \
                if \$LPL_Configure(RFGUN) \" \
                   $frame.top.left.startup.rfgun invoke \
                \" ; \
                if !\$LPL_Configure(Modulators) \" \
                   $frame.top.left.startup.modulators invoke \
                \" ; \
                if \"\[string compare \$LPL_Configure(modeVal) {Normal}\]\" \" \
                   $frame.top.left.startup.mod3.frame.normal invoke \
                \" ; \
                if !\$LPL_Configure(PowerSupplies) \" \
                   puts \$LPL_Configure(PowerSupplies) ; \
                   $frame.top.left.startup.powersupplies invoke ; \
                   puts \$LPL_Configure(PowerSupplies) \
                \" ; \
                if \$LPL_Configure(L1) \" \
                   $frame.top.left.startup.mod.k1 invoke \
                \" ; \
                if \$LPL_Configure(L2) \" \
                   $frame.top.left.startup.mod.k2 invoke \
                \" ; \
                if \$LPL_Configure(L3) \" \
                   $frame.top.left.startup.mod.k3 invoke \
                \" ; \
                if !\$LPL_Configure(L4) \" \
                   $frame.top.left.startup.mod.k4 invoke \
                \" ; \
                if !\$LPL_Configure(L5) \" \
                   $frame.top.left.startup.mod.k5 invoke \
                \" ; \
                if !\$LPL_Configure(startupLTP) \" \
                   $frame.top.left.startup.ltp.turnon invoke \
                \" ; \
                if !\$LPL_Configure(conditionLTP) \" \
                   $frame.top.left.startup.ltp.condition invoke \
                \" ; \
                if !\$LPL_Configure(conditionLTPB1) \" \
                   $frame.top.left.startup.ltp.conditionB1 invoke \
                \" ; \
                if !\$LPL_Configure(startupPAR) \" \
                   $frame.top.left.startup.par.turnon invoke \
                \" ; \
                if !\$LPL_Configure(conditionPAR) \" \
                   $frame.top.left.startup.par.condition invoke \
                \" ; \
                if \$LPL_Configure(PARrfSystems) \" \
                   $frame.top.left.startup.par.rf invoke \
                \" ; \
                if !\$LPL_Configure(PARPulsedPS) \" \
                   $frame.top.left.startup.par.pulsedPS invoke \
                \" ; \
                if !\$LPL_Configure(startupPTB) \" \
                   $frame.top.left.startup.ptb.turnon invoke \
                \" ; \
                if !\$LPL_Configure(conditionPTB) \" \
                   $frame.top.left.startup.ptb.condition invoke \
                \" ; \
                if \$LPL_Configure(startupPARBypass) \" \
                   $frame.top.left.startup.parbypass.turnon invoke \
                \" ; \
                $frame.fStartConditioning.frame.cb1.frame.none.button invoke ; \
                set APSMpLControlPS(StartConditioning,L4:SC) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L4:SC1:HZ) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L4:SC1:VL) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L4:SC2:HZ) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L4:SC2:VL) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L4:SC3:HZ) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L4:SC3:VL) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L4:SC4:HZ) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L4:SC4:VL) 1 ; \
                set APSMpLControlPS(StartConditioning,L4:QM) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L4:QM1) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L4:QM2) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L4:QM3) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L4:QM4) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L4:QM5) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L4:QM6) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L4:QM7) 1 ; \
                set APSMpLControlPS(StartConditioning,L5:SC) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L5:SC1:HZ) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L5:SC1:VL) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L5:SC2:HZ) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L5:SC2:VL) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L5:SC3:HZ) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L5:SC3:VL) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L5:SC4:HZ) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L5:SC4:VL) 1 ; \
                set APSMpLControlPS(StartConditioning,L5:QM) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L5:QM1) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L5:QM2) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L5:QM3) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L5:QM4) 1 ; \
                set APSMpLControlPS(StartConditioning,L5:AM) 1 ; \
                set APSMpLControlPS(StartConditioningDetailed,L5:AM1) 1 ; \
                $frame.scr.frame.apsSCRlist.frame.preflist.frame.list.lbox selection clear 0 end  ; \
                $frame.scr.frame.apsSCRlist.frame.preflist.frame.list.lbox see \[lsearch -exact \[$frame.scr.frame.apsSCRlist.frame.preflist.frame.list.lbox get 0 end\] \"Sys. Ref. High Charge \$LPL_Configure(gun)->PAR->BS 375MeV\" \]  ; \
                $frame.scr.frame.apsSCRlist.frame.preflist.frame.list.lbox selection set \[lsearch -exact \[$frame.scr.frame.apsSCRlist.frame.preflist.frame.list.lbox get 0 end\] \"Sys. Ref. High Charge \$LPL_Configure(gun)->PAR->BS 375MeV\" \]  ; \
                set APSMpLControlPS(Filename) /home/helios/oagData/SCR/snapshots/LPL/LPL-\[exec sddsprocess /home/helios/oagData/SCR/preferredChoices/LPL.sdds -pipe=out \"-match=column,ChoiceName=Sys. Ref. High Charge \$LPL_Configure(gun)->PAR->BS 375MeV\" | sdds2stream -pipe=in -column=Suffix \].gz ; \
                set APSMpLControlPS(Description) \[exec sdds2stream \$APSMpLControlPS(Filename) -param=SnapshotDescription -noquote\] ; \
                set APSMpLControlPS(ShortFilename) \[file tail \$APSMpLControlPS(Filename) \] ; \
"


    pack $frame.top.right.energyTransition.energy325
    pack $frame.top.right.energyTransition.energy375

    # Include or Bypass PAR
    labelframe $frame.top.right.ibpar -text "Include or Bypass PAR"
    pack $frame.top.right.ibpar -anchor nw -pady 5

    radiobutton $frame.top.right.ibpar.includePAR \
      -text "Include PAR (Standard Ops or RG2 to Leutl)" \
      -variable LPL_Configure(bypass) -value 0 \
      -command "set APSMpLControlPS(ShortFilename) \"\" ; \
                set APSMpLControlPS(Description) \"\" ; \
                set APSMpLControlPS(Filename) \"\" ; \
                set LPL_Configure(startupLTP) 1 ; \
                $frame.top.left.startup.ltp.condition configure -state normal ; \
                $frame.top.left.startup.ltp.conditionB1 configure -state normal ; \
                set LPL_Configure(startupPAR) 1 ; \
                set LPL_Configure(PARrfSystems) 1 ; \
                set LPL_Configure(PARPulsedPS) 1 ; \
                $frame.top.left.startup.par.condition configure -state normal ; \
                $frame.top.left.startup.par.rf configure -state normal ; \
                $frame.top.left.startup.par.pulsedPS configure -state normal ; \
                set LPL_Configure(startupPTB) 1 ; \
                $frame.top.left.startup.ptb.condition configure -state normal ; \
                set LPL_Configure(startupPARBypass) 0 ; \
                $frame.top.left.startup.parbypass.condition configure -state disable ; \
                set LPL_Configure(conditionLTP) 1 ; \
                set LPL_Configure(conditionLTPB1) 1 ; \
                set LPL_Configure(conditionPAR) 1 ; \
                set LPL_Configure(conditionPTB) 1 ; \
                set LPL_Configure(conditionPARBypass) 0 ; \
                set LPL_Configure(restoreBooster) 1 ; \
                $frame.top.right.par.par1.system1 configure -state normal ; \
                $frame.top.right.par.par1.system2 configure -state normal ; \
                $frame.top.right.par.par12.system1 configure -state normal ; \
                $frame.top.right.par.par12.system2 configure -state normal ; \
                $frame.top.right.parSCR.scr1 configure -state normal; \
                $frame.top.right.parSCR.scr2 configure -state normal ; \
                if !\$LPL_Configure(Modulators) \" \
                    $frame.top.left.startup.mod.k3 configure -state disable \
                \" else \" \
                    $frame.top.left.startup.mod.k3 configure -state normal \
                \" ; \
                if \$LPL_Configure(currentParState) \" \
                    set LPL_Configure(RFGUN) 1 ; \
                    $frame.top.left.startup.rg.rg1 configure -state normal ; \
                    $frame.top.left.startup.rg.rg2 configure -state normal \
                \""
    pack $frame.top.right.ibpar.includePAR
    
    radiobutton $frame.top.right.ibpar.bypassPAR \
      -text "Bypass PAR (For Booster Direct Injection)" \
      -variable LPL_Configure(bypass) -value 1 \
      -command "set APSMpLControlPS(ShortFilename) LPL-SysRef_RG2_PB_BS_\${LPL_Configure(bypassEnergy)}MeV ; \
                set APSMpLControlPS(Description) SysRef_RG2_PB_BS_\${LPL_Configure(bypassEnergy)}MeV ; \
                set APSMpLControlPS(Filename) /home/helios/oagData/SCR/snapshots/LPL/LPL-SysRef_RG2_PB_BS_\${LPL_Configure(bypassEnergy)}MeV.gz ; \
                set LPL_Configure(startupLTP) 1 ; \
                $frame.top.left.startup.ltp.condition configure -state normal ; \
                $frame.top.left.startup.ltp.conditionB1 configure -state normal ; \
                set LPL_Configure(startupPAR) 0 ; \
                set LPL_Configure(PARrfSystems) 1 ; \
                set LPL_Configure(PARPulsedPS) 1 ; \
                $frame.top.left.startup.par.condition configure -state disable ; \
                $frame.top.left.startup.par.rf configure -state disable ; \
                $frame.top.left.startup.par.pulsedPS configure -state disable ; \
                set LPL_Configure(startupPTB) 1 ; \
                $frame.top.left.startup.ptb.condition configure -state normal ; \
                set LPL_Configure(startupPARBypass) 1 ; \
                $frame.top.left.startup.parbypass.condition configure -state normal ; \
                set LPL_Configure(conditionLTP) 1 ; \
                set LPL_Configure(conditionLTPB1) 1 ; \
                set LPL_Configure(conditionPAR) 0 ; \
                set LPL_Configure(conditionPTB) 1 ; \
                set LPL_Configure(conditionPARBypass) 1 ; \
                set LPL_Configure(restoreBooster) 1 ; \
                $frame.top.right.par.par1.system1 configure -state disable ; \
                $frame.top.right.par.par1.system2 configure -state disable ; \
                $frame.top.right.par.par12.system1 configure -state disable ; \
                $frame.top.right.par.par12.system2 configure -state disable ; \
                $frame.top.right.parSCR.scr1 configure -state disable ; \
                $frame.top.right.parSCR.scr2 configure -state disable ; \
                if \"\$LPL_Configure(Modulators) && !\[string compare \$LPL_Configure(modeVal) {Normal}\]\" \" \
                    $frame.top.left.startup.mod.k3 configure -state disable \
                \" elseif !\$LPL_Configure(Modulators) \" \
                    $frame.top.left.startup.mod.k3 configure -state disable \
                \" else \" \
                    $frame.top.left.startup.mod.k3 configure -state normal \
                \" ; \
                if !\$LPL_Configure(currentParState) \" \
                    set LPL_Configure(RFGUN) 1 ; \
                    $frame.top.left.startup.rg.rg1 configure -state normal ; \
                    $frame.top.left.startup.rg.rg2 configure -state normal \
                \""
    pack $frame.top.right.ibpar.bypassPAR -anchor w

    checkbutton $frame.top.right.ibpar.boosterSCR \
      -text "Select and Restore Booster SCR" \
      -variable LPL_Configure(restoreBooster)
    pack $frame.top.right.ibpar.boosterSCR -anchor w

    # PAR RF Tube Amp
    frame $frame.top.right.par
    pack $frame.top.right.par -anchor nw -pady 5

    labelframe $frame.top.right.par.par1 -text "PAR Fundamental RF"
    pack $frame.top.right.par.par1 -anchor nw -pady 5 -side left

    radiobutton $frame.top.right.par.par1.system1 \
      -text "System \#1 Tube Amplifier" \
      -variable LPL_Configure(rf1amp) -value 1
    radiobutton $frame.top.right.par.par1.system2 \
      -text "System \#2 Tube Amplifier" \
      -variable LPL_Configure(rf1amp) -value 2
    pack $frame.top.right.par.par1.system1 $frame.top.right.par.par1.system2

    labelframe $frame.top.right.par.par12 -text "PAR Harmonic RF"
    pack $frame.top.right.par.par12 -anchor nw -pady 5 -side left

    radiobutton $frame.top.right.par.par12.system1 \
      -text "System \#1 Tube Amplifier" \
      -variable LPL_Configure(rf12amp) -value 1
    radiobutton $frame.top.right.par.par12.system2 \
      -text "System \#2 Tube Amplifier" \
      -variable LPL_Configure(rf12amp) -value 2
    pack $frame.top.right.par.par12.system1 $frame.top.right.par.par12.system2

    labelframe $frame.top.right.parSCR -text "PAR RF SCR"
    pack $frame.top.right.parSCR -anchor nw -pady 5

    radiobutton $frame.top.right.parSCR.scr1 \
      -text "Use Selected SCR File" \
      -variable LPL_Configure(parRFscr) -value 0
    radiobutton $frame.top.right.parSCR.scr2 \
      -text "Use System Reference File" \
      -variable LPL_Configure(parRFscr) -value 2
    pack $frame.top.right.parSCR.scr1 $frame.top.right.parSCR.scr2 -anchor nw


    if {[set LPL_Configure(bypass)]} {
        set APSMpLControlPS(ShortFilename) LPL-SysRef_RG2_PB_BS_\${LPL_Configure(bypassEnergy)}MeV
        set APSMpLControlPS(Description) SysRef_RG2_PB_BS_\${LPL_Configure(bypassEnergy)}MeV
        set APSMpLControlPS(Filename) /home/helios/oagData/SCR/snapshots/LPL/LPL-SysRef_RG2_PB_BS_\${LPL_Configure(bypassEnergy)}MeV.gz
        set LPL_Configure(startupLTP) 1
        $frame.top.left.startup.ltp.condition configure -state normal
        $frame.top.left.startup.ltp.conditionB1 configure -state normal
        set LPL_Configure(startupPAR) 0
        set LPL_Configure(PARPulsedPS) 0
        set LPL_Configure(PARrfSystems) 0
        $frame.top.left.startup.par.condition configure -state disable
        $frame.top.left.startup.par.rf configure -state disable
        $frame.top.left.startup.par.pulsedPS configure -state disable
        set LPL_Configure(startupPTB) 1
        $frame.top.left.startup.ptb.condition configure -state normal
        set LPL_Configure(startupPARBypass) 1
        $frame.top.left.startup.parbypass.condition configure -state normal
        set LPL_Configure(conditionLTP) 1
        set LPL_Configure(conditionLTPB1) 1
        set LPL_Configure(conditionPAR) 0
        set LPL_Configure(conditionPTB) 1
        set LPL_Configure(conditionPARBypass) 1
        $frame.top.right.par.par1.system1 configure -state disable
        $frame.top.right.par.par1.system2 configure -state disable
        $frame.top.right.par.par12.system1 configure -state disable
        $frame.top.right.par.par12.system2 configure -state disable
        $frame.top.right.parSCR.scr1 configure -state disable
        $frame.top.right.parSCR.scr2 configure -state disable
    }
    if {!$LPL_Configure(RFGUN)} {
        $frame.top.left.startup.rg.rg1 configure -state disable
        $frame.top.left.startup.rg.rg2 configure -state disable
    }
    if {!$LPL_Configure(Modulators)} {
        $frame.top.left.startup.mod.k1 configure -state disable
        $frame.top.left.startup.mod.k2 configure -state disable
        $frame.top.left.startup.mod.k3 configure -state disable
        $frame.top.left.startup.mod.k4 configure -state disable
        $frame.top.left.startup.mod.k5 configure -state disable
        $frame.top.left.startup.mod.k6 configure -state disable
        $frame.top.left.startup.mod3.frame.normal configure -state disable
        $frame.top.left.startup.mod3.frame.k1 configure -state disable
        $frame.top.left.startup.mod3.frame.k2 configure -state disable
        $frame.top.left.startup.mod3.frame.k3 configure -state disable
        $frame.top.left.startup.mod3.frame.testroom configure -state disable
    } else {
        if {$LPL_Configure(modeVal) == "K1 Down"} {
            $frame.top.left.startup.mod.k1 configure -state disable
        }
        if {$LPL_Configure(modeVal) == "K2 Down"} {
            $frame.top.left.startup.mod.k2 configure -state disable
        }
        if {$LPL_Configure(modeVal) == "K3 Down"} {
            $frame.top.left.startup.mod.k3 configure -state disable
        }
    }
    if {!$LPL_Configure(startupLTP)} {
        $frame.top.left.startup.ltp.condition configure -state disable
        $frame.top.left.startup.ltp.conditionB1 configure -state disable
        $frame.top.left.startup.ltp.dcps configure -state disable
        $frame.top.left.startup.ltp.ramped configure -state disable
        $frame.top.left.startup.ltp.h configure -state disable
        $frame.top.left.startup.ltp.v configure -state disable
        $frame.top.left.startup.ltp.q configure -state disable
        $frame.top.left.startup.ltp.b1 configure -state disable
    }
    if {!$LPL_Configure(startupPAR)} {
        $frame.top.left.startup.par.condition configure -state disable
        $frame.top.left.startup.par.rf configure -state disable
        $frame.top.left.startup.par.pulsedPS configure -state disable
        $frame.top.left.startup.par.dcps configure -state disable
        $frame.top.left.startup.par.bm configure -state disable
        $frame.top.left.startup.par.ramped configure -state disable
        $frame.top.right.par.par1.system1 configure -state disable
        $frame.top.right.par.par1.system2 configure -state disable
        $frame.top.right.par.par12.system1 configure -state disable
        $frame.top.right.par.par12.system2 configure -state disable
        $frame.top.right.parSCR.scr1 configure -state disable
        $frame.top.right.parSCR.scr2 configure -state disable
    }
    if {!$LPL_Configure(startupPTB)} {
        $frame.top.left.startup.ptb.condition configure -state disable
        $frame.top.left.startup.ptb.dcps configure -state disable
        $frame.top.left.startup.ptb.ramped configure -state disable
    }
    if {!$LPL_Configure(startupPARBypass)} {
        $frame.top.left.startup.parbypass.condition configure -state disable
        $frame.top.left.startup.parbypass.dcps configure -state disable
        $frame.top.left.startup.parbypass.h configure -state disable
        $frame.top.left.startup.parbypass.v configure -state disable
        $frame.top.left.startup.parbypass.q configure -state disable
    }
}

proc LPL_ConfigurePackProcBottom {frame} {
    pack forget $frame.fTurnOff
    global LPL_Configure APSMpLControlPS
    if {${LPL_Configure(bypass)}} {
        set APSMpLControlPS(ShortFilename) LPL-SysRef_RG2_PB_BS_${LPL_Configure(bypassEnergy)}MeV
        set APSMpLControlPS(Description) SysRef_RG2_PB_BS_${LPL_Configure(bypassEnergy)}MeV
        set APSMpLControlPS(Filename) /home/helios/oagData/SCR/snapshots/LPL/LPL-SysRef_RG2_PB_BS_${LPL_Configure(bypassEnergy)}MeV.gz
    }
}
