Skip to content

Commit

Permalink
Merge pull request NOAA-EMC#188 from AlexanderRichert-NOAA/cmake_upda…
Browse files Browse the repository at this point in the history
…te_aug2023

Reorganize compiler flags & update code to eliminate warnings
  • Loading branch information
AlexanderRichert-NOAA authored Aug 26, 2023
2 parents 3f21382 + 58c7020 commit dac7990
Show file tree
Hide file tree
Showing 12 changed files with 63 additions and 45 deletions.
17 changes: 16 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ include(GNUInstallDirs)

# Handle user options.
option(ENABLE_DOCS "Enable generation of doxygen-based documentation." OFF)
option(OPENMP "use OpenMP threading" OFF)
option(OPENMP "Use OpenMP threading" OFF)
option(BUILD_SHARED_LIBS "Build shared libraries" OFF)
option(BUILD_4 "Build the 4-byte real version of the library, libip_4.a" ON)
option(BUILD_D "Build the 8-byte real version of the library, libip_d.a" ON)
Expand Down Expand Up @@ -46,6 +46,21 @@ endif()
# We need the NCEPLIBS-sp library.
find_package(sp 2.3.0 REQUIRED)

# Set compiler flags.
if(CMAKE_Fortran_COMPILER_ID MATCHES "^(Intel|IntelLLVM)$")
set(CMAKE_Fortran_FLAGS "-g -traceback -assume byterecl -fp-model strict -fpp -auto ${CMAKE_Fortran_FLAGS}")
set(CMAKE_Fortran_FLAGS_DEBUG "-O0 -check all -warn all")
if(CMAKE_Fortran_COMPILER_ID MATCHES "^(IntelLLVM)$")
# Avoid Intel OneAPI 2023.2.1 bug
set(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG} -check nouninit ")
endif()
set(fortran_d_flags "-r8")
elseif(CMAKE_Fortran_COMPILER_ID MATCHES "^(GNU)$")
set(CMAKE_Fortran_FLAGS "-g -fbacktrace -cpp -fimplicit-none ${CMAKE_Fortran_FLAGS}")
set(CMAKE_Fortran_FLAGS_DEBUG "-O0 -ggdb -Wall -Wno-unused-dummy-argument -Wsurprising -Wextra -fcheck=all")
set(fortran_d_flags "-fdefault-real-8")
endif()

# This is the source code directiroy.
add_subdirectory(src)

Expand Down
2 changes: 1 addition & 1 deletion docs/Doxyfile.in
Original file line number Diff line number Diff line change
Expand Up @@ -929,7 +929,7 @@ EXCLUDE_PATTERNS =
# Note that the wildcards are matched against the file with absolute path, so to
# exclude all test directories use the pattern */test/*

EXCLUDE_SYMBOLS =
EXCLUDE_SYMBOLS = tinyreal

# The EXAMPLE_PATH tag can be used to specify one or more files or directories
# that contain example code fragments that are included (see the \include
Expand Down
11 changes: 0 additions & 11 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,6 @@ ip_rot_equid_cylind_egrid_mod.F90 ip_rot_equid_cylind_grid_mod.F90
constants_mod.F90 ip_grids_mod.F90 ip_grid_factory_mod.F90
ip_interpolators_mod.F90 earth_radius_mod.F90 polfix_mod.F90)

# Set compiler flags.
if(CMAKE_Fortran_COMPILER_ID MATCHES "^(Intel|IntelLLVM)$")
set(CMAKE_Fortran_FLAGS "-g -traceback -warn all -auto -convert big_endian -assume byterecl -fp-model strict -fpp ${CMAKE_Fortran_FLAGS}")
set(CMAKE_Fortran_FLAGS_DEBUG "-O0 -check all -warn all")
set(fortran_d_flags "-r8")
elseif(CMAKE_Fortran_COMPILER_ID MATCHES "^(GNU)$")
set(CMAKE_Fortran_FLAGS "-g -fbacktrace -fconvert=big-endian -cpp ${CMAKE_Fortran_FLAGS}")
set(CMAKE_Fortran_FLAGS_DEBUG "-O0 -ggdb -Wall -fcheck=all")
set(fortran_d_flags "-fdefault-real-8")
endif()

# We build a version of the library with 4-byte reals (_4), and one
# with 8-byte reals (_d).
foreach(kind ${kinds})
Expand Down
7 changes: 5 additions & 2 deletions src/bicubic_interp_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ module bicubic_interp_mod
module procedure interpolate_bicubic_vector
end interface interpolate_bicubic

! Smallest positive real value (use for equality comparisons)
REAL :: TINYREAL=TINY(1.0)

contains

!> This subprogram performs bicubic interpolation
Expand Down Expand Up @@ -174,7 +177,7 @@ SUBROUTINE interpolate_bicubic_scalar(IPOPT,grid_in,grid_out, &
RLATX(N)=RLAT(N)
XIJ=XPTS(N)
YIJ=YPTS(N)
IF(XIJ.NE.FILL.AND.YIJ.NE.FILL) THEN
IF(ABS(XIJ-FILL).GT.TINYREAL.AND.ABS(YIJ-FILL).GT.TINYREAL) THEN
IJX(1:4)=FLOOR(XIJ-1)+(/0,1,2,3/)
IJY(1:4)=FLOOR(YIJ-1)+(/0,1,2,3/)
XF=XIJ-IJX(2)
Expand Down Expand Up @@ -439,7 +442,7 @@ subroutine interpolate_bicubic_vector(ipopt, grid_in, grid_out, &
SROTX(N)=SROT(N)
XIJ=XPTS(N)
YIJ=YPTS(N)
IF(XIJ.NE.FILL.AND.YIJ.NE.FILL) THEN
IF(ABS(XIJ-FILL).GT.TINYREAL.AND.ABS(YIJ-FILL).GT.TINYREAL) THEN
IJX(1:4)=FLOOR(XIJ-1)+(/0,1,2,3/)
IJY(1:4)=FLOOR(YIJ-1)+(/0,1,2,3/)
XF=XIJ-IJX(2)
Expand Down
9 changes: 6 additions & 3 deletions src/bilinear_interp_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ module bilinear_interp_mod
module procedure interpolate_bilinear_vector
end interface interpolate_bilinear

! Smallest positive real value (use for equality comparisons)
REAL :: TINYREAL=TINY(1.0)

contains

!> This subprogram performs bilinear interpolation
Expand Down Expand Up @@ -165,7 +168,7 @@ subroutine interpolate_bilinear_scalar(IPOPT,grid_in,grid_out,MI,MO,KM,IBI,LI,GI
RLATX(N)=RLAT(N)
XIJ=XPTS(N)
YIJ=YPTS(N)
IF(XIJ.NE.FILL.AND.YIJ.NE.FILL) THEN
IF(ABS(XIJ-FILL).GT.TINYREAL.AND.ABS(YIJ-FILL).GT.TINYREAL) THEN
IJX(1:2)=FLOOR(XIJ)+(/0,1/)
IJY(1:2)=FLOOR(YIJ)+(/0,1/)
XF=XIJ-IJX(1)
Expand Down Expand Up @@ -217,7 +220,7 @@ subroutine interpolate_bilinear_scalar(IPOPT,grid_in,grid_out,MI,MO,KM,IBI,LI,GI
LO(N,K)=W.GE.PMP
IF(LO(N,K)) THEN
GO(N,K)=G/W
ELSEIF(MSPIRAL.GT.0.AND.XPTS(N).NE.FILL.AND.YPTS(N).NE.FILL) THEN
ELSEIF(MSPIRAL.GT.0.AND.ABS(XPTS(N)-FILL).GT.TINYREAL.AND.ABS(YPTS(N)-FILL).GT.TINYREAL) THEN
I1=NINT(XPTS(N))
J1=NINT(YPTS(N))
IXS=INT(SIGN(1.,XPTS(N)-I1))
Expand Down Expand Up @@ -429,7 +432,7 @@ SUBROUTINE interpolate_bilinear_vector(ipopt,grid_in,grid_out, &
SROTX(N)=SROT(N)
XIJ=XPTS(N)
YIJ=YPTS(N)
IF(XIJ.NE.FILL.AND.YIJ.NE.FILL) THEN
IF(ABS(XIJ-FILL).GT.TINYREAL.AND.ABS(YIJ-FILL).GT.TINYREAL) THEN
IJX(1:2)=FLOOR(XIJ)+(/0,1/)
IJY(1:2)=FLOOR(YIJ)+(/0,1/)
XF=XIJ-IJX(1)
Expand Down
11 changes: 7 additions & 4 deletions src/budget_interp_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ module budget_interp_mod
module procedure interpolate_budget_vector
end interface interpolate_budget

! Smallest positive real value (use for equality comparisons)
REAL :: TINYREAL=TINY(1.0)

contains

!> Performs budget interpolation from any grid to any grid (or to
Expand Down Expand Up @@ -195,7 +198,7 @@ SUBROUTINE interpolate_budget_scalar(IPOPT,grid_in,grid_out, &
ELSEIF(LSW.EQ.1) THEN
WB=IPOPT(2+LB)
ENDIF
IF(WB.NE.0) THEN
IF(ABS(WB).GT.TINYREAL) THEN
!$OMP PARALLEL DO PRIVATE(N) SCHEDULE(STATIC)
DO N=1,NO
XPTB(N)=XPTS(N)+IB*RB2
Expand All @@ -214,7 +217,7 @@ SUBROUTINE interpolate_budget_scalar(IPOPT,grid_in,grid_out, &
DO N=1,NO
XI=XPTB(N)
YI=YPTB(N)
IF(XI.NE.FILL.AND.YI.NE.FILL) THEN
IF(ABS(XI-FILL).GT.TINYREAL.AND.ABS(YI-FILL).GT.TINYREAL) THEN
I1=INT(XI)
I2=I1+1
J1=INT(YI)
Expand Down Expand Up @@ -556,7 +559,7 @@ SUBROUTINE interpolate_budget_vector(IPOPT,grid_in,grid_out, &
ELSEIF(IPOPT(2).NE.-1) THEN
WB=IPOPT(2+LB)
ENDIF
IF(WB.NE.0) THEN
IF(ABS(WB).GT.TINYREAL) THEN
!$OMP PARALLEL DO PRIVATE(N) SCHEDULE(STATIC)
DO N=1,NO
XPTB(N)=XPTS(N)+IB*RB2
Expand All @@ -576,7 +579,7 @@ SUBROUTINE interpolate_budget_vector(IPOPT,grid_in,grid_out, &
DO N=1,NO
XI=XPTB(N)
YI=YPTB(N)
IF(XI.NE.FILL.AND.YI.NE.FILL) THEN
IF(ABS(XI-FILL).GT.TINYREAL.AND.ABS(YI-FILL).GT.TINYREAL) THEN
I1=INT(XI)
I2=I1+1
WI2=XI-I1
Expand Down
9 changes: 5 additions & 4 deletions src/ip_lambert_conf_grid_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ module ip_lambert_conf_grid_mod
REAL :: DYS !< y-direction grid length adjusted for scan model. GRIB2, Section 3, octets 60-63.
REAL :: H !< Hemisphere flag. 1-NH, minus 1-SH.
REAL :: RERTH !< Radius of the earth. GRIB2, Section 3, octets 15-30.
REAL :: TINYREAL=TINY(1.0) !< Smallest positive real value (use for equality comparisons)

contains

Expand Down Expand Up @@ -269,14 +270,14 @@ SUBROUTINE GDSWZD_LAMBERT_CONF(self,IOPT,NPTS,FILL, &

rerth = self%rerth

IF(RLATI1.EQ.RLATI2) THEN
IF(ABS(RLATI1-RLATI2).LT.TINYREAL) THEN
AN=SIN(RLATI1/DPR)
ELSE
AN=LOG(COS(RLATI1/DPR)/COS(RLATI2/DPR))/ &
LOG(TAN((90-RLATI1)/2/DPR)/TAN((90-RLATI2)/2/DPR))
ENDIF
DE=RERTH*COS(RLATI1/DPR)*TAN((RLATI1+90)/2/DPR)**AN/AN
IF(H*RLAT1.EQ.90) THEN
IF(ABS(H*RLAT1-90).LT.TINYREAL) THEN
XP=1
YP=1
ELSE
Expand Down Expand Up @@ -341,8 +342,8 @@ SUBROUTINE GDSWZD_LAMBERT_CONF(self,IOPT,NPTS,FILL, &
ELSEIF(IOPT.EQ.-1) THEN
!$OMP PARALLEL DO PRIVATE(N,DR,DLON) REDUCTION(+:NRET) SCHEDULE(STATIC)
DO N=1,NPTS
IF(ABS(RLON(N)).LE.360.AND.ABS(RLAT(N)).LE.90.AND. &
H*RLAT(N).NE.-90) THEN
IF(ABS(RLON(N)).LT.(360.+TINYREAL).AND.ABS(RLAT(N)).LT.(90.+TINYREAL).AND. &
ABS(H*RLAT(N)+90).GT.TINYREAL) THEN
DR=H*DE*TAN((90-RLAT(N))/2/DPR)**AN
DLON=MOD(RLON(N)-ORIENT+180+3600,360.)-180
XPTS(N)=XP+H*SIN(AN*DLON/DPR)*DR/DXS
Expand Down
11 changes: 6 additions & 5 deletions src/ip_polar_stereo_grid_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ module ip_polar_stereo_grid_mod
REAL :: RERTH !< Radius of the Earth.
REAL :: H !< Local copy of h.
REAL :: ORIENT !< Local copy of orient.
REAL :: TINYREAL=TINY(1.0) !< Smallest positive real value (use for equality comparisons)

CONTAINS

Expand Down Expand Up @@ -102,7 +103,7 @@ subroutine init_grib1(self, g1_desc)
HI=(-1.)**ISCAN
HJ=(-1.)**(1-JSCAN)

IF(self%H.EQ.-1)self%ORIENT=self%ORIENT+180.
IF(ABS(self%H+1.).LT.TINYREAL) self%ORIENT=self%ORIENT+180.

self%DXS=DX*HI
self%DYS=DY*HJ
Expand Down Expand Up @@ -405,8 +406,8 @@ SUBROUTINE GDSWZD_POLAR_STEREO(self,IOPT,NPTS, &
IF(.NOT.ELLIPTICAL)THEN
!$OMP PARALLEL DO PRIVATE(N,DR,DR2) REDUCTION(+:NRET) SCHEDULE(STATIC)
DO N=1,NPTS
IF(ABS(RLON(N)).LE.360.AND.ABS(RLAT(N)).LE.90.AND. &
H*RLAT(N).NE.-90) THEN
IF(ABS(RLON(N)).LT.(360.+TINYREAL).AND.ABS(RLAT(N)).LT.(90.+TINYREAL).AND. &
ABS(H*RLAT(N)+90).GT.TINYREAL) THEN
DR=DE*TAN((90-H*RLAT(N))/2/DPR)
DR2=DR**2
XPTS(N)=XP+H*SIN((RLON(N)-ORIENT)/DPR)*DR/DXS
Expand All @@ -431,8 +432,8 @@ SUBROUTINE GDSWZD_POLAR_STEREO(self,IOPT,NPTS, &
ELSE ! ELLIPTICAL CASE
!$OMP PARALLEL DO PRIVATE(N,ALAT,ALONG,T,RHO) REDUCTION(+:NRET) SCHEDULE(STATIC)
DO N=1,NPTS
IF(ABS(RLON(N)).LE.360.AND.ABS(RLAT(N)).LE.90.AND. &
H*RLAT(N).NE.-90) THEN
IF(ABS(RLON(N)).LT.(360+TINYREAL).AND.ABS(RLAT(N)).LT.(90+TINYREAL).AND. &
ABS(H*RLAT(N)+90).GT.TINYREAL) THEN
ALAT = H*RLAT(N)/DPR
ALONG = (RLON(N)-ORIENT)/DPR
T=TAN(PI4-ALAT*0.5)/((1.-E*SIN(ALAT))/ &
Expand Down
11 changes: 7 additions & 4 deletions src/neighbor_budget_interp_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ module neighbor_budget_interp_mod
module procedure interpolate_neighbor_budget_vector
end interface interpolate_neighbor_budget

! Smallest positive real value (use for equality comparisons)
REAL :: TINYREAL=TINY(1.0)

contains

!> Interpolate scalar fields (budget).
Expand Down Expand Up @@ -189,7 +192,7 @@ SUBROUTINE interpolate_neighbor_budget_scalar(IPOPT,grid_in,grid_out, &
LB=MAX(ABS(IB),ABS(JB))
WB=1
IF(LSW.EQ.1) WB=IPOPT(2+LB)
IF(WB.NE.0) THEN
IF(ABS(WB).GT.TINYREAL) THEN
DO N=1,NO
XPTB(N)=XPTS(N)+IB/REAL(NB2)
YPTB(N)=YPTS(N)+JB/REAL(NB2)
Expand All @@ -205,7 +208,7 @@ SUBROUTINE interpolate_neighbor_budget_scalar(IPOPT,grid_in,grid_out, &
DO N=1,NO
XI=XPTB(N)
YI=YPTB(N)
IF(XI.NE.FILL.AND.YI.NE.FILL) THEN
IF(ABS(XI-FILL).GT.TINYREAL.AND.ABS(YI-FILL).GT.TINYREAL) THEN
I1=NINT(XI)
J1=NINT(YI)
N11(N)=grid_in%field_pos(i1, j1)
Expand Down Expand Up @@ -470,7 +473,7 @@ SUBROUTINE interpolate_neighbor_budget_vector(IPOPT,grid_in,grid_out, &
LB=MAX(ABS(IB),ABS(JB))
WB=1
IF(LSW.EQ.1) WB=IPOPT(2+LB)
IF(WB.NE.0) THEN
IF(ABS(WB).GT.TINYREAL) THEN
DO N=1,NO
XPTB(N)=XPTS(N)+IB/REAL(NB2)
YPTB(N)=YPTS(N)+JB/REAL(NB2)
Expand All @@ -486,7 +489,7 @@ SUBROUTINE interpolate_neighbor_budget_vector(IPOPT,grid_in,grid_out, &
DO N=1,NO
XI=XPTB(N)
YI=YPTB(N)
IF(XI.NE.FILL.AND.YI.NE.FILL) THEN
IF(ABS(XI-FILL).GT.TINYREAL.AND.ABS(YI-FILL).GT.TINYREAL) THEN
I1=NINT(XI)
J1=NINT(YI)
N11(N)=grid_in%field_pos(i1, j1)
Expand Down
7 changes: 5 additions & 2 deletions src/neighbor_interp_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ module neighbor_interp_mod
module procedure interpolate_neighbor_vector
end interface interpolate_neighbor

! Smallest positive real value (use for equality comparisons)
REAL :: TINYREAL=TINY(1.0)

contains

!> Interpolate scalar fields (neighbor).
Expand Down Expand Up @@ -185,7 +188,7 @@ SUBROUTINE interpolate_neighbor_scalar(IPOPT,grid_in,grid_out, &
RLATX(N)=RLAT(N)
XPTSX(N)=XPTS(N)
YPTSX(N)=YPTS(N)
IF(XPTS(N).NE.FILL.AND.YPTS(N).NE.FILL) THEN
IF(ABS(XPTS(N)-FILL).GT.TINYREAL.AND.ABS(YPTS(N)-FILL).GT.TINYREAL) THEN
nxy(n) = grid_in%field_pos(NINT(XPTS(N)), NINT(YPTS(N)))
ELSE
NXY(N)=0
Expand Down Expand Up @@ -449,7 +452,7 @@ SUBROUTINE interpolate_neighbor_vector(IPOPT,grid_in,grid_out, &
YPTSX(N)=YPTS(N)
CROTX(N)=CROT(N)
SROTX(N)=SROT(N)
IF(XPTS(N).NE.FILL.AND.YPTS(N).NE.FILL) THEN
IF(ABS(XPTS(N)-FILL).GT.TINYREAL.AND.ABS(YPTS(N)-FILL).GT.TINYREAL) THEN
nxy(n) = grid_in%field_pos(NINT(XPTS(N)),NINT(YPTS(N)))
IF(NXY(N).GT.0) THEN
CALL MOVECT(RLAI(NXY(N)),RLOI(NXY(N)),RLAT(N),RLON(N),CM,SM)
Expand Down
11 changes: 4 additions & 7 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,13 @@ execute_process(COMMAND cmake -E create_symlink
"${CMAKE_CURRENT_BINARY_DIR}/data" # New name
)

# Set compiler flags for intel.
# Set compiler flags.
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${CMAKE_Fortran_FLAGS_DEBUG}")
if(CMAKE_Fortran_COMPILER_ID MATCHES "^(Intel|IntelLLVM)$")
set(CMAKE_Fortran_FLAGS "-r8 -g -check all -traceback -warn all -heap-arrays -assume byterecl ${CMAKE_Fortran_FLAGS} ")
if(CMAKE_Fortran_COMPILER_ID MATCHES "^(IntelLLVM)$")
# Avoid Intel OneAPI 2023.2.1 bug
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -check nouninit ")
endif()
set(CMAKE_Fortran_FLAGS "-r8 -heap-arrays ${CMAKE_Fortran_FLAGS}")
set(CMAKE_C_FLAGS "-std=c99")
elseif(CMAKE_Fortran_COMPILER_ID MATCHES "^(GNU)$")
set(CMAKE_Fortran_FLAGS "-fdefault-real-8 -fno-range-check -g -fbacktrace -fcheck=all -Wall -O0 -fimplicit-none -Wsurprising -Wextra ${CMAKE_Fortran_FLAGS} ")
set(CMAKE_Fortran_FLAGS "-fdefault-real-8 ${CMAKE_Fortran_FLAGS}")
endif()

# Set compiler flags for GNU.
Expand Down
2 changes: 1 addition & 1 deletion tests/input_data_mod_grib2.F90
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ module input_data_mod_grib2
integer, public :: input_gdtmpl(input_gdtlen)
integer, public :: vector_input_gdtmpl(input_gdtlen)

integer, parameter :: missing=4294967296
integer, parameter :: missing=huge(1)

real(KIND=REALSIZE), allocatable, public :: input_data(:,:)
real(KIND=REALSIZE), allocatable, public :: input_u_data(:,:)
Expand Down

0 comments on commit dac7990

Please sign in to comment.