@@ -16,7 +16,11 @@ subroutine collect_loadtxt(testsuite)
16
16
testsuite = [ &
17
17
new_unittest(" loadtxt_int32" , test_loadtxt_int32), &
18
18
new_unittest(" loadtxt_sp" , test_loadtxt_sp), &
19
+ new_unittest(" loadtxt_sp_huge" , test_loadtxt_sp_huge), &
20
+ new_unittest(" loadtxt_sp_tiny" , test_loadtxt_sp_tiny), &
19
21
new_unittest(" loadtxt_dp" , test_loadtxt_dp), &
22
+ new_unittest(" loadtxt_dp_huge" , test_loadtxt_dp_huge), &
23
+ new_unittest(" loadtxt_dp_tiny" , test_loadtxt_dp_tiny), &
20
24
new_unittest(" loadtxt_complex" , test_loadtxt_complex) &
21
25
]
22
26
@@ -27,18 +31,21 @@ subroutine test_loadtxt_int32(error)
27
31
! > Error handling
28
32
type (error_type), allocatable , intent (out ) :: error
29
33
integer (int32), allocatable :: input(:,:), expected(:,:)
30
-
31
- call loadtxt(" array1.dat" , input)
32
- call savetxt(" array1_new.dat" , input)
33
- call loadtxt(" array1_new.dat" , expected)
34
- call check(error, all (input == expected))
35
- if (allocated (error)) return
36
-
37
- call loadtxt(" array2.dat" , input)
38
- call savetxt(" array2_new.dat" , input)
39
- call loadtxt(" array2_new.dat" , expected)
40
- call check(error, all (input == expected))
41
- if (allocated (error)) return
34
+ real (sp), allocatable :: harvest(:,:)
35
+ integer :: n
36
+
37
+ allocate (harvest(10 ,10 ))
38
+ allocate (input(10 ,10 ))
39
+ allocate (expected(10 ,10 ))
40
+
41
+ do n = 1 , 10
42
+ call random_number (harvest)
43
+ input = int (harvest * 100 )
44
+ call savetxt(' test_int32.txt' , input)
45
+ call loadtxt(' test_int32.txt' , expected)
46
+ call check(error, all (input == expected))
47
+ if (allocated (error)) return
48
+ end do
42
49
43
50
end subroutine test_loadtxt_int32
44
51
@@ -47,54 +54,151 @@ subroutine test_loadtxt_sp(error)
47
54
! > Error handling
48
55
type (error_type), allocatable , intent (out ) :: error
49
56
real (sp), allocatable :: input(:,:), expected(:,:)
57
+ integer :: n
50
58
51
- call loadtxt(" array3.dat" , input)
52
- call savetxt(" array3_sp.dat" , input)
53
- call loadtxt(" array3_sp.dat" , expected)
54
- call check(error, all (input == expected))
55
- if (allocated (error)) return
59
+ allocate (input(10 ,10 ))
60
+ allocate (expected(10 ,10 ))
56
61
57
- call loadtxt(" array4.dat" , input)
58
- call savetxt(" array4_sp.dat" , input)
59
- call loadtxt(" array4_sp.dat" , expected)
60
- call check(error, all (input == expected))
61
- if (allocated (error)) return
62
+ do n = 1 , 10
63
+ call random_number (input)
64
+ input = input - 0.5
65
+ call savetxt(' test_sp.txt' , input)
66
+ call loadtxt(' test_sp.txt' , expected)
67
+ call check(error, all (input == expected))
68
+ if (allocated (error)) return
69
+ end do
62
70
63
71
end subroutine test_loadtxt_sp
64
72
65
73
74
+ subroutine test_loadtxt_sp_huge (error )
75
+ ! > Error handling
76
+ type (error_type), allocatable , intent (out ) :: error
77
+ real (sp), allocatable :: input(:,:), expected(:,:)
78
+ integer :: n
79
+
80
+ allocate (input(10 ,10 ))
81
+ allocate (expected(10 ,10 ))
82
+
83
+ do n = 1 , 10
84
+ call random_number (input)
85
+ input = (input - 0.5 ) * huge (input)
86
+ call savetxt(' test_sp_huge.txt' , input)
87
+ call loadtxt(' test_sp_huge.txt' , expected)
88
+ call check(error, all (input == expected))
89
+ if (allocated (error)) return
90
+ end do
91
+
92
+ end subroutine test_loadtxt_sp_huge
93
+
94
+
95
+ subroutine test_loadtxt_sp_tiny (error )
96
+ ! > Error handling
97
+ type (error_type), allocatable , intent (out ) :: error
98
+ real (sp), allocatable :: input(:,:), expected(:,:)
99
+ integer :: n
100
+
101
+ allocate (input(10 ,10 ))
102
+ allocate (expected(10 ,10 ))
103
+
104
+ do n = 1 , 10
105
+ call random_number (input)
106
+ input = (input - 0.5 ) * tiny (input)
107
+ call savetxt(' test_sp_tiny.txt' , input)
108
+ call loadtxt(' test_sp_tiny.txt' , expected)
109
+ call check(error, all (input == expected))
110
+ if (allocated (error)) return
111
+ end do
112
+
113
+ end subroutine test_loadtxt_sp_tiny
114
+
115
+
66
116
subroutine test_loadtxt_dp (error )
67
117
! > Error handling
68
118
type (error_type), allocatable , intent (out ) :: error
69
119
real (dp), allocatable :: input(:,:), expected(:,:)
120
+ integer :: n
70
121
71
- call loadtxt(" array3.dat" , input)
72
- call savetxt(" array3_dp.dat" , input)
73
- call loadtxt(" array3_dp.dat" , expected)
74
- call check(error, all (input == expected))
75
- if (allocated (error)) return
122
+ allocate (input(10 ,10 ))
123
+ allocate (expected(10 ,10 ))
76
124
77
- call loadtxt(" array4.dat" , input)
78
- call savetxt(" array4_dp.dat" , input)
79
- call loadtxt(" array4_dp.dat" , expected)
80
- call check(error, all (input == expected))
81
- if (allocated (error)) return
125
+ do n = 1 , 10
126
+ call random_number (input)
127
+ input = input - 0.5
128
+ call savetxt(' test_dp.txt' , input)
129
+ call loadtxt(' test_dp.txt' , expected)
130
+ call check(error, all (input == expected))
131
+ if (allocated (error)) return
132
+ end do
82
133
83
134
end subroutine test_loadtxt_dp
84
135
85
136
86
- subroutine test_loadtxt_complex (error )
87
- ! > Error handling
88
- type (error_type), allocatable , intent (out ) :: error
89
- complex (dp), allocatable :: input(:,:), expected(:,:)
137
+ subroutine test_loadtxt_dp_huge (error )
138
+ ! > Error handling
139
+ type (error_type), allocatable , intent (out ) :: error
140
+ real (dp), allocatable :: input(:,:), expected(:,:)
141
+ integer :: n
142
+
143
+ allocate (input(10 ,10 ))
144
+ allocate (expected(10 ,10 ))
145
+
146
+ do n = 1 , 10
147
+ call random_number (input)
148
+ input = (input - 0.5 ) * huge (input)
149
+ call savetxt(' test_dp_huge.txt' , input)
150
+ call loadtxt(' test_dp_huge.txt' , expected)
151
+ call check(error, all (input == expected))
152
+ if (allocated (error)) return
153
+ end do
154
+
155
+ end subroutine test_loadtxt_dp_huge
156
+
157
+
158
+ subroutine test_loadtxt_dp_tiny (error )
159
+ ! > Error handling
160
+ type (error_type), allocatable , intent (out ) :: error
161
+ real (dp), allocatable :: input(:,:), expected(:,:)
162
+ integer :: n
163
+
164
+ allocate (input(10 ,10 ))
165
+ allocate (expected(10 ,10 ))
166
+
167
+ do n = 1 , 10
168
+ call random_number (input)
169
+ input = (input - 0.5 ) * tiny (input)
170
+ call savetxt(' test_dp_tiny.txt' , input)
171
+ call loadtxt(' test_dp_tiny.txt' , expected)
172
+ call check(error, all (input == expected))
173
+ if (allocated (error)) return
174
+ end do
90
175
91
- call loadtxt(" array5.dat" , input)
92
- call savetxt(" array5_new.dat" , input)
93
- call loadtxt(" array5_new.dat" , expected)
94
- call check(error, all (input == expected))
95
- if (allocated (error)) return
176
+ end subroutine test_loadtxt_dp_tiny
96
177
97
- end subroutine test_loadtxt_complex
178
+
179
+ subroutine test_loadtxt_complex (error )
180
+ ! > Error handling
181
+ type (error_type), allocatable , intent (out ) :: error
182
+ complex (dp), allocatable :: input(:,:), expected(:,:)
183
+ real (dp), allocatable :: re(:,:), im(:,:)
184
+ integer :: n
185
+
186
+ allocate (re(10 ,10 ))
187
+ allocate (im(10 ,10 ))
188
+ allocate (input(10 ,10 ))
189
+ allocate (expected(10 ,10 ))
190
+
191
+ do n = 1 , 10
192
+ call random_number (re)
193
+ call random_number (im)
194
+ input = cmplx (re, im)
195
+ call savetxt(' test_complex.txt' , input)
196
+ call loadtxt(' test_complex.txt' , expected)
197
+ call check(error, all (input == expected))
198
+ if (allocated (error)) return
199
+ end do
200
+
201
+ end subroutine test_loadtxt_complex
98
202
99
203
end module test_loadtxt
100
204
0 commit comments