From 643eaf53cbbfe133df54f38c5bb0d0c23cb93442 Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Fri, 18 Nov 2016 11:04:34 -0600 Subject: [PATCH] Add function to read all ENDF evaluations from a single file --- docs/source/pythonapi/index.rst | 1 + openmc/data/endf.py | 39 +++++++++++++++++++++++++++++---- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/docs/source/pythonapi/index.rst b/docs/source/pythonapi/index.rst index b86107f37..fc01b99e7 100644 --- a/docs/source/pythonapi/index.rst +++ b/docs/source/pythonapi/index.rst @@ -478,6 +478,7 @@ Functions openmc.data.endf.float_endf openmc.data.endf.get_cont_record + openmc.data.endf.get_evaluations openmc.data.endf.get_head_record openmc.data.endf.get_tab1_record openmc.data.endf.get_tab2_record diff --git a/openmc/data/endf.py b/openmc/data/endf.py index 0197b65e4..34553ad2d 100644 --- a/openmc/data/endf.py +++ b/openmc/data/endf.py @@ -14,6 +14,7 @@ import os from math import pi from collections import OrderedDict, Iterable +from six import string_types import numpy as np from numpy.polynomial.polynomial import Polynomial @@ -249,14 +250,40 @@ def get_tab2_record(file_obj): return params, Tabulated2D(breakpoints, interpolation) +def get_evaluations(filename): + """Return a list of all evaluations within an ENDF file. + + Parameters + ---------- + filename : str + Path to ENDF-6 formatted file + + Returns + ------- + list + A list of :class:`openmc.data.endf.Evaluation` instances. + + """ + evaluations = [] + with open(filename, 'r') as fh: + while True: + pos = fh.tell() + line = fh.readline() + if line[66:70] == ' -1': + break + fh.seek(pos) + evaluations.append(Evaluation(fh)) + return evaluations + class Evaluation(object): """ENDF material evaluation with multiple files/sections Parameters ---------- - filename : str - Path to ENDF file to read + filename_or_obj : str or file-like + Path to ENDF file to read or an open file positioned at the start of an + ENDF material Attributes ---------- @@ -273,8 +300,11 @@ class Evaluation(object): indicator (MOD). """ - def __init__(self, filename): - fh = open(filename, 'r') + def __init__(self, filename_or_obj): + if isinstance(filename_or_obj, string_types): + fh = open(filename_or_obj, 'r') + else: + fh = filename_or_obj self.section = {} self.info = {} self.target = {} @@ -304,6 +334,7 @@ class Evaluation(object): # If end of material reached, exit loop if MAT == 0: + fh.readline() break section_data = ''