The rank of the Cartier operator and linear systems on curves