Skip to content

Commit

Permalink
use c99 and cxx11 int32 type
Browse files Browse the repository at this point in the history
  • Loading branch information
scivision committed Aug 2, 2020
1 parent 99bd377 commit c192ead
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 20 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/ci_linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,12 @@ jobs:
sudo apt install -yq --no-install-recommends gfortran libhdf5-dev
- run: ctest -S setup.cmake -VV

- name: build examples
run: |
cmake -B Examples/build -S Examples
cmake --build Examples/build
- name: test examples
run: ctest -V
working-directory: Examples/build
9 changes: 9 additions & 0 deletions .github/workflows/ci_mac.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,12 @@ jobs:
env:
FC: gfortran-9
CC: gcc-9

- name: build examples
run: |
cmake -B Examples/build -S Examples
cmake --build Examples/build
- name: test examples
run: ctest -V
working-directory: Examples/build
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ if(NOT CMAKE_BUILD_TYPE)
endif()
project(h5fortran
LANGUAGES C Fortran
VERSION 2.11.2
VERSION 2.11.3
DESCRIPTION "thin, light object-oriented HDF5 Fortran interface"
HOMEPAGE_URL https://github.com/geospace-code/h5fortran)
enable_testing()
Expand Down
18 changes: 13 additions & 5 deletions Examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ include(FetchContent)

FetchContent_Declare(h5fortran_proj
GIT_REPOSITORY https://github.com/geospace-code/h5fortran.git
GIT_TAG v2.11.2
GIT_TAG v2.11.3
)

FetchContent_MakeAvailable(h5fortran_proj)
Expand All @@ -23,19 +23,27 @@ target_link_libraries(fortran_interface PRIVATE h5fortran::h5fortran)
# --- example 1
add_executable(example1 example1.f90)
target_link_libraries(example1 h5fortran::h5fortran)
add_test(NAME h5fortran:Example1 COMMAND $<TARGET_FILE:example1>)
add_test(NAME h5fortran:Example1 COMMAND $<TARGET_FILE:example1>
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})

# --- example 2
add_executable(example2 example2.f90)
target_link_libraries(example2 h5fortran::h5fortran)
add_test(NAME h5fortran:Example2 COMMAND $<TARGET_FILE:example2>)
add_test(NAME h5fortran:Example2 COMMAND $<TARGET_FILE:example2>
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})

# --- example 3
add_executable(example3 example3.c)
target_link_libraries(example3 fortran_interface)
add_test(NAME h5fortran:Example3 COMMAND $<TARGET_FILE:example3>)
target_compile_features(example3 PRIVATE c_std_99)
# https://en.cppreference.com/w/c/types/integer
add_test(NAME h5fortran:Example3 COMMAND $<TARGET_FILE:example3>
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})

# --- example 4
add_executable(example4 example4.cxx)
target_link_libraries(example4 fortran_interface)
add_test(NAME h5fortran:Example4 COMMAND $<TARGET_FILE:example4>)
target_compile_features(example3 PRIVATE cxx_std_11)
# https://en.cppreference.com/w/cpp/types/integer
add_test(NAME h5fortran:Example4 COMMAND $<TARGET_FILE:example4>
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
7 changes: 4 additions & 3 deletions Examples/example3.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#include <stdio.h>
#include <stdint.h>
#include "fortran_interface.h"



int main(void) {

long x = 321;
long y;
int_least32_t x = 321;
int_least32_t y;

char filename[256] = "h5fortran_example3.h5";

Expand All @@ -15,7 +16,7 @@ write_int32(filename, &x);
read_int32(filename, &y);

if (x != y) {
fprintf(stderr, "ERROR: read/write mismatch value. Expected %ld but got %ld", x, y);
fprintf(stderr, "ERROR: read/write mismatch value. Expected %d but got %d", x, y);
return 1;
}

Expand Down
5 changes: 3 additions & 2 deletions Examples/example4.cxx
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#include <iostream>
#include <cstdint>
#include "fortran_interface.hpp"



int main(void) {

long x = 321;
long y;
int_least32_t x = 321;
int_least32_t y;

char filename[256] = "h5fortran_example4.h5";

Expand Down
6 changes: 3 additions & 3 deletions Examples/fortran_interface.f90
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module fortran_interface

use, intrinsic :: iso_c_binding, only : C_LONG, C_CHAR, C_NULL_CHAR
use, intrinsic :: iso_c_binding, only : C_INT32_T, C_CHAR, C_NULL_CHAR
use h5fortran, only : h5write, h5read

implicit none (type, external)
Expand All @@ -10,7 +10,7 @@ module fortran_interface

subroutine write_int32(filename, i32) bind(C)
character(kind=C_CHAR) :: filename(256)
integer(C_LONG), intent(in) :: i32
integer(C_INT32_T), intent(in) :: i32

call h5write(cstr2fstr(filename), '/x', i32)

Expand All @@ -19,7 +19,7 @@ end subroutine write_int32

subroutine read_int32(filename, i32) bind(C)
character(kind=C_CHAR) :: filename(256)
integer(C_LONG), intent(out) :: i32
integer(C_INT32_T), intent(out) :: i32

call h5read(cstr2fstr(filename), '/x', i32)

Expand Down
4 changes: 2 additions & 2 deletions Examples/fortran_interface.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
extern void write_int32(char*, long*);
extern void write_int32(char*, int_least32_t*);

extern void read_int32(char*, long*);
extern void read_int32(char*, int_least32_t*);
4 changes: 2 additions & 2 deletions Examples/fortran_interface.hpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
extern "C" void write_int32(char*, long*);
extern "C" void write_int32(char*, int_least32_t*);

extern "C" void read_int32(char*, long*);
extern "C" void read_int32(char*, int_least32_t*);
2 changes: 1 addition & 1 deletion Install.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ include(FetchContent)
FetchContent_Declare(h5fortran_proj
GIT_REPOSITORY https://github.com/geospace-code/h5fortran.git
GIT_TAG v2.11.2
GIT_TAG v2.11.3
)
FetchContent_MakeAvailable(h5fortran_proj)
Expand Down
2 changes: 1 addition & 1 deletion meson.build
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
project('h5fortran', 'fortran',
meson_version : '>=0.52.0',
version : '2.11.2',
version : '2.11.3',
default_options : ['default_library=static', 'buildtype=release', 'warning_level=3'])

subdir('meson')
Expand Down

0 comments on commit c192ead

Please sign in to comment.