WIP: file output section

Updated main program, before split into modules; currently working on
file output section.