Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: fortran-lang/stdlib
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: e24675c0723a522add596b642c058e0dad9394be
Choose a base ref
..
head repository: fortran-lang/stdlib
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: c011b1e7f49b4e83f201caef50d28decddd517c9
Choose a head ref
Showing with 57 additions and 36 deletions.
  1. +1 −1 .github/workflows/main.yml
  2. +2 −0 .gitignore
  3. +2 −1 CMakeLists.txt
  4. +9 −9 src/stdlib_experimental_io.f90
  5. +1 −2 src/tests/ascii/CMakeLists.txt
  6. +4 −5 src/tests/loadtxt/CMakeLists.txt
  7. +38 −18 src/tests/loadtxt/test_savetxt.f90
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -52,7 +52,7 @@ jobs:
run: brew install gcc@${GCC_V} || brew upgrade gcc@${GCC_V} || true

- name: Configure with CMake
run: cmake -Wdev -S . -B build
run: cmake -Wdev -DCMAKE_BUILD_TYPE=Release -S . -B build

- name: Build and compile
run: cmake --build build || cmake --build build --verbose --parallel 1
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
build/

# Prerequisites
*.d

3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
cmake_minimum_required(VERSION 3.5.0 FATAL_ERROR)
cmake_minimum_required(VERSION 3.5.0)
project(stdlib Fortran)
enable_testing()

# this avoids stdlib and projects using stdlib from having to introspect stdlib's directory structure
set(CMAKE_Fortran_MODULE_DIRECTORY ${CMAKE_BINARY_DIR})

# compiler feature checks
18 changes: 9 additions & 9 deletions src/stdlib_experimental_io.f90
Original file line number Diff line number Diff line change
@@ -46,7 +46,7 @@ subroutine sloadtxt(filename, d)
integer :: s
integer :: nrow,ncol,i

open(newunit=s, file=filename, status="old")
open(newunit=s, file=filename, status="old", action="read")

! determine number of columns
ncol = number_of_columns(s)
@@ -89,7 +89,7 @@ subroutine dloadtxt(filename, d)
integer :: s
integer :: nrow,ncol,i

open(newunit=s, file=filename, status="old")
open(newunit=s, file=filename, status="old", action="read")

! determine number of columns
ncol = number_of_columns(s)
@@ -132,7 +132,7 @@ subroutine qloadtxt(filename, d)
integer :: s
integer :: nrow,ncol,i

open(newunit=s, file=filename, status="old")
open(newunit=s, file=filename, status="old", action="read")

! determine number of columns
ncol = number_of_columns(s)
@@ -164,7 +164,7 @@ subroutine ssavetxt(filename, d)
! call savetxt("log.txt", data)

integer :: s, i
open(newunit=s, file=filename, status="replace")
open(newunit=s, file=filename, status="replace", action="write")
do i = 1, size(d, 1)
write(s, *) d(i, :)
end do
@@ -187,7 +187,7 @@ subroutine dsavetxt(filename, d)
! call savetxt("log.txt", data)

integer :: s, i
open(newunit=s, file=filename, status="replace")
open(newunit=s, file=filename, status="replace", action="write")
do i = 1, size(d, 1)
write(s, *) d(i, :)
end do
@@ -210,7 +210,7 @@ subroutine qsavetxt(filename, d)
! call savetxt("log.txt", data)

integer :: s, i
open(newunit=s, file=filename, status="replace")
open(newunit=s, file=filename, status="replace", action="write")
do i = 1, size(d, 1)
write(s, *) d(i, :)
end do
@@ -243,17 +243,17 @@ integer function number_of_rows_numeric(s)
! determine number or rows
integer,intent(in)::s
integer :: ios

real::r

rewind(s)
number_of_rows_numeric = 0
do
read(s, *, iostat=ios) r
if (ios /= 0) exit
number_of_rows_numeric = number_of_rows_numeric + 1
end do

rewind(s)

end function
3 changes: 1 addition & 2 deletions src/tests/ascii/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
add_executable(test_ascii test_ascii.f90)
target_link_libraries(test_ascii fortran_stdlib)

add_test(test_ascii ${PROJECT_BINARY_DIR}/test_ascii)

