#!/bin/sh  
# \
  exec oagwish "$0" "$@"

set auto_path [linsert $auto_path 0  /usr/local/oag/apps/lib/$env(HOST_ARCH)]
set auto_path [linsert $auto_path 0 /usr/local/oag/lib_patch/$env(HOST_ARCH)]
APSStandardSetup

if [regexp {.0} $env(DISPLAY)] {
    set otherDisplay :0.1
} else {
    set otherDisplay :0.0
}
if [string match ":0" $env(DISPLAY)] {
    set otherDisplay :0
}


APSApplication . -name ScanIDapertures -version 1.0  -overview {Collects data during a scan of orbits through P1. Limits placed on lifetime determine the aperture a tthe upstream and downstrema locations}

set status Ready.
APSScrolledStatus .status -parent .userFrame -textVariable status -width 60 -height 10

# this procedure has a sddsmonitor that blocks till the end
proc CollectData {args} {
    APSParseArguments {filename seconds sector}
    set sector1 [expr $sector + 1]
    set monFile /tmp/[APSTmpString].mon
    exec replaceText /home/helios/oagData/sr/IDs/apertureScanTemplate.mon \
      $monFile \
      -original=<sector>,<sector1> -replace=$sector,$sector1
    catch {exec sddsmonitor $monFile $filename -steps=$seconds -erase &} pid
    return $pid
}

proc WaitForCollection {args} {
    set seconds 10
    set pid ""
    set abortVariable ""
    set cavputCommand ""
    APSParseArguments {seconds pid abortVariable cavputCommand}
    set timer $seconds
    if [string length $abortVariable] {
        global $abortVariable
    }
    while {$timer}  {
        update
        # if aborting, restore the P1 setpoints.
        if {[string length $abortVariable] && [subst \$$abortVariable]} {
            if [catch {exec kill -KILL $pid} result] {
                APSSetVarAndUpdate status $result
            }
            APSSetVarAndUpdate status "Aborting ..."
            APSSetVarAndUpdate status "running $cavputCommand -pend=5"
            eval exec $cavputCommand -pend=5
            set $abortVariable 0
            return -code error "WaitForCollection: Abort requested externally"
        }
        after 1000
        incr timer -1
    }
}

proc DryRunScan {args} {
    global OAGGlobal
    APSParseArguments {yInitialUStop yInitialDStop yInitialUSbot yInitialDSbot yStep angleBumpMixture seconds fileRoot sector}
    # Use elegant trajectories through P1s
    set steps 10
    set twissFile $OAGGlobal(SRLatticesDirectory)/default/aps.twi
    return
}

