function J =objectivefunctionC(search_scalar,m,p_g,u_g_obs,grad_g,n);
        
%recover some parameters
optscal=m.parameters.optscal(n);
fit=m.parameters.fit(n);
control_type=m.parameters.control_type;

%Update along gradient using scalar supplied by fmincon optimization routine
parameter=p_g+search_scalar*optscal*grad_g;

%Plug parameter into inputs
eval(['inputs.' control_type '=parameter;']);

%Run diagnostic with updated parameters.
u_g=diagnostic_core_nonlinear(m,inputs);

%Compute misfit for this velocity field. 
inputs.fit=fit;
J=Misfit(m.elements,m.nodes,m.loads,m.materials,m.parameters, u_g, u_g_obs,inputs);
