Set truncation file handle check from < 0 to == -1#739
Merged
Conversation
adcroft
approved these changes
Oct 18, 2024
This patch replaces the `CS%[uv]_file < 0` checks with `CS%[uv]_file == -1`. FMS1 returns negative file handles for missing or otherwise error-prone files, but the FMS2 IO framework relies on `newunit=` to autogenerate handle IDs, which are always negative and cannot be used with checks for negative values. The check is replaced with equality with -1. `newunit` is guaranteed to never return -1 for a valid file, so this is a valid check for a missing file. It also lets us continue to use -1 as the initial (unopened) value. Behavior is compatible with `mpp_open()` output, so this can also be used with the FMS1 API. A better solution would be to introduce some validation function which is defined by each API, but there is not yet any need for such sophistication.
68701fd to
51cae91
Compare
Member
theresa-cordero
pushed a commit
to theresa-cordero/MOM6
that referenced
this pull request
Nov 18, 2024
This patch replaces the `CS%[uv]_file < 0` checks with `CS%[uv]_file == -1`. FMS1 returns negative file handles for missing or otherwise error-prone files, but the FMS2 IO framework relies on `newunit=` to autogenerate handle IDs, which are always negative and cannot be used with checks for negative values. The check is replaced with equality with -1. `newunit` is guaranteed to never return -1 for a valid file, so this is a valid check for a missing file. It also lets us continue to use -1 as the initial (unopened) value. Behavior is compatible with `mpp_open()` output, so this can also be used with the FMS1 API. A better solution would be to introduce some validation function which is defined by each API, but there is not yet any need for such sophistication.
This was referenced Nov 27, 2024
herrwang0
added a commit
to herrwang0/SIS2
that referenced
this pull request
Nov 8, 2025
This patch fixes a bug that velocity trunction files were not written using FMS2. The issue was that negative file handles returned by open(newunit) is disregarded. This is the same patch as in NOAA-GFDL/MOM6#739 but for SIS2.
herrwang0
added a commit
to herrwang0/SIS2
that referenced
this pull request
Nov 8, 2025
This patch fixes a bug that velocity trunction files were not written using FMS2. The issue was that negative file handles returned by open(newunit) is disregarded. This is the same patch as in NOAA-GFDL/MOM6#739 but for SIS2.
Hallberg-NOAA
pushed a commit
to NOAA-GFDL/SIS2
that referenced
this pull request
Dec 3, 2025
This patch fixes a bug that velocity trunction files were not written using FMS2. The issue was that negative file handles returned by open(newunit) is disregarded. This is the same patch as in NOAA-GFDL/MOM6#739 but for SIS2.
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.
This patch replaces the
CS%[uv]_file < 0checks withCS%[uv]_file == -1. FMS1 returns negative file handles for missing or otherwise error-prone files, but the FMS2 IO framework relies onnewunit=to autogenerate handle IDs, which are always negative and cannot be used with checks for negative values.The check is replaced with equality with -1.
newunitis guaranteed to never return -1 for a valid file, so this is a valid check for a missing file. It also lets us continue to use -1 as the initial (unopened) value.Behavior is compatible with
mpp_open()output, so this can also be used with the FMS1 API.A better solution would be to introduce some validation function which is defined by each API, but there is not yet any need for such sophistication.