Skip to content

Commit 389255d

Browse files
authored
Merge pull request #51 from scivision/master
improve cmake build
2 parents 5a2183e + 17fc4d2 commit 389255d

File tree

7 files changed

+60
-49
lines changed

7 files changed

+60
-49
lines changed

.github/workflows/main.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ jobs:
5252
run: brew install gcc@${GCC_V} || brew upgrade gcc@${GCC_V} || true
5353

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

5757
- name: Build and compile
5858
run: cmake --build build || cmake --build build --verbose --parallel 1

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
build/
2+
13
# Prerequisites
24
*.d
35

CMakeLists.txt

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
cmake_minimum_required(VERSION 3.5.0 FATAL_ERROR)
2-
3-
enable_language(Fortran)
4-
5-
project(stdlib)
6-
1+
cmake_minimum_required(VERSION 3.5.0)
2+
project(stdlib Fortran)
73
enable_testing()
84

5+
# this avoids stdlib and projects using stdlib from having to introspect stdlib's directory structure
6+
set(CMAKE_Fortran_MODULE_DIRECTORY ${CMAKE_BINARY_DIR})
7+
98
add_subdirectory(src)

src/stdlib_experimental_io.f90

+9-9
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ subroutine sloadtxt(filename, d)
4646
integer :: s
4747
integer :: nrow,ncol,i
4848

49-
open(newunit=s, file=filename, status="old")
49+
open(newunit=s, file=filename, status="old", action="read")
5050

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

92-
open(newunit=s, file=filename, status="old")
92+
open(newunit=s, file=filename, status="old", action="read")
9393

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

135-
open(newunit=s, file=filename, status="old")
135+
open(newunit=s, file=filename, status="old", action="read")
136136

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

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

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

212212
integer :: s, i
213-
open(newunit=s, file=filename, status="replace")
213+
open(newunit=s, file=filename, status="replace", action="write")
214214
do i = 1, size(d, 1)
215215
write(s, *) d(i, :)
216216
end do
@@ -243,17 +243,17 @@ integer function number_of_rows_numeric(s)
243243
! determine number or rows
244244
integer,intent(in)::s
245245
integer :: ios
246-
246+
247247
real::r
248-
248+
249249
rewind(s)
250250
number_of_rows_numeric = 0
251251
do
252252
read(s, *, iostat=ios) r
253253
if (ios /= 0) exit
254254
number_of_rows_numeric = number_of_rows_numeric + 1
255255
end do
256-
256+
257257
rewind(s)
258258

259259
end function

src/tests/ascii/CMakeLists.txt

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
include_directories(${PROJECT_BINARY_DIR}/src)
2-
3-
project(ascii)
4-
51
add_executable(test_ascii test_ascii.f90)
62
target_link_libraries(test_ascii fortran_stdlib)
73

8-
add_test(test_ascii ${PROJECT_BINARY_DIR}/test_ascii)
9-
4+
add_test(NAME ASCII COMMAND $<TARGET_FILE:test_ascii>)

src/tests/loadtxt/CMakeLists.txt

+4-9
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
1-
include_directories(${PROJECT_BINARY_DIR}/src)
2-
3-
project(loadtxt)
4-
51
add_executable(test_loadtxt test_loadtxt.f90)
62
target_link_libraries(test_loadtxt fortran_stdlib)
73

84
add_executable(test_savetxt test_savetxt.f90)
95
target_link_libraries(test_savetxt fortran_stdlib)
106

