An Algorithm for Tuning NMPC Controllers with Application to Chemical Processes