proc APSMpPARLETConditionInfo {} {
    return "This procedure will allow the user to select which DCPS should be conditioned. It then turns them on if they are off. Next it conditions the power supplies and finally it restores the SCR values related to the selected power supplies."
}


proc APSMpPARLETConditionInitDialog {frame} {
    global APSMpPARLETCondition

    pack [frame $frame.frame]
    APSCheckButtonFrame .cb1 \
      -parent $frame.frame \
      -label "PAR PS" \
      -packOption "-side left" \
      -allNone 1 \
      -buttonList {"Dipole" "Quads" "Sextupoles" "Correctors"} \
      -variableList {APSMpPARLETCondition(PARdipole) APSMpPARLETCondition(PARquads) APSMpPARLETCondition(PARsextupoles) APSMpPARLETCondition(PARcorrectors)}

    APSCheckButtonFrame .cb2 \
      -parent $frame.frame \
      -label "LTP PS" \
      -packOption "-side left" \
      -allNone 1 \
      -buttonList {"Dipole" "Quads" "Correctors"} \
      -variableList {APSMpPARLETCondition(LTPdipole) APSMpPARLETCondition(LTPquads) APSMpPARLETCondition(LTPcorrectors)}
    
    APSCheckButtonFrame .cb3 \
      -parent $frame.frame \
      -label "PTB PS" \
      -packOption "-side left" \
      -allNone 1 \
      -buttonList {"Dipole" "Quads" "Correctors"} \
      -variableList {APSMpPARLETCondition(PTBdipole) APSMpPARLETCondition(PTBquads) APSMpPARLETCondition(PTBcorrectors)}
    
    APSLabeledEntry .conditioningTime \
      -parent $frame \
      -label "Minutes for conditioning: " \
      -width 5 \
      -packOption "-fill none" \
      -textVariable APSMpPARLETCondition(conditioningTime)

    bindtags $frame.conditioningTime.entry "Entry .promptDialog all $frame.conditioningTime.entry"
    bind $frame.conditioningTime.entry <KeyPress> "
        if \"(\[llength \[set APSMpPARLETCondition(conditioningTime)\]\]) && (\[string is integer \[set APSMpPARLETCondition(conditioningTime)\]\])\" \{
            if \"(\[llength \[set APSMpPARLETCondition(conditioningTime)\]\]) && (\[set APSMpPARLETCondition(conditioningTime)\] <= 14) && (\[set APSMpPARLETCondition(conditioningTime)\] >= 14)\" \{ $frame.conditioningTime.entry configure -bg white \} else \{ $frame.conditioningTime.entry configure -bg yellow \}
        \} else \{ $frame.conditioningTime.entry configure -bg yellow \}
    "
    bind $frame.conditioningTime.entry <ButtonRelease-2> "
        if \"(\[llength \[set APSMpPARLETCondition(conditioningTime)\]\]) && (\[string is integer \[set APSMpPARLETCondition(conditioningTime)\]\])\" \{
            if \"(\[llength \[set APSMpPARLETCondition(conditioningTime)\]\]) && (\[set APSMpPARLETCondition(conditioningTime)\] <= 14) && (\[set APSMpPARLETCondition(conditioningTime)\] >= 14)\" \{ $frame.conditioningTime.entry configure -bg white \} else \{ $frame.conditioningTime.entry configure -bg yellow \}
        \} else \{ $frame.conditioningTime.entry configure -bg yellow \}
    "

    APSAddSCRDialog .scr \
      -parent $frame \
      -system LPL \
      -arrayName APSMpPARLETCondition \
      -defaultFile $APSMpPARLETCondition(SCRFile)
}

