Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/f4enix/input/MCNPinput.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
from f4enix.input.materials import MatCardsList, Material

PAT_MT = re.compile(r"m[tx]\d+", re.IGNORECASE)
PAT_COLUMN_FORMAT = re.compile(r"\s*\#")
PAT_BLANK_LINE = re.compile(r"\n[\s\t]*\n")
ADD_LINE_FORMAT = " {}\n"

Expand Down Expand Up @@ -601,6 +602,15 @@ def _to_dict(cards: list[parser.Card]) -> dict[str, parser.Card]:
comment = card.lines
flag_add = True
continue

# check if it is a column format
if PAT_COLUMN_FORMAT.match(card.lines[0]) is not None:
# then this needs to be added to the previous card
new_cards[previous_key].lines.extend(card.lines)
new_cards[previous_key].get_input()
new_cards[previous_key].get_values()
continue

# and then if it is a proper card
else:
key = card.card().split()[0].upper()
Expand All @@ -615,6 +625,7 @@ def _to_dict(cards: list[parser.Card]) -> dict[str, parser.Card]:
flag_add = False

new_cards[key] = card
previous_key = key

return new_cards

Expand Down
18 changes: 18 additions & 0 deletions tests/MCNPinput_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -917,3 +917,21 @@ def test_add_SDDR_dose_function(self):
"DF14 0.0485 0.1254 0.2050 0.2999 0.3381 0.3572"
in inp.other_data["DF14"].lines[0]
)

def test_column_format(self, tmp_path):
with as_file(resources_inp.joinpath("column_format.i")) as FILE1:
inp = Input.from_input(FILE1)

outfile = tmp_path / "column_format_output.i"
inp.write(outfile)

inp2 = Input.from_input(outfile)
# check for the # line
with open(outfile) as f:
lines = f.readlines()
found = False
for line in lines:
if " # wwn1:p" in line:
found = True
break
assert found
Loading
Loading