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

#
# $Log: not supported by cvs2svn $
# Revision 1.17  2002/03/26 17:14:31  emery
# Changed argument of togglePulseMagnet from PARto.. to Gunto..
#
# Revision 1.16  2002/03/04 19:50:14  emery
# Initial values come from present values
#
# Revision 1.15  2001/10/30 07:43:37  emery
# Detects which setpum is scanned for hozirontal axis of plots.
#
# Revision 1.14  2001/07/27 19:29:37  emery
# Fixed radiation monitor cawait line which had bad syntax.
#
# Revision 1.13  2001/05/29 08:50:56  emery
# Eliminated cerenkov detector turn specification.
#
# Revision 1.12  2001/02/17 00:08:29  emery
# Corrected daily directory button definition, and make
# sure that the daily directory button is placed next to the
# directory entry slot.
#
# Revision 1.11  2000/08/07 22:47:56  emery
# Use APSWaitWithUpdate instead of after
#
# Revision 1.10  2000/06/02 21:59:02  emery
# Moved cerenkov detector from sector 6 to sector3
#
# Revision 1.9  2000/03/17 20:06:14  emery
# Added process and plot process buttons and procedures.
#
# Revision 1.8  2000/02/16 10:38:38  emery
# Fixed a quantity name in a sddsplot command.
#
# Revision 1.7  2000/01/25 19:56:02  emery
# Added APSMakeSafeQualifierString to comment.
#
# Revision 1.6  2000/01/19 08:10:50  emery
# Added -leg option to sddsplot.
#
# Revision 1.5  2000/01/19 06:57:38  emery
# Fixed cerenkov PV label.
#
# Revision 1.4  2000/01/19 06:56:36  emery
# Replaced S1 cerenkov detector PVs with those at S6.
#
# Revision 1.3  1999/11/16 05:24:29  emery
# Fixed cerenkov PV name for plotting.
#
# Revision 1.2  1999/11/16 05:15:28  emery
# Using PVs for cerenkov detector S1.
#
# Revision 1.1  1999/09/30 23:58:28  emery
# First installation.
#

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
set CVSRevisionAuthor "\$Revision: 1.18 $ \$Author: emery $"


proc MakeInputFrame {widget args} {
    set parent ""
    global start end delta steps output historySector xHistorySector yHistorySector comment 
    global beamCurrent outputDir
    APSStrictParseArguments {parent}

    set outputDir .
    APSFrame $widget -parent $parent -label "Input parameters"
    set w $parent$widget.frame
    APSRadioButtonFrame .pulseMode -parent $w -orientation horizontal \
      -label "Septum pulse mode: " -variable singleShot -buttonList {continuous  "single shot"} \
      -valueList {0 1} \
      -contextHelp \
      "Choose whether the septum will fire continuously at each setpoint or fire only once.\n\nContinuous mode is normally used.\n\nSingle pulse is used to determine the optimum setpoint of the thick septum when single pulses far apart in time are required, say, for top-up injection."
    APSLabeledEntry .outputDir -parent $w \
      -label "Output directory:" -textVariable outputDir \
      -contextHelp "Enter a name for the output file directory." -width 50
    APSButton .daily -parent $w.outputDir -packOption "-anchor e" \
      -text "daily" -size small \
      -command {set outputDir [APSGoToDailyDirectory -subdirectory septumScans]}
    APSLabeledEntry .root -parent $w -label "Root name of file: " \
      -textVariable root \
      -contextHelp "Enter the root name of the file for the processed output <root>-nnn."
    APSLabeledEntry .index -parent $w -label "Index: " -textVariable index \
      -contextHelp "Enter the index (minus 1) to be part of the name of the output file. The index is incremented by 1 before execution."
    APSLabeledEntry .comment -parent $w -label "Comment: " -textVariable comment \
      -width 55 \
      -contextHelp "Enter a comment to be written as a parameter to the output file."

    APSLabeledEntry .start1 -parent $w -label "S:IS1 start (V): " -textVariable startSIS1 \
      -contextHelp "Enter the starting value for SIS1."
    APSLabeledEntry .end1 -parent $w -label "S:IS1 end (V): " -textVariable endSIS1 \
      -contextHelp "Enter the starting value for SIS1."

    APSLabeledEntry .start2 -parent $w -label "S:IS2 start (V): " -textVariable startSIS2 \
      -contextHelp "Enter the starting value for SIS2."
    APSLabeledEntry .end2 -parent $w -label "S:IS2 end (V): " -textVariable endSIS2 \
      -contextHelp "Enter the starting value for SIS2."

    APSLabeledEntry .start3 -parent $w -label "S38 Top Scraper start (cm): " -textVariable startS38Top \
      -contextHelp "Enter the starting value for S38 Top Scraper."
    APSLabeledEntry .end3 -parent $w -label "S38 Top Scraper end (cm) " -textVariable endS38Top \
      -contextHelp "Enter the starting value for S38 Top Scraper."

    APSLabeledEntry .start4 -parent $w -label "S36 Top Scraper start (cm): " -textVariable startS36Top \
      -contextHelp "Enter the starting value for S36 Top Scraper."
    APSLabeledEntry .end4 -parent $w -label "S36 Top Scraper end (cm) " -textVariable endS36Top \
      -contextHelp "Enter the starting value for S36 Top Scraper."

    APSLabeledEntry .interval -parent $w -label "Interval (s): " -textVariable interval \
      -contextHelp "Interval at each step in the septum scan."
    APSLabeledEntry .steps -parent $w -label "Steps: " -textVariable steps \
      -contextHelp "Number of steps in the septum scan."
}

