Skip to content

c_geometry: write parsed fields back on trailing-field cards - #115

Merged
tmolteno merged 1 commit into
tmolteno:masterfrom
KJ7LNW:c-geometry-writeback-trailing-fields
Jul 21, 2026
Merged

c_geometry: write parsed fields back on trailing-field cards#115
tmolteno merged 1 commit into
tmolteno:masterfrom
KJ7LNW:c-geometry-writeback-trailing-fields

Conversation

@KJ7LNW

@KJ7LNW KJ7LNW commented Jul 20, 2026

Copy link
Copy Markdown

Description

The shared geometry card parser only wrote its output pointers inside the in-loop end-of-string guards. A card carrying more numeric fields than the two integers and seven reals the reader consumes left line_idx short of the terminator, so the write-back never fired and the caller (which reuses one parse state across every card) retained the previous card values.

Concretely a GM move card took its repeat count from a preceding GA arc segment count and replicated the whole structure, exploding the segment total. The regression came from 220977d, which extracted the shared parser and dropped the unconditional write-back that the nec2c and xnec2c ancestors retain.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)

Implementation Details

Restore the unconditional write-back of the parsed integers and reals at the normal loop-exit of the shared geometry card parser, repairing every geometry card type that carries trailing fields.

Testing

Reproduce with cebik 84-8.nec, whose 12-field GM card after two 90-segment GA arcs yielded 16380 segments instead of 180 and ran multi-hour at 8 GB:

CM 2-element circular quad beam
CE
GA 1 90 .1572 0 360 .001
GA 2 90 .1722 0 360 .001
GM 0 0 0 0 0 0 .1665 0 2 0 0 0
GE 0 -1 0
EX 0 1 68 0 1.0 0.0
FR 0 1 0 0 299.8 1
RP 0 1 361 1000 90 0 1 1
EN

The shared geometry card parser only wrote its output pointers inside the
in-loop end-of-string guards, so a card carrying more numeric fields than the
two integers and seven reals it consumes returned without writing. The caller
reuses one parse state across every card, so a GM move card took its repeat
count from the preceding GA arc segment count and replicated the whole
structure, exploding the segment total. The regression came from 220977d,
which extracted the shared parser and dropped the unconditional write-back that
the nec2c and xnec2c ancestors retain.

Reproduce with cebik 84-8.nec, whose 12-field GM card after two 90-segment GA
arcs yields 16380 segments instead of 180 and runs multi-hour at 8 GB:

  CM 2-element circular quad beam
  CM https://antenna2.github.io/cebik/books/Antenna-Modeling-Notes-Models-Vol-1-4.zip { /Vol-4/nec/84-8.nec }
  CE
  GA 1 90 .1572 0 360 .001
  GA 2 90 .1722 0 360 .001
  GM 0 0 0 0 0 0 .1665 0 2 0 0 0
  GE 0 -1 0
  EX 0 1 68 0 1.0 0.0
  FR 0 1 0 0 299.8 1
  RP 0 1 361 1000 90 0 1 1
  EN

- restore unconditional write-back of the parsed integers and reals at the
  normal loop-exit of the shared geometry card parser, repairing every geometry
  card type that carries trailing fields

Signed-off-by: Eric Wheeler <necpp@z.ewheeler.org>
@tmolteno
tmolteno merged commit 0c53c19 into tmolteno:master Jul 21, 2026
1 check passed
@tmolteno

Copy link
Copy Markdown
Owner

Review ✅ Approved & Merged

@KJ7LNW — thank you for this excellent contribution. This is a textbook
bug fix: single logical correction, clear root cause, concrete reproducer
(84-8.nec), zero risk to existing paths, and a severe regression
(16K→180 segments on a GM card).

Key findings from review:

  • Root cause precisely identified: the shared parse_geometry_card_line()
    only wrote back on \0 terminator, but GM has 12 fields (exceeding the
    2+7 parsed), so the write-back never fired and the caller's reused parse
    state retained stale GM repeat-count values from the preceding GA card.
  • Fix is idempotent: the unconditional write-back at function-end fires
    only on normal loop exit. All existing working paths return before reaching
    it, so zero risk to existing callers.
  • Excellent reproduction deck: the Cebik 84-8.nec quad beam clearly
    demonstrates the segment explosion (180→16380 before, 180 correct after).

Nice work!

@tmolteno tmolteno self-assigned this Jul 21, 2026
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