add_test(NAME ASCII COMMAND $<TARGET_FILE:test_ascii>)
9 changes: 4 additions & 5 deletions src/tests/loadtxt/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -4,8 +4,7 @@ target_link_libraries(test_loadtxt fortran_stdlib)
add_executable(test_savetxt test_savetxt.f90)
target_link_libraries(test_savetxt fortran_stdlib)

add_test(test_loadtxt ${PROJECT_BINARY_DIR}/test_loadtxt)
add_test(test_savetxt ${PROJECT_BINARY_DIR}/test_savetxt)

file(COPY array1.dat array2.dat array3.dat array4.dat
DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
add_test(NAME load_text COMMAND $<TARGET_FILE:test_loadtxt> ${CMAKE_CURRENT_BINARY_DIR}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
add_test(NAME save_text COMMAND $<TARGET_FILE:test_savetxt> ${CMAKE_CURRENT_BINARY_DIR}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
56 changes: 38 additions & 18 deletions src/tests/loadtxt/test_savetxt.f90
Original file line number Diff line number Diff line change
@@ -4,57 +4,77 @@ program test_loadtxt
use stdlib_experimental_error, only: assert
implicit none

call test_sp()
call test_dp()
call test_qp()
character(:), allocatable :: outpath

outpath = get_outpath() // "/tmp.dat"

call test_sp(outpath)
call test_dp(outpath)
call test_qp(outpath)

contains

subroutine test_sp()
function get_outpath() result(outpath)
integer :: ierr
character(256) :: argv
character(:), allocatable :: outpath

call get_command_argument(1, argv, status=ierr)
if (ierr==0) then
outpath = trim(argv)
else
outpath = '.'
endif
end function get_outpath

subroutine test_sp(outpath)
character(*), intent(in) :: outpath
real(sp) :: d(3, 2), e(2, 3)
real(sp), allocatable :: d2(:, :)
d = reshape([1, 2, 3, 4, 5, 6], [3, 2])
call savetxt("tmp.dat", d)
call loadtxt("tmp.dat", d2)
call savetxt(outpath, d)
call loadtxt(outpath, d2)
call assert(all(shape(d2) == [3, 2]))
call assert(all(abs(d-d2) < epsilon(1._sp)))

e = reshape([1, 2, 3, 4, 5, 6], [2, 3])
call savetxt("tmp.dat", e)
call loadtxt("tmp.dat", d2)
call savetxt(outpath, e)
call loadtxt(outpath, d2)
call assert(all(shape(d2) == [2, 3]))
call assert(all(abs(e-d2) < epsilon(1._sp)))
end subroutine


subroutine test_dp()
subroutine test_dp(outpath)
character(*), intent(in) :: outpath
real(dp) :: d(3, 2), e(2, 3)
real(dp), allocatable :: d2(:, :)
d = reshape([1, 2, 3, 4, 5, 6], [3, 2])
call savetxt("tmp.dat", d)
call loadtxt("tmp.dat", d2)
call savetxt(outpath, d)
call loadtxt(outpath, d2)
call assert(all(shape(d2) == [3, 2]))
call assert(all(abs(d-d2) < epsilon(1._dp)))

e = reshape([1, 2, 3, 4, 5, 6], [2, 3])
call savetxt("tmp.dat", e)
call loadtxt("tmp.dat", d2)
call savetxt(outpath, e)
call loadtxt(outpath, d2)
call assert(all(shape(d2) == [2, 3]))
call assert(all(abs(e-d2) < epsilon(1._dp)))
end subroutine

subroutine test_qp()
subroutine test_qp(outpath)
character(*), intent(in) :: outpath
real(qp) :: d(3, 2), e(2, 3)
real(qp), allocatable :: d2(:, :)
d = reshape([1, 2, 3, 4, 5, 6], [3, 2])
call savetxt("tmp.dat", d)
call loadtxt("tmp.dat", d2)
call savetxt(outpath, d)
call loadtxt(outpath, d2)
call assert(all(shape(d2) == [3, 2]))
call assert(all(abs(d-d2) < epsilon(1._qp)))

e = reshape([1, 2, 3, 4, 5, 6], [2, 3])
call savetxt("tmp.dat", e)
call loadtxt("tmp.dat", d2)
call savetxt(outpath, e)
call loadtxt(outpath, d2)
call assert(all(shape(d2) == [2, 3]))
call assert(all(abs(e-d2) < epsilon(1._qp)))
end subroutine