#!/usr/bin/env bash

sed -e 's/,/ /g;s/</ /g;s/>/ /g' $1 | awk  -vfname=$1 '

function prtFname() {
	if( printed == 0) {
		print fname
		printed = 1
	}
}
BEGIN {
maxZone[0] = 5;
maxZone[1] = 10;
maxZone[2] = 15;
maxZone[3] = 20;
print "Begin"
}
#
#
#
/Ramp AngleID/ {
		angleID = $3
}
/Counting AOI:/ {
		#print $0, "--", $4, "...", $7 
		if( $4 < 380 || $4 > 600 ) {
			prtFname();
			print "\tProblem with Counting AOI MIN at Ramp AngleID: ", angleID, "Value: ", $4, "out of Expected Range 380-600"
		}
		if( $7 < -400 || $7 > -200 ) {
			prtFname();
			print "\tProblem with Counting AOI MAX at Ramp AngleID: ", angleID, "Value: ", $7, "out of Expected Range -400 - -200"
		}
}
/ZoneID: 0/ {
		zoneID = $2
		if(angleID == 0) {
			zone[zoneID] = $4
		} else {
			diff = zone[zoneID] - $4;
			if(diff < 0) {
				diff = 0-diff;
			}
			if(diff > maxZone[zoneID]) {
				prtFname();
				print "\tProblem with ZoneID: ", zoneID, " at Ramp AngleID: ", angleID, ", Value: ", $4, " has jumped ", diff, " pixels in 1 angle change"
			}
			zone[zoneID] = $4
		}
				
		if( $4 < -400 || $4 > -200) {
			prtFname();
			print "\tProblem with ZoneID: ", zoneID, " at Ramp AngleID: ", angleID, "Value: ", $4, "out of Expected Range -400 - -200"
		}
}
/ZoneID: 1/ {
		zoneID = $2
		if(angleID == 0) {
			zone[zoneID] = $4
		} else {
			diff = zone[zoneID] - $4;
			if(diff < 0) {
				diff = 0-diff;
			}
			if(diff > maxZone[zoneID]) {
				prtFname();
				print "\tProblem with ZoneID: ", zoneID, " at Ramp AngleID: ", angleID, ", Value: ", $4, " has jumped ", diff, " pixels in 1 angle change"
			}
			zone[zoneID] = $4
		}
		#print "--"$0 ,"--", $4
		if( $4 < -300 || $4 > -100) {
			prtFname();
			print "\tProblem with ZoneID: ", zoneID, " at Ramp AngleID: ", angleID, "Value: ", $4, "out of Expected Range -300 - -100"
		}
}
/ZoneID: 2/ {
		zoneID = $2
		if(angleID == 0) {
			zone[zoneID] = $4
		} else {
			diff = zone[zoneID] - $4;
			if(diff < 0) {
				diff = 0-diff;
			}
			if(diff > maxZone[zoneID]) {
				prtFname();
				print "\tProblem with ZoneID: ", zoneID, " at Ramp AngleID: ", angleID, ", Value: ", $4, " has jumped ", diff, " pixels in 1 angle change"
			}
			zone[zoneID] = $4
		}
		#print "--"$0 ,"--", $4
		if( $4 < 0 || $4 > 200) {
			prtFname();
			print "\tProblem with ZoneID: ", zoneID, " at Ramp AngleID: ", angleID, "Value: ", $4, "out of Expected Range 0-200"
		}
}
/ZoneID: 3/ {
		zoneID = $2
		if(angleID == 0) {
			zone[zoneID] = $4
		} else {
			diff = zone[zoneID] - $4;
			if(diff < 0) {
				diff = 0-diff;
			}
			if(diff > maxZone[zoneID]) {
				prtFname();
				print "\tProblem with ZoneID: ", zoneID, " at Ramp AngleID: ", angleID, ", Value: ", $4, " has jumped ", diff, " pixels in 1 angle change"
			}
			zone[zoneID] = $4
		}
		#print "--"$0 ,"--", $4
		if( $4 < 200 || $4 > 400) {
			prtFname();
			print "\tProblem with ZoneID: ", zoneID, " at Ramp AngleID: ", angleID, "Value: ", $4, "out of Expected Range 200-400"
		}
}

' 