proc RunScan {args} {
    set abortVariable ""
    set apertureList ""
    APSParseArguments {yInitialUStop yInitialDStop yInitialUSbot yInitialDSbot yStep angleBumpMixture seconds fileRoot sector abortVariable apertureList}
    if [string length $abortVariable] {
        global $abortVariable
        set $abortVariable 0
    }
    if [llength $apertureList] {
        # items are TopUS TopDS BottomUS BottomDS
        foreach item $apertureList {
            global $item
        }
    }
    global status lifetimeLimit currentLimit currentRequirement
    set counter 0
    if [file exists $fileRoot.[format %03ld $counter]] {
        APSSetVarAndUpdate status "RunScan: File $fileRoot.[format %03ld $counter] already exists."
        return
    }
    # At least make sure that datapool y-plane is not suspended.
    catch {exec cavput -list=DP:S:OrbitControlLawYSDDS.SUSP=Resume}
    # make sure the lifetime calculation is fast
    catch {exec cavput -list=S-DCCT:LifetimeStdesPoints2FitC=10}
    set sector1 [expr $sector + 1]
    # the set of original P1 setpoints.
    set returnString [exec cavget -list=S${sector}B:P1,S${sector1}A:P1 -list=:ms:y:SetpointAO -cavput]

# it turns out that 5 mm is too small for regular straight sections.
    exec cavput -list=S${sector}B:P1,S${sector1}A:P1 -list=:ms:y:SetpointAO -list=.DRVH=10.0,.DRVL=-10.0
    if {[APScavget -list=S-DCCT:CurrentM] < $currentRequirement} {
        APSSetVarAndUpdate status "Inject more beam, please.... You have 60 seconds to do it..."
        exec cawait -waitFor=S-DCCT:CurrentM,above=$currentRequirement -interval=2 -timelimit=60
    }

    # if aborting, restore the P1 setpoints.
    if {[string length $abortVariable] && [subst \$$abortVariable]} {
        APSSetVarAndUpdate status "Aborting ..."
        APSSetVarAndUpdate status "cavput -list=$returnString -pend=5"
        exec cavput -list=$returnString -pend=5
        set $abortVariable 0
        return
    }

    # Scan upstream top upwards to limit
    # Scan upstream bottom downwards to limit
    # Scan downstream top upwards to limit
    # Scan downstream bottom downwards to limit
    if !$TopUS {
        APSSetVarAndUpdate status "Skipping upstream top."
    } else {
        set label UpstreamTop
        APSSetVarAndUpdate status "Upstream top."

        set y $yInitialUStop
        exec cavput -list=S${sector}B:P1=$yInitialUStop,S${sector1}A:P1=[expr $angleBumpMixture * $yInitialDStop] -list=:ms:y:SetpointAO  -pend=5
        APSSetVarAndUpdate status "$counter: $y"
        after 5000
        if {[CheckDecay] > 1.0} {
            APSSetVarAndUpdate status "Decay is too fast. Moving beam quickly away from aperture..."
            exec cavput -list=$returnString -pend=5
            set $abortVariable 1
            return
        }
        set fileList ""
        update
        if [catch {CollectData -filename $fileRoot.[format %03ld $counter] -seconds $seconds -sector $sector } pid] {
            return -code error "CollectData: $pid"
        }
        if [catch {WaitForCollection -seconds $seconds -pid $pid -cavputCommand "cavput -list=$returnString" -abortVariable $abortVariable} result] {
            return -code error "CollectData: $result"
        }
        update
        lappend fileList $fileRoot.[format %03ld $counter]
        set limitReached 0
        while {!$limitReached} {
            APSSetVarAndUpdate status "Moving upstream top."
            # here one could increase yStep if the lifetime was high in order to speed up the scan.
            if {[APScavget -list=SRlifeTimeStdesSUB] > 5 * $lifetimeLimit} {
                exec cavput -list=S${sector}B:P1:ms:y:SetpointAO=$yStep -delta=factor=2 -pend=5
                set y [expr $y + 2 * $yStep]
            } else {
                exec cavput -list=S${sector}B:P1:ms:y:SetpointAO=$yStep -delta=factor=1 -pend=5
                set y [expr $y + $yStep]
            }
            incr counter
            APSSetVarAndUpdate status "$counter: $y"
            if {[CheckDecay] > 1.0} {
                APSSetVarAndUpdate status "Decay is too fast. Moving beam quickly..."
                exec cavput -list=$returnString -pend=5
                set $abortVariable 1
                return
            }
            if [catch {CollectData -filename $fileRoot.[format %03ld $counter] -seconds $seconds -sector $sector} pid] {
                return -code error "CollectData: $pid"
            }
            if [catch {WaitForCollection -seconds $seconds -pid $pid -cavputCommand "cavput -list=$returnString" -abortVariable $abortVariable} result] {
                return -code error "CollectData: $result"
            }
            lappend fileList $fileRoot.[format %03ld $counter]
            # check if we reached a limit using lifetime PV. The lifetime
            # could stay at 0 mins for some time after a step loss in
            # current. I put in a check previously that the lifetime reads
            # something higher than 0 for a valid data to go with the
            # orbit.
            exec cawait -waitFor=SRlifeTimeStdesSUB,above=0 -timelimit=60
            if {[APScavget -list=SRlifeTimeStdesSUB] < $lifetimeLimit \
                    || [APScavget -list=S-DCCT:CurrentM] < $currentLimit} {
                set limitReached 1
            }
        }
        # restart lifetime
        APScavput -list=S-DCCT:LifetimeStdesRestartC=1
        # move away from aperture quickly I hope.
        APSSetVarAndUpdate status "cavput -list=$returnString -pend=5"
        exec cavput -list=$returnString -pend=5
        eval exec sddscombine $fileList $fileRoot.$label.sdds 
        if {[APScavget -list=S-DCCT:CurrentM] < $currentRequirement} {
            APSSetVarAndUpdate status "Inject more beam, please..."
            exec cawait -waitFor=S-DCCT:CurrentM,above=$currentRequirement -interval=2 -timelimit=60
        }
        exec cawait -waitFor=SRlifeTimeStdesSUB,above=0 -timelimit=60
    }
    if !$BottomUS {
        APSSetVarAndUpdate status "Skipping upstream bottom."
    } else {
        set label UpstreamBot
        APSSetVarAndUpdate status "Upstream bottom."

        exec cavput -list=S${sector}B:P1=[expr -1 * $yInitialUSbot],S${sector1}A:P1=[expr -1 * $angleBumpMixture * $yInitialDSbot] -list=:ms:y:SetpointAO  -pend=5
        set y [expr -1 * $yInitialUSbot]
        APSSetVarAndUpdate status "$counter: $y"
        after 5000
        if {[CheckDecay] > 1.0} {
            APSSetVarAndUpdate status "Decay is too fast. Moving beam quickly..."
            exec cavput -list=$returnString -pend=5
            set $abortVariable 1
            return
        }
        set fileList ""
        if [catch {CollectData -filename $fileRoot.[format %03ld $counter] -seconds $seconds -sector $sector} pid] {
            return -code error "CollectData: $pid"
        }
        if [catch {WaitForCollection -seconds $seconds -pid $pid -cavputCommand "cavput -list=$returnString" -abortVariable $abortVariable} result] {
            return -code error "CollectData: $result"
        }
        lappend fileList $fileRoot.[format %03ld $counter]
        set limitReached 0
        while {!$limitReached} {
            APSSetVarAndUpdate status "Moving upstream bottom."
            if {[APScavget -list=SRlifeTimeStdesSUB] > 5 * $lifetimeLimit} {
                exec cavput -list=S${sector}B:P1:ms:y:SetpointAO=$yStep -delta=factor=-2 -pend=5
                set y [expr $y - 2 * $yStep]
            } else {
                exec cavput -list=S${sector}B:P1:ms:y:SetpointAO=$yStep -delta=factor=-1 -pend=5
                set y [expr $y - $yStep]
            }
            incr counter
            APSSetVarAndUpdate status "$counter: $y"
            if {[CheckDecay] > 1.0} {
                APSSetVarAndUpdate status "Decay is too fast. Moving beam quickly..."
                exec cavput -list=$returnString -pend=5
                set $abortVariable 1
                return
            }
            if [catch {CollectData -filename $fileRoot.[format %03ld $counter] -seconds $seconds -sector $sector} pid] {
                return -code error "CollectData: $pid"
            }
            if [catch {WaitForCollection -seconds $seconds -pid $pid -cavputCommand "cavput -list=$returnString" -abortVariable $abortVariable} result] {
                return -code error "CollectData: $result"
            }
            lappend fileList $fileRoot.[format %03ld $counter]
            # check if we reached a limit
            exec cawait -waitFor=SRlifeTimeStdesSUB,above=0 -timelimit=60
            if {[APScavget -list=SRlifeTimeStdesSUB] < $lifetimeLimit \
                    || [APScavget -list=S-DCCT:CurrentM] < $currentLimit} {
                set limitReached 1
            }
        }
        # restart lifetime
        APScavput -list=S-DCCT:LifetimeStdesRestartC=1
        # move away from aperture quickly I hope.
        APSSetVarAndUpdate status "cavput -list=$returnString -pend=5"
        exec cavput -list=$returnString -pend=5
        eval exec sddscombine $fileList $fileRoot.$label.sdds
        if {[APScavget -list=S-DCCT:CurrentM] < $currentRequirement} {
            APSSetVarAndUpdate status "Inject more beam, please..."
            exec cawait -waitFor=S-DCCT:CurrentM,above=$currentRequirement -interval=2 -timelimit=60
        }
        exec cawait -waitFor=SRlifeTimeStdesSUB,above=0 -timelimit=60
    }

    if !$TopDS {
        APSSetVarAndUpdate status "Skipping downstream top."
    } else {
        set label DownstreamTop
        APSSetVarAndUpdate status "Downstream top."

        exec cavput -list=S${sector}B:P1=[expr $angleBumpMixture * $yInitialUStop],S${sector1}A:P1=$yInitialDStop -list=:ms:y:SetpointAO -pend=5
        set y $yInitialDStop
        APSSetVarAndUpdate status "$counter: $y"
        after 5000
        set fileList ""
        if {[CheckDecay] > 1.0} {
            APSSetVarAndUpdate status "Decay is too fast. Moving beam quickly..."
            exec cavput -list=$returnString -pend=5
            set $abortVariable 1
            return
        }
        if [catch {CollectData -filename $fileRoot.[format %03ld $counter] -seconds $seconds -sector $sector} pid] {
            return -code error "CollectData: $pid"
        }
        if [catch {WaitForCollection -seconds $seconds -pid $pid -cavputCommand "cavput -list=$returnString" -abortVariable $abortVariable} result] {
            return -code error "CollectData: $result"
        }
        lappend fileList $fileRoot.[format %03ld $counter]
        set limitReached 0
        while {!$limitReached} {
            APSSetVarAndUpdate status "Moving downstream top."
            if {[APScavget -list=SRlifeTimeStdesSUB] > 5 * $lifetimeLimit} {
                exec cavput -list=S${sector1}A:P1:ms:y:SetpointAO=$yStep -delta=factor=2 -pend=5
                set y [expr $y + 2 * $yStep]
            } else {
                exec cavput -list=S${sector1}A:P1:ms:y:SetpointAO=$yStep -delta=factor=1 -pend=5
                set y [expr $y + $yStep]
            }
            incr counter
            APSSetVarAndUpdate status "$counter: $y"
            if {[CheckDecay] > 1.0} {
                APSSetVarAndUpdate status "Decay is too fast. Moving beam quickly..."
                exec cavput -list=$returnString -pend=5
                set $abortVariable 1
                return
            }
            if [catch {CollectData -filename $fileRoot.[format %03ld $counter] -seconds $seconds -sector $sector} pid] {
                return -code error "CollectData: $pid"
            }
            if [catch {WaitForCollection -seconds $seconds -pid $pid -cavputCommand "cavput -list=$returnString" -abortVariable $abortVariable} result] {
                return -code error "CollectData: $result"
            }
            lappend fileList $fileRoot.[format %03ld $counter]
            # this ensures that no old data is included in the lifetime calculation
            exec cawait -waitFor=SRlifeTimeStdesSUB,above=0 -timelimit=60
            # check if we reached a limit
            if {[APScavget -list=SRlifeTimeStdesSUB] < $lifetimeLimit \
                    || [APScavget -list=S-DCCT:CurrentM] < $currentLimit} {
                set limitReached 1
            }
        }

        # restart lifetime
        APScavput -list=S-DCCT:LifetimeStdesRestartC=1
        # move away from aperture quickly I hope.
        APSSetVarAndUpdate status "cavput -list=$returnString -pend=5"
        exec cavput -list=$returnString -pend=5
        eval exec sddscombine $fileList $fileRoot.$label.sdds
        
        if {[APScavget -list=S-DCCT:CurrentM] < $currentRequirement} {
            APSSetVarAndUpdate status "Inject more beam, please..."
            exec cawait -waitFor=S-DCCT:CurrentM,above=$currentRequirement -interval=2 -timelimit=60
        }
        exec cawait -waitFor=SRlifeTimeStdesSUB,above=0 -timelimit=60
    }

    if !$BottomDS {
        APSSetVarAndUpdate status "Skipping downstream bottom."
    } else {
        set label DownstreamBot
        APSSetVarAndUpdate status "Downstream bottom."

        exec cavput -list=S${sector}B:P1=[expr -$angleBumpMixture * $yInitialUSbot],S${sector1}A:P1=[expr -1 * $yInitialDSbot] -list=:ms:y:SetpointAO  -pend=5
        set y [expr -1 * $yInitialDSbot]
        APSSetVarAndUpdate status "$counter: $y"
        after 5000
        if {[CheckDecay] > 1.0} {
            APSSetVarAndUpdate status "Decay is too fast. Moving beam quickly..."
            exec cavput -list=$returnString -pend=5
            set $abortVariable 1
            return
        }
        set fileList ""
        if [catch {CollectData -filename $fileRoot.[format %03ld $counter] -seconds $seconds -sector $sector} pid] {
            return -code error "CollectData: $pid"
        }
        if [catch {WaitForCollection -seconds $seconds -pid $pid -cavputCommand "cavput -list=$returnString" -abortVariable $abortVariable} result] {
            return -code error "CollectData: $result"
        }
        lappend fileList $fileRoot.[format %03ld $counter]
        set limitReached 0
        while {!$limitReached} {
            APSSetVarAndUpdate status "Moving downstream bottom."
            if {[APScavget -list=SRlifeTimeStdesSUB] > 5 * $lifetimeLimit} {
                exec cavput -list=S${sector1}A:P1:ms:y:SetpointAO=$yStep -delta=factor=-2 -pend=5
                set y [expr $y - 2 * $yStep]
            } else {
                exec cavput -list=S${sector1}A:P1:ms:y:SetpointAO=$yStep -delta=factor=-1 -pend=5
                set y [expr $y - $yStep]
            }
            incr counter
            APSSetVarAndUpdate status "$counter: $y"
            if {[CheckDecay] > 1.0} {
                APSSetVarAndUpdate status "Decay is too fast. Moving beam quickly..."
                exec cavput -list=$returnString -pend=5
                set $abortVariable 1
                return
            }
            if [catch {CollectData -filename $fileRoot.[format %03ld $counter] -seconds $seconds -sector $sector} pid] {
                return -code error "CollectData: $pid"
            }
            if [catch {WaitForCollection -seconds $seconds -pid $pid -cavputCommand "cavput -list=$returnString" -abortVariable $abortVariable} result] {
                return -code error "CollectData: $result"
            }
            lappend fileList $fileRoot.[format %03ld $counter]
            exec cawait -waitFor=SRlifeTimeStdesSUB,above=0 -timelimit=60
            # check if we reached a limit
            if {[APScavget -list=SRlifeTimeStdesSUB] < $lifetimeLimit \
                    || [APScavget -list=S-DCCT:CurrentM] < $currentLimit} {
                set limitReached 1
            }
        }
        # restart lifetime
        APScavput -list=S-DCCT:LifetimeStdesRestartC=1
        # move away from aperture quickly I hope.
        APSSetVarAndUpdate status "cavput -list=$returnString -pend=5"
        exec cavput -list=$returnString -pend=5
        eval exec sddscombine $fileList $fileRoot.$label.sdds
    }
}

