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:
objectA single record from a CCCC file
Reads binary information sequentially.
-
class
armi.nuclearDataIO.cccc.CCCCReader(fName='ISOTXS')[source]¶ Bases:
objectReads 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
-
-
class
armi.nuclearDataIO.cccc.IORecord(stream, hasRecordBoundaries=True)[source]¶ Bases:
objectA 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¶
-
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
valshould have value, but when the record is being read,valcan beNoneor 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
valshould have value, but when the record is being read,valcan beNoneor 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
valshould have value, but when the record is being read,valcan beNoneor 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
valshould have value, but when the record is being read,valcan beNoneor 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
contentsshould have value, but when the record is being read,contentscan beNoneor anything else; it is ignored.Warning
If a
contentsevaluates toTrue, the array must be the same size aslength.
-
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
contentsshould have value, but when the record is being read,contentscan beNoneor anything else; it is ignored.Warning
If a
contentsis notNone, 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
contentsshould have value, but when the record is being read,contentscan beNoneor anything else; it is ignored.Warning
If a
contentsis notNone, the array must be the same shape as*shape.
-
class
armi.nuclearDataIO.cccc.BinaryRecordReader(stream, hasRecordBoundaries=True)[source]¶ Bases:
armi.nuclearDataIO.cccc.IORecordWrites 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.
-
-
class
armi.nuclearDataIO.cccc.BinaryRecordWriter(stream, hasRecordBoundaries=True)[source]¶ Bases:
armi.nuclearDataIO.cccc.IORecorda single record from a CCCC file
Reads binary information sequentially.
-
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
valshould have value, but when the record is being read,valcan beNoneor 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
valshould have value, but when the record is being read,valcan beNoneor 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
valshould have value, but when the record is being read,valcan beNoneor 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
valshould have value, but when the record is being read,valcan beNoneor anything else; it is ignored.
-
-
class
armi.nuclearDataIO.cccc.AsciiRecordReader(stream, hasRecordBoundaries=True)[source]¶ Bases:
armi.nuclearDataIO.cccc.BinaryRecordReaderReads a single CCCC record in ASCII format.
See also
-
class
armi.nuclearDataIO.cccc.AsciiRecordWriter(stream, hasRecordBoundaries=True)[source]¶ Bases:
armi.nuclearDataIO.cccc.IORecordWrites 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 theAsciiRecordReaderputs a space in front of all values (ints, floats, and strings), and puts a newline character\nat the end of all records.-
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
valshould have value, but when the record is being read,valcan beNoneor 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
valshould have value, but when the record is being read,valcan beNoneor 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
valshould have value, but when the record is being read,valcan beNoneor 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
valshould have value, but when the record is being read,valcan beNoneor anything else; it is ignored.
-
-
class
armi.nuclearDataIO.cccc.Stream(fileName, fileMode)[source]¶ Bases:
objectAn 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.
-
__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