Skip to content

make real128 optional #93

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
46 changes: 46 additions & 0 deletions .github/workflows/ci_real128.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: ci_real128

on: [push, pull_request]

env:
CI: "ON"

jobs:
linux:
runs-on: ubuntu-latest
strategy:
fail-fast: false

steps:
- uses: actions/checkout@v1

- name: Set up Python 3.x
uses: actions/setup-python@v1
with:
python-version: 3.x

- name: Set up CMake
run: pip install --upgrade cmake

- name: Cmake configure
- run: cmake -DREAL128=true -B build
env:
FC: gfortran
CC: gcc
CXX: g++

- name: CMake build
run: cmake --build build --parallel

- run: cmake --build build --verbose --parallel 1
if: failure()

- name: CTest
run: ctest --output-on-failure --parallel -V
working-directory: build

- uses: actions/upload-artifact@v1
if: failure()
with:
name: Real128CMakeTestlog
path: build/Testing/Temporary/LastTest.log
2 changes: 1 addition & 1 deletion .github/workflows/ci_windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ env:
CI: "ON"

jobs:
Build:
cmake:
runs-on: windows-latest
strategy:
fail-fast: false
Expand Down
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ enable_testing()
# and thereby can clash if module/submodule names are the same in different parts of library
set(CMAKE_Fortran_MODULE_DIRECTORY ${CMAKE_BINARY_DIR})

option(REAL128 "make real128 precision available")

# --- compiler options
if(CMAKE_Fortran_COMPILER_ID STREQUAL GNU)
add_compile_options(-fimplicit-none)
Expand All @@ -21,5 +23,8 @@ include(CheckFortranSourceCompiles)
include(CheckFortranSourceRuns)
check_fortran_source_compiles("error stop i; end" f18errorstop SRC_EXT f90)
check_fortran_source_runs("use, intrinsic :: iso_fortran_env, only : real128; real(real128) :: x; x = x+1; end" f03real128)
if(NOT f03real128)
set(REAL128 false)
endif()

add_subdirectory(src)
11 changes: 8 additions & 3 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
set(SRC
stdlib_experimental_ascii.f90
stdlib_experimental_io.f90
stdlib_experimental_io.F90
stdlib_experimental_error.f90
stdlib_experimental_optval.f90
stdlib_experimental_kinds.f90
stdlib_experimental_optval.F90
stdlib_experimental_kinds.F90
)

add_library(fortran_stdlib ${SRC})
Expand All @@ -14,6 +14,11 @@ else()
target_sources(fortran_stdlib PRIVATE f08estop.f90)
endif()

if(REAL128)
target_compile_definitions(fortran_stdlib PRIVATE REAL128)
target_sources(fortran_stdlib PRIVATE io_qp.f90 opt_qp.f90)
endif()

add_subdirectory(tests)

