function insert(name,newmodel)
global zeng zeng2

varnum=name.varnum;
name=name.name;

%dummymodel(i).name ,.para,.nodes

temp=find(name=='{');
if isempty(temp)
    eval(['global ' name])
else
    eval(['global ' name(1:(temp-1))])
end
if isempty(zeng2.var)

    zexstim('err',['Error in INSERT.' ]);
    return
end

newmodel=feval(newmodel,'Initial');

if isfield(newmodel,'vini')
    eval([name '.vini=newmodel.vini;'])
    newmodel=rmfield(newmodel,'vini');
end
if isfield(newmodel,'temperature')
    zeng.temperature=newmodel.temperature;
    newmodel=rmfield(newmodel,'temperature');
end 
%Remove fields and find Ilk--------------------------------------------
temp=newmodel;
for i=1:length(temp.I)
   temp.I{i}=rmfield(temp.I{i},'gate');
   if isempty(newmodel.I{i}.gate)
      zeng2.var{varnum}.Ilk=i; %Used in gui_var to identify which I is Ileak   
      eval([name '.rm=1/newmodel.I{i}.G;'])
   end
end
eval([name '.model=temp;'])
%/Remove fields and find Ilk--------------------------------------------


%create setting.var for viewplot%------------------------------------------------------------------------------
paraname_length=4+length(newmodel.I)+length(newmodel.gate); %[four extra are Vm, Ve, Itotal, and Ic]
paraname=cell(paraname_length,1);
paraname{1}='vm';
paraname{2}='ve';
paraname{3}='I';
j=3;
for i=(1:length(newmodel.I))
    j=j+1;
    paraname{j}=['I' newmodel.I{i}.name];
end
j=j+1;
paraname{j}=['Ic'];
for i=(1:length(newmodel.gate))
    j=j+1;
    paraname{j}=[newmodel.gate{i}];
end
zeng2.var{varnum}.paraname=paraname;
%------------------------------------------------------------------------------

%/Remove fields--------------------------------------------
temp=newmodel;
for i=1:length(temp.I)
    temp.I{i}=rmfield(temp.I{i},'G');
    temp.I{i}=rmfield(temp.I{i},'E');
end
newmodel=temp;
%/Remove fields--------------------------------------------


model_length=length(zeng2.dummymodel);
if model_length==0;
   zeng2.dummymodel=cell(1);
   zeng2.dummymodel{1}           =newmodel;
   zeng2.dummymodel{1}.gatenumber=length(zeng2.dummymodel{1}.gate);
   zeng2.dummymodel{1}.Inumber   =length(zeng2.dummymodel{1}.I); 
   zeng2.dummymodel{1}.var=varnum;
   zeng2.dummymodel{1}.nodes=[];
else
   %check if the model exists or not
   for i=1:model_length
      temp=find(zeng2.dummymodel{i}.var==varnum);
      if ~isempty(temp)
         zeng2.dummymodel{i}.var(temp)=[];
         break 
      end
   end
   for i=1:model_length
      if strcmp(zeng2.dummymodel{i}.name, newmodel.name)
         zeng2.dummymodel{i}.var =[zeng2.dummymodel{i}.var varnum];
         return
      end
   end
   zeng2.dummymodel{model_length+1}           =newmodel;
   zeng2.dummymodel{model_length+1}.gatenumber=length(zeng2.dummymodel{1}.gate);
   zeng2.dummymodel{model_length+1}.Inumber   =length(zeng2.dummymodel{1}.I); 
   zeng2.dummymodel{model_length+1}.var       =varnum;
   zeng2.dummymodel{model_length+1}.nodes     =[];
end