Commit 49de1b71 authored by Daniel Brown's avatar Daniel Brown
Browse files

adding in block selector to loadkatfile and parsecommands, so that it only...

adding in block selector to loadkatfile and parsecommands, so that it only reads in certain blocks. Fixed factorial code in HG_beam
parent 2989e95b
......@@ -9,3 +9,5 @@ beam.n = 5
beam.m = 6
beam.plot()
......@@ -20,7 +20,7 @@ class Command(object):
def __init__(self, name):
self.tag = None
self.__removed = False
self.__name = name
self.__name = name.strip("*")
def getFinesseText(self):
""" Base class for individual finesse optical components """
......
......@@ -484,15 +484,15 @@ class kat(object):
( '::;;+;;: `-"' =" /,`"" `) /
L. \\`:::a:f c_/ n_'
..`--...___`. . ,
`^-....____: +. {1}""".format(pykat.__version__, pykat_web)
`^-....____: +. {1}\n""".format(pykat.__version__, pykat_web)
def loadKatFile(self, katfile):
def loadKatFile(self, katfile, blocks=None):
commands=open(katfile).read()
self.parseCommands(commands)
self.parseCommands(commands, blocks=blocks)
def parseKatCode(self, code):
def parseKatCode(self, code, blocks=None):
#commands = code.split("\n")
self.parseCommands(code)
self.parseCommands(code, blocks=blocks)
def processConstants(self, commands):
"""
......@@ -547,7 +547,7 @@ class kat(object):
return commands_new
def parseCommands(self, commands):
def parseCommands(self, commands, blocks=None):
blockComment = False
commands=self.remove_comments(commands)
......@@ -558,12 +558,13 @@ class kat(object):
# objects have been set and created
for line in commands:
#for line in commands:
try:
if len(line.strip()) >= 2:
line = line.strip()
# Looking for block start or end
values = line.split()
if values[0] == "%%%":
if values[1] == "FTblock":
newTag = values[2]
......@@ -581,7 +582,10 @@ class kat(object):
self.__currentTag = NO_BLOCK
continue
#warnings.warn("current tag {0}".format(self.__currentTag))
# only include listed blocks, if we have specfied them
if blocks != None and self.__currentTag not in blocks:
continue
# don't read comment lines
if line[0] == "#" or line[0] == "%":
......@@ -597,6 +601,7 @@ class kat(object):
first = line.split(" ",1)[0]
obj = None
if(first == "m" or first == "m1" or first == "m2"):
obj = pykat.components.mirror.parseFinesseText(line)
elif(first == "s"):
......@@ -703,6 +708,11 @@ class kat(object):
print "Removed existing object '{0}' of type {1} to add line '{2}'".format(obj.name, obj.__class__, line)
self.add(obj)
except:
print "--------------------------------------------------------"
print "Error parsing line: " + line
print "--------------------------------------------------------"
raise
# now process all the varous gauss/attr etc. commands which require
......@@ -894,7 +904,7 @@ class kat(object):
if line.lstrip().startswith('*'):
if self.verbose: sys.stdout.write(line)
elif line.rstrip().endswith('s') and line.contains('%'):
elif line.rstrip().endswith('s') and '%' in line:
vals = line.split("-")
action = vals[0].strip()
prc = vals[1].strip()[:]
......
......@@ -43,6 +43,7 @@ def start(instance_path,port=5000, debug=True, ip="0.0.0.0", git_bin="/usr/bin/g
if not os.path.exists(os.path.join(app.instance_path,"finesse_test")):
print "finesse test folder didn't exist, cloning now..."
utils.git(["clone","git://gitmaster.atlas.aei.uni-hannover.de/finesse/test.git","finesse_test"])
utils.git(["config","core.sharedRepository","true"], cwd="./finesse_test/")
# load up the actual interface code
import pykat.testing.web.web_interface
......
......@@ -319,12 +319,12 @@ class HG_beam(object):
def _calc_constants(self):
self.__xpre_const = math.pow(2.0/math.pi, 0.25)
self.__xpre_const *= np.sqrt(1.0/(self._qx.w0 * 2**(self._n) * np.factorial(self._n)))
self.__xpre_const *= np.sqrt(1.0/(self._qx.w0 * 2**(self._n) * np.math.factorial(self._n)))
self.__xpre_const *= np.sqrt(1j*self._qx.imag / self._qx.q)
self.__xpre_const *= ((1j*self._qx.imag * self._qx.q.conjugate())/(-1j*self._qx.imag * self._qx.q)) ** ( self._n/2.0)
self.__ypre_const = math.pow(2.0/math.pi, 0.25)
self.__ypre_const *= np.sqrt(1.0/(self._qy.w0 * 2**(self._m) * np.factorial(self._m)))
self.__ypre_const *= np.sqrt(1.0/(self._qy.w0 * 2**(self._m) * np.math.factorial(self._m)))
self.__ypre_const *= np.sqrt(1j*self._qy.imag / self._qy.q)
self.__ypre_const *= ((1j*self._qy.imag * self._qy.q.conjugate())/(-1j*self._qy.imag * self._qy.q)) **(self._m/2.0)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment