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

puts "NOT USED"
puts "Run utils/monitoring/makeBoosterReqFile instead"
exit
# 2/6/2013 shang
# first version, for generating Booster.req 

set root Booster
set recordFile /home/helios/oagData/pvdata/iocRecNamesOAG.sdds

set generation 1
set newFile ""
while 1 {
    set lastFile $newFile
    set newFile [format ${root}.req-%04ld $generation]
    if ![file exists $newFile] {
        break
    }
    incr generation
}
set FPGAList {B1C8 B1C9 B2C0 B2C1 B2C2 B2C3 B2C4 B2C5 B2C6 B2C7 B2C8 B2C9}

set fileList ""
for {set b 1} {$b<5} {incr b} {
    for {set c 0} {$c<10} {incr c} {
        foreach P {P1 P2} plane {H V} {
            set bpm B${b}C${c}$P
            set sector  B${b}C${c}
            if [catch {exec replaceText Booster.req.bpm.template ${root}.bpm.$bpm \
                         -orig=<bpm>,<sector>,<plane> -repl=${bpm},${sector},${plane} } result] {
                puts stderr "makeBoosterReqFile(1): $result"
                exit 1
            }
            
            if [lsearch -exact $FPGAList $sector]>=0 {
                if [catch {exec sddsprocess ${root}.bpm.$bpm -nowarnings "-match=col,ControlName=*scdu*,!" } result] {
                    puts stderr "makeBoosterReqFile(3): $result"
                    exit 1
                }
            }
            lappend fileList ${root}.bpm.$bpm
        }
    }
}
if [catch {eval exec sddscombine Booster.req.others $fileList -merge -pipe=out | sddsprocess -pipe -edit=column,SimpleControlName,ControlName,S?/./K | sddssort -col=ControlName -pipe=in /tmp/Booster.req -nowarning -numericHigh} result] {
    puts stderr "makeBoosterReqFile(2): $result"
    exit 1
}
puts "Comparing against master PV list"
exec sddsselect /tmp/Booster.req /home/helios/oagData/pvdata/iocRecNamesOAG.sdds -pipe=out -match=SimpleControlName=rec_name -nowarning -reuse | sddsconvert -pipe=in $newFile -delete=column,SimpleControlName


eval file delete $fileList /tmp/Booster.req
puts stderr "Old file: [exec sdds2stream -rows $root.req]"
puts stderr "New  file: [exec sdds2stream -rows $newFile]"
catch {exec rm ${root}.req}
exec ln -s $newFile ${root}.req
exit
