#!/bin/csh -f
unalias rm
set case    = `pwd`
set case    = $case:t
if ($case == "") then
echo "ERROR: no case.inst-file -> exit"
exit 1
endif
if (-e in.tel) then
cp in.tel in.teloud
rm -f in.tel
endif
if (-e in.tell) rm -f in.tell
if (-e $case.telnes) then
mv $case.telnes $case.telne
endif


set oud = 
set teller = 0
set type =


foreach i ($case.telnes*)
 set j = `echo $i |sed -e "s/$case.telnes//g" `
 echo $i $j
 set j = `echo $j |sed -e "s/[0-9]//g" `
 echo $j
 if ($j != $oud) then
 if ($oud != "") then
    if ($teller == 1) then
	cp $case.telnes${type}1 $case.telnes${type}sum
    else
	echo "2 1.0" >> in.tell
	set t = 1
	while ($t < $teller)
		echo "2 A 1.0" >> in.tell
		@ t ++
	end
	echo "COPY" >> in.tell
	echo $case.telnes${type}sum >> in.tell
	set t = $teller
	@ t --
	echo $teller $t > in.tel
	cat in.tell >> in.tel
	cp in.tel in.tel$type
	tel
    endif
    rm -f in.tel
    set teller = 0
    set type = $j
    set oud = $j
 endif
 rm -f in.tel in.tell
 set teller = 0
 set type = $j
 set oud = $j
 endif
 echo $i >> in.tell
 echo "12 7" >> in.tell
 @ teller ++
end

if ($teller == 1) then
 cp $case.telnes${type}1 $case.telnes${type}sum
else
 echo "2 1.0" >> in.tell
 set t = 1
 while ($t < $teller)
      echo "2 A 1.0" >> in.tell
      @ t ++
 end
 echo "COPY" >> in.tell
 echo $case.telnes${type}sum >> in.tell
 set t = $teller
 @ t --
 echo $teller $t > in.tel
 cat in.tell >> in.tel
 cp in.tel in.tel$type
 tel
 endif
																		    


if (-e $case.telne) then
mv $case.telne $case.telnes
endif

echo "Done."

exit 0

