Conditions for isoscaling in nuclear reactions