#!/bin/sh

if [ "$#" -lt 1  ]; then
   echo "Need to specify scenario table file"
   exit
fi


filename="$1"
output_dir=/exports/csce/eddie/geos/groups/LURG/models/PLUM/output
echo "Starting scenarios in $output_dir"

while read -r datarow
do
  IFS=',' read -r -a array <<< "$datarow"

  if [ -z "$header" ]; then
     header=( "${array[@]}" )
  else
     scenario="${array[0]}"
     scenario_dir=$output_dir/$scenario
     echo $scenario

     if [ ! -d "$scenario_dir" ]; then
        echo "Scenario $scenario dir is missing, so skipping"
        continue;
     fi

     echo "qsub /exports/csce/eddie/geos/groups/LURG/models/PLUM/plumv2/scripts/runPlum.sh $scenario"
     qsub /exports/csce/eddie/geos/groups/LURG/models/PLUM/plumv2/scripts/runPlum.sh $scenario
  fi
done < $filename

