From 925906a077e1aa27f88a78d5fbf66b6fc3d8d6f0 Mon Sep 17 00:00:00 2001 From: Daniel Brown <ddb@star.sr.bham.ac.uk> Date: Tue, 4 Feb 2014 20:19:58 +0000 Subject: [PATCH] sorting out multiple dump node connection issues --- bin/test_const.py | 3 +++ pykat/commands.py | 31 +++++++++++++++++++++++++++---- pykat/components.py | 16 ++++++++-------- pykat/finesse.py | 2 +- pykat/node_network.py | 10 +++++++--- 5 files changed, 46 insertions(+), 16 deletions(-) mode change 100644 => 100755 bin/test_const.py diff --git a/bin/test_const.py b/bin/test_const.py old mode 100644 new mode 100755 index 3dc33b3..9722cb3 --- a/bin/test_const.py +++ b/bin/test_const.py @@ -1,3 +1,6 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + from pykat import finesse from pykat.detectors import * from pykat.components import * diff --git a/pykat/commands.py b/pykat/commands.py index a47b0dd..2b70e25 100644 --- a/pykat/commands.py +++ b/pykat/commands.py @@ -44,11 +44,34 @@ class cavity(Command): class gauss(object): @staticmethod def parseFinesseText(text, kat): - values = text.split(" ") + values = text.split() - if not values[0].startswith("gauss"): + if not values[0].startswith("gauss") or (len(values) != 6 and len(values != 8)): raise exceptions.RuntimeError("'{0}' not a valid Finesse gauss command".format(text)) + name = values[1] + component = values[2] + node = values[3] + + + + if values[0].endswith("**"): + if len(values) == 6: + print "" + elif len(values) == 8: + print "" + elif values[0].endswith("*"): + if len(values) == 6: + print "" + elif len(values) == 8: + print "" + else: + if len(values) == 6: + print "" + elif len(values) == 8: + print "" + + class xaxis(Command): def __init__(self, scale, limits, param, steps, comp=None, axis_type="xaxis"): @@ -94,7 +117,7 @@ class xaxis(Command): @staticmethod def parseFinesseText(text): - values = text.split(" ") + values = text.split() if values[0] != "xaxis" and values[0] != "xaxis*": raise exceptions.RuntimeError("'{0}' not a valid Finesse xaxis command".format(text)) @@ -125,7 +148,7 @@ class x2axis(xaxis): @staticmethod def parseFinesseText(text): - values = text.split(" ") + values = text.split() if values[0] != "x2axis" and values[0] != "x2axis*": raise exceptions.RuntimeError("'{0}' not a valid Finesse xaxis command".format(text)) diff --git a/pykat/components.py b/pykat/components.py index 6761808..ee2242d 100644 --- a/pykat/components.py +++ b/pykat/components.py @@ -234,7 +234,7 @@ class mirror(AbstractMirrorComponent): @staticmethod def parseFinesseText(text): - values = text.split(" ") + values = text.split() if values[0] != "m" and values[0] != "m1" and values[0] != "m2": raise pkex.BasePyKatException("'{0}' not a valid Finesse mirror command".format(text)) @@ -289,7 +289,7 @@ class beamSplitter(AbstractMirrorComponent): @staticmethod def parseFinesseText(text): - values = text.split(" ") + values = text.split() if values[0] != "bs" and values[0] != "bs1" and values[0] != "bs2": raise pkex.BasePyKatException("'{0}' not a valid Finesse beam splitter command".format(text)) @@ -355,7 +355,7 @@ class space(Component): @staticmethod def parseFinesseText(text): - values = text.split(" ") + values = text.split() if values[0] != "s": raise pkex.BasePyKatException("'{0}' not a valid Finesse space command".format(text)) @@ -465,7 +465,7 @@ class grating(Component): @staticmethod def parseFinesseText(text): - values = text.split(" ") + values = text.split() if values[0][0 : 2] != "gr": raise pkex.BasePyKatException("'{0}' not a valid Finesse grating command".format(text)) @@ -533,7 +533,7 @@ class isolator(Component): @staticmethod def parseFinesseText(text): - values = text.split(" ") + values = text.split() if values[0] != "isol": raise pkex.BasePyKatException("'{0}' not a valid Finesse isolator command".format(text)) @@ -575,7 +575,7 @@ class lens(Component): @staticmethod def parseFinesseText(text): - values = text.split(" ") + values = text.split() if values[0] != "lens": raise pkex.BasePyKatException("'{0}' not a valid Finesse lens command".format(text)) @@ -650,7 +650,7 @@ class modulator(Component): @staticmethod def parseFinesseText(text): - v = text.split(" ") + v = text.split() if v[0] != "mod": raise pkex.BasePyKatException("'{0}' not a valid Finesse modulator command".format(text)) @@ -706,7 +706,7 @@ class laser(Component): @staticmethod def parseFinesseText(text): - values = text.split(" ") + values = text.split() if values[0] != "l": raise pkex.BasePyKatException("'{0}' not a valid Finesse laser command".format(text)) diff --git a/pykat/finesse.py b/pykat/finesse.py index 01dcce3..8217878 100644 --- a/pykat/finesse.py +++ b/pykat/finesse.py @@ -497,7 +497,7 @@ class kat(object): for line in after_process: first = line.split(" ",1)[0] if first == "gauss" or first == "gauss*" or first == "gauss**": - pykat.commands.gauss.parseFinesseText(line) + pykat.commands.gauss.parseFinesseText(line, self) elif (first == "scale"): v = line.split() if len(v) == 3: diff --git a/pykat/node_network.py b/pykat/node_network.py index d5e006f..c882dc2 100644 --- a/pykat/node_network.py +++ b/pykat/node_network.py @@ -86,7 +86,7 @@ class NodeNetwork(object): comps = (None,) * 2 if len(comps) >= 2 and comps[0] != None and comps[1] != None: - raise pkex.BasePyKatException("Node is already connected to 2 components") + raise pkex.BasePyKatException("Node '{0}' is already connected to 2 components ({1}, {2})".format(node.name, comps[0], comps[1])) l = list(comps) @@ -118,6 +118,7 @@ class NodeNetwork(object): return n def removeNode(self, node): + if not isinstance(node,Node): raise exceptions.ValueError("node argument is not of type Node") @@ -326,9 +327,12 @@ class Node(object): @property def name(self): return self.__name - + class DumpNode(Node): + __total_dump_node_id = 0 + def __init__(self): - Node.__init__(self, 'dump', None, -1) + DumpNode.__total_dump_node_id -= 1 + Node.__init__(self, 'dump', None, DumpNode.__total_dump_node_id) -- GitLab