#!/bin/sh  
# \
  exec oagwish "$0" "$@"
# $Log: not supported by cvs2svn $
# Revision 1.1  2010/09/23 23:26:37  xiaoam
# First install CPU DC to AC conversion.
#

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.2 $ \$Author: lemery $"

APSApplication . -name "CPUDC2AC" -version \
  $CVSRevisionAuthor -overview "Convert CPU DC mode correction table to AC mode correction table."

proc MakeInputFrame {widget args} {
    set parent ""
    APSStrictParseArguments {parent}
    APSFrame $widget -parent $parent -label "DC 2 AC Convert"
    set w $parent$widget.frame

    APSCheckButtonFrame .convert -parent $w -label Convert: \
      -buttonList {Orbit Tune Coupling} \
      -variableList {flag(orbit) flag(tune) flag(coupling)} \
      -orientation horizontal \
      -contextHelp "Choose which correction table need to be converted from DC to AC."
    APSLabeledEntry .output -parent $w \
      -label "Output suffix:" -textVariable suffix \
      -contextHelp "Enter a suffix name for the output file." -width 50

    APSLabeledEntry .dcfile -parent $w \
      -label "DC correction file:" -textVariable DCfile \
      -contextHelp "Enter the DC correction file for converting or reset." -width 50
    APSLabeledEntry .h1 -parent $w \
      -label "AC hcorr1:" -textVariable AC(H1) \
      -contextHelp "Enter the AC hcorr1 correction file for reset." -width 50
    APSLabeledEntry .h2 -parent $w \
      -label "AC hcorr2:" -textVariable AC(H2) \
      -contextHelp "Enter the AC hcorr2 correction file for reset." -width 50
    APSLabeledEntry .v1 -parent $w \
      -label "AC vcorr1:" -textVariable AC(V1) \
      -contextHelp "Enter the AC vcorr1 correction file for reset." -width 50
    APSLabeledEntry .v2 -parent $w \
      -label "AC vcorr2:" -textVariable AC(V2) \
      -contextHelp "Enter the AC vcorr2 correction file for reset." -width 50
    APSLabeledEntry .quad -parent $w \
      -label "AC Quad:" -textVariable AC(Quad) \
      -contextHelp "Enter the AC Quad correction file for reset." -width 50
    APSLabeledEntry .sq -parent $w \
      -label "AC Skew Quad(US):" -textVariable AC(SQ) \
      -contextHelp "Enter the AC skew Quad correction file for reset." -width 50
    APSLabeledEntry .so -parent $w \
      -label "AC Skew Oct(DS):" -textVariable AC(SO) \
      -contextHelp "Enter the AC skew Oct. (DS quad) correction file for reset." -width 50

    APSButton .run -parent $w -text "Convert" -command Process \
      -contextHelp "Convert selected correction from DC to AC."
    APSButton .reset -parent $w -text "Reload" -command  Reload \
      -contextHelp "Reload default corretion table to CPU's ioc"
}

proc Reload {} {
    global DCfile AC

    exec cavput -list=ID04b:corrFile.VAL=/sr/IDs/CPU/DCmodes/$DCfile
    exec cavput -list=ID04b:corrFile_1.VAL=/sr/IDs/CPU/ACmodes/$AC(V2)
    exec cavput -list=ID04b:corrFile_2.VAL=/sr/IDs/CPU/ACmodes/$AC(H2)
    exec cavput -list=ID04b:corrFile_3.VAL=/sr/IDs/CPU/ACmodes/$AC(H1)
    exec cavput -list=ID04b:corrFile_4.VAL=/sr/IDs/CPU/ACmodes/$AC(V1)
    exec cavput -list=ID04b:corrFile_5.VAL=/sr/IDs/CPU/ACmodes/$AC(Quad)
    exec cavput -list=ID04b:corrFile_6.VAL=/sr/IDs/CPU/ACmodes/$AC(SO)
    exec cavput -list=ID04b:corrFile_7.VAL=/sr/IDs/CPU/ACmodes/$AC(SQ)

    exec cavput -list=ID04b:loadCorr.VAL=1
    exec cavput -list=ID04b:loadCorr_ -list=1,2,3,4,5,6,7 -list=.VAL=1
    APSSetVarAndUpdate status "Reload file done."
}

