reading csv and processing to return a dat file