eval 'exec /usr/local/bin/perl -S $0 ${1+"$@"}'  # -*- Mode: perl -*-
    if 0;
#==============================================================
#
#  Abs:  Generate a ChannelWatcher restore file
#
#  Name: cw.pl
#
#  Rem:  This perl script generates the ChannelWatcher
#        restore file from list of devices and a list
#        of attributes with corresponding values.
#        
#  Usage: cw  <device file> <attribute file> <output file>
#
#  Facility: SLAC/LCLS
#
#  Auth: 20-Feb-2007, Koosh           (KOOSH)
#  Rev:  dd-mmm-yyyy, Reviewer's Name (USERNAME)
#--------------------------------------------------------------
#  Mod:
#        dd-mmm-yyyy, First Lastname  (USERNAME):
#          comments
#
#==============================================================
#
use strict;
my $devfile = $ARGV[0];
my $attfile = $ARGV[1];
my $outfile = $ARGV[2];
open(DEVDATA,"$devfile") or 
  die("Error: cannot open file 'devfile'\n");
open (ATTDATA,"$attfile") or
  die("Error: cannot open file 'attfile'\n");
open (OUTDATA, ">$outfile");
my $devline;
my $devnum = 1;
my $attline;
my $attnum = 1;

while( $devline = <DEVDATA> )
{
  chomp($devline);
  while ( $attline = <ATTDATA> )
  {
    chomp ($attline);
    print OUTDATA "$devline:$attline \n";
    $attline++;
  }
  
  seek(ATTDATA, $attline, 0);
  print OUTDATA "\n";
  $devline++;
}

close DEVDATA;
close ATTDATA;
close OUTDATA;
print "Success!\n";

exit 0;
