Add scalar_type argument to write_scalars and other functions.