Skip to content

Add python examples and relax integer parsing to accept ints in float representation#3

Merged
Abraxas3d merged 3 commits into
mainfrom
nec-import-working
Apr 15, 2026
Merged

Add python examples and relax integer parsing to accept ints in float representation#3
Abraxas3d merged 3 commits into
mainfrom
nec-import-working

Conversation

@sconklin
Copy link
Copy Markdown
Contributor

Added two python examples to demonstrate how to use the python bindings for nec-input.
nec_inspect.py parses a .nec inpout file and prints information about the cards
nec2json parses an input file and outputs the content in json

I encountered an issue because existing tools write .nec files with a float representation of integer fields, e.g. "0.00000E+00".
The parser now allows this if there is no fractional part of the value in an integer field.

I added test cases for this change, and updated the documentation.

This is the initial work for the nec-import crate,
which will be responsible for parsing NEC files
and converting them into a format that can be used
by the rest of the Arcanum project.

This commit includes the basic structure of the
crate, as well as some initial tests and
documentation.

Also included are a CONTRIBUTING.md file and a
GitHub Actions workflow for
Add example utilities and fix integer parsing for scientific notation

Add two example Python programs in examples/:
- nec2json.py: parses a .nec file and writes SimulationInput as JSON to
  stdout; warnings go to stderr; suitable for piping to jq or other tools
- nec_inspect.py: prints a human-readable annotated breakdown of a parsed
  deck, organized by card category (geometry, ground, frequencies,
  excitations, loads, output requests, warnings)

Fix FieldParseFailure when NEC generators write integer fields in scientific
notation (e.g. "0.00000E+00"). Tools such as 4nec2 write every field
uniformly in this format, including semantically-integer fields like the GM
card's ITS (tag increment). The lexer now falls back to float parsing when
i32 parsing fails, accepting the value as an integer if it has no fractional
part. Non-whole floats in integer fields continue to produce a hard error.

Add validation cases and Rust tests:
- V-FMT-006: scientific notation accepted in integer fields (GM ITS field)
- V-FMT-006 negative case: non-whole float in integer field still errors

Update input-format.md Section 2.2 and validation.md to document this
behavior and the new test cases.
@Abraxas3d Abraxas3d merged commit 2d8832e into main Apr 15, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants