Skip to content

Fix _rerun.csv file handling so rerun can re-read its labels#17

Open
hdrake wants to merge 2 commits into
TRACMASS:mainfrom
hdrake:fix-rerun-file-handling
Open

Fix _rerun.csv file handling so rerun can re-read its labels#17
hdrake wants to merge 2 commits into
TRACMASS:mainfrom
hdrake:fix-rerun-file-handling

Conversation

@hdrake

@hdrake hdrake commented Jun 23, 2026

Copy link
Copy Markdown

Summary

Two independent fixes to the ./runtracmass rerun file-handling path. As-is, a rerun pass cannot re-read the trajectory labels (lbas) it needs, so it silently deactivates/mislabels every trajectory.

⚠️ Stacked on #16. The "Files changed" tab includes #16's commits until it merges — this PR's own change is the single commit "Fix _rerun.csv file handling…". It will retarget cleanly to main once #16 lands.

The bugs

  1. Filename prefix applied too late. outDataFile defaults to 'TRACMASS' only inside open_outfiles, which runs after read_rerun. So read_rerun looked for _rerun.csv instead of TRACMASS_rerun.csv → "No rerun file" → every trajectory label left unset. Fixed by applying the default in init_namelist, before first use.
  2. Read/write format mismatch. _rerun.csv is written comma-separated ((I8,',',I3,',',I10)) but read_rerun parsed it with (I8,I3,I10), mis-reading lbas. Fixed with list-directed input.

Effect

Without these, a rerun pass reports 0 exited and writes an empty _run.csv — it never re-integrates the labelled trajectories. (Offline never noticed because it ignores the re-integration and re-reads the trajectory files from disk.) With the fixes, a rerun pass correctly re-seeds and re-integrates the labelled trajectories — verified: exit positions are identical to a normal run.

Also fixes a crash in offline rerun

As a side effect, this resolves a crash in offline rerun (./runtracmass rerun with l_offline=.TRUE.). On main, the broken file handling leaves every trajectory deactivated, producing inconsistent _ini/_rerun files; the offline postprocess then reads an ntrac beyond what it allocated and crashes:

Fortran runtime error: Index '442' of dimension 1 of array 'traj_out' above upper bound of 441

With read_rerun working, the files are consistent and the crash no longer occurs. (A separate, narrower robustness gap remains — the postprocess indexes traj_out(ntrac1) without a bounds check, so a genuinely inconsistent/stale _rerun.csv could still crash ungracefully — but that is independent of this PR.)

Testing

Theoretical project, gfortran -fbounds-check: clean build; a rerun pass now reports the same terminations as the original run and reproduces identical trajectory exit positions; offline rerun completes without the out-of-bounds crash.

🤖 Generated with Claude Code


Addresses #19.

hdrake and others added 2 commits June 22, 2026 19:04
The streamfunction flux arrays and their per-zone loops were hard-coded to
a fixed 21 kill zones, and the kill-zone (10) and tracer (10) capacities
were scattered as bare literals across many files (including per-project
kill_zones.F90). This generalizes those limits and sizes the streamfunction
allocation to the zones a run actually uses.

- Add named capacity constants in mod_precdef: MAXGEOZONES, MAXTRACERS, and
  MAXZONES = 1 + MAXTRACERS + MAXGEOZONES, used to dimension the kill-zone
  and tracer configuration arrays.
- Compute maxlbas (the actual streamfunction zone count) from the run:
  namelist geographic zones + subdomain wall zones + tracer kill zones,
  finalised in init_subdomain once exitType and all zones are known. The
  flux arrays (offline) and the compute_stream loop now size to maxlbas
  instead of a fixed 21.
- Derive runtime loop bounds and the subdomain "last 4" wall slots from
  SIZE() of the arrays, removing the hard-coded slot numbers (7-10) in
  mod_subdomain and the 1,10 loops in kill_zones.F90 (x5), mod_diffusion,
  and mod_init.
- Initialise ienw/iene/jens/jenn to 0 so undefined slots are well-defined.

Fixes a latent out-of-bounds when the configured zone count differs from
21, and an under-allocation when an exitType=2 run uses a subdomain (which
promotes exitType to 3 and adds geographic walls). Behaviour is otherwise
unchanged: streamfunction output now contains the actual number of zone
blocks, verified byte-identical to the previous output for the real zones.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
`./runtracmass rerun` could not re-read the trajectory labels it needs,
due to two issues in the rerun file path (both independent of
streamfunctions):

- The output-file prefix default (outDataFile = 'TRACMASS' when empty)
  was applied only inside open_outfiles, which runs AFTER read_rerun.
  So read_rerun looked for '_rerun.csv' instead of 'TRACMASS_rerun.csv'
  and reported "No rerun file", leaving every trajectory label unset.
  Apply the default in init_namelist, before it is first used.

- _rerun.csv is written comma-separated but read_rerun parsed it with a
  fixed "(I8,I3,I10)" format, mis-reading lbas. Use list-directed input.

With both fixes a rerun pass correctly re-seeds and re-integrates the
labelled trajectories (verified: exit positions identical to a normal
run).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.

1 participant