#!/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

#
# $Log: not supported by cvs2svn $
# Revision 1.2  1998/09/04 21:43:31  borland
# Added -nowarnings option to sddsselect.
#
# Revision 1.1  1998/09/04 21:40:08  borland
# First version of a script to clean out missing PVs from an SDDS file.
# The file must have a column "ControlName" with the PV names.
#
#

set usage {usage: removeMissingPVs -input <filename> [-output <filename>]}
set args $argv
set input ""
set output ""
if {[APSStrictParseArguments {input output}]} {
    puts stderr $usage
    exit 1
}
if ![string length $input] {
    puts stderr "Error in [file tail $argv0]: no input file given"
    exit 1
}
if ![file exists $input] {
    puts stderr "Error in [file tail $argv0]: $input not found"
    exit 1
}
set tmpRoot /tmp/[APSTmpString]
if [catch {exec sddsconvert $input -pipe=out -retain=column,ControlName \
             | sddsprocess -pipe=in $tmpRoot.burtIn \
             -print=column,ControlType,pv} result] {
    puts stderr "Error in [file tail $argv0]: $result"
    exit 1
}
catch {exec burtrb -f $tmpRoot.burtIn -o $tmpRoot.burtOut -r 5}
if [catch {eval exec sddsselect $input $tmpRoot.burtOut $output \
             -match=ControlName -nowarnings} result] {
    puts stderr "Error in [file tail $argv0]: $result"
    exit 1
}

    
