NOAA-EMC / NCEPLIBS-g2

Utilities for coding/decoding GRIB2 messages.
Other
6 stars 15 forks source link

Remove use of mkieee() in IEEE floating point machines #287

Open edwardhartnett opened 2 years ago

edwardhartnett commented 2 years ago

Currently we have a function called mkieee() which we call in a number of places:

find ../../src/ -name '*.F90'|xargs grep mkieee
../../src/misspack.F90:  call mkieee(rmin4, ref, 1)   ! ensure reference value is IEEE format
../../src/mkieee.F90:subroutine mkieee(a, rieee, num)
../../src/mkieee.F90:end subroutine mkieee
../../src/addfield.F90:     call mkieee(coordlist, coordieee, numcoord)
../../src/addfield.F90:     call mkieee(real(pfld(1)), re00, 1) ! ensure RE(0, 0) value is IEEE format
../../src/specpack.F90:  call mkieee(unpk, cpack, Ts)
../../src/simpack.F90:  call mkieee(rmin4, ref, 1)   ! ensure reference value is IEEE format
../../src/pngpack.F90:  call mkieee(rmin4, ref, 1)  ! Ensure reference value is IEEE format
../../src/jpcpack.F90:  call mkieee(rmin4, ref, 1)   ! ensure reference value is IEEE format
../../src/compack.F90:  call mkieee(rmin4, ref, 1)   ! ensure reference value is IEEE format

Back in olden times, there were machines that did not use IEEE floating point. Are there any longer machines that don't use it?

Also it seems that only some floats are converted to IEEE. So who knows what the output would look like on a machine without IEEE float point. Some floats would be IEEE and many would not. So that would be confusing!

We should either remove mkieee()/rdieee() and check in configuration whether the machine supports IEEE and ifdef() out these calls on machines that don't use them.

@kgerheiser @DusanJovic-NOAA @Hang-Lei-NOAA @BrianCurtis-NOAA @BoiVuong-NOAA comments welcome.

DusanJovic-NOAA commented 2 years ago

If I remember correctly all floating-point values encoded in grib message must be ieee. Which floats are not converted to ieee?

edwardhartnett commented 2 years ago

Well above is a list of all places that mkieee is called in the library.

Most of them seem to be just converting one value, not an array. Only in specpack does an array get converted.

For example in pngpack.F90 we pack an array into our message:

call g2_sbytesc(ctemp, ifld, 0, nbits, 0, ndpts) The contents of this pack are never run through mkieee(). If this were to run on a non-IEEE machine, the message would contain a lot of non-IEEE data, as far as I can see.

Am I missing something?

Has this code always been run on machines that use IEEE for floating point? So this doesn't matter? If so, why were the mkieee()/rdieee() functions developed in the first place?

DusanJovic-NOAA commented 2 years ago

Well above is a list of all places that mkieee is called in the library.

Most of them seem to be just converting one value, not an array. Only in specpack does an array get converted.

For example in pngpack.F90 we pack an array into our message:

call g2_sbytesc(ctemp, ifld, 0, nbits, 0, ndpts) The contents of this pack are never run through mkieee(). If this were to run on a non-IEEE machine, the message would contain a lot of non-IEEE data, as far as I can see.

In this specific call none of the argumens is floating point, ifld is integer.

Am I missing something?

Has this code always been run on machines that use IEEE for floating point? So this doesn't matter? If so, why were the mkieee()/rdieee() functions developed in the first place?

I assume in the past this library was used on non-ieee architecture.