The morphologies of distant galaxies. 1: an automated classification system