armi.nuclearDataIO.cccc.cccc module

Defines containers for the reading and writing standard interface files for reactor physics codes.

armi.nuclearDataIO.cccc.cccc.IMPLICIT_INT = 'IJKLMN'

Letters that trigger implicit integer types in old FORTRAN 77 codes

class armi.nuclearDataIO.cccc.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 = 885
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.

rwIntMatrix(contents, *shape)[source]

Read or write a matrix of int values.

rwImplicitlyTypedMap(keys: List[str], contents) dict[source]

Read a dict of floats and/or ints with FORTRAN77-style implicit typing.

Length of list is determined by length of list of keys passed in.

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

Bases: 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.cccc.BinaryRecordWriter(stream, hasRecordBoundaries=True)[source]

Bases: IORecord

a single record from a CCCC file.

Reads binary information sequentially.

open()[source]
close()[source]
rwInt(val)[source]
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]
rwDouble(val)[source]
rwString(val, length)[source]
class armi.nuclearDataIO.cccc.cccc.AsciiRecordReader(stream, hasRecordBoundaries=True)[source]

Bases: BinaryRecordReader

Reads a single CCCC record in ASCII format.

close()[source]
rwInt(val)[source]
rwFloat(val)[source]
rwDouble(val)[source]
rwString(val, length)[source]
class armi.nuclearDataIO.cccc.cccc.AsciiRecordWriter(stream, hasRecordBoundaries=True)[source]

Bases: 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]
close()[source]
rwInt(val)[source]
rwFloat(val)[source]
rwDouble(val)[source]
rwString(val, length)[source]
class armi.nuclearDataIO.cccc.cccc.DataContainer[source]

Bases: object

Data representation that can be read/written to/from with a cccc.Stream.

This is an optional convenience class expected to be used in concert with StreamWithDataStructure.

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

Bases: object

An abstract CCCC IO stream.

Warning

This is more of a stream Parser/Serializer than an actual 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.

readWrite()[source]

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

createRecord(hasRecordBoundaries=True)[source]
classmethod readBinary(fileName: str)[source]

Read data from a binary file into a data structure.

classmethod readAscii(fileName: str)[source]

Read data from an ASCII file into a data structure.

classmethod writeBinary(data: DataContainer, fileName: str)[source]

Write the contents of a data container to a binary file.

classmethod writeAscii(data: DataContainer, fileName: str)[source]

Write the contents of a data container to an ASCII file.

class armi.nuclearDataIO.cccc.cccc.StreamWithDataContainer(data: DataContainer, fileName: str, fileMode: str)[source]

Bases: Stream

A cccc.Stream that reads/writes to a specialized data container.

This is a relatively common pattern so some of the boilerplate is handled here.

Warning

This is more of a stream Parser/Serializer than an actual stream.

Notes

It should be possible to fully merge this with Stream, which may make this a little less confusing.

armi.nuclearDataIO.cccc.cccc.getBlockBandwidth(m, nintj, nblok)[source]

Return block bandwidth JL, JU from CCCC interface files.

It is common for CCCC files to block data in various records with a description along the lines of:

WITH M AS THE BLOCK INDEX, JL=(M-1)*((NINTJ-1)/NBLOK +1)+1
AND JU=MIN0(NINTJ,JUP) WHERE JUP=M*((NINTJ-1)/NBLOK +1)

This function computes JL and JU for these purposes. It also converts JL and JU to zero based indices rather than 1 based ones, as is almost always wanted when dealing with python/numpy matrices.

The term bandwidth refers to a kind of sparse matrix representation. Some rows only have columns JL to JH in them rather than 0 to JMAX. The non-zero band from JL to JH is what we’re talking about here.