@bgood,
Here’s a link where @sam.mckay worked out a solution to what looks like a very comparable problem:
This should provide a good starting point.