Change to long format data

I'm trying to move away from having a list of arrays (e.g. one per
sector in P) to having a more consistent data structure. This is the
first step towards having everything in 'long format'
First working model w/ code refactoring

There are a lot of changes in this commit, but the summary is that it
takes a refactored demo model and makes it work for the first time.