def __init__(self,filename = DataBaseFile): """ Constructor to open the materials definition file and read in the data to self.data as a list of lines. The database is only loaded once. param filename the database (defaults to package default) """ global DataBase if DataBase == None : try : filename = getExpandedFilename(filename) # Sort out logicals filestream = open(filename,"r") DataBase = filestream.readlines() filestream.close() except : print("materail.MaterialData() unable to open data file {0:s}".format(filename)) raise IOError("optics: Unable to run without materail data")
def main(): d = t.getString("Dir") d = t.getExpandedFilename(d) for filename in os.listdir(d): t.tprint(filename)
def __init__(self,fn = None): """ Read in the lens from specified file. param fn the name of the lens file If the filename does not end in lens then ".lens" is appended """ Lens.__init__(self,0.0) # Create a blank lens # # Open file, if None then prompt via tio interface # if fn == None: lensfile = tio.openFile("Lens file","r","lens") else: fn = tio.getExpandedFilename(fn) # Sort out logicals if not fn.endswith("lens"): # Append ".lens" if not given fn += ".lens" lensfile= open(fn,"r") # open file # read file and process one line at a time # for line in lensfile.readlines(): line = line.strip() if not line.startswith("#") and len(line) > 0: # Kill comments and blanks token = line.split() if token[0].startswith("title"): # Deal with title self.title = str(token[1]) elif token[0].startswith("point"): # Deal with Po v = eval(token[1]) self.setPoint(v) # Set point elif token[0].startswith("iris"): # Iris aperture p = float(token[1]) # z-position r = float(token[3]) # radius s = sur.IrisAperture(p,r,1.0) self.add(s) elif token[0].startswith("circular"): # Circular aperture p = float(token[1]) # z-poistion r = float(token[3]) # radius s = sur.CircularAperture(p,r) self.add(s) elif token[0].startswith("annular"): # Annular aperture p = float(token[1]) # z-poistion inner = float(token[3]) # inner radius outer = float(token[4]) # outer radius s = sur.AnnularAperture(p,inner,outer) self.add(s) elif token[0].startswith("spherical"): # Spherical surface p = float(token[1]) # z-position c = float(token[3]) # curvature r = float(token[5]) # max radius if token[6].startswith("index"): # refrective index index = mat.MaterialData().getIndex(token[7]) s = sur.SphericalSurface(p,c,r,index) elif token[6].startswith("mirror"): # else its a mirror s = sur.SphericalSurface(p,c,r) else: raise IOError("inknow type") self.add(s) elif token[0].startswith("parabolic"): # Parabolic p = float(token[1]) c = float(token[3]) r = float(token[5]) if token[6].startswith("index"): index = mat.MaterialData().getIndex(token[7]) s = sur.ParabolicSurface(p,c,r,index) elif token[6].startswith("mirror"): s = sur.ParabolicSurface(p,c,r) else: raise IOError("inknow type") self.add(s) elif token[0].startswith("quadric"): # Quadric p = float(token[1]) c = float(token[3]) e = float(token[5]) r = float(token[7]) if token[8].startswith("index"): index = mat.MaterialData().getIndex(token[9]) s = sur.QuadricSurface(p,c,r,e,index) elif token[8].startswith("mirror"): s = sur.QuadricSurface(p,c,e,r) else: raise IOError("inknow index ") self.add(s) else: print("Unknown token : " + str(token[0])) lensfile.close() # close file