1
1
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
6
6
7
- character (:), allocatable :: outpath
7
+ character (:), allocatable :: outpath
8
8
9
- outpath = get_outpath() // " /tmp.dat"
9
+ outpath = get_outpath() // " /tmp.dat"
10
10
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)
16
16
17
17
contains
18
18
19
- function get_outpath () result(outpath)
19
+ function get_outpath () result(outpath)
20
20
integer :: ierr
21
21
character (256 ) :: argv
22
22
character (:), allocatable :: outpath
23
23
24
24
call get_command_argument(1 , argv, status= ierr)
25
25
if (ierr== 0 ) then
26
- outpath = trim (argv)
26
+ outpath = trim (argv)
27
27
else
28
- outpath = ' .'
28
+ outpath = ' .'
29
29
endif
30
- end function get_outpath
30
+ end function get_outpath
31
31
32
- subroutine test_int32 (outpath )
32
+ subroutine test_int32 (outpath )
33
33
character (* ), intent (in ) :: outpath
34
34
integer (int32) :: d(3 , 2 ), e(2 , 3 )
35
35
integer (int32), allocatable :: d2(:, :)
@@ -44,10 +44,10 @@ subroutine test_int32(outpath)
44
44
call loadtxt(outpath, d2)
45
45
call assert(all (shape (d2) == [2 , 3 ]))
46
46
call assert(all (abs (e- d2) == 0 ))
47
- end subroutine test_int32
47
+ end subroutine
48
48
49
49
50
- subroutine test_rsp (outpath )
50
+ subroutine test_rsp (outpath )
51
51
character (* ), intent (in ) :: outpath
52
52
real (sp) :: d(3 , 2 ), e(2 , 3 )
53
53
real (sp), allocatable :: d2(:, :)
@@ -62,7 +62,7 @@ subroutine test_rsp(outpath)
62
62
call loadtxt(outpath, d2)
63
63
call assert(all (shape (d2) == [2 , 3 ]))
64
64
call assert(all (abs (e- d2) < epsilon (1._sp )))
65
- end subroutine test_rsp
65
+ end subroutine
66
66
67
67
68
68
subroutine test_rdp (outpath )
@@ -80,9 +80,9 @@ subroutine test_rdp(outpath)
80
80
call loadtxt(outpath, d2)
81
81
call assert(all (shape (d2) == [2 , 3 ]))
82
82
call assert(all (abs (e- d2) < epsilon (1._dp )))
83
- end subroutine test_rdp
83
+ end subroutine
84
84
85
- subroutine test_csp (outpath )
85
+ subroutine test_csp (outpath )
86
86
character (* ), intent (in ) :: outpath
87
87
complex (sp) :: d(3 , 2 ), e(2 , 3 )
88
88
complex (sp), allocatable :: d2(:, :)
@@ -92,14 +92,14 @@ subroutine test_csp(outpath)
92
92
call assert(all (shape (d2) == [3 , 2 ]))
93
93
call assert(all (abs (d- d2) < epsilon (1._sp )))
94
94
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 ])
96
96
call savetxt(outpath, e)
97
97
call loadtxt(outpath, d2)
98
98
call assert(all (shape (d2) == [2 , 3 ]))
99
99
call assert(all (abs (e- d2) < epsilon (1._sp )))
100
- end subroutine test_csp
100
+ end subroutine
101
101
102
- subroutine test_cdp (outpath )
102
+ subroutine test_cdp (outpath )
103
103
character (* ), intent (in ) :: outpath
104
104
complex (dp) :: d(3 , 2 ), e(2 , 3 )
105
105
complex (dp), allocatable :: d2(:, :)
@@ -109,11 +109,11 @@ subroutine test_cdp(outpath)
109
109
call assert(all (shape (d2) == [3 , 2 ]))
110
110
call assert(all (abs (d- d2) < epsilon (1._dp )))
111
111
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 ])
113
113
call savetxt(outpath, e)
114
114
call loadtxt(outpath, d2)
115
115
call assert(all (shape (d2) == [2 , 3 ]))
116
116
call assert(all (abs (e- d2) < epsilon (1._dp )))
117
- end subroutine test_cdp
117
+ end subroutine
118
118
119
119
end program test_savetxt
0 commit comments