#!/usr/bin/perl
# script to dump multiple jobs into qsub 
# Written by Gary Hill,    8/27/2001
# Modified by Chihwa Song, 12/17/2004
#
# move to the directory where you want to generate scripts, and then 
# squeuejobs.pl book-ic.pl gz hbook /data/sim/.../muon/ /data/sim/.../book/

$execu  = $ARGV[0];
$inext  = $ARGV[1];
$outext = $ARGV[2];
$indir  = $ARGV[3];
$outdir = $ARGV[4];

$root   = "/home/csong/icecube/simu2002/simuperl/";
$sdummy = $root.$execu." infile outfile";


$i = 0;
foreach  (`ls $indir | grep $inext`) {
   $i++;
   $scriptfile = $execu.".".$i;
   $scriptfile =~ s/.pl//;
   chop($_);

   $script = $sdummy;
   $script =~ s/infile/$indir$_/;
   $ofile  = $_;
   $ofile  =~ s/$inext/$outext/;
   $script =~ s/outfile/$outdir$ofile/;
   print "$script \n\n";

   `echo "#!/bin/sh" > $scriptfile `;
   `echo "$script" >> $scriptfile `;
   `chmod +x  $scriptfile`;
#   `qsub $scriptfile`;   
};
