diff --git a/pykat/finesse.py b/pykat/finesse.py index f920cda09055aec82abc959d87089b05d47a08f2..b30b36d66d5fc55e314281f62011e5cb2e37e490 100644 --- a/pykat/finesse.py +++ b/pykat/finesse.py @@ -393,14 +393,14 @@ class kat(object): if values[1] == "FTblock": newTag = values[2] - if self.__currentTag != None and newTag != self.__currentTag: + if self.__currentTag != None and self.__currentTag != NO_BLOCK: 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".format(newTag)) self.__blocks[newTag] = Block(newTag) # create new list to store all references to components in block - self.__currentTag = newTag + self.__currentTag = newTag if values[1] == "FTend": self.__currentTag = NO_BLOCK @@ -524,7 +524,7 @@ class kat(object): raise pkex.BasePyKatException("pdtype command `{0}` is incorrect.".format(line)) self.__currentTag = NO_BLOCK - + def saveScript(self, filename=None): """ Saves the current kat object to a Finesse input file @@ -812,11 +812,12 @@ class kat(object): import datetime strtoday = datetime.datetime.now() out.append(strtoday.strftime("%% Generated by PyKat %d.%m.%Y %H:%M:%S\n") ) - + for key in self.__blocks: objs = self.__blocks[key].contents - if key != NO_BLOCK: + out.append("\n") + if key != NO_BLOCK and np.size(objs)>0: out.append("%%% FTblock " + key + "\n") for obj in objs: @@ -833,7 +834,7 @@ class kat(object): else: out.append(txt + "\n") - if key != NO_BLOCK: + if key != NO_BLOCK and np.size(objs)>0: out.append("%%% FTend " + key + "\n") # now loop through all the nodes and get any gauss commands