0001 function model = dsCombineModels(model1,model2, varargin)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017 options = dsCheckOptions(varargin,{'auto_gen_test_data_flag',0,{0,1}},false);
0018 if options.auto_gen_test_data_flag
0019 varargs = varargin;
0020 varargs{find(strcmp(varargs, 'auto_gen_test_data_flag'))+1} = 0;
0021 varargs(end+1:end+2) = {'unit_test_flag',1};
0022 argin = [{model1}, {model2}, varargs];
0023 end
0024
0025
0026 model1=dsCheckModel(model1, varargin{:});
0027 model2=dsCheckModel(model2, varargin{:});
0028
0029
0030 model.parameters=concatenate_structures(model1.parameters,model2.parameters);
0031 model.fixed_variables=concatenate_structures(model1.fixed_variables,model2.fixed_variables);
0032 model.functions=concatenate_structures(model1.functions,model2.functions);
0033 model.monitors=concatenate_structures(model1.monitors,model2.monitors);
0034 model.ODEs=concatenate_structures(model1.ODEs,model2.ODEs);
0035 model.ICs=concatenate_structures(model1.ICs,model2.ICs);
0036
0037
0038 model.state_variables=cat(2,model1.state_variables,model2.state_variables);
0039 model.conditionals=cat(2,model1.conditionals,model2.conditionals);
0040 model.linkers=cat(2,model1.linkers,model2.linkers);
0041 model.comments=cat(2,model1.comments,model2.comments);
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055 model=orderfields(model,model1);
0056
0057
0058 if options.auto_gen_test_data_flag
0059 argout = {model};
0060
0061 dsUnitSaveAutoGenTestData(argin, argout);
0062 end
0063
0064 end
0065
0066
0067 function out=concatenate_structures(a,b)
0068 if isempty(a) && ~isempty(b)
0069 out=b;
0070 elseif ~isempty(a) && isempty(b)
0071 out=a;
0072 elseif isempty(a) && isempty(b)
0073 out=a;
0074 elseif ~isempty(a) && ~isempty(b)
0075 out=catstruct(a,b);
0076 end
0077 end