%% Write to CellML
function writeBGparas(kappa_name,kappa,Kname,K,q,appendix,fileName)
%kappa_name,kappa,Kname,K,q input:column vectors of string, number
blank='';
unitimport =["J_per_mol","fmol","fmol_per_sec","per_fmol"];
blanks=strcat('',strings(1,length(unitimport)));
unit_all=[blanks;unitimport;unitimport];
kappa_unit=strcat('fmol_per_sec',cell(length(kappa_name),1));
data_kappa=[strcat('kappa_',kappa_name,appendix),kappa_unit,num2cell(kappa)]';
K_unit=strcat('per_fmol',cell(length(Kname),1));
data_K=[strcat('K_',Kname,appendix),K_unit,num2cell(K)]';
q_unit=strcat('fmol',cell(length(Kname),1));
data_q=[strcat('q_',Kname,'_init',appendix),q_unit,num2cell(q)]';
blanks=strcat('',cell(1,(length(kappa_unit)+length(K_unit)+length(q_unit))));
data_all=[blanks;data_q,data_K,data_kappa];
fileID = fopen(fileName,'w');
[~,name,~] = fileparts(fileName);
fprintf(fileID,'def model %s as\n',name);

fprintf(fileID,'%3s def import using "../cellLib/BG/units_BG.cellml" for\n',blank);
fprintf(fileID,'%7s unit %s using unit %s;\n',unit_all(:));
fprintf(fileID,'%3s enddef;\n',blank);
fprintf(fileID,'\n');

fprintf(fileID,'%3s def comp %s as\n',blank,name);
fprintf(fileID,'%7s var %s: %s {init: %g ,pub: out};\n',data_all);
fprintf(fileID,'%3s enddef;\n',blank);
fprintf(fileID,'\n');
fprintf(fileID,'enddef;\n');

fprintf(fileID,'\n');
fclose(fileID);
end