--- /home/sjplimp/oldpizza/src/log.py 2005-11-07 17:10:41.000000000 -0700 +++ /home/sjplimp/pizza/src/log.py 2005-11-28 16:34:35.000000000 -0700 @@ -12,8 +12,8 @@ docstr = """ l = log("file1") read in one or more log files -l = log("log1 log2.gz") can be gzipped -l = log("file*") wildcard expands to multiple files +l = log("log1 log2.gz") can be gzipped +l = log("file*") wildcard expands to multiple files l = log("log.lammps",0) two args = store filename, but don't read incomplete and duplicate thermo entries are deleted @@ -91,7 +91,6 @@ # read all thermo from all files def read_all(self): - self.read_header(self.flist[0]) if self.nvec == 0: raise StandardError,"log file has no values" @@ -110,7 +109,6 @@ # -------------------------------------------------------------------- def next(self): - if not self.increment: raise StandardError,"cannot read incrementally" if self.nvec == 0: @@ -202,8 +200,7 @@ def read_header(self,file): str_multi = "----- Step" - str_one = "Step Temperature" - str_gran = "Step Atoms" + str_one = "Step " if file[-3:] == ".gz": txt = popen("%s -c %s" % (PIZZA_GUNZIP,file),'r').read() @@ -216,22 +213,10 @@ elif txt.find(str_one) >= 0: self.firststr = str_one self.style = 2 - elif txt.find(str_gran) >= 0: - self.firststr = str_gran - self.style = 3 else: return - if self.style > 1: - s1 = txt.find(self.firststr) - s2 = txt.find("\n",s1) - line = txt[s1:s2] - words = line.split() - for i in range(len(words)): - self.names.append(words[i]) - self.ptr[words[i]] = i - - else: + if self.style == 1: s1 = txt.find(self.firststr) s2 = txt.find("\n",s1) + 1 s3 = txt.find("\n--",s1) @@ -245,6 +230,15 @@ self.names.append(keyword) self.ptr[keyword] = i+1 + else: + s1 = txt.find(self.firststr) + s2 = txt.find("\n",s1) + line = txt[s1:s2] + words = line.split() + for i in range(len(words)): + self.names.append(words[i]) + self.ptr[words[i]] = i + self.nvec = len(self.names) # -------------------------------------------------------------------- @@ -280,7 +274,7 @@ s2 = txt.find("Loop time of",start+1) if s1 >= 0 and s2 >= 0 and s1 < s2: # found s1,s2 with s1 before s2 - if self.style > 1: + if self.style == 2: s1 = txt.find("\n",s1) + 1 elif s1 >= 0 and s2 >= 0 and s2 < s1: # found s1,s2 with s2 before s1 s1 = 0 @@ -291,7 +285,7 @@ last = 1 if self.style == 1: s2 = txt.rfind("\n--",s1) + 1 - elif self.style > 1: + else: s1 = txt.find("\n",s1) + 1 s2 = txt.rfind("\n",s1) + 1 eof -= len(txt) - s2 @@ -307,7 +301,7 @@ s1 = 0 if self.style == 1: s2 = txt.rfind("\n--",s1) + 1 - elif self.style > 1: + else: s2 = txt.rfind("\n",s1) + 1 eof -= len(txt) - s2 if s1 == s2: break @@ -318,13 +312,7 @@ # split chunk into entries # parse each entry for numeric fields, append to data - if self.style > 1: - lines = chunk.split("\n") - for line in lines: - words = line.split() - self.data.append(map(float,words)) - - else: + if self.style == 1: sections = chunk.split("\n--") pat1 = re.compile("Step\s*(\S*)\s") pat2 = re.compile("=\s*(\S*)") @@ -333,7 +321,13 @@ word2 = re.findall(pat2,section) words = word1 + word2[1:] self.data.append(map(float,words)) - + + else: + lines = chunk.split("\n") + for line in lines: + words = line.split() + self.data.append(map(float,words)) + # print last timestep of chunk print int(self.data[len(self.data)-1][0]),