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

# $Log: not supported by cvs2svn $
# Revision 1.1  2003/12/12 23:13:12  soliday
# This program replaces the lattice section that was in makeOrbitGlitchFiles
#
#

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 usage "usage: makeLatticeFiles -latticeList \"<lattice1> <lattice2>\""
set latticeList "default"
set args $argv
APSParseArguments {latticeList}

if ![llength $latticeList] {
    puts stderr "Error (0) for $argv0 in [pwd]: No latticeList given"
}

foreach lattice $latticeList {
    cd /home/helios/oagData/sr/lattices/$lattice
    if ![llength [glob -nocomplain sr.h1rm-????]] {
        set output sr.h1rm-0001
    } else {
        set output [APSNextGenerationedName \
                      -name [lindex [lsort [glob -nocomplain sr.h1rm-????]] end] \
                      -newFile 1]
    }
    if [catch {exec sddsxref aps.hrm aps.twi -take=etax -pipe=out \
                 -match=BPMName=ElementName -nowarnings \
                 | sddsnormalize -pipe=in -columns=*:* $output
        file delete sr.h1rm 
        exec ln -s $output sr.h1rm} result] {
        puts stderr "Error (4) for $argv0 in [pwd]: $result"
        exit 1
    }
    if ![llength [glob -nocomplain sr.v1rm-????]] {
        set output sr.v1rm-0001
    } else {
        set output [APSNextGenerationedName \
                      -name [lindex [lsort [glob -nocomplain sr.v1rm-????]] end] \
                      -newFile 1]
    }
    if [catch {exec sddsnormalize aps.vrm $output -column=*:* 
        file delete sr.v1rm 
        exec ln -s $output sr.v1rm} result] {
        puts stderr "Error (5) for $argv0 in [pwd]: $result"
        exit 1
    }
}

exit
