Skip to content

Commit fafd229

Browse files
committed
Reverted formatting changes. Complex support for loadtxt and savetxt
1 parent c1a7956 commit fafd229

File tree

2 files changed

+77
-77
lines changed

2 files changed

+77
-77
lines changed

src/tests/io/test_loadtxt.f90

Lines changed: 51 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,63 @@
11
program test_loadtxt
2-
use stdlib_experimental_kinds, only: int32, sp, dp
3-
use stdlib_experimental_io, only: loadtxt
4-
use stdlib_experimental_error, only: error_stop
5-
implicit none
2+
use stdlib_experimental_kinds, only: int32, sp, dp
3+
use stdlib_experimental_io, only: loadtxt
4+
use stdlib_experimental_error, only: error_stop
5+
implicit none
66

7-
integer(int32), allocatable :: i(:, :)
8-
real(sp), allocatable :: s(:, :)
9-
real(dp), allocatable :: d(:, :)
10-
complex(dp), allocatable :: z(:, :)
7+
integer(int32), allocatable :: i(:, :)
8+
real(sp), allocatable :: s(:, :)
9+
real(dp), allocatable :: d(:, :)
10+
complex(dp), allocatable :: z(:, :)
1111

12-
call loadtxt("array1.dat", i)
13-
call print_array(i)
12+
call loadtxt("array1.dat", i)
13+
call print_array(i)
1414

15-
call loadtxt("array1.dat", s)
16-
call print_array(s)
15+
call loadtxt("array1.dat", s)
16+
call print_array(s)
1717

18-
call loadtxt("array1.dat", d)
19-
call print_array(d)
18+
call loadtxt("array1.dat", d)
19+
call print_array(d)
2020

21-
call loadtxt("array2.dat", d)
22-
call print_array(d)
21+
call loadtxt("array2.dat", d)
22+
call print_array(d)
2323

24-
call loadtxt("array3.dat", d)
25-
call print_array(d)
24+
call loadtxt("array3.dat", d)
25+
call print_array(d)
2626

27-
call loadtxt("array4.dat", d)
28-
call print_array(d)
27+
call loadtxt("array4.dat", d)
28+
call print_array(d)
2929

30-
call loadtxt("array5.dat", z)
31-
call print_array(z)
30+
call loadtxt("array5.dat", z)
31+
call print_array(z)
3232

3333
contains
3434

35-
subroutine print_array(a)
36-
class(*),intent(in) :: a(:, :)
37-
integer :: i
38-
print *, "Array, shape=(", size(a, 1), ",", size(a, 2), ")"
39-
40-
select type(a)
41-
type is(integer(int32))
42-
do i = 1, size(a, 1)
43-
print *, a(i, :)
44-
end do
45-
type is(real(sp))
46-
do i = 1, size(a, 1)
47-
print *, a(i, :)
48-
end do
49-
type is(real(dp))
50-
do i = 1, size(a, 1)
51-
print *, a(i, :)
52-
end do
53-
type is(complex(dp))
54-
do i = 1, size(a, 1)
55-
print *, a(i, :)
56-
end do
57-
class default
58-
call error_stop('The proposed type is not supported')
59-
end select
60-
61-
end subroutine print_array
62-
63-
end program test_loadtxt
35+
subroutine print_array(a)
36+
class(*),intent(in) :: a(:, :)
37+
integer :: i
38+
print *, "Array, shape=(", size(a, 1), ",", size(a, 2), ")"
39+
40+
select type(a)
41+
type is(integer(int32))
42+
do i = 1, size(a, 1)
43+
print *, a(i, :)
44+
end do
45+
type is(real(sp))
46+
do i = 1, size(a, 1)
47+
print *, a(i, :)
48+
end do
49+
type is(real(dp))
50+
do i = 1, size(a, 1)
51+
print *, a(i, :)
52+
end do
53+
type is(complex(dp))
54+
do i = 1, size(a, 1)
55+
print *, a(i, :)
56+
end do
57+
class default
58+
call error_stop('The proposed type is not supported')
59+
end select
60+
61+
end subroutine
62+
63+
end program

src/tests/io/test_savetxt.f90

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
11
program test_savetxt
2-
use stdlib_experimental_kinds, only: int32, sp, dp
3-
use stdlib_experimental_io, only: loadtxt, savetxt
4-
use stdlib_experimental_error, only: assert
5-
implicit none
2+
use stdlib_experimental_kinds, only: int32, sp, dp
3+
use stdlib_experimental_io, only: loadtxt, savetxt
4+
use stdlib_experimental_error, only: assert
5+
implicit none
66