proc DoSeptumScan {args} {
    APSParseArguments {outputDir root index \
                         startSIS1 endSIS1 startSIS2 endSIS2 \
                         startS38Top endS38Top startS36Top endS36Top \
                         steps interval monitorInterval singleShot \
                         comment abortVariable}
    
    global $abortVariable

    if {![string length $outputDir] || ![string length $root]} {
        APSSetVarAndUpdate status "Output directory or root not given."
        return
    }
    set output $outputDir/$root-[format %03ld $index]
    if [file exists $output] {
        APSSetVarAndUpdate status "File $output exists."
        return
    }

    APSSetVarAndUpdate status "Toggling all manner of pulsed magnets..."

    update

    TogglePulsedMagnetEnables -location GuntoBoosterExt
    if [catch {exec cavput -list=Mt:Ddg -list=3chan0,3chan4,4chan3 -list=.GATE=0  -pend=5
        after 1000
        if !$singleShot {
            exec cavput -list=Mt:Ddg -list=3chan0,3chan4,4chan3 -list=.GATE=1 -pend=5
        } else {
            exec cavput -list=Mt:Ddg -list=4chan3 -list=.GATE=1 -pend=5
        } \
             } result ] {
        APSSetVarAndUpdate status $result
        return
    }
    
    update
    if [catch {exec cavget -list=S:I -list=S1,S2,K1 -list=:VoltageSetSendAO  -float=%12.5f \
             } result ] {
        APSSetVarAndUpdate status $result
        return
    }

    set initialSIS1 [lindex $result 0]
    set initialSIS2 [lindex $result 1]
    set initialIK1 [lindex $result 2]
    if [catch {exec cavget -list=S36,S38 -list=:VTSC:SM:sm  -float=%12.5f \
             } result ] {
        APSSetVarAndUpdate status $result
        return
    }
    set initialS36Top [lindex $result 0]
    set initialS38Top [lindex $result 1]
    update
    APSWaitWithUpdate -waitSeconds $interval -updateInterval 1
    #turn off beam and set IK1 to 13 kV
    if [catch {exec cavput -list=Mt:Ddg3chan1.GATE=0  -pend=5
        exec cavput -list=S:IK1:VoltageSetSendAO=13  -pend=5\
             } result ] {
        APSSetVarAndUpdate status $result
        return
    }
    update
    # wait for 2 seconds for each setpoints so that the dac can ramp.
    if [catch {exec cavput -list=S:IS1:VoltageSetSendAO=$startSIS1 -pend=5
        exec cavput -list=S36=$startS36Top,S38=$startS38Top -list=:VTSC:SM:sm -pend=5
        # sending new setpoints to the septums must be separated
        # in time, otherwise one command will be ignored.
        after 1000
        exec cavput -list=S:IS2:VoltageSetSendAO=$startSIS2  -pend=5\
             } result ] {
        APSSetVarAndUpdate status $result
        return
    }
    after 2000
    update

#wait until scrapers are stopped
    APSSetVarAndUpdate status "Waiting for scrapers..."
    exec cawait -interval=1 \
      -waitFor=S36:VTSC:SM:sm.DMOV,equal=1 \
      -waitFor=S38:VTSC:SM:sm.DMOV,equal=1 -and 
    APSSetVarAndUpdate status "Scrapers arrived..."
#    exec cawait -interval=1 -timeLimit=30 \
      -waitFor=S36:VTSC:SM:sm.RBV,equal=$startS36Top \
      -waitFor=S38:VTSC:SM:sm.RBV,equal=$startS38Top -and 

    set monDir /home/helios/oagData/sr/sddsmonitorFiles
    if !$singleShot {
        if [catch {set pid [exec sddsmonitor $monDir/septumScan.mon $output \
                              -conditions=$monDir/septumScan.conditions,allMustPass,retakeStep \
                              -step=3000 -interval=$monitorInterval \
                              "-comment=Comment,[APSMakeSafeQualifierString $comment]" &] \
                 } result ] {
            APSSetVarAndUpdate status $result
            return
        }
    } else {
        if [catch {set pid [exec sddsmonitor $monDir/septumScan.mon $output \
                              -step=3000 -interval=$monitorInterval \
                              -comment=Comment,$comment &] \
                 } result ] {
            APSSetVarAndUpdate status $result
            return
        }
    }
    APSSetVarAndUpdate status "sddsmonitor launched..."
    update
    if !$singleShot {
        # turn on beam
        if [catch {exec cavput -list=Mt:Ddg -list=3chan1,3chan4 -list=.GATE=1  -pend=5 \
                 } result ] {
            APSSetVarAndUpdate status $result
            return
        }
        after [expr 1000 * $interval]
        #turn off beam
        if [catch {exec cavput -list=Mt:Ddg -list=3chan1,3chan4 -list=.GATE=0  -pend=5\
                 } result ] {
            APSSetVarAndUpdate status $result
            return
        }
    }
    set deltaSIS1 [expr 1.0 * ($endSIS1 - $startSIS1) / ($steps - 1)]
    set deltaSIS2 [expr 1.0 * ($endSIS2 - $startSIS2) / ($steps - 1)]
    set deltaS36Top [expr 1.0 * ($endS36Top - $startS36Top) / ($steps - 1)]
    set deltaS38Top [expr 1.0 * ($endS38Top - $startS38Top) / ($steps - 1)]
    for {set i 1} {$i < $steps} {incr i} {
        set SIS1 [expr $startSIS1 + $i * $deltaSIS1]
        set SIS2 [expr $startSIS2 + $i * $deltaSIS2]
        set S36Top [expr $startS36Top + $i * $deltaS36Top]
        set S38Top [expr $startS38Top + $i * $deltaS38Top]
        APSSetVarAndUpdate status "Step $i of $steps."
        update
        if {[string length $abortVariable] && [subst \$$abortVariable]} {
            if [catch {RestoreSeptums -SIS1 $initialSIS1 \
                         -SIS2 $initialSIS2 \
                         -IK1 $initialIK1 \
                         -S36Top $initialS36Top \
                         -S38Top $initialS38Top \
                     } result] {
                return -code error "DoSeptumScan: $result"
            }
            set $abortVariable 0
            break
        }
        update
        # wait for 2 seconds for each septoints so that the dac can ramp.
        if [catch {exec cavput -list=S:IS1:VoltageSetSendAO=$SIS1 -pend=5
            exec cavput -list=S36=$S36Top,S38=$S38Top -list=:VTSC:SM:sm -pend=5
            # sending new setpoints to the septums must be separated
            # in time, otherwise one command will be ignored.
            after 1000
            exec cavput -list=S:IS2:VoltageSetSendAO=$SIS2 -pend=5 \
                 } result ] {
            APSSetVarAndUpdate status $result
            return
        }
        after 2000
        exec cawait -interval=1 \
          -waitFor=S36:VTSC:SM:sm.DMOV,equal=1 \
          -waitFor=S38:VTSC:SM:sm.DMOV,equal=1 -and 
#        exec cawait -interval=1 \
          -waitFor=S36:VTSC:SM:sm.RBV,equal=$S36Top \
          -waitFor=S38:VTSC:SM:sm.RBV,equal=$S38Top -and 
        update
        if !$singleShot {
            # turn on beam if rad monitors are ok.
            if [catch {exec cavget -list=S:RM:ID -list=3,4,5,6,9,22 -list=:NRateAi -float=%12.5f -pend=5 \
                     } result ] {
                APSSetVarAndUpdate status $result
                return
            }
            if {[expr [lindex $result 0] > 2 || [lindex $result 1] > 2 \
                   || [lindex $result 2] > 2 || [lindex $result 3] > 2 \
                   || [lindex $result 4] > 2 || [lindex $result 5] > 2 ]} {
                APSSetVarAndUpdate status "Need to wait for radiation monitors to cool down..."
                exec cawait -interval=1 \
                  -waitFor=S:RM:ID2:NRateAi,below=1 \
                  -waitFor=S:RM:ID3:NRateAi,below=1 -and \
                  -waitFor=S:RM:ID4:NRateAi,below=1 -and \
                  -waitFor=S:RM:ID5:NRateAi,below=1 -and \
                  -waitFor=S:RM:ID6:NRateAi,below=1 -and \
                  -waitFor=S:RM:ID7:NRateAi,below=1 -and \
                  -waitFor=S:RM:ID9:NRateAi,below=1 -and \
                  -waitFor=S:RM:ID22:NRateAi,below=1 -and 
            }
            if {[string length $abortVariable] && [subst \$$abortVariable]} {
                if [catch {RestoreSeptums -SIS1 $initialSIS1 \
                             -SIS2 $initialSIS2 \
                             -IK1 $initialIK1 \
                             -S36Top $initialS36Top \
                             -S38Top $initialS38Top \
                         } result] {
                    return -code error "DoSeptumScan: $result"
                }
                set $abortVariable 0
                break
            }
            if [catch {exec cavput -list=Mt:Ddg -list=3chan1,3chan4 -list=.GATE=1  -pend=5 \
                     } result ] {
                APSSetVarAndUpdate status $result
                return
            }
            after [expr 1000 * $interval]
            #turn off beam
            if [catch {exec cavput -list=Mt:Ddg -list=3chan1,3chan4 -list=.GATE=0  -pend=5\
                     } result ] {
                APSSetVarAndUpdate status $result
                return
                if {[string length $abortVariable] && [subst \$$abortVariable]} {
                    if [catch {RestoreSeptums -SIS1 $initialSIS1 \
                                 -SIS2 $initialSIS2 \
                                 -IK1 $initialIK1 \
                                 -S36Top $initialS36Top \
                                 -S38Top $initialS38Top \
                             } result] {
                        return -code error "DoSeptumScan: $result"
                    }
                    set $abortVariable 0
                    break
                }
            }
        } else {
            if {[string length $abortVariable] && [subst \$$abortVariable]} {
                if [catch {RestoreSeptums -SIS1 $initialSIS1 \
                             -SIS2 $initialSIS2 \
                             -IK1 $initialIK1 \
                             -S36Top $initialS36Top \
                             -S38Top $initialS38Top \
                         } result] {
                    return -code error "DoSeptumScan: $result"
                }
                set $abortVariable 0
                break
            }
            exec cavput -list=Mt:SRinjectZeroBucketsBO=1,Mt:SRinjectMaxCyclesAO.VAL=1,Mt:SRinjectNumBunchesAO.VAL=1 -pend=5
            after 1000
            exec cavput -list=Mt:SRinjectMultiBO.VAL=1 -pend=5
            after [expr 1000 * $interval]
        }
    }
    
    APSSetVarAndUpdate status "Killing sddsmonitor..."
    if [catch {exec kill -KILL $pid} result] {
        APSSetVarAndUpdate status $result
    }

    if [catch {exec cavput -list=S:IS1:VoltageSetSendAO=$initialSIS1 -pend=5
        exec cavput -list=S36=$initialS36Top,S38=$initialS38Top -list=:VTSC:SM:sm -pend=5
        exec cavput -list=S:IK1:VoltageSetSendAO=$initialIK1  -pend=5 \
             } result ] {
        APSSetVarAndUpdate status $result
        return
    }
    after 1000
    if [catch {exec cavput -list=S:IS2:VoltageSetSendAO=$initialSIS2 -pend=5 \
             } result ] {
        APSSetVarAndUpdate status $result
        return
    }
    APSSetVarAndUpdate status "Done."
}