proc Process {} {
    global flag suffix DCfile AC

    set rootDC /home/helios/oagData/sr/IDs/CPU/DCmodes
    set rootAC /home/helios/oagData/sr/IDs/CPU/ACmodes
    set tmpFile /tmp/[APSTmpString]

    if {$flag(orbit)} {
        exec sddscollapse $rootAC/$AC(H1) $tmpFile.corrRef
        exec sddsprocess $rootDC/$DCfile -pipe=out -match=para,Mode=CW "-redef=col,Iv,Iv abs" \
          | sddsinterp -pipe -col=Iv,?corr? \
	  -fileValues=$tmpFile.corrRef,Col=MainCurrent -order=2 \
          | sddsbreak -pipe=in $tmpFile.CWcorr -changeof=Iv
        exec sddsprocess $rootDC/$DCfile -pipe=out -match=para,Mode=CCW "-redef=col,Iv,Iv abs" \
          | sddsinterp -pipe -col=Iv,?corr? \
	  -fileValues=$tmpFile.corrRef,Col=MainCurrent -order=2 \
          | sddsbreak -pipe=in $tmpFile.CCWcorr -changeof=Iv
        exec sddsxref $rootAC/$AC(H1) $tmpFile.CWcorr -take=Hcorr1 -reuse=rows -pipe=out -noWarning \
          | sddsprocess -pipe -redef=col,CurrentNeg,Hcorr1 \
          | sddsprocess -pipe -del=col,Hcorr1 \
          | sddsxref -pipe -noWarning $tmpFile.CCWcorr -take=Hcorr1 -reuse=rows \
          | sddsprocess -pipe -redef=col,CurrentPos,Hcorr1 \
          | sddsprocess -pipe -del=col,Hcorr1 -retain=para,Main* \
          | sddsinterp -pipe=in $rootAC/hcorr1-from-DC.$suffix -col=TimeIndex,Cur* -equ=1,0,127
        exec sddsxref $rootAC/$AC(H2) $tmpFile.CWcorr -take=Hcorr2 -reuse=rows -pipe=out -noWarning \
          | sddsprocess -pipe -redef=col,CurrentNeg,Hcorr2 \
          | sddsprocess -pipe -del=col,Hcorr2 \
          | sddsxref -pipe -noWarning $tmpFile.CCWcorr -take=Hcorr2 -reuse=rows \
          | sddsprocess -pipe -redef=col,CurrentPos,Hcorr2 \
          | sddsprocess -pipe -del=col,Hcorr2 -retain=para,Main* \
          | sddsinterp -pipe=in $rootAC/hcorr2-from-DC.$suffix -col=TimeIndex,Cur* -equ=1,0,127
        exec sddsxref $rootAC/$AC(V1) $tmpFile.CWcorr -take=Vcorr1 -reuse=rows -pipe=out -noWarning \
          | sddsprocess -pipe -redef=col,CurrentNeg,Vcorr1 \
          | sddsprocess -pipe -del=col,Vcorr1 \
          | sddsxref -pipe -noWarning $tmpFile.CCWcorr -take=Vcorr1 -reuse=rows \
          | sddsprocess -pipe -redef=col,CurrentPos,Vcorr1 \
          | sddsprocess -pipe -del=col,Vcorr1 -retain=para,Main* \
          | sddsinterp -pipe=in $rootAC/vcorr1-from-DC.$suffix -col=TimeIndex,Cur* -equ=1,0,127
        exec sddsxref $rootAC/$AC(V2) $tmpFile.CWcorr -take=Vcorr2 -reuse=rows -pipe=out -noWarning \
          | sddsprocess -pipe -redef=col,CurrentNeg,Vcorr2 \
          | sddsprocess -pipe -del=col,Vcorr2 \
          | sddsxref -pipe -noWarning $tmpFile.CCWcorr -take=Vcorr2 -reuse=rows \
          | sddsprocess -pipe -redef=col,CurrentPos,Vcorr2 \
          | sddsprocess -pipe -del=col,Vcorr2 -retain=para,Main* \
          | sddsinterp -pipe=in $rootAC/vcorr2-from-DC.$suffix -col=TimeIndex,Cur* -equ=1,0,127
    }

    if {$flag(tune)} {
        exec sddscollapse $rootAC/$AC(Quad) $tmpFile.quadRef
        exec sddsprocess $rootDC/$DCfile -pipe=out -match=para,Mode=CW "-redef=col,Iv,Iv abs" \
          | sddsinterp -pipe -col=Iv,NormalQuad \
	  -fileValues=$tmpFile.quadRef,Col=MainCurrent -order=2 \
          | sddsbreak -pipe=in $tmpFile.CWquad -changeof=Iv
        exec sddsprocess $rootDC/$DCfile -pipe=out -match=para,Mode=CCW "-redef=col,Iv,Iv abs" \
          | sddsinterp -pipe -col=Iv,NormalQuad \
	  -fileValues=$tmpFile.quadRef,Col=MainCurrent -order=2 \
          | sddsbreak -pipe=in $tmpFile.CCWquad -changeof=Iv
        exec sddsxref $rootAC/$AC(Quad) $tmpFile.CWquad -take=NormalQuad -reuse=rows -pipe=out -noWarning \
          | sddsprocess -pipe -redef=col,CurrentNeg,NormalQuad -retain=para,MainCurrent \
          | sddsprocess -pipe -del=col,NormalQuad \
          | sddsxref -pipe -noWarning $tmpFile.CCWquad -take=NormalQuad -reuse=rows -transf=para,CaliCoef \
          | sddsprocess -pipe -redef=col,CurrentPos,NormalQuad \
          | sddsprocess -pipe -del=col,NormalQuad \
          | sddsprocess -pipe -proc=CurrentNeg,first,CurrentNegDCLevel \
	  -proc=CurrentPos,first,CurrentPosDCLevel \
          | sddsinterp -pipe=in -col=TimeIndex,Cur* -equ=1,0,70 $rootAC/normalQuad-from-DC.$suffix
    }

    if {$flag(coupling)} {
        exec sddscollapse $rootAC/$AC(SQ) $tmpFile.skewQRef
        exec sddsprocess $rootDC/$DCfile -pipe=out -match=para,Mode=CW "-redef=col,Iv,Iv abs" \
          | sddsinterp -pipe -col=Iv,RotatedQuad \
	  -fileValues=$tmpFile.skewQRef,Col=MainCurrent -order=2 \
          | sddsbreak -pipe=in $tmpFile.CWskewQ -changeof=Iv
        exec sddsprocess $rootDC/$DCfile -pipe=out -match=para,Mode=CCW "-redef=col,Iv,Iv abs" \
          | sddsinterp -pipe -col=Iv,RotatedQuad \
	  -fileValues=$tmpFile.skewQRef,Col=MainCurrent -order=2 \
          | sddsbreak -pipe=in $tmpFile.CCWskewQ -changeof=Iv
        exec sddsprocess $rootDC/$DCfile -pipe=out -match=para,Mode=CW "-redef=col,Iv,Iv abs" \
          | sddsinterp -pipe -col=Iv,RotatedOct \
	  -fileValues=$tmpFile.skewQRef,Col=MainCurrent -order=2 \
          | sddsbreak -pipe=in $tmpFile.CWskewO -changeof=Iv
        exec sddsprocess $rootDC/$DCfile -pipe=out -match=para,Mode=CCW "-redef=col,Iv,Iv abs" \
          | sddsinterp -pipe -col=Iv,RotatedOct \
	  -fileValues=$tmpFile.skewQRef,Col=MainCurrent -order=2 \
          | sddsbreak -pipe=in $tmpFile.CCWskewO -changeof=Iv
        exec sddsxref $rootAC/$AC(SQ) $tmpFile.CWskewQ -take=RotatedQuad -reuse=rows -pipe=out -noWarning \
          | sddsprocess -pipe -redef=col,CurrentNeg,RotatedQuad -retain=para,MainCurrent \
          | sddsprocess -pipe -del=col,RotatedQuad \
          | sddsxref -pipe -noWarning $tmpFile.CCWskewQ -take=RotatedQuad -reuse=rows \
          | sddsprocess -pipe -redef=col,CurrentPos,RotatedQuad \
          | sddsprocess -pipe -del=col,RotatedQuad \
          | sddsprocess -pipe -proc=CurrentNeg,first,CurrentNegDCLevel \
	  -proc=CurrentPos,first,CurrentPosDCLevel \
          | sddsinterp -pipe=in -col=TimeIndex,Cur* -equ=1,0,70 $rootAC/skewQuad-from-DC.$suffix
        exec sddsxref $rootAC/$AC(SO) $tmpFile.CWskewO -take=RotatedOct -reuse=rows -pipe=out -noWarning \
          | sddsprocess -pipe -redef=col,CurrentNeg,RotatedOct -retain=para,MainCurrent \
          | sddsprocess -pipe -del=col,RotatedOct \
          | sddsxref -pipe -noWarning $tmpFile.CCWskewO -take=RotatedOct -reuse=rows \
          | sddsprocess -pipe -redef=col,CurrentPos,RotatedOct \
          | sddsprocess -pipe -del=col,RotatedOct \
          | sddsprocess -pipe -proc=CurrentNeg,first,CurrentNegDCLevel \
	  -proc=CurrentPos,first,CurrentPosDCLevel \
          | sddsinterp -pipe=in -col=TimeIndex,Cur* -equ=1,0,70 $rootAC/skewOct-from-DC.$suffix
    }
    if [catch {eval exec rm -rf [glob $tmpFile.*]} result] {
        APSSetVarAndUpdate status "$results"
        return 
    }
    APSSetVarAndUpdate status "Process done."
}

