#!/usr/bin/perl


@gov = split (/\//,$0); pop @gov; $BINDIR = join ('/',@gov);
$getpar   = "$BINDIR/getpar";

$mk_spec_weight_exe = "$BINDIR/mk_spec_weight_exe";
$fcopy  = "$BINDIR/fitscopy"; # it is more efficient to use fitscopy because
                              # we will be creating columns

$UNDEF = "undefined";

# Read common PERL subs
require "$BINDIR/perlutil.pl";

@PARS = &fixpars (@ARGV); # this is needed to escape arguments with parens etc
chop ( ($infile,$outfile,$expmap) = `$getpar evtfile,o,expmap @PARS` );

if ( $infile  eq $UNDEF ) { die "evtfile=?\n" }
if ( $outfile eq $UNDEF ) { die "o=?\n" }
if ( $expmap  eq $UNDEF ) { die "expmap=?\n" }

if ( ! -e $expmap ) { die "$expmap: file not found\n"; }

system ($fcopy,$infile."[events][col specwght(1E)=0]",$outfile) && die;

$outfile =~ s/^!//;

system ($mk_spec_weight_exe,
	"evtfile=$outfile",
	"expmap=$expmap") && die;

