0

I am working on NCEPLIBS-g2, a free software library from NOAA which allows meteorologists and climate scientists to access GRIB2 data.

I have a warning:

  121 |   allones = Z'FFFFFFFF'
      |            1
Warning: Conversion from ‘INTEGER(16)’ to ‘INTEGER(4)’ at (1) [-Wconversion]

This comes from the following code:

  integer(4) :: ire00, allones

  allones = Z'FFFFFFFF'

Apparently the BOZ constant Z'FFFFFFFF' is being interpreted as an INTEGER(16).

How do I indicate that it is an INTEGER(4), and so silence this warning?

Edward Hartnett
  • 882
  • 7
  • 16
  • 2
    The error you have and the code you show don't match. (And the code you show is not valid Fortran.) – francescalus Jul 29 '22 at 16:42
  • 1
    Upgrade your version of gfortran to 11.x. – steve Jul 29 '22 at 19:29
  • 1
    BTW, using the magic numbers like 4 or 16 for kind numbers is an ugly code smell and will only work for certain (even if the most widespread) compilers. See https://stackoverflow.com/questions/3170239/fortran-integer4-vs-integer4-vs-integerkind-4 Just use named constants and initialize them to 4 and 16 if you really want these values. – Vladimir F Героям слава Jul 31 '22 at 12:59

1 Answers1

1

The answer to your question is to use the INT intrinsic with the KIND specifier you want, for example, INT(Z'FFFFFFFF',KIND(allones)). This is standard-conforming, the usage you show is not in Fortran 2018 and what it means can vary by implementation.

The assignment you show WILL be valid in Fortran 2023 and the BOZ constant will be interpreted the same as the INT expression I show above. For a lot more on this, see my post Doctor Fortran in “We’re All BOZos on This Bus”

Steve Lionel
  • 6,972
  • 18
  • 31