#!/bin/csh 

# this program will do the segmentation for the new vm-data
# it uses the program 'autoseg' after cutting the speech signal 
# and converting the raw-data into a phondat-file
# usage: vmIIseg CD=<cd-root> <dirpattern> <filepattern>
# If the pattern DIRECTORY or FILE is omitted, the script expands to 
# all possible directories in the volume and all possible files in the
# directories.
# Typical call for a total volume (VM21):
# vmIIseg CD=/data/data19/vm15.0.1 '[a-z][0-9][0-9][0-9][a-z]'
# Typical call for a single directory:
# vmIIseg CD=/data/data19/vm15.0.1 g101a
# Typical call for a single file:
# vmIIseg CD=/data/data19/vm15.0.1 g101a g101acn2.16

set TARGET=/data/data1/beringer
set TURNS=/data/data1/beringer
set CD = ""
set DIRECTORY = ""
set FILE = ""
set name = ""

# set verbose # debugging

# Actually do the argument parsing here

while ( "$1" != "" )
        switch ("$1")
        case *=*:
                set key = `echo "$1" | cut -d= -f1`
                set val = `echo "$1" | cut -d= -f2`
                eval "set $key "= \'"$val"\'
                unset key val
                shift
                breaksw
        default:
                break
        endsw
end

# end option parser

if ( $name == '' ) then
 echo 'usage: autotest CD=volume [icsioptions] [dirpattern] [filepattern]'
 echo CAUTION: If dirpattern or filepattern is ommited, the script will expand to '*'
 exit 1
endif

if ( $CD == '' ) then
 echo 'usage: autotest CD=volume [icsioptions] [dirpattern] [filepattern]'
 echo CAUTION: If dirpattern or filepattern is ommited, the script will expand to '*'
 exit 1
endif
set cd = ${CD:t}


if ( "$1" == '' ) then
  set DIRECTORY = '*'
  echo script will expand to all directories
else 
  set DIRECTORY = "$1"
endif
if ( "$2" == '' ) then
  set FILE = '*'
  echo script will expand to all files
else 
  set FILE = "$2"
endif



# delete old files if present

echo using $TARGET as target directory
if ( -e $TARGET/slflist ) then
  /bin/rm $TARGET/slflist
  touch $TARGET/slflist
endif

cd $CD

#cutting the data into turns

#csh -x ~beringer/autoseg/maketurns CD=$CD #$DIRECTORY $FILE

foreach dir ( $CD/$DIRECTORY ) 
	cd $dir
	foreach rawfile ($TURNS/tmp/$dir:t/$dir:t{c}/*)#`cat $FILE{c}.mar` )
		set output = $rawfile

# phondatfile
		if ( ! -e $output.a16 ) then
			mkdir $TARGET/$name
			mkdir $TARGET/$name/$dir:t{c}
			cat $output | raw2phondat > $TARGET/$name/$dir:t{c}/$output:t.a16
		endif


		echo $TARGET/$name
	end
end

# segmentation

foreach file ( $TARGET/$name/*/* )
	csh -x ~beringer/autoseg/mausseg CD=$TARGET/$name PARTITURSOURCE=/data/data1/beringer/tmp/Eval $file:h:t $file:r:t
end
#csh -x ~beringer/autoseg/mausseg CD=$TARGET/$name PARTITURSOURCE=/home/schiel/bas/VM20.1/par '[a-z][0-9][0-9][0-9][a-z][a-z]'	#$dir:t{c} $output.a16

		echo $cd
		pwd
#	end
#end
#csh -x ~beringer/autoseg/mausseg CD=/data4/SI1000_3 PARTITURSOURCE=/data3/BAS/SI1000/doc/partitur/ta ta tamd100.16