Esempio n. 1
0
def test_read_BR():
    set_int = 8
    set_float = 3.14
    set_double_list = [1.6e-19, 6.02e23]
    set_string = b"Hello World!"

    binary_file = _BinaryReader("test_readBR.ref")

    test_record = binary_file.get_fortran_record()

    try:
        test_int = test_record.get_int()[0]
    except:
        raise SkipTest
    assert_equal(set_int, test_int)

    test_string = test_record.get_string(12)[0]
    assert_equal(set_string.decode(), test_string)

    test_double_list = test_record.get_double(2)
    if test_double_list != set_double_list:
        raise ValueError("List of doubles was not as expected.")

    test_float = test_record.get_float()[0]
    # NOTE: since Python doesn't do native 32-bit floats, both values should be
    #       passed through a string formatting to truncate to 6 digits
    set_float = "%10.6f" % set_float
    test_float = "%10.6f" % test_float

    if test_float != set_float:
        print("{0} != {1}".format(set_float, test_float))
        raise ValueError("Float value was not as expected.")

    return 1
Esempio n. 2
0
def test_write_BR():

    binaryFile = _BinaryReader('test.file', 'wb')
    if not binaryFile.f:
        raise BinaryReaderError("Failed to open new file for writing.")

    setInt = 8
    setFloat = 3.14
    setDoubleList = [1.6e-19, 6.02e23]
    setString = "Hello World!"

    testRecord = _FortranRecord('', 0)
    testRecord.put_int([setInt])
    testRecord.put_string([setString], len(setString))
    testRecord.put_double(setDoubleList)
    testRecord.put_float([setFloat])

    testRecord.reset()

    binaryFile.put_fortran_record(testRecord)

    binaryFile.close()

    if not filecmp.cmp('test.file', 'test_readBR.ref'):
        raise BinaryReaderError('Created file does not match reference.')

    return 1
Esempio n. 3
0
def test_write_BR():
    binary_file = _BinaryReader("test.file", "wb")
    if not binary_file.f:
        raise ValueError("Failed to open new file for writing.")

    set_int = 8
    set_float = 3.14
    set_double_list = [1.6e-19, 6.02e23]
    set_string = "Hello World!"

    test_record = _FortranRecord("", 0)
    test_record.put_int([set_int])
    test_record.put_string([set_string], len(set_string))
    test_record.put_double(set_double_list)
    test_record.put_float([set_float])

    test_record.reset()

    binary_file.put_fortran_record(test_record)

    binary_file.close()

    if not filecmp.cmp("test.file", "test_readBR.ref"):
        raise ValueError("Created file does not match reference.")

    return 1
Esempio n. 4
0
def test_read_BR():

    setInt = 8
    setFloat = 3.14
    setDoubleList = [1.6e-19, 6.02e23]
    setString = "Hello World!"

    binaryFile = _BinaryReader('test_readBR.ref')

    testRecord = binaryFile.get_fortran_record()

    testInt = testRecord.get_int()[0]
    if testInt != setInt:
        raise BinaryReaderError("Integer value was not as expected.")

    testString = testRecord.get_string(12)[0]
    if testString != setString:
        raise BinaryReaderError("String was not as expected.")

    testDoubleList = testRecord.get_double(2)
    if testDoubleList != setDoubleList:
        raise BinaryReaderError("List of doubles was not as expected.")

    testFloat = testRecord.get_float()[0]
    # NOTE: since Python doesn't do native 32-bit floats, both values should be
    #       passed through a string formatting to truncate to 6 digits
    setFloat = '%10.6f' % setFloat
    testFloat = '%10.6f' % testFloat

    if testFloat != setFloat:
        print str(setFloat) + " != " + str(testFloat)
        raise BinaryReaderError("Float value was not as expected.")

    return 1
Esempio n. 5
0
def test_read_BR():
    set_int = 8
    set_float = 3.14
    set_double_list = [1.6e-19, 6.02e23]
    set_string = b"Hello World!"

    binary_file = _BinaryReader('test_readBR.ref')

    test_record = binary_file.get_fortran_record()

    try:
        test_int = test_record.get_int()[0]
    except:
        raise SkipTest
    assert_equal(set_int, test_int)

    test_string = test_record.get_string(12)[0]
    assert_equal(set_string.decode(), test_string)

    test_double_list = test_record.get_double(2)
    if test_double_list != set_double_list:
        raise ValueError("List of doubles was not as expected.")

    test_float = test_record.get_float()[0]
    # NOTE: since Python doesn't do native 32-bit floats, both values should be
    #       passed through a string formatting to truncate to 6 digits
    set_float = '%10.6f' % set_float
    test_float = '%10.6f' % test_float

    if test_float != set_float:
        print("{0} != {1}".format(set_float, test_float))
        raise ValueError("Float value was not as expected.")

    return 1
