A variational method for inverting hydrographic data