Skip to content

bug: check that input netcdf files have consistent FillValues and missing_values are not working with NaNs #970

@mjs2369

Description

@mjs2369

The check_attribute_value_int/r4/r8 subroutines ensure that the FillValue and missing_value are consistent across input netcdf files. This check is not working correctly if there are inconsistent values and one of them in a NaN.

if (ret_spvalR4 /= ret_spvalR4) then
return
endif
if (spvalR4 /= ret_spvalR4) then
write(msgstring,*) ' variable attribute, ', trim(att_string), ' in state', spvalR4, &
' does not match ', trim(att_string), ' ', ret_spvalR4, ' in ', trim(filename)
call error_handler(E_ERR, 'check_attribute_value_r4', msgstring, source)
endif
endif

It checks if ret_spvalR4 is a NaN with if (ret_spvalR4 /= ret_spvalR4) , but then returns without checking if spvalR4 is also a NaN. So it won't error out as it should with the message that the "variable attribute FillValue in state does not match FillValue in filename"

This is causing this minval function to error out with a floating point exception at this point in the adaptive_inflate_mod -

minmax_mean(1) = minval(ens_handle%copies(ss_inflate_index, :))

This small reproducer program without any DART code errors out in the minval function in this way when given NaNs :

masmith@derecho5:/glade/work/masmith/DART11.14.2/DART/models/ROMS_rutgers/minmax_mean-nan> cat tester.f90
program MinMax
   
   use ieee_arithmetic
   
   implicit none

   real :: arr(7)
   real :: minnie
   real :: x

   x = sqrt(-1.0) ! Generates a NaN
   write(*,*) 'x: ', x

   ! find min and max vals
   arr = [x, x, x, x, 0.0, 2.0, x]
   minnie = minval(arr)
   write(*,*) 'minnie: ', minnie

   !minmax_mean(2) = maxval(ens_handle%copies(ss_inflate_index, :))

end program MinMax

This error only occurs with debugging flags on (namely, -ftrapuv and -fpe0)

Describe the bug

  1. List the steps someone needs to take to reproduce the bug.
    Run DART with input netcdf files in which some have NaNs specified as the FillValue and others do not.

  2. What was the expected outcome?
    DART errors out in check_attributes as it should

  3. What actually happened? ### Error Message
    DART continues running, which causes it to error out (if debugging flags are being used) in the adaptive_inflate_mod due to NaNs being passed into the minval function

Please provide any error messages.
"floating point invalid"

Which model(s) are you working with?

All models

Version of DART

Which version of DART are you using?
v11.15.0

Have you modified the DART code?

No

Build information

Please describe:

  1. The machine you are running on (e.g. windows laptop, NSF NCAR supercomputer Derecho).
  2. The compiler you are using (e.g. gnu, intel).

All machines, all compilers

Note: some compilers might not error out at the minval function in the adaptive_inflate_mod (both gfortran and ifort do), but the issue of the check not evaluating correctly when one of the FillValues is NaN will be present for all compilers.

Metadata

Metadata

Assignees

Labels

BugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions