#!/usr/bin/ksh
#imagedir="/export/home1/sdc_image_pool/images"
imagedir=$MOJOE_POOL
if (test ${#imagedir} -lt 1)
    then
    imagedir="/export/home1/sdc_image_pool/images"
fi
#mojoe_dir="/export/home/sdc/mojoe"
mojoe_dir=$MOJOE_DIR
if (test ${#mojoe_dir} -lt 1)
    then
    mojoe_dir=$HOME/mojoe
fi
pattern=`echo $1 | awk '{printf "%05ld", $1}'`
lineno=`cut -c1-5 < $mojoe_dir/dicom_patientlist | grep -n "$pattern" | cut -f1 -d':'`
#
lines=$lineno","$lineno"p"
cat $mojoe_dir/dicom_patientlist | sed -n $lines > $mojoe_dir/dicom_patient1
exam=`cut -c1-5 < $mojoe_dir/dicom_patient1`
dir=`cut -c50- < $mojoe_dir/dicom_patient1 | tr -d ' '`
pat=`cut -c7-48 < $mojoe_dir/dicom_patient1`
if [[ ${#pat} -ge 1 ]]; then
#	echo "$mojoe_dir/dicom/pat2 $imagedir $dir $exam"
	$mojoe_dir/dicom/pat2 $imagedir $dir $exam > $mojoe_dir/dicom_serieslist  2>/dev/null
	awk '{printf "%d %s %d \n", $2, $3, $4}' < $mojoe_dir/dicom_serieslist > $mojoe_dir/serieslist
fi
