Skip to content

Make real128 optional #83

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
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)
else()
target_sources(fortran_stdlib PRIVATE f08estop.f90)
endif()

# --- tests

add_subdirectory(tests)

# --- install

install(TARGETS fortran_stdlib
RUNTIME DESTINATION bin
ARCHIVE DESTINATION lib
Expand Down
4 changes: 2 additions & 2 deletions src/Makefile.manual
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -22,7 +22,7 @@ $(LIB): $(OBJS)
clean:
$(RM) $(LIB) $(OBJS) $(MODS) $(SMODS)

%.o: %.f90
%.o: %.f90 %.F90
$(FC) $(FFLAGS) -c $<


Expand Down
15 changes: 12 additions & 3 deletions src/stdlib_experimental_io.f90 → src/stdlib_experimental_io.F90
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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.
!
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
!
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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 $<TARGET_FILE:test_${name}> ${CMAKE_CURRENT_BINARY_DIR}
Expand Down
4 changes: 2 additions & 2 deletions src/tests/Makefile.manual.test.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -20,7 +20,7 @@ $(TESTPROGS):
clean:
$(RM) $(PROGS) $(OBJS) $(CLEAN_FILES)

%.o: %.f90
%.o: %.f90 %.F90
$(FC) $(FFLAGS) $(CPPFLAGS) -c $<

$(PROGS): %: %.o
Expand Down
File renamed without changes.
2 changes: 2 additions & 0 deletions src/tests/io/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
12 changes: 6 additions & 6 deletions src/tests/io/Makefile.manual
Original file line number Diff line number Diff line change
@@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
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

implicit none

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
Expand All @@ -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
Expand All @@ -43,109 +47,109 @@ 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"
call assert(foo_int16(1_int16) == 1_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"
call assert(foo_logical(.true.))
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"
call assert(foo_character("x") == "x")
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
File renamed without changes.
File renamed without changes.