proc CheckDecay {} {
    return [expr [APScavget -list=S-DCCT:LifetimeStdesAveAI] - [APScavget -list=S-DCCT:LifetimeStdesSourceM]]
}

APSLabeledEntry .outputDir -parent .userFrame \
  -label "Output file root:" -textVariable fileRoot \
  -contextHelp "Enter a name for the output file." -width 40
APSLabeledEntry .sector -parent .userFrame \
  -label "Sector number:" -textVariable sector \
  -contextHelp "Enter the sector number for the straight section." -width 15

APSLabeledEntry .yInitialUStop -parent .userFrame \
  -label "Top US Scan starting from y:" -textVariable yInitialUStop \
  -contextHelp "Scan orbit from this value at the US end." -width 15
APSLabeledEntry .yInitialDStop -parent .userFrame \
  -label "Top DS Scan starting from y:" -textVariable yInitialDStop \
  -contextHelp "Scan orbit from this value at the DS end." -width 15
APSLabeledEntry .yInitialUSbottom -parent .userFrame \
  -label "Bottom US Scan starting from y:" -textVariable yInitialUSbot \
  -contextHelp "Scan orbit from this value at the US end." -width 15
APSLabeledEntry .yInitialDSbottom -parent .userFrame \
  -label "Bottom DS Scan starting from y:" -textVariable yInitialDSbot \
  -contextHelp "Scan orbit from this value at the DS end." -width 15