proc APSMpPARLETCondition {args} {
    set conditioningTime 14
    set PARdipole 1
    set PARquads 1
    set PARsextupoles 1
    set PARcorrectors 1
    set LTPdipole 1
    set LTPquads 1
    set LTPcorrectors 1
    set PTBdipole 1
    set PTBquads 1
    set PTBcorrectors 1
    set SCRFile ""
    APSStrictParseArguments {conditioningTime SCRFile PARdipole PARquads PARsextupoles PARcorrectors LTPdipole LTPquads LTPcorrectors PTBdipole PTBquads PTBcorrectors}
    global execMode

    if {$execMode != "Automatic"} {
        if {[catch {exec cavget -list=ACIS:LAOL_INH_GUN,ACIS:LBL_GUN_INH,ACIS:LA_BP_MODE,ACIS:LB_BP_MD -num -pend=20} acisState]} {
            APSMpReturn error "APSMpPARLETCondition: $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 "APSMpPARLETCondition: 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 "APSMpPARLETCondition: Linac/PAR is in an acis trip state."
            }
        }
    }

    global APSMpPARLETCondition
    set APSMpPARLETCondition(Filename) $SCRFile

    APSMpStep init -promptDialog APSMpPARLETConditionInitDialog \
      -vars {conditioningTime SCRFile PARdipole PARquads PARsextupoles PARcorrectors LTPdipole LTPquads LTPcorrectors PTBdipole PTBquads PTBcorrectors}

    if {[catch {APSLinkToLINACPVs} result]} {
	APSMpReturn error "LPL_Configure: $result"
    }

    set SCRFile $APSMpPARLETCondition(Filename)
    if {![llength $SCRFile]} {
        APSMpReturn error "APSMpPARLETCondition: No SCR file selected."
    }
    if {![file exists $SCRFile]} {
        APSMpReturn error "APSMpPARLETCondition: File $SCRFile not found."
    }
    if {[catch {exec sdds2stream $SCRFile -parameter=SnapshotDescription -page=1 -noquotes} results]} {
        APSMpReturn error "APSMpPARLETCondition: Invalid SCR file"
    }    
    if {[string first "Limited save:" $results] != -1} {
        APSMpReturn error "APSMpPARLETCondition: LIMITED SAVE SCR files cannot be used for this procedure."
    }

    set paramString ""
    foreach param {conditioningTime SCRFile PARdipole PARquads PARsextupoles PARcorrectors LTPdipole LTPquads LTPcorrectors PTBdipole PTBquads PTBcorrectors} {
        append paramString "$param=\"[set $param]\" "
    }
    catch {APSLogScriptAction -procedure APSMpPARLETCondition -action initialize \
             -state ok -parameters $paramString}
    

    #Check double stop
    if {$LTPdipole} {
        APSMpStep "Check that the linac-to-LEUTL (double stop) is open"
        if [catch {APScavget -list=ACIS:LAO_LTB_2S_CLSD -num} result] {
            APSMpReturn error "APSMpPARLETCondition: $result"
        }
        if {$result != 0} {
            if {[APSPEMTKDialog .warningDialog -text "The Linac to LEUTL double stop is not open. Please open the double stop then click continue."] == 1} {
                APSMpReturn error "APSMpPARLETCondition: the Linac to LEUTL double stop is not open"
            }
            if [catch {APScavget -list=ACIS:LAO_LTB_2S_CLSD -num} result] {
                APSMpReturn error "APSMpPARLETCondition: $result"
            }
            if {$result != 0} {
                if {[APSPEMTKDialog .warningDialog -text "The Linac to LEUTL double stop is still not open. Pressing continue will cause it to condition the LTP dipole with the double stop open. Press continue at your own risk."] == 1} {
                    APSMpReturn error "APSMpPARLETCondition: the Linac to LEUTL double stop is not open"
                }
            }

        }
    }


    #Turn on supplies
    if {[catch {APSMpPARLETTurnOnDCPS -PARdipole $PARdipole -PARquads $PARquads -PARsextupoles $PARsextupoles -PARcorrectors $PARcorrectors -LTPdipole $LTPdipole -LTPquads $LTPquads -LTPcorrectors $LTPcorrectors -PTBdipole $PTBdipole -PTBquads $PTBquads -PTBcorrectors $PTBcorrectors} results]} {
        if {[APSPEMTKDialog .warningDialog -text "APSMpPARLETCondition: $results"] == 1} {
            APSMpReturn error "APSMpPARLETCondition: $results"
        }
    }

    #Configure for conditioning
    APSMpStep "Configure for conditioning"
    set energy [APSPARLETDefaultEnergy]
    if {($PARdipole) || ($PARquads)} {
        set configFile /home/helios/oagData/controlFiles/PAR/P${energy}MeV.std
        set tmpfile /tmp/[APSTmpString]
        set tmpfile2 /tmp/[APSTmpString]
        set tmpfile3 /tmp/[APSTmpString]
        if {[catch {exec sddsprocess $configFile $tmpfile \
		      "-redefine=col,NumCycles,$conditioningTime Minutes Seconds 60 / + 2 * / int 4 > ? 4 : $conditioningTime Minutes Seconds 60 / + 2 * / int \$ ,type=long"} result]} {
            APSMpReturn error "APSMpPARLETCondition: Error during processing prior to standardizing: $result"
        }
        if {[catch {exec sddsprocess $SCRFile $tmpfile2 \
                      -match=column,ControlName=P:BM:CurrentAO,ControlName=P:Q*:CurrentAO,| \
                      -edit=column,ElementName,ControlName,%/:CurrentAO// \
                      -scan=column,Finish,ValueString,%le
            exec sddsconvert $tmpfile -pipe=out -delete=column,Finish \
                      | sddsxref -pipe=in $tmpfile2 $tmpfile3 \
                      -match=ControlName=ElementName -take=Finish -nowarning
            file rename -force $tmpfile3 $tmpfile
            file delete -force $tmpfile2} result]} {
            eval file delete -force $tmpfile $tmpfile2 $tmpfile3
            APSMpReturn error "APSMpPARLETCondition: Error setting up standardization of PAR BM and Q: $result"
        }
        if {[catch {exec standardize -configure $tmpfile } result]} {
            APSMpReturn error "APSMpPARLETCondition: Error configuring standardization of PAR BM and Q: $result"
        }
        file delete -force $tmpfile
    }
    if {$PARsextupoles} {
        #Ignore cycles variable
        set configFile /home/helios/oagData/controlFiles/PAR/P${energy}MeV.Sstd
        set tmpfile /tmp/[APSTmpString]
        set tmpfile2 /tmp/[APSTmpString]
        set tmpfile3 /tmp/[APSTmpString]
        if {[catch {exec sddsprocess $configFile $tmpfile \
		      "-redefine=col,NumCycles,$conditioningTime Minutes Seconds 60 / + 2 * / int 4 > ? 4 : $conditioningTime Minutes Seconds 60 / + 2 * / int \$ ,type=long"} result]} {
            APSMpReturn error "APSMpPARLETCondition: Error during processing prior to standardizing: $result"
        }
        set matchOption -match=column,ControlName=P:SD:*,ControlName=P:SF:*,|
        if {[catch {exec sddsprocess $SCRFile $tmpfile2 \
                      $matchOption \
                      -edit=column,ElementName,ControlName,%/:CurrentAO// \
                      -scan=column,Finish,ValueString,%le
            exec sddsconvert $tmpfile -pipe=out -delete=column,Finish \
                      | sddsxref -pipe=in $tmpfile2 $tmpfile3 \
                      -match=ControlName=ElementName -take=Finish -nowarning
            file rename -force $tmpfile3 $tmpfile
            file delete -force $tmpfile2} result]} {
            eval file delete -force $tmpfile $tmpfile2 $tmpfile3
            APSMpReturn error "APSMpPARLETCondition: Error setting up standardization of PAR sextupoles: $result"
        }
        if {[catch {exec standardize -configure $tmpfile } result]} {
            APSMpReturn error "APSMpPARLETCondition: Error initiating standardization of PAR sextupoles: $result"
        }
        file delete -force $tmpfile
    }
    if {$PARcorrectors} {
        set configFile /home/helios/oagData/controlFiles/PAR/PAR_degauss.sdds
        set tmpfile /tmp/[APSTmpString]
        set tmpfile2 /tmp/[APSTmpString]
        if {[catch {exec sddsprocess $configFile $tmpfile -nowarning -match=column,ControlName=P*H1} result]} {
            APSMpReturn error "APSMpPARLETCondition: Error initiating degaussing for PAR correctors: $result"
        }
        if {0} {
            if {[catch {exec sddsconvert $tmpfile -pipe=out -delete=col,DecayMinutes,DecaySeconds | \
                          sddsprocess -pipe=in $tmpfile2 \
                          "-define=col,DecayTime,$conditioningTime NumDecay /" \
                          "-define=col,DecayMinutes,DecayTime int,type=long" \
                          "-define=col,DecaySeconds,DecayTime DecayMinutes - 60 * int,type=long"} result]} {
                APSMpReturn error "APSMpPARLETCondition: Error initiating degaussing for PAR correctors: $result"
            }
        }
        while {1} {
            if {[catch {APScavput -list=P:S1:CurrentAO=0,P1H2:CurrentAO=0,P1H3:CurrentAO=0,P1V1:CurrentAO=0,P1V2:CurrentAO=0,P1V3:CurrentAO=0,P2H2:CurrentAO=0,P2H3:CurrentAO=0,P2V1:CurrentAO=0,P2V2:CurrentAO=0,P2V3:CurrentAO=0,P3H2:CurrentAO=0,P3V1:CurrentAO=0,P3V2:CurrentAO=0,P4H2:CurrentAO=0,P4V1:CurrentAO=0,P4V2:CurrentAO=0 -pend=20} result]} {
                if {[APSPEMTKDialog .warningDialog -text "APSMpPARLETCondition: Unable to set some PAR correctors to 0: $result"] == 1} {
                    APSMpReturn error "APSMpPARLETCondition: Unable to set some PAR correctors to 0: $result"
                }
                continue
            }
            break
        }
        if {0} {
            if {[catch {exec degauss -configure $tmpfile2} result]} {
                APSMpReturn error "APSMpPARLETCondition: Error initiating degaussing for PAR correctors: $result"
            }
            file delete -force $tmpfile $tmpfile2
        } else {
            if {[catch {exec degauss -configure $tmpfile} result]} {
                APSMpReturn error "APSMpPARLETCondition: Error initiating degaussing for PAR correctors: $result"
            }
            file delete -force $tmpfile
        }
    }
    if {($LTPdipole) || ($LTPquads)} {
        set configFile /home/helios/oagData/controlFiles/LTP/LTPe${energy}MeV.std
        set tmpfile /tmp/[APSTmpString]
        set tmpfile2 /tmp/[APSTmpString]
        set tmpfile3 /tmp/[APSTmpString]
        if {[catch {exec sddsprocess $configFile $tmpfile \
		      "-redefine=col,NumCycles,$conditioningTime Minutes Seconds 60 / + 2 * / int 4 > ? 4 : $conditioningTime Minutes Seconds 60 / + 2 * / int \$ ,type=long"} result]} {
            APSMpReturn error "APSMpPARLETCondition: Error during processing prior to standardizing: $result"
        }
        if {[catch {exec sddsprocess $SCRFile $tmpfile2 \
                      -match=column,ControlName=LTP:B*,ControlName=LTP:Q*,| \
                      -edit=column,ElementName,ControlName,%/:CurrentAO// \
                      -scan=column,Finish,ValueString,%le
            exec sddsconvert $tmpfile -pipe=out -delete=column,Finish \
                      | sddsxref -pipe=in $tmpfile2 $tmpfile3 \
                      -match=ControlName=ElementName -take=Finish -nowarning
            file rename -force $tmpfile3 $tmpfile
            file delete -force $tmpfile2} result]} {
            eval file delete -force $tmpfile $tmpfile2 $tmpfile3
            APSMpReturn error "APSMpPARLETCondition: Error setting up standardization of PAR BM and Q: $result"
        }
        if {[catch {exec standardize -configure $tmpfile } result]} {
            APSMpReturn error "APSMpPARLETCondition: Error configuring standardization of PAR BM and Q: $result"
        }
        file delete -force $tmpfile
    }
    if {$LTPdipole} {
        while {1} {
            if {[catch {APScavput -list=LTP:B1:modeSetC=0 -pend=20} result]} {
                if {[APSPEMTKDialog .warningDialog -text "APSMpPARLETCondition: Unable to set LTP:B1:modeSetC=0"] == 1} {
                    APSMpReturn error "APSMpPARLETCondition: Error setting LTP:B1 to DC Mode: $result"
                }
                continue
            }
            break
        }
    }
    if {$LTPcorrectors} {
        set configFile /home/helios/oagData/controlFiles/LTP/LTP_degauss.sdds
        set tmpfile /tmp/[APSTmpString]
	if {[catch {exec sddsconvert $configFile -pipe=out -delete=col,DecayMinutes,DecaySeconds | \
		      sddsprocess -pipe=in $tmpfile \
		      "-define=col,DecayTime,$conditioningTime NumDecay /" \
		      "-define=col,DecayMinutes,DecayTime int,type=long" \
		      "-define=col,DecaySeconds,DecayTime DecayMinutes - 60 * int,type=long"} result]} {
	    APSMpReturn error "APSMpPARLETCondition: Error initiating degaussing for LTP correctors: $result"
	}
        if {[catch {exec degauss -configure $tmpfile} result]} {
            APSMpReturn error "APSMpPARLETCondition: Error initiating degaussing for LTP correctors: $result"
        }
	file delete -force $tmpfile
    }
    if {($PTBdipole) || ($PTBquads)} {
        set configFile /home/helios/oagData/controlFiles/PTB/PTB${energy}MeV.std
        set tmpfile /tmp/[APSTmpString]
        set tmpfile2 /tmp/[APSTmpString]
        set tmpfile3 /tmp/[APSTmpString]
        if {[catch {exec sddsprocess $configFile $tmpfile \
		      "-redefine=col,NumCycles,$conditioningTime Minutes Seconds 60 / + 2 * / int 4 > ? 4 : $conditioningTime Minutes Seconds 60 / + 2 * / int \$ ,type=long"} result]} {
            APSMpReturn error "APSMpPARLETCondition: Error during processing prior to standardizing: $result"
        }
        if {[catch {exec sddsprocess $SCRFile $tmpfile2 \
                      -match=column,ControlName=PTB:B*,ControlName=PTB:Q*,| \
                      -edit=column,ElementName,ControlName,%/:CurrentAO// \
                      -scan=column,Finish,ValueString,%le
            exec sddsconvert $tmpfile -pipe=out -delete=column,Finish \
                      | sddsxref -pipe=in $tmpfile2 $tmpfile3 \
                      -match=ControlName=ElementName -take=Finish -nowarning
            file rename -force $tmpfile3 $tmpfile
            file delete -force $tmpfile2} result]} {
            eval file delete -force $tmpfile $tmpfile2 $tmpfile3
            APSMpReturn error "APSMpPARLETCondition: Error setting up standardization of PAR BM and Q: $result"
        }
        if {[catch {exec standardize -configure $tmpfile } result]} {
            APSMpReturn error "APSMpPARLETCondition: Error configuring standardization of PAR BM and Q: $result"
        }
        file delete -force $tmpfile
    }
    if {$PTBdipole} {
        while {1} {
            if {[catch {APScavput -list=PTB:B1:modeSetC=0 -pend=20} result]} {
                if {[APSPEMTKDialog .warningDialog -text "APSMpPARLETCondition: Unable to set PTB:B1:modeSetC=0"] == 1} {
                    APSMpReturn error "APSMpPARLETCondition: Error setting PTB:B1 to DC Mode: $result"
                }
                continue
            }
            if {[catch {APScavput -list=PTB:B2:modeSetC=0 -pend=20} result]} {
                if {[APSPEMTKDialog .warningDialog -text "APSMpPARLETCondition: Unable to set PTB:B2:modeSetC=0"] == 1} {
                    APSMpReturn error "APSMpPARLETCondition: Error setting PTB:B2 to DC Mode: $result"
                }
                continue
            }
            break
        }
    }
    if {$PTBcorrectors} {
        set configFile /home/helios/oagData/controlFiles/PTB/PTB_degauss.sdds
        set tmpfile /tmp/[APSTmpString]
	if {[catch {exec sddsconvert $configFile -pipe=out -delete=col,DecayMinutes,DecaySeconds | \
		      sddsprocess -pipe=in $tmpfile \
		      "-define=col,DecayTime,$conditioningTime NumDecay /" \
		      "-define=col,DecayMinutes,DecayTime int,type=long" \
		      "-define=col,DecaySeconds,DecayTime DecayMinutes - 60 * int,type=long"} result]} {
	    APSMpReturn error "APSMpPARLETCondition: Error initiating degaussing for PTB correctors: $result"
	}
        if {[catch {exec degauss -configure $tmpfile} result]} {
            APSMpReturn error "APSMpPARLETCondition: Error initiating degaussing for PTB correctors: $result"
        }
	file delete -force $tmpfile
    }

    #Start conditioning
    APSMpStep "Start conditioning"
    set conditionPV ""
    if {$PARdipole} {
        append conditionPV "P:BM "
    }
    if {$PARquads} {
        append conditionPV "P:Q1 P:Q2 P:Q3BP P:Q4 "
    }
    if {$PARsextupoles} {
        append conditionPV "P:SD P:SF "
    }
    if {$PARcorrectors} {
        append conditionPV "P1H1 P2H1 P3H1 P4H1 "
    }
    if {$LTPdipole} {
        if {[catch {exec cavget -list=L5:AM1:PS2:overTempBI -num} result]} {
            APSMpReturn error "Unable to read L5:AM1:PS2:overTempBI: $result"
        }
        if {$result == 0} {
            if {[catch {exec cavput -list=L5:AM1:PS2:resetBO=1} result]} {
                APSMpReturn error "Unable to reset over temp fault for L5:AM1: $result"
            }
            APSWaitWithUpdate -waitSeconds 2
        }
        if [catch {APSDevSend -group LinacPS -operation QueryOff -deviceList "L3:AM1"} result] {
            APSMpReturn error "APSMpPARLETCondition: $result"
        }
        if {$result} {
            #This is really a reset. It will set the current to 0.
            if {[catch {APSDevSend \
                          -group LinacPS \
                          -operation TurnOn \
                          -deviceList "L3:AM1 L5:AM1"} result]} {
                if {[APSPEMTKDialog .warningDialog -text "Unable turn on L3:AM1 and/or L5:AM1.\nAPSMpPARLETCondition: $result"] == 1} {
                    APSMpReturn error "Unable turn on L3:AM1 and/or L5:AM1: APSMpPARLETCondition: $result"
                }
            }
            APSWaitWithUpdate -waitSeconds 15
        }
        if [catch {APSDevSend \
                     -releaseLinks 1 \
                     -group LinacPS \
                     -operation SetCurrent \
                     -deviceList L3:AM1 \
                     -valueList 63 \
                     -timeout 0} result] {
            APSMpReturn error "APSMpPARLETCondition: $result"
        }
        APSWaitWithUpdate -waitSeconds 15
        set try 10
        while {$try >= 0} {
            incr try -1
            if {[catch {exec cavget -list=L3:AM1:readyCC,L3:AM1:CurrentAI} result]} {
                APSMpReturn error "Unable to read current for L3:AM1: APSMpPARLETCondition: $result"
            }
            if {([lindex $result 0] == 1) && ([lindex $result 1] > 60)} {
                break
            }
            APSWaitWithUpdate -waitSeconds 5
        }
        if {$try == -1} {
            if {([lindex $result 0] != 1) || ([lindex $result 1] <= 60)} {
                if {[APSPEMTKDialog .warningDialog -text "Unable to set L3:AM1 63amps. Please fix manually and then click Continue."] == 1} {
                    APSMpReturn error "Unable to set L3:AM1 to 63amps. Aborted by operator"
                }
            }
        }
        
        append conditionPV "LTP:B1 "
    }
    if {$LTPquads} {
        append conditionPV "LTP:Q1 LTP:Q2 LTP:Q3 LTP:Q4 LTP:Q5 LTP:Q6 LTP:Q7 LTP:Q8 LTP:Q9 LTP:Q10 "
    }
    if {$LTPcorrectors} {
        append conditionPV "LTP:H1 LTP:H2 LTP:H3 LTP:H4 LTP:V1 LTP:V2 LTP:V3 LTP:V4 "
    }
    if {$PTBdipole} {
        append conditionPV "PTB:B1 PTB:B2 "
    }
    if {$PTBquads} {
        append conditionPV "PTB:Q1 PTB:Q2 PTB:Q3 PTB:Q4 PTB:Q5 PTB:Q6 PTB:Q7 PTB:Q8 PTB:Q9 PTB:Q10 PTB:Q11 "
    }
    if {$PTBcorrectors} {
        append conditionPV "PTB:H1 PTB:H2 PTB:H3 PTB:H4 PTB:V1 PTB:V2 PTB:V3 PTB:V4 "
    }

    if {![llength $conditionPV]} {
        APSMpReturn ok
    }
    #First stop any existing conditioning.
    if {[catch {APScavput -list=[join $conditionPV ,] -list=:StandardizeSUB.PROC=0 -pend=20} result]} {
        APSMpReturn error "APSMpPARLETCondition: Error initiating conditioning of $conditionPV: $result"
    }
    APSWaitWithUpdate -waitSeconds 5

    #Now start conditioning
    if {[catch {APScavput -list=[join $conditionPV ,] -list=:StandardizeSUB.PROC=1 -pend=20} result]} {
        APSMpReturn error "APSMpPARLETCondition: Error initiating conditioning of $conditionPV: $result"
    }
    
    APSMpStep "Check that all selected DC power supplies are conditioning"
    if {[catch {APScavget -list=[join $conditionPV ,] -list=:StandardizeSUB.PROC -label -pend=20} condList]} {
        APSMpReturn error "APSMpPARLETCondition: Error checking the see if the power supplies are conditioning: $condList"
    }
    set problemCond [APSSearchAssociateListForValue -list $condList -value 0]
    if {[llength $problemCond]} {
        APSMpReturn error "APSMpPARLETCondition: [llength $problemCond] magnets not conditioning as expected."
    }
    APSWaitWithUpdate -waitSeconds 10

    #Wait for conditioning to finish
    if {($PARdipole) || ($PARquads)} {
        lappend condCheckPVList "P:Q:BM:CondCALC"
    }
    if {$PARsextupoles} {
        lappend condCheckPVList "P:S:CondCALC"
    }
    if {$PARcorrectors} {
        lappend condCheckPVList "P:HV:CondCALC"
    }
    if {($LTPdipole) || ($LTPquads)} {
        lappend condCheckPVList "LTP:Q:BM:CondCALC"
    }
    if {$LTPcorrectors} {
        lappend condCheckPVList "LTP:HV:CondCALC"
    }
    if {($PTBdipole) || ($PTBquads)} {
        lappend condCheckPVList "PTB:Q:BM:CondCALC"
    }
    if {$PTBcorrectors} {
        lappend condCheckPVList "PTB:HV:CondCALC"
    }
    set condStep 0
    while {1} {
        if {$condStep == 0} {
            APSMpStep "Waiting for conditioning to finish"
        }
        incr condStep
        if {$condStep >= 10} {
            set condStep 0
        }
        if {[catch {APScavget -label -pend=20 -list=[join $condCheckPVList ,]} condList]} {
            APSMpReturn error "APSMpPARLETCondition: Error checking the see if the power supplies are conditioning: $condList"
        }
        set problemCond [APSSearchAssociateListForValue -list $condList -value ?]
        if {[llength $problemCond]} {
            if {[APSPEMTKDialog .warningDialog -text "APSMpPARLETCondition: Error reading PVs: $problemCond"] == 1} {
                APSMpReturn error "APSMpPARLETCondition: Error checking the see if the power supplies are conditioning: $condList"
            }
        }
        set doneCond [APSSearchAssociateListForValue -list $condList -value 0]
        if {[llength $doneCond] == [llength $condCheckPVList]} {
            break
        }
        APSWaitWithUpdate -waitSeconds 2
    }
    if {$LTPdipole} {
        if [catch {APSDevSend \
                     -releaseLinks 1 \
                     -group LinacPS \
                     -operation SetCurrent \
                     -deviceList L3:AM1 \
                     -valueList 0 \
                     -timeout 0} result] {
            APSMpReturn error "APSMpPARLETCondition: $result"
        }
        set try 30
        while {$try >= 0} {
            APSWaitWithUpdate -waitSeconds 1
            if {[catch {exec cavget -list=L3:AM1:CurrentAI} result]} {
                APSMpReturn error "Unable to read current for L3:AM1: APSMpPARLETCondition: $result"
            }
            if {$result <= 3} {
                break
            }
            incr try -1
        }
        if {[catch {APSDevSend \
                      -group LinacPS \
                      -operation TurnOff \
                      -deviceList L3:AM1} result]} {
            if {[APSPEMTKDialog .warningDialog -text "Unable turn off L3:AM1.\nAPSMpPARLETCondition: $result"] == 1} {
                APSMpReturn error "Unable turn off L3:AM1: APSMpPARLETCondition: $result"
            }
        }
    }
    #Restore corrector values
    APSMpStep "Restore SCR values"
    set tmpfile /tmp/[APSTmpString]
    set i 0
    set option ""
    if {$PARcorrectors} {
        if {$i == 0} {
            append option "-match=col,Beamline=PAR"
        } else {
            append option ",Beamline=PAR,|"
        }
        incr i
    }
    if {$LTPcorrectors} {
        if {$i == 0} {
            append option "-match=col,Beamline=LTP,Beamline=LTP1,|,Beamline=LTP2,|"
        } else {
            append option ",Beamline=LTP,|,Beamline=LTP1,|,Beamline=LTP2,|"
        }
        incr i
    }
    if {$PTBcorrectors} {
        if {$i == 0} {
            append option "-match=col,Beamline=PTB,Beamline=PTB1,|,Beamline=PTB2,|,Beamline=PTB3,|"
        } else {
            append option ",Beamline=PTB,|,Beamline=PTB1,|,Beamline=PTB2,|,Beamline=PTB3,|"
        }
        incr i
    }
    if {[llength $option]} {
        if [catch \
              {exec sddsprocess $SCRFile $tmpfile \
                 $option \
                 -match=col,Category=SteeringPS \
                 -match=column,ControlName=*H*,ControlName=*V*,| \
                 -match=col,IsReadOnly=+y,! \
                 -match=col,ValueString=,! } result] {
            if {[APSPEMTKDialog .warningDialog -text "APSMpPARLETCondition: Error during processing prior restoring file $SCRFile: $result"] == 1} {
                APSMpReturn error "APSMpPARLETCondition: Error during processing prior restoring file $SCRFile: $result"
            }
        }
        if {[catch {exec sddscasr -restore $tmpfile} result]} {
            catch {APSSendEMail -address soliday \
                     -subject "Problem restoring SCR file."  \
                     -message "Problem restore SCR file\nAPSMpPARLETCondition\n${SCRFile}\n$result"}
        }
        file delete -force $tmpfile
    }

    set i 0
    set option ""
    if {$PARquads} {
        if {$i == 0} {
            append option "-match=col,Beamline=PAR"
        } else {
            append option ",Beamline=PAR,|"
        }
        incr i
    }
    if {$LTPquads} {
        if {$i == 0} {
            append option "-match=col,Beamline=LTP,Beamline=LTP1,|,Beamline=LTP2,|"
        } else {
            append option ",Beamline=LTP,|,Beamline=LTP1,|,Beamline=LTP2,|"
        }
        incr i
    }
    if {$PTBquads} {
        if {$i == 0} {
            append option "-match=col,Beamline=PTB,Beamline=PTB1,|,Beamline=PTB2,|,Beamline=PTB3,|"
        } else {
            append option ",Beamline=PTB,|,Beamline=PTB1,|,Beamline=PTB2,|,Beamline=PTB3,|"
        }
        incr i
    }
    if {[llength $option]} {
        if [catch \
              {exec sddsprocess $SCRFile $tmpfile \
                 $option \
                 -match=col,Category=MainPS \
                 -match=column,ControlName=*Q*:CurrentAO \
                 -match=col,IsReadOnly=+y,! \
                 -match=col,ValueString=,! } result] {
            if {[APSPEMTKDialog .warningDialog -text "APSMpPARLETCondition: Error during processing prior restoring file $SCRFile: $result"] == 1} {
                APSMpReturn error "APSMpPARLETCondition: Error during processing prior restoring file $SCRFile: $result"
            }
        }
        if {[catch {exec sddscasr -restore $tmpfile} result]} {
            catch {APSSendEMail -address soliday \
                     -subject "Problem restoring SCR file."  \
                     -message "Problem restore SCR file\nAPSMpPARLETCondition\n${SCRFile}\n$result"}
        }
        file delete -force $tmpfile
    }


    set i 0
    set option ""
    if {$PARdipole} {
        if {$i == 0} {
            append option "-match=col,Beamline=PAR"
        } else {
            append option ",Beamline=PAR,|"
        }
        incr i
    }
    if {$LTPdipole} {
        if {$i == 0} {
            append option "-match=col,Beamline=LTP,Beamline=LTP1,|,Beamline=LTP2,|"
        } else {
            append option ",Beamline=LTP,|,Beamline=LTP1,|,Beamline=LTP2,|"
        }
        incr i
    }
    if {$PTBdipole} {
        if {$i == 0} {
            append option "-match=col,Beamline=PTB,Beamline=PTB1,|,Beamline=PTB2,|,Beamline=PTB3,|"
        } else {
            append option ",Beamline=PTB,|,Beamline=PTB1,|,Beamline=PTB2,|,Beamline=PTB3,|"
        }
        incr i
    }
    if {[llength $option]} {
        if [catch \
              {exec sddsprocess $SCRFile $tmpfile \
                 $option \
                 -match=col,Category=MainPS,Category=SteeringPS,| \
                 -match=column,ControlName=LTP:B?:CurrentAO,ControlName=PTB:B?:CurrentAO,|,ControlName=P:BM:CurrentAO,|,ControlName=P?BMT?:CurrentAO,| \
                 -match=col,IsReadOnly=+y,! \
                 -match=col,ValueString=,! } result] {
            if {[APSPEMTKDialog .warningDialog -text "APSMpPARLETCondition: Error during processing prior restoring file $SCRFile: $result"] == 1} {
                APSMpReturn error "APSMpPARLETCondition: Error during processing prior restoring file $SCRFile: $result"
            }
        }
        if {[catch {exec sddscasr -restore $tmpfile} result]} {
            catch {APSSendEMail -address soliday \
                     -subject "Problem restoring SCR file."  \
                     -message "Problem restore SCR file\nAPSMpPARLETCondition\n${SCRFile}\n$result"}
        }
        file delete -force $tmpfile
    }

    if {$PARsextupoles} {
	set option "-match=col,Beamline=PAR"
        if [catch \
              {exec sddsprocess $SCRFile $tmpfile \
                 $option \
                 -match=col,Category=MainPS \
                 -match=column,ControlName=P:SF:CurrentAO,ControlName=P:SD:CurrentAO,| \
                 -match=col,IsReadOnly=+y,! \
                 -match=col,ValueString=,! } result] {
            if {[APSPEMTKDialog .warningDialog -text "APSMpPARLETCondition: Error during processing prior restoring file $SCRFile: $result"] == 1} {
                APSMpReturn error "APSMpPARLETCondition: Error during processing prior restoring file $SCRFile: $result"
            }
        }
        if {[catch {exec sddscasr -restore $tmpfile} result]} {
            catch {APSSendEMail -address soliday \
                     -subject "Problem restoring SCR file."  \
                     -message "Problem restore SCR file\nAPSMpPARLETCondition\n${SCRFile}\n$result"}
        }
        file delete -force $tmpfile
    }



    APSMpReturn ok
}

proc APSMpPARLETTurnOnDCPSInfo {} {
    return "This procedure will allow the user to select which DCPS should be turned on. It then turns them on if they are off."
}

proc APSMpPARLETTurnOnDCPSInitDialog {frame} {
    global APSMpPARLETTurnOnDCPS

    pack [frame $frame.frame]
    APSCheckButtonFrame .cb1 \
      -parent $frame.frame \
      -label "PAR PS" \
      -packOption "-side left" \
      -allNone 1 \
      -buttonList {"Dipole" "Quads" "Sextupoles" "Correctors"} \
      -variableList {APSMpPARLETTurnOnDCPS(PARdipole) \
                       APSMpPARLETTurnOnDCPS(PARquads) \
                       APSMpPARLETTurnOnDCPS(PARsextupoles) \
                       APSMpPARLETTurnOnDCPS(PARcorrectors)}

    APSCheckButtonFrame .cb2 \
      -parent $frame.frame \
      -label "LTP PS" \
      -packOption "-side left" \
      -allNone 1 \
      -buttonList {"Dipole" "Quads" "Correctors"} \
      -variableList {APSMpPARLETTurnOnDCPS(LTPdipole) \
                       APSMpPARLETTurnOnDCPS(LTPquads) \
                       APSMpPARLETTurnOnDCPS(LTPcorrectors)}
    
    APSCheckButtonFrame .cb3 \
      -parent $frame.frame \
      -label "PTB PS" \
      -packOption "-side left" \
      -allNone 1 \
      -buttonList {"Dipole" "Quads" "Correctors"} \
      -variableList {APSMpPARLETTurnOnDCPS(PTBdipole) \
                       APSMpPARLETTurnOnDCPS(PTBquads) \
                       APSMpPARLETTurnOnDCPS(PTBcorrectors)}
}


proc APSMpPARLETTurnOnDCPS {args} {
    set PARdipole 1
    set PARquads 1
    set PARsextupoles 1
    set PARcorrectors 1
    set LTPdipole 1
    set LTPquads 1
    set LTPcorrectors 1
    set PTBdipole 1
    set PTBquads 1
    set PTBcorrectors 1
    APSStrictParseArguments {PARdipole PARquads PARsextupoles PARcorrectors \
                         LTPdipole LTPquads LTPcorrectors \
                         PTBdipole PTBquads PTBcorrectors}

    global execMode

    if {$execMode != "Automatic"} {
        if {[catch {exec cavget -list=ACIS:LAOL_INH_GUN,ACIS:LBL_GUN_INH,ACIS:LA_BP_MODE,ACIS:LB_BP_MD -num -pend=20} acisState]} {
            APSMpReturn error "APSMpPARLETTurnOnDCPS: $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 "APSMpPARLETTurnOnDCPS: 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 "APSMpPARLETTurnOnDCPS: Linac/PAR is in an acis trip state."
            }
        }
    }


    APSMpStep init -promptDialog APSMpPARLETTurnOnDCPSInitDialog \
      -vars {PARdipole PARquads PARsextupoles PARcorrectors \
               LTPdipole LTPquads LTPcorrectors \
               PTBdipole PTBquads PTBcorrectors}

    set paramString ""
    foreach param {PARdipole PARquads PARsextupoles PARcorrectors LTPdipole LTPquads LTPcorrectors PTBdipole PTBquads PTBcorrectors} {
        append paramString "$param=\"[set $param]\" "
    }
    catch {APSLogScriptAction -procedure APSMpPARLETTurnOnDCPS -action initialize \
             -state ok -parameters $paramString}


    #Check MPEOB
    APSMpStep "Check that the MPEOBs are pulled out"
    while {1} {
        if {[catch {APSPLETMPEOBsAreOut} mpeob]} {
            if {[APSPEMTKDialog .warningDialog -text "APSMpPARLETTurnOnDCPS: Error checking MPEOB: $mpeob"] == 1} {
                APSMpReturn error "APSMpPARLETTurnOnDCPS: Error checking MPEOB: $mpeob"
            }
            continue
        }
        if {!$mpeob} {
            if {[APSPEMTKDialog .warningDialog -text "APSMpPARLETTurnOnDCPS: Both MPEOBs must be pulled out to start DCPS."] == 1} {
                APSMpReturn error "APSMpPARLETTurnOnDCPS: Both MPEOBs must be pulled out to start DCPS."
            }
            continue
        }
        break
    }

    #Turn on supplies
    APSMpStep "Turning on selected DC power supplies"
    set pause 0
    set statusPV ""
    if {$PARdipole} {
        append statusPV "P:BM:StatusCALC \
                         P1BMT1:StatusCALC P1BMT2:StatusCALC \
                         P2BMT1:StatusCALC P2BMT2:StatusCALC \
                         P3BMT1:StatusCALC P3BMT2:StatusCALC \
                         P4BMT1:StatusCALC P4BMT2:StatusCALC "
        if {$pause < 24} { set pause 24 }
    }
    if {$PARquads} {
        append statusPV "P:Q1:StatusCALC P:Q2:StatusCALC P:Q3BP:StatusCALC P:Q4:StatusCALC "
        if {$pause < 24} { set pause 24 }
    }
    if {$PARsextupoles} {
        append statusPV "P:SF:StatusCALC P:SD:StatusCALC P:S1:StatusCALC "
        if {$pause < 24} { set pause 24 }
    }
    if {$PARcorrectors} {
        append statusPV "P1H1:StatusCALC P1H2:StatusCALC P1H3:StatusCALC \
                         P2H1:StatusCALC P2H3:StatusCALC \
                         P3H1:StatusCALC P3H2:StatusCALC \
                         P4H1:StatusCALC P4H2:StatusCALC \
                         P1V1:StatusCALC P1V2:StatusCALC \
                         P1V3:StatusCALC P2V1:StatusCALC \
                         P2V2:StatusCALC P2V3:StatusCALC \
                         P3V1:StatusCALC P3V2:StatusCALC \
                         P4V1:StatusCALC P4V2:StatusCALC "
        if {$pause < 24} { set pause 24 }
    }
    if {$LTPdipole} {
        append statusPV "LTP:B1:StatusCALC "
        if {$pause < 8} { set pause 8 }
        while {1} {
            if {[catch {APScavget -list=LTP:B1:StatusCALC -num -pend=20} LTPB1] || [string compare $LTPB1 ?]==0} {
                if {[APSPEMTKDialog .warningDialog -text "APSMpPARLETTurnOnDCPS: Unable to connect to LTP:B1:StatusCALC"] == 1} {
                    APSMpReturn error "APSMpPARLETTurnOnDCPS: Unable to connect to LTP:B1:StatusCALC"
                }
                continue
            }
            break
        }
    }
    if {$LTPquads} {
        append statusPV "LTP:Q1:StatusCALC LTP:Q2:StatusCALC LTP:Q3:StatusCALC \
                         LTP:Q4:StatusCALC LTP:Q5:StatusCALC LTP:Q6:StatusCALC \
                         LTP:Q7:StatusCALC LTP:Q8:StatusCALC LTP:Q9:StatusCALC \
                         LTP:Q10:StatusCALC "
        if {$pause < 8} { set pause 8 }
    }
    if {$LTPcorrectors} {
        append statusPV "LTP:H1:StatusCALC LTP:H2:StatusCALC LTP:H3:StatusCALC \
                         LTP:H4:StatusCALC LTP:V1:StatusCALC LTP:V2:StatusCALC \
                         LTP:V3:StatusCALC LTP:V4:StatusCALC "
        if {$pause < 8} { set pause 8 }
    }
    if {$PTBdipole} {
        append statusPV "PTB:B1:StatusCALC PTB:B2:StatusCALC "
        if {$pause < 8} { set pause 8 }
        while {1} {
            if {[catch {APScavget -list=PTB:B1:StatusCALC -num -pend=20} PTBB1] || [string compare $PTBB1 ?]==0} {
                if {[APSPEMTKDialog .warningDialog -text "APSMpPARLETTurnOnDCPS: Unable to connect to PTB:B1:StatusCALC"] == 1} {
                    APSMpReturn error "APSMpPARLETTurnOnDCPS: Unable to connect to PTB:B1:StatusCALC"
                }
                continue
            }
            break
        }
        while {1} {
            if {[catch {APScavget -list=PTB:B2:StatusCALC -num -pend=20} PTBB2] || [string compare $PTBB2 ?]==0} {
                if {[APSPEMTKDialog .warningDialog -text "APSMpPARLETTurnOnDCPS: Unable to connect to PTB:B2:StatusCALC"] == 1} {
                    APSMpReturn error "APSMpPARLETTurnOnDCPS: Unable to connect to PTB:B2:StatusCALC"
                }
                continue
            }
            break
        }
    }
    if {$PTBquads} {
        append statusPV "PTB:Q1:StatusCALC PTB:Q2:StatusCALC PTB:Q3:StatusCALC \
                         PTB:Q4:StatusCALC PTB:Q5:StatusCALC PTB:Q6:StatusCALC \
                         PTB:Q7:StatusCALC PTB:Q8:StatusCALC PTB:Q9:StatusCALC \
                         PTB:Q10:StatusCALC PTB:Q11:StatusCALC "
        if {$pause < 8} { set pause 8 }
    }
    if {$PTBcorrectors} {
        append statusPV "PTB:H1:StatusCALC PTB:H2:StatusCALC PTB:H3:StatusCALC \
                         PTB:H4:StatusCALC PTB:V1:StatusCALC PTB:V2:StatusCALC \
                         PTB:V3:StatusCALC PTB:V4:StatusCALC "
        if {$pause < 8} { set pause 8 }
    }
    if {[llength $statusPV]} {
        set retries 5
        while {$retries} {
            while {1} {
                if {[catch {APScavget -list=[join $statusPV ,] -label -pend=20} statusList]} {
                    if {[APSPEMTKDialog .warningDialog -text "APSMpPARLETTurnOnDCPS: Unable to connect to PVs: $statusList"] == 1} {
                        APSMpReturn error "APSMpPARLETTurnOnDCPS: unable to connect to PVs: $statusList"
                    }
                    continue
                }
                set invalidList [APSSearchAssociateListForValue -list $statusList -value ?]
                if {[llength $invalidList]} {
                    if {[APSPEMTKDialog .warningDialog -text "APSMpPARLETTurnOnDCPS: Unable to connect to PVs: $invalidList"] == 1} {
                        APSMpReturn error "APSMpPARLETTurnOnDCPS: unable to connect to PVs: $invalidList"
                    }
                    continue
                }
                break
            }
            set toDoList0 [APSSearchAssociateListForValue -list $statusList -value 2]
            set toDoList [concat $toDoList0 [APSSearchAssociateListForValue -list $statusList -value 3]]
            regsub -all {:StatusCALC} $toDoList {} toDoList
            if {([llength $toDoList]) && ($retries != 1)} {
                while {1} {
                    if {[catch {APScavput -list=[join $toDoList ,] -list=:ResetSEQ=1 -pend=20} result]} {
                        if {[APSPEMTKDialog .warningDialog -text "APSMpPARLETTurnOnDCPS: Error sending on commands to power supplies ([join $toDoList ,]): $result"] == 1} {
                            APSMpReturn error "APSMpPARLETTurnOnDCPS: Error sending on commands to power supplies ([join $toDoList ,]): $result"
                        }
                        continue
                    }
                    break
                }
                if {$LTPdipole} {
                    if {$LTPB1} {
                        after 50
                        while {1} {
                            if [catch {APScavput -list=LTP:B1:OnSEQ=1 -pend=20} result] {
                                if {[APSPEMTKDialog .warningDialog -text "APSMpPARLETTurnOnDCPS: Error setting LTP:B1:OnSEQ=1: $result"] == 1} {
                                    APSMpReturn error "APSMpPARLETTurnOnDCPS: Error setting LTP:B1:OnSEQ=1: $result"
                                }
                                continue
                            }
                            break
                        }
                    }
                }
                if {$PTBdipole} {
                    if {$PTBB1} {
                        after 50
                        while {1} {
                            if [catch {APScavput -list=PTB:B1:OnSEQ=1 -pend=20} result] {
                                if {[APSPEMTKDialog .warningDialog -text "APSMpPARLETTurnOnDCPS: Error setting PTB:B1:OnSEQ=1: $result"] == 1} {
                                    APSMpReturn error "APSMpPARLETTurnOnDCPS: Error setting PTB:B1:OnSEQ=1: $result"
                                }
                                continue
                            }
                            break
                        }
                    }
                    if {$PTBB2} {
                        after 50
                        while {1} {
                            if [catch {APScavput -list=PTB:B2:OnSEQ=1 -pend=20} result] {
                                if {[APSPEMTKDialog .warningDialog -text "APSMpPARLETTurnOnDCPS: Error setting PTB:B2:OnSEQ=1: $result"] == 1} {
                                    APSMpReturn error "APSMpPARLETTurnOnDCPS: Error setting PTB:B2:OnSEQ=1: $result"
                                }
                                continue
                            }
                            break
                        }
                    }
                }
                APSWaitWithUpdate -waitSeconds $pause
            } else {
                break
            }
            incr retries -1
        }
        #Check to see if any PS did not turn on
        APSMpStep "Check to see if any selected DC power supplies failed to turn on"
        set status2List0 [APSSearchAssociateListForValue -list $statusList -value 2]
        set status2List [concat $status2List0 [APSSearchAssociateListForValue -list $statusList -value 3]]
        if {[llength $status2List]} {
            if {[APSPEMTKDialog .warningDialog -text "APSMpPARLETTurnOnDCPS: Unable to turn on DC power supplies: $status2List"] == 1} {
                APSMpReturn error "APSMpPARLETTurnOnDCPS: Unable to turn on DC power supplies: $status2List."
            }
        }

        set status1List [APSSearchAssociateListForValue -list $statusList -value 1]
        if {[llength $status1List]} {
            regsub -all :StatusCALC [join $status1List ,] "" probList
            if {[APSPEMTKDialog .warningDialog -text "APSMpPARLETTurnOnDCPS: Some DC power supplies may need manual turn on.  Look at these supplies: $probList"] == 1} {
                APSMpReturn error "APSMpPARLETTurnOnDCPS: Some DC power supplies may need manual turn on.  Look at these supplies: $probList"
            }
        }
    }
    #Done turning on power supplies

    APSMpReturn ok
}
