##################################
#                                #
# Last modified 06/08/2010       # 
#                                #
# Georgi Marinov                 #
#                                # 
##################################

import sys
import math

try:
	import psyco
	psyco.full()
except:
	pass

def run():

    if len(sys.argv) < 2:
        print 'usage: python %s listoffile outputfilename' % sys.argv[0]
        sys.exit(1)

    inputfilenames = sys.argv[1]
    outputfilename = sys.argv[2]

    outfile = open(outputfilename, 'w')
    outfile.write('#filename\tmean\tstd-dev\n')

    lineslist = open(inputfilenames)
    for fileline in lineslist:
        filename=fileline.strip().split('\t')[0]
        lines=open(filename)
        for line in lines:
            if line.startswith('#mean = '):
                mean=float(line.strip().split('#mean = ')[1])
                mean = int(mean)
            if line.startswith('#st. dev = '):
                stdev=float(line.strip().split('#st. dev = ')[1])
                stdev=int(stdev)
        outfile.write(filename + '\t' + str(mean) + '\t' + str(stdev) + '\n')

    outfile.close()

run()

