Skip to content

Aton reader module added (similar to MESA reader) - #858

Merged
danieljprice merged 12 commits into
danieljprice:mainfrom
orsolademarco-astronomy:aton-reader
Aug 4, 2026
Merged

Aton reader module added (similar to MESA reader)#858
danieljprice merged 12 commits into
danieljprice:mainfrom
orsolademarco-astronomy:aton-reader

Conversation

@orsolademarco-astronomy

@orsolademarco-astronomy orsolademarco-astronomy commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Description:
Added a readwrite_aton module similar to MESA and KEPLER. Updated all the lines in setup that needed to include the new option.

Components modified:

  • [ X] Setup (src/setup)
  • Main code (src/main)
  • Moddump utilities (src/utils/moddump)
  • Analysis utilities (src/utils/analysis)
  • Test suite (src/tests)
  • Documentation (docs/)
  • Build/CI (build/ or github actions)

Type of change:

  • Bug fix
  • Physics improvements
  • Better initial conditions
  • Performance improvements
  • Documentation update
  • Better testing
  • Code cleanup / refactor
  • [X ] Other Added a new module like readwirte_mesa.f90 called readwrite_aton.f90 to read star files from another code.

Testing:
I can read the file which is now option 8, and the behaviour is identical to mesa.

Did you run the bots? no

Did you update relevant documentation in the docs directory? no

Did you add comments such that the purpose of the code is understandable? yes

Is there a unit test that could be added for this feature/bug? yes I think anything that is done for MESA would work.

If so, please describe what a unit test might check:
a test should check that running phantomsetup on SETUP=star with ieos=10 and option=8 successfully creates a dump

Summary by CodeRabbit

  • New Features

    • Added support for importing/exporting ATON-format stellar profiles.
    • Introduced ATON as a selectable density-profile/EOS option, including input-profile handling and updated setup/option I/O.
  • Bug Fixes

    • Improved ATON profile detection and validation by inferring ATON from column labels and expanding nonnegativity checks to cover additional required fields.
    • Refined softened-core workflows to reuse ATON read/write steps consistently.
    • Enhanced multi-star EOS setup so variable-component options are requested only when relevant.
  • Chores

    • Updated build configuration to include an additional ATON-related compilation unit.
    • Updated editor settings to disable the Fortran language server.

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Adds ATON stellar-profile file parsing and validation, registers an ATON profile option, integrates it into stellar setup, relaxation, softened-core handling, and EOS configuration, and includes the source in star-related builds.

Changes

ATON Profile Support

Layer / File(s) Summary
ATON profile I/O
src/setup/readwrite_aton.f90, build/Makefile
Updates ATON profile parsing, file detection, validation, and build inclusion.
ATON profile option wiring
src/setup/set_star_utils.f90, src/setup/set_star.f90, src/.vscode/settings.json, src/setup/readwrite_mesa.f90
Registers the ATON option and filename, extends setup, relaxation, EOS, and input-file branches, and updates supporting metadata and editor configuration.
Profile loading and softened-core flow
src/setup/set_star_utils.f90
Loads ATON profiles, performs ATON softened-core write/readback, tracks filenames, and reports read errors by status.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Suggested reviewers: themikelau

Sequence Diagram(s)

sequenceDiagram
  participant setstar
  participant read_star_profile
  participant read_aton
  participant write_aton
  setstar->>read_star_profile: select iaton profile
  read_star_profile->>read_aton: load input profile
  read_aton-->>read_star_profile: profile data and ierr
  read_star_profile->>write_aton: write softened ATON profile
  write_aton-->>read_star_profile: softened profile
  read_star_profile->>read_aton: reload softened profile
  read_aton-->>read_star_profile: profile data and ierr
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: adding an ATON reader module similar to the MESA reader.
Description check ✅ Passed The description covers the required sections and gives a usable summary, testing notes, and unit-test idea.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 6

🧹 Nitpick comments (2)
src/.vscode/settings.json (1)

1-3: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Drop this local editor config from the PR.

