Index: mttroot/mtt/bin/trans/m/cbg2ese.m ================================================================== --- mttroot/mtt/bin/trans/m/cbg2ese.m +++ mttroot/mtt/bin/trans/m/cbg2ese.m @@ -1,9 +1,9 @@ function structure = cbg2ese(system_name, system_type, system_cr, ... system_args, full_name, full_name_repetition, ... repetition,... - structure, infofile) + structure, structure_file, infofile) % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % %%%%% Model Transformation Tools %%%%% % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % @@ -14,10 +14,13 @@ % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % %% Version control history % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % %% $Id$ % %% $Log$ +% %% Revision 1.11 1996/12/07 18:20:11 peterg +% %% Replaces null argument by a default and tells user. +% %% % %% Revision 1.10 1996/12/07 17:37:07 peterg % %% Now handles numbered SS ports appearing at top level. % %% % %% Revision 1.9 1996/12/04 21:49:47 peterg % %% Compares full-name with empty string (instead of testing for zero @@ -50,17 +53,20 @@ % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% system_name, system_type, full_name, pc = '%'; -if nargin<3 - eqnfile = 'stdout'; -end; -if nargin<4 - infofile = 'stdout'; -end; + +% Set up the names corresponding to the structure matrix. +structure_name = [ + 'state ', + 'nonstate ', + 'input ', + 'output ', + 'zero_output ']; + % Are we at the top level of the heirarchy? at_top_level = strcmp(full_name, ''); % Create the (full) system name if at_top_level @@ -70,10 +76,11 @@ else full_name = [full_name, '_', system_name]; full_name_repetition = [full_name_repetition, ... '_', system_name, '_', num2str(repetition)]; end; + % $$$ full_name_type = [full_name, '_', system_type]; % $$$ cbg_name = [full_name_type, '_cbg']; cbg_name = [full_name, '_cbg']; % Return if cbg file doesn't exist @@ -80,16 +87,17 @@ if exist(cbg_name)~=2 disp([cbg_name, ' does not exist']); return end; -% Setup file +% Setup files ese_name = [full_name_repetition, '_ese.r']; -filenum = fopen(ese_name, 'w'); -fprintf(filenum, '\n%s%s Equation file for system %s (file %s)\n', ... +ese_file = fopen(ese_name, 'w'); + +fprintf(ese_file, '\n%s%s Equation file for system %s (file %s)\n', ... pc, pc, full_name_repetition, ese_name); -fprintf(filenum, '%s%s Generated by MTT\n\n', pc, pc); +fprintf(ese_file, '%s%s Generated by MTT\n\n', pc, pc); % Evaluate the system function to get the bonds eval(['[bonds,status,system_type] = ', cbg_name, ';']); abg_name = [system_type, '_abg']; cmp_name = [system_type, '_cmp']; @@ -177,72 +185,95 @@ if exist(eqn_name)~=2 % Try a compound component disp('---PUSH---'); structure = cbg2ese(comp_name, comp_type, cr, args, ... full_name, full_name_repetition, ... - k, structure, infofile); + k, structure, structure_file, infofile); % Link up the bonds - fprintf(filenum, ... + fprintf(ese_file, ... '\n\t%s Equations linking up subsystem %s (%s)\n\n', ... pc, comp_name, comp_type); - name_comp_name = sprintf('%s_%s_%1.0f', ... + name_comp_name = sprintf('%s_%s_%d', ... full_name_repetition, comp_name, k); for port_number=1:length(bond_list) % Effort if comp_bonds(port_number,1)==1 % Source - fprintf(filenum, '%s_MTTu%1.0f := %s;\n', ... + fprintf(ese_file, '%s_MTTu%d := %s;\n', ... name_comp_name, port_number, varname(name_r, ... bond_list(port_number),1)); else % sensor - fprintf(filenum, '%s := %s_MTTy%1.0f;\n', ... + fprintf(ese_file, '%s := %s_MTTy%d;\n', ... varname(name_r, ... bond_list(port_number),1), name_comp_name, port_number); end; % flow if comp_bonds(port_number,2)==-1 % Source - fprintf(filenum, '%s_MTTu%1.0f := %s;\n', ... + fprintf(ese_file, '%s_MTTu%d := %s;\n', ... name_comp_name, port_number, varname(name_r, ... bond_list(port_number),-1)); else % sensor - fprintf(filenum, '%s := %s_MTTy%1.0f;\n', ... + fprintf(ese_file, '%s := %s_MTTy%d;\n', ... varname(name_r, ... bond_list(port_number),-1), name_comp_name, port_number); end; end; disp('---POP---'); else % its a simple component - fprintf(filenum, '\n\t%s Equations for component %s (%s), repetition %1.0f\n\n', ... + fprintf(ese_file, '\n\t%s Equations for component %s (%s), repetition %d\n\n', ... pc, comp_name, comp_type,k); -% Take port SS to be ordinary SS at top level -if at_top_level & strcmp(comp_type, 'SS') - effort_attribute = cr; - flow_attribute = args; - if strcmp(effort_attribute, 'MTT_port') % Its a numbered port - effort_attribute = 'external'; - flow_attribute = 'external'; - cr = effort_attribute; - args = flow_attribute; - end; -end; - -eval(['structure = ', ... + % Take port SS to be ordinary SS at top level + if at_top_level & strcmp(comp_type, 'SS') + effort_attribute = cr; + flow_attribute = args; + if strcmp(effort_attribute, 'MTT_port') % Its a numbered port + effort_attribute = 'external'; + flow_attribute = 'external'; + cr = effort_attribute; + args = flow_attribute; + end; + end; + + % Save the current structure + old_structure = structure; + + % Generate the simple component equations + eval(['structure = ', ... eqn_name, ... - '(name_r,bond_list,comp_bonds,direction,cr,args,structure,filenum);' ]); + '(name_r,bond_list,comp_bonds, ... + direction,cr,args,structure,ese_file);' ]); + + % If structure has changed, write info to structure file. + structure_change = structure-old_structure; + structure_changes = sum(structure_change); + + if structure_changes>0 + which_indices = getindex(structure_change,1); + which_indices = which_indices(:,2)'; + for which_index=which_indices + value = structure(which_index); + fprintf(structure_file, ... + '%s\t%1.0f\t%s\t%s\t%1.0f\n', ... + structure_name(which_index,:), value, ... + comp_name, full_name, repetition); + end; + end; + end; end; end; - fclose(filenum); - + % Close the files + fclose(ese_file); +