#!/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 args $argv
set configFile ""
set verbose 0
#set outputDir ""
set usage "kill_pv_group -configFile <filename> \[-verbose 1]"
if {[APSStrictParseArguments {configFile verbose}] || ![string length $configFile]} {
    puts stderr "$usage"
    exit 1
}

if ![file exist $configFile] {
    puts stderr "Error: $configFile does not exist!"
    exit 1
}

set pvList [exec sdds2stream -par=ControlName $configFile]
foreach pv $pvList {
    if [catch {exec daq-pv-group status --group-channel $pv} result] {
        # Presumably doesn't exist
        if $verbose {
            puts "$pv doesn't exist"
            flush stdout
        }
    } else {
        if $verbose {
            puts "Destroying $pv"
            flush stdout
        }
        exec daq-pv-group destroy --group-channel $pv
    }
}
if $verbose {
    puts "done."
}
exit 0
