mttCheckBondgraphDeclarations.m 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. function mttCheckBondgraphDeclarations(model)
  2. for i = 1:length(model.sympar)
  3. mttAssert(~ismember(model.sympar{i},model.numpar),...
  4. ['Same name (',model.sympar{i},') used for "numpar" and "abg[...]" parameters']) ;
  5. mttAssert(~ismember(model.sympar{i},model.input),...
  6. ['Same name (',model.sympar{i},') used for "input" and "abg[...]" parameters']) ;
  7. end
  8. for i = 1:length(model.numpar)
  9. mttAssert(~ismember(model.numpar{i},model.input),...
  10. ['Same name (',model.numpar{i},') used for "numpar" and "input" parameters']) ;
  11. mttAssert(~ismember(model.numpar{i},model.sympar),...
  12. ['Same name (',model.numpar{i},') used for "numpar" and "abg[...]" parameters']) ;
  13. end
  14. for i = 1:length(model.input)
  15. mttAssert(~ismember(model.input{i},model.sympar),...
  16. ['Same name (',model.input{i},') used for "input" and "abg[...]" parameters']) ;
  17. mttAssert(~ismember(model.input{i},model.numpar),...
  18. ['Same name (',model.input{i},') used for "numpar" and "input" parameters']) ;
  19. end
  20. all_parameters = [] ;
  21. if ~isempty(model.sympar)
  22. all_parameters = model.sympar ;
  23. end
  24. if ~isempty(model.numpar)
  25. if isempty(all_parameters)
  26. all_parameters = model.numpar ;
  27. else
  28. all_parameters = [all_parameters, model.numpar] ;
  29. end
  30. end
  31. if ~isempty(model.input)
  32. if isempty(all_parameters)
  33. all_parameters = model.input ;
  34. else
  35. all_parameters = [all_parameters, model.input] ;
  36. end
  37. end
  38. object_names = mttGetFieldNames(model,'obj') ;
  39. if ~isempty(all_parameters)
  40. for i = 1:length(object_names)
  41. object_name = object_names{i} ;
  42. object = getfield(model,'obj',object_name) ;
  43. for j = 1:length(object.parameter)
  44. object_parameter = object.parameter{j} ;
  45. if ~isnumeric(object_parameter)
  46. mttAssert(ismember(object_parameter,all_parameters),...
  47. ['Object parameter "',object.parameter{j},'" not previously declared']) ;
  48. end
  49. end
  50. end
  51. for j = 1:length(all_parameters)
  52. current_parameter = all_parameters{j} ;
  53. other_parameters = all_parameters ;
  54. other_parameters(j) = [] ;
  55. mttAssert(~ismember(current_parameter,other_parameters),...
  56. ['Repeated parameter/input name "',current_parameter,'"']) ;
  57. end
  58. end
  59. counter = 0 ;
  60. all_instance_parameters = [] ;
  61. for i = 1:length(object_names)
  62. object_name = object_names{i} ;
  63. object = getfield(model,'obj',object_name) ;
  64. for j = 1:length(object.parameter)
  65. object_parameter = object.parameter{j} ;
  66. if ~isnumeric(object_parameter)
  67. counter = counter + 1 ;
  68. all_instance_parameters{counter} = object_parameter ;
  69. end
  70. end
  71. end
  72. for k = 1:length(all_parameters)
  73. parameter = all_parameters{k} ;
  74. if isempty(all_instance_parameters)
  75. mttAssert(0,['Declared parameter/input "',parameter,'" not used']) ;
  76. else
  77. mttAssert(ismember(parameter,all_instance_parameters),...
  78. ['Declared parameter/input "',parameter,'" not used']) ;
  79. end
  80. end