#!/usr/bin/perl

################################################################################
#
# File: HResults.pl
# A perl script for parellel processing of the command 'HResults' from HTK
# 
# Usage:
#	HResults.pl [options] labelList recFiles... 
#
# For details about the usage, check it by typing "HResults" without any options
#	
# This perl script is designed to run transparently, e.g., you can run this
#   script as if you run 'HResults'.
#
# This script submits a single job to the cluster and does not check for
#   job completion.
#
# Written by Bowon Lee, 02/22/2006
#
# Department of the Electrical and Computer Engineering
# University of Illinois at Urbana-Champaign
#
################################################################################

# Specify the command to be executed
$COMMAND = "HResults";

# Generate parameters for the command
@ARGIN = @ARGV;
$command = $COMMAND;
foreach $narg (0..$#ARGIN) {
    $command = "$command $ARGIN[$narg]";
}
print "$command\n";

# Write a script for job submission
$scps = "$COMMAND.sh";
open(SGESCP,">$scps") || die "Cannot open $scps: $!";
print SGESCP '#!/bin/bash';
print SGESCP "\n";
print SGESCP '#$ -S /bin/bash';
print SGESCP "\n";
print SGESCP '#$ -cwd';
print SGESCP "\n";
print SGESCP "\n";
print SGESCP "$command\n";
close(SGESCP);

# Send a job
system("qsub $scps");
system("rm -f $scps*");
