1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
######################################
##### Model Transformation Tools #####
######################################
# gawk script: rbg_fig2m.awk
# Raw bond-graph conversion from fig to matlab
# P.J.Gawthrop June 1996
# Copyright (c) P.J.Gawthrop, 1996.
###############################################################
## Version control history
###############################################################
## $Id$
## $Log$
## Revision 1.21 1997/08/04 12:49:17 peterg
## Modified to use named (as opposed to numbered) ports.
## Generates a list of component ports in the .rbg file.
## As octave handles string vectors properly, the .cmp file format is not
## really necessary - but I've let it be for the moment.
##
## Revision 1.20 1997/03/19 12:02:01 peterg
|
>
>
>
>
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
######################################
##### Model Transformation Tools #####
######################################
# gawk script: rbg_fig2m.awk
# Raw bond-graph conversion from fig to matlab
# P.J.Gawthrop June 1996
# Copyright (c) P.J.Gawthrop, 1996.
###############################################################
## Version control history
###############################################################
## $Id$
## $Log$
# Revision 1.22 1997/08/09 14:42:39 peterg
# Added underscore to port regexp
#
## Revision 1.21 1997/08/04 12:49:17 peterg
## Modified to use named (as opposed to numbered) ports.
## Generates a list of component ports in the .rbg file.
## As octave handles string vectors properly, the .cmp file format is not
## really necessary - but I've let it be for the moment.
##
## Revision 1.20 1997/03/19 12:02:01 peterg
|
189
190
191
192
193
194
195
196
197
198
199
200
201
202
|
isa_plain_component = isa_plain_component && (depth==0);
# A port is a string within []
isa_port = (match(str, port_regexp)>0)
# It must also be specified at depth 0
isa_port = isa_port && (depth==0);
# A port component is SS followed by : followed by a port string
isa_port_component = 0;
if (match(str, delimiter)) {
split(str,a,delimiter);
isa_port_component = (exact_match(a[1], "SS"))&&
(match(a[2], port_regexp)>0)
|
>
>
>
>
>
>
>
|
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
|
isa_plain_component = isa_plain_component && (depth==0);
# A port is a string within []
isa_port = (match(str, port_regexp)>0)
# It must also be specified at depth 0
isa_port = isa_port && (depth==0);
# Vector port definitions
isa_PORT = ((match(str, PORT_regexp)>0) && (depth==0));
if (isa_PORT) {
print str
}
# A port component is SS followed by : followed by a port string
isa_port_component = 0;
if (match(str, delimiter)) {
split(str,a,delimiter);
isa_port_component = (exact_match(a[1], "SS"))&&
(match(a[2], port_regexp)>0)
|
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
|
default_args = "";
delimiter = ":";
repetition_delimiter = "*";
repetition_regexp = "\\*";
q = "\047";
terminator = "\\001";
component_regexp = "[^0-9a-zA-Z_:\*-]";
port_regexp = "^\[[a-zA-Z0-9_]*\]";
nonport_regexp = "[a-zA-Z]";
isa_fig_file = 0;
min_line_length = 10;
object = 0;
polyline = 2;
sub_polyline=1;
firm_style = 0;
text = 4;
|
|
|
|
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
|
default_args = "";
delimiter = ":";
repetition_delimiter = "*";
repetition_regexp = "\\*";
q = "\047";
terminator = "\\001";
component_regexp = "[^0-9a-zA-Z_:\*-]";
port_regexp = "^\[[a-zA-Z0-9_,]*\]";
nonport_regexp = "[a-zA-Z]";
PORT_regexp = "^PORT .*=";
isa_fig_file = 0;
min_line_length = 10;
object = 0;
polyline = 2;
sub_polyline=1;
firm_style = 0;
text = 4;
|
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
|
# Now do the ordinary components (in no particular order)
for (i = 1; i <= i_label; i++) {
name = label[i,1];
cr = label[i,2];
arg = label[i,3];
if (length(x[name])==0)
printf(warning_l, name);
else {
j++;
print x[name], y[name], info[name] >> b_file;
printf("if i==%1.0f\n", j) >> c_file;
printf("\tcomp_type = %s%s%s;\n", q, comp_type[name], q) >> c_file;
printf("\tname = %s%s%s;\n", q, name, q) >> c_file;
printf("\tcr = %s%s%s;\n", q, cr, q) >> c_file;
|
|
>
>
|
>
|
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
|
# Now do the ordinary components (in no particular order)
for (i = 1; i <= i_label; i++) {
name = label[i,1];
cr = label[i,2];
arg = label[i,3];
if (length(x[name])==0) {
# print error unless its a port component
if (match(name,port_regexp)==0)
printf(warning_l, name);
}
else {
j++;
print x[name], y[name], info[name] >> b_file;
printf("if i==%1.0f\n", j) >> c_file;
printf("\tcomp_type = %s%s%s;\n", q, comp_type[name], q) >> c_file;
printf("\tname = %s%s%s;\n", q, name, q) >> c_file;
printf("\tcr = %s%s%s;\n", q, cr, q) >> c_file;
|
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
|
printf("%s %s\n", a[1], a[2]) >> b_file;
}
printf("];\n\n") >> b_file;
printf("port_name = [\n") >> b_file;
for (i = 1; i <= i_port; i++) {
split(ports[i],a, " ");
printf("'%s'\n", a[3]) >> b_file;
}
printf("];\n\n") >> b_file;
# Print the (external) port list
# printf("n_ports = %1.0f;\n", i_port_component) >> b_file;
printf("port_list = [\n") >> b_file;
for (i = 1; i <= i_port_component; i++)
printf("'[%s]'\n", port_labels[i]) >> b_file;
printf("];\n\n") >> b_file;
}
|
>
>
|
|
|
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
|
printf("%s %s\n", a[1], a[2]) >> b_file;
}
printf("];\n\n") >> b_file;
printf("port_name = [\n") >> b_file;
for (i = 1; i <= i_port; i++) {
split(ports[i],a, " ");
# Remove the []
name = substr(a[3],2,length(a[3])-2);
printf("'%s'\n", name) >> b_file;
}
printf("];\n\n") >> b_file;
# Print the (external) port list
# printf("n_ports = %1.0f;\n", i_port_component) >> b_file;
printf("port_list = [\n") >> b_file;
for (i = 1; i <= i_port_component; i++)
printf("'%s'\n", port_labels[i]) >> b_file;
printf("];\n\n") >> b_file;
}
|