NASA-LIS / LISF

Land Information System Framework
Apache License 2.0
118 stars 157 forks source link

GFortran in debug mode flags calls to HDF-EOS2 gdrdfld function with inconsistent buffer types #1432

Open emkemp opened 1 year ago

emkemp commented 1 year ago

Bug Description

When compiling with gfortran in debug mode, syntax errors will be reported for subroutines that call the HDF-EOS2 'gdrdfld' function with inconsistent buffer types.

For example, in ldt/DAobs/GLASSlai/readGLASSlaiObs.F90, there are two calls to gdrdfld for AVHRR and MODIS data (depending on user settings). The AVHRR buffer array is of type integer2, but for MODIS it is of type integer1.

gdrdfld is implemented in C, and is specified to treat the buffer argument as a void pointer (e.g., type is ignored). So this is not illegal per se. However, if gfortran is being used to debug other code, the compiler will not compile this code.

A partial solution is to disable HDF-EOS2 when compiling. But a better solution is needed if the user actually needs that library.

A better solution would be to write simple customized wrapper functions to gdrdfld in Fortran 90 (with an interface block containing module procedure declarations), and call gdrdfld within those wrapper functions. If only a single gdrdfld call occurs in each wrapper function, then I don't expect gfortran to report a problem.

Steps to Replicate

Run the LDT configure script with a GNU module (e.g., lisf_7.5_gnu_11.2.0_impi_2021.4.0), select Optimization level -2 (strict checks), and select use HDFEOS. Then compile LDT.

emkemp commented 4 months ago

Still TODO.

ShangyongShi commented 2 weeks ago

I am currently compiling LISF 7.5.1 and I came across the same problem about gdrdfld. I checked the codes that used gdrdfld using

grep -rnw '/path/LISF/' -e 'gdrdfld'

and found that same problem exist in these codes:

image

I checked the /ldt/make/Makefile and found the following lines:

ifeq ($(LIS_ARCH),linux_gfortran)
# For MPI
LDT_historyMod.o: LDT_historyMod.F90
        $(FC) $(FFLAGS) -fallow-argument-mismatch $(HEADER_DIRS) $<
# For HDF-EOS2
readGLASSlaiObs.o: readGLASSlaiObs.F90
        $(FC) $(FFLAGS) -fallow-argument-mismatch $(HEADER_DIRS) $<
readNASA_AMSREsmObs.o: readNASA_AMSREsmObs.F90
        $(FC) $(FFLAGS) -fallow-argument-mismatch $(HEADER_DIRS) $<
endif

This is when I found that my LIS_ARCH was set to linux_ifc. After changing it to LIS_ARCH=linux_gfortran, the mismatch in types can be ignored by gfortran. Hope this could provide some hints.