Skip to content

Commit 68701fd

Browse files
committed
Set truncation file handle check from < 0 to == -1
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.
1 parent f90b071 commit 68701fd

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/diagnostics/MOM_PointAccel.F90

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,11 @@ subroutine write_u_accel(I, j, um, hin, ADp, CDp, dt, G, GV, US, CS, vel_rpt, st
121121
do_k(:) = .false.
122122

123123
! Open up the file for output if this is the first call.
124-
if (CS%u_file < 0) then
124+
if (CS%u_file == -1) then
125125
if (len_trim(CS%u_trunc_file) < 1) return
126126
call open_ASCII_file(CS%u_file, trim(CS%u_trunc_file), action=APPEND_FILE, &
127127
threading=MULTIPLE, fileset=SINGLE_FILE)
128-
if (CS%u_file < 0) then
128+
if (CS%u_file == -1) then
129129
call MOM_error(NOTE, 'Unable to open file '//trim(CS%u_trunc_file)//'.')
130130
return
131131
endif
@@ -462,11 +462,11 @@ subroutine write_v_accel(i, J, vm, hin, ADp, CDp, dt, G, GV, US, CS, vel_rpt, st
462462
do_k(:) = .false.
463463

464464
! Open up the file for output if this is the first call.
465-
if (CS%v_file < 0) then
465+
if (CS%v_file == -1) then
466466
if (len_trim(CS%v_trunc_file) < 1) return
467467
call open_ASCII_file(CS%v_file, trim(CS%v_trunc_file), action=APPEND_FILE, &
468468
threading=MULTIPLE, fileset=SINGLE_FILE)
469-
if (CS%v_file < 0) then
469+
if (CS%v_file == -1) then
470470
call MOM_error(NOTE, 'Unable to open file '//trim(CS%v_trunc_file)//'.')
471471
return
472472
endif

0 commit comments

Comments
 (0)