From fdcd1ad06dda5d17827f87505caf73a49b3289c8 Mon Sep 17 00:00:00 2001 From: "Michael Hirsch, Ph.D" Date: Sun, 5 Jan 2020 00:22:16 -0500 Subject: [PATCH 1/2] fence out real128 with preprocessor --- src/CMakeLists.txt | 11 ++++- ...ntal_io.f90 => stdlib_experimental_io.F90} | 15 ++++-- ...val.f90 => stdlib_experimental_optval.F90} | 13 ++++-- src/tests/io/CMakeLists.txt | 2 + src/tests/io/test_loadtxt.f90 | 2 +- .../{test_optval.f90 => test_optval.F90} | 46 ++++++++++--------- 6 files changed, 59 insertions(+), 30 deletions(-) rename src/{stdlib_experimental_io.f90 => stdlib_experimental_io.F90} (97%) rename src/{stdlib_experimental_optval.f90 => stdlib_experimental_optval.F90} (94%) rename src/tests/optval/{test_optval.f90 => test_optval.F90} (95%) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d65cd416d..4d1da69cd 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,11 +1,14 @@ set(SRC stdlib_experimental_ascii.f90 - stdlib_experimental_io.f90 + stdlib_experimental_io.F90 stdlib_experimental_error.f90 - stdlib_experimental_optval.f90 + stdlib_experimental_optval.F90 ) add_library(fortran_stdlib ${SRC}) +if(f03real128) + target_compile_definitions(fortran_stdlib PRIVATE REAL128) +endif() if(f18errorstop) target_sources(fortran_stdlib PRIVATE f18estop.f90) @@ -13,8 +16,12 @@ else() target_sources(fortran_stdlib PRIVATE f08estop.f90) endif() +# --- tests + add_subdirectory(tests) +# --- install + install(TARGETS fortran_stdlib RUNTIME DESTINATION bin ARCHIVE DESTINATION lib diff --git a/src/stdlib_experimental_io.f90 b/src/stdlib_experimental_io.F90 similarity index 97% rename from src/stdlib_experimental_io.f90 rename to src/stdlib_experimental_io.F90 index 547f9c0a9..c6c274f34 100644 --- a/src/stdlib_experimental_io.f90 +++ b/src/stdlib_experimental_io.F90 @@ -1,5 +1,8 @@ module stdlib_experimental_io -use iso_fortran_env, only: sp=>real32, dp=>real64, qp=>real128 +use iso_fortran_env, only: sp=>real32, dp=>real64 +#ifdef REAL128 +use iso_fortran_env, only: qp => real128 +#endif use stdlib_experimental_error, only: error_stop use stdlib_experimental_optval, only: optval implicit none @@ -14,13 +17,17 @@ module stdlib_experimental_io interface loadtxt module procedure sloadtxt module procedure dloadtxt +#ifdef REAL128 module procedure qloadtxt +#endif end interface interface savetxt module procedure ssavetxt module procedure dsavetxt +#ifdef REAL128 module procedure qsavetxt +#endif end interface contains @@ -111,6 +118,7 @@ subroutine dloadtxt(filename, d) close(s) end subroutine +#ifdef REAL128 subroutine qloadtxt(filename, d) ! Loads a 2D array from a text file. ! @@ -153,7 +161,7 @@ subroutine qloadtxt(filename, d) end do close(s) end subroutine - +#endif subroutine ssavetxt(filename, d) ! Saves a 2D array into a textfile. @@ -201,6 +209,7 @@ subroutine dsavetxt(filename, d) close(s) end subroutine +#ifdef REAL128 subroutine qsavetxt(filename, d) ! Saves a 2D array into a textfile. ! @@ -223,7 +232,7 @@ subroutine qsavetxt(filename, d) end do close(s) end subroutine - +#endif integer function number_of_columns(s) ! determine number of columns diff --git a/src/stdlib_experimental_optval.f90 b/src/stdlib_experimental_optval.F90 similarity index 94% rename from src/stdlib_experimental_optval.f90 rename to src/stdlib_experimental_optval.F90 index 85e67b8ce..30716074d 100644 --- a/src/stdlib_experimental_optval.f90 +++ b/src/stdlib_experimental_optval.F90 @@ -8,7 +8,12 @@ module stdlib_experimental_optval !! !! It is an error to call `optval` with a single actual argument. !! - use iso_fortran_env, only: sp => real32, dp => real64, qp => real128, int8, int16, int32, int64 + use iso_fortran_env, only: sp => real32, dp => real64, int8, int16, int32, int64 +#ifdef REAL128 + use iso_fortran_env, only: qp => real128 +#endif + + implicit none @@ -19,7 +24,9 @@ module stdlib_experimental_optval interface optval module procedure optval_sp module procedure optval_dp +#ifdef REAL128 module procedure optval_qp +#endif module procedure optval_int8 module procedure optval_int16 module procedure optval_int32 @@ -59,7 +66,7 @@ pure function optval_dp(x, default) result(y) end if end function optval_dp - +#ifdef REAL128 pure function optval_qp(x, default) result(y) real(qp), intent(in), optional :: x real(qp), intent(in) :: default @@ -71,7 +78,7 @@ pure function optval_qp(x, default) result(y) y = default end if end function optval_qp - +#endif pure function optval_int8(x, default) result(y) integer(int8), intent(in), optional :: x diff --git a/src/tests/io/CMakeLists.txt b/src/tests/io/CMakeLists.txt index 68388a5e5..77dc54ee8 100644 --- a/src/tests/io/CMakeLists.txt +++ b/src/tests/io/CMakeLists.txt @@ -1,10 +1,12 @@ ADDTEST(loadtxt) ADDTEST(savetxt) +if(f03real128) ADDTEST(loadtxt_qp) ADDTEST(savetxt_qp) set_tests_properties(loadtxt_qp PROPERTIES LABELS quadruple_precision) set_tests_properties(savetxt_qp PROPERTIES LABELS quadruple_precision) +endif() ADDTEST(open) ADDTEST(parse_mode) diff --git a/src/tests/io/test_loadtxt.f90 b/src/tests/io/test_loadtxt.f90 index 4b0ba95c8..cf832bf87 100644 --- a/src/tests/io/test_loadtxt.f90 +++ b/src/tests/io/test_loadtxt.f90 @@ -1,5 +1,5 @@ program test_loadtxt -use iso_fortran_env, only: sp=>real32, dp=>real64 +use, intrinsic :: iso_fortran_env, only: sp=>real32, dp=>real64 use stdlib_experimental_io, only: loadtxt use stdlib_experimental_error, only: error_stop implicit none diff --git a/src/tests/optval/test_optval.f90 b/src/tests/optval/test_optval.F90 similarity index 95% rename from src/tests/optval/test_optval.f90 rename to src/tests/optval/test_optval.F90 index 85d9748c9..0e2ce5459 100644 --- a/src/tests/optval/test_optval.f90 +++ b/src/tests/optval/test_optval.F90 @@ -1,7 +1,10 @@ program test_optval use, intrinsic :: iso_fortran_env, only: & - sp => real32, dp => real64, qp => real128, & + sp => real32, dp => real64, & int8, int16, int32, int64 +#ifdef REAL128 +use, intrinsic :: iso_fortran_env, only : qp => real128 +#endif use stdlib_experimental_error, only: assert use stdlib_experimental_optval, only: optval @@ -9,8 +12,9 @@ program test_optval call test_optval_sp call test_optval_dp +#ifdef REAL128 call test_optval_qp - +#endif call test_optval_int8 call test_optval_int16 call test_optval_int32 @@ -22,14 +26,14 @@ program test_optval contains - + subroutine test_optval_sp print *, "test_optval_sp" call assert(foo_sp(1.0_sp) == 1.0_sp) call assert(foo_sp() == 2.0_sp) end subroutine test_optval_sp - + function foo_sp(x) result(z) real(sp), intent(in), optional :: x real(sp) :: z @@ -43,41 +47,41 @@ subroutine test_optval_dp call assert(foo_dp() == 2.0_dp) end subroutine test_optval_dp - + function foo_dp(x) result(z) real(dp), intent(in), optional :: x real(dp) :: z z = optval(x, 2.0_dp) endfunction foo_dp - +#ifdef REAL128 subroutine test_optval_qp print *, "test_optval_qp" call assert(foo_qp(1.0_qp) == 1.0_qp) call assert(foo_qp() == 2.0_qp) end subroutine test_optval_qp - + function foo_qp(x) result(z) real(qp), intent(in), optional :: x real(qp) :: z z = optval(x, 2.0_qp) endfunction foo_qp - - +#endif + subroutine test_optval_int8 print *, "test_optval_int8" call assert(foo_int8(1_int8) == 1_int8) call assert(foo_int8() == 2_int8) end subroutine test_optval_int8 - + function foo_int8(x) result(z) integer(int8), intent(in), optional :: x integer(int8) :: z z = optval(x, 2_int8) endfunction foo_int8 - + subroutine test_optval_int16 print *, "test_optval_int16" @@ -85,41 +89,41 @@ subroutine test_optval_int16 call assert(foo_int16() == 2_int16) end subroutine test_optval_int16 - + function foo_int16(x) result(z) integer(int16), intent(in), optional :: x integer(int16) :: z z = optval(x, 2_int16) endfunction foo_int16 - + subroutine test_optval_int32 print *, "test_optval_int32" call assert(foo_int32(1_int32) == 1_int32) call assert(foo_int32() == 2_int32) end subroutine test_optval_int32 - + function foo_int32(x) result(z) integer(int32), intent(in), optional :: x integer(int32) :: z z = optval(x, 2_int32) endfunction foo_int32 - + subroutine test_optval_int64 print *, "test_optval_int64" call assert(foo_int64(1_int64) == 1_int64) call assert(foo_int64() == 2_int64) end subroutine test_optval_int64 - + function foo_int64(x) result(z) integer(int64), intent(in), optional :: x integer(int64) :: z z = optval(x, 2_int64) endfunction foo_int64 - + subroutine test_optval_logical print *, "test_optval_logical" @@ -127,13 +131,13 @@ subroutine test_optval_logical call assert(.not.foo_logical()) end subroutine test_optval_logical - + function foo_logical(x) result(z) logical, intent(in), optional :: x logical :: z z = optval(x, .false.) endfunction foo_logical - + subroutine test_optval_character print *, "test_optval_character" @@ -141,11 +145,11 @@ subroutine test_optval_character call assert(foo_character() == "y") end subroutine test_optval_character - + function foo_character(x) result(z) character(len=*), intent(in), optional :: x character(len=:), allocatable :: z z = optval(x, "y") endfunction foo_character - + end program test_optval From e6f076bd34c14f5fe0f783fee42005749d496145 Mon Sep 17 00:00:00 2001 From: "Michael Hirsch, Ph.D" Date: Sun, 5 Jan 2020 08:42:22 -0500 Subject: [PATCH 2/2] assume all tests are preprocessed .F90 --- src/Makefile.manual | 4 ++-- src/tests/CMakeLists.txt | 2 +- src/tests/Makefile.manual.test.mk | 4 ++-- src/tests/ascii/{test_ascii.f90 => test_ascii.F90} | 0 src/tests/io/Makefile.manual | 12 ++++++------ src/tests/io/{test_loadtxt.f90 => test_loadtxt.F90} | 0 .../io/{test_loadtxt_qp.f90 => test_loadtxt_qp.F90} | 0 src/tests/io/{test_open.f90 => test_open.F90} | 0 .../io/{test_parse_mode.f90 => test_parse_mode.F90} | 0 src/tests/io/{test_savetxt.f90 => test_savetxt.F90} | 0 .../io/{test_savetxt_qp.f90 => test_savetxt_qp.F90} | 0 .../{test_always_fail.f90 => test_always_fail.F90} | 0 .../{test_always_skip.f90 => test_always_skip.F90} | 0 13 files changed, 11 insertions(+), 11 deletions(-) rename src/tests/ascii/{test_ascii.f90 => test_ascii.F90} (100%) rename src/tests/io/{test_loadtxt.f90 => test_loadtxt.F90} (100%) rename src/tests/io/{test_loadtxt_qp.f90 => test_loadtxt_qp.F90} (100%) rename src/tests/io/{test_open.f90 => test_open.F90} (100%) rename src/tests/io/{test_parse_mode.f90 => test_parse_mode.F90} (100%) rename src/tests/io/{test_savetxt.f90 => test_savetxt.F90} (100%) rename src/tests/io/{test_savetxt_qp.f90 => test_savetxt_qp.F90} (100%) rename src/tests/{test_always_fail.f90 => test_always_fail.F90} (100%) rename src/tests/{test_always_skip.f90 => test_always_skip.F90} (100%) diff --git a/src/Makefile.manual b/src/Makefile.manual index 31ca7cad7..edd6426da 100644 --- a/src/Makefile.manual +++ b/src/Makefile.manual @@ -8,7 +8,7 @@ LIB = libstdlib.a -OBJS = $(SRC:.f90=.o) +OBJS = $(SRC:.f90=.o) $(SRC:.F90=.o) MODS = $(OBJS:.o=.mod) SMODS = $(OBJS:.o=*.smod) @@ -22,7 +22,7 @@ $(LIB): $(OBJS) clean: $(RM) $(LIB) $(OBJS) $(MODS) $(SMODS) -%.o: %.f90 +%.o: %.f90 %.F90 $(FC) $(FFLAGS) -c $< diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt index dc1bdbc96..0332d110f 100644 --- a/src/tests/CMakeLists.txt +++ b/src/tests/CMakeLists.txt @@ -1,5 +1,5 @@ macro(ADDTEST name) - add_executable(test_${name} test_${name}.f90) + add_executable(test_${name} test_${name}.F90) target_link_libraries(test_${name} fortran_stdlib) add_test(NAME ${name} COMMAND $ ${CMAKE_CURRENT_BINARY_DIR} diff --git a/src/tests/Makefile.manual.test.mk b/src/tests/Makefile.manual.test.mk index ee0eed31e..e1d6bd21a 100644 --- a/src/tests/Makefile.manual.test.mk +++ b/src/tests/Makefile.manual.test.mk @@ -4,7 +4,7 @@ CPPFLAGS += -I../.. LDFLAGS += -L../.. -lstdlib -OBJS = $(PROGS_SRC:.f90=.o) +OBJS = $(PROGS_SRC:.f90=.o) $(PROGS_SRC:.F90=.o) PROGS = $(OBJS:.o=) TESTPROGS = $(PROGS:=TEST) @@ -20,7 +20,7 @@ $(TESTPROGS): clean: $(RM) $(PROGS) $(OBJS) $(CLEAN_FILES) -%.o: %.f90 +%.o: %.f90 %.F90 $(FC) $(FFLAGS) $(CPPFLAGS) -c $< $(PROGS): %: %.o diff --git a/src/tests/ascii/test_ascii.f90 b/src/tests/ascii/test_ascii.F90 similarity index 100% rename from src/tests/ascii/test_ascii.f90 rename to src/tests/ascii/test_ascii.F90 diff --git a/src/tests/io/Makefile.manual b/src/tests/io/Makefile.manual index 3bbce9db7..f22d9aca0 100644 --- a/src/tests/io/Makefile.manual +++ b/src/tests/io/Makefile.manual @@ -1,9 +1,9 @@ -PROGS_SRC = test_loadtxt.f90 \ - test_savetxt.f90 \ - test_loadtxt_qp.f90 \ - test_savetxt_qp.f90 \ - test_parse_mode.f90 \ - test_open.f90 +PROGS_SRC = test_loadtxt.F90 \ + test_savetxt.F90 \ + test_loadtxt_qp.F90 \ + test_savetxt_qp.F90 \ + test_parse_mode.F90 \ + test_open.F90 CLEAN_FILES = tmp.dat tmp_qp.dat io_open.dat io_open.stream diff --git a/src/tests/io/test_loadtxt.f90 b/src/tests/io/test_loadtxt.F90 similarity index 100% rename from src/tests/io/test_loadtxt.f90 rename to src/tests/io/test_loadtxt.F90 diff --git a/src/tests/io/test_loadtxt_qp.f90 b/src/tests/io/test_loadtxt_qp.F90 similarity index 100% rename from src/tests/io/test_loadtxt_qp.f90 rename to src/tests/io/test_loadtxt_qp.F90 diff --git a/src/tests/io/test_open.f90 b/src/tests/io/test_open.F90 similarity index 100% rename from src/tests/io/test_open.f90 rename to src/tests/io/test_open.F90 diff --git a/src/tests/io/test_parse_mode.f90 b/src/tests/io/test_parse_mode.F90 similarity index 100% rename from src/tests/io/test_parse_mode.f90 rename to src/tests/io/test_parse_mode.F90 diff --git a/src/tests/io/test_savetxt.f90 b/src/tests/io/test_savetxt.F90 similarity index 100% rename from src/tests/io/test_savetxt.f90 rename to src/tests/io/test_savetxt.F90 diff --git a/src/tests/io/test_savetxt_qp.f90 b/src/tests/io/test_savetxt_qp.F90 similarity index 100% rename from src/tests/io/test_savetxt_qp.f90 rename to src/tests/io/test_savetxt_qp.F90 diff --git a/src/tests/test_always_fail.f90 b/src/tests/test_always_fail.F90 similarity index 100% rename from src/tests/test_always_fail.f90 rename to src/tests/test_always_fail.F90 diff --git a/src/tests/test_always_skip.f90 b/src/tests/test_always_skip.F90 similarity index 100% rename from src/tests/test_always_skip.f90 rename to src/tests/test_always_skip.F90