Making AVG_NUM configurable by compiler define (Submitted by Lars)

A minor change which makes the AVG_NUM configurable by compiler define.
Partly Closed #956 and Closes #1166