This is an awk script that, given a list of sensor locations and a 24×365
line annual illuminance file, calculates 300/2000 UDI. I place it in the
public domain, but would appreciate credit.
# Takes as input an 8760-line 3- or 5-phase annual illuminance file
# and a sensor location file called photocells.pts
···
#
# Run with:
# getinfo - < ill-file | awk -f udi.awk
BEGIN {
for (i = 1; (r = getline < "photocells.pts") > 0; i++) {
pt = "(" $1 "," $2 ")"
pts[i] = pt
}
if (r < 0) {
print "photocells.pts does not exist" > "/dev/stderr"
error = 2
exit
}
npts = i - 1;
for (i = 1; i <= npts; i++)
under[i] = over[i] = within[i] = 0
}
{
# samples are every hour, at the half-hour
hr = (NR - 1) % 24
tod = hr + 0.5
# between 8:30am and 5:30pm
if (8.0 <= tod && tod <= 18.0) {
hours++
for (i = 1; i <= npts; i++)
if ($(i) < 300)
under[i]++
else if ($(i) > 2000)
over[i]++
else
within[i]++
}
}
END {
if (error)
exit error
if (NR != 365 * 24) {
print "Error: number of hours not 365 * 24" >"/dev/stderr"
exit 1
}
OFS = "\t"
print "Location", "UDI", "Too Dark", "Too Bright"
for (i = 1; i <= npts; i++)
print pts[i], within[i] / hours, under[i] / hours, over[i] / hours
exit 0
}