1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Abinit Post Process Application
author: Martin Alexandre
last edited: May 2013
"""
import commands
class ReadGraph:
# This class can read graph in a file
# This is useful to add graphics
#-----------------------------#
#-------CONSTRUCTOR-----------#
#-----------------------------#
def __init__(self, pnamefile):
self.input_file = str(pnamefile)
self.number_column = 0
file = open(self.input_file)
#-----------------------------#
#-----------METHODS-----------#
#-----------------------------#
def read(self,c1,c2):
file = open(self.input_file)
x = []
y = []
idx1 = int(c1) - 1
idx2 = int(c2) - 1
for line in file:
temp = line.split()
try:
x.append(float(temp[idx1]))
except:
pass
try:
y.append(float(temp[idx2]))
except:
pass
if len(x)==len(y):
return [x,y]
else:
return [0,0]
def getFile(self):
file = open(self.input_file)
return file.read()
def getNbColumn(self):
file = open(self.input_file)
for line in file:
test = line.split()
nb = len(test)
if nb != self.number_column :
self.number_column = nb
file.close()
return self.number_column
|