def __init__(self, path, mode="r", nplanes=-1): self.mode = mode self.stream = None if path[-3:] == "bz2": print "INFO: Read bz2 compressed pattern bank", self.stream = bz2.BZ2File(path, mode) print "Done" elif path[-2:] == "gz": print "INFO: Read gzip compressed pattern bank", self.stream = bz2.GzipFile(path, mode) print "Done" else: self.stream = open(path, mode) if mode.find("r") > -1: # read the header of the nank line = self.stream.readline() vals = line.split() # set the global attributes fro the bank self.npatterns = int(vals[0]) self.nplanes = int(vals[1]) self.patterns = [] else: self.npatterns = 0 self.nplanes = nplanes self.patterns = [] return None
def open_helper(self, path): print "Open", path if path[-3:] == "bz2": print "INFO: Read bz2 compressed data file", self.stream = bz2.BZ2File(path, "r") print "Done" elif path[-2:] == "gz": print "INFO: Read gzip compressed data file", self.stream = bz2.GzipFile(path, "r") print "Done" else: self.stream = open(path, "r") return None
def __init__(self, path, mode="r", nplanes=-1): self.mode = mode self.stream = None self.path = path if path[-3:] == "bz2": print "INFO: Read bz2 compressed pattern bank", self.stream = bz2.BZ2File(path, mode) print "Done" elif path[-2:] == "gz": print "INFO: Read gzip compressed pattern bank", self.stream = bz2.GzipFile(path, mode) print "Done" else: self.stream = open(path, mode) if mode.find("r") > -1: # read the header of the bank line = "" while line.find("NPLANES") == -1: line = self.stream.readline() print " 1", line line = self.stream.readline() print "2", line self.nplanes = line.split()[0] while line.find("NSECTORS") == -1: line = self.stream.readline() print "3", line line = self.stream.readline() print "4", line self.nconstants = int(line.split()[0]) while line.find("NDIM") == -1: line = self.stream.readline() line = self.stream.readline() self.ndim = line.split()[0] self.constants = [] else: self.nplanes = nplanes self.nconstants = 0 self.ndims = 0 self.patterns = [] return None