| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
from auto import parseB |
| 20 |
from auto import parseS |
| 21 |
from auto import parseD |
| 22 |
from auto import AUTOExceptions |
| 23 |
|
| 24 |
class parseBandS: |
| 25 |
def __init__(self,fort7_filename=None,fort8_filename=None,fort9_filename=None): |
| 26 |
self.diagnostics = None |
| 27 |
if isinstance(fort7_filename, list): |
| 28 |
self.diagram = None |
| 29 |
self.solution = parseS.parseS(fort7_filename) |
| 30 |
elif fort8_filename is None and fort7_filename is not None: |
| 31 |
raise AUTOExceptions.AUTORuntimeError("Must set both both filenames") |
| 32 |
elif isinstance(fort7_filename, str) or fort7_filename is None: |
| 33 |
self.diagram = parseB.parseB(fort7_filename) |
| 34 |
self.solution = parseS.parseS(fort8_filename) |
| 35 |
if not fort9_filename is None: |
| 36 |
self.diagnostics = parseD.parseD(fort9_filename) |
| 37 |
else: |
| 38 |
self.diagram = fort7_filename |
| 39 |
self.solution = fort8_filename |
| 40 |
self.diagnostics = fort9_filename |
| 41 |
if self.diagnostics is None: |
| 42 |
self.diagnostics = [] |
| 43 |
self.dg = self.diagram |
| 44 |
self.sl = self.solution |
| 45 |
|
| 46 |
def __str__(self): |
| 47 |
return self.diagram.summary() |
| 48 |
|
| 49 |
def __repr__(self): |
| 50 |
return "" |
| 51 |
|
| 52 |
def getLabel(self,label): |
| 53 |
if isinstance(label, int): |
| 54 |
return self.solution(label) |
| 55 |
return parseBandS(self.diagram(label),self.solution(label), |
| 56 |
self.diagnostics) |
| 57 |
|
| 58 |
def __add__(self,x): |
| 59 |
if x == []: |
| 60 |
x = parseBandS() |
| 61 |
add = parseBandS(self.diagram + x.diagram, |
| 62 |
self.solution + x.solution, |
| 63 |
self.diagnostics + x.diagnostics) |
| 64 |
add.uniquelyLabel() |
| 65 |
return add |
| 66 |
|
| 67 |
def __radd__(self,x): |
| 68 |
if x == []: |
| 69 |
x = parseBandS() |
| 70 |
add = parseBandS(x.diagram + self.diagram, |
| 71 |
x.solution + self.solution, |
| 72 |
x.diagnostics + self.diagnostics) |
| 73 |
add.uniquelyLabel() |
| 74 |
return add |
| 75 |
|
| 76 |
def __iadd__(self,x): |
| 77 |
if x != []: |
| 78 |
self.diagram.__iadd__(x.diagram) |
| 79 |
self.solution.__iadd__(x.solution) |
| 80 |
self.diagnostics.__iadd__(x.diagnostics) |
| 81 |
self.uniquelyLabel() |
| 82 |
return self |
| 83 |
|
| 84 |
def extend(self,x): |
| 85 |
self.__iadd__(x) |
| 86 |
|
| 87 |
def read(self,fort7_input,fort8_input,fort9_input=None): |
| 88 |
self.diagram.read(fort7_input) |
| 89 |
self.solution.read(fort8_input) |
| 90 |
if not fort9_input is None: |
| 91 |
self.diagnostics.read(fort9_input) |
| 92 |
|
| 93 |
def write(self,fort7_output,fort8_output,fort9_output=None): |
| 94 |
self.diagram.write(fort7_output) |
| 95 |
self.solution.write(fort8_output) |
| 96 |
if not fort9_output is None: |
| 97 |
self.diagnostics.write(fort9_output) |
| 98 |
|
| 99 |
def save(self,output_filename): |
| 100 |
self.writeFilename('b.'+output_filename, |
| 101 |
's.'+output_filename, |
| 102 |
'd.'+output_filename) |
| 103 |
return self |
| 104 |
|
| 105 |
def readFilename(self,fort7_filename,fort8_filename,fort9_filename=None): |
| 106 |
self.diagram.readFilename(fort7_filename) |
| 107 |
self.solution.readFilename(fort8_filename) |
| 108 |
if not fort9_filename is None: |
| 109 |
self.diagnostics.readFilename(fort9_filename) |
| 110 |
|
| 111 |
def writeFilename(self,fort7_filename,fort8_filename=None,fort9_filename=None): |
| 112 |
|
| 113 |
if fort8_filename is None: |
| 114 |
fort8_filename = fort7_filename |
| 115 |
else: |
| 116 |
self.diagram.writeFilename(fort7_filename) |
| 117 |
self.solution.writeFilename(fort8_filename) |
| 118 |
if not fort9_filename is None: |
| 119 |
self.diagnostics.writeFilename(fort9_filename) |
| 120 |
|
| 121 |
def deleteLabel(self,label=None,keepTY=0,keep=0): |
| 122 |
self.diagram.deleteLabel(label,keepTY,keep) |
| 123 |
self.solution.deleteLabel(label,keep) |
| 124 |
|
| 125 |
def relabel(self,old_label=None,new_label=None): |
| 126 |
if old_label is None and new_label is None: |
| 127 |
self.diagram.uniquelyLabel() |
| 128 |
self.solution.uniquelyLabel() |
| 129 |
return self |
| 130 |
self.diagram.relabel(old_label,new_label) |
| 131 |
self.solution.relabel(old_label,new_label) |
| 132 |
|
| 133 |
def uniquelyLabel(self): |
| 134 |
self.diagram.uniquelyLabel() |
| 135 |
self.solution.uniquelyLabel() |
| 136 |
|
| 137 |
def getLabels(self): |
| 138 |
return self.diagram.getLabels() |
| 139 |
|
| 140 |
def pointtest7(a,b): |
| 141 |
if "TY name" not in a: |
| 142 |
raise AUTOExceptions.AUTORegressionError("No TY name label") |
| 143 |
if "TY number" not in a: |
| 144 |
raise AUTOExceptions.AUTORegressionError("No TY number label") |
| 145 |
if "BR" not in a: |
| 146 |
raise AUTOExceptions.AUTORegressionError("No BR label") |
| 147 |
if "data" not in a: |
| 148 |
raise AUTOExceptions.AUTORegressionError("No data label") |
| 149 |
if "PT" not in a: |
| 150 |
raise AUTOExceptions.AUTORegressionError("No PT label") |
| 151 |
if "LAB" not in a: |
| 152 |
raise AUTOExceptions.AUTORegressionError("No LAB label") |
| 153 |
if len(a["data"]) != len(b["data"]): |
| 154 |
raise AUTOExceptions.AUTORegressionError("Data sections have different lengths") |
| 155 |
|
| 156 |
|
| 157 |
def pointtest8(a,b): |
| 158 |
keys = ['Type number', 'Type name', |
| 159 |
'Free Parameters', 'Branch number', 'Parameter NULL vector', |
| 160 |
'data', 'NCOL', 'Label', 'ISW', 'NTST', |
| 161 |
'Point number', 'Parameters'] |
| 162 |
|
| 163 |
scratch=a['Parameters'] |
| 164 |
scratch=b['Parameters'] |
| 165 |
for key in keys: |
| 166 |
if key not in a: |
| 167 |
raise AUTOExceptions.AUTORegressionError("No %s label"%(key,)) |
| 168 |
if len(a["data"]) != len(b["data"]): |
| 169 |
raise AUTOExceptions.AUTORegressionError("Data sections have different lengths") |
| 170 |
|
| 171 |
|
| 172 |
def test(): |
| 173 |
foo = parseBandS() |
| 174 |
foo.readFilename("test_data/fort.7","test_data/fort.8") |
| 175 |
if len(foo.diagram) != 150: |
| 176 |
raise AUTOExceptions.AUTORegressionError("File length incorrect") |
| 177 |
pointtest7(foo.diagram.getIndex(0),foo.diagram.getIndex(57)) |
| 178 |
if len(foo.solution) != 5: |
| 179 |
raise AUTOExceptions.AUTORegressionError("File length incorrect") |
| 180 |
pointtest8(foo.solution.getIndex(0),foo.solution.getIndex(3)) |
| 181 |
|
| 182 |
if len(foo.getLabels()) != 5: |
| 183 |
raise AUTOExceptions.AUTORegressionError("Incorrect number of labels") |
| 184 |
|
| 185 |
print("Deleting labels") |
| 186 |
foo.deleteLabel(range(6,9)) |
| 187 |
|
| 188 |
if len(foo.getLabels()) != 2: |
| 189 |
raise AUTOExceptions.AUTORegressionError("Incorrect number of labels") |
| 190 |
|
| 191 |
print("Relabeling") |
| 192 |
foo.relabel(9,57) |
| 193 |
|
| 194 |
for i in range(len(foo.diagram)): |
| 195 |
if foo.diagram.getIndex(0)["TY number"] != 0: |
| 196 |
if foo.diagram.getIndex(0)["LAB"] != 57: |
| 197 |
raise AUTOExceptions.AUTORegressionError("Incorrect label") |
| 198 |
break |
| 199 |
if foo.solution.getIndex(0)["Label"] != 57: |
| 200 |
raise AUTOExceptions.AUTORegressionError("Incorrect label") |
| 201 |
|
| 202 |
print("Making labels unique") |
| 203 |
foo.uniquelyLabel() |
| 204 |
|
| 205 |
for i in range(len(foo.diagram)): |
| 206 |
if foo.diagram.getIndex(0)["TY number"] != 0: |
| 207 |
if foo.diagram.getIndex(0)["LAB"] != 1: |
| 208 |
raise AUTOExceptions.AUTORegressionError("Incorrect label") |
| 209 |
break |
| 210 |
if foo.solution.getIndex(0)["Label"] != 1: |
| 211 |
raise AUTOExceptions.AUTORegressionError("Incorrect label") |
| 212 |
|
| 213 |
print("parseBandS passed all tests") |
| 214 |
|
| 215 |
if __name__ == '__main__' : |
| 216 |
test() |