install(TARGETS fortran_stdlib
Expand Down
74 changes: 74 additions & 0 deletions src/io_qp.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
submodule (stdlib_experimental_io) io_qp

use stdlib_experimental_kinds, only : qp

implicit none

contains

module procedure qloadtxt
! Loads a 2D array from a text file.
!
! Arguments
! ---------
!
! Filename to load the array from
! The array 'd' will be automatically allocated with the correct dimensions
!
! Example
! -------
!
! real(qp), allocatable :: data(:, :)
! call loadtxt("log.txt", data) ! 'data' will be automatically allocated
!
! Where 'log.txt' contains for example::
!
! 1 2 3
! 2 4 6
! 8 9 10
! 11 12 13
! ...
!
integer :: s
integer :: nrow,ncol,i

s = open(filename)

! determine number of columns
ncol = number_of_columns(s)

! determine number or rows
nrow = number_of_rows_numeric(s)

allocate(d(nrow, ncol))
do i = 1, nrow
read(s, *) d(i, :)
end do
close(s)
end procedure

module procedure qsavetxt
! Saves a 2D array into a textfile.
!
! Arguments
! ---------
!
!
! Example
! -------
!
! real(dp) :: data(3, 2)
! call savetxt("log.txt", data)

integer :: s, i
character(len=14) :: format_string

write(format_string, '(a1,i06,a7)') '(', size(d, 2), 'f40.34)'
s = open(filename, "w")
do i = 1, size(d, 1)
write(s, format_string) d(i, :)
end do
close(s)
end procedure

end submodule
15 changes: 15 additions & 0 deletions src/opt_qp.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
submodule (stdlib_experimental_optval) opt_qp

implicit none

contains

module procedure optval_qp
if (present(x)) then
y = x
else
y = default
end if
end procedure optval_qp

end submodule opt_qp
96 changes: 24 additions & 72 deletions src/stdlib_experimental_io.f90 → src/stdlib_experimental_io.F90
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
module stdlib_experimental_io
use stdlib_experimental_kinds, only: sp, dp, qp
use stdlib_experimental_kinds, only: sp, dp
#ifdef REAL128
use stdlib_experimental_kinds, only: qp
#endif
use stdlib_experimental_error, only: error_stop
use stdlib_experimental_optval, only: optval
use stdlib_experimental_ascii, only: is_blank
implicit none
private
! Public API
public :: loadtxt, savetxt, open
public :: loadtxt, savetxt, open, number_of_columns, number_of_rows_numeric

! Private API that is exposed so that we can test it in tests
public :: parse_mode
Expand All @@ -15,15 +18,34 @@ 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

#ifdef REAL128
interface
module subroutine qsavetxt(filename, d)
character(len=*), intent(in) :: filename ! File to save the array to
real(qp), intent(in) :: d(:,:) ! The 2D array to save
end subroutine

module subroutine qloadtxt(filename, d)
character(len=*), intent(in) :: filename
real(qp), allocatable, intent(out) :: d(:,:)
end subroutine

end interface
#endif

contains

subroutine sloadtxt(filename, d)
Expand Down Expand Up @@ -112,49 +134,6 @@ subroutine dloadtxt(filename, d)
close(s)
end subroutine

subroutine qloadtxt(filename, d)
! Loads a 2D array from a text file.
!
! Arguments
! ---------
!
! Filename to load the array from
character(len=*), intent(in) :: filename
! The array 'd' will be automatically allocated with the correct dimensions
real(qp), allocatable, intent(out) :: d(:,:)
!
! Example
! -------
!
! real(qp), allocatable :: data(:, :)
! call loadtxt("log.txt", data) ! 'data' will be automatically allocated
!
! Where 'log.txt' contains for example::
!
! 1 2 3
! 2 4 6
! 8 9 10
! 11 12 13
! ...
!
integer :: s
integer :: nrow,ncol,i

s = open(filename)

! determine number of columns
ncol = number_of_columns(s)

! determine number or rows
nrow = number_of_rows_numeric(s)

allocate(d(nrow, ncol))
do i = 1, nrow
read(s, *) d(i, :)
end do
close(s)
end subroutine


subroutine ssavetxt(filename, d)
! Saves a 2D array into a textfile.
Expand Down Expand Up @@ -202,33 +181,6 @@ subroutine dsavetxt(filename, d)
close(s)
end subroutine

subroutine qsavetxt(filename, d)
! Saves a 2D array into a textfile.
!
! Arguments
! ---------
!
character(len=*), intent(in) :: filename ! File to save the array to
real(qp), intent(in) :: d(:,:) ! The 2D array to save
!
! Example
! -------
!
! real(dp) :: data(3, 2)
! call savetxt("log.txt", data)

integer :: s, i
character(len=14) :: format_string

write(format_string, '(a1,i06,a7)') '(', size(d, 2), 'f40.34)'
s = open(filename, "w")
do i = 1, size(d, 1)
write(s, format_string) d(i, :)
end do
close(s)
end subroutine


integer function number_of_columns(s)
! determine number of columns
integer,intent(in)::s
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
module stdlib_experimental_kinds
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 iso_fortran_env, only: int8, int16, int32, int64
! If we decide later to use iso_fortran_env instead of iso_fortran_env:
!use iso_c_binding, only: sp=>c_float, dp=>c_double, qp=>c_float128
!use iso_c_binding, only: int8=>c_int8_t, int16=>c_int16_t, int32=>c_int32_t, int64=>c_int64_t
implicit none
private
public sp, dp, qp, int8, int16, int32, int64
public :: sp, dp, int8, int16, int32, int64
#ifdef REAL128
public :: qp
#endif
end module
Loading