proc RestoreSeptums {args} {
    APSParseArguments {SIS1 SIS2  S36Top S38Top}
    if [catch {exec cavput -list=S:IS1:VoltageSetSendAO=$SIS1 -pend=5
        exec cavput -list=S36=$S36Top,S38=$S38Top -list=:VTSC:SM:sm -pend=5
        # sending new setpoints to the septums must be separated
        # in time, otherwise one command will be ignored.
        after 1000
        exec cavput -list=S:IS2:VoltageSetSendAO=$SIS2 -pend=5 \
             } result ] {
        APSSetVarAndUpdate status $result
        return
    }
}

set usage "SRSeptumScan -startSIS1 <value> -startSIS2 <value> -endSIS1 <value> -endSIS2 <value> -steps <value> -outputDir <directory> -root <root> -interval <seconds> -singleShot \{0|1\} "

set args $argv
set root ""
# initial values should come from present values.
set SIS1Initial [exec cavget -list=S:IS1:VoltageSetSendAO]
set startSIS1 [expr $SIS1Initial - 2]
set endSIS1 [expr $SIS1Initial + 2]
set SIS2Initial [exec cavget -list=S:IS2:VoltageSetSendAO]
set startSIS2 $SIS2Initial
set endSIS2 $SIS2Initial
set S36TopInitial [exec cavget -list=S36:VTSC:SM:sm]
set startS36Top $S36TopInitial
set endS36Top $S36TopInitial
set S38TopInitial [exec cavget -list=S38:VTSC:SM:sm]
set startS38Top $S38TopInitial
set endS38Top $S38TopInitial
set steps 21
set outputDir ""
set root "septumScan"
set index -1
set comment "test scan"
set interval 10
set monitorInterval 0.5
set singleShot 0

