Overview
Comment: | Initial revision |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | origin/master | trunk |
Files: | files | file ages | folders |
SHA3-256: |
0df907d386137be91c0d0c491a003f8e |
User & Date: | gawthrop@users.sourceforge.net on 1996-08-04 20:01:58 |
Other Links: | branch diff | manifest | tags |
Context
1996-08-04
| ||
20:05:25 | Included port components - eg SS:[1] check-in: 158fedb6ad user: gawthrop@users.sourceforge.net tags: origin/master, trunk | |
20:01:58 | Initial revision check-in: 0df907d386 user: gawthrop@users.sourceforge.net tags: origin/master, trunk | |
18:37:57 | Fixed no causal strokes bug. check-in: 00f3f1f154 user: gawthrop@users.sourceforge.net tags: origin/master, trunk | |
Changes
Added mttroot/mtt/bin/trans/awk/rbg_fig2m.awk version [37a4f0f086].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 | ###################################### ##### 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$ ############################################################### ############################################################## # This (g)awk script reads a fig file in fig 3.1 format. # It interprets the picture as: bonds, arrows and components # as follows: # # Bonds are firm (not dashed etc) polylines with 2 line segments - # fig represents this by a firstline record where # field 1 = 2 (always 2) # field 2 = 1 (polyline) # field 3 = 0 (style is a firm line) # field 14 = 0 (no forward arrow) # field 15 = 0 (backward arrow) # a data field starting with a tab followed by 3 (x,y) cordinates # # Arrows are polylines with 1 line segment and an arrow # fig represents this by a firstline record where # field 1 = 2 (always 2) # field 2 = 1 (polyline) # field 3 = 0 (style is a firm line) # field 14 = 1 for a forward arrow # field 15 = 1 for a backward arrow # an additional data files # a data field starting with a tab followed by 2(x,y) cordinates # # # Strokes are polylines with 1 line segment and and no arrow # fig represents this by a firstline record where # field 1 = 2 (always 2) # field 2 = 1 (polyline) # field 3 = 0 (style is a firm line) # field 14 = 0 (no forward arrow) # field 15 = 0 (backward arrow) # a data field starting with a tab followed by 2(x,y) cordinates # # Components appear in two files -- the fig file and the lbl file # these two files are concatenated with the lbl file first # The lbl file represents components by 3 fields # field 1 is the name # field 2 is the CR name # field 3 is the CR arguments # The fig file represents components by 14 fields # field 1 = 4 # fields 12 and 13 are the coordinates # field 14 is the type:name string terminated by \001 # To prevent text being confused with components, components consist # of alphanumeric characters and : and _ only. # The lbl file is used to sort the components. ############################################################## function exact_match(name1, name2) { return ((match(name1,name2)>0)&&(length(name1)==length(name2))) } function process_lbl() { # This puts the components in the lable file at the top of the list # and saves up the corresponding CR and arguments # note that there may be more than one component per label if ((match($1,"%")==0)&&(NF>0)) { i_label++; name = $1; CR = $2; args = $3; label[i_label,1] = name; label[i_label,2] = CR; label[i_label,3] = args } } function process_text() { # The text string is field 14 onwards str = $14; for (i=15; i<=NF; i++) { str = sprintf("%s %s", str, $i) } # It is terminated by /001 - so delete this termination str = substr(str,1,length(str)-4); # A component string contain only alphanumeric _ and : isa_plain_component = match(str, component_regexp)==0; # A port is an integer within [] isa_port = match(str, port_regexp)>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) } # A component is a plain or a port component isa_component = isa_plain_component||isa_port_component; print str, isa_component; # Coordinates in fields 12 & 13 x_coord = $12; y_coord = $13; if (isa_component) { i_text++; named_component = (match(str,delimiter) > 0); if (named_component) { split(str,a,delimiter); type = a[1]; name = a[2]; # Check if name is in label file and if used already found = 0; name_used = 0; for (i=1; i<=i_label; i++) { lname = label[i,1]; if ( exact_match(name,lname) ) { found = 1; if (name in used) { name_used = 1; CR = label[i,2]; args = label[i,3]; } else { used[name] = 1 } break } } if (!found) { if (isa_plain_component) { printf(warning_f, name) } i_label++; CR = default_cr; args = ""; label[i_label,1] = name; label[i_label,2] = CR; label[i_label,3] = args } # Give it a new entry if already used if (name_used) { i_label++; i_name++; name = sprintf("%1.0f", i_name); label[i_label,1] = name; label[i_label,2] = CR; label[i_label,3] = args } } # Unnamed component if (named_component==0) { i_name++; name = sprintf("%1.0f", i_name); type = str; i_label++; label[i_label,1] = name; label[i_label,2] = default_cr; label[i_label,3] = default_args } # Save in associative arrays by name comp_type[name] = type; x[name] = x_coord; y[name] = y_coord; info[name] = sprintf("%s %s %s %s %s %s %s %s %s %s %s ", \ $1, $2, $3, $4, $5, $6, $7, \ $8, $9, $10, $11); } if (isa_port) { i_port++; port_index = substr(str,2,length(str)-2); ports[i_port] = sprintf("%s %s %s", x_coord, y_coord, port_index); } } function process_bond() { arg_count++; if ( (arg_count-arrow)==1 ) { #Save up bond coords if (NF == (2*bond_coords+1) ) { i_bond++; bonds[i_bond] = sprintf("%s %s %s %s %s %s", \ $2, $3, $4, $5, $6, $7); } #Save up arrow coords if ( (arrow)&&(NF==(2*arrow_coords+1)) ) { i_arrow++; arrows[i_arrow] = sprintf("%s %s %s %s", $2, $3, $4, $5); } #Save up stroke coords if ( (!arrow)&&(NF==(2*stroke_coords+1)) ) { i_stroke++; strokes[i_stroke] = sprintf("%s %s %s %s", $2, $3, $4, $5); } } } function write_cbg() { # Create _cbg.fig file from _abg file - not components if ( (fig_file)&&((object!=text)||(isa_component==0))) { printf $1 >> cbg_file for (i=2; i<=NF; i++) printf(" %s", $i) >> cbg_file; printf("\n") >> cbg_file } } function process_fig() { # Test for the fig format first line and data line data_line = (match($1,data_symbol)>0); first_line = (data_line==0)&&(NF>min_line_length); #Process firstline if (first_line) { object = $1; sub_type = $2; style = $3; f_arrow = ($14==1)&&(object=polyline); b_arrow = ($15==1)&&(object=polyline); arrow = f_arrow||b_arrow; arg_count = 0; } #Process text if (object==text) { process_text() } # Process bond if ( \ (data_line)&& \ (object==polyline)&& \ (sub_type==sub_polyline)&& \ (style==firm_style) \ ) { process_bond() } write_cbg() } BEGIN { sys_name = ARGV[1]; delete ARGV[1]; b_file = sprintf("%s_rbg.m", sys_name); c_file = sprintf("%s_cmp.m", sys_name); cbg_file = sprintf("%s_cbg1.fig", sys_name); warning_f = "WARNING %s \t in fig file but not lbl file - using\n"; warning_l = "WARNING %s \t in lbl file but not fig file - ignoring\n"; data_symbol = "----"; default_cr = ""; default_args = ""; delimiter = ":"; q = "\047"; terminator = "\\001"; component_regexp = "[^0-9a-zA-Z_:]"; port_regexp = "\[[0-9]*\]"; fig_file = 0; min_line_length = 10; object = 0; polyline = 2; sub_polyline=1; firm_style = 0; text = 4; bond_coords = 3; stroke_coords = 2; arrow_coords = 2; i_bond = 0; i_port = 0; i_stroke = 0; i_arrow = 0; i_label = 0; i_text = 0; i_name = 0; } { # Start of .fig file? if ( (NF>0) && (match("#FIG", $1) > 0) ) { fig_file=1; } if (fig_file==0) { process_lbl() } else { process_fig() } } END { #Print out the matlab functions print sprintf("function [rbonds, rstrokes,rcomponents,rports] = %s_rbg", sys_name) > b_file; print sprintf("%%[rbonds,rstrokes,rcomponents,rports] = %s_rbg", sys_name) > b_file; print sprintf("%%Generated by MTT") > b_file; print sprintf("function [comp_type, name, cr, arg] = %s_cmp(i)",\ sys_name) > c_file; print sprintf("%%[comp_type, name, cr, arg] = %s_cmp", sys_name) > c_file; print sprintf("%%Generated by MTT") > c_file; print sprintf("rbonds = [") >> b_file; for (i = 1; i <= i_bond; i++) print bonds[i] >> b_file; for (i = 1; i <= i_arrow; i++) print arrows[i], "-1 -1" >> b_file; print sprintf("];") >> b_file; print sprintf("rstrokes = [") >> b_file; for (i = 1; i <= i_stroke; i++) print strokes[i] >> b_file; print sprintf("];") >> b_file; print sprintf("rcomponents = [") >> b_file; j = 0; 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; printf("\targ = %s%s%s;\n", q, arg, q) >> c_file; print "end" >> c_file } } print sprintf("];") >> b_file; print sprintf("rports = [") >> b_file; for (i = 1; i <= i_port; i++) print ports[i] >> b_file; print sprintf("];") >> b_file; } |