proc MakeOptFrame {widget args} {
    global abort
    set parent ""
    APSStrictParseArguments {parent}
    APSFrame $widget -parent $parent -label "Optimization Input parameters" \
      -relief ridge -packOption {-fill x} \
      -contextHelp "Optimize CPU multipole's ramping speed."
    set w $parent$widget.frame

    APSLabeledEntry .logDir -parent $w -width 50 \
      -textVariable logDir \
      -label "Log directory:" \
      -contextHelp "Directory for log file of minimization."

    APSButton .daily -parent $w.logDir -packOption "-anchor e" \
      -text "daily" -size small \
      -command {set logDir [APSGoToDailyDirectory -subDirectory .]}
    APSLabeledEntry .saveFile -parent $w \
      -label "Save file with extension:" -textVariable savefile \
      -contextHelp "Enter an output file extension. The file will be saved as Quad.root etc."

    APSLabeledEntry .t0 -parent $w \
      -label "Mininum Ramp time (ms):" -textVariable t0 \
      -contextHelp "Enter a time for start of optimization."

    APSLabeledEntry .t1 -parent $w \
      -label "Maximum Ramp time (ms):" -textVariable t1 \
      -contextHelp "Enter a time for stop of optimization."

    APSLabeledEntry .step -parent $w \
      -label "Steps:" -textVariable step \
      -contextHelp "Enter number of steps for optimization."

    APSRadioButtonFrame .opt -parent $w -label Optimize \
      -variable optimOption \
      -buttonList {Quad skewQuad skewOct} \
      -valueList {1 2 3} \
      -orientation horizontal \
      -contextHelp "Chooses which correction table need to be optimized."

    APSButton .dspScopeSetup -parent $w \
      -text "DSP Setup" \
      -command {DSPScopeSetup -statusCallback SetStatus} \
      -packOption {-side left} \
      -contextHelp "This button sets up the DSP scope for data collection."
    APSButton .minimize  -parent $w -text "Optimize Multipole" -command \
      { \
          runOptimize -logDir $logDir -t0 $t0 -t1 $t1 -step $step
      } \
      -contextHelp "Starts sddsoptimize to find best ramping time."
    APSButton .abortbutton -parent $w -text "Abort" \
      -packOption "-side left" \
      -command {set abort 1} \
      -contextHelp "Abort data collection."
}