Esempio n. 6
0
def test_write_BR():
    binary_file = _BinaryReader('test.file', 'wb')
    if not binary_file.f:
        raise ValueError("Failed to open new file for writing.")

    set_int = 8
    set_float = 3.14
    set_double_list = [1.6e-19, 6.02e23]
    set_string = "Hello World!"

    test_record = _FortranRecord('', 0)
    test_record.put_int([set_int])
    test_record.put_string([set_string], len(set_string))
    test_record.put_double(set_double_list)
    test_record.put_float([set_float])

    test_record.reset()

    binary_file.put_fortran_record(test_record)

    binary_file.close()

    if not filecmp.cmp('test.file', 'test_readBR.ref'):
        raise ValueError('Created file does not match reference.')

    return 1
Esempio n. 7
0
def test_read_BR():

    setInt = 8
    setFloat = 3.14
    setDoubleList = [1.6e-19,6.02e23]
    setString = "Hello World!"
    
    binaryFile = _BinaryReader('test_readBR.ref')
    
    testRecord = binaryFile.get_fortran_record()

    testInt = testRecord.get_int()[0]
    if testInt != setInt:
        raise BinaryReaderError("Integer value was not as expected.")

    testString = testRecord.get_string(12)[0]
    if testString != setString:
        raise BinaryReaderError("String was not as expected.")

    testDoubleList = testRecord.get_double(2)
    if testDoubleList != setDoubleList:
        raise BinaryReaderError("List of doubles was not as expected.")

    testFloat = testRecord.get_float()[0]
    # NOTE: since Python doesn't do native 32-bit floats, both values should be
    #       passed through a string formatting to truncate to 6 digits
    setFloat  = '%10.6f' % setFloat
    testFloat = '%10.6f' % testFloat

    if testFloat != setFloat:
        print str(setFloat) + " != " + str(testFloat)
        raise BinaryReaderError("Float value was not as expected.")
    
    return 1
Esempio n. 8
0
def test_open_writable_BR():
    binary_file = _BinaryReader("test.file", "wb")
    if not binary_file.f:
        raise ValueError("Failed to open new file for writing.")

    binary_file.close()

    return 1
Esempio n. 9
0
def test_open_writable_BR():
    binary_file = _BinaryReader('test.file', 'wb')
    if not binary_file.f:
        raise ValueError("Failed to open new file for writing.")

    binary_file.close()

    return 1
Esempio n. 10
0
def test_open_writable_BR():

    binaryFile = _BinaryReader('test.file', 'wb')
    if not binaryFile.f:
        raise BinaryReaderError("Failed to open new file for writing.")

    binaryFile.close()

    return 1
Esempio n. 11
0
    def __init__(self, filename):
        """
        Parameters
        ----------
        filename : str
            Path to the RTFLUX file to be read.
        """

        b = _BinaryReader(filename)
        fr = b.get_fortran_record()

        # read file identification
        self.hname = fr.get_string(8)[0].strip()
        self.huse = fr.get_string(8)[0].strip()
        self.ivers = fr.get_string(8)[0].strip()
        mult = fr.get_int(1)

        if self.hname == "rtflux":
            self.adjoint = False
        elif self.hname == "atflux":
            self.adjoint = True

        # read specifcations
        fr = b.get_fortran_record()
        self.ndim, self.ngroup, self.ninti, self.nintj, self.nintk, self.niter \
            = fr.get_int(6)
        self.effk = fr.get_float(1)[0]
        if not self.adjoint:
            self.power = fr.get_float(1)[0]
        else:
            fr.get_float(1)
        self.nblok = fr.get_int(1)[0]

        # read fluxes
        flux = []

        # This is the 1D binary spec, specified by CCCC.
        # It does not work the the PyNE binary reader, but using the 3D format
        # does work, as tested.
        #
        # if self.ndim == 1:
        #    for m in range(1, self.nblok + 1):
        #        fr = b.get_fortran_record()
        #        print fr.num_bytes
        #        jl = (m - 1)*((self.ngroup - 1)/self.nblok + 1) + 1
        #        jup = m*((self.ngroup -1)/self.nblok + 1)
        #        ju = min(self.ngroup, jup)
        #        flux += fr.get_double(int(self.ninti*(ju-jl+1)))

        # 3D binary spec
        for l in range(1, self.ngroup + 1):
            for k in range(1, self.nintk + 1):
                for m in range(1, self.nblok + 1):
                    fr = b.get_fortran_record()
                    jl = (m - 1) * ((self.nintj - 1) / self.nblok + 1) + 1
                    jup = m * ((self.nintj - 1) / self.nblok + 1)
                    ju = min(self.nintj, jup)
                    flux += fr.get_double(int(self.ninti * (ju - jl + 1)))

        flux2 = []
        num_intervals = self.ninti * self.nintj * self.nintk
        for i in range(self.ngroup):
            if not self.adjoint:
                flux2.insert(0,
                             flux[i * num_intervals:(i + 1) * num_intervals])
            else:
                flux2.append(flux[i * num_intervals:(i + 1) * num_intervals])

        flux2 = np.array(flux2)
        flux2 = flux2.transpose()

        self.flux = flux2
        b.close()