Snippets

Rene Cejas Bolecek Parsing: get column from file & split data with even/odd row index

Created by Rene Cejas Bolecek last modified
#!/usr/bin/python

##################################################################################
# Parsing
# Rel. 11/2015
# Dr. Rene Cejas Bolecek
# Low Temperatures Laboratory, CAB, Argentine.
# email: reneczechdev@gmail.com
##################################################################################

#Libs
import numpy as np


####################################################################################################################################
#User setup
filename = '01b_00Tpara'
filenameOut = filename
####################################################################################################################################
dataIn = np.loadtxt(filename+".dat")
writeItOdd = open(filenameOut+"_odd.dat", "w")	
writeItEven = open(filenameOut+"_even.dat", "w")	
offset = 0
cutoff = 0
print dataIn.shape[0]
print dataIn.shape[0]-cutoff

if cutoff > dataIn.shape[0]:
        raise  RuntimeError ("cutoff can't be more than data length")
              
for i in range(offset, dataIn.shape[0]-cutoff):
	if (i%2 ==0): writeItOdd.write("%d\t" % (i+1))
	if (i%2 ==1): writeItEven.write("%d\t" % (i+1))
	for j in range(dataIn.shape[1]):
		if(j==1 or j == 2 or j == 5 or j == 6 or j == 7 or j == 10 or j == 11 or j == 10 or j == 19 or j == 20):
			if (i%2 ==0):
				writeItOdd.write("%.8e\t" % (dataIn[i,j]))
			if (i%2 ==1):
				writeItEven.write("%.8e\t" % (dataIn[i,j]))
	if (i%2 ==0):writeItOdd.write("\n")
	if (i%2 ==1):writeItEven.write("\n")

writeItOdd.close()
writeItEven.close()
#OUTPUT
#row index | DeltaT1 | DeltaT2 | Kappa | C1 | C2 | Tau1 | Tau2 | tiempo0 | tiempo 1

#Checks
#for i in range(0,10):
#    print i%2
#out:
#0
#1
#0
#1
#0
#1
#0

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.