#!/bin/sh  
# \
exec oagtclsh "$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

set patternList \
  [list \
     *:StandardizeSUB \
     *:StdSU \
     *:Std1SU \
     *:DegaussC \
     *:ConditionC \
     *:StandardizeC \
     *:degaussSU \
     *chargeLimitAO \
    ]

set descriptionList \
  [list \
     "conditioning state" \
     "conditioning state" \
     "conditioning state" \
     "conditioning state" \
     "conditioning state" \
     "conditioning state" \
     "conditioning state" \
     "pulsed supply charge limit timeout" \
    ]

set matchOpt ""
foreach pattern $patternList {
    if ![string length $matchOpt] {
        set matchOpt "-match=column,ControlName=$pattern"
    } else {
        append matchOpt ,ControlName=$pattern,|
    }
}

set tmpRoot /tmp/[APSTmpString]
APSAddToTempFileList $tmpRoot

exec sddsconvert /home/helios/oagData/pvdata/iocRecNamesOAG.sdds -pipe=out \
    -retain=column,rec_name -rename=column,rec_name=ControlName \
    | sddsprocess -pipe=in $tmpRoot.all $matchOpt
  
set list1 ""
set index 0
foreach pattern $patternList description $descriptionList {
    APSAddToTempFileList $tmpRoot.$index
    if [catch {exec sddsprocess $tmpRoot.all $tmpRoot.$index \
                 -match=column,ControlName=$pattern \
                 "-print=column,Description,$description" \
                 -reedit=column,ControlName,ei/.PROC/ } result] {
        return -code error "$argv0: problem for pattern $pattern"
    }
    lappend list1 $tmpRoot.$index
    incr index
}


eval exec sddscombine $list1 -merge -pipe=out | sddssort -pipe=in ../DataLogging/PowerSupplies.loc -col=ControlName -numeric
eval file delete $list1 $tmpRoot.all

if {[catch {exec sddsprocess ./../DataLogging/PowerSupplies.loc -print=column,Provider,ca -print=column,ExpectNumeric,y,type=character -print=column,ExpectFieldType,scalar -define=column,ExpectElements,1,type=long -nowarn} results]} {
    puts "ERROR: $results"
    exit
}

sdds load ./../DataLogging/PowerSupplies.loc data
set data(ParameterNames) "InstallLocation"
set data(Parameter.InstallLocation) [list /home/helios/oagData/logonchange/PowerSupplies/PowerSupplies.loc]
set data(Layout.DataMode.Mode) "ascii"
sdds save ./../DataLogging/PowerSupplies.loc data
