OpenCDSS / cdss-app-statecu-fortran

Colorado's Decision Support Systems (CDSS) StateCU consumptive use model code, documentation, tests
GNU General Public License v3.0
1 stars 1 forks source link

Error at end of run: floating-point exceptions are signalling IEEE_INVALID_FLAG #13

Closed smalers closed 3 years ago

smalers commented 5 years ago

At the end of running the CDSS gm2015 dataset, get:

Note: The following floating-point exceptions are signalling: IEEE_INVALID_FLAG

smalers commented 5 years ago

Found the SO article Debugging with gdb and gfortran - FPE's.

Also see GitHub issue for an open source project listing error codes.

smalers commented 5 years ago

I changed the compile options to:

FCFLAGS = -g -cpp -fno-align-commons -static -fbounds-check -fno-automatic -finit-local-zero -fbacktrace -ffpe-trap=invalid,zero,overflow,underflow,denormal

This identified an issue on line 1512 of statecu.for, dividing by zero ttacre

smalers commented 5 years ago

Some dataset files had NaN and 0.0 that were resulting in divide by zero, but strangely did not cause an immediate issue...in some cases only resulting in an error after the full run completed. The following illustrates how NaN can e detected when read from an input file: Something like this may be needed if using NaN in input files for missing data or to catch as a fallthrough.

! Program to test reading a NaN from disk
       program nantest
       USE, INTRINSIC :: IEEE_ARITHMETIC, ONLY:  IEEE_IS_NAN
       implicit none
       real f1, f2
       integer IERR

       OPEN (UNIT=1,FILE='data.txt',STATUS='OLD',IOSTAT=IERR)
       IF (IERR.NE.0) CALL MYEXIT(1)

       read(1,100) f1, f2
100    format(f8.0,f8.0)
       write(*,*) 'Values read =', f1, f2

       if (ieee_is_nan(f1) ) then
               write(*,*) 'Detected first value is NaN'
       endif
       if (ieee_is_nan(f2) ) then
               write(*,*) 'Detected second value is NaN'
       endif

       CLOSE(1)

       end

       subroutine MYEXIT(status)
       integer status
       write(*,*) 'Error=',status
       return
       end

Use a data file with (8 characters for each value):

1.0     NaN

Compile with: gfortran nantest.for -o nantest.exe

Then run nantest.

smalers commented 3 years ago

I'm closing this issue. It is similar to issue #15, which has been resolved.