proc DSPScopeSetup {args} {
    global configFile
    APSParseArguments {statusCallback}

    APSRestoreSRFBDspScope -filename $configFile -timing 1 \
      -channels 1 -clearMode 1 
    
    if {$statusCallback!=""} {
        $statusCallback "DSP scope setup complete."
    }
}

proc SetStatus {text} {
    global status
    set status $text
    update
}

proc runOptimize {args} {
    set t0 0
    set t1 40
    set step 8
    APSParseArguments {logDir t0 t1 step}
    global optimOption AC abort savefile

    if {$optimOption == 1} {
        set root Quad
        set file $AC(Quad)
        set index 5
    }
    if {$optimOption == 2} {
        set root skewQuad
        set file $AC(SQ)
        set index 7
    }
    if {$optimOption == 3} {
        set root skewOct
        set file $AC(SO)
        set index 6
    }

    cd $logDir
    set setpointList [exec sdds2stream -para=MainCurrent $file]
    set fid [sdds open $root.optLog w]
    sdds defineColumn $fid MainCurrent -type SDDS_STRING
    sdds defineColumn $fid DeltaT -type SDDS_LONG
    sdds writeLayout $fid
    sdds startPage $fid [llength $setpointList]

    set MainCurrent ""
    set DeltaT ""
    set Max 1000
    set dt 0
    exec caput ID04b:TriggerSelect.VAL 2 
    exec caput ID04b:DesireMode.VAL 4
    set rootAC /home/helios/oagData/sr/IDs/CPU/ACmodes
    set tmpFile /tmp/[APSTmpString]
    set loadFile testfile
    #set rootAC /home/oxygen/XIAOAM/Operation/CPU1/work/command
    set output $root.[string range $savefile [expr [string first . $savefile]+1] end]

    foreach setpoint $setpointList {
        # set CPU
        exec cavput -list=ID04b:set_V_coil.VAL=$setpoint
        exec cawait -interval=0.5 -waitFor=ID04b:feedback.VAL,sameAs=Ready
        for {set t $t0} {$t <= $t1} {incr t $step} {
            if $abort {SetStatus aborted}
            SetStatus "Doing CPU $setpoint with time delay $t"
            if {!$setpoint} {
                set dt 0
                break
            }
            # process file.
            if {$t} {
                exec sddsprocess $rootAC/$file $rootAC/$loadFile -del=para,C*DCLevel -nowarning \
                  -proc=CurrentPos,last,CurrentPosDCLevel \
                  -proc=CurrentNeg,last,CurrentNegDCLevel \
                  "-redef=col,CurrentPos,TimeIndex $t > ? CurrentPos : CurrentNegDCLevel CurrentPosDCLevel CurrentNegDCLevel - $t / TimeIndex * + $ " \
                  "-redef=col,CurrentNeg,TimeIndex $t > ? CurrentNeg : CurrentPosDCLevel CurrentNegDCLevel CurrentPosDCLevel - $t / TimeIndex * + $ "
                # load file.
                exec cavput -list=ID04b:corrFile_$index.VAL=/sr/IDs/CPU/ACmodes/$loadFile
                exec cavput -list=ID04b:loadCorr_ -list=$index -list=.VAL=1
            }
            #take measurement
            CollectData -output $tmpFile.1 -statusCallback SetStatus
            #compare
            set error [exec sddsprocess $tmpFile.1 -pipe=out \
                         -proc=S4A:H3:Error,sta,S4A:H3:ErrorStd \
                         -proc=S5A:H3:Error,sta,S5A:H3:ErrorStd \
                         -proc=S4A:V3:Error,sta,S4A:V3:ErrorStd \
                         -proc=S5A:V3:Error,sta,S5A:V3:ErrorStd \
                         "-redef=para,error,S4A:H3:ErrorStd S5A:H3:ErrorStd  S4A:V3:ErrorStd S5A:V3:ErrorStd + + +" \
                         | sdds2stream -pipe=in -para=error]
            if {$error < $Max} {
                set dt $t
                set Max $error
            }
        }
        lappend MainCurrent [expr $setpoint]
        lappend DeltaT $dt
    }
    
    eval sdds setColumn $fid MainCurrent $MainCurrent
    eval sdds setColumn $fid DeltaT $DeltaT
    sdds writePage $fid
    sdds close $fid

    exec sddsbreak $root.optLog -pipe=out -changeof=MainCurrent \
      | sddsprocess -pipe=in $tmpFile.2 -proc=DeltaT,first,dT
    exec sddsprocess $rootAC/$file -pipe=out -del=para,dT,C*DCLevel -nowarning \
      -proc=CurrentPos,last,CurrentPosDCLevel \
      -proc=CurrentNeg,last,CurrentNegDCLevel \
      | sddsxref -pipe $tmpFile.2 -leave=* -trans=para,dT -nowarning \
      | sddsprocess -pipe "-filt=para,dT,0,0,!" \
      | sddsprocess -pipe=in $tmpFile.3 \
      "-redef=col,CurrentPos,TimeIndex dT > ? CurrentPos : CurrentNegDCLevel CurrentPosDCLevel CurrentNegDCLevel - $dt / TimeIndex * + $ " \
      "-redef=col,CurrentNeg,TimeIndex dT > ? CurrentNeg : CurrentPosDCLevel CurrentNegDCLevel CurrentPosDCLevel - $dt / TimeIndex * + $ "
    exec sddsprocess $rootAC/$file -pipe=out -del=para,dT,C*DCLevel -nowarning \
      -proc=CurrentPos,last,CurrentPosDCLevel \
      -proc=CurrentNeg,last,CurrentNegDCLevel \
      | sddsxref -pipe $tmpFile.2 -leave=* -trans=para,dT -nowarning \
      | sddsprocess -pipe=in $tmpFile.4 -filt=para,dT,0,0
    eval exec sddscombine $tmpFile.3  $tmpFile.4 -pipe=out \
      | sddssort -pipe=in $output -para=MainCurrent
    eval file delete -force [glob $tmpFile.*] $rootAC/$loadFile
    SetStatus "Optimization done."
}

