Re: Extract value and average

2009-06-09 Thread Glauco
Francesco Pietra ha scritto: I come 'naked', which is unusual and unfair. However, I find it difficult to give a correct start. The files consist, among other things, of a huge number of blocks of the type NSTEP = 1000 TIME(PS) = 152.000 TEMP(K) = 298.54 PRESS =89.4 Etot =

Fwd: Extract value and average

2009-06-08 Thread Francesco Pietra
her blocks in the output file is the same. francesco -- Forwarded message -- From: Francesco Pietra Date: Mon, Jun 8, 2009 at 11:55 PM Subject: Re: Extract value and average To: Tim Chase On Mon, Jun 8, 2009 at 8:54 PM, Tim Chase wrote: >> Of the various suggestions, of which I am most gra

Re: Extract value and average

2009-06-08 Thread Tim Chase
Tim Chase wrote: I would like to extract values corresponding to variable DIHED (here 4660.1650) and getting also the mean value from all DIHED. To just pull the DIHED values, you can use this: import re find_dihed_re = re.compile(r'\bDIHED\s*=\s*([.-e\d]+)', re.I) total = count = 0

Re: Extract value and average

2009-06-08 Thread Scott David Daniels
Steven D'Aprano wrote: ... Assuming no DIHED value will ever be split over two lines: data = open(filename) values = [] for line in data: if line and line.strip(): # ignore blanks words = line.strip().split() words = line.split() # does the same as above try:

Re: Extract value and average

2009-06-08 Thread Rhodri James
On Mon, 08 Jun 2009 17:29:12 +0100, Steven D'Aprano wrote: On Mon, 08 Jun 2009 18:13:50 +0200, Francesco Pietra wrote: I come 'naked', which is unusual and unfair. ??? Yeah, I had to go and scrub my brain out :-) Assuming no DIHED value will ever be split over two lines: data = open

Re: Extract value and average

2009-06-08 Thread MRAB
Steven D'Aprano wrote: On Mon, 08 Jun 2009 18:13:50 +0200, Francesco Pietra wrote: I come 'naked', which is unusual and unfair. ??? However, I find it difficult to give a correct start. The files consist, among other things, of a huge number of blocks of the type NSTEP = 1000 TIME(

Re: Extract value and average

2009-06-08 Thread Tim Chase
I would like to extract values corresponding to variable DIHED (here 4660.1650) and getting also the mean value from all DIHED. To just pull the DIHED values, you can use this: import re find_dihed_re = re.compile(r'\bDIHED\s*=\s*([.-e\d]+)', re.I) total = count = 0 for line in file('fi

Re: Extract value and average

2009-06-08 Thread Steven D'Aprano
On Mon, 08 Jun 2009 18:13:50 +0200, Francesco Pietra wrote: > I come 'naked', which is unusual and unfair. ??? > However, I find it > difficult to give a correct start. The files consist, among other > things, of a huge number of blocks of the type > > > NSTEP = 1000 TIME(PS) = 152.

Re: Extract value and average

2009-06-08 Thread MRAB
Francesco Pietra wrote: I come 'naked', which is unusual and unfair. However, I find it difficult to give a correct start. The files consist, among other things, of a huge number of blocks of the type NSTEP = 1000 TIME(PS) = 152.000 TEMP(K) = 298.54 PRESS =89.4 Etot = -1

Extract value and average

2009-06-08 Thread Francesco Pietra
I come 'naked', which is unusual and unfair. However, I find it difficult to give a correct start. The files consist, among other things, of a huge number of blocks of the type NSTEP = 1000 TIME(PS) = 152.000 TEMP(K) = 298.54 PRESS =89.4 Etot = -134965.2123 EKtot =