7-
character(:), allocatable :: outpath
7+
character(:), allocatable :: outpath
88

9-
outpath = get_outpath() // "/tmp.dat"
9+
outpath = get_outpath() // "/tmp.dat"
1010

11-
call test_int32(outpath)
12-
call test_rsp(outpath)
13-
call test_rdp(outpath)
14-
call test_csp(outpath)
15-
call test_cdp(outpath)
11+
call test_int32(outpath)
12+
call test_rsp(outpath)
13+
call test_rdp(outpath)
14+
call test_csp(outpath)
15+
call test_cdp(outpath)
1616

1717
contains
1818

19-
function get_outpath() result(outpath)
19+
function get_outpath() result(outpath)
2020
integer :: ierr
2121
character(256) :: argv
2222
character(:), allocatable :: outpath
2323

2424
call get_command_argument(1, argv, status=ierr)
2525
if (ierr==0) then
26-
outpath = trim(argv)
26+
outpath = trim(argv)
2727
else
28-
outpath = '.'
28+
outpath = '.'
2929
endif
30-
end function get_outpath
30+
end function get_outpath
3131

32-
subroutine test_int32(outpath)
32+
subroutine test_int32(outpath)
3333
character(*), intent(in) :: outpath
3434
integer(int32) :: d(3, 2), e(2, 3)
3535
integer(int32), allocatable :: d2(:, :)
@@ -44,10 +44,10 @@ subroutine test_int32(outpath)
4444
call loadtxt(outpath, d2)
4545
call assert(all(shape(d2) == [2, 3]))
4646
call assert(all(abs(e-d2) == 0))
47-
end subroutine test_int32
47+
end subroutine
4848

4949

50-
subroutine test_rsp(outpath)
50+
subroutine test_rsp(outpath)
5151
character(*), intent(in) :: outpath
5252
real(sp) :: d(3, 2), e(2, 3)
5353
real(sp), allocatable :: d2(:, :)
@@ -62,7 +62,7 @@ subroutine test_rsp(outpath)
6262
call loadtxt(outpath, d2)
6363
call assert(all(shape(d2) == [2, 3]))
6464
call assert(all(abs(e-d2) < epsilon(1._sp)))
65-
end subroutine test_rsp
65+
end subroutine
6666

6767

6868
subroutine test_rdp(outpath)
@@ -80,9 +80,9 @@ subroutine test_rdp(outpath)
8080
call loadtxt(outpath, d2)
8181
call assert(all(shape(d2) == [2, 3]))
8282
call assert(all(abs(e-d2) < epsilon(1._dp)))
83-
end subroutine test_rdp
83+
end subroutine
8484

85-
subroutine test_csp(outpath)
85+
subroutine test_csp(outpath)
8686
character(*), intent(in) :: outpath
8787
complex(sp) :: d(3, 2), e(2, 3)
8888
complex(sp), allocatable :: d2(:, :)
@@ -92,14 +92,14 @@ subroutine test_csp(outpath)
9292
call assert(all(shape(d2) == [3, 2]))
9393
call assert(all(abs(d-d2) < epsilon(1._sp)))
9494

95-
e = reshape([1, 2, 3, 4, 5, 6], [2, 3])
95+
e = cmplx(1, 1)* reshape([1, 2, 3, 4, 5, 6], [2, 3])
9696
call savetxt(outpath, e)
9797
call loadtxt(outpath, d2)
9898
call assert(all(shape(d2) == [2, 3]))
9999
call assert(all(abs(e-d2) < epsilon(1._sp)))
100-
end subroutine test_csp
100+
end subroutine
101101

102-
subroutine test_cdp(outpath)
102+
subroutine test_cdp(outpath)
103103
character(*), intent(in) :: outpath
104104
complex(dp) :: d(3, 2), e(2, 3)
105105
complex(dp), allocatable :: d2(:, :)
@@ -109,11 +109,11 @@ subroutine test_cdp(outpath)
109109
call assert(all(shape(d2) == [3, 2]))
110110
call assert(all(abs(d-d2) < epsilon(1._dp)))
111111

112-
e = reshape([1, 2, 3, 4, 5, 6], [2, 3])
112+
e = cmplx(1, 1)* reshape([1, 2, 3, 4, 5, 6], [2, 3])
113113
call savetxt(outpath, e)
114114
call loadtxt(outpath, d2)
115115
call assert(all(shape(d2) == [2, 3]))
116116
call assert(all(abs(e-d2) < epsilon(1._dp)))
117-
end subroutine test_cdp
117+
end subroutine
118118

119119
end program test_savetxt

0 commit comments

Comments
 (0)