APSParseArguments {outputDir root index startSIS1 endSIS1 startSIS2 endSIS2 steps interval monitorInterval singleShot comment  abortVariable}

APSApplication . -name SRSeptumScan -version $CVSRevisionAuthor \
  -overview {Scan the septum while taking stored current data}

set status Working
APSScrolledStatus .status -parent .userFrame -textVariable status -width 50
MakeInputFrame .input -parent .userFrame
set status Ready
set abortRun 0
update

APSButton .run -parent .userFrame -text Run -command \
  { \
      APSDisableButton .userFrame.run.button 
      APSEnableButton .userFrame.stop.button
      incr index
      catch {DoSeptumScan -outputDir $outputDir \
               -root $root -index $index \
               -startSIS1 $startSIS1 -startSIS2 $startSIS2 \
               -endSIS1 $endSIS1 -endSIS2 $endSIS2 \
               -startS36Top $startS36Top -startS38Top $startS38Top \
               -endS36Top $endS36Top -endS38Top $endS38Top \
               -steps $steps -interval $interval \
               -monitorInterval $monitorInterval \
               -singleShot $singleShot \
               -comment $comment \
               -abortVariable abortRun} status
      update idletasks
      APSDisableButton .userFrame.stop.button 
      APSEnableButton .userFrame.run.button }