11-
add_test(test_loadtxt ${PROJECT_BINARY_DIR}/test_loadtxt)
12-
add_test(test_savetxt ${PROJECT_BINARY_DIR}/test_savetxt)
13-
14-
file(COPY array1.dat array2.dat array3.dat array4.dat
15-
DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
7+
add_test(NAME load_text COMMAND $<TARGET_FILE:test_loadtxt> ${CMAKE_CURRENT_BINARY_DIR}
8+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
9+
add_test(NAME save_text COMMAND $<TARGET_FILE:test_savetxt> ${CMAKE_CURRENT_BINARY_DIR}
10+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})

src/tests/loadtxt/test_savetxt.f90

+38-18
Original file line numberDiff line numberDiff line change
@@ -4,57 +4,77 @@ program test_loadtxt
44
use stdlib_experimental_error, only: assert
55
implicit none
66

7-
call test_sp()
8-
call test_dp()
9-
call test_qp()
7+
character(:), allocatable :: outpath
8+
9+
outpath = get_outpath() // "/tmp.dat"
10+
11+
call test_sp(outpath)
12+
call test_dp(outpath)
13+
call test_qp(outpath)
1014

1115
contains
1216

13-
subroutine test_sp()
17+
function get_outpath() result(outpath)
18+
integer :: ierr
19+
character(256) :: argv
20+
character(:), allocatable :: outpath
21+
22+
call get_command_argument(1, argv, status=ierr)
23+
if (ierr==0) then
24+
outpath = trim(argv)
25+
else
26+
outpath = '.'
27+
endif
28+
end function get_outpath
29+
30+
subroutine test_sp(outpath)
31+
character(*), intent(in) :: outpath
1432
real(sp) :: d(3, 2), e(2, 3)
1533
real(sp), allocatable :: d2(:, :)
1634
d = reshape([1, 2, 3, 4, 5, 6], [3, 2])
17-
call savetxt("tmp.dat", d)
18-
call loadtxt("tmp.dat", d2)
35+
call savetxt(outpath, d)
36+
call loadtxt(outpath, d2)
1937
call assert(all(shape(d2) == [3, 2]))
2038
call assert(all(abs(d-d2) < epsilon(1._sp)))
2139

2240
e = reshape([1, 2, 3, 4, 5, 6], [2, 3])
23-
call savetxt("tmp.dat", e)
24-
call loadtxt("tmp.dat", d2)
41+
call savetxt(outpath, e)
42+
call loadtxt(outpath, d2)
2543
call assert(all(shape(d2) == [2, 3]))
2644
call assert(all(abs(e-d2) < epsilon(1._sp)))
2745
end subroutine
2846

2947

30-
subroutine test_dp()
48+
subroutine test_dp(outpath)
49+
character(*), intent(in) :: outpath
3150
real(dp) :: d(3, 2), e(2, 3)
3251
real(dp), allocatable :: d2(:, :)
3352
d = reshape([1, 2, 3, 4, 5, 6], [3, 2])
34-
call savetxt("tmp.dat", d)
35-
call loadtxt("tmp.dat", d2)
53+
call savetxt(outpath, d)
54+
call loadtxt(outpath, d2)
3655
call assert(all(shape(d2) == [3, 2]))
3756
call assert(all(abs(d-d2) < epsilon(1._dp)))
3857

3958
e = reshape([1, 2, 3, 4, 5, 6], [2, 3])
40-
call savetxt("tmp.dat", e)
41-
call loadtxt("tmp.dat", d2)
59+
call savetxt(outpath, e)
60+
call loadtxt(outpath, d2)
4261
call assert(all(shape(d2) == [2, 3]))
4362
call assert(all(abs(e-d2) < epsilon(1._dp)))
4463
end subroutine
4564

46-
subroutine test_qp()
65+
subroutine test_qp(outpath)
66+
character(*), intent(in) :: outpath
4767
real(qp) :: d(3, 2), e(2, 3)
4868
real(qp), allocatable :: d2(:, :)
4969
d = reshape([1, 2, 3, 4, 5, 6], [3, 2])
50-
call savetxt("tmp.dat", d)
51-
call loadtxt("tmp.dat", d2)
70+
call savetxt(outpath, d)
71+
call loadtxt(outpath, d2)
5272
call assert(all(shape(d2) == [3, 2]))
5373
call assert(all(abs(d-d2) < epsilon(1._qp)))
5474

5575
e = reshape([1, 2, 3, 4, 5, 6], [2, 3])
56-
call savetxt("tmp.dat", e)
57-
call loadtxt("tmp.dat", d2)
76+
call savetxt(outpath, e)
77+
call loadtxt(outpath, d2)
5878
call assert(all(shape(d2) == [2, 3]))
5979
call assert(all(abs(e-d2) < epsilon(1._qp)))
6080
end subroutine

0 commit comments

Comments
 (0)