import glob import array ##import os ### GLOBALS NUMBER_OF_TABLES = 41 NUM_ENTRIES = 100 FIRST = True HEADER = "" SKIP = False drift_table = [] ### read all of the table info in for filename in sorted(glob.glob("xt_cdc_*.asc")): print "Processing " + filename + "..." # make array to store 100 columns drift_times = array.array('f', [0]*100) # store file f = open(filename) n = 0 last_time = 0 for line in f: if line.startswith('#'): # if this is the first file we're looking at, grab the header info # there are some lines we don't want though if SKIP: SKIP = False continue if line.startswith("#Gas mix") or line.startswith("#Radius"): SKIP = True continue HEADER = HEADER + line continue (dist, time) = line.strip().split(' ') drift_times[n] = float(time) last_time = float(time) n = n+1 f.close() # fill out the rest of table for i in xrange(n,NUM_ENTRIES): drift_times[i] = last_time # save this file drift_table.append( drift_times ) if FIRST: FIRST = False outf = open("header","w") outf.write(HEADER) outf.close() ### check the number of tables if len(drift_table) != NUMBER_OF_TABLES: print "WARNING: Found " + str(len(drift_table)) + " tables, expected " + str(NUMBER_OF_TABLES) ## finally, output the tables to start outf = open("CDC_t2d_table", "w") for i in xrange(0,NUM_ENTRIES): outstr = "" for j in xrange(0,NUMBER_OF_TABLES): ## handle if we weren't passed enough tables if(j>outf,outstr outf.close()