armi.nuclearDataIO.cccc module

Standard interface files for reactor physics codes.

This module is designed to read/write Fortran record-based binary files that comply with the format established by the Committee on Computer Code Coordination (CCCC). [CCCC-IV]

Notes

A CCCC record consists of a leading and ending integer, which indicates the size of the record in bytes. As a result, it is possible to perform a check when reading in a record to determine if it was read correctly, by making sure the record size at the beginning and ending of a record are always equal.

There are similarities between this code and that in the PyNE cccc subpackage. This is the original source of the code. TerraPower authorized the publication of some of the CCCC code to the PyNE project way back in the 2011 era. This code has since been updated significantly to both read and write the files.

This was originally created following Prof. James Paul Holloway’s alpha release of ccccutils written in c++ from 2001.

class armi.nuclearDataIO.cccc.CCCCRecord(data)[source]

Bases: object

A single record from a CCCC file

Reads binary information sequentially.

getInt()[source]
getFloat()[source]
getDouble()[source]
getString(length)[source]
getList(ltype, length, strLength=0)[source]
class armi.nuclearDataIO.cccc.CCCCReader(fName='ISOTXS')[source]

Bases: object

Reads a binary file according to CCCC standards.

getInt()[source]

Get an integer from the file before we have a record.

Required for reading a record.

See also

armi.nuclearDataIO.CCCCReader.getInt()

gets integers once a record is already read

getFloat()[source]
getRecord()[source]

CCCC records start with an int and end with the same int. This int represents the number of bytes that the record is. That makes it easy to read.

readFileID()[source]

This reads the file ID record in the binary file.

This information is currently not used - just getting to the next record.

class armi.nuclearDataIO.cccc.IORecord(stream, hasRecordBoundaries=True)[source]

Bases: object

A single CCCC record.

Reads, or writes, information to, or from, a stream.

Parameters
  • stream – A collection of data to be read or written

  • hasRecordBoundaries (bool) – A True value means the fortran file was written using access=’sequential’ and contains a 4 byte int count at the beginning and end of each record. Otherwise, if False the fortran file was written using access=’direct’.

Notes

The methods in this object often have rw prefixes, meaning the same method can be used for both reading and writing. We consider this a significant achievement that enforces consistency between the code for reading and writing CCCC records. The tradeoff is that it’s a bit challenging to comprehend at first.

maxsize = 10
count = 0
__enter__()[source]

Open the stream for reading/writing and return self.

open()[source]

Abstract method for opening the stream.

close()[source]

Abstract method for closing the stream.

rwInt(val)[source]

Abstract method for reading or writing an integer.

Notes

The method has a seemingly odd signature, because it is used for both reading and writing. When writing, the val should have value, but when the record is being read, val can be None or anything else; it is ignored.

rwBool(val)[source]

Read or write a boolean value from an integer.

rwFloat(val)[source]

Abstract method for reading or writing a floating point (single precision) value.

Notes

The method has a seemingly odd signature, because it is used for both reading and writing. When writing, the val should have value, but when the record is being read, val can be None or anything else; it is ignored.

rwDouble(val)[source]

Abstract method for reading or writing a floating point (double precision) value.

Notes

The method has a seemingly odd signature, because it is used for both reading and writing. When writing, the val should have value, but when the record is being read, val can be None or anything else; it is ignored.

rwString(val, length)[source]

Abstract method for reading or writing a string.

Notes

The method has a seemingly odd signature, because it is used for both reading and writing. When writing, the val should have value, but when the record is being read, val can be None or anything else; it is ignored.

rwList(contents, containedType, length, strLength=0)[source]

A method for reading and writing a (array) of items of a specific type.

Notes

The method has a seemingly odd signature, because it is used for both reading and writing. When writing, the contents should have value, but when the record is being read, contents can be None or anything else; it is ignored.

Warning

If a contents evaluates to True, the array must be the same size as length.

rwMatrix(contents, *shape)[source]

A method for reading and writing a matrix of floating point values.

Notes

The method has a seemingly odd signature, because it is used for both reading and writing. When writing, the contents should have value, but when the record is being read, contents can be None or anything else; it is ignored.

Warning

If a contents is not None, the array must be the same shape as *shape.

rwDoubleMatrix(contents, *shape)[source]

Read or write a matrix of floating point values.

Notes

The method has a seemingly odd signature, because it is used for both reading and writing. When writing, the contents should have value, but when the record is being read, contents can be None or anything else; it is ignored.

Warning

If a contents is not None, the array must be the same shape as *shape.

class armi.nuclearDataIO.cccc.BinaryRecordReader(stream, hasRecordBoundaries=True)[source]

Bases: armi.nuclearDataIO.cccc.IORecord

Writes a single CCCC record in binary format.

Notes

This class reads a single CCCC record in binary format. A CCCC record consists of a leading and ending integer indicating how many bytes the record is. The data contained within the record may be integer, float, double, or string.

open()[source]

Open the record by reading the number of bytes in the record, this value will be used to ensure the entire record was read.

close()[source]

Closes the record by reading the number of bytes from then end of the record, if it does not match the initial value, an exception will be raised.

rwInt(val)[source]

Reads an integer value from the binary stream.

rwBool(val)[source]

Read or write a boolean value from an integer.

rwLong(val)[source]

Reads an integer value from the binary stream.

rwFloat(val)[source]

Reads a single precision floating point value from the binary stream.

rwDouble(val)[source]

Reads a double precision floating point value from the binary stream.

rwString(val, length)[source]

Reads a string of specified length from the binary stream.

class armi.nuclearDataIO.cccc.BinaryRecordWriter(stream, hasRecordBoundaries=True)[source]

Bases: armi.nuclearDataIO.cccc.IORecord

a single record from a CCCC file

Reads binary information sequentially.

open()[source]

Abstract method for opening the stream.

close()[source]

Abstract method for closing the stream.

rwInt(val)[source]

Abstract method for reading or writing an integer.

Notes

The method has a seemingly odd signature, because it is used for both reading and writing. When writing, the val should have value, but when the record is being read, val can be None or anything else; it is ignored.

rwBool(val)[source]

Read or write a boolean value from an integer.

rwLong(val)[source]

Reads an integer value from the binary stream.

rwFloat(val)[source]

Abstract method for reading or writing a floating point (single precision) value.

Notes

The method has a seemingly odd signature, because it is used for both reading and writing. When writing, the val should have value, but when the record is being read, val can be None or anything else; it is ignored.

rwDouble(val)[source]

Abstract method for reading or writing a floating point (double precision) value.

Notes

The method has a seemingly odd signature, because it is used for both reading and writing. When writing, the val should have value, but when the record is being read, val can be None or anything else; it is ignored.

rwString(val, length)[source]

Abstract method for reading or writing a string.

Notes

The method has a seemingly odd signature, because it is used for both reading and writing. When writing, the val should have value, but when the record is being read, val can be None or anything else; it is ignored.

class armi.nuclearDataIO.cccc.AsciiRecordReader(stream, hasRecordBoundaries=True)[source]

Bases: armi.nuclearDataIO.cccc.BinaryRecordReader

Reads a single CCCC record in ASCII format.

close()[source]

Closes the record by reading the number of bytes from then end of the record, if it does not match the initial value, an exception will be raised.

rwInt(val)[source]

Reads an integer value from the binary stream.

rwFloat(val)[source]

Reads a single precision floating point value from the binary stream.

rwDouble(val)[source]

Reads a double precision floating point value from the binary stream.

rwString(val, length)[source]

Reads a string of specified length from the binary stream.

class armi.nuclearDataIO.cccc.AsciiRecordWriter(stream, hasRecordBoundaries=True)[source]

Bases: armi.nuclearDataIO.cccc.IORecord

Writes a single CCCC record in ASCII format.

Since there is no specific format of an ASCII CCCC record, the format is roughly the same as the BinaryRecordWriter, except that the AsciiRecordReader puts a space in front of all values (ints, floats, and strings), and puts a newline character \n at the end of all records.

open()[source]

Abstract method for opening the stream.

close()[source]

Abstract method for closing the stream.

rwInt(val)[source]

Abstract method for reading or writing an integer.

Notes

The method has a seemingly odd signature, because it is used for both reading and writing. When writing, the val should have value, but when the record is being read, val can be None or anything else; it is ignored.

rwFloat(val)[source]

Abstract method for reading or writing a floating point (single precision) value.

Notes

The method has a seemingly odd signature, because it is used for both reading and writing. When writing, the val should have value, but when the record is being read, val can be None or anything else; it is ignored.

rwDouble(val)[source]

Abstract method for reading or writing a floating point (double precision) value.

Notes

The method has a seemingly odd signature, because it is used for both reading and writing. When writing, the val should have value, but when the record is being read, val can be None or anything else; it is ignored.

rwString(val, length)[source]

Abstract method for reading or writing a string.

Notes

The method has a seemingly odd signature, because it is used for both reading and writing. When writing, the val should have value, but when the record is being read, val can be None or anything else; it is ignored.

class armi.nuclearDataIO.cccc.Stream(fileName, fileMode)[source]

Bases: object

An abstract CCCC IO stream.

Notes

A concrete instance of this class should implement the readWrite() method.

Create an instance of a Stream.

Parameters
  • fileName (str) – name of the file to be read

  • fileMode (str) – the file mode, i.e. ‘w’ for writing ASCII, ‘r’ for reading ASCII, ‘wb’ for writing binary, and ‘rb’ for reading binary.

__deepcopy__(memo)[source]

Open file objects can’t be deepcopied so we clear them before copying.

__enter__()[source]

At the inception of a with command, navigate to a new directory if one is supplied

__exit__(exc_type, exc_value, traceback)[source]

At the termination of a with command, navigate back to the original directory

readWrite()[source]

This method should be implemented on any sub-classes to specify the order of records.

createRecord(hasRecordBoundaries=True)[source]
classmethod readBinary(fileName)[source]
classmethod readAscii(fileName)[source]
classmethod writeBinary(lib, fileName)[source]
classmethod writeAscii(lib, fileName)[source]