Unidata / netcdf-fortran

Official GitHub repository for netCDF-Fortran libraries, which depend on the netCDF C library. Install the netCDF C library first.
Other
244 stars 98 forks source link

argument TKR mismatches between nf90_ usage and nf_ interface #417

Closed rwirth closed 10 months ago

rwirth commented 1 year ago

In NetCDF-fortran 4.5.3, there are 4 functions that are used with scalar arguments from the nf90_ functions, but are defined as assumed-size arrays in netcdf4_nf_interfaces or have a completely different data type. When compiling any file that indirectly references -- through any number of intermediate modules -- both the netcdf and netcdf4_nf_interfaces module, the NAG Fortran compiler (Version 7.1) detects this mismatch and throws an error:

Error: file.f90: Reference to NF_INQ_COMPOUND_FIELDDIM_SIZES from NETCDF inconsistent with INTERFACE in NETCDF4_NF_INTERFACES --
       Argument DIM_SIZES (no. 4) is not an array
Error: file.f90: Reference to NF_INSERT_ARRAY_COMPOUND from NETCDF inconsistent with INTERFACE in NETCDF4_NF_INTERFACES --
       Argument DIM_SIZES (no. 7) is not an array
Error: file.f90: Reference to NF_INQ_ENUM_IDENT from NETCDF inconsistent with INTERFACE in NETCDF4_NF_INTERFACES --
       Argument NAME (no. 4) has the wrong data type
Error: file.f90: Reference to NF_INQ_COMPOUND_FIELD from NETCDF inconsistent with INTERFACE in NETCDF4_NF_INTERFACES --
       Argument DIM_SIZES (no. 8) is not an array

My project is large and uses both interfaces to handle NetCDF files, so refactoring out one of the interfaces is not an option. Unfortunately, there seems to be no way in NAG Fortran to downgrade that error to a warning; I've tried -wmismatch without effect. Maybe disabling argument type checking altogether would help. I'd like to avoid that if possible, though.

WardF commented 1 year ago

Out of curiosity, are you able to check netCDF-Fortran 4.6.0? I do not have immediate access to the NAG Fortran compiler. I will look into the NAG documentation to see if I can figure out a solution, but in the meantime, I wonder if the refactoring we did in v4.6.0 will resolve this.

rwirth commented 1 year ago

I've compiled the library and put a use netcdf4_nf_interfaces into nf03_test4/f90tst_nc4.F90 to provoke the error. The error persists (though it is a warning here because -mismatch_all is given to make the tests compile, disabling all argument TKR checking).

Warning: ../../netcdf-fortran/nf03_test4/f90tst_nc4.F90: Reference to NF_INQ_COMPOUND_FIELDDIM_SIZES from NETCDF inconsistent with INTERFACE in NETCDF4_NF_INTERFACES --
         Argument DIM_SIZES (no. 4) is not an array
Warning: ../../netcdf-fortran/nf03_test4/f90tst_nc4.F90: Reference to NF_INSERT_ARRAY_COMPOUND from NETCDF inconsistent with INTERFACE in NETCDF4_NF_INTERFACES --
         Argument DIM_SIZES (no. 7) is not an array
Warning: ../../netcdf-fortran/nf03_test4/f90tst_nc4.F90: Reference to NF_INQ_ENUM_IDENT from NETCDF inconsistent with INTERFACE in NETCDF4_NF_INTERFACES --
         Argument NAME (no. 4) has the wrong data type
Warning: ../../netcdf-fortran/nf03_test4/f90tst_nc4.F90: Reference to NF_INQ_COMPOUND_FIELD from NETCDF inconsistent with INTERFACE in NETCDF4_NF_INTERFACES --
         Argument DIM_SIZES (no. 8) is not an array

Looking at the current master, it seems that the errors are still there: nf90_inq_cmp_fielddim_sizes has an intent-out argument dim_sizes, which is associated with an assumed-size array in the call to nf_inq_compound_fielddim_sizes. Judging by the plurals, it should actually be some kind of array.

For nf90_inq_enum_ident, the last argument looks like it should be character(len=*), intent(out) :: identifier instead of an integer.