#!/usr/bin/perl -w
#-----------------------
# Set memory parameters (pjh, 8/26/2010) may not need to be exactly these; modify threads as needed
# Becky's additions for queuing system
#$ -pe smp 8            # sets queue and number of processors
#$ -V
#$ -cwd
#$ -M mzatko@atmos.washington.edu
#$ -N GEOS_2x25_run       # job name

#---------------------------------------------------------------------------
# Make output files readable by everyone
umask(022);
#---------------------------------------------------------------------------
# Create local shadow variables
my $sCodeDir = qq(/home/disk/horton/mzatko/GEOS-Chem_photod/Code.v9-01-01_photod);
my $sRunDir  = qq(/home/disk/horton/mzatko/GEOS-Chem_photod/runs_v9_01_01_photod);
my $sLog     = qq(/home/disk/horton/mzatko/GEOS-Chem_photod/runs_v9_01_01_photod/log);

#---------------------------------------------------------------------------
# Timestamp start of run
qx(echo '===> Run began at' `date` >> $sLog); 
#---------------------------------------------------------------------------
# Change to the run directory
chdir( qq($sRunDir) ) or die( qq(Cannot cd to $sRunDir) );
if ( $? != 0 ) {
qx(echo 'ERROR: Cannot change to run directory!' >> $sLog );     
exit(1);}

     # qx(limit stacksize unlimited)
     # qx(setenv OMP_NUM_THREADS 8)
     # qx(setenv KMP_STACKSIZE 100m) 

#---------------------------------------------------------------------------
# Run the GEOS-CHEM code
qx(time geos >> $sLog );
if ( $? != 0 ) {
qx(echo 'ERROR running GEOS-CHEM!' >> $sLog );    
exit(1);}
#---------------------------------------------------------------------------
# Rename the binary punch file
qx( mv -f ctm.bpch ctm.bpch.v9-01-01 );                    
#---------------------------------------------------------------------------
# Timestamp end of run
qx(echo '===> Run ended at' `date` >> $sLog);
#---------------------------------------------------------------------------

# Exit normally
exit(0);
