final version of analyze that makes the 4 output files before plotting