function gk_new = update_g_from_CHEASE(xk,gk,vk,xdot,u,stap,geop,trap,it,dt,model,params)
%%
persistent NOUT_file

if isempty(NOUT_file)
    NOUT_file = '';
end

steptime = dt*(it-1) + model.equi.offset - model.equi.init_time;
if steptime >= model.equi.offset && mod(it,model.equi.updateequi) == 1 && model.equi.updateequi >= 1 || model.equi.updateequi == 1 
    % mod=1 not 0 to make sure we execute this at the first
    % iteration
    out = RAPTOR_out(xk,gk,vk,xdot,u, it, stap,geop,trap,model,params);
    out.time = out.time + model.equi.offset - model.equi.init_time;
    
    [gk_new,NOUT_file] = recompute_chease_equil_from_RAPTOR(out,model, steptime, NOUT_file);

else 
    gk_new = gk;
end

return