Replacing endf c functions with package (#3101)

This commit is contained in:
Jonathan Shimwell 2024-08-14 05:43:44 +01:00 committed by GitHub
parent 346f751deb
commit 3ef54ec349
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 3 additions and 75 deletions

View file

@ -1,8 +0,0 @@
# cython: c_string_type=str, c_string_encoding=ascii
cdef extern from "endf.c":
double cfloat_endf(const char* buffer, int n)
def float_endf(s):
cdef const char* c_string = s
return cfloat_endf(c_string, len(s))

View file

@ -1,57 +0,0 @@
#include <stdlib.h>
//! Convert string representation of a floating point number into a double
//
//! This function handles converting floating point numbers from an ENDF 11
//! character field into a double, covering all the corner cases. Floating point
//! numbers are allowed to contain whitespace (which is ignored). Also, in
//! exponential notation, it allows the 'e' to be omitted. A field containing
//! only whitespace is to be interpreted as a zero.
//
//! \param buffer character input from an ENDF file
//! \param n Length of character input
//! \return Floating point number
double cfloat_endf(const char* buffer, int n)
{
char arr[13]; // 11 characters plus e and a null terminator
int j = 0; // current position in arr
int found_significand = 0;
int found_exponent = 0;
// limit n to 11 characters
n = n > 11 ? 11 : n;
int i;
for (i = 0; i < n; ++i) {
char c = buffer[i];
// Skip whitespace characters
if (c == ' ') continue;
if (found_significand) {
if (!found_exponent) {
if (c == '+' || c == '-') {
// In the case that we encounter +/- and we haven't yet encountered
// e/E, we manually add it
arr[j++] = 'e';
found_exponent = 1;
} else if (c == 'e' || c == 'E' || c == 'd' || c == 'D') {
arr[j++] = 'e';
found_exponent = 1;
continue;
}
}
} else if (c == '.' || (c >= '0' && c <= '9')) {
found_significand = 1;
}
// Copy character
arr[j++] = c;
}
// Done copying. Add null terminator and convert to double
arr[j] = '\0';
return atof(arr);
}

View file

@ -14,11 +14,7 @@ import numpy as np
from .data import gnds_name
from .function import Tabulated1D
try:
from ._endf import float_endf
_CYTHON = True
except ImportError:
_CYTHON = False
from endf.records import float_endf
_LIBRARY = {0: 'ENDF/B', 1: 'ENDF/A', 2: 'JEFF', 3: 'EFF',
@ -91,10 +87,6 @@ def py_float_endf(s):
return float(ENDF_FLOAT_RE.sub(r'\1e\2\3', s))
if not _CYTHON:
float_endf = py_float_endf
def int_endf(s):
"""Convert string of integer number in ENDF to int.

View file

@ -34,6 +34,7 @@ dependencies = [
"lxml",
"uncertainties",
"setuptools",
"endf",
]
[project.optional-dependencies]

View file

@ -6,7 +6,7 @@ from Cython.Build import cythonize
kwargs = {
# Cython is used to add resonance reconstruction and fast float_endf
# Cython is used to add resonance reconstruction
'ext_modules': cythonize('openmc/data/*.pyx'),
'include_dirs': [np.get_include()]
}