#!/usr/bin/env python

#import xml.etree.ElementTree as ET
import sys

if len(sys.argv) < 2:
	print 'Usage:\npython <script> <monitorFile> \n'
	print 'Output:\n a more human readable file'
	exit()


meshFile = open(sys.argv[1], 'r')
temp = sys.argv[1].split('.')[0]
try:
	temp = temp.split('Monitor')
	if	temp[1] == '_x':
		outName=temp[0]+'Monitor'+'Position.dat'
	elif	temp[1] == '_f':
		outName=temp[0]+'Monitor'+'Force.dat'
	else:
		print 'Error'
		exit()
except IndexError:
	print temp
	outName = temp[0]+'_clean.dat'

outFile = open(outName, 'w')

line=True

while line:
	#make pretty human readable columns
	line=meshFile.readline()
	if not line:	break;
	elif line.startswith('#') or line.startswith('*'):
		outFile.write( line )
	else:
		line=line.split()	#split by whitespace
		floatLine = [float(i) for i in line]
		outFile.write( ('{: 5.2f}	'+('{: 8.4f}	'*(len(line)-1))+'\n').format(*floatLine) )


meshFile.close()	
outFile.close()

print 'Wrote', outName

