#!/usr/bin/env python import sys if len(sys.argv) != 3: print >> sys.stderr, "Usage: src2tsv infile outfile\n" sys.exit(1) from ciao_contrib.runtool import dmcopy dmcopy.infile = sys.argv[1] dmcopy.outfile = sys.argv[2]+'[opt kernel=text/tsv]' dmcopy.clobber = True dmcopy() with open( sys.argv[2], "r" ) as fp: outfile = fp.readlines() # first 1st line w/o comment character idx = next( ii for ii in xrange( len(outfile) ) if outfile[ii][0] != "#" ) # replace vector and arrays with scalars outfile[idx] = outfile[idx].replace( "POS(X,Y)", "X\tY") outfile[idx] = outfile[idx].replace( "CELLPOS(CELL_X,CELL_Y)", "CELL_X\tCELL_Y") outfile[idx] = outfile[idx].replace( "R[2]", "R1\tR2") with open( sys.argv[2], "w" ) as fp: fp.writelines( outfile ) sys.exit(0)