APSButton .stop -parent .userFrame -text Stop -command \
  { \
      set abortRun 1
      APSDisableButton .userFrame.stop.button
      APSEnableButton .userFrame.run.button } \
  -contextHelp "Aborts scan."

APSButton .plot -parent .userFrame -text PLOT -command \
  PlotSeptumScan \
  -contextHelp "Plots data corresponding to the file root and index."

APSButton .process -parent .userFrame -text PROCESS -command \
  ProcessSeptumScan \
  -contextHelp "Processes the output file corresponding to the root and index for the efficiency."

APSButton .processPlot -parent .userFrame -text "PLOT PROCESS" -command \
  PlotProcessSeptumScan \
  -contextHelp "Plots the processing of the output file corresponding to the root and index for the efficienc."

proc PlotSeptumScan {args} {
    global outputDir root index
    set output $outputDir/$root-[format %03ld $index]

    # determine which septum was scanned
    set spreads [exec sddsprocess $outputDir/$root-[format %03ld $index] -pipe=out \
                   -proc=S:IS1:DacAI,spread,S:IS1Spread \
                   -proc=S:IS2:DacAI,spread,S:IS2Spread \
                   | sdds2stream -pipe -para=S:IS1Spread,S:IS2Spread ]
    if {[lindex $spreads 0] != 0} {
        set septum S:IS1
    } else {
        set septum S:IS2
    }
    if ![file exists $output] {
        APSSetVarAndUpdate status "Can't find $output."
        return
    }

    if [catch {exec sddsplot -filename -tick=xtime $output \
                 -sev=xgap=2 -col=Time,(S:IS*,S35*,BTS*) -sep & \
             } result] {
        APSSetVarAndUpdate status "PlotSeptumScan: $result"
    }
    if [catch {exec sddsplot -filename $output -grap=sym \
                 -col=${septum}:DacAI,S-DCCT:CurrentM -leg=spec=S35DCCT \
                 -col=${septum}:DacAI,BTS:CM:q -leg=spec=BTS:CM:q \
                 -uns=y -grap=dots,sub=2,type=1 -yscale=id=bts \
                 -end \
                 -col=${septum}:CurrentAI,S-DCCT:CurrentM -leg=spec=S35DCCT \
                 -col=${septum}:CurrentAI,BTS:CM:q -leg=spec=BTS:CM:q \
                 -uns=y -grap=dots,sub=2,type=1 -yscale=id=bts \
                 -end \
                 -col=${septum}:DacAI,BTS:CM:q -leg=spec=BTS:CM:q \
                 -uns=y -grap=dots,sub=2,type=1 -yscale=id=bts \
                 -end \
                 -end \
                 & \
             } result] {
        APSSetVarAndUpdate status "PlotSeptumScan: $result"
    }
    return
}

