Ejemplo n.º 1
0
    def read(self, inputfile):
        line = inputfile.readline()
        lineno = 1
        while line != '':
            data = line.split()
            if len(data) > 0:
                if data[0][0].isdigit():
                    break
                self.parseline(line, inputfile=inputfile, lineno=lineno)
            line = inputfile.readline()
            lineno += 1

        if line == '':
            return

        self["new"] = False
        self["NDIM"] = int(data[0])
        self["IPS"] = int(data[1])
        try:
            self["IRS"] = int(data[2])
        except ValueError:
            self["IRS"] = data[2]
        self["ILP"] = int(data[3])

        line = inputfile.readline()
        data = line.split()
        icp = []
        for i in range(int(data[0])):
            d = data[i + 1]
            try:
                d = int(d)
            except ValueError:
                pass
            icp.append(d)
        self["ICP"] = icp

        for line_comment in self.line_comments[2:7]:
            line = inputfile.readline()
            data = line.split()
            for d, key in zip(data, line_comment.split(",")):
                if key[0] in 'IJKLMN':
                    self[key] = int(d)
                else:
                    self[key] = parseB.AUTOatof(d)

        for key in ["THL", "THU", "UZR"]:
            line = inputfile.readline()
            data = line.split()
            item = []
            for i in range(int(data[0])):
                line = inputfile.readline()
                data = line.split()
                d = data[0]
                try:
                    d = int(d)
                except ValueError:
                    pass
                item.append([d, parseB.AUTOatof(data[1])])
            self[key] = item
Ejemplo n.º 2
0
 def __readAll(self):
     for item in self.data:
         solution = item["Text"]
         item.update({
             "Branch number": 0,
             "Point number": 0,
             "Label": 0,
             "Eigenvalues": [],
             "Multipliers": []
         })
         lines = solution.splitlines()
         if len(lines) < 3:
             continue
         i = 0
         for line in lines:
             sp = line.split()
             if len(sp) > 0 and sp[0] == 'BR':
                 break
             i = i + 1
         if i + 1 >= len(lines):
             continue
         sp = lines[i + 1].split()
         if len(sp) < 2:
             continue
         item["Branch number"] = int(sp[0])
         item["Point number"] = int(sp[1])
         labline = 0
         for line in lines:
             sp = line.split()
             if labline and len(sp) > 3:
                 if sp[2] != '0':
                     try:
                         item["Label"] = int(sp[2])
                     except:
                         item["Label"] = int(sp[3])
                 break
             if sp[0:4] == ['BR', 'PT', 'TY', 'LAB']:
                 labline = 1
         result = re.findall("Eigenvalue\s.*", solution)
         for eigenvalue_string in result:
             eigenvalue_string = eigenvalue_string.split()
             real_part = parseB.AUTOatof(eigenvalue_string[2])
             imag_part = parseB.AUTOatof(eigenvalue_string[3])
             item["Eigenvalues"].append([real_part, imag_part])
         result = re.findall("Multiplier\s.*", solution)
         for multiplier_string in result:
             multiplier_string = multiplier_string.split()
             # "inaccurate" or "accurate"
             if multiplier_string[1][-1] == "e":
                 continue
             real_part = parseB.AUTOatof(multiplier_string[2])
             imag_part = parseB.AUTOatof(multiplier_string[3])
             item["Multipliers"].append([real_part, imag_part])
Ejemplo n.º 3
0
 def readfloats(self, i, total):
     if not Points.numpyimported:
         Points.importnumpy()
     N = Points.N
     data = self.readstr(i)
     if hasattr(N, "ndarray") and isinstance(data, N.ndarray):
         return data
     fromstring = Points.fromstring
     if fromstring:
         fdata = []
         if "D".encode("ascii") not in data:
             fdata = fromstring(data, dtype=float, sep=' ')
         if fdata == [] or len(fdata) != total:
             fdata = N.array(map(parseB.AUTOatof, data.split()), 'd')
         else:
             #make sure the last element is correct
             #(fromstring may not do this correctly for a
             #string like -2.05071-106)
             fdata[-1] = parseB.AUTOatof(
                 data[data.rfind(" ".encode("ascii")) + 1:].strip())
     else:
         data = data.split()
         try:
             fdata = N.array(map(float, data), 'd')
         except ValueError:
             fdata = N.array(map(parseB.AUTOatof, data), 'd')
     if total != len(fdata):
         raise PrematureEndofData
     del self.solutions[i]['data']
     self.solutions[i]['data'] = fdata
     return fdata
Ejemplo n.º 4
0
 def parseline(self, line, userspec=False, inputfile=None, lineno=None):
     # parses a new-style constant file line and puts the keys
     # in the dictionary c; also used for the header of a b. file
     while line != "":
         line = line.strip()
         if line[0] in ['#', '!', '_']:
             return
         pos = line.find('=')
         if pos == -1:
             return
         key = line[:pos].strip()
         value, line = self.scanvalue(line[pos + 1:], inputfile)
         if key in ['ICP', 'IREV', 'IFIXED', 'IPSI']:
             d = []
             for v in value:
                 try:
                     v = int(v)
                 except ValueError:
                     pass
                 d.append(v)
             value = d
         elif key in ['THU', 'THL', 'UZR', 'UZSTOP', 'U', 'PAR']:
             d = []
             i = 0
             while i < len(value):
                 try:
                     v0 = int(value[i])
                 except ValueError:
                     v0 = value[i]
                 if value[i + 1] == '[':
                     i = i + 1
                     v1 = []
                     while i + 1 < len(value) and value[i + 1] != ']':
                         v1.append(parseB.AUTOatof(value[i + 1]))
                         i = i + 1
                 else:
                     v1 = parseB.AUTOatof(value[i + 1])
                 d.append([v0, v1])
                 i = i + 2
             value = self.__compactindexed(d)
         elif key in ['unames', 'parnames']:
             value = [[int(value[i]), value[i + 1]]
                      for i in range(0, len(value), 2)]
         elif key in ['s', 'dat', 'sv', 'e', 'SP', 'STOP', 'TY']:
             pass
         elif key in self:
             if key[0] in 'IJKLMN':
                 if value[0] == '*':
                     value = 10**len(value)
                 elif key == 'IRS':
                     try:
                         value = int(value)
                     except ValueError:
                         pass
                 else:
                     value = int(value)
             else:
                 value = parseB.AUTOatof(value)
         elif lineno is not None:
             raise AUTOExceptions.AUTORuntimeError(
                 "Unknown AUTO constant %s on line %d" % (key, lineno))
         else:
             value = None
         if value is not None:
             if userspec:
                 self["Active " + key] = self[key]
             self[key] = value
Ejemplo n.º 5
0
def check_demo(demo,correct_filename,trial_filename,epsilon,abseps):
    # A regular expression for finding floating point numbers
    float_regex=re.compile('[ -][0-9]\.[0-9]+[-+eE][-+0-9][0-9]+',re.S)
    # A regular expression for finding each demo block
    demo_regex=re.compile("Demo %s is started.*Demo %s is done"%(demo,demo),re.S,)
    # A regular expression for finding a header
    header_regex=re.compile('BR',re.S)
    # A regular expression for finding each error block
    error_regex=re.compile("===%s start===.*===%s end==="%(demo,demo),re.S)

    # This is where the report get stored until it gets returned
    report = cStringIO.StringIO()

    # Search for all possible demos in each file
    correct_file=open(correct_filename,"r")
    correct_file=correct_file.read()
    trial_file=open(trial_filename,"r")
    trial_file=trial_file.read()

    # Use the regular expressions to find the appropriate blocks (if any)
    correct_result=demo_regex.search(correct_file)
    if correct_result is None:
        return (DEMO_FAILED,"Correct file does not have appropriate demo")
    else:
        correct_string=correct_result.group()

    trial_result=demo_regex.search(trial_file)
    if trial_result is None:
        error_file = open("%serrors"%trial_filename,"r")
        error_file = error_file.read()
        error_result=error_regex.search(error_file)
        if error_result is None:
            return (DEMO_FAILED,"Demo could not be found in trial file")
        else:
            return (DEMO_FAILED,no_demo_string%error_result.group())
    else:
        trial_string=trial_result.group()

    # Now that we have the corresponding blocks from each file we look at each
    # Floating point number is each and see if they are within epsilon
    # percentage of each other.
    end=0
    offset=1
    correct_item=header_regex.search(correct_string,0)
    trial_item=header_regex.search(trial_string,0)
    maxdiff = 0
    maxratio = 0
    if correct_item is not None and trial_item is not None:
        end=correct_item.end()
        offset=trial_item.end()-end
    while True:
        start=end
        correct_item=float_regex.search(correct_string,start)
        if correct_item is None:
            break
        start=correct_item.start()
        end=correct_item.end()
        trial_item=float_regex.search(trial_string[start+offset-1:end+offset+1])
        correct_data=parseB.AUTOatof(correct_item.group())
        try:
            trial_data=parseB.AUTOatof(trial_item.group())
            if trial_item.start() > 0:
                offset=trial_item.start()+offset-1
        except (ValueError, AttributeError):
            correct_string="%s<B><font color=Red>%s</font></B>%s"%(
                correct_string[:start],correct_string[start:end],
                correct_string[end:])
            trial_string="%s<B><font color=Red>%s</font></B>%s"%(
                trial_string[:start+offset],trial_string[start+offset:end+offset],
                trial_string[end+offset:])
            return (DEMO_MAJOR_DATA_ERROR,
                    no_matching_float%(demo,correct_item.group(),trial_item,
                                       trial_string,correct_string))

        if correct_string[start-7:start-3] == "Time":
            start=end
            correct_item=header_regex.search(correct_string,start)
            trial_item=header_regex.search(trial_string,start+offset)
            if correct_item is not None and trial_item is not None:
                start=correct_item.start()
                end=correct_item.end()
                offset=trial_item.end()-end
        else:
            diff = abs(trial_data-correct_data)
            if trial_data == 0.0:
                ratio1 = abs(correct_data)+epsilon
            else:
                ratio1 = abs(diff/trial_data)

            if correct_data == 0.0:
                ratio2 = abs(trial_data)+epsilon
            else:
                ratio2 = abs(diff/correct_data)
            ratio = max(ratio1, ratio2)

            if diff > abseps and ratio > epsilon:
                maxdiff = max(diff, maxdiff)
                maxratio = max(ratio, maxratio)
                report.write("Files do not match at the %dth character for demo %s\n"%(start,demo))
                report.write("Value of trial is %e\n"%trial_data)
                report.write("Value of correct file is %e\n\n"%correct_data)
                correct_string="%s<I><font color=Blue>%s</font></I>%s"%(
                    correct_string[:start],correct_string[start:end],
                    correct_string[end:])
                trial_string="%s<I><font color=Blue>%s</font></I>%s"%(
                    trial_string[:start+offset],trial_string[start+offset:end+offset],
                    trial_string[end+offset:])
                start += 31
                end += 31
    report_string = report.getvalue()
    if len(report_string)==0:
        return (DEMO_OK,"")
    else:
        return (DEMO_MINOR_DATA_ERROR,report_string+
                different_floats%(trial_string,correct_string),
                maxratio,maxdiff)