Loading src/log.py +16 −17 Changes for src/log.py: 16 added lines, 17 removed lines. Original line number Diff line number Diff line Loading @@ -5,6 +5,7 @@ # DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains # certain rights in this software. This software is distributed under # the GNU General Public License. from __future__ import print_function # log tool Loading Loading @@ -76,14 +77,14 @@ class log: self.flist = [] for word in words: self.flist += glob.glob(word) if len(self.flist) == 0 and len(list) == 1: raise StandardError,"no log file specified" raise Exception("no log file specified") if len(list) == 1: self.increment = 0 self.read_all() else: if len(self.flist) > 1: raise StandardError,"can only incrementally read one log file" raise Exception("can only incrementally read one log file") self.increment = 1 self.eof = 0 Loading @@ -92,24 +93,24 @@ class log: def read_all(self): self.read_header(self.flist[0]) if self.nvec == 0: raise StandardError,"log file has no values" if self.nvec == 0: raise Exception("log file has no values") # read all files for file in self.flist: self.read_one(file) print print() # sort entries by timestep, cull duplicates self.data.sort(self.compare) self.cull() self.nlen = len(self.data) print "read %d log entries" % self.nlen print("read %d log entries" % self.nlen) # -------------------------------------------------------------------- def next(self): if not self.increment: raise StandardError,"cannot read incrementally" if not self.increment: raise Exception("cannot read incrementally") if self.nvec == 0: try: open(self.flist[0],'r') Loading @@ -124,7 +125,7 @@ class log: def get(self,*keys): if len(keys) == 0: raise StandardError, "no log vectors specified" raise Exception("no log vectors specified") map = [] for key in keys: Loading @@ -139,12 +140,12 @@ class log: if count == 1: map.append(index) else: raise StandardError, "unique log vector %s not found" % key raise Exception("unique log vector %s not found" % key) vecs = [] for i in range(len(keys)): vecs.append(self.nlen * [0]) for j in xrange(self.nlen): for j in range(self.nlen): vecs[i][j] = self.data[j][map[i]] if len(keys) == 1: return vecs[0] Loading @@ -167,15 +168,15 @@ class log: if count == 1: map.append(index) else: raise StandardError, "unique log vector %s not found" % key raise Exception("unique log vector %s not found" % key) else: map = range(self.nvec) f = open(filename,"w") for i in xrange(self.nlen): for j in xrange(len(map)): print >>f,self.data[i][map[j]], print >>f for i in range(self.nlen): for j in range(len(map)): print(self.data[i][map[j]], end='', file=f) print(file=f) f.close() # -------------------------------------------------------------------- Loading Loading @@ -229,7 +230,6 @@ class log: self.names.append(keyword) self.ptr[keyword] = i i += 1 else: s1 = txt.find(self.firststr) s2 = txt.find("\n",s1) Loading Loading @@ -321,7 +321,6 @@ class log: word2 = re.findall(pat2,section) words = word1 + word2 self.data.append(map(float,words)) else: lines = chunk.split("\n") for line in lines: Loading @@ -330,7 +329,7 @@ class log: # print last timestep of chunk print int(self.data[len(self.data)-1][0]), print(int(self.data[len(self.data)-1][0]), end='') sys.stdout.flush() return eof Loading
src/log.py +16 −17 Changes for src/log.py: 16 added lines, 17 removed lines. Original line number Diff line number Diff line Loading @@ -5,6 +5,7 @@ # DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains # certain rights in this software. This software is distributed under # the GNU General Public License. from __future__ import print_function # log tool Loading Loading @@ -76,14 +77,14 @@ class log: self.flist = [] for word in words: self.flist += glob.glob(word) if len(self.flist) == 0 and len(list) == 1: raise StandardError,"no log file specified" raise Exception("no log file specified") if len(list) == 1: self.increment = 0 self.read_all() else: if len(self.flist) > 1: raise StandardError,"can only incrementally read one log file" raise Exception("can only incrementally read one log file") self.increment = 1 self.eof = 0 Loading @@ -92,24 +93,24 @@ class log: def read_all(self): self.read_header(self.flist[0]) if self.nvec == 0: raise StandardError,"log file has no values" if self.nvec == 0: raise Exception("log file has no values") # read all files for file in self.flist: self.read_one(file) print print() # sort entries by timestep, cull duplicates self.data.sort(self.compare) self.cull() self.nlen = len(self.data) print "read %d log entries" % self.nlen print("read %d log entries" % self.nlen) # -------------------------------------------------------------------- def next(self): if not self.increment: raise StandardError,"cannot read incrementally" if not self.increment: raise Exception("cannot read incrementally") if self.nvec == 0: try: open(self.flist[0],'r') Loading @@ -124,7 +125,7 @@ class log: def get(self,*keys): if len(keys) == 0: raise StandardError, "no log vectors specified" raise Exception("no log vectors specified") map = [] for key in keys: Loading @@ -139,12 +140,12 @@ class log: if count == 1: map.append(index) else: raise StandardError, "unique log vector %s not found" % key raise Exception("unique log vector %s not found" % key) vecs = [] for i in range(len(keys)): vecs.append(self.nlen * [0]) for j in xrange(self.nlen): for j in range(self.nlen): vecs[i][j] = self.data[j][map[i]] if len(keys) == 1: return vecs[0] Loading @@ -167,15 +168,15 @@ class log: if count == 1: map.append(index) else: raise StandardError, "unique log vector %s not found" % key raise Exception("unique log vector %s not found" % key) else: map = range(self.nvec) f = open(filename,"w") for i in xrange(self.nlen): for j in xrange(len(map)): print >>f,self.data[i][map[j]], print >>f for i in range(self.nlen): for j in range(len(map)): print(self.data[i][map[j]], end='', file=f) print(file=f) f.close() # -------------------------------------------------------------------- Loading Loading @@ -229,7 +230,6 @@ class log: self.names.append(keyword) self.ptr[keyword] = i i += 1 else: s1 = txt.find(self.firststr) s2 = txt.find("\n",s1) Loading Loading @@ -321,7 +321,6 @@ class log: word2 = re.findall(pat2,section) words = word1 + word2 self.data.append(map(float,words)) else: lines = chunk.split("\n") for line in lines: Loading @@ -330,7 +329,7 @@ class log: # print last timestep of chunk print int(self.data[len(self.data)-1][0]), print(int(self.data[len(self.data)-1][0]), end='') sys.stdout.flush() return eof