APSLabeledEntry .mixture -parent .userFrame \
  -label "Angle bump mixture:" -textVariable angleBumpMixture \
  -contextHelp "The initial value from the bpm on the other side is multiplied by this quantity to produce a fixed beam position there.\n\nSo essentially this controls the angle to the parallel bump so that only the aperture at the ends are probed. Use value of 0 if you want a 3-bump." -width 15
APSLabeledEntry .yStep -parent .userFrame \
  -label "Orbit step:  " -textVariable yStep \
  -contextHelp "Orbit step size." -width 15
APSLabeledEntry .seconds -parent .userFrame \
  -label "Seconds to wait at each step  " -textVariable seconds -width 15
APSLabeledEntry .lifetime -parent .userFrame \
  -label "Lifetime limit (minutes) " -textVariable lifetimeLimit -width 15 \
  -contextHelp "Orbit scan stops when low lifetime is reached." 
APSLabeledEntry .current -parent .userFrame \
  -label "Current limit (mA) " -textVariable currentLimit -width 15 \
  -contextHelp "Orbit scan stops when low current is reached." 
APSLabeledEntry .currentReq -parent .userFrame \
  -label "Required Current (mA) " -textVariable currentRequirement -width 15 \
  -contextHelp "Orbit scans will resume when this current is reached." 