proc CollectData {args} {
    global configFile scalarsFile abort

    APSParseArguments {output}

    if ![string length $output] {
        return -code error "CollectData: No output file specified."
    }
    if [file exists $output] {
        file delete -force $output
    }
 
    if {[exec cavget -pend=15 -list=SRFB:DS:SampleBO] == "Off"} {
        armDSPscope -statusCallback $statusCallback
    }
    set abort 0
        
    # Triggers from external trigger, which is the 2 Hz injection trigger.
    waitForTrigger -statusCallback $statusCallback
    if {$statusCallback!=""} {
        $statusCallback "Collecting data from DSPscope...[exec date +%H:%M:%S]"
    }
    update
    if [catch {exec sddswmonitor $configFile $output \
                 -pend=15 -scalars=$scalarsFile \
             } result] {
        if {$statusCallback!=""} {
            $statusCallback "CollectData: Error with sddswmonitor: $result"
            $statusCallback "Continuing anyway..."
        }
    }
}

proc armDSPscope {args} {
    global abort
    
    APSParseArguments {statusCallback}
    set dum 1
    while {[exec cavget -pend=15 -list=SRFB:GBL:FeedbackBlockedBI] == "Blocked"} {
        if {$dum == 1} {
            set status "Waiting for feedback block to clear... [exec date +%H:%M:%S]"
            set dum 0
        }
        APSWaitWithUpdate -waitSeconds 1 -updateInterval 0.5
    }
    
    set dum 1
    while {(([exec cavget -pend=15 -list=SRFB:GBL:HorzTripBI] == "Trip") || \
              ([exec cavget -pend=15 -list=SRFB:GBL:VertTripBI] == "Trip")) && \
             ($abort == 0) } {
        if {$dum == 1} {
            if {$statusCallback!=""} {
                $statusCallback "Waiting for trips to be reset... [exec date +%H:%M:%S]"
            }
            set dum 0
        }
        APSWaitWithUpdate -waitSeconds 1 -updateInterval 0.5
    }

    if {$abort == 0} {
        if {$statusCallback!=""} {
            $statusCallback "Arming DSPscope... [exec date +%H:%M:%S]"; update
        }
        exec cavput -pend=15 -list=SRFB:DS:SampleBO=1
        while {[exec cavget -pend=15 -list=SRFB:DS:SampleBO] == "Off"} {
            APSWaitWithUpdate -waitSeconds 1 -updateInterval 0.5
        }
    }
}

