#!/usr/bin/perl
$config_file = $ARGV[0];
system("cp -v control.in.template control.in");
open(PARAMS, $config_file);
while (<PARAMS>) {
    chomp;
    @token = split/\s+/;
    $pattern = $token[0];
    $value = $token[1];
    if ($pattern eq '<seed1>' and $value eq 'random') {
	if ($ENV{JOB_ID}) {
	    split(/\./, $ENV{JOB_ID});
	    $value = $token[0];
	} else {
	    $value = 54321
	}
    }
    if ($pattern eq '<seed2>' and $value eq 'random') {
	$value = `date +%s`;
    }
    print "gsr.pl \"$pattern\" \"$value\" control.in\n";
    system("gsr.pl \"$pattern\" \"$value\" control.in");
}
close(PARAMS);
check_file_for_raw_tags();
exit;

sub check_file_for_raw_tags {
    open (FILE, "control.in");
    while (<FILE>) {
	if (/<.*>/) {
	    #system("rm -v control.in");
	    print;
	    die "un-substituted tag in control.in";
	}
    }
    close(FILE)
}
