Index: mttroot/mtt/bin/trans/m/cbg2ese.m ================================================================== --- mttroot/mtt/bin/trans/m/cbg2ese.m +++ mttroot/mtt/bin/trans/m/cbg2ese.m @@ -4,13 +4,13 @@ structure, structure_file,infofilenum) % Set up globals to count the component inputs and outputs. This relies on % the named SS (the ports) being in the correct order. Using globals here % avoids changing the common argument list for all _eqn files for something % which is only used for named SS components. -global local_u_index -global local_y_index -global at_top_level + global local_u_index + global local_y_index + global at_top_level % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % %%%%% Model Transformation Tools %%%%% % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % @@ -21,10 +21,13 @@ % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % %% Version control history % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % %% $Id$ % %% $Log$ +% %% Revision 1.24 1998/07/27 10:26:02 peterg +% %% No change - but fixed bug in alias_args +% %% % %% Revision 1.23 1998/07/08 12:33:51 peterg % %% Reinstated the infofilenum parameter. % %% % %% Revision 1.22 1998/07/04 07:10:27 peterg % %% Don't evaluate alias if no constitutive relationship or args and write @@ -94,71 +97,71 @@ % %% Sorted out file naming sceme % %% % %% Revision 1.1 1996/08/08 15:53:23 peter % %% Initial revision % %% -% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% system_name, system_type, full_name, -pc = '%'; +pc = "%"; % Set up the names corresponding to the structure matrix. structure_name = [ - 'state ', - 'nonstate ', - 'input ', - 'output ', - 'zero_output ', - 'unknown_input']; + "state ", + "nonstate ", + "input ", + "output ", + "zero_output ", + "unknown_input"]; % Are we at the top level of the heirarchy? -at_top_level = strcmp(full_name, ''); +at_top_level = strcmp(full_name, ""); % Create the (full) system name if at_top_level full_name = system_name; full_name_repetition = system_name; system_type = system_name; else - full_name = [full_name, '_', system_name]; + full_name = [full_name, "_", system_name]; full_name_repetition = [full_name_repetition, ... - '_', system_name, '_', num2str(repetition)]; + "_", system_name, "_", num2str(repetition)]; end; -% $$$ full_name_type = [full_name, '_', system_type]; -% $$$ cbg_name = [full_name_type, '_cbg']; -cbg_name = [full_name, '_cbg']; +% $$$ 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 if exist(cbg_name)~=2 - disp([cbg_name, ' does not exist']); + disp([cbg_name, " does not exist"]); return end; % Setup files -ese_name = [full_name_repetition, '_ese.r']; -ese_file = fopen(ese_name, 'w'); +ese_name = [full_name_repetition, "_ese.r"]; +ese_file = fopen(ese_name, "w"); -fprintf(ese_file, '\n%s%s Equation file for system %s (file %s)\n', ... +fprintf(ese_file, "\n%s%s Equation file for system %s (file %s)\n", ... pc, pc, full_name_repetition, ese_name); -fprintf(ese_file, '%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,components] = ', cbg_name, ';']); - abg_name = [system_type, '_abg']; - cmp_name = [system_type, '_cmp']; - alias_name = [system_type, '_alias']; + eval(["[bonds,status,system_type,components] = ", cbg_name, ";"]); + abg_name = [system_type, "_abg"]; + cmp_name = [system_type, "_cmp"]; + alias_name = [system_type, "_alias"]; % No longer needed - cbg now has components: -% eval(['[junk,components]=', abg_name, ';']); +% eval(["[junk,components]=", abg_name, ";"]); % Find number of bonds [n_bonds,columns] = size(bonds); if (columns ~= 2)&(n_bonds>0) - error('Incorrect bonds matrix: must have 2 columns'); + error("Incorrect bonds matrix: must have 2 columns"); end; % Find number of components [n_components,columns] = size(components); n_components = n_components @@ -190,13 +193,13 @@ bond_list = abs(comp); direction = sign(comp)'*[1 1]; % Convert from arrow orientated to component orientated causality comp_bonds = bonds(bond_list,:).*direction; -disp('---- Component ---'); +disp("---- Component ---"); % Get the component details - eval([ '[comp_type,comp_name,cr,args,repetitions] = ', cmp_name, '(i)' ... + eval([ "[comp_type,comp_name,cr,args,repetitions] = ", cmp_name, "(i)" ... ]); % Alias the args list -- if not at top level message = sprintf("\tfor component %s (%s) within %s",\ comp_name,comp_type,full_name); @@ -207,29 +210,29 @@ cr = alias_args(cr,alias,";",message,infofilenum) end; % Substitute positional ($1 etc) arguments cr = subs_arg(cr,system_cr, ... - 'lin',full_name,comp_type,comp_name,infofilenum); + "lin",full_name,comp_type,comp_name,infofilenum); args = subs_arg(args,system_args, ... - '1',full_name,comp_type,comp_name,infofilenum); + "1",full_name,comp_type,comp_name,infofilenum); % change name of 0 and 1 components -- matlab doesn't like numbers here - if strcmp(comp_type,'0') - comp_type = 'zero'; + if strcmp(comp_type,"0") + comp_type = "zero"; end; - if strcmp(comp_type,'1') - comp_type = 'one'; + if strcmp(comp_type,"1") + comp_type = "one"; end; ports = length(bond_list); if repetitions>1 port_pairs = ports/2; if round(port_pairs)~=port_pairs; - mtt_info(['Repeated component ', comp_name, ... - ' has an odd number of ports - ignoring repetitions'], infofilenum); + mtt_info(["Repeated component ", comp_name, ... + " has an odd number of ports - ignoring repetitions"], infofilenum); repetitions = 1; end; end; if repetitions>1 @@ -257,86 +260,90 @@ end; % Invoke the appropriate equation-generating procedure name_r = full_name_repetition; - eqn_name = [comp_type, '_eqn'] + eqn_name = [comp_type, "_eqn"] if exist(eqn_name)~=2 % Try a compound component - disp('---PUSH---'); + disp("---PUSH---"); bond_list, comp_name, comp_type structure = cbg2ese(comp_name, comp_type, cr, args, ... full_name, full_name_repetition, ... k, structure, structure_file, infofilenum); % Link up the bonds fprintf(ese_file, ... - '\n\t%s Equations linking up subsystem %s (%s)\n\n', ... + "\n\t%s Equations linking up subsystem %s (%s)\n\n", ... pc, comp_name, comp_type); - name_comp_name = sprintf('%s_%s_%d', ... + name_comp_name = sprintf("%s_%s_%d", ... full_name_repetition, comp_name, k); - + +printf("\n\t%s Equations linking up subsystem %s (%s)\n\n",\ + pc, comp_name, comp_type); +bond_list + u_index = 0; y_index = 0; % Count the inputs and outputs for port_number=1:length(bond_list) % Effort if comp_bonds(port_number,1)==1 % Source u_index = u_index + 1; - fprintf(ese_file, '%s_MTTu%d := %s;\n', ... + fprintf(ese_file, "%s_MTTu%d := %s;\n", ... name_comp_name, u_index, varname(name_r, ... bond_list(port_number),1)); else % Sensor y_index = y_index + 1; - fprintf(ese_file, '%s := %s_MTTy%d;\n', ... + fprintf(ese_file, "%s := %s_MTTy%d;\n", ... varname(name_r, ... bond_list(port_number),1), name_comp_name, y_index); end; % Flow if comp_bonds(port_number,2)==-1 % Source u_index = u_index + 1; - fprintf(ese_file, '%s_MTTu%d := %s;\n', ... + fprintf(ese_file, "%s_MTTu%d := %s;\n", ... name_comp_name, u_index, varname(name_r, ... bond_list(port_number),-1)); else % Sensor y_index = y_index + 1; - fprintf(ese_file, '%s := %s_MTTy%d;\n', ... + fprintf(ese_file, "%s := %s_MTTy%d;\n", ... varname(name_r, ... bond_list(port_number),-1), name_comp_name, y_index); end; end; - disp('---POP---'); + disp("---POP---"); else % its a simple component - fprintf(ese_file, '\n\t%s Equations for component %s (%s), repetition %d\n\n', ... + fprintf(ese_file, "\n\t%s Equations for component %s (%s), repetition %d\n\n", ... pc, comp_name, comp_type,k); % Is it a named port? (Name begins with [) - Named_Port = (comp_name(1)=='['); + Named_Port = (comp_name(1)=="["); if Named_Port %Add [ to start of name - name_r = ['[' name_r]; + name_r = ["[" name_r]; end; # % Take port SS to be ordinary SS at top level -# if at_top_level & strcmp(comp_type, 'SS') +# 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'; +# 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 = ', ... + eval(["structure = ", ... eqn_name, ... - '(name_r,bond_list,comp_bonds, ... - direction,cr,args,structure,ese_file);' ]); + "(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; % The following line is to avoid probs with multiport C or I @@ -350,11 +357,11 @@ for which_index=which_indices value = structure(which_index); value_change=value-old_structure(which_index); for k=1:value_change fprintf(structure_file, ... - '%s\t%1.0f\t%s\t%s\t%1.0f\n', ... + "%s\t%1.0f\t%s\t%s\t%1.0f\n", ... structure_name(which_index,:), value-k+1, ... comp_name, full_name, repetition); end; end; end;