clear

cd run1
for ((sim=0;sim<1;sim++));
	do
	cd simulation$sim
	echo $(pwd)
	rm  -r results
	rm  -r resultsQoE
	mkdir resultsQoE
	cp -R videos results

	cp ../../../Parameters/videoTraces/st_hall_h264 results
	cp ../../../Parameters/videoTraces/hall_h264_128.mp4 results
	cp ../../../Parameters/videoTraces/etmp4 results

	cd results
	mkdir videos
	cp ../../../../Parameters/videoTraces/hall_qcif.yuv videos/hall_qcif.yuv
	cp ../../../../Parameters/videoTraces/psnr videos/psnr

	for ((sn=0;sn<10;sn++)); do
		for ((ch=1;ch<2;ch++)); do
			unset sender 
			sender=$(ls sd_sn_$sn'_ch_'$ch)
			case $? in # se não deu erro
				 0)
				unset receiver 
				unset path 

				receiver=$(ls rd_sn_$sn'_ch_'$ch)
				path=$(pwd)
				path=$path'/videos'

				echo $sender 
				echo $receiver
				echo $path

				./etmp4 -F -0 $sender $receiver st_hall_h264 hall_h264_128.mp4 'video_'$receiver
	
				ffmpeg -i 'video_'$receiver'.mp4' 'video_'$receiver'.yuv'

				mv 'video_'$receiver'.mp4' videos
				mv 'video_'$receiver'.yuv' videos

				cd videos
				./psnr  176  144  420 hall_qcif.yuv  'video_'$receiver'.yuv' > 'psnr_'$receiver
				cd ..

				;; #fim if
				*) #se deu erro
				echo rd_sn_$sn ' não encontrado' >> erro.txt
				;; #fim else
			esac
		done
	done
	cp videos/psnr_* ../resultsQoE
	cp videos/*.mp4 ../resultsQoE
	cp delay*'.txt' ../resultsQoE
	cp loss*'.txt' ../resultsQoE
done
cd ../../..
