#!/bin/sh

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=`./getMax $PHANTOM $MASK $CONFIG`
		  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 ./mitopacq -c $CONFIG -p $PHANTOM -m $MASK -f $FINAL -s $SCALE"
		  ./mitopacq -c $CONFIG -p $PHANTOM -m $MASK -f $FINAL -s $SCALE
done

