NOAA-EMC / wgrib2

Provides functionality for interacting with, reading, writing, and manipulating GRIB2 files.
12 stars 8 forks source link

Failing to compile on raspberry pi 5 - fortran type mismatch #88

Closed stackjohn closed 5 months ago

stackjohn commented 5 months ago

Hello!

I'm trying to compile this on a raspberry pi 5, but I'm getting the following:

cd "/home/someuser/Development/wgrib2/ip2lib_d" && export FFLAGS="-c -O3 -ffast-math  -fallow-argument-mismatch -MP" && export FTN_REAL8="-fdefault-real-8"  && make && cp libip2_d.a /home/someuser/Development/wgrib2/lib/libip2_d.a
make[1]: Entering directory '/home/someuser/Development/wgrib2/ip2lib_d'
gfortran -c -O3 -ffast-math  -fallow-argument-mismatch -MP -fdefault-real-8 -cpp -DLSIZE=8 gdswzd_c.F90
gdswzd_c.F90:233:48:

  233 |              CROT,SROT,XLON,XLAT,YLON,YLAT,AREA)
      |                                                1
Error: Type mismatch in argument ‘fill’ at (1); passed REAL(8) to REAL(4)
gdswzd_c.F90:233:48:

  233 |              CROT,SROT,XLON,XLAT,YLON,YLAT,AREA)
      |                                                1
Error: Type mismatch in argument ‘xpts’ at (1); passed REAL(8) to REAL(4)
gdswzd_c.F90:233:48:

  233 |              CROT,SROT,XLON,XLAT,YLON,YLAT,AREA)
      |                                                1
Error: Type mismatch in argument ‘ypts’ at (1); passed REAL(8) to REAL(4)
gdswzd_c.F90:233:48:

  233 |              CROT,SROT,XLON,XLAT,YLON,YLAT,AREA)
      |                                                1
Error: Type mismatch in argument ‘rlon’ at (1); passed REAL(8) to REAL(4)
gdswzd_c.F90:233:48:

  233 |              CROT,SROT,XLON,XLAT,YLON,YLAT,AREA)
      |                                                1
Error: Type mismatch in argument ‘rlat’ at (1); passed REAL(8) to REAL(4)
gdswzd_c.F90:233:48:

  233 |              CROT,SROT,XLON,XLAT,YLON,YLAT,AREA)
      |                                                1
Error: Type mismatch in argument ‘crot’ at (1); passed REAL(8) to REAL(4)
gdswzd_c.F90:233:48:

  233 |              CROT,SROT,XLON,XLAT,YLON,YLAT,AREA)
      |                                                1
Error: Type mismatch in argument ‘srot’ at (1); passed REAL(8) to REAL(4)
gdswzd_c.F90:233:48:

  233 |              CROT,SROT,XLON,XLAT,YLON,YLAT,AREA)
      |                                                1
Error: Type mismatch in argument ‘xlon’ at (1); passed REAL(8) to REAL(4)
gdswzd_c.F90:233:48:

  233 |              CROT,SROT,XLON,XLAT,YLON,YLAT,AREA)
      |                                                1
Error: Type mismatch in argument ‘xlat’ at (1); passed REAL(8) to REAL(4)
gdswzd_c.F90:233:48:

  233 |              CROT,SROT,XLON,XLAT,YLON,YLAT,AREA)
      |                                                1
Error: Type mismatch in argument ‘ylon’ at (1); passed REAL(8) to REAL(4)
gdswzd_c.F90:233:48:

  233 |              CROT,SROT,XLON,XLAT,YLON,YLAT,AREA)
      |                                                1
Error: Type mismatch in argument ‘ylat’ at (1); passed REAL(8) to REAL(4)
gdswzd_c.F90:233:48:

  233 |              CROT,SROT,XLON,XLAT,YLON,YLAT,AREA)
      |                                                1
Error: Type mismatch in argument ‘area’ at (1); passed REAL(8) to REAL(4)
make[1]: *** [Makefile:28: gdswzd_c.o] Error 1
make[1]: Leaving directory '/home/someuser/Development/wgrib2/ip2lib_d'
make: *** [makefile:1081: /home/someuser/Development/wgrib2/lib/libip2_d.a] Error 2
gcc --version
gcc (Debian 12.2.0-14) 12.2.0
Copyright (C) 2022 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

makefile contains:

COMP_SYS=clang_linux
export CC=gcc
export FC=gfortran

USE_NETCDF3=0
USE_NETCDF4=1
USE_PNG=0
USE_JASPER=0

I've tried to make use of

FTN_REAL8:="-fdefault-real-8

