Index: mttroot/mtt/bin/trans/m/write_abg.m ================================================================== --- mttroot/mtt/bin/trans/m/write_abg.m +++ mttroot/mtt/bin/trans/m/write_abg.m @@ -3,10 +3,14 @@ ############################################################### ## Version control history ############################################################### ## $Id$ ## $Log$ +## Revision 1.4 1998/08/26 12:45:38 peterg +## Just prefix ports (comps can't start with numeral) +## Prefix with mttp +## ## Revision 1.3 1998/08/26 12:31:07 peterg ## numerical names prefixed by mtt ## ## Revision 1.2 1998/08/26 11:59:20 peterg ## Don't use strrep to remove[] @@ -30,17 +34,17 @@ fprintf(fid,"function [%s] = %s_abg\n", system_name, system_name); fprintf(fid,"# This function is the acausal bond graph representation of %s\n",system_name); fprintf(fid,"# Generated by MTT on %s",ctime(time)); fprintf(fid,"# The file is in Octave format\n"); - fprintf(fid,"\n# Subsystems and Ports\n"); - i_port=0; + i_port=0; SubsystemList = ""; PortList =""; for i=1:N eval(["[comp_type, name, cr, arg, repetitions] = ", system_name, "_cmp(i);"]); if index(name,"[")==0 # Not a port + SubsystemList = [SubsystemList; name]; fprintf(fid,"\n# Component %s\n", name); fprintf(fid,Sformat,system_name,name,"type",comp_type); fprintf(fid,Sformat,system_name,name,"cr",cr); fprintf(fid,Sformat,system_name,name,"arg",arg); fprintf(fid,Iformat,system_name,name,"repetitions",repetitions); @@ -58,10 +62,11 @@ ch=name(1); # First char of name if (ch>="0")&&(ch<="9") # Its a numeral name=["mttp",name]; # prefix by mttp endif; + PortList = [PortList; name]; fprintf(fid,"\n# Port %s\n", name); fprintf(fid,PIformat,system_name,name,"index",++i_port); fprintf(fid,PSformat,system_name,name,"type",comp_type); fprintf(fid,PSformat,system_name,name,"cr",cr); fprintf(fid,PSformat,system_name,name,"arg",arg); @@ -76,11 +81,27 @@ endfor; fprintf(fid,"];\n"); endif; endfor; - + [N,M]=size(PortList); + if N>0 # Put name in list + fprintf(fid,"\n# Ordered list of Port names\n"); + for i=1:N + fprintf(fid," %s.portlist(%i,:) = \"%s\";\n", system_name, i, PortList(i,:)); + endfor; + endif; + + [N,M]=size(SubsystemList); + if N>0 # Put name in list + fprintf(fid,"\n# Ordered list of subsystem names\n"); + for i=1:N + fprintf(fid," %s.subsystemlist(%i,:) = \"%s\";\n", system_name, i, SubsystemList(i,:)); + endfor; + endif; + + fprintf(fid,"\n# Bonds \n"); [N,M]=size(bonds); # Bonds fprintf(fid,Bformat,system_name); for i=1:N fprintf(fid," ");