src/.vscode/settings.json disables the Fortran language server for every contributor and is unrelated to ATON support. Keep it local (or gitignored).

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/.vscode/settings.json` around lines 1 - 3, Remove the
src/.vscode/settings.json editor configuration from the change so the
fortran.fortls.disabled setting is not committed. Keep this local-only
configuration outside version control or ensure it is gitignored.
src/setup/readwrite_aton.f90 (1)

63-97: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Remove leftover debug prints.

Lines 64, 73, 88 (and arguably 97) are development traces ('I am after ...') that will pollute setup output.

🧹 Proposed cleanup
 lines = get_nlines(fullfilepath) ! total number of lines in file
-write(*,*)'I am after get_nlines', lines 
 
 open(newunit=iu,file=fullfilepath,status='old',iostat=ierr)
@@
 call get_ncolumns(iu,ncols,nheaderlines)
- write(*,*)'I am after get_ncolummns in ATON. This is nheaderlines', nheaderlines
 lines = lines - nheaderlines
@@
 call read_column_labels(iu,nheaderlines,ncols,nlabels,header)
- write(*,*)'I am after read_column_labels', nlabels,ncols  
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/setup/readwrite_aton.f90` around lines 63 - 97, Remove the development
trace write statements around get_nlines, get_ncolumns, and read_column_labels
in the setup flow; retain the meaningful “Reading ATON from centre to surface”
status message unless it is also considered unwanted debug output.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/setup/readwrite_aton.f90`:
- Around line 179-184: Update the ATON input validation in the read routine to
include the initialized sentinel arrays r and m alongside pres and rho, so
missing radius or mass columns set an error before downstream calculations. Use
a distinct ierr value for missing required columns, and ensure the setstar_utils
error mapping reports incomplete columns rather than “file does not exist,”
while preserving the existing missing-file code.
- Around line 254-262: Update read_aton’s mass-unit detection to inspect the
parsed column-label line for the case-insensitive `#m/msun` label, rather than
relying on nheaderlines == 5. Ensure the ATON-specific solar-mass conversion is
enabled whenever that label is present before cgs conversion.
- Line 17: Update the :Dependencies: header for read_aton to include table_utils
alongside the existing dependencies, matching its use of table_utils:flip_array.
Leave the implementation unchanged.
- Around line 170-177: Remove the dead rewind-and-header-reskip block after the
data-reading logic so it cannot overwrite ierr before the existing validation.
Also remove the vestigial idir declaration, conditional print, and related
scaffolding in the readwrite_aton routine, while preserving the actual
header/data parsing and close behavior.

In `@src/setup/readwrite_mesa.f90`:
- Line 13: Correct the header metadata tag in the file header from :OWner: to
:Owner:, preserving the existing owner value and leaving unrelated ATON changes
untouched.

In `@src/setup/set_star.f90`:
- Line 1180: Wrap the long conditional call in the setup flow around the
`read_inopt` invocation, splitting the `any(star(:)%iprofile==imesa .or.
star(:)%iprofile==iaton)` condition across continuation lines so every line
stays within 100 columns. Apply the same formatting to the corresponding
condition around the second occurrence noted in the review, without changing
behavior.

---

Nitpick comments:
In `@src/.vscode/settings.json`:
- Around line 1-3: Remove the src/.vscode/settings.json editor configuration
from the change so the fortran.fortls.disabled setting is not committed. Keep
this local-only configuration outside version control or ensure it is
gitignored.

In `@src/setup/readwrite_aton.f90`:
- Around line 63-97: Remove the development trace write statements around
get_nlines, get_ncolumns, and read_column_labels in the setup flow; retain the
meaningful “Reading ATON from centre to surface” status message unless it is
also considered unwanted debug output.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 4b67ce54-6b64-4a0f-bce2-5fc34247cb88

📥 Commits

Reviewing files that changed from the base of the PR and between 41c142e and 4969068.

📒 Files selected for processing (6)
  • build/Makefile
  • src/.vscode/settings.json
  • src/setup/readwrite_aton.f90
  • src/setup/readwrite_mesa.f90
  • src/setup/set_star.f90
  • src/setup/set_star_utils.f90

Comment thread src/setup/readwrite_aton.f90 Outdated
Comment thread src/setup/readwrite_aton.f90 Outdated
Comment thread src/setup/readwrite_aton.f90 Outdated
Comment thread src/setup/readwrite_aton.f90
Comment thread src/setup/readwrite_mesa.f90
Comment thread src/setup/set_star.f90 Outdated
@orsolademarco-astronomy

Copy link
Copy Markdown
Contributor Author

Hello Daniel, I have addressed all the bot comments that came to me after my pull request. I have tested and re-committed and also pushed.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (1)
src/setup/set_star.f90 (1)

676-678: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Add an end-to-end regression test for profile option 8.

Exercise phantomsetup with SETUP=star, ieos=10, and ATON option 8, then assert that a dump is created. This validates the parser, option registration, EOS configuration, and softened-profile path wired through src/setup/set_star_utils.f90.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/setup/set_star.f90` around lines 676 - 678, Add an end-to-end regression
test invoking phantomsetup with SETUP=star, ieos=10, and ATON profile option 8,
then assert that the expected dump file is created. Ensure the test exercises
the parser, option registration, EOS setup, and softened-profile path in
set_star_utils.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/setup/readwrite_aton.f90`:
- Line 17: Update the dependency metadata comment in the module header so the
entries use canonical alphabetical order, placing table_utils before units while
preserving all other dependencies.
- Around line 81-84: Format the label scan in the isatonfile detection block to
satisfy Fortitude: split the long conditional involving header(i) across
continuation lines and use the project’s lint-compliant loop terminator form for
both affected loops, including the loop near the second reported location.

In `@src/setup/set_star.f90`:
- Around line 1180-1181: Convert the continued inline if statements guarding
read_inopt calls in the setup flow to block if/end if statements, including both
occurrences near the star profile checks. Preserve the existing conditions, call
arguments, and execution behavior while making the EOS wiring explicit.