proc ProcessSeptumScan {} {
    global outputDir root index
    set output $outputDir/$root-[format %03ld $index]

    # determine which septum was scanned
    set spreads [exec sddsprocess $outputDir/$root-[format %03ld $index] -pipe=out \
                   -proc=S:IS1:DacAI,spread,S:IS1Spread \
                   -proc=S:IS2:DacAI,spread,S:IS2Spread \
                   | sdds2stream -pipe -para=S:IS1Spread,S:IS2Spread ]
    if {[lindex $spreads 0] != 0} {
        set septum S:IS1
    } else {
        set septum S:IS2
    }

    if ![file exists $output] {
        APSSetVarAndUpdate status "Can't find $output."
        return
    }

    if [catch {exec sddsbreak $output -pipe=out \
                 -change=${septum}:DacAI \
                 | sddsprocess -pipe \
                 -proc=*,average,%sAve \
                 | sddscollapse -pipe \
                 | sddsconvert -pipe \
                 -edit=col,*Ave,%/Ave// \
                 | sddsprocess -pipe=in $output.break \
                 "-def=col,Efficiency,S-DCCT:CurrentM BTS:CM:q / .271 /" \
             } result] {
        APSSetVarAndUpdate status "ProcessSeptumScan: $result"
    }
    PlotProcessSeptumScan
    APSSetVarAndUpdate status "Done."
    return
}
    
proc PlotProcessSeptumScan {} {
    global outputDir root index
    set output $outputDir/$root-[format %03ld $index]
    
    # determine which septum was scanned
    set spreads [exec sddsprocess $outputDir/$root-[format %03ld $index] -pipe=out \
                   -proc=S:IS1:DacAI,spread,S:IS1Spread \
                   -proc=S:IS2:DacAI,spread,S:IS2Spread \
                   | sdds2stream -pipe -para=S:IS1Spread,S:IS2Spread ]
    if {[lindex $spreads 0] != 0} {
        set septum S:IS1
    } else {
        set septum S:IS2
    }

    if ![file exists $output.break] {
        APSSetVarAndUpdate status "Can't find $output.break."
        return
    }
    
    if [catch {exec sddsplot $output.break  \
                 -grap=sym,conn=sub,vary=sub,sca=2 -leg \
                 -col=Time,${septum}:DacAI -tick=xtime -yscale=id=dac \
                 -col=Time,${septum}:CurrentAI -tick=xtime -yscale=id=current -end \
                 -col=Time,${septum}:MagTemp -tick=xtime -end \
                 -col=Time,S-DCCT:CurrentM -tick=xtime -yscale=id=S35DCCT \
                 -col=Time,BTS:CM:q -tick=xtime -yscale=id=BTS \
                 -col=Time,Efficiency -tick=xtime -limit=ymax=1.1 -end \
                 -col=${septum}:DacAI,S-DCCT:CurrentM -yscale=id=S35DCCT \
                 -col=${septum}:DacAI,BTS:CM:q -yscale=id=BTS \
                 -col=${septum}:DacAI,Efficiency -limit=ymax=1.1 & \
             } result] {
        APSSetVarAndUpdate status "ProcessSeptumScan: $result"
    }
    APSSetVarAndUpdate status "Done."
    return
}
