Skip to content

Prevented values requiring exponents of three digits from being written exactly in ASCII pixmaps.#129

Open
s-neilson wants to merge 13 commits into
danieljprice:mainfrom
s-neilson:pixmapAsciiValueTruncation
Open

Prevented values requiring exponents of three digits from being written exactly in ASCII pixmaps.#129
s-neilson wants to merge 13 commits into
danieljprice:mainfrom
s-neilson:pixmapAsciiValueTruncation

Conversation

@s-neilson

@s-neilson s-neilson commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

When ASCII pixmaps are written, they are written with values with exponents of two digits. If value is written that requires more digits, then the "E" will be missing from the written value, making the value invalid.

The following truncations are applied to data to be written into an ASCII pixmap:

  • value > -1.0E-99 and < 0, value becomes = -1.0E-99
  • value < 1.0E-99 and > 0, value becomes = 1.0E-99
  • value > 9.999999E99, value becomes = 9.999999E99
  • value < -9.999999E99, value becomes = -9.999999E99

The user is given warnings when the truncation happens. They are given the type of truncation that occurred and how many pixels that this was done to.

Similar truncation happens to the datmin and datmax values of the headers of ASCII and ppm pixmaps as they use the same formatting string as the ASCII pixmap data.

The truncation will only occur when SPLASH is compiled in double precision mode as it is unnecessary and causes problems when SPLASH is compiled in single precision mode.

I did it this way as opposed to changing the output format in order to maintain compatibility with any applications/scripts that expect a particular format.

Summary by CodeRabbit

  • Bug Fixes
    • Improved ASCII pixmap output by clamping extreme pixel values to the supported numeric range before writing.
    • Added warnings indicating when values were adjusted due to being outside the supported range.
    • Kept the existing ASCII formatting and success behavior unchanged.
  • Build / Chores
    • Updated the build configuration so the pixmap writer is compiled with preprocessing enabled for consistent processing of that source.

…more digits are now truncated to values that can be formatted using an exponent of two digits. This prevents invalid values from being written to the file as ascii pixmaps are written with values that have exponents of two digits. The user is given warnings when the truncation happens.
… be represented with a negative exponent of two digits.
…mits for the largest and smallest values that can be represented with negative expodents of two digits.
@coderabbitai

coderabbitai Bot commented Jun 26, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

write_pixmap_ascii now writes from a clamped pixel buffer and reports counts for extreme values. The build files also switch write_pixmap to the .F90 source name.

Changes

Pixmap ASCII clamping

Layer / File(s) Summary
Clamped buffer and warnings
src/write_pixmap.F90
Allocates and initializes a truncated pixel buffer, counts and clamps extreme values, writes the clamped data, deallocates it, and prints range warnings.
F90 source wiring
build/Makefile, build/.depends
Updates write_pixmap references to write_pixmap.F90 in the build source list and dependency metadata.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐇 I hopped through pixels, big and small,
And clamped the strays before they fall.
With warnings soft and numbers neat,
The pixmap write feels snug and sweet.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: clamping values that would need three-digit exponents in ASCII pixmap output.
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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ 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.

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request introduces value truncation and warning logs for extreme pixel values in the write_pixmap_ascii subroutine to prevent underflow and overflow issues. The feedback highlights two critical issues: first, declaring the temporary array on the stack can cause stack overflow for large pixmaps; second, the current implementation is highly inefficient as it performs nine passes over the array and uses single-precision literals that may cause compile-time errors. It is recommended to allocate the temporary array on the heap and optimize the truncation logic into a single-pass nested loop using double-precision literals.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread src/write_pixmap.f90 Outdated
Comment thread src/write_pixmap.f90 Outdated

@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: 1

🤖 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/write_pixmap.f90`:
- Around line 167-185: The header in write_pixmap is being written from the
original datpix range before clamping, so it can advertise datmin/datmax values
that do not match the saved payload. Update the header-writing logic in
write_pixmap to compute and emit min/max from datpixTruncated after the
truncation and count adjustments, and ensure the same corrected values are used
anywhere else the file metadata is written so the .pix contents and header stay
consistent.
🪄 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: 9fb25452-4fc4-4f3e-ad44-e5750bcb6802

📥 Commits

Reviewing files that changed from the base of the PR and between 4efd030 and a894ddf.

📒 Files selected for processing (1)
  • src/write_pixmap.f90

Comment thread src/write_pixmap.f90 Outdated

@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: 1

🤖 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/write_pixmap.f90`:
- Around line 153-157: The current flow in write_pixmap opens the destination
file with status='replace' before allocating datpixTruncated, so an allocation
failure can delete an existing .pix file and exit without a valid replacement.
Move the datpixTruncated allocation and any copy/truncation work to occur before
the OPEN of the destination unit, or alternatively write to a temporary file and
only replace the final output after the allocation and write steps succeed. Keep
the fix localized around the datpixTruncated allocation/error path and the
destination file OPEN logic.
🪄 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: 555fb55f-52e2-4ade-befc-82d6416ebc2a

📥 Commits

Reviewing files that changed from the base of the PR and between a894ddf and dd473f1.

📒 Files selected for processing (1)
  • src/write_pixmap.f90

Comment thread src/write_pixmap.f90
…uncation will only occur when SPLASH is compiled in double precision mode as it is unnecessary and creates problems in single precision mode. Also added truncation (only in double precision mode) to the header datmin and datmax values for the ascii and ppm pixmaps as they use the same formatting string as the pixel values.
@danieljprice

Copy link
Copy Markdown
Owner

Hi Stephen, thanks for highlighting + submitting a fix for this. However, strongly against introducing ifdefs into the codebase unless it is related to a library. Should rely on epsilon(0.) or tiny(0.) for finding tolerances in the working precision.

@s-neilson

Copy link
Copy Markdown
Contributor Author

@danieljprice I will find another solution that doesn't involve using the preprocessor.

@s-neilson

Copy link
Copy Markdown
Contributor Author

@danieljprice I have changed it so write_pixmap will no longer use the preprocessor.

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