---

Nitpick comments:
In `@src/setup/set_star.f90`:
- Around line 676-678: Add an end-to-end regression test invoking phantomsetup
with SETUP=star, ieos=10, and ATON profile option 8, then assert that the
expected dump file is created. Ensure the test exercises the parser, option
registration, EOS setup, and softened-profile path in set_star_utils.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: dd72345e-255e-4dc0-af77-1a9c925d5326

📥 Commits

Reviewing files that changed from the base of the PR and between 4969068 and 610522d.

📒 Files selected for processing (2)
  • src/setup/readwrite_aton.f90
  • src/setup/set_star.f90

Comment thread src/setup/readwrite_aton.f90 Outdated
Comment thread src/setup/readwrite_aton.f90
Comment thread src/setup/set_star.f90 Outdated
@orsolademarco-astronomy

Copy link
Copy Markdown
Contributor Author

One more round of minor fixes identified by the bot.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/setup/readwrite_aton.f90 (1)

73-75: 🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

Close iu before every post-open return.

read_aton opens iu at Line 65, but the empty-data, data-read-error, and invalid-header branches return without closing it. Repeated calls can leak Fortran I/O units; use a cleanup path or close the unit before each return.

Proposed fix
 if (lines <= 0) then
    ierr = 1
+   close(iu)
    return
 endif
...
 if (ierr /= 0) then
    print "(a,/)",' ERROR reading data from ATON file (new statement)'
+   close(iu)
    return
 endif
...
           ierr = 2
+          close(iu)
           return

Also applies to: 94-99, 106-112

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/setup/readwrite_aton.f90` around lines 73 - 75, Update read_aton so every
return after opening iu closes the unit first, including the empty-data,
data-read-error, and invalid-header branches. Prefer a shared cleanup path if
appropriate, while preserving each branch’s existing ierr behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@src/setup/readwrite_aton.f90`:
- Around line 73-75: Update read_aton so every return after opening iu closes
the unit first, including the empty-data, data-read-error, and invalid-header
branches. Prefer a shared cleanup path if appropriate, while preserving each
branch’s existing ierr behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: b4d338cc-6789-4971-b6a7-4a7b79170979

📥 Commits

Reviewing files that changed from the base of the PR and between 610522d and 8476d65.

📒 Files selected for processing (2)
  • src/setup/readwrite_aton.f90
  • src/setup/set_star.f90

@danieljprice

Copy link
Copy Markdown
Owner

Delighted to see your pull request @orsolademarco-astronomy :)

One thing that would be helpful for testing is to supply an example Aton file that we can use as the default setup for iprofile=8. You should be able to just attach it as a file in the description or comments thread, or alternatively post an example file on zenodo and link to the phantom zenodo community (and update src/main/datafiles.f90 with the lookup address).

One of the tests we run is to check that default SETUP=star with iprofile=[0,1,2,3,4,5...] etc all manage to relax a star with default settings. This is done by some code in scripts/buildbot.sh:

test_setupfile_options()
{
   myfail=0;
   setupfile=$1;
   flags=$2;
   setup=$3;
   infile=$4;
   range=''
   if [ "X$setup" == "Xstar" ]; then
      param='iprofile1'
      range='0 1 2 3 4 5 6 7'
   fi

It'd make sense to expand the range to 8... that way we can guarantee that the ATON read is not broken.

There are also a bunch of tests run in .github/workflows/binary.yml that test against various "known" .setup and .in files so could equivalently add something there (e.g. if you want to test something other than a single star)

@orsolademarco-astronomy

Copy link
Copy Markdown
Contributor Author

I have a question about updating datafiles.f90. I expected to have to add the new zenodo repo, but what I found was there is only one line referring to data/star_data_files which currently points to a zenodo repo that Ali has added with his WD file. (I realise that a number of other star data files are inside the phantom repo, like the Kpler or Jan stars.) If I just want to add my new zendo repo with the ATON star what case should I use since "my case" is already used? This is what is in the file:

case('data/star_data_files')
url = 'https://zenodo.org/records/20738843/files/'

but I also need the file to go into data/star_data_files, but I cannot make a new case, nor have another URL in there. The AI suggestion is a structural rewrite of datafiles.f90 to be more granular and search files rather than entire directories, but I do not really want to go there.

So the alternative you give is the zenodo link to phantom which I have done. But the other suggestions you make "You should be able to just attach it as a file in the description or comments thread" seems vague. Should I not just commit the file to the data_star_file for now? Awaiting a rationalisation of star files in general?

@danieljprice

Copy link
Copy Markdown
Owner

I will merge this for now, I can add the test in a subsequent P-R, the file is online so should be easy.

General documentation on datafiles here:
https://phantomsph.readthedocs.io/en/latest/developer-guide/datafiles.html

@danieljprice
danieljprice merged commit f68ddd7 into danieljprice:main Aug 4, 2026
537 of 539 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