But still the same issue. Is there a work around that someone knows of?

webisu commented 5 months ago

Looks like a compiler problem. FILL is defined as C_DOUBLE in the calling routine, and FILL is defined as REAL in gdswzd_mod.f90. However, REAL is defined as real*8 by the compiler option -fdefault-real-8 . Is C_DOUBLE not a 8 byte real on the ARM? Does -fdefault-real-8 not work? I use the CLANG from the AOCC build. Is this different from the clang for the ARM?

The routine gdswiz_c.F90 is not called by wgrib2, Change (whatever)/grib2/ip2lib_d/make.filelist from "FPP_FILES = gdswzd_c.F90" to "FPP_FILES =". Then you can build by "make clean; make" from the (whatever)/grib2 directory.

Wgrib2 is transitioning to the stock version of ip2lib_d which is maintained by the NCEPlibs group. (Wgrib2 took the stock version of ip2lib_d, added many parallelizations and were later added to the stock version. Since then, wgrib2 hasn't updated ip2lib_d.) After wgrib2 is using the stock version of ip2lib, this issue can be addressed by the NCEPlibs group.

stackjohn commented 5 months ago

@webisu thank you for coming back to me so quickly. I was eventually able to get -fdefault-real-8 to work, I had to run a make clean inside ip2lib_d for it to be picked up. But anyhow I eventually went down a few other rabbit holes with proj4 and ended up checking the makefile out and starting again to clean it up. Now it looks as follows:

diff --git a/makefile b/makefile
index 1ec5699..6e4f820 100644
--- a/makefile
+++ b/makefile
@@ -133,7 +133,7 @@
 # export FC=xlf_r
 #
 # for AOCC (AMD Optimizing C Compiler, version of clang)
-# export CC=clang
+ export CC=clang
 # export FC=flang
 # export COMP_SYS=clang_linux
 #
@@ -151,8 +151,8 @@
 #
 # Main development platform: linux with gcc/gfortran
 #
-# export CC=gcc
-# export FC=gfortran
+export CC=gcc
+export FC=gfortran
 #
 SHELL=/bin/sh
 # SHELL=/bin/ksh
@@ -164,9 +164,9 @@ SHELL=/bin/sh
 # if USE_NETCDF3=1, then USE_NETCDF4 must 0
 #
 # USE_NETCDF3=0
-USE_NETCDF3=1
+USE_NETCDF3=0
 #
-USE_NETCDF4=0
+USE_NETCDF4=1
 # USE_NETCDF4=compile
 # USE_NETCDF4=system
 #USE_NETCDF4=${NETCDF_INCLUDES}:${NETCDF_LIBRARIES}
@@ -182,7 +182,7 @@ USE_IPOLATES=3
 USE_SPECTRAL=1
 USE_UDF=0
 USE_OPENMP=1
-USE_PROJ4=1
+USE_PROJ4=0
 USE_WMO_VALIDATION=0
 USE_NAMES=NCEP
 MAKE_FTN_API=1
@@ -192,7 +192,7 @@ MAKE_SHARED_LIB=0

 USE_G2CLIB=0
 USE_PNG=1
-USE_JASPER=1
+USE_JASPER=0
 USE_OPENJPEG=0
 USE_AEC=1

@@ -1038,7 +1038,7 @@ ${proj4lib}:
    gunzip -f tmpproj4.tar.gz
    tar -xvf tmpproj4.tar
    rm tmpproj4.tar
-   cd ${proj4dir}  && export CFLAGS="${wCPPFLAGS}" &&  ./configure --disable-shared --prefix=${cwd} && ${MAKE} -j 1 check install
+   cd ${proj4dir}  && export CFLAGS="${wCPPFLAGS}" &&  ./configure --build=aarch64-unknown-linux-gnu --disable-shared --prefix=${cwd} && ${MAKE} -j 1 check install

Perhaps this was the main fix:

 export CC=clang

Perhaps I had fiddled with that trying to get proj4 to compile, as it does not auto detect the arch correct so I added the --build=aarch64-unknown-linux-gnu above, and then it is able to compile. The issue then is the proj4 tests fail.

I eventually just disabled proj4 and got it all to compile, and wgrib2 seems to function fine for my needs without it.

All is working 🎉 Thanks again for responding, much appreciated!

webisu commented 5 months ago

The Proj4 option is having problems with some builds, and needs to be disabled in order to build wgrib2. This only affects determining the lat-lon of grid points for an aspherical equal-area Lambert projection. The build issues will be addressed by replacing Proj4 by Proj9.x.x. This is necessary for integrating wgrib2 with the EMC build framework.