Merit function for the design of grating instruments