Optimal control and data assimilation: principles and approximations