#!/bin/sh

# Shellscript mit " chmod u+x dateiname " freigeben!

# Funktion: vergleicht rpr-File und nist-Header auf gleiche Eintrge

# Aufruf: VM_rpr_nist_check  rprfile  signalfile


sigfile=$2
if test -r $sigfile
 then :
 else
  echo "Error:" $sigfile "not a readable file!"
  exit 1
fi
signame=`echo $2 | sed 's#.*\/\([0-9a-z\.]*\)$#\1#'`

rprfile=$1 
if test -r $rprfile
 then :
 else
  echo "Error:" $rprfile "not a readable file!"
  exit 1
fi

rprname=`echo $1 | sed 's#.*\/\([0-9a-z\.]*\)$#\1#'`
echo $rprname $signame

a=`grep "dialogue_name" $rprfile | cut -f 2 | sed "s/[0-9][0-9][0-9][abcd]//"`
b=`head -n 19 $sigfile | grep "scenario_language" | cut -d " " -f 3  | sed "s/\([gejm]\).*/\1/"`
if test "$a" != "$b" -o "$a" = "" -o "$b" = ""
 then
  echo "Error: scenario_language in NIST-Header and dialogue_name in rpr-file do not fit together!"
fi

a=`grep "dialogue_name" $rprfile | cut -f 2 | sed 's/[gejm][0-9][0-9][0-9]\([abcd]\)/\1/'`
b=`head -n 19 $sigfile | grep "scenario_id" | cut -d " " -f 3`
if test "$b" = "main"
 then 
  b="a"
elif test "$b" = "information_desk"
 then
  b="b"
elif test "$b" = "remote_maintenance"
 then
  b="c"
elif test "$b" = "vm1"
 then
  b="d"
 else 
  echo "Error: Invalid scenario_id in NIST-header!"
fi
if test "$a" != "$b" -o "$a" = "" -o "$b" = ""
 then
  echo "Error: scenario_id in NIST-header and dialogue_name in rpr-file do not fit together!"
fi

a=`grep "scenario_id" $rprfile | cut -f 2`
if test "$a" != "$b" -o "$a" = "" -o "$b" = ""
 then
  echo "Error: scenario_id in NIST-header and rpr-file do not fit together!"
fi

a=`grep "dialogue_name" $rprfile | cut -f 2 | sed 's/[gejm]\([0-9][0-9][0-9]\)[abcd]/\1/'`
b=`head -n 19 $sigfile | grep "dialog_id" | cut -d " " -f 3`
if test "$a" != "$b" -o "$a" = "" -o "$b" = ""
 then
  echo "Error: dialog_id in NIST-header and dialogue_name in rpr-file do not fit together!"
fi

a=`grep "scenario_date" $rprfile | cut -f 2`
b=`head -n 19 $sigfile | grep "scenario_date" | cut -d " " -f 3`
if test "$a" != "$b" -o "$a" = "" -o "$b" = ""
 then
  echo "Error: scenario_date in rpr-file and NIST-header are different!"
fi

a=`grep "recording_site" $rprfile | cut -f 2`
b=`head -n 19 $sigfile | grep "recording_site" | cut -d " " -f 3`
if test "$a" != "$b" -o "$a" = "" -o "$b" = ""
 then
  echo "Error: recording_site in rpr-file and NIST-header are different!"
fi

a=`grep "recording_site" $rprfile | cut -f 2`
b=`head -n 19 $sigfile | grep "recording_site" | cut -d " " -f 3`
if test "$a" != "$b" -o "$a" = "" -o "$b" = ""
 then
  echo "Error: recording_site in rpr-file and NIST-header are different!"
fi


a=`grep "recording_site" $rprfile |  cut -f 2`
b=`head -n 19 $sigfile | grep "recording_site" | cut -d " " -f 3`
if test "$a" != "$b" -o "$a" = "" -o "$b" = ""
 then
  echo "Error: recording_site in rpr-file and NIST-header are different!"
fi

channo=`echo $signame | sed 's/[mjeg][0-9][0-9][0-9][abcd][crt][pmwnhdrc]\([1234]\)\.[1a][6l]/\1/'`
a=`egrep -e "speaker${channo}_id" $rprfile | cut -f 2`
b=`head -n 19 $sigfile | grep "speaker_id" | cut -d " " -f 3`
if test "$a" != "$b" -o "$a" = "" -o "$b" = ""
 then
  echo "Error: speaker${channo}_id in rpr-file and speaker_id in NIST-header are different!"
fi

b=`head -n 19 $sigfile | grep "scenario_language" | cut -d " " -f 3 | sed 's/\([gejm]\).*/\1/'`
if test $b = "m"
 then
  a=`egrep -e "speaker${channo}_language" $rprfile | cut -f 2 | tr "," " "`
  c=`echo -n $a | wc -c`
  if test $c -le 2 
   then
    b=`head -n 19 $sigfile | grep "scenario_language" | cut -d " " -f 3 | sed 's/multi_\([egj]\)[a-z]*/\10/'`
    if test $a != $b -o "$a" = "" -o "$b" = ""
     then 
      echo "Error: speaker${channo}_language in rpr-file and scenario_language in NIST-header are different!"
    fi
   else
    aa=`echo $a | sed 's/[egj]\([0123]\) [egj][0123]/\1/'`
    ab=`echo $a | sed 's/[egj][0123] [egj]\([0123]\)/\1/'`
    if test ${ab} != "0"
     then 
      echo "Error: native language in rpr-file not at end of line!"
    fi
    if test $ab -ge $aa
     then
      echo "Error: native language in rpr-file not at end of line!"
    fi 
    b=`head -n 19 $sigfile | grep "scenario_language" | cut -d " " -f 3 | sed 's/multi_\([egj]\)[a-z]*_\([egj]\)[a-z]*/\1 \2/'`
    a=`echo $a | sed 's/\([egj]\)[0123] \([egj]\)[0123]/\1 \2/' | sort`
    if test "$a" != "$b" -o "$a" = "" -o "$b" = ""
     then
      echo "Error: native language in rpr-file and scenario_language in NIST-header are different!"
    fi       
  fi
fi 

b=`head -n 19 $sigfile | grep "recmed_spec" | cut -d " " -f 3 | sed 's/\(.\).*/\1/'`
if test "$b" = "a" 
 then 
  b="p"
fi
argument="/[mwndhpcr]*\("$b"\)[mwnhdcrp]*/\1/"
a=`egrep -e "speaker${channo}_recmed_spec" $rprfile | cut -f 2 | sed s$argument`
if test "$a" != "$b" -o "$a" = "" -o "$b" = ""
 then
  echo "Error: recmed_spec in NIST-header is not in speaker${channo}_recmed_spec in rpr-file!"
fi


