A federal judge in California ordered the National Science Foundation to reinstate millions of dollars in grants awarded to the University of California, Los Angeles, finding that the agency had tried to circumvent a ruling in June requiring restoration of the funds.