diff --git a/pykat/commands.py b/pykat/commands.py index a86647bcbc79c18b3bcc7d5787cfc020097381c3..9a2ac779ec67587771116d196925bf8405af5de4 100644 --- a/pykat/commands.py +++ b/pykat/commands.py @@ -11,6 +11,9 @@ from components import * from structs import * class Command(object): + def __init__(self): + self.tag = None + def getFinesseText(self): """ Base class for individual finesse optical components """ raise NotImplementedError("This function is not implemented") diff --git a/pykat/components.py b/pykat/components.py index 783aa5535f196c792218f1d3f946305a6bc8083b..b5398de66d39d009933fb973f65526b4460ebdee 100644 --- a/pykat/components.py +++ b/pykat/components.py @@ -34,6 +34,7 @@ class Component(object) : self._nodes = None self._requested_node_names = [] self._kat = None + self.tag = None # store a unique ID for this component global next_component_id diff --git a/pykat/detectors.py b/pykat/detectors.py index afdc83beaca2d878ff6c0ce250cb76729d2da979..ebbaed8d1be528584ece7d838f58b7d0a6f769e6 100644 --- a/pykat/detectors.py +++ b/pykat/detectors.py @@ -18,6 +18,7 @@ class Detector(object) : self._kat = None self.noplot = False self.enabled = True + self.tag = None if node.find('*'): self._alternate_beam = True diff --git a/pykat/finesse.py b/pykat/finesse.py index 18899984c4f246e66dc1b7f827dcb7b6e094a3b1..c859112e2253ed3d3a566fc0c715b7daf508c70b 100644 --- a/pykat/finesse.py +++ b/pykat/finesse.py @@ -141,11 +141,19 @@ class kat(object): if values[0] == "%%%": if values[1] == "FTblock": newTag = values[2] - if newTag != self.__currentTag and self.__currentTag: + + if self.__currentTag != None and newTag != self.__currentTag: warnings.warn("found block {0} before block {1} ended".format(newTag, self.__currentTag)) + + if newTag in self.__blocks: + raise pkex.BasePyKatException("Block `{0}` has already been read") + + self.__blocks{newTag} = [] # create new list to store all references to components in block self.__currentTag = newTag + if values[1] == "FTend": - self.__currentTag = "" + self.__currentTag = None + continue #warnings.warn("current tag {0}".format(self.__currentTag)) @@ -174,6 +182,7 @@ class kat(object): else: print "Parsing `{0}` into pykat object not implemented yet, added as extra line.".format(line) self.__extra_lines.append(line + "\n") + self.__currentTag= "" def run(self, printout=1, printerr=1, save_output=False, save_kat=False,kat_name=None) : @@ -308,6 +317,7 @@ class kat(object): def add(self, obj) : try: obj.tag = self.__currentTag + if isinstance(obj, Component): if obj.name in self.__components :