function writeDefault(comp,defaultfile,idx)
vars=extractfield(comp,'vars');
all_vars=[];
blank='';
defUnit=["ampere","becquerel","candela","celsius","coulomb","dimensionless","farad","gram","gray","henry",...
    "hertz","joule","katal","kelvin","kilogram","liter","litre","lumen","lux","meter","metre","mole",...
    "newton","ohm","pascal","radian","second","siemens","sievert","steradian","tesla","volt","watt","weber"];
for i=1: length(vars)
    all_vars=[all_vars;vars{1,i}];    
end
% get all non-repetitive parameters
units=all_vars(:,idx.unit)';
indexp=all_vars(:,idx.vctg)=="para";
[pnames,ip,~]=unique(all_vars(indexp,idx.var)','stable');
punits0=(all_vars(indexp,idx.unit)');
punits=punits0(ip);
pvalues0=(all_vars(indexp,idx.val)');
pvalues=pvalues0(ip);
% init
initIdx=contains(pnames,'_init');
initnames=pnames(initIdx);
initvalues=pvalues(initIdx);
initunits=punits(initIdx);
% Para
paranames=pnames(~initIdx);
paravalues=pvalues(~initIdx);
paraunits=punits(~initIdx);
% Write unit import for default
fileID = fopen(defaultfile,'w');
punitsimport=unique(units);
punitsimport=setdiff(punitsimport,defUnit);
blanks=strcat('',strings(1,length(punitsimport)));
punit_all=[blanks;punitsimport;punitsimport];
fprintf(fileID,'def model default_values as\n');
fprintf(fileID,'%3s def import using "../cellLib/Components/units.cellml" for\n',blank);
fprintf(fileID,'%7s unit %s using unit %s;\n',punit_all(:));
fprintf(fileID,'%3s enddef;\n',blank);
fprintf(fileID,'\n');
% Write paras for default
fprintf(fileID,'%3s def model model_para as\n',blank);
blanks=strcat('',strings(1,length(paranames)));
data_all=[blanks;paranames;paraunits;paravalues];
fprintf(fileID,'%7s var %s: %s {init: %s, pub: out};\n',data_all(:));
fprintf(fileID,'%3s enddef;\n',blank);
fprintf(fileID,'\n');
% Write init for default
fprintf(fileID,'%3s def model initials as\n',blank);
blanks=strcat('',strings(1,length(initnames)));
data_all=[blanks;initnames;initunits;initvalues];
fprintf(fileID,'%7s var %s: %s {init: %s, pub: out};\n',data_all(:));
fprintf(fileID,'%3s enddef;\n',blank);
fprintf(fileID,'enddef;\n');
fclose(fileID);
end