Sort channels and sensors in output.

This is required to make the output consistent across different
analysis runs across the same input file.
Code cleanup.