
def trim_sim_file(filename_in, filename_out):
	
	import sys	
	file_in = open(filename_in)
	file_out = open(filename_out, "w")
	firstline = True
	line_no = 0
	rows = 0
	for line in file_in:
		if firstline:
			firstline = False
			file_out.write(line)
			tokens = line.strip().split(" ")
			rows = int(tokens[0])
			continue
		line = line.strip()
		if len(line) == 0:
			file_out.write('\n')
			line_no += 1
			continue 
		tokens = line.split(" ")
		if len(tokens) % 2 != 0:
			print >> sys.stderr, "len(tokens) % 2 != 0, line:",line
			continue
		for tok_no in xrange(0, len(tokens), 2):
			id = int(tokens[tok_no])
			val = float(int(100 * float(tokens[tok_no+1])))/100.
			file_out.write(str(id) + " " + str(val) + " " )
		
		file_out.write("\n") 
		line_no +=1

		if line_no % 100 == 0:
			print "Reading row %s / %s" % (line_no + 1, rows )
	
	file_out.close()
		

if __name__ == "__main__":
	import sys
	print "Quantifier starting..."
	
	simmatrix_file = sys.argv[1]
	outfile = sys.argv[2]

	trim_sim_file(simmatrix_file, outfile)
	
