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

puts "Not used"
exit
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 relatedSuffixList { PeakAbsDevAI  GCountAI }

set output(ColumnNames) "ControlName RelatedControlName"
set output(ParameterNames) "InstallLocation"

# correctors 
for {set sector 1} {$sector<41} {incr sector} {
    foreach side {A B} {
        foreach num {1 2 3 4} {
            foreach plane {H V} {
                lappend prefixList S${sector}$side:${plane}$num
            }
        }
    }
}

# trims
for {set sector 1} {$sector<41} {incr sector} {
    foreach side {A B} {
        lappend prefixList S${sector}$side:MT
    }
}

# quads 
for {set sector 1} {$sector<41} {incr sector} {
    foreach side {A B} {
        foreach num {1 2 3 4 5} {
            lappend prefixList S${sector}$side:Q$num
        }
    }
}

# skews
set AB B
for {set sector 1} {$sector<40} {incr sector 2} {
    lappend prefixList S$sector$AB:QS
    if [string compare $AB A]==0 {
        set AB B
    } else {
        set AB A
    }
}

# sextupoles
for {set sector 1} {$sector<41} {incr sector} {
    foreach side {A:S1 A:S2 A:S3 A:S4 B:S3 B:S2 B:S1} {
        lappend prefixList S${sector}$side
    }
}

foreach prefix $prefixList {
    foreach suffix $relatedSuffixList {
        lappend CNList $prefix:GCountDeltaCALC
        lappend RCNList $prefix:$suffix
    }
}

foreach plane {X Y} {
    foreach suffix {HBTO RUN} {
        lappend CNList S:OrbitControlLaw${plane}RC.$suffix
        lappend RCNList ""
    }
}

foreach type {"" L M} {
    lappend CNList S35DCCT:CurrentLossAlarm${type}BO
    lappend RCNList S35DCCT:currentCC
}

set output(Column.ControlName) [list $CNList]
set output(Column.RelatedControlName) [list $RCNList]
set output(Parameter.InstallLocation) [list /home/helios/oagData/Alarms/SRDCPS-100Hz.alog]
if {[catch {sdds save /tmp/SRDCPS-100Hz.alog output} results]} {
    puts "error: $results"
    exit
}

puts "Comparing against master PV list"
exec sddsprocess /tmp/SRDCPS-100Hz.alog -pipe=out -edit=column,SimpleControlName,ControlName,S?/./K | sddssort -col=ControlName -col=RelatedControlName -pipe -numericHigh | sddsselect -pipe /home/helios/oagData/pvdata/iocRecNamesOAG.sdds -match=SimpleControlName=rec_name -nowarning -reuse | sddsconvert -pipe=in ./Alarms/SRDCPS-100Hz.alog -delete=column,SimpleControlName

file delete /tmp/SRDCPS-100Hz.alog

puts "Use cppatch to install SRDCPS-100Hz.alog"
