Пример #1
0
def test_endftod():

    from pyne._utils import endftod

    obs = [
        endftod(" 3.28559+12"),
        endftod(" 2.328559+4"),
        endftod(" 3.28559-12"),
        endftod(" 2.328559-2"),
        endftod("-3.28559+12"),
        endftod("-2.328559+2"),
        endftod("-3.28559-12"),
        endftod("-2.328559-2"),
        endftod("        121"),
        endftod("       -121"),
    ]
    exp = [
        3.28559e12,
        2.328559e4,
        3.28559e-12,
        2.328559e-2,
        -3.28559e12,
        -2.328559e2,
        -3.28559e-12,
        -2.328559e-2,
        121.0,
        -121.0,
    ]
    obs = np.array(obs)
    exp = np.array(exp)
    assert_allclose(obs, exp, rtol=1e-8)
Пример #2
0
    def _read_headers(self):
        """Read all the table headers from an ENDL file."""
        opened_here = False
        if isinstance(self.fh, basestring):
            fh = open(self.fh, 'rU')
            opened_here = True
        else:
            fh = self.fh

        while True:
            # get header lines
            line1 = fh.readline()
            line2 = fh.readline()

            # EOF?
            if len(line2) == 0:
                break

            # store the start of the table
            start = fh.tell()

            # parse the first header line
            nuc_zzzaaa = int(line1[0:6].strip())
            yi = int(line1[7:9].strip() or -1)
            yo = int(line1[10:12].strip() or -1)
            aw_str = line1[13:24]
            aw = utils.endftod(aw_str) if aw_str else np.float64(-1.)
            date = line1[25:31].strip()
            iflag = int(line1[31].strip() or 0)

            # parse the second header line
            rdesc = int(line2[0:2].strip() or -1)
            rprop = int(line2[2:5].strip() or -1)
            rmod = int(line2[5:8].strip() or -1)
            x1_str = line2[21:32]
            x1 = int(utils.endftod(x1_str or -1.))

            # convert to Pyne native formats
            nuc = nucname.zzzaaa_to_id(nuc_zzzaaa)

            # skip to the end of the table
            read_eot = False
            while not read_eot:
                stop = fh.tell()
                line = fh.readline()
                read_eot = (len(line) == 0 or END_OF_TABLE_RE.match(line))

            # insert the table in the self.structure dictionary
            self.structure[nuc]['pin'].add(yi)
            self.structure[nuc]['rdesc'].add(rdesc)
            self.structure[nuc]['rprop'].add(rprop)

            pdp_dict = self.structure[nuc]['pin_rdesc_rprop']
            table_dict = pdp_dict[yi, rdesc, rprop]
            table_dict['rmod'] = rmod

            x1_in_tuple = x1 if rmod != 0 else None
            data_tuple = DataTuple(x1=x1_in_tuple, yo=yo, limits=(start, stop))
            table_dict['data_tuples'].append(data_tuple)

        # close the file if it was opened here
        if opened_here:
            fh.close()