set apertureList "TopUS TopDS BottomUS BottomDS"
foreach $apertureList {1 1 1 1} {}

APSCheckButtonFrame .aperture -parent .userFrame  \
      -orientation  horizontal -limitPerRow 4 \
      -packOption {-side top -fill x} \
      -label "Apertures to test" \
      -buttonList "TopUS TopDS BottomUS BottomDS" \
      -variableList "TopUS TopDS BottomUS BottomDS" \
      -contextHelp "List of apertures. If you need to repeat a scan, deselect those that have already been done."

APSButton .run -parent .userFrame -text "Run orbit scan" -command {
    if {[string length $fileRoot] == 0} {
        APSSetVarAndUpdate status "fileRoot is empty. Scan is not run."
    } else {
        APSDisableButton .userFrame.run.button 
        APSEnableButton .userFrame.stop.button 
        
        if [catch {RunScan -yInitialUStop $yInitialUStop -yInitialDStop $yInitialDStop  -yInitialUSbot $yInitialUSbot -yInitialDSbot $yInitialDSbot \
                       -yStep $yStep -angleBumpMixture $angleBumpMixture -seconds $seconds \
                       -fileRoot $fileRoot -sector $sector \
                       -abortVariable abortScan \
                       -apertureList $apertureList
            APSDisableButton .userFrame.stop.button 
            APSEnableButton .userFrame.run.button
        } result] {
            APSSetVarAndUpdate status "RunScan: $result"
        }
    }

} -contextHelp "Changes setpoints on B:P1 and A:P1, records SCU chamber temperature."