proc waitForTrigger {args} {
    global abort

    APSParseArguments {statusCallback}

    if {$abort == 0} {
        set triggered 0
        if {$statusCallback!=""} {
            $statusCallback "Waiting for dspscope to trigger... [exec date +%H:%M:%S]"; update
        }
        while {($triggered == 0) && ($abort == 0)} {
            if {[exec cavget -pend=15 -list=SRFB:DS:SampleBO] == "Off" } {
                set triggered 1
            }
            APSWaitWithUpdate -waitSeconds 1 -updateInterval 1
        }
        
        if {$triggered == 1} {
            if {$statusCallback!=""} {
                $statusCallback "Triggered [exec date +%H:%M:%S]"
            }
            update
        } else {
            if {$statusCallback!=""} {
                $statusCallback "Aborted... [exec date +%H:%M:%S]"
            }
            update
            set triggered 0
        }
    }
}

set DCfile default
set AC(H1) hcorr1.default
set AC(H2) hcorr2.default
set AC(V1) vcorr1.default
set AC(V2) vcorr2.default
set AC(Quad) normalQuad.sdds
set AC(SO) skewOct.sdds
set AC(SQ) skewQuad.sdds
set flag(orbit) 1
set flag(tune) 1
set flag(coupling) 1
set suffix [clock format [clock seconds] -format %y%m%d]

set optimOption 1
set logDir .
set savefile .opt
set configFile /home/helios/oagData/sr/RTFB/monitorFiles/S4S5CorrError.dspscope
set scalarsFile /home/helios/oagData/sr/RTFB/monitorFiles/SRFBTrigReadStatus.monitor
set t0 0
set t1 40
set step 8
set abort 0

set status "Working..."
APSScrolledStatus .status -parent .userFrame -textVariable status -width 50
MakeInputFrame .input -parent .userFrame
MakeOptFrame .opt -parent .userFrame

set status Ready.
update


# Local Variables:
# mode: tcl
# indent-tabs-mode: nil
# End:
