Index: mttroot/mtt/bin/trans/abg2cmp_dia2txt ================================================================== --- mttroot/mtt/bin/trans/abg2cmp_dia2txt +++ mttroot/mtt/bin/trans/abg2cmp_dia2txt @@ -9,6 +9,6 @@ ###################################### set -e # set LANG until fixed bug [647664] -LANG="C" dia2abg.pl --create_component_list --diagram_name=$1 --component_list_file=$1_cmp.txt +LANG="C" dia2abg.pl --create_component_list --diagram_name=$1 Index: mttroot/mtt/bin/trans/abg_dia2m ================================================================== --- mttroot/mtt/bin/trans/abg_dia2m +++ mttroot/mtt/bin/trans/abg_dia2m @@ -9,6 +9,6 @@ ###################################### set -e # set LANG until fixed bug [647664] -LANG="C" dia2abg.pl --create_abg --diagram_name=$1 > $1_abg.m +LANG="C" dia2abg.pl --create_abg --diagram_name=$1 Index: mttroot/mtt/bin/trans/dia2abg.pl ================================================================== --- mttroot/mtt/bin/trans/dia2abg.pl +++ mttroot/mtt/bin/trans/dia2abg.pl @@ -91,24 +91,27 @@ my $label_file = ''; my $component_list_file = ''; my $debug = 0; my $create_component_list = 0; my $create_abg = 0; +my $abg_file = ''; GetOptions ('diagram_name=s' => \$diagram_name, 'dia_file=s' => \$dia_file, 'label_file=s' => \$label_file, 'component_list_file=s' => \$component_list_file, 'debug' => \$debug, 'create_component_list' => \$create_component_list, 'create_abg' => \$create_abg, + 'abg_file=s' => \$abg_file, ); die usage() if $diagram_name eq ''; # Use defaults if necessary: $dia_file = $diagram_name . "_abg.dia" if ($dia_file eq ''); $label_file = $diagram_name . "_lbl.txt" if ($label_file eq ''); +$abg_file = $diagram_name . "_abg.m" if ($abg_file eq ''); $component_list_file = $diagram_name . "_cmp.txt" if ($component_list_file eq ''); # Start Parsing XML, and creating files: my $dom = new XML::DOM::Parser; my ($doc); @@ -119,10 +122,13 @@ get_component_data($objects); get_bond_data($objects); create_component_list() if ($create_component_list); if ($create_abg) { + open (OUT,">$abg_file") || + die "Cannot open $abg_file for writing.\n"; + # Don't update the label file unless we are creating component list and abg simultaneously... if ($create_component_list) { #system("abg2lbl_fig2txt -c $component_list_file $diagram_name") && system("abg2lbl_fig2txt -x $diagram_name") && die "abg2lbl_fig2txt failed."; @@ -130,11 +136,11 @@ get_label_data(); output_abg(); output_bond_causality(); parse_aliases(); - print "endfunction\n"; + print OUT "endfunction\n"; } #print $doc->toString; @@ -186,12 +192,12 @@ } sub parse_aliases { my ($name,@line,$alias); - print "# Aliases\n"; - print "# A double underscore __ represents a comma\n"; + print OUT "# Aliases\n"; + print OUT "# A double underscore __ represents a comma\n"; open (LBL,$label_file) || die "Cannot open label file: $label_file\n"; while () { chomp; @@ -202,15 +208,15 @@ @line = split(/\s+/); die "Label file ALIAS entries must have 2 columns!\n" unless @line == 2; - print "$diagram_name.alias.$line[1] = \"$line[0]\";\n"; + print OUT "$diagram_name.alias.$line[1] = \"$line[0]\";\n"; } close(LBL); - print "## Port domain and units\n"; - print "## Explicit variable declarations\n"; + print OUT "## Port domain and units\n"; + print OUT "## Explicit variable declarations\n"; } sub get_objects_node { my ( $doc_node, $layer_name )= @_; my ($root,$layer_node,$objects); @@ -266,11 +272,11 @@ sub output_abg_header { my ($date); $date = `date`; chomp($date); - print <<"EOF"; + print OUT <<"EOF"; function [${diagram_name}] = ${diagram_name}_abg # This function is the acausal bond graph representation of $diagram_name # Generated by dia2abg.pl on $date # The file is in Octave format @@ -280,11 +286,11 @@ } sub output_component { my ($NM,$type,$cr,$arg,$rep,$stat,$connections) = @_; - print <<"EOF"; + print OUT <<"EOF"; # Component $NM $diagram_name.subsystems.$NM.type = "$type"; $diagram_name.subsystems.$NM.cr = "$cr"; $diagram_name.subsystems.$NM.arg = "$arg"; $diagram_name.subsystems.$NM.repetitions = $rep; @@ -337,11 +343,11 @@ $connections = join(" ",@clist); output_component($NM,$type,$cr,$arg,$rep,$stat,$connections); } - print "# Ordered list of subsystem names\n"; + print OUT "# Ordered list of subsystem names\n"; # order component id's so that entries found in _lbl.txt file are # in _lbl file order, and other entries follow. my (@id_list); @id_list = keys(%component_id_tag); @id_list = sort by_label_file @id_list; @@ -354,36 +360,32 @@ }; my $i=1; foreach my $id (@id_list) { my $name = id_to_name($id); - print " " . $diagram_name . ".subsystemlist($i,:)" . ' = "' + print OUT " " . $diagram_name . ".subsystemlist($i,:)" . ' = "' . $name . " " x ($strlength - length($name)) . '";' . "\n"; $i++; } - print "\n"; + print OUT "\n"; } sub output_bond_causality { my ($mtt_bond_id,$dia_bond_id,$mtt_causality,%reverse_mtt_bond_id_index); - print "# Bonds\n"; - print " $diagram_name.bonds = [\n"; + print OUT "# Bonds\n"; + print OUT " $diagram_name.bonds = [\n"; %reverse_mtt_bond_id_index = reverse(%mtt_bond_id_index); while (($mtt_bond_id,$dia_bond_id) = each(%reverse_mtt_bond_id_index)) { - - #print "mtt: $mtt_bond_id\n"; - #print "dia: $dia_bond_id\n"; - $mtt_causality = get_sign_of_power($dia_bond_id) * get_sign_of_causality($dia_bond_id); - print " $mtt_causality $mtt_causality\n"; + print OUT " $mtt_causality $mtt_causality\n"; } - print " ];\n\n"; + print OUT " ];\n\n"; } sub get_component_data { my ( $objects_node )= @_; my($obj,$id,$attr,$comp,$strattr,$str_elem,$string); @@ -577,16 +579,18 @@ sub print_debug { print STDERR $_[0] if ($debug); } sub usage { - print STDERR "\n"; - print STDERR "Usage: dia2abg.pl --diagram_name [options]\n"; - print STDERR "Options:\n"; - print STDERR "\t--dia_file \n"; - print STDERR "\t--label_file \n"; - print STDERR "\t--component_list_file\n"; - print STDERR "\t--create_component_list\n"; - print STDERR "\t--create_abg\n"; - print STDERR "\t--debug\n"; - print STDERR "\n"; + return + "\n" . + "Usage: dia2abg.pl --diagram_name [options]\n" . + "Options:\n" . + "\t--dia_file \n" . + "\t--label_file \n" . + "\t--component_list_file\n" . + "\t--create_component_list\n" . + "\t--create_abg\n" . + "\t--debug\n" . + "\t--abg_file \n" . + "\n" }