Skip to content

Commit a561753

Browse files
committed
apply h5fortran fixes
1 parent 4f30e01 commit a561753

File tree

9 files changed

+76
-71
lines changed

9 files changed

+76
-71
lines changed

.gitignore

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1 @@
1-
build*/
2-
*.h5
31
CMakeUserPresets.json
4-
*.png
5-
*.eps
6-
data/
7-
8-
# Prerequisites
9-
*.d
10-
11-
# Compiled Object files
12-
*.slo
13-
*.lo
14-
*.o
15-
*.obj
16-
17-
# Precompiled Headers
18-
*.gch
19-
*.pch
20-
21-
# Compiled Dynamic libraries
22-
*.so
23-
*.dylib
24-
*.dll
25-
26-
# Fortran module files
27-
*.mod
28-
*.smod
29-
30-
# Compiled Static libraries
31-
*.lai
32-
*.la
33-
*.a
34-
*.lib
35-
36-
# Executables
37-
*.exe
38-
*.out
39-
*.app

cmake/compilers.cmake

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# check C and Fortran compiler ABI compatibility
22

33
if(NOT abi_ok)
4-
message(CHECK_START "checking that C and Fortran compilers can link")
4+
message(CHECK_START "checking that compilers can link together")
55
try_compile(abi_ok
66
${CMAKE_CURRENT_BINARY_DIR}/abi_check ${CMAKE_CURRENT_LIST_DIR}/abi_check
77
abi_check
@@ -10,30 +10,58 @@ if(NOT abi_ok)
1010
if(abi_ok)
1111
message(CHECK_PASS "OK")
1212
else()
13+
set(err_log ${CMAKE_CURRENT_BINARY_DIR}/abi_check/CMakeError.log)
1314
message(FATAL_ERROR "ABI-incompatible compilers:
1415
C compiler ${CMAKE_C_COMPILER_ID} ${CMAKE_C_COMPILER_VERSION}
1516
Fortran compiler ${CMAKE_Fortran_COMPILER_ID} ${CMAKE_Fortran_COMPILER_VERSION}
16-
${abi_log}
17+
For logged errors see ${err_log}
1718
"
1819
)
20+
file(WRITE ${err_log} ${abi_log})
1921
endif()
2022
endif()
2123

22-
# --- compiler options
23-
# we left off "-std=f2018" type flags as they tend to issue false warnings
24+
# --- C compile flags
25+
if(CMAKE_C_COMPILER_ID MATCHES "Clang|GNU|^Intel")
26+
add_compile_options(
27+
"$<$<AND:$<COMPILE_LANGUAGE:C>,$<CONFIG:Debug>>:-Wextra>"
28+
"$<$<COMPILE_LANGUAGE:C>:-Wall>"
29+
"$<$<COMPILE_LANGUAGE:C>:-Werror=implicit-function-declaration>"
30+
)
31+
elseif(CMAKE_C_COMPILER_ID MATCHES "MSVC")
32+
add_compile_options("$<$<COMPILE_LANGUAGE:C>:/W3>")
33+
endif()
2434

35+
if(WIN32)
36+
if(CMAKE_C_COMPILER_ID MATCHES "^Intel|MSVC")
37+
add_compile_options($<$<AND:$<COMPILE_LANGUAGE:C>,$<CONFIG:Debug>>:/Od>)
38+
endif()
39+
elseif(CMAKE_C_COMPILER_ID MATCHES "^Intel")
40+
add_compile_options($<$<AND:$<COMPILE_LANGUAGE:C>,$<CONFIG:Debug>>:-O0>)
41+
endif()
42+
43+
# --- Fortran compile flags
2544
if(CMAKE_Fortran_COMPILER_ID MATCHES "^Intel")
45+
2646
add_compile_options(
2747
"$<$<COMPILE_LANGUAGE:Fortran>:-warn>"
2848
"$<$<AND:$<COMPILE_LANGUAGE:Fortran>,$<CONFIG:Debug>>:-traceback;-check;-debug>"
2949
)
50+
51+
if(WIN32)
52+
add_compile_options($<$<AND:$<COMPILE_LANGUAGE:Fortran>,$<CONFIG:Debug>>:/Od>)
53+
else()
54+
add_compile_options($<$<AND:$<COMPILE_LANGUAGE:Fortran>,$<CONFIG:Debug>>:-O0>)
55+
endif()
56+
3057
elseif(CMAKE_Fortran_COMPILER_ID STREQUAL "GNU")
31-
add_compile_options(-Wall
32-
$<$<COMPILE_LANGUAGE:Fortran>:-fimplicit-none>
58+
59+
add_compile_options(
60+
"$<$<COMPILE_LANGUAGE:Fortran>:-Wall;-fimplicit-none;-Wno-maybe-uninitialized>"
3361
"$<$<AND:$<COMPILE_LANGUAGE:Fortran>,$<CONFIG:Debug>>:-Wextra;-fcheck=all;-Werror=array-bounds>"
34-
"$<$<AND:$<COMPILE_LANGUAGE:Fortran>,$<CONFIG:Release>>:-fno-backtrace;-Wno-maybe-uninitialized>"
35-
"$<$<AND:$<COMPILE_LANGUAGE:Fortran>,$<CONFIG:RelWithDebInfo>>:-Wno-maybe-uninitialized>"
62+
"$<$<AND:$<COMPILE_LANGUAGE:Fortran>,$<CONFIG:Release>>:-fno-backtrace>"
3663
)
64+
3765
endif()
3866

3967
# --- code coverage
@@ -42,3 +70,10 @@ if(coverage)
4270
append_coverage_compiler_flags()
4371
set(COVERAGE_EXCLUDES ${PROJECT_SOURCE_DIR}/test)
4472
endif()
73+
74+
# --- clang-tidy
75+
if(tidy)
76+
find_program(CLANG_TIDY_EXE NAMES "clang-tidy" REQUIRED)
77+
set(CMAKE_C_CLANG_TIDY ${CLANG_TIDY_EXE})
78+
set(CMAKE_CXX_CLANG_TIDY ${CLANG_TIDY_EXE})
79+
endif()

cmake/install.cmake

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
include(CMakePackageConfigHelpers)
44

55
configure_package_config_file(${CMAKE_CURRENT_LIST_DIR}/config.cmake.in
6-
${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${PROJECT_NAME}Config.cmake
6+
${CMAKE_CURRENT_BINARY_DIR}/cmake/${PROJECT_NAME}Config.cmake
77
INSTALL_DESTINATION cmake
88
)
99

1010
write_basic_package_version_file(
11-
${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${PROJECT_NAME}ConfigVersion.cmake
11+
${CMAKE_CURRENT_BINARY_DIR}/cmake/${PROJECT_NAME}ConfigVersion.cmake
1212
COMPATIBILITY SameMajorVersion
1313
)
1414

@@ -18,8 +18,8 @@ DESTINATION cmake
1818
)
1919

2020
install(FILES
21-
${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${PROJECT_NAME}Config.cmake
22-
${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${PROJECT_NAME}ConfigVersion.cmake
21+
${CMAKE_CURRENT_BINARY_DIR}/cmake/${PROJECT_NAME}Config.cmake
22+
${CMAKE_CURRENT_BINARY_DIR}/cmake/${PROJECT_NAME}ConfigVersion.cmake
2323
DESTINATION cmake
2424
)
2525

cmake/options.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ message(STATUS "${PROJECT_NAME} ${PROJECT_VERSION} CMake ${CMAKE_VERSION}")
44

55
option(benchmark "Run benchmarks")
66
option(coverage "Code coverage tests")
7+
option(tidy "Run clang-tidy on the code")
8+
79
option(hdf5_parallel "use HDF5-MPI layer" true)
810

911
set(CMAKE_TLS_VERIFY true)

src/interface.f90

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,7 @@ module subroutine h5close(self, close_hdf5_interface)
690690
!! close_hdf5_interface is when you know you have exactly one HDF5 file in your
691691
!! application, if true it closes ALL files, even those invoked directly from HDF5.
692692

693-
class(hdf5_file), intent(in) :: self
693+
class(hdf5_file), intent(inout) :: self
694694
logical, intent(in), optional :: close_hdf5_interface
695695
end subroutine
696696

@@ -704,7 +704,7 @@ module logical function has_parallel_compression()
704704

705705
module subroutine destructor(self)
706706
!! Close file and handle if user forgets to do so
707-
type(hdf5_file), intent(in) :: self
707+
type(hdf5_file), intent(inout) :: self
708708
end subroutine
709709

710710
module function hdf5version() result(v)

src/read_ascii.f90

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ subroutine open_char(self, obj_name, obj_id, space_id, charlen, obj_type, type_i
2828

2929
integer :: drank, ier
3030
integer(HSIZE_T), dimension(size(dims)) :: maxdims
31-
31+
integer(SIZE_T) :: ds_size
3232

3333
call H5Iget_type_f(obj_id, obj_type, ier)
3434
if(ier /= 0) error stop "ERROR:h5fortran:read:H5Iget_type: " // obj_name // " " // self%filename
@@ -54,13 +54,15 @@ subroutine open_char(self, obj_name, obj_id, space_id, charlen, obj_type, type_i
5454
endif
5555
if(ier/=0) error stop "ERROR:h5fortran:read:H5Tget_storage_size " // obj_name // " " // self%filename
5656
else
57-
call H5Tget_size_f(type_id, dsize, ier)
57+
call H5Tget_size_f(type_id, ds_size, ier)
5858
if(ier/=0) error stop "ERROR:h5fortran:read:H5Tget_size " // obj_name // " " // self%filename
5959

60-
if(dsize > charlen) then
61-
write(stderr,'(a,i0,a3,i0,1x,a)') "ERROR:h5fortran:read: buffer too small: ", dsize, " > ", charlen, obj_name
60+
if(ds_size > charlen) then
61+
write(stderr,'(a,i0,a3,i0,1x,a)') "ERROR:h5fortran:read: buffer too small: ", ds_size, " > ", charlen, obj_name
6262
error stop
6363
endif
64+
65+
dsize = int(ds_size, HSIZE_T)
6466
endif
6567

6668

src/utils.f90

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737

3838
module procedure h5open
3939

40-
character(:), allocatable :: laction
40+
character(2) :: laction
4141
integer :: ier
4242
integer(HID_T) :: fapl !< file access property list
4343
integer :: file_mode
@@ -181,12 +181,14 @@
181181

182182

183183
!> close hdf5 file
184-
call h5fclose_f(self%file_id, ierr)
184+
call H5Fclose_f(self%file_id, ierr)
185185
if (ierr /= 0) then
186-
write(stderr,'(a,i0)') 'ERROR:h5fortran:h5fclose: HDF5 file close: ' // self%filename // ' mpi_id: ', self%mpi_id
186+
write(stderr,'(a,i0)') 'ERROR:h5fortran:H5Fclose: HDF5 file close: ' // self%filename // ' mpi_id: ', self%mpi_id
187187
error stop
188188
endif
189189

190+
deallocate(self%filename)
191+
190192
if (present(close_hdf5_interface)) then
191193
if (close_hdf5_interface) then
192194
call h5close_f(ierr)

src/write_scalar.f90

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111

1212
integer(HSIZE_T) :: dset_dims(0), mem_dims(0)
1313
integer(HID_T) :: file_space_id, dset_id, dtype_id, xfer_id, dtype
14-
integer :: ier, L
14+
integer :: ier, charlen
15+
16+
charlen = 0
1517

1618
select type (A)
1719
type is (real(real32))
@@ -24,14 +26,14 @@
2426
dtype = H5T_STD_I64LE
2527
type is (character(*))
2628
dtype = H5T_NATIVE_CHARACTER
27-
L = len(A) !< workaround for GCC 8.3.0 bug
29+
charlen = len(A) !< workaround for GCC 8.3.0 bug
2830
class default
2931
error stop "ERROR:h5fortran:write: unknown variable type for " // dname
3032
end select
3133

3234
call hdf_create(self, dname, dtype, mem_dims=mem_dims, dset_dims=dset_dims, &
3335
filespace_id=file_space_id, dset_id=dset_id, compact=compact, dtype_id=dtype_id, &
34-
charlen=L)
36+
charlen=charlen)
3537

3638
xfer_id = mpi_collective(dname, self%use_mpi)
3739

@@ -58,13 +60,13 @@
5860
class default
5961
error stop "ERROR:h5fortran:write: unsupported type for " // dname
6062
end select
61-
if (ier /= 0) error stop 'ERROR:h5fortran:write: could not write ' // dname // ' to ' // self%filename
63+
if (ier /= 0) error stop 'ERROR:h5fortran:write:H5Dwrite ' // dname // ' to ' // self%filename
6264

6365
call H5Dclose_f(dset_id, ier)
64-
if(ier /= 0) error stop "ERROR:h5fortran:writer: closing dataset: " // dname // " in " // self%filename
66+
if(ier /= 0) error stop "ERROR:h5fortran:writer:H5Dclose: " // dname // " " // self%filename
6567

66-
call h5sclose_f(file_space_id, ier)
67-
if(ier /= 0) error stop "ERROR:h5fortran:writer closing file dataspace: " // dname // " in " // self%filename
68+
call H5Sclose_f(file_space_id, ier)
69+
if(ier /= 0) error stop "ERROR:h5fortran:writer:H5Sclose file: " // dname // " " // self%filename
6870

6971
if(self%use_mpi) call h5pclose_f(xfer_id, ier)
7072
if(ier /= 0) error stop "ERROR:h5fortran:writer closing property: " // dname // " in " // self%filename

src/writer.inc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ type is (integer(int32))
2525
type is (integer(int64))
2626
dtype = H5T_STD_I64LE
2727
type is (character(*))
28-
charlen = len(A)
2928
dtype = H5T_NATIVE_CHARACTER
29+
charlen = len(A) !< workaround for GCC 8.3.0 bug
3030
class default
3131
error stop "ERROR:h5fortran:writer:unknown variable type for " // dname
3232
end select
@@ -70,15 +70,15 @@ type is (character(*))
7070
class default
7171
error stop "ERROR:h5fortran:writer: unknown variable type for " // dname
7272
end select
73-
if (ier /= 0) error stop 'ERROR:h5fortran:h5dwrite: could not write ' // dname // ' to ' // self%filename
73+
if (ier /= 0) error stop 'ERROR:h5fortran:write:H5Dwrite: could not write ' // dname // ' ' // self%filename
7474

7575
call h5dclose_f(dset_id, ier)
7676
if(ier /= 0) error stop "ERROR:h5fortran:writer: closing dataset: " // dname // " in " // self%filename
7777

78-
if(mem_space_id /= H5S_ALL_F) call h5sclose_f(mem_space_id, ier)
79-
if(ier /= 0) error stop "ERROR:h5fortran:writer closing memory dataspace: " // dname // " in " // self%filename
78+
if(mem_space_id /= H5S_ALL_F) call H5Sclose_f(mem_space_id, ier)
79+
if(ier /= 0) error stop "ERROR:h5fortran:writer:H5Sclose memory: " // dname // " in " // self%filename
8080

81-
call h5sclose_f(file_space_id, ier)
81+
call H5Sclose_f(file_space_id, ier)
8282
if(ier /= 0) error stop "ERROR:h5fortran:writer closing file dataspace: " // dname // " in " // self%filename
8383

8484
if(self%use_mpi) call h5pclose_f(xfer_id, ier)

0 commit comments

Comments
 (0)