| 1 |
#!/bin/sh |
| 2 |
|
| 3 |
# imglob - expand list of image filenames |
| 4 |
# |
| 5 |
# Stephen Smith and Mark Jenkinson, FMRIB Image Analysis Group |
| 6 |
# |
| 7 |
# |
| 8 |
# The imglob file was originally part of FSL - FMRIB's Software Library |
| 9 |
# http://www.fmrib.ox.ac.uk/fsl |
| 10 |
# imglob has now been placed in the public domain. |
| 11 |
# |
| 12 |
# |
| 13 |
# Developed at FMRIB (Oxford Centre for Functional Magnetic Resonance |
| 14 |
# Imaging of the Brain), Department of Clinical Neurology, Oxford |
| 15 |
# University, Oxford, UK |
| 16 |
# |
| 17 |
# |
| 18 |
|
| 19 |
if [ $# -lt 1 ] ; then |
| 20 |
echo "Usage: $0 [-oneperimage] <list of names>" |
| 21 |
exit 0; |
| 22 |
fi |
| 23 |
|
| 24 |
oneperimg=0; |
| 25 |
if [ X"$1"X = "X-oneperimageX" ] ; then |
| 26 |
oneperimg=1; |
| 27 |
shift; |
| 28 |
fi |
| 29 |
|
| 30 |
# process each argument, removing any possible extension and |
| 31 |
# then expanding for valid extensions |
| 32 |
|
| 33 |
lst=""; |
| 34 |
for aa in $@ ; do |
| 35 |
# repeat remove_ext a few times to expand out all wildmasking |
| 36 |
a=`${FSLDIR}/bin/remove_ext ${aa}`; |
| 37 |
# at this point variable 'a' may have been expanded into a list |
| 38 |
for b in $a ; do |
| 39 |
if [ $oneperimg = 1 ] ; then |
| 40 |
fn=`echo ${b}.hdr ${b}.hdr.gz ${b}.nii ${b}.nii.gz ${b}.mnc ${b}.mnc.gz`; |
| 41 |
else |
| 42 |
fn=`echo ${b}.hdr ${b}.hdr.gz ${b}.nii ${b}.nii.gz ${b}.mnc ${b}.mnc.gz ${b}.img ${b}.img.gz`; |
| 43 |
fi |
| 44 |
lst="$lst $fn"; |
| 45 |
done |
| 46 |
done |
| 47 |
|
| 48 |
# remove any instances of unmatched wildmasks (still with * in them) |
| 49 |
lst2=""; |
| 50 |
for fn in $lst ; do |
| 51 |
if [ -f $fn ] ; then |
| 52 |
lst2="$lst2 $fn"; |
| 53 |
fi |
| 54 |
done |
| 55 |
|
| 56 |
# make list unique |
| 57 |
lst=`echo $lst2 | tr ' ' '\n' | sort -u`; |
| 58 |
echo $lst |