- Author:
- WeiweiAi <wai484@aucklanduni.ac.nz>
- Date:
- 2022-05-04 16:46:31+12:00
- Desc:
- update the readme
- Permanent Source URI:
- https://models.cellml.org/workspace/6bc/rawfile/1fb1954d66fe1e42d0adacab6b501180d6aef676/Scripts/buildComponents.m
function [comp,idx]=buildComponents(csvFile,cellmlFiles,whichComp,labelRead,encap,Eqs)
% Build new components from the .csv
[comp,idx]=newComp(csvFile);
% Build the para component
comp=getPara(comp,idx);
[filepath,~,~] = fileparts(csvFile);
paraCsv=[filepath filesep 'Para.csv'];
writePara(comp,idx,paraCsv)
% Reuse existing cellml models
for i=1:length(cellmlFiles)
comp=[comp,readComp(cellmlFiles(i),whichComp{i})];
end
% Specify the inputs for the existing components
labelComps=string(extractfield(labelRead,'comp'));%unique
cmnames=string(extractfield(comp,'name'));%unique
for i=1:length(labelComps)
icomp=comp(cmnames==labelComps(i));
[~,idxVar,~]=intersect(icomp.vars(:,idx.var),labelRead.vars,'stable');
icomp.vars(idxVar,idx.vctg)="in";
comp(cmnames==labelComps(i)).vars=icomp.vars;
end
% Encapsuate new components
for i=1:length(encap)
chdname=cellstr(encap(i).chd.name);
chddef=cellstr(encap(i).chd.def);
labels=cell(length(chdname),1);
chd={};
[chd(1:length(chdname)).name]=deal(chdname{:});
[chd(1:length(chdname)).def]=deal(chddef{:});
[chd(1:length(chdname)).label]=deal(labels{:});
in_labels=encap(i).chd.label;
if ~isempty(in_labels)
label_comps=string(extractfield(in_labels,'comp'));%unique
label_vars=extractfield(in_labels,'vars');
[~,idxa,idxb]=intersect(chdname,label_comps);
[chd(idxa).label]=deal(label_vars{idxb});
end
comp=encapNew(comp,encap(i).name,chd,idx);
end
% Update variable io description
comp=updateVIO(comp,idx);
% Check the uniqueness of the components
cmnames=string(extractfield(comp,'name'));%unique
if length(cmnames)>length(unique(cmnames))
disp('There are duplicate component names')
return
end
% Link the equations to the components
for i=1:length(Eqs)
comp(cmnames==Eqs(i).comp).Eqs=Eqs(i).listEqs;
end
end