@@ -2217,7 +2217,18 @@ subroutine read_dyn_field_2d(fieldname, fh, dimname, buffer)
22172217 ! to NaN. In that case infld can return NaNs where the element GLL points
22182218 ! are not "unique columns"
22192219 ! Set NaNs or fillvalue points to zero
2220- where (isnan(buffer) .or. (buffer== fillvalue)) buffer = 0.0_r8
2220+ where (isnan(buffer))
2221+ ! check for NaN first, as comparing NaN to fillvalue raises floating invalid.
2222+ buffer = 0.0_r8
2223+ end where
2224+
2225+ if (.not. isnan(fillvalue)) then
2226+ ! only compare against fillvalue if fillvalue is not NaN, otherwise the comparison
2227+ ! will raise floating invalid.
2228+ where (buffer == fillvalue)
2229+ buffer = 0.0_r8
2230+ end where
2231+ end if
22212232
22222233end subroutine read_dyn_field_2d
22232234
@@ -2247,7 +2258,18 @@ subroutine read_dyn_field_3d(fieldname, fh, dimname, buffer)
22472258 ! to NaN. In that case infld can return NaNs where the element GLL points
22482259 ! are not "unique columns"
22492260 ! Set NaNs or fillvalue points to zero
2250- where (isnan(buffer) .or. (buffer == fillvalue)) buffer = 0.0_r8
2261+ where (isnan(buffer))
2262+ ! check for NaN first, as comparing NaN to fillvalue raises floating invalid.
2263+ buffer = 0.0_r8
2264+ end where
2265+
2266+ if (.not. isnan(fillvalue)) then
2267+ ! only compare against fillvalue if fillvalue is not NaN, otherwise the comparison
2268+ ! will raise floating invalid.
2269+ where (buffer == fillvalue)
2270+ buffer = 0.0_r8
2271+ end where
2272+ end if
22512273
22522274end subroutine read_dyn_field_3d
22532275
0 commit comments