@@ -4,57 +4,77 @@ program test_loadtxt
4
4
use stdlib_experimental_error, only: assert
5
5
implicit none
6
6
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)
10
14
11
15
contains
12
16
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
14
32
real (sp) :: d(3 , 2 ), e(2 , 3 )
15
33
real (sp), allocatable :: d2(:, :)
16
34
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)
19
37
call assert(all (shape (d2) == [3 , 2 ]))
20
38
call assert(all (abs (d- d2) < epsilon (1._sp )))
21
39
22
40
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)
25
43
call assert(all (shape (d2) == [2 , 3 ]))
26
44
call assert(all (abs (e- d2) < epsilon (1._sp )))
27
45
end subroutine
28
46
29
47
30
- subroutine test_dp ()
48
+ subroutine test_dp (outpath )
49
+ character (* ), intent (in ) :: outpath
31
50
real (dp) :: d(3 , 2 ), e(2 , 3 )
32
51
real (dp), allocatable :: d2(:, :)
33
52
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)
36
55
call assert(all (shape (d2) == [3 , 2 ]))
37
56
call assert(all (abs (d- d2) < epsilon (1._dp )))
38
57
39
58
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)
42
61
call assert(all (shape (d2) == [2 , 3 ]))
43
62
call assert(all (abs (e- d2) < epsilon (1._dp )))
44
63
end subroutine
45
64
46
- subroutine test_qp ()
65
+ subroutine test_qp (outpath )
66
+ character (* ), intent (in ) :: outpath
47
67
real (qp) :: d(3 , 2 ), e(2 , 3 )
48
68
real (qp), allocatable :: d2(:, :)
49
69
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)
52
72
call assert(all (shape (d2) == [3 , 2 ]))
53
73
call assert(all (abs (d- d2) < epsilon (1._qp )))
54
74
55
75
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)
58
78
call assert(all (shape (d2) == [2 , 3 ]))
59
79
call assert(all (abs (e- d2) < epsilon (1._qp )))
60
80
end subroutine
0 commit comments