Separate out the SGRD writing into its own stand-alone script, this
helps with maintenance, testing, and consistency. Fixes #111.