#!/bin/bash

CONFIG=$1
OUTPUT_BIT_DEPTH=16

MAX_VALUE=-1
for PHANTOM in scenePhantoms[0-9][0-9][0-9]\.*; do
		  MASK=`echo $PHANTOM | sed 's/Phantoms/Masks/'`
		  echo "Processing ./getMax $PHANTOM $MASK $CONFIG"
		  NEW_VALUE_LINE=`./getMax $PHANTOM $MASK $CONFIG | grep MAXX`
		  NEW_VALUE="${NEW_VALUE_LINE:6}"
		  echo "Last max was $NEW_VALUE"
		  if [ $NEW_VALUE -gt $MAX_VALUE ]; then
					 MAX_VALUE=$NEW_VALUE;
		  fi
done

echo "Max value is: " $MAX_VALUE

# MAX_VALUE=60

SCALE=`echo "(2^$OUTPUT_BIT_DEPTH)/$MAX_VALUE" | bc`

echo "Scale is: " $SCALE

for PHANTOM in scenePhantoms[0-9][0-9][0-9]\.*; do
		  MASK=`echo $PHANTOM | sed 's/Phantoms/Masks/'`
		  FINAL=`echo $PHANTOM | sed 's/Phantoms/Final/'`
		  echo "Running ./mitogen -c $CONFIG -p $PHANTOM -m $MASK -f $FINAL -s $SCALE"
		  ./mitogen -c $CONFIG -p $PHANTOM -m $MASK -f $FINAL -s $SCALE
done

