#!/usr/bin/python import os,sys from QOD_tools import * def nicely_spaced(el,sp): print_str = '' for e in el: print_str+=str(e).ljust(sp) return print_str if __name__=='__main__': if len(sys.argv)!=2: print 'usage: parse_rates.py data_file' print 'example: parse_rates.py rates.txt' sys.exit(-1) data_file = sys.argv[1] print nicely_spaced(['#run','M_accumulated'],12) f = file(data_file,'r') fl = f.readlines() for i,l in enumerate(fl): if l.startswith('* Scaler information for run'): r = int(l.split()[-2]) n = [fl[i+j].replace('|','').replace('*','').split() for j in range(4,8+1)] ## suppress crazy output if int(n[0][1]) < 0: n[0][4] = 'None' ##T1Ion rate n[1][2],n[2][2],n[3][2],n[4][2] = 'None','None','None','None' ## Reset divided by T1Ion for j in range(1,4+1): if int(n[j][1]) < 0: n[j][2],n[j][4] = 'None','None' #just get the M-stuff if n[2][0]=='M': print nicely_spaced([r,n[2][1]],12) ##okay, now print out # print nicely_spaced([r,n[0][4],n[1][4],n[1][2],n[2][4],n[2][2],n[3][4],n[3][2],n[4][4],n[4][2]],12)