mttCreateAcausalBondgraph.m 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. function model = mttCreateAcausalBondgraph(system,root)
  2. global mtt_environment
  3. switch nargin
  4. case 0,
  5. model = [] ; return ;
  6. case 1,
  7. root = [] ;
  8. is_root_model = 1 ;
  9. otherwise,
  10. is_root_model = 0 ;
  11. end
  12. if is_root_model
  13. model = intialise_model(system) ;
  14. directory_name = identify_directory_name(system) ;
  15. source_name = identify_source_name(system,directory_name) ;
  16. mttNotify('...acquiring "abg" source definitions') ;
  17. mttWriteNewLine ;
  18. else
  19. model = propagate_root_data(root) ;
  20. source_name = system ;
  21. end
  22. specification_filename = [source_name,'_abg.txt'] ;
  23. specification = mttFetchSpecification(specification_filename) ;
  24. specification = mttSetFieldDefault(specification,'bondgraph',system) ;
  25. [local_system_name,rubbish] = mttDetachText(system,'/') ;
  26. if isempty(local_system_name)
  27. local_system_name = system ;
  28. end
  29. if is_root_model
  30. source_name = identify_source_name(specification.bondgraph,directory_name) ;
  31. else
  32. source_name = specification.bondgraph ;
  33. end
  34. source_name = mttCutText(source_name,'_abg.fig') ;
  35. bondgraph_filename = [source_name,'_abg.fig'] ;
  36. bondgraph = mttFetchBondgraph(bondgraph_filename) ;
  37. model = mttCreateUnifiedModel(model,bondgraph,specification) ;
  38. model = mttDeleteField(model,'branch') ;
  39. model = mttDeleteField(model,'leaf') ;
  40. if is_root_model
  41. mttWriteNewLine ;
  42. mttNotify('...acquiring "cr" source definitions') ;
  43. mttWriteNewLine ;
  44. for n = 1:length(model.crs)
  45. source_name = model.crs{n} ;
  46. cr_filename = [source_name,'_cr.txt'] ;
  47. if ~mttFileExists(cr_filename)
  48. cr_short_name = mttDetachText(source_name,'/') ;
  49. mttNotify([' ...ERROR: "',cr_short_name,'_cr" source does not exist']) ;
  50. mttWriteNewLine ;
  51. mttNotify([' ...finding dependencies for ',source_name,':']) ;
  52. mttWriteNewLine ;
  53. prefix = mttDetachText(system,'/') ;
  54. if isempty(prefix)
  55. prefix = system ;
  56. end
  57. cr_user = model.cr_usage(n).obj ;
  58. for i = 1:length(cr_user)
  59. mttNotify([' ',prefix,'/',cr_user{i}]) ;
  60. mttWriteNewLine ;
  61. end
  62. end
  63. model.cr(n) = mttFetchInterfaceDefinition(cr_filename) ;
  64. end
  65. model = mttDeleteField(model,'cr_usage') ;
  66. model = mttDeleteField(model,'crs') ;
  67. model = mttDeleteField(model,'abgs') ;
  68. end
  69. model.env = mtt_environment ;
  70. function model = intialise_model(system)
  71. model.representation = 'abg' ;
  72. model.abgs = [] ;
  73. model.crs = [] ;
  74. model.cr_usage = [] ;
  75. model.branch = [] ;
  76. model.leaf = [] ;
  77. function model = propagate_root_data(root)
  78. model.abgs = root.abgs ;
  79. model.crs = root.crs ;
  80. model.cr_usage = root.cr_usage ;
  81. model.branch = root.branch ;
  82. model.leaf = root.leaf ;
  83. function directory = identify_directory_name(system)
  84. mttAssert(ischar(system),'System must be specified by name') ;
  85. working_directory = pwd ;
  86. working_directory = strrep(working_directory,'\','/') ;
  87. [system_name,local_directory] = mttDetachText(system,'/') ;
  88. if isempty(system_name)
  89. local_directory = [] ;
  90. end
  91. if isempty(local_directory)
  92. directory = working_directory ;
  93. else
  94. directory = mttLocateDirectory(working_directory,local_directory) ;
  95. end
  96. function source = identify_source_name(system,directory)
  97. [system_name,local_directory] = mttDetachText(system,'/') ;
  98. if isempty(system_name)
  99. system_name = system ;
  100. local_directory = [] ;
  101. end
  102. source = [directory,'/',system_name] ;