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

# $Log: not supported by cvs2svn $
# Revision 1.3  2011/09/27 16:32:40  shang
# corrected the usage message.
#
# Revision 1.2  2011/09/27 16:28:15  shang
# modified to also work for a list of sectors.
#
# Revision 1.1  2011/09/27 16:17:01  shang
# update corrector ADT file for canted undulators through replace S<sector>A:[HV]4 by S<sector>C:[HV]1, <sector> is the canted ID sector number.
#
# 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/OAG/oagData/ADTFiles/srOther
cd $dir

set newFile [APSNextGenerationedName \
		 -directory $dir \
		 -name sr.setread.pv.00001 -newFile 1 -separator "."]
set option "-reedit=col,ControlName,"
foreach sect $CUSectorList {
    append option %/S${sect}A:H4/S${sect}C:H1/%/S${sect}A:V4/S${sect}C:V1/
}

if [catch {exec sddsprocess sr.setread.pv $newFile $option } result] {
    puts stderr "Error1: $result"
    exit 1
}

exec rm  sr.setread.pv
exec ln -s $newFile sr.setread.pv


exit 0