function [C_phi]=resample_func(x,C_phi,gaussp_target)
global ini_Val Invariant Invariant_vt Invariant_sample Invariant_aux ...
    InvariantLog Constraints ODE_pack


ce=ini_Val.ce; cc=ini_Val.cc;
[C_fit, phi_fit] = original_shape_to_fit(x,C_phi); % at points uniformly spaced in arc-length
creparametrize(x,ce,cc); C_phi = reparametrize_func(phi_fit,C_phi);
%[C_fit] = original_shape_to_fit(x); % at points uniformly spaced in arc-length
creparametrize(x,ce,cc); C_phi = reparametrize_func(phi_fit,C_phi);
%[C_fit] = original_shape_to_fit(x); % at points uniformly spaced in arc-length
%creparametrize(x,ce,cc); x = reparametrize(C_fit);


%Update what needs to be updated
% Low order 
if isfield(Invariant,'lower')
    [N_hat,dN_hat,connect_l,h_l] = loworder_Bsp(ini_Val,Invariant.lower);
    Invariant.connect_l = connect_l;    
    Invariant.N_hat = N_hat; 
    Invariant.dN_hat = dN_hat; 
    Invariant.h_l = h_l; 
end
%Even lower order for stabilization
% [N_hatt,dN_hatt,connect_ll,h_l] = loworder_Bsp(ini_Val,Invariant.lower_stab);
% Invariant.N_hatt = N_hatt;
% Invariant.dN_hatt = dN_hatt;
% Invariant.connect_ll = connect_ll;    

% post-processing
Invariant_sample=precal_generic(Invariant_sample.gaussp);
Invariant_aux=precal_generic(Invariant_aux.gaussp);
if isfield(Invariant,'lower')
   [N_hat,dN_hat,spv_l] = loworder_Bsp_generic(ini_Val,Invariant.lower,Invariant_sample.gaussp);
   Invariant_sample.spv_l = spv_l;    
   Invariant_sample.N_hat = N_hat;
end

%if (strcmp(ODE_pack.Dissipation,'MeSt') | strcmp(ODE_pack.Dissipation,'St'))
%    precal_gauss_log;
%end

[C_aux,C1_aux,C2_aux]=interpolate(Invariant_aux,x);
Aux_aux = auxiliary_calculations(Invariant_aux,ini_Val.p,0,C_aux,C1_aux,C2_aux);
arclength=0;
arc(1)=0;
for i = 1:(length(Invariant_aux.gaussp)-1)
    arclength = arclength + 1/(length(Invariant_aux.gaussp)-1)*(Aux_aux.au(i)+Aux_aux.au(i+1))/2;
    arc(i+1)=arclength;
end
arc= arc/arclength;
Invariant_vt.gaussp(1)=0;
for i=2:(length(gaussp_target)-1)
  [val index] = min(abs(gaussp_target(i)-arc));
  Invariant_vt.gaussp(i) = arc(index);
end
Invariant_vt.gaussp(length(gaussp_target))=1;
Invariant_vt=precal_generic(Invariant_vt.gaussp);



