- Author:
- WeiweiAi <wai484@aucklanduni.ac.nz>
- Date:
- 2022-04-22 10:49:38+12:00
- Desc:
- Remove interactive labeling;
Specify index when using intersect to avoid order errors
add buildComponents.m to wrap multiple building processes;
- Permanent Source URI:
- https://models.cellml.org/workspace/6bc/rawfile/71a79f4273ebfe232057a071766138694777ab84/Scripts/buildComponents.m
function [comp,idx]=buildComponents(csvFile,cellmlFiles,encap,Eqs)
% Build new components from the .csv
[comp,idx]=newComp(csvFile);
% Reuse existing cellml models
for i=1:length(cellmlFiles)
compRead=readComp(cellmlFiles(i));
comp=[comp,compRead];
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
% Build the para component
comp=getPara(comp,idx);
% 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 repetitions of 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