Overview
| Comment: | "mtt -ibg rc odeso view" now works! Still some remaining issues, particularly ports/aliasing. |
|---|---|
| Downloads: | Tarball | ZIP archive |
| Timelines: | family | ancestors | descendants | both | origin/master | trunk |
| Files: | files | file ages | folders |
| SHA3-256: |
6b0982c6b851765044e28e747a3ceeeb |
| User & Date: | geraint@users.sourceforge.net on 2003-04-13 14:22:37.000 |
| Other Links: | branch diff | manifest | tags |
Context
|
2003-04-13
| ||
| 14:59:18 | rc2 now works. Clutch plot is upside down !? check-in: c4ef9d98ab user: geraint@users.sourceforge.net tags: origin/master, trunk | |
| 14:22:37 |
"mtt -ibg rc odeso view" now works! Still some remaining issues, particularly ports/aliasing. check-in: 6b0982c6b8 user: geraint@users.sourceforge.net tags: origin/master, trunk | |
|
2003-04-12
| ||
| 21:06:26 | *** empty log message *** check-in: 094c056f82 user: geraint@users.sourceforge.net tags: origin/master, trunk | |
Changes
Modified mttroot/mtt/bin/trans/m/ibg2abg.m
from [f87d930b16]
to [7d20a69f04].
1 2 3 4 5 6 7 8 |
## -*-octave-*-
function [bonds,components,n_vector_bonds] = \
ibg2abg(name,bonds,infofile,errorfile)
## write useful quantity of data to log
struct_levels_to_print = 4;
| < < | | | < | < < | < | < < < < < > > < > | < | | > | | < < < | < | < < < | < < < | < | | < < < < < < < > | < | | | < | | | < < | | | < | | < | | | | | < | | | | < | < < < < < < < < < < < < < < < | < < < | < < > > | < | < | < | > | > | < < < > | | < < | < | < > | < | < | | < | < < < < < < < < < < < < | > | < > | < | | < < < < < < | < < < < < | < | < > | | | | > | | < < < < < < | | | | < | < > | > | | < | | > | | | < | | | | | | | | | | | | | | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > < < < | > > > | | | > | > > > > > | | > < < > | < < > < > > | | | < | | | | | | > > > | | > > > | > | > | | < | > > > | | | > > > > > > > | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | > > > > > > > > | > > > > > > > > > > > > > > > > | > > > > > > > > > > > > > > > > | | > > > > > > > | > > > > > > > > > > > > > > > > > > > > | | 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 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 |
## -*-octave-*-
function [bonds,components,n_vector_bonds] = \
ibg2abg(name,bonds,infofile,errorfile)
## write useful quantity of data to log
struct_levels_to_print = 4;
################################
## create component structure ##
################################
## loop over each bond in ibg.m file
for [bond, bond_name] = bonds
i = str2num(split(bond_name, "bond")(2,:));
## populate "head" and "tail" structures
## then copy the contents to an overall structure
## track (signed) vector bond number within each component
head.index = +i
tail.index = -i
## extract type of component at each end
head_type = deblank(split(bond.head.component, ":")(1,:));
tail_type = deblank(split(bond.tail.component, ":")(1,:));
## extract name of component at each end
head_name = deblank(split(bond.head.component, ":")(2,:));
tail_name = deblank(split(bond.tail.component, ":")(2,:));
## extract port label data
head.label = bond.head.ports;
tail.label = bond.tail.ports;
## determine whether internal port or subsystem
## and fix names of ports
if (strcmp(head_type, "SS") & (index(head_name, "[") == 1))
head_comp_or_port = "port";
head_name = mtt_strip_name(head_name);
else
head_comp_or_port = "comp";
endif
if (strcmp(tail_type, "SS") & (index(tail_name, "[") == 1))
tail_comp_or_port = "port";
tail_name = mtt_strip_name(tail_name);
else
tail_comp_or_port = "comp";
endif
eval(sprintf("comp_s.%s.%s.type = '%s'",
head_comp_or_port, head_name, head_type));
eval(sprintf("comp_s.%s.%s.type = '%s'",
tail_comp_or_port, tail_name, tail_type));
eval(sprintf("comp_s.%s.%s.bond%i = head",
head_comp_or_port, head_name, i));
eval(sprintf("comp_s.%s.%s.bond%i = tail",
tail_comp_or_port, tail_name, i));
endfor
## comp_s
## comp
## %s (name)
## type
## bond%i
## label
## port
## %s (name)
## type
## bond%i
## label
####################################################
## count number of vector bonds on each component ##
####################################################
if (struct_contains(comp_s, "comp"))
for [comp, comp_name] = comp_s.comp
n = size(struct_elements(comp))(1) - 1;
eval(sprintf("comp_s.comp.%s.n_bonds = %i",
comp_name, n));
endfor
endif
if (struct_contains(comp_s, "port"))
for [port, port_name] = comp_s.port
n = size(struct_elements(port))(1) - 1;
eval(sprintf("comp_s.port.%s.n_bonds = %i",
port_name, n));
endfor
endif
## comp_s
## comp
## %s (name)
## type
## n_bonds
## bond%i
## label
## port
## %s (name)
## type
## n_bonds
## bond%i
## label
########################################################
## ensure labels exist on all ports of each component ##
########################################################
if (struct_contains(comp_s, "comp"))
for [comp, comp_name] = comp_s.comp
if (strcmp(comp.type, "0") | strcmp(comp.type, "1"))
## component is a junction
n_named_ports = 0;
## get labelled ports
for [bond, bond_name] = comp
if (index(bond_name, "bond") == 1)
if (! exist("bond.label"))
bond.label = "[]";
endif
if (! strcmp(bond.label, "[]"))
n_named_ports += 1;
port_label = bond.label;
endif
endif
eval(sprintf("comp.%s = bond", bond_name));
endfor
## attach labels to unlabelled ports
if (n_named_ports == 0)
for [bond, bond_name] = comp
if (index(bond_name, "bond") == 1)
bond.label = "in";
endif
eval(sprintf("comp.%s = bond", bond_name));
endfor
elseif (n_named_ports == 1)
mtt_info(sprintf("Defaulting all ports on junction %s to %s", \
comp_name, port_label), infofile);
for [bond, bond_name] = comp
if (index(bond_name, "bond") == 1)
bond.label = port_label;
endif
eval(sprintf("comp.%s = bond", bond_name));
endfor
elseif (n_named_ports != bond.n_bonds)
mtt_error(sprintf("Junction must have 0,1 or %i port labels", \
n_bonds), errorfile);
endif
else
## component is not a junction
for [bond, bond_name] = comp
if (index(bond_name, "bond") == 1)
if (strcmp(bond.label, "[]"))
if (bond.index > 0)
bond.label = "in";
else
bond.label = "out";
endif
else
bond.label = mtt_strip_name(bond.label);
endif
endif
eval(sprintf("comp.%s = bond", bond_name));
endfor
endif
eval(sprintf("comp_s.comp.%s = comp", comp_name));
endfor
endif
####################
## expand aliases ##
####################
if (struct_contains(comp_s, "comp"))
for [comp, comp_name] = comp_s.comp
if ((! strcmp(comp.type, "0")) & (! strcmp(comp.type, "1")))
alias = eval(sprintf("%s_alias", comp.type));
if (is_struct(alias))
for [bond, bond_name] = comp
if (struct_contains(alias, "bond.label"))
old_name = bond.label;
new_name = eval(sprintf("alias.%s", old_name));
bond.label = new_name;
mtt_info(sprintf("Aliasing [%s] on %s (%s) to [%s]",
old_name, comp_name, comp.type, new_name),
infofile);
endif
eval(sprintf("comp.%s = bond", bond_name));
endfor
endif
eval(sprintf("comp_s.%s = comp", comp_name));
endif
endfor
endif
## comp_s
## comp
## %s (name)
## type
## n_bonds
## bond%i
## label
## port
## %s (name)
## type
## n_bonds
## bond%i
## label
##########################################
## create sub-bonds according to labels ##
##########################################
if (struct_contains(comp_s, "comp"))
for [comp, comp_name] = comp_s.comp
for [bond, bond_name] = comp
if (index(bond_name, "bond") == 1)
[sub_bonds, n_sub_bonds] = split_port(bond.label);
for i = 1:n_sub_bonds
eval(sprintf("bond.subbond%i.label = '%s'",
i, deblank(sub_bonds(i,:))))
endfor
endif
eval(sprintf("comp.%s = bond", bond_name));
endfor
eval(sprintf("comp_s.comp.%s = comp", comp_name));
endfor
endif
if (struct_contains(comp_s, "port"))
for [port, port_name] = comp_s.port
for [bond, bond_name] = port
if (index(bond_name, "bond") == 1)
[sub_bonds, n_sub_bonds] = split_port(bond.label);
for i = 1:n_sub_bonds
eval(sprintf("bond.subbond%i.label = '%s'",
i, deblank(sub_bonds(i,:))));
endfor
endif
eval(sprintf("port.%s = bond", bond_name));
endfor
eval(sprintf("comp_s.port.%s = comp", port_name));
endfor
endif
######################################################
## check that both ends of each bond are compatible ##
######################################################
for [bond, bond_name] = bonds
## FIXME:
1;
endfor
## comp_s
## comp
## %s (name)
## type
## n_bonds
## bond%i
## label
## subbond%i
## port
## %s (name)
## type
## n_bonds
## bond%i
## label
## subbond%i
#########################################
## assign a unique number to each bond ##
#########################################
unique_bond_number = 0;
for [bond, bond_name] = bonds
i = str2num(split(bond_name, "bond")(2,:));
## extract type of component at each end
head.type = deblank(split(bond.head.component, ":")(1,:));
tail.type = deblank(split(bond.tail.component, ":")(1,:));
## extract name of component at each end
head_name = deblank(split(bond.head.component, ":")(2,:));
tail_name = deblank(split(bond.tail.component, ":")(2,:));
## determine whether internal port or subsystem
## and fix names of ports
if (strcmp(head.type, "SS") & (index(head_name, "[") == 1))
head_comp_or_port = "port";
head_name = mtt_strip_name(head_name);
else
head_comp_or_port = "comp";
endif
if (strcmp(tail.type, "SS") & (index(tail_name, "[") == 1))
tail_comp_or_port = "port";
tail_name = mtt_strip_name(tail_name);
else
tail_comp_or_port = "comp";
endif
## create strings to reference each component
head_str = sprintf("comp_s.%s.%s.bond%i",
head_comp_or_port, head_name, i);
tail_str = sprintf("comp_s.%s.%s.bond%i",
tail_comp_or_port, tail_name, i);
head_bond = eval(head_str);
tail_bond = eval(tail_str);
## check compatible sizes
head.n_subs = size(struct_elements(head_bond))(1) - 2;
tail.n_subs = size(struct_elements(tail_bond))(1) - 2;
if (head.n_subs != tail.n_subs)
mtt_error(sprintf("Vector ports %s and %s are not compatible",
head_bond.label, tail_bond.label), errorfile);
elseif (head.n_subs > 1)
mtt_info(sprintf("Vector port %s matches %s",
head_bond.label, tail_bond.label), infofile);
endif
## assign bond number
for i = 1:head.n_subs
++unique_bond_number;
eval(sprintf("%s.subbond%i.index = +%i",
head_str, i, unique_bond_number));
eval(sprintf("%s.subbond%i.index = -%i",
tail_str, i, unique_bond_number));
## write causality for bond
if (strcmp(bond.causality.effort, "head"))
eval(sprintf("causality(%i,1) = +1", unique_bond_number));
elseif (strcmp(bond.causality.effort, "tail"))
eval(sprintf("causality(%i,1) = -1", unique_bond_number));
else
eval(sprintf("causality(%i,1) = 0", unique_bond_number));
endif
if (strcmp(bond.causality.flow, "head"))
eval(sprintf("causality(%i,2) = -1", unique_bond_number));
elseif (strcmp(bond.causality.flow, "tail"))
eval(sprintf("causality(%i,2) = +1", unique_bond_number));
else
eval(sprintf("causality(%i,2) = 0", unique_bond_number));
endif
endfor
endfor
## causality matrix is called "bonds"
bonds = causality;
## comp_s
## comp
## %s (name)
## type
## n_bonds
## bond%i
## label
## subbond%i
## index
## port
## %s (name)
## type
## n_bonds
## bond%i
## label
## subbond%i
## index
#################################
## map component data to cmp.m ##
#################################
## count number of components
if (struct_contains(comp_s, "comp"))
n_comps = size(struct_elements(comp_s.comp), 1)
else
n_comps = 0;
|
| ︙ | ︙ | |||
317 318 319 320 321 322 323 |
this_name = mtt_strip_name(this_name)
else
comp_or_port = "comp";
endif
eval(sprintf("comp_s.%s.%s.index = cmp", comp_or_port, this_name));
endfor
| < | > > > > > > > > > > > > > > > > > > > | > > | < < < < < < | | > > > > > > > > < | | > > > > > > > > > | > > > > | > > | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 |
this_name = mtt_strip_name(this_name)
else
comp_or_port = "comp";
endif
eval(sprintf("comp_s.%s.%s.index = cmp", comp_or_port, this_name));
endfor
## comp_s
## comp
## %s (name)
## type
## n_bonds
## bond%i
## label
## subbond%i
## index
## index
## port
## %s (name)
## type
## n_bonds
## bond%i
## label
## subbond%i
## index
## index
##########################
## write n_vector_bonds ##
##########################
if (struct_contains(comp_s, "comp"))
for [comp, comp_name] = comp_s.comp
n_vector_bonds(comp.index) = comp.n_bonds;
endfor
endif
###########################################
## Write connections matrix (components) ##
###########################################
if (struct_contains(comp_s, "comp"))
n_comps = size(struct_elements(comp_s.comp))(1);
else
n_comps = 0;
endif
components = zeros(n_comps, max(n_vector_bonds));
if (struct_contains(comp_s, "comp"))
for [comp, comp_name] = comp_s.comp
counter = 0;
for [bond, bond_name] = comp
if (index(bond_name, "bond") == 1)
for [sub_bond, sub_bond_name] = bond
if (index(sub_bond_name, "subbond") == 1)
components(comp.index, ++counter) = sub_bond.index
endif
endfor
endif
endfor
endfor
endif
if (struct_contains(comp_s, "port"))
for [port, port_name] = comp_s.port
counter = 0;
for [bond, bond_name] = port
if (index(bond_name, "bond") == 1)
for [sub_bond, sub_bond_name] = bond
if (index(sub_bond_name, "subbond") == 1)
components(port.index, ++counter) = subbond.index;
endif
endfor
endif
endfor
endfor
endif
endfunction
|