Write dat files and added tests for reading dats too