Second seed Stanislas Wawrinka advanced to the quarter-finals of the Portugal Open with a hard-fought victory over Spain's Albert Ramos in Oeiras.