X-Git-Url: http://woldlab.caltech.edu/gitweb/?p=erange.git;a=blobdiff_plain;f=binstocdf.py;fp=binstocdf.py;h=27b48e22e8ecde5b4fd9c817ff17d4ab75dcbd13;hp=63aa9558b8848183d4528bb16149cd0ced38aadd;hb=77dccd7c98d8cdb60caaf178b1123df71ea662c9;hpb=bc30aca13e5ec397c92e67002fbf7a103130b828 diff --git a/binstocdf.py b/binstocdf.py index 63aa955..27b48e2 100755 --- a/binstocdf.py +++ b/binstocdf.py @@ -1,4 +1,5 @@ import sys +import string print "binstocdf: version 1.1" @@ -6,19 +7,19 @@ def main(argv=None): if not argv: argv = sys.argv - if len(argv) < 2: - print 'usage: python %s infile outfile' % sys.argv[0] + if len(argv) < 3: + print "usage: python %s infile outfile" % sys.argv[0] sys.exit(1) - infilename = argv[0] - outfilename = argv[1] + infilename = argv[1] + outfilename = argv[2] binToCDF(infilename, outfilename) def binToCDF(infilename, outfilename): infile = open(infilename) - outfile = open(outfilename, 'w') + outfile = open(outfilename, "w") for line in infile: fields = line.strip().split() @@ -30,14 +31,15 @@ def binToCDF(infilename, outfilename): outfile.write(line) continue - outfile.write('%s\t%s\t%s\t%s' % (fields[0], fields[1], fields[2], fields[3])) - cum = 0 + outputFields = fields[:4] + runningTotal = 0 for bin in fields[4:]: - cum += int(bin) - percent = 100 * cum / total - outfile.write('\t%d' % percent) + runningTotal += int(bin) + percent = 100 * runningTotal / total + outputFields.append("%d" % percent) - outfile.write('\n') + outputLine = string.join(outputFields, "\t") + outfile.write("%s\n" % outputLine) infile.close() outfile.close()