#!/usr/bin/perl -w
# the above is generic form of #! for perl, with warnings
#
# uncommnent following line to run on unix machine, where *.pl is not
# associated with perl 
# this is needed to submit perl script in batch mode on sdx
#
# This is a perl script to run all the input files in a directory.
# this IS NOT the main auto run script that happens every night - that is autorun.pl
#
# to submit this script in batch mode on the sdx make the #!perl the first line,
# submit to serial queue with bsub -q serial runall.pl

# It is designed to be executed from the directory where the input files live.
# The string "$exe" must be modified to point to your executable version
# of cloudy.

# this script could be run as simply
# perl runall.pl, or even 
# runall.pl

# after all the models are run the "checkall.pl" script can be run
# to check that everything went ok

# this is the path to the executable version of the code
# change the string between the double quotes to the location
# of the cloudy executable on your system
#
#$exe = "c:/Projects/Cloudy/trunk/debug/trunk.exe";
#$exe = "c:/projects/Cloudy/trunk/release/trunk.exe";
$exe = "c:/projects/Cloudy/trunk/icl/release/cloudy_icl.exe";

$nMod = 0;
$nskip = 0;

# this loops over all the *.in files in the current directory
# and runs the code to produce *.out files
while ( defined( $input = glob("h2*.in") ) )
{
   if ( $nMod>=$nskip )
   {
      print( "$input going to " );
      $output = $input;
      $output =~ s/\.in//gi;
      if( -e "$output".".out" )
      {
         rename( "$output".".out" , "$output".".bak" );
      }
      $out = "$output".".out";
      print("$output\n");
      # execute the code
      system "nice -n 5 $exe < $input  > $out";
      #system "$exe < $input  > $out";
   }
   ++$nMod;
}

print("\n=========================\n");
printf( "\n %i models were computed, and %i were skipped.\n ",$nMod,$nskip);
print("Now use the checkall.pl script to check results.\n");
print("=========================\n");

