#!/usr/bin/env python
import csv
import sys
import math
import copy


with open( sys.argv[2], 'wb' ) as out:
	fn = sys.argv[1]
	delimiter = ','
	csv_reader = csv.DictReader( open(fn,'rb'), delimiter=delimiter )
	for row in csv_reader:
		pass
	fieldnames = csv_reader.fieldnames

	fieldnames += ['EOC_velocity', 'EOC_pressure']
	csv_reader = csv.DictReader( open(fn,'rb'), delimiter=delimiter )
	#out.write( '\t'.join(fieldnames) + '\n' )
	writer = csv.DictWriter( out, fieldnames, delimiter=delimiter )
	writer.writeheader()
	lastRow = None
	for row in csv_reader:
		u_eoc = 'none'
		p_eoc = 'none'
		if lastRow:
			print lastRow
			u_last = float(lastRow['L2_0'])
			p_last = float(lastRow['L2_1'])
			h_last = float(lastRow['grid_width'])
			u_this = float(row['L2_0'])
			p_this = float(row['L2_1'])
			h_this = float(row['grid_width'])
			u_eoc = math.log(u_this/u_last) / math.log(h_this/h_last)
			p_eoc = math.log(p_this/p_last) / math.log(h_this/h_last)
			new = [str(u_eoc), str(p_eoc)]
		row['EOC_velocity'] = u_eoc
		row['EOC_pressure'] = p_eoc
		writer.writerow(row)
		
		lastRow = copy.deepcopy(row)
	out.flush()


@@ -37,16 +37,26 @@
 ort sys%0A
+import os%0A
 import m
@@ -76,19 +76,16 @@
 py%0A%0A
-%0Awith open(
+out_fn =
  sys
@@ -92,16 +92,34 @@
 .argv%5B2%5D
+%0Awith open( out_fn
 , 'wb' )
@@ -591,27 +591,26 @@
 %09%09u_eoc = 'n
-one
+an
 '%0A%09%09p_eoc = 
@@ -611,19 +611,18 @@
 eoc = 'n
-one
+an
 '%0A%09%09if l
@@ -633,25 +633,8 @@
 ow:%0A
-%09%09%09print lastRow%0A
 %09%09%09u
@@ -1126,8 +1126,117 @@
 lush()%0A%0A
+os.system( %22sed -i 's/L2_0/L2_velocity/g' %25s%22%25out_fn )%0Aos.system( %22sed -i 's/L2_1/L2_pressure/g' %25s%22%25out_fn )

remove dbg print in new python script