first working version; now need to make plots neater and add labels, etc, and functions to make this a callable routine.