function [numnew]=renew(vari,varname,serialnew)
% fucntion to rewrite the xf.newvarlist
global xf xcount xfnew whereat xnum

indx=find(strcmp(lower(xf.newvarlist),lower(varname))==1);
if ~isempty(indx)
	xf.newvarlist{indx}=varname;
	xfnew(indx).data=vari;
	if serialnew==0
		whereat(indx)=xnum.file;
	elseif serialnew<0
		whereat(xcount.new)=1; %arbitrary number identifying _merg or _f2f type
	else
		whereat(indx)=whereat(serialnew);
		if ~isempty(findstr(varname,'_merg'))
			xfnew(indx).mergfrom=xfnew(serialnew).mergfrom;
		elseif ~isempty(findstr(varname,'_f2f'))
			xfnew(indx).f2f=xfnew(serialnew).f2f;
		end;
	end;
	numnew=indx;
	
% 	indx2=find(whereat([indx])==xnum.file);
% 	if strcmpi(varname(end-4:end),'_merg') | strcmpi(varname(end-3:end),'_f2f')
% 		xf.newvarlist{indx}=varname;
% 		xfnew(indx).data=vari;
% 		numnew=indx;		
% 	elseif ~isempty(indx2)
% 		xf.newvarlist{indx(indx2)}=varname;
% 		xfnew(indx(indx2)).data=vari;
% 		numnew=indx(indx2);
% 	else
% 		xcount.new=xcount.new+1;
% 		xf.newvarlist{xcount.new}=varname;
% 		xfnew(xcount.new).data=vari;
% 		if serialnew==0
% 			whereat(xcount.new)=xnum.file;
% 		else
% 			whereat(xcount.new)=whereat(serialnew);
% 		end;
% 		numnew=xcount.new;
% 	end;

else
	xcount.new=xcount.new+1;
	xf.newvarlist{xcount.new}=varname;
	xfnew(xcount.new).data=vari;
	if serialnew==0
		whereat(xcount.new)=xnum.file;
	elseif serialnew<0
		whereat(xcount.new)=1; %arbitrary number identifying _merg or _f2f type
	else
		whereat(xcount.new)=whereat(serialnew);
		if ~isempty(findstr(varname,'_merg'))
			xfnew(xcount.new).mergfrom=xfnew(serialnew).mergfrom;
		elseif ~isempty(findstr(varname,'_f2f'))
			xfnew(xcount.new).f2f=xfnew(serialnew).f2f;
		end;
	end;
	numnew=xcount.new;
end;
return;

