#!/bin/csh -f
#
# Name: ima-getrunlist
# Purpose: given a directory with ima files from one exam, 
# returns a list of the run numbers.

if($#argv != 1) then
  echo "USAGE: ima-getrunlist imadir"
  exit 1;
endif

set imadir  = $argv[1];
if( ! -e $imadir ) then
  echo "ERROR: $imadir does not exist"
  exit 1;
endif

pushd $imadir > /dev/null

# Create a tmp file with three columns: seriesno runno imageno 
# for each ima file
set tmpfile = /tmp/ima-getrunlist-$$
rm -f $tmpfile
touch $tmpfile
ima-parse-name * > $tmpfile
if($status) then
  echo "ERROR: ima-parse-name failed" 
  rm -f $tmpfile
  exit 1;
endif

# Mine the tmp file for a unique list of series numbers #
set serieslist  = `cat $tmpfile | awk '{print $2}' | sort -n | uniq`;

echo $serieslist

rm -f $tmpfile


exit 0;

#--------------------------------------------------------#
