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

# $Log: not supported by cvs2svn $
# Revision 1.3  2011/09/27 16:32:20  shang
# changed the argument name to sector (to be consistent with UpdateCorrectorADT) and made it also work for list of sectors.
#
# Revision 1.2  2011/09/16 19:35:42  shang
# corrected the usage message.
#
# Revision 1.1  2011/08/23 19:11:22  shang
# swap corrector index in corrector waveform config file for canted undulators through replace S<sector>A:[HV]4 by S<sector>C:[HV]1, <sector> is the canted ID sector number.
#

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

#this script will update the corrector waveform config files due to ID change to canted undulator
#the change is simple, just replace S<cantedIDSector>A:[HV]4 by S<catedIDSector>C:[HV]1

if [catch {exec sddsprocess /home/helios/oagData/sr/XAXSTF/sectors.sdds -pipe=out \
	       -filter=col,CUflag,1,1 \
	       | sdds2stream -pipe -col=Sector} CUSectorList] {
    puts stderr "Error in obtaining Canted undulator sectors: $CUSectorList."
    exit 1
}

set dir /home/helios/oagData/sr/orbitControllaw/waveforms
cd $dir

foreach plane {h v} Plane {H V} {
    set option "-reedit=col,DeviceName,"
    set newFile [APSNextGenerationedName \
		     -directory $dir \
		     -name ${plane}corrInfo.sdds-0001 -newFile 1 -separator -]
    foreach sect $CUSectorList {
	append option %/S${sect}A:${Plane}4/S${sect}C:${Plane}1/
    }
    if [catch {exec sddsprocess ${plane}corrInfo.sdds $newFile $option } result] {
	puts stderr "Error1: $result"
	exit 1
    }
    exec rm ${plane}corrInfo.sdds
    exec ln -s $newFile ${plane}corrInfo.sdds
}

exit 0