| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
import re |
| 8 |
import sys |
| 9 |
try: |
| 10 |
from UserList import UserList |
| 11 |
except ImportError: |
| 12 |
from collections import UserList |
| 13 |
import getopt |
| 14 |
from auto import AUTOutil |
| 15 |
from auto import parseB |
| 16 |
|
| 17 |
class parseD(UserList): |
| 18 |
def __init__(self,filename=None): |
| 19 |
if isinstance(filename, str): |
| 20 |
UserList.__init__(self) |
| 21 |
self.readFilename(filename) |
| 22 |
else: |
| 23 |
UserList.__init__(self,filename) |
| 24 |
|
| 25 |
def __getitem__(self,index): |
| 26 |
return self.getIndex(index) |
| 27 |
|
| 28 |
def __call__(self,label): |
| 29 |
return self.getLabel(label) |
| 30 |
|
| 31 |
def __str__(self): |
| 32 |
s = [] |
| 33 |
for d in self.data: |
| 34 |
s.append(d["Text"]) |
| 35 |
return "".join(s) |
| 36 |
|
| 37 |
def getIndex(self,index): |
| 38 |
self.__readAll() |
| 39 |
return self.data[index] |
| 40 |
|
| 41 |
def getLabel(self,label): |
| 42 |
self.__readAll() |
| 43 |
for x in self.data: |
| 44 |
if x["Label"] == label: |
| 45 |
return x |
| 46 |
|
| 47 |
def __readAll(self): |
| 48 |
for item in self.data: |
| 49 |
solution = item["Text"] |
| 50 |
item.update({ |
| 51 |
"Branch number": 0, |
| 52 |
"Point number": 0, |
| 53 |
"Label": 0, |
| 54 |
"Eigenvalues": [], |
| 55 |
"Multipliers": []}) |
| 56 |
lines = solution.splitlines() |
| 57 |
if len(lines) < 3: |
| 58 |
continue |
| 59 |
i = 0 |
| 60 |
for line in lines: |
| 61 |
sp = line.split() |
| 62 |
if len(sp) > 0 and sp[0] == 'BR': |
| 63 |
break |
| 64 |
i = i + 1 |
| 65 |
if i + 1 >= len(lines): |
| 66 |
continue |
| 67 |
sp = lines[i+1].split() |
| 68 |
if len(sp) < 2: |
| 69 |
continue |
| 70 |
item["Branch number"] = int(sp[0]) |
| 71 |
item["Point number"] = int(sp[1]) |
| 72 |
labline = 0 |
| 73 |
for line in lines: |
| 74 |
sp = line.split() |
| 75 |
if labline and len(sp) > 3: |
| 76 |
if sp[2] != '0': |
| 77 |
try: |
| 78 |
item["Label"] = int(sp[2]) |
| 79 |
except: |
| 80 |
item["Label"] = int(sp[3]) |
| 81 |
break |
| 82 |
if sp[0:4] == ['BR', 'PT', 'TY', 'LAB']: |
| 83 |
labline = 1 |
| 84 |
result = re.findall("Eigenvalue\s.*",solution) |
| 85 |
for eigenvalue_string in result: |
| 86 |
eigenvalue_string = eigenvalue_string.split() |
| 87 |
real_part = parseB.AUTOatof(eigenvalue_string[2]) |
| 88 |
imag_part = parseB.AUTOatof(eigenvalue_string[3]) |
| 89 |
item["Eigenvalues"].append([real_part,imag_part]) |
| 90 |
result = re.findall("Multiplier\s.*",solution) |
| 91 |
for multiplier_string in result: |
| 92 |
multiplier_string = multiplier_string.split() |
| 93 |
|
| 94 |
if multiplier_string[1][-1] == "e": |
| 95 |
continue |
| 96 |
real_part = parseB.AUTOatof(multiplier_string[2]) |
| 97 |
imag_part = parseB.AUTOatof(multiplier_string[3]) |
| 98 |
item["Multipliers"].append([real_part,imag_part]) |
| 99 |
|
| 100 |
def read(self,input): |
| 101 |
data = input.read() |
| 102 |
divstr = "===============================================\n" |
| 103 |
data=data.split(divstr) |
| 104 |
if len(data) == 1: |
| 105 |
divstr = "--------------------------------------------------------------------------------------------\n" |
| 106 |
data=data[0].split(divstr) |
| 107 |
self.data=[] |
| 108 |
for solution in data: |
| 109 |
self.data.append({"Text": solution + divstr}) |
| 110 |
self.data[-1]["Text"] = self.data[-1]["Text"][:-len(divstr)] |
| 111 |
|
| 112 |
def readFilename(self,filename): |
| 113 |
inputfile = AUTOutil.openFilename(filename, "r") |
| 114 |
self.read(inputfile) |
| 115 |
|
| 116 |
def write(self,output): |
| 117 |
output.write(self.__str__()) |
| 118 |
|
| 119 |
def writeFilename(self,filename,append=False): |
| 120 |
if append: |
| 121 |
output = open(filename,"a") |
| 122 |
else: |
| 123 |
output = open(filename,"w") |
| 124 |
self.write(output) |
| 125 |
output.close() |
| 126 |
|
| 127 |
|
| 128 |
def test(): |
| 129 |
pass |
| 130 |
|
| 131 |
if __name__ == "__main__": |
| 132 |
|
| 133 |
opts_list,args=getopt.getopt(sys.argv[1:],"i:") |
| 134 |
opts={} |
| 135 |
for x in opts_list: |
| 136 |
opts[x[0]]=x[1] |
| 137 |
|
| 138 |
foo = parseD(args[0]) |
| 139 |
foo.printMatrix(int(opts["-i"]),sys.stdout) |
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|