switchtodesign; deleteall; closeall; ############################# #set control switch_control = 1; routing_control = [0, 0, 0; 0, 0, 0]; ############################# #----------------------------------------------------------------# ##position of the elements device_heigth = 400; n1 = 3; n2 = 2; hspace = 300; vspace = device_heigth / n1; for ( i = 1 : n1) { for (j = 1 : n2) { auto_name = addelement("Optical Switch"); switch_name = "S_" + num2str(i) + "_" + num2str(j); setnamed(auto_name, "name", switch_name); setposition(switch_name, i * hspace, j * vspace); setnamed(switch_name, "control", routing_control(j, i)); } } flipelement( "S_3_1" ); flipelement( "S_3_2" ); #----------------------------------------------------------------# ##connections connect("S_1_1", "port 3", "S_2_1", "port 1"); connect("S_1_1", "port 4", "S_2_2", "port 1"); connect("S_1_2", "port 3", "S_2_1", "port 2"); connect("S_1_2", "port 4", "S_2_2", "port 2"); connect("S_2_1", "port 3", "S_3_1", "port 3"); connect("S_2_1", "port 4", "S_3_2", "port 3"); connect("S_2_2", "port 3", "S_3_1", "port 4"); connect("S_2_2", "port 4", "S_3_2", "port 4"); #----------------------------------------------------------------# ##create compound n = 4; selectall; createcompound; COMP_name = "SWITCH"; set("name", COMP_name); setposition(COMP_name, 200, 200); for (i = 1 : n) { addport(COMP_name, "input_" + num2str(i), "Input", "Optical Signal", "left"); } for (j = 1 : n) { addport(COMP_name, "output_" + num2str(j), "Output", "Optical Signal", "right"); } autoarrange(COMP_name,1); for (ii = 1 : n) { select("SWITCH::RELAY_" + num2str(ii)); set("x position", 0); set("y position", (ii - 1) * vspace); if (mod(ii, 2) == 1) { connect("SWITCH::RELAY_" + num2str(ii), "output", "SWITCH::S_1_" + num2str(ceil(ii / 2)), "port 1"); } else { connect("SWITCH::RELAY_" + num2str(ii), "output", "SWITCH::S_1_" + num2str(ii / 2), "port 2"); } select("SWITCH::RELAY_" + num2str(ii + n)); set("x position", 4 * hspace); set("y position", (ii - 1) * vspace); if (mod(ii, 2) == 1) { connect("SWITCH::RELAY_" + num2str(ii + n), "input", "SWITCH::S_3_" + num2str(ceil(ii / 2)), "port 1"); } else { connect("SWITCH::RELAY_" + num2str(ii + n), "input", "SWITCH::S_3_" + num2str(ii / 2), "port 2"); } } #----------------------------------------------------------------# ##setup script string1 = "routing_control = [" + num2str(0) + ", " + num2str(0) + ", " + num2str(0) + ";\n"; string2 = " " + num2str(0) + ", " + num2str(0) + ", " + num2str(0) + "];\n\n"; string3 = "for (i = 1 : 3) {\n for (j = 1 : 2) {\n switch_name = \"S_\" + num2str(i) + \"_\" + num2str(j);\n setnamed(switch_name, \"control\", routing_control(j, i));\n }\n}"; setnamed(COMP_name, "setup script", string1 + string2 + string3);