set abortScan 0
APSButton .stop -parent .userFrame -text "Stop orbit scan" -command {
    if [catch {set abortScan 1
        APSDisableButton .userFrame.stop.button
	APSEnableButton .userFrame.run.button
    } result] {
        puts stdout "RunScan: $result"
    }

} -contextHelp "Changes setpoints on B:P1 and A:P1."

set sector 4
set sector1 [expr $sector + 1]

APSButton .adt -parent .userFrame -text "SR BPM AdjustedCC ADT" \
    -command "exec adt -display $otherDisplay -geometry +30+0 -f /home/helios/oagData/ADTFiles/srBpm/sr.bpm.adjusted.pv -z 2.5 -s $sector &" -contextHelp "Launches ADT of adjustedCC."

APSButton .process -parent .userFrame -text "Process" -command {
    set scriptDir /home/helios/SR/daily/2015/04/15/1/ApertureScan
    set fileList [glob -nocomplain ${fileRoot}.*stream*.sdds]
    if ![llength $fileList] {
        APSSetVarAndUpdate status "No file matching $fileRoot.*stream*.sdds"
    } else {
        if [catch {exec $scriptDir/processScan -rootname $fileRoot &} result] {
            APSSetVarAndUpdate status "$scriptDir/processScan: $result"
        } 
    }
} -contextHelp "Process data using an external script"

#APSDisableButton .userFrame.process.button 
APSDisableButton .userFrame.stop.button 

set yInitialUStop 1.5
set yInitialDStop 0.9
set yInitialUSbot 1.3
set yInitialDSbot 1.3
# a value of zero means purely a 3-bump. A value of 1.0 means use full value
# specified by the starting value of the bpm on the other end.
set angleBumpMixture 0.5
set yStep 0.03
set seconds 10
set fileRoot scan01
set lifetimeLimit 60
# make sure this is higher than the datapool current limit!
set currentLimit 15
# inject to say 25 mA initially, more than the required current.
set currentRequirement 15

update
APSInfoWindow .info  -name "Operational Recommendations" -width 20 -modal 1 -infoMessage "This programs scans Y orbit at each end of an ID vacuum chamber by changing B:P1 and A:P1 setpoints. A user is responsible in creating an appropriate orbit correction using V2s and P1s prior to running the orbit scan.\nIt is also recommended that after starting the orbit correction, the user verifies its performance by running the command \n\"cavput -list=S<n>B:P1,S<n1>A:P1 -list=:ms:y:SetpointAO=-1.5 -delta=factor=1 -pend=5\"\nin positive and negative directions.\nUser should set the corrector error range to 300 A, and set the corretor delta to 5 A in order to converge fast initially."

# Local Variables:
# mode: tcl
# End:

