#!/bin/bash

PYTOIMG=../python/wec_radar/scans.py

if [ -z "$1" ]
	then
		echo "usage: $0 [ target_directory ]"
		exit -1
fi

rm -f scans.csv
rm -f ahrs.csv


FILES=$1
for f in $FILES
do
	#* Decompress
	echo "-------------------------------------------------"
	echo "Decompressing $f"

	#gunzip -c $f > ./out.pcapng 
	cp $f ./out.pcapng


	#* Print stats for file
	echo "-------------------------------------------------"
	echo "Statistics for $f"
	time pcaptoradar -s out.pcapng

	#* Now Convert to ahrs and scans files
	echo "-------------------------------------------------"
	echo "Creating CSV files for $f"
	time pcaptoahrs -h out.pcapng > ahrs.csv
	time pcaptoradar -AH out.pcapng > scans.csv

	#* Use the python script to make scan frames
	echo "-------------------------------------------------"
	echo "Rendering images for $f"
	mkdir -p img
	time python3 $PYTOIMG -a ahrs.csv -s scans.csv

	#* Render movie
	echo "-------------------------------------------------"
	echo "Rendering movie $f.mp4"
	time ffmpeg -framerate 5 -i ./img/scan_pa_%05d.jpg -vf format=yuv420p  $f.mp4

	#* Cleanup
	echo "-------------------------------------------------"
	echo "Cleaning up"
	rm out.pcapng
	rm scans.csv

done

