First rough pass.  It works, at least for my ad hoc purposes.