code to generate a csv.  Not yet tested