#!/bin/csh -f
# sortsflist

if ($#argv == 0) then
echo  sortsflist ': sorts a list of soundfiles contained within one'
echo  'or more ascii files  (such as the files created by "findsflib"'
echo ' or "findsnd") by pitch abbreviation, and reorders these'
echo ' soundfiles from lowest pitched to highest pitched, followed'
echo ' by any soundfiles whose names do not include a pitch abbreviation.'
echo '   syntax:   sortsflist  infile  [infile2]  [infileN]'
exit 1
endif

/bin/rm -r ~/.tmpsortsflist* >& /dev/null

cat $argv | grep -v COMMENT > ~/.tmpsortsflist2

foreach NOTE (`cat /usr/local/lib/notes | grep -v COMMENT`)
   grep $NOTE ~/.tmpsortsflist2 >> ~/.tmpsortsflist
end

foreach PITCHEDSF (`cat ~/.tmpsortsflist`)
   cat ~/.tmpsortsflist2 | grep -v $PITCHEDSF  > ~/.tmpsortsflist2
end
set PITCHEDNUM =  `cat ~/.tmpsortsflist | wc -w`
set UNPITCHEDNUM =  `cat ~/.tmpsortsflist2 | wc -w`

echo "COMMENT $PITCHEDNUM soundfiles sorted by pitch:"
cat ~/.tmpsortsflist
if (-z ~/.tmpsortsflist2) then
  else
  if ( $UNPITCHEDNUM == "0" ) then
   else
  echo "COMMENT $UNPITCHEDNUM Additional soundfiles without a pitch abbreviation:"
  cat ~/.tmpsortsflist2
   endif
endif
/bin/rm -r ~/.tmpsortsflist* >& /dev/null
