#!/usr/bin/env python

import sys
from numpy import array

def usage(argv):
	print
	print 'USAGE: ' + argv[0]
	print


def main(argv):

	# Check for appropriate usage
	if len(argv) != 1:
		usage(argv)
		sys.exit(1)

	stress_filename = 'el_strs.txt'

	StressFile = open(stress_filename,'r')
	StressFileLines = StressFile.readlines()
	StressFile.close()

	max_stress = 0.0

	# Find the maximum principal stress throughout the entire simulation
	for line in StressFileLines:

		if line[0]!='*':

			stress = array(map(float,line.strip('\n').split(',')[1:]))

			if max_stress<max(abs(stress)):
				max_stress = max(abs(stress))

	# Output post processed results to a text file
	post_process_filename = 'post_process.txt'

	PostProcessFile = open(post_process_filename,'w')

	PostProcessFile.write('%f\n' % max_stress)

	PostProcessFile.close()

# END OF main()


if __name__ == "__main__":
    main(sys.argv)
