Fix _rerun.csv file handling so rerun can re-read its labels#17
Open
hdrake wants to merge 2 commits into
Open
Conversation
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>
This was referenced Jun 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two independent fixes to the
./runtracmass rerunfile-handling path. As-is, a rerun pass cannot re-read the trajectory labels (lbas) it needs, so it silently deactivates/mislabels every trajectory.The bugs
outDataFiledefaults to'TRACMASS'only insideopen_outfiles, which runs afterread_rerun. Soread_rerunlooked for_rerun.csvinstead ofTRACMASS_rerun.csv→ "No rerun file" → every trajectory label left unset. Fixed by applying the default ininit_namelist, before first use._rerun.csvis written comma-separated ((I8,',',I3,',',I10)) butread_rerunparsed it with(I8,I3,I10), mis-readinglbas. Fixed with list-directed input.Effect
Without these, a rerun pass reports
0 exitedand 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 rerunwithl_offline=.TRUE.). Onmain, the broken file handling leaves every trajectory deactivated, producing inconsistent_ini/_rerunfiles; the offline postprocess then reads anntracbeyond what it allocated and crashes:With
read_rerunworking, the files are consistent and the crash no longer occurs. (A separate, narrower robustness gap remains — the postprocess indexestraj_out(ntrac1)without a bounds check, so a genuinely inconsistent